Skip to content

Commit bbf3bff

Browse files
committed
🤖 fix: don't force dark theme when globals.theme is undefined
Chromatic modes only set context.globals.theme during their CI snapshot process, not during local development. When undefined, we should let ThemeProvider use its default behavior (system preference/localStorage) rather than forcing dark theme. This way: - Local dev: uses system preference (no forcedTheme) - Chromatic dark mode: gets forcedTheme='dark' from modes config - Chromatic light mode: gets forcedTheme='light' from modes config - Toolbar usage: manually set globals.theme applies forcedTheme
1 parent da627a2 commit bbf3bff

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

.storybook/preview.tsx

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,16 @@ const preview: Preview = {
2020
},
2121
decorators: [
2222
(Story, context) => {
23+
// Chromatic modes don't set context.globals during local development
24+
// They only work during Chromatic's CI snapshot process
25+
// For local development, globals.theme can be set via the toolbar
2326
const mode = context.globals.theme as ThemeMode | undefined;
24-
console.log('🔍 Storybook decorator - Story:', context.name);
25-
console.log('🔍 context.globals:', context.globals);
26-
console.log('🔍 context.parameters:', context.parameters);
27-
console.log('🔍 context.parameters.chromatic:', context.parameters.chromatic);
28-
console.log('🔍 Full context keys:', Object.keys(context));
29-
console.log('🔍 Theme mode from globals:', mode);
30-
// Default to dark when no mode is explicitly set (e.g., Latest view)
31-
const forcedTheme = mode ?? "dark";
32-
console.log('🔍 forcedTheme passed to ThemeProvider:', forcedTheme);
27+
28+
// When no explicit mode is set (locally or via toolbar), don't force a theme
29+
// Let ThemeProvider use its default behavior (system preference / localStorage)
30+
// When Chromatic runs with modes, it will set globals.theme appropriately
3331
return (
34-
<ThemeProvider forcedTheme={forcedTheme}>
32+
<ThemeProvider forcedTheme={mode}>
3533
<Story />
3634
</ThemeProvider>
3735
);

0 commit comments

Comments
 (0)