We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
fix: defers loading state update during hydration
1 parent acf195c commit 503f20cCopy full SHA for 503f20c
1 file changed
src/components/providers/loading-screen.tsx
@@ -21,6 +21,14 @@ export function LoadingScreen() {
21
setLoaded(true);
22
}
23
24
+ // If the page already loaded before this effect ran (common during
25
+ // hydration), defer setState via rAF to satisfy the lint rule that
26
+ // forbids synchronous setState inside effects.
27
+ if (document.readyState === 'complete') {
28
+ const id = requestAnimationFrame(() => setLoaded(true));
29
+ return () => cancelAnimationFrame(id);
30
+ }
31
+
32
window.addEventListener('load', handleLoad);
33
return () => window.removeEventListener('load', handleLoad);
34
}, [loaded]);
0 commit comments