Framework Integration
Storybook Astro supports rendering components from React, Vue, Svelte, Preact, Solid, and Alpine.js alongside native Astro components. Each framework is handled by an integration adapter.
Integration architecture
Section titled “Integration architecture”Each integration extends the BaseIntegration class and implements four methods:
getAstroRenderer()— Returns the Astro framework integration (e.g.@astrojs/react)getVitePlugins()— Returns Vite plugins needed for the framework (e.g.@vitejs/plugin-react)getStorybookRenderer()— Returns the Storybook renderer name (e.g.@storybook/react)resolveClient(specifier)— Handles client-side module resolution if needed
Integration files live in packages/@storybook-astro/framework/src/integrations/.
The include pattern
Section titled “The include pattern”Most integrations accept an include option — a glob pattern that tells Vite which files to process with the framework’s compiler:
react({ include: ['**/react/**'] })solid({ include: ['**/solid/**'] })How delegation works
Section titled “How delegation works”When a story sets parameters.renderer, the render pipeline changes:
- The renderer (
render.tsx) checksparameters.rendereron the story - Instead of routing through the Astro Container API, it delegates to the specified framework’s
renderToCanvasfunction - The framework renderer manages its own reactive root and lifecycle
storyFn()is called after delegation — this ordering is critical for frameworks like Solid that manage their own reactive roots- The teardown the framework returns goes back to Storybook, so the story is unmounted, and its effects clean up, when Storybook removes it: on navigation, on a remount, and when a Docs page closes. A teardown only unmounts while the canvas still holds that story, so a Docs story block’s late teardown leaves a newer story alone. A framework story is also unmounted before a story of another framework or an Astro story renders into its canvas, and before a remount. If its cleanup throws, the error is logged to the console and the next story still renders. Preact’s renderer returns no teardown, so a Preact story stays mounted until another Preact story renders into its canvas. A story of another framework or an Astro story clears its DOM but doesn’t unmount it
Virtual modules
Section titled “Virtual modules”The framework integration system uses two virtual modules:
virtual:astro-container-renderers— Provides anaddRenderersfunction to register framework renderers with the Astro Containervirtual:storybook-renderer-fallback— Provides framework renderers for client-side delegation
Adding a new framework
Section titled “Adding a new framework”To add a new framework integration:
- Create an integration file in
packages/@storybook-astro/framework/src/integrations/ - Extend
BaseIntegrationand implement the required methods - Export a factory function in
integrations/index.ts - Install the corresponding Astro integration, Vite plugin, and Storybook renderer packages
See the existing integrations (e.g. react.ts, vue.ts) for reference implementations.