Skip to content

Commit 503f20c

Browse files
committed
fix: defers loading state update during hydration
1 parent acf195c commit 503f20c

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

src/components/providers/loading-screen.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ export function LoadingScreen() {
2121
setLoaded(true);
2222
}
2323

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+
2432
window.addEventListener('load', handleLoad);
2533
return () => window.removeEventListener('load', handleLoad);
2634
}, [loaded]);

0 commit comments

Comments
 (0)