-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: include external Storybook entries for full story name retrieval #29452
fix: include external Storybook entries for full story name retrieval #29452
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1 file(s) reviewed, 3 comment(s)
Edit PR Review Bot Settings | Greptile
function combineIndexes(rootIndex: API_IndexHash | undefined, refs: API_Refs) { | ||
// Create a copy of the root index to avoid mutation | ||
const combinedIndex = { ...(rootIndex || {}) }; // Use an empty object as fallback | ||
|
||
// Traverse refs and merge each nested index with the root index | ||
Object.values(refs).forEach((ref) => { | ||
if (ref.index) { | ||
Object.assign(combinedIndex, ref.index); | ||
} | ||
}); | ||
|
||
return combinedIndex; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: potential race condition if refs are updated while combining indexes - consider using useMemo to cache the combined index
while ('parent' in node && node.parent && index[node.parent] && fullStoryName.length < 24) { | ||
// @ts-expect-error (non strict) | ||
node = index[node.parent]; | ||
let node = combinedIndex[currentStory.id]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: add null check for combinedIndex[currentStory.id] to prevent runtime errors
while ( | ||
node && | ||
'parent' in node && | ||
node.parent && | ||
combinedIndex[node.parent] && | ||
fullStoryName.length < 24 | ||
) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: consider moving length check to beginning of loop to prevent unnecessary iterations
7c5f8f1
to
6098c01
Compare
Closes #29268
What I did
This PR resolves the issue of composition failures by including external Storybook entries in the index data. Previously, the current story ID was only searched in the internal Storybook index, which caused mismatches. By incorporating external Storybook IDs into the combined index, full story names are now correctly retrieved and visible on mobile devices without breaking.
Screen.Recording.2024-10-26.at.2.39.59.AM.mov
Checklist for Contributors
Testing
The changes in this PR are covered in the following automated tests:
Manual testing
yarn start
.Documentation
MIGRATION.MD
Checklist for Maintainers
When this PR is ready for testing, make sure to add
ci:normal
,ci:merged
orci:daily
GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found incode/lib/cli/src/sandbox-templates.ts
Make 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/core
team 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
Enhanced mobile navigation to properly handle external Storybook composition by merging root and external indexes for accurate story name retrieval.
combineIndexes
function in/code/core/src/manager/components/mobile/navigation/MobileNavigation.tsx
to merge root and external ref indexes@ts-expect-error
comments and adding proper type checksuseFullStoryName
hook to handle undefined nodes gracefullyrefs
object to prevent runtime errors during composition