Commit d83e9d2
committed
🤖 fix: apply theme synchronously to document before React renders
The key insight: React's useLayoutEffect runs AFTER initial render, but
Chromatic needs the theme applied BEFORE rendering starts to avoid
flashing and capture correct snapshots.
Solution: Apply theme to document.documentElement synchronously in the
decorator, before returning the ThemeProvider. This ensures:
- Light mode stories render in light theme immediately
- Dark mode stories render in dark theme immediately
- No flash of wrong theme during Chromatic snapshots
Credit: simpler synchronous approach beats async React lifecycle.1 parent 0780973 commit d83e9d2
1 file changed
+7
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | 23 | | |
27 | 24 | | |
28 | | - | |
29 | | - | |
30 | | - | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
31 | 32 | | |
32 | 33 | | |
33 | 34 | | |
| |||
0 commit comments