Skip to content
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

Composition: Fix composed story search #29453

Merged

Conversation

jsingh0026
Copy link
Contributor

@jsingh0026 jsingh0026 commented Oct 25, 2024

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:

  • stories
  • unit tests
  • integration tests
  • end-to-end tests

Manual testing

  1. Run a sandbox locally using yarn start.
  2. Open Storybook in your browser.
  3. Access a story from the external Storybook.
  4. Resize the browser window to mobile view (e.g., 375px width) to verify that the external Storybook is composed correctly and that the full story names are displayed as expected.

Documentation

  • Add or update documentation reflecting your changes
  • If you are deprecating/removing a feature, make sure to update
    MIGRATION.MD

Checklist for Maintainers

  • When this PR is ready for testing, make sure to add ci:normal, ci:merged or ci:daily GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found in code/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>

name before after diff z %
createSize 0 B 0 B 0 B - -
generateSize 78.2 MB 78.2 MB 100 B 1.13 0%
initSize 143 MB 143 MB 301 B 1.31 0%
diffSize 65.2 MB 65.2 MB 201 B 0.59 0%
buildSize 6.88 MB 6.88 MB 201 B 4.19 0%
buildSbAddonsSize 1.51 MB 1.51 MB 0 B - 0%
buildSbCommonSize 195 kB 195 kB 0 B - 0%
buildSbManagerSize 1.9 MB 1.9 MB 201 B 4.19 0%
buildSbPreviewSize 271 kB 271 kB 0 B - 0%
buildStaticSize 0 B 0 B 0 B - -
buildPrebuildSize 3.88 MB 3.88 MB 201 B 4.19 0%
buildPreviewSize 3 MB 3 MB 0 B - 0%
testBuildSize 0 B 0 B 0 B - -
testBuildSbAddonsSize 0 B 0 B 0 B - -
testBuildSbCommonSize 0 B 0 B 0 B - -
testBuildSbManagerSize 0 B 0 B 0 B - -
testBuildSbPreviewSize 0 B 0 B 0 B - -
testBuildStaticSize 0 B 0 B 0 B - -
testBuildPrebuildSize 0 B 0 B 0 B - -
testBuildPreviewSize 0 B 0 B 0 B - -
name before after diff z %
createTime 23.1s 23s -85ms 1.38 -0.4%
generateTime 22.5s 19.1s -3s -414ms -0.79 -17.9%
initTime 17.9s 13.6s -4s -274ms -1.39 🔰-31.2%
buildTime 7.4s 8.5s 1.1s -0.23 13.4%
testBuildTime 0ms 0ms 0ms - -
devPreviewResponsive 6.4s 6.1s -253ms 0.68 -4.1%
devManagerResponsive 4.3s 3.8s -520ms 0.61 -13.4%
devManagerHeaderVisible 673ms 580ms -93ms 0.11 -16%
devManagerIndexVisible 709ms 753ms 44ms 1.45 🔺5.8%
devStoryVisibleUncached 836ms 1.1s 306ms 0.42 26.8%
devStoryVisible 708ms 607ms -101ms -0.19 -16.6%
devAutodocsVisible 555ms 508ms -47ms -0.17 -9.3%
devMDXVisible 511ms 507ms -4ms -0.18 -0.8%
buildManagerHeaderVisible 692ms 749ms 57ms 2.19 🔺7.6%
buildManagerIndexVisible 713ms 770ms 57ms 2.13 🔺7.4%
buildStoryVisible 682ms 718ms 36ms 1.84 🔺5%
buildAutodocsVisible 582ms 548ms -34ms 1.15 -6.2%
buildMDXVisible 458ms 529ms 71ms 1.18 13.4%

Greptile Summary

Enhanced external Storybook composition by implementing index merging functionality to correctly display story paths in mobile view.

  • Added combineIndexes function in code/core/src/manager/components/mobile/navigation/MobileNavigation.tsx to merge root and external ref indexes
  • Modified useFullStoryName hook to use combined indexes for proper story path resolution
  • Added null safety checks and proper type handling for external Storybook refs
  • Fixed composition failures by ensuring external story IDs are included in index lookup

Copy link
Contributor

@greptile-apps greptile-apps bot left a 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, 2 comment(s)
Edit PR Review Bot Settings | Greptile

Comment on lines +27 to +31
Object.values(refs).forEach((ref) => {
if (ref.index) {
Object.assign(combinedIndex, ref.index);
}
});
Copy link
Contributor

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 ref.index is modified during iteration - consider using Object.entries and destructuring for safer iteration

Comment on lines +53 to +59
while (
node &&
'parent' in node &&
node.parent &&
combinedIndex[node.parent] &&
fullStoryName.length < 24
) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: check node.parent type explicitly since it could be undefined from external sources

@jsingh0026 jsingh0026 changed the title fix: add external Storybook entries to index fix: include external Storybook entries for full story name retrieval Oct 25, 2024
@shilman shilman changed the title fix: include external Storybook entries for full story name retrieval Composition: Fix composed story search Oct 28, 2024
Copy link

nx-cloud bot commented Nov 5, 2024

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 39601d1. 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 target

Sent with 💌 from NxCloud.

Copy link
Member

@shilman shilman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jsingh0026 thank you so much for this PR! can we please add an automated test or two to check the new functionality? 🙏

Copy link
Member

@yannbf yannbf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for the fix @jsingh0026! I added some tests to make sure we don't regress.

@yannbf yannbf merged commit 9955a0b into storybookjs:next Nov 15, 2024
54 of 56 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Storybook Composition Fails When Composing a Valid External Storybook
3 participants