Docs: Filter mount stories from Stories block, error when referenced in MDX#28434
Docs: Filter mount stories from Stories block, error when referenced in MDX#28434kasperpeulen merged 11 commits intonextfrom
Stories block, error when referenced in MDX#28434Conversation
…e when used in MDX
There was a problem hiding this comment.
PR Summary
code/core/src/preview-api/modules/preview-web/Preview.tsx: ReplacedmountDestructuredwith direct check forr.story.usesMount.code/core/src/preview-api/modules/preview-web/render/StoryRender.ts: Simplified logic by directly checkingstory.usesMount.code/core/src/preview-api/modules/store/csf/portable-stories.ts: RemovedmountDestructuredimport, modifiedisMountDestructuredlogic.code/core/src/preview-errors.ts: AddedPlayFunctionWithMountNotAvailableErrorclass underBLOCKScategory.code/lib/blocks/src/blocks/Stories.tsx: Filtered out stories using 'mount' in docs to prevent rendering issues.
9 file(s) reviewed, 1 comment(s)
Edit PR Review Bot Settings
☁️ Nx Cloud ReportCI is running/has finished running commands for commit 6b92b98. As they complete they will appear below. Click to see the status, the terminal output, and the build insights. 📂 See all runs for this CI Pipeline Execution ✅ Successfully ran 1 targetSent with 💌 from NxCloud. |
There was a problem hiding this comment.
PR Summary
(updates since last review)
code/core/src/preview-api/modules/store/csf/prepareStory.ts: Replaced generic error withNoRenderFunctionErrorfor missing render function.code/core/src/preview-errors.ts: IntroducedNoRenderFunctionErrorfor better error handling when no render function is available.
2 file(s) reviewed, 1 comment(s)
Edit PR Review Bot Settings
There was a problem hiding this comment.
PR Summary
(updates since last review)
- Removed
PlayFunctionWithMountNotAvailableErrorclass incode/core/src/preview-errors.ts - Updated error message in
NoRenderFunctionErrorclass incode/core/src/preview-errors.ts - Simplified error handling by consolidating rendering function errors
- Corrected typo in
NoRenderFunctionErrorclass message
1 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings
# Conflicts: # code/core/src/preview-api/modules/preview-web/render/StoryRender.ts # code/core/src/preview-errors.ts
There was a problem hiding this comment.
PR Summary
(updates since last review)
- Modified
PreviewWithSelection.tsxto streamline story rendering by passingrenderToCanvasdirectly and addingshowStoryDuringRendercallback. - Updated
StoryRender.test.tswithbeforeEachhook, introducedmountSpyfunction, and enhanced error handling tests. - Enhanced
StoryRender.tswithNoStoryMountedError, improvedrunPhasemethod, and refinedmountfunction for better error scenarios. - Added
NoStoryMountedErrorinpreview-errors.tsfor clearer error messages in MDX scenarios.
4 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings
There was a problem hiding this comment.
PR Summary
(updates since last review)
- Added
usesMountproperty to story objects in/code/core/src/preview-api/modules/store/StoryStore.test.ts - Ensured
usesMountis set tofalsein various test scenarios inStoryStore.test.ts - Added
usesMountfield to prepared story object in/code/core/src/preview-api/modules/store/csf/prepareStory.test.ts - Verified
usesMountis carried through from story annotations inprepareStory.test.ts
2 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings
| return ( | ||
| <ErrorMessage> | ||
| This story mounts inside of play. Set{' '} | ||
| <a href="https://storybook.js.org/docs/api/doc-blocks/doc-block-story#autoplay">autoplay</a>{' '} |
There was a problem hiding this comment.
Make sure to track the docs update as a followup issue
There was a problem hiding this comment.
As an alternative, we might just not filter these stores in Stories and instead use this message? Would that solve the discoverability issue?
The user could just set tags: ['-autoplay'] on the story to avoid the error, no?
There was a problem hiding this comment.
I could live with that, although the error is quite a bit ugly atm, cc @shilman
| stories = stories.filter((story) => story.tags?.includes('autodocs')); | ||
| // Don't show stories where mount is used in docs. | ||
| // As the play function is not running in docs, and when mount is used, the mounting is happening in play itself. | ||
| stories = stories.filter((story) => story.tags?.includes('autodocs') && !story.usesMount); |
There was a problem hiding this comment.
Probably also want to document this somewhere, either in this PR or in a tracked followup
| } | ||
|
|
||
| if (!mounted) { | ||
| throw new NoStoryMountedError(); |
There was a problem hiding this comment.
Duplicate with #28431 .. were these PRs up split properly?
There was a problem hiding this comment.
sorry changed the base branch now
Stories block, error when referenced in MDX
Stories block, error when referenced in MDXStories block, error when referenced in MDX
There was a problem hiding this comment.
LGTM
No file(s) reviewed, no comment(s)
Edit PR Review Bot Settings
# Conflicts: # code/core/src/preview-api/modules/preview-web/Preview.tsx
There was a problem hiding this comment.
LGTM
30 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings
There was a problem hiding this comment.
LGTM
9 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings
There was a problem hiding this comment.
LGTM
No file(s) reviewed, no comment(s)
Edit PR Review Bot Settings
Closes #28420
What I did
Filter mount stories inside of Stories and give a proper error message when used in MDX
Checklist for Contributors
Testing
The changes in this PR are covered in the following automated tests:
Manual testing
This section is mandatory for all contributions. If you believe no manual test is necessary, please state so explicitly. Thanks!
Documentation
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/src/sandbox-templates.tsMake 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 canary-release-pr.yml --field pr=<PR_NUMBER>Greptile Summary
/code/lib/blocks/src/blocks/Stories.tsx/code/core/src/preview-errors.ts/code/frameworks/nextjs/src/babel/preset.tsfor specific browser targets and bugfixes/code/lib/cli/core/components/index.cjs/code/core/template/stories/