Commit d32f711
committed
🤖 fix: apply Storybook theme synchronously before React renders
Root cause: Original code used useEffect to set theme, which is async.
Chromatic sometimes captured snapshots before the effect ran.
Also removed:
- preview-head.html (not needed, decorator handles theme)
- ThemeProvider.forcedTheme prop (not needed, decorator sets localStorage)
Fix:
- Restored defaultValue: 'dark' in globalTypes (ensures context.globals.theme always has value)
- Apply theme synchronously in decorator BEFORE React renders
- Write to localStorage, document.dataset.theme, and colorScheme directly
Net: -25 lines1 parent f248522 commit d32f711
File tree
3 files changed
+20
-45
lines changed- .storybook
- src/browser/contexts
3 files changed
+20
-45
lines changedThis file was deleted.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| 12 | + | |
11 | 13 | | |
12 | 14 | | |
13 | 15 | | |
| |||
20 | 22 | | |
21 | 23 | | |
22 | 24 | | |
23 | | - | |
| 25 | + | |
24 | 26 | | |
25 | | - | |
26 | | - | |
27 | | - | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
28 | 32 | | |
29 | 33 | | |
30 | 34 | | |
31 | 35 | | |
32 | 36 | | |
33 | | - | |
| 37 | + | |
34 | 38 | | |
35 | 39 | | |
36 | 40 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
68 | 58 | | |
69 | 59 | | |
70 | | - | |
71 | | - | |
| 60 | + | |
| 61 | + | |
72 | 62 | | |
73 | 63 | | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
| 64 | + | |
| 65 | + | |
79 | 66 | | |
80 | 67 | | |
81 | 68 | | |
82 | | - | |
83 | | - | |
| 69 | + | |
| 70 | + | |
84 | 71 | | |
85 | 72 | | |
86 | | - | |
| 73 | + | |
87 | 74 | | |
88 | 75 | | |
89 | 76 | | |
| |||
0 commit comments