-
-
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
Addons, core: Make react
and Storybook packages devDependencies
where possible
#24676
Conversation
@shilman could I get you to run benchmarks for this branch/version? It's largely complete now. We expect unchanged performance and build size, but we expect a noticeable reduction in install size. |
"./manager": "./dist/manager.js", | ||
"./register": "./dist/manager.js", |
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.
manager and preview entries don't need types nor cjs outputs as they are always loaded in the manager or preview in the browser, never directly imported by the user.
"exportEntries": [ | ||
"./src/index.ts" | ||
], | ||
"platform": "browser" | ||
"managerEntries": [ | ||
"./src/manager.tsx" | ||
] |
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.
these new fields are used by addon-bundle.ts
to determine which entry points needs which packages externalized.
exportEntries
are assumed to be imported by users, so they won't have any externalization and they'll keep their d.ts
files
code/addons/docs/src/preset.ts
Outdated
const optimizeDeps = [ | ||
'@mdx-js/react', | ||
'@storybook/addon-docs > acorn-jsx', | ||
'@storybook/addon-docs', | ||
'@storybook/addon-essentials/docs/mdx-react-shim', | ||
'markdown-to-jsx', | ||
]; |
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.
Moved from the Vite builder's default optimization, as that would break if addon-essentials
was installed without react
, which is a valid scenario now.
@shilman benchmark comparisons between I don't know how much of this is noise and how much is actual change. ViteWebpack |
"@testing-library/react": "^11.2.2", | ||
"lodash": "^4.17.21", | ||
"react": "^16.8.0", | ||
"react-dom": "^16.8.0", |
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.
Did you check if the react-dom
dep is needed truly in these addons?
It's not a big deal at all having them as devDependencies of course, no harm to users.
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.
no, I added it as a todo to my cooldown period.
- Remove
react-dom
frompackage.json
s when not needed- Audit dependencies of frameworks+renderers, they might have a lot of unused
@storybook
dependencies we can remove
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.
I only reviewed for perf. I found that the sizes were slightly worse across the board, but not by an amount large enough to block the work. It would be useful to explain why the sizes all increased by a small amount, though, since it's not intuitive to me based on the change.
Works on #24490
TODODocument newoptimizeDeps
preset propertymanager-api
and still have correct types, even though@storybook/types
and@types/react
are not part of the package.What I did
This PR is a retry of #23486 with many non-essential things ignored.
The main purpose of this PR is to minimize the amount of peer dependencies in addons and a few of the core packages, most notably removing
react
as a peer dependency.The way the manager and the preview globalizes a fixed set of dependencies means that these packages don't strictly need the dependencies, as they will be referenced from the global window instead, which our builders ensures. Removing them from peer dependencies mean that users don't need to specify them either.
Having them as devDependencies will however make our (tsup) bundler default to bundle them in, which we don't want. Therefore this PR also introduces a new bundler configuration,
addon-bundle
that makes sure that the globalized packages are externalized (thus the imports are kept intact), so they can be replaced with the global reference when built.A handful of packages like
manager-api
are not usingaddon-bundle
but still need these packages externalized, so they've been added to their bundler configuration manually to ensure that happens.addon-essentials
andaddon-docs
are largely left out of this PR, as tackling them in terms ofreact
requires more work.Checklist for Contributors
Testing
The changes in this PR are covered in the following automated tests:
Manual testing
It's important to test this in the different package manager configuration, npm, yarn, yarn pnp and pnpm and with both builders.
For each configuration and builder:
npx sb@next sandbox
)Testing
addon-essentials
with docsstorybook
andbuild-storybook
and see that it worksTesting
addon-docs
directlyaddon-essentials
withaddon-docs
both inmain.ts
andpackage.json
storybook
andbuild-storybook
and see that it worksTesting
addon-essentials
with docs disabledmdx
glob fromstories
inmain.ts
addon-docs
withaddon-essentails
both inmain.ts
andpackage.json
againreact
andreact-dom
frompackage.json
. You will see an unmet peer deps fromaddon-essentials
, that's okay.docs
inmain.ts
with{ name: '@storybook/addon-essential', options: { docs: false } }
storybook
andbuild-storybook
and see that it works, now without ReactTesting without
addon-essentials
andaddon-docs
addon-docs
withaddon-essentails
both frommain.ts
andpackage.json
againstorybook
andbuild-storybook
and see that it worksDocumentation
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 pull request has been released as version
0.0.0-pr-24676-sha-214a6f84
. Install it by pinning all your Storybook dependencies to that version.More information
0.0.0-pr-24676-sha-214a6f84
experiment-addon-peer-dep
214a6f84
1699442401
)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=24676