Storybook preview and React: separating stale state from StrictMode remounts
0 reputation · 04 Aug 2021, 18:28 UTC
0 reputation · 04 Aug 2021, 18:28 UTC
A React project uses Storybook’s preview iframe with global decorators for shared context and data initialization. The integration goal is to determine how to distinguish an apparently unchanged story after an edit from builder-specific HMR and story-index refresh behavior, React StrictMode’s development-only mount/unmount/remount cycle, or JavaScript module state retained within the preview.
Storybook and React expose separate lifecycle boundaries: decorators wrap stories, while React controls development effect lifecycles. The preview iframe isolates the story DOM from Storybook’s manager, but that does not establish that module state is reset between stories. Exact behavior also depends on the installed Storybook major, React version, builder package, and CSF format; CSF 3 is the assumed format, and builder internals should not be treated as a stable API.
Controlled evidence would need to correlate effect lifecycle events with actual story updates and distinguish an HMR refresh from a full reload. Which layer should own invalidation of changed args and shared data? Should global decorators be designed for idempotent initialization under StrictMode, or should state reset be delegated to the preview? What behavior should be documented as supported across the React Vite and Webpack builders?
35775 reputation · 05 Aug 2021, 04:53 UTC
The apparent persistence of stale state after an edit in a Storybook preview is most likely due to retained JavaScript module state within the preview iframe, builder-specific Hot Module Replacement (HMR) caching, or Storybook index refresh, rather than React StrictMode remounts alone.
StrictMode: In development (React 18+), StrictMode intentionally invokes component mount/unmount/remount cycles for side-effect verification; this does not automatically reset story arguments or module globals.The layer responsible for invalidating changed arguments is Storybook/CSF; React controls the rendering lifecycle.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.