Commit 1bfa4a0
committed
🤖 fix: prevent nested ThemeProvider from overriding forced theme
Root cause: When running in Storybook with Chromatic modes, the decorator
wraps stories in ThemeProvider with forcedTheme. But App.tsx also has its
own ThemeProvider without forcedTheme. The inner provider's useLayoutEffect
was overwriting the outer forced theme with the browser's prefers-color-scheme.
Solution: ThemeProvider now tracks whether it has a forced theme via isForced
context value. Nested providers check parentContext.isForced and defer to the
parent's theme when true, preventing the inner provider from overwriting.
Verified locally using Playwright:
- Browser prefers light + globals=theme:dark → correctly shows dark
- Browser prefers dark + globals=theme:light → correctly shows light
- Background colors correctly differ between themes
_Generated with `mux`_1 parent 075e156 commit 1bfa4a0
1 file changed
+25
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
| 19 | + | |
18 | 20 | | |
19 | 21 | | |
20 | 22 | | |
| |||
58 | 60 | | |
59 | 61 | | |
60 | 62 | | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
61 | 67 | | |
62 | 68 | | |
63 | 69 | | |
| |||
66 | 72 | | |
67 | 73 | | |
68 | 74 | | |
69 | | - | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
70 | 83 | | |
| 84 | + | |
71 | 85 | | |
72 | | - | |
73 | | - | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
74 | 90 | | |
75 | 91 | | |
76 | | - | |
77 | | - | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
78 | 96 | | |
79 | 97 | | |
80 | 98 | | |
81 | 99 | | |
82 | 100 | | |
83 | 101 | | |
| 102 | + | |
84 | 103 | | |
85 | | - | |
| 104 | + | |
86 | 105 | | |
87 | 106 | | |
88 | 107 | | |
| |||
0 commit comments