327255bd5a
Describe what your pull request does. If appropriate, add GIFs or images showing the before and after. ### Change Type - [ ] `patch` — Bug fix - [ ] `minor` — New feature - [ ] `major` — Breaking change - [ ] `dependencies` — Changes to package dependencies[^1] - [x] `documentation` — Changes to the documentation only[^2] - [ ] `tests` — Changes to any test code only[^2] - [ ] `internal` — Any other changes that don't affect the published package[^2] - [ ] I don't know [^1]: publishes a `patch` release, for devDependencies use `internal` [^2]: will not publish a new version ### Test Plan 1. Add a step-by-step description of how to test your PR here. 2. - [ ] Unit Tests - [ ] End to end tests ### Release Notes - Add a brief release note for your PR here.
30 lines
574 B
TypeScript
30 lines
574 B
TypeScript
'use client'
|
|
|
|
import { useRouter } from 'next/navigation'
|
|
import { useEffect } from 'react'
|
|
|
|
let AutoRefresh = ({ children }: { children: any }) => {
|
|
return children
|
|
}
|
|
|
|
if (process.env.NODE_ENV === 'development') {
|
|
AutoRefresh = function AutoRefresh({ children }) {
|
|
const router = useRouter()
|
|
|
|
useEffect(() => {
|
|
const ws = new WebSocket('ws://localhost:3201')
|
|
ws.onmessage = (event) => {
|
|
if (event.data === 'refresh') {
|
|
router.refresh()
|
|
}
|
|
}
|
|
return () => {
|
|
ws.close()
|
|
}
|
|
}, [router])
|
|
|
|
return children
|
|
}
|
|
}
|
|
|
|
export default AutoRefresh
|