Skip to content

Commit 424de7d

Browse files
committed
chore: fix ssr in react devtools
1 parent c932819 commit 424de7d

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

packages/react-devtools/src/devtools.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,19 @@ const convertRender = (
2525
setComponent(typeof Component === 'function' ? Component() : Component)
2626
}
2727

28+
let hydrated = false
29+
30+
const useHydrated = () => {
31+
useEffect(() => {
32+
if (!hydrated) {
33+
hydrated = true
34+
}
35+
}, [])
36+
return hydrated
37+
}
38+
2839
export const Devtools = ({ plugins, options }: DevtoolsProps) => {
40+
const isHydrated = useHydrated()
2941
const devToolRef = useRef<HTMLDivElement>(null)
3042
const [PluginComponent, setPluginComponent] = useState<JSX.Element | null>(
3143
null,
@@ -57,6 +69,8 @@ export const Devtools = ({ plugins, options }: DevtoolsProps) => {
5769
devtools.unmount()
5870
}
5971
}, [devtools])
72+
// we only render on the client side after hydration
73+
if (!isHydrated) return null
6074
const pluginContainer = document.getElementById(PLUGIN_CONTAINER_ID)
6175
const titleContainer = document.getElementById(PLUGIN_TITLE_CONTAINER_ID)
6276
return (

0 commit comments

Comments
 (0)