Skip to content

Core: Fix cyclical dependency in core addons#31750

Merged
JReinhold merged 5 commits into
nextfrom
jeppe/fix-preview-api-bicycle
Jun 12, 2025
Merged

Core: Fix cyclical dependency in core addons#31750
JReinhold merged 5 commits into
nextfrom
jeppe/fix-preview-api-bicycle

Conversation

@JReinhold

@JReinhold JReinhold commented Jun 11, 2025

Copy link
Copy Markdown
Contributor

Closes #31573

What I did

  • Changed core addons to be imported relatively instead of via an entry point. that way, they become part of the preview-api bundle instead of a separate thing. the separate entry point was causing a cyclical dependency, storybook/preview-api -> storybook/highlight/preview -> storybook/preview-api
  • Stopped producing these /preview entry points, as they weren't actually useful for anything. They are automatically applied in the Storybook runtime as well as in portable stories, implicitly via setProjectAnnotations().

As discussed with @kasperpeulen, @yannbf, @ndelangen.

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

This section is mandatory for all contributions. If you believe no manual test is necessary, please state so explicitly. Thanks!

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-storybook/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 pull request has been released as version 0.0.0-pr-31750-sha-3896d4de. Try it out in a new sandbox by running npx storybook@0.0.0-pr-31750-sha-3896d4de sandbox or in an existing project with npx storybook@0.0.0-pr-31750-sha-3896d4de upgrade.

More information
Published version 0.0.0-pr-31750-sha-3896d4de
Triggered by @JReinhold
Repository storybookjs/storybook
Branch jeppe/fix-preview-api-bicycle
Commit 3896d4de
Datetime Wed Jun 11 13:52:41 UTC 2025 (1749649961)
Workflow run 15586796328

To request a new release of this pull request, mention the @storybookjs/core team.

core team members can create a new canary release here or locally with gh workflow run --repo storybookjs/storybook canary-release-pr.yml --field pr=31750

Greptile Summary

Resolves critical cyclical dependency issue in Storybook's core addons by restructuring how preview APIs are bundled and imported.

  • Changed addon imports to use relative paths instead of entry points in code/core/src/csf/core-annotations.ts
  • Removed separate /preview entry points from code/core/package.json for various addons (backgrounds, measure, outline, etc.)
  • Removed empty index files from multiple addons in code/core/src/ (backgrounds, outline, measure, component-testing)
  • Modified code/core/scripts/entries.ts and dts.ts to remove preview entries from external dependencies
  • Functionality now handled implicitly via setProjectAnnotations(), fixing Metro bundler crashes in React Native

@JReinhold JReinhold requested a review from Copilot June 11, 2025 13:52
@JReinhold JReinhold added bug core ci:normal Run our default set of CI jobs (choose this for most PRs). labels Jun 11, 2025
@JReinhold JReinhold self-assigned this Jun 11, 2025

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes a cyclical dependency issue in core addons by removing empty exports and outdated module mappings while updating import paths.

  • Removed now-unneeded files and exports for outline, measure, and component-testing.
  • Updated import paths in csf/core-annotations to use relative references.
  • Cleaned up configuration entries in the scripts and package.json files to eliminate obsolete alias mappings.

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.

Show a summary per file
File Description
code/core/src/outline/index.ts Removed empty export to eliminate an unnecessary module.
code/core/src/measure/index.ts Removed empty export to eliminate an unnecessary module.
code/core/src/csf/core-annotations.ts Updated import paths from absolute to relative to reduce coupling.
code/core/src/component-testing/index.ts Removed an empty module to resolve cyclical dependency.
code/core/src/backgrounds/index.ts Removed empty export to resolve unused alias.
code/core/scripts/entries.ts Removed definitions for removed modules to avoid dangling references.
code/core/scripts/dts.ts Cleaned up type definition mappings corresponding to removed modules.
code/core/package.json Removed outdated alias mappings to reflect module removals.
Comments suppressed due to low confidence (2)

code/core/package.json:86

  • The removal of legacy alias mappings for modules such as backgrounds, measure, and outline may affect external consumers. It is recommended to update the migration documentation to clearly state these breaking changes.
"./internal/backgrounds": {

code/core/scripts/entries.ts:22

  • Removing these module definitions is key to fixing the cyclical dependency, but please ensure that any dependent tests or consumers are updated or notified, as this may be a breaking change.
define('src/backgrounds/index.ts', ['browser', 'node'], true, ['react'], [], [], true),

@JReinhold JReinhold added the patch:yes Bugfix & documentation PR that need to be picked to main branch label Jun 11, 2025
@JReinhold

Copy link
Copy Markdown
Contributor Author

@dannyhw can you check if this canary fixes the cyclical issue?
If so, I'll try to patch this back to 9.0.

@nx-cloud

nx-cloud Bot commented Jun 11, 2025

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit d051121.

Command Status Duration Result
nx run-many -t build --parallel=3 ✅ Succeeded 1m 13s View ↗

☁️ Nx Cloud last updated this comment at 2025-06-11 19:07:17 UTC

@JReinhold JReinhold marked this pull request as ready for review June 11, 2025 14:03
@JReinhold JReinhold requested a review from ndelangen June 11, 2025 14:03
@storybook-app-bot

storybook-app-bot Bot commented Jun 11, 2025

Copy link
Copy Markdown

Package Benchmarks

Commit: d051121, ran on 11 June 2025 at 19:13:12 UTC

The following packages have significant changes to their size or dependencies:

storybook

Before After Difference
Dependency count 49 49 0
Self size 31.88 MB 31.85 MB 🎉 -38 KB 🎉
Dependency size 17.41 MB 17.41 MB 0 B
Bundle Size Analyzer Link Link

sb

Before After Difference
Dependency count 50 50 0
Self size 1 KB 1 KB 0 B
Dependency size 49.29 MB 49.25 MB 🎉 -38 KB 🎉
Bundle Size Analyzer Link Link

@storybook/cli

Before After Difference
Dependency count 216 216 0
Self size 582 KB 582 KB 0 B
Dependency size 94.66 MB 94.57 MB 🎉 -95 KB 🎉
Bundle Size Analyzer Link Link

@storybook/codemod

Before After Difference
Dependency count 185 185 0
Self size 31 KB 31 KB 0 B
Dependency size 78.74 MB 78.70 MB 🎉 -38 KB 🎉
Bundle Size Analyzer Link Link

create-storybook

Before After Difference
Dependency count 1 1 0
Self size 12.53 MB 12.47 MB 🎉 -58 KB 🎉
Dependency size 98 KB 98 KB 0 B
Bundle Size Analyzer Link Link

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

8 files reviewed, no comments
Edit PR Review Bot Settings | Greptile

Comment thread code/core/scripts/dts.ts Outdated
Comment thread code/core/scripts/dts.ts Outdated
@JReinhold JReinhold merged commit 16a316c into next Jun 12, 2025
57 checks passed
@JReinhold JReinhold deleted the jeppe/fix-preview-api-bicycle branch June 12, 2025 07:19
@github-actions github-actions Bot mentioned this pull request Jun 12, 2025
14 tasks
JReinhold added a commit that referenced this pull request Jun 12, 2025
Core: Fix cyclical dependency in core addons
(cherry picked from commit 16a316c)
@github-actions github-actions Bot added the patch:done Patch/release PRs already cherry-picked to main/release branch label Jun 12, 2025
@dannyhw

dannyhw commented Jun 12, 2025

Copy link
Copy Markdown
Member

Hey @JReinhold Sorry I couldn't test the other day had a lot going on. Unfortunately react native actions was actually using the actions/preview entrypoint to setup actions, maybe there is a way around this but I would need some help to figure that out.

edit:

still looking into this, the main thing currently is it just breaking the build but I need to see if I can just remove that part

Regarding the react compiler, it is still erroring and I still need to comment out the core annotations to get things to work, one thing I noticed though is that if I just comment out the core annotations in the list even without removing the import it works.

Yeah right now I can't seem to get the react native actions addon to work :/ my workaround now is to just duplicate the actions annotations code to react native

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug ci:normal Run our default set of CI jobs (choose this for most PRs). core patch:done Patch/release PRs already cherry-picked to main/release branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: v9 cyclic dependency in storybook/preview causes metro to crash when react compiler is enabled

5 participants