CodeVetter · Repo Unpack · Behavior traces
storybookjs/storybook
Three concrete flows were followed through implementation: development startup, selecting and rendering a story, and saving Controls changes to source. Startup has separate configuration-discovery and final preset passes. Selection branches between stories and docs and handles asynchronous replacement of an existing render. Saving crosses from browser events to AST mutation and filesystem output, then returns through correlated response events.
- Startup begins dispatcher.run() → core dev action → resolveDevCommandOptions() → dev() → withTelemetry() → buildDevStandalone(); invalid CLI options use handleCommandFailure().
- buildDevStandalone resolves port/config → first loadAllPresets → builder selection → second loadAllPresets → features/services/server-channel hooks → storybookDevServer; the server starts builders, listens, and conditionally opens the browser.
- Initial preview selection runs initializeWithStoryIndex() → selectSpecifiedStory() → entryFromSpecifier() → setSelection() → STORY_SPECIFIED/CURRENT_STORY_WAS_SET → renderSelection(); missing selection or index matches produce explicit error views.
- renderSelection resolves the entry → constructs StoryRender/MdxDocsRender/CsfDocsRender → prepare(); StoryRender.prepare calls StoryStore.loadStory → loadCSFFileByStoryId → importFn → storyFromCSFFile.
- After preparation, the preview emits STORY_PREPARED and renders to an element; StoryRender applies loaders → beforeEach → mount → conditional play, while React renderToCanvas creates the story subtree and calls renderElement inside act.
- Update story runs SaveStory.onSaveStory → Controls saveStory → experimental_requestResponse(SAVE_STORY_REQUEST); the dev preset has already registered initializeSaveStory, which reads/parses CSF, checks source/export names, and updates args or duplicates the export.
- The save handler formats source → concurrently writes and waits for STORY_RENDERED or 3000 ms → emits SAVE_STORY_RESPONSE; the manager resets args and optionally selects the new story, while errors produce a failed response and notification.
- Static build runs output cleanup → configuration/preset resolution → services registration → optional manager build → service snapshots before dependent manifests → preview build alongside remaining output effects.