Skip to content

Commit 43fa874

Browse files
authored
🤖 fix: collapse right sidebar by default in Storybook (#1252)
## Problem Right sidebar expansion state was non-deterministic across Storybook stories because: - Storybook/Chromatic preserves `localStorage` across story runs in the same session - `App.rightsidebar.stories.tsx` calls `expandRightSidebar()` to show the sidebar - Other stories that don't explicitly set sidebar state would inherit whatever state was left behind ## Solution Add `collapseRightSidebar()` to the global decorator in `.storybook/preview.tsx`. This ensures every story starts with a collapsed right sidebar, and stories that need it expanded call `expandRightSidebar()` in their setup after the decorator runs. Follows the same pattern already used for disabling tutorials globally. --- _Generated with `mux` • Model: `anthropic:claude-opus-4-5` • Thinking: `high`_
1 parent ffe9c34 commit 43fa874

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

.storybook/preview.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ import React from "react";
22
import type { Preview } from "@storybook/react-vite";
33
import { ThemeProvider, type ThemeMode } from "../src/browser/contexts/ThemeContext";
44
import "../src/browser/styles/globals.css";
5-
import { TUTORIAL_STATE_KEY, type TutorialState } from "../src/common/constants/storage";
5+
import {
6+
TUTORIAL_STATE_KEY,
7+
RIGHT_SIDEBAR_COLLAPSED_KEY,
8+
type TutorialState,
9+
} from "../src/common/constants/storage";
610
import { NOW } from "../src/browser/stories/mockFactory";
711

812
// Mock Date.now() globally for deterministic snapshots
@@ -21,6 +25,14 @@ function disableTutorials() {
2125
}
2226
}
2327

28+
// Collapse right sidebar by default to ensure deterministic snapshots
29+
// Stories that need expanded sidebar call expandRightSidebar() in their setup
30+
function collapseRightSidebar() {
31+
if (typeof localStorage !== "undefined") {
32+
localStorage.setItem(RIGHT_SIDEBAR_COLLAPSED_KEY, JSON.stringify(true));
33+
}
34+
}
35+
2436
const preview: Preview = {
2537
globalTypes: {
2638
theme: {
@@ -56,6 +68,10 @@ const preview: Preview = {
5668
disableTutorials();
5769
}
5870

71+
// Collapse right sidebar by default for deterministic snapshots
72+
// Stories can expand via expandRightSidebar() in setup after this runs
73+
collapseRightSidebar();
74+
5975
return (
6076
<ThemeProvider forcedTheme={mode}>
6177
<Story />

0 commit comments

Comments
 (0)