Repository navigation
Core: Compose core annotations before preview beforeAll - #35323
Conversation
Plain (CSF1-3) previews don't fold the core annotations into `getProjectAnnotations()`, so `PreviewWeb` ran `beforeAll` against annotations without them — meaning core `beforeAll` hooks (e.g. the ones registering the `core/docgen` and `core/story-docs` open services in the preview) never ran, and an HMR of preview.js dropped core annotations entirely (losing backgrounds/viewport/etc. globals until a full reload). Compose the core annotations at the `PreviewWeb` layer, mirroring what the store and portable stories already do. The shared decision (prepend core unless already composed, then mark the result) is extracted into `composeProjectAnnotationsWithCore` so the preview, the store, and portable stories stay in sync instead of each re-implementing it. Co-authored-by: Cursor <cursoragent@cursor.com>
TypeScript cannot infer the renderer from ModuleExports[], so the helper defaulted to Renderer and broke compile in Preview.tsx. Co-authored-by: Cursor <cursoragent@cursor.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (6)
📝 WalkthroughWalkthroughIntroduces a new Core Annotation Composition Refactor
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes ✨ Finishing Touches📝 Generate docstrings
Warning Review ran into problems🔥 ProblemsGit: Failed to clone repository. Please run the Comment |
Closes #
What I did
Plain (CSF1–3) previews don't fold Storybook's core annotations into
getProjectAnnotations(), soPreviewWebranbeforeAllagainst annotations that lacked them. CorebeforeAllhooks (registering built-in open services likecore/docgenandcore/story-docsin the preview) never ran — e.g. autodocs<Controls />in MDX failed with "No registered service with id core/docgen exists in this environment". HMR ofpreview.jsalso dropped core annotations entirely (backgrounds/viewport globals lost until full reload).This PR composes core annotations at the
PreviewWeblayer (beforebeforeAllruns) and extracts the shared "prepend core unless already composed, then mark" logic intocomposeProjectAnnotationsWithCore, used by the preview,StoryStore, and portable stories so they can't drift.Reviewer guide
composeProjectAnnotationsWithCore.tsPreview.tsxrunBeforeAllHookStoryStore.ts,portable-stories.tsPreviewWeb.test.tsobjectContainingbecause core globals are now correctly preservedRisk areas: CSF4
definePreviewdouble-composition (guarded byhasCoreAnnotationsmarker), portable-storiesimport * as previewnamespace unwrapping (now onecomposeConfigspass instead of per-module), falsy annotation entries (filter(Boolean)in helper).Checklist for Contributors
Testing
The changes in this PR are covered in the following automated tests:
Manual testing
Caution
This section is mandatory for all contributions. If you believe no manual test is necessary, please state so explicitly. Thanks!
definePreview), e.g.yarn task sandbox --template react-vite/default-ts --start-from autoexperimentalDocgenServerin.storybook/main.ts(or via feature flag if your template supports it)<Controls />for a component story.storybook/preview.tsglobals (e.g. change a background) and save to trigger HMRyarn test PreviewWebandyarn test portable-stories— both should passDocumentation
MIGRATION.MD
Checklist for Maintainers
When this PR is ready for testing, make sure to add
ci:normal,ci:mergedorci:dailyGH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found incode/lib/cli-storybook/src/sandbox-templates.tsDeclare whether manual QA will be needed for this PR during the next release, through
qa:neededorqa:skipMake sure this PR contains one of the labels below:
Available labels
bug: Internal changes that fixes incorrect behavior.maintenance: User-facing maintenance tasks.dependencies: Upgrading (sometimes downgrading) dependencies.build: Internal-facing build tooling & test updates. Will not show up in release changelog.cleanup: Minor cleanup style change. Will not show up in release changelog.documentation: Documentation only changes. Will not show up in release changelog.feature request: Introducing a new feature.BREAKING CHANGE: Changes that break compatibility in some way with current major version.other: Changes that don't fit in the above categories.🦋 Canary release
This PR does not have a canary release associated. You can request a canary release of this pull request by mentioning the
@storybookjs/coreteam here.core team members can create a canary release here or locally with
gh workflow run --repo storybookjs/storybook publish.yml --field pr=<PR_NUMBER>Made with Cursor
Summary by CodeRabbit