Repository navigation
React: Prebundle react/jsx-runtime to avoid a reload when plugins import it - #36682
Conversation
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configuration
📒 Files selected for processing (2)
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review. WalkthroughThe React renderer preset now includes ChangesReact Vite dependency optimization
Priority: ➖ Normal Severity of issue fixed: Medium Merge Risk: ⚪ Minimal · up to The change covers the reported late-import scenario, and no actionable merge risk remains. ✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Package BenchmarksCommit: The following packages have significant changes to their size or dependencies:
|
| Before | After | Difference | |
|---|---|---|---|
| Dependency count | 1 | 1 | 0 |
| Self size | 206 KB | 195 KB | 🎉 -11 KB 🎉 |
| Dependency size | 28 KB | 28 KB | 0 B |
| Bundle Size Analyzer | Link | Link |
storybook
| Before | After | Difference | |
|---|---|---|---|
| Dependency count | 73 | 73 | 0 |
| Self size | 21.64 MB | 21.62 MB | 🎉 -20 KB 🎉 |
| Dependency size | 31.24 MB | 31.24 MB | 0 B |
| Bundle Size Analyzer | Link | Link |
@storybook/angular-vite
| Before | After | Difference | |
|---|---|---|---|
| Dependency count | 20 | 20 | 0 |
| Self size | 23.42 MB | 23.42 MB | 🚨 +3 KB 🚨 |
| Dependency size | 11.56 MB | 11.55 MB | 🎉 -11 KB 🎉 |
| Bundle Size Analyzer | Link | Link |
@storybook/html-vite
| Before | After | Difference | |
|---|---|---|---|
| Dependency count | 4 | 4 | 0 |
| Self size | 22 KB | 22 KB | 0 B |
| Dependency size | 269 KB | 259 KB | 🎉 -11 KB 🎉 |
| Bundle Size Analyzer | Link | Link |
@storybook/nextjs-vite
| Before | After | Difference | |
|---|---|---|---|
| Dependency count | 100 | 100 | 0 |
| Self size | 1.42 MB | 1.42 MB | 0 B |
| Dependency size | 24.16 MB | 24.15 MB | 🎉 -11 KB 🎉 |
| Bundle Size Analyzer | Link | Link |
@storybook/preact-vite
| Before | After | Difference | |
|---|---|---|---|
| Dependency count | 4 | 4 | 0 |
| Self size | 12 KB | 12 KB | 🚨 +12 B 🚨 |
| Dependency size | 287 KB | 276 KB | 🎉 -11 KB 🎉 |
| Bundle Size Analyzer | Link | Link |
@storybook/react-native-web-vite
| Before | After | Difference | |
|---|---|---|---|
| Dependency count | 117 | 120 | 🚨 +3 🚨 |
| Self size | 104 KB | 29 KB | 🎉 -75 KB 🎉 |
| Dependency size | 26.10 MB | 26.28 MB | 🚨 +187 KB 🚨 |
| Bundle Size Analyzer | Link | Link |
@storybook/react-vite
| Before | After | Difference | |
|---|---|---|---|
| Dependency count | 78 | 78 | 0 |
| Self size | 33 KB | 33 KB | 🚨 +18 B 🚨 |
| Dependency size | 21.27 MB | 21.26 MB | 🎉 -11 KB 🎉 |
| Bundle Size Analyzer | Link | Link |
@storybook/svelte-vite
| Before | After | Difference | |
|---|---|---|---|
| Dependency count | 12 | 12 | 0 |
| Self size | 56 KB | 56 KB | 0 B |
| Dependency size | 30.73 MB | 30.72 MB | 🎉 -11 KB 🎉 |
| Bundle Size Analyzer | Link | Link |
@storybook/sveltekit
| Before | After | Difference | |
|---|---|---|---|
| Dependency count | 13 | 13 | 0 |
| Self size | 58 KB | 58 KB | 🎉 -24 B 🎉 |
| Dependency size | 30.79 MB | 30.77 MB | 🎉 -11 KB 🎉 |
| Bundle Size Analyzer | Link | Link |
@storybook/tanstack-react
| Before | After | Difference | |
|---|---|---|---|
| Dependency count | 79 | 79 | 0 |
| Self size | 124 KB | 124 KB | 🎉 -81 B 🎉 |
| Dependency size | 21.31 MB | 21.30 MB | 🎉 -11 KB 🎉 |
| Bundle Size Analyzer | Link | Link |
@storybook/vue3-vite
| Before | After | Difference | |
|---|---|---|---|
| Dependency count | 95 | 95 | 0 |
| Self size | 32 KB | 32 KB | 0 B |
| Dependency size | 18.77 MB | 18.74 MB | 🎉 -31 KB 🎉 |
| Bundle Size Analyzer | Link | Link |
@storybook/web-components-vite
| Before | After | Difference | |
|---|---|---|---|
| Dependency count | 6 | 6 | 0 |
| Self size | 19 KB | 19 KB | 0 B |
| Dependency size | 515 KB | 423 KB | 🎉 -92 KB 🎉 |
| Bundle Size Analyzer | Link | Link |
@storybook/cli
| Before | After | Difference | |
|---|---|---|---|
| Dependency count | 179 | 179 | 0 |
| Self size | 872 KB | 863 KB | 🎉 -9 KB 🎉 |
| Dependency size | 87.08 MB | 87.06 MB | 🎉 -21 KB 🎉 |
| Bundle Size Analyzer | Link | Link |
@storybook/codemod
| Before | After | Difference | |
|---|---|---|---|
| Dependency count | 172 | 172 | 0 |
| Self size | 44 KB | 44 KB | 0 B |
| Dependency size | 85.57 MB | 85.55 MB | 🎉 -20 KB 🎉 |
| Bundle Size Analyzer | Link | Link |
create-storybook
| Before | After | Difference | |
|---|---|---|---|
| Dependency count | 74 | 74 | 0 |
| Self size | 1.07 MB | 1.07 MB | 🎉 -633 B 🎉 |
| Dependency size | 52.88 MB | 52.86 MB | 🎉 -20 KB 🎉 |
| Bundle Size Analyzer | node | node |
@storybook/vue3
| Before | After | Difference | |
|---|---|---|---|
| Dependency count | 91 | 91 | 0 |
| Self size | 229 KB | 209 KB | 🎉 -20 KB 🎉 |
| Dependency size | 18.21 MB | 18.21 MB | 0 B |
| Bundle Size Analyzer | Link | Link |
@storybook/web-components
| Before | After | Difference | |
|---|---|---|---|
| Dependency count | 4 | 4 | 0 |
| Self size | 182 KB | 101 KB | 🎉 -81 KB 🎉 |
| Dependency size | 126 KB | 126 KB | 0 B |
| Bundle Size Analyzer | Link | Link |
Closes #36681
What I did
Added
react/jsx-runtimetooptimizeViteDepsin the React renderer preset.Vite plugins such as
vite-plugin-svgremitreact/jsx-runtimeimports while transforming non-JS files. The dependency scan does not run those transforms, so the import is only found while stories are rendering. Vite then re-optimizes React and reloads, and withaddon-vitestthe page ends up with two copies of React (Invalid hook call). This happens on every run with an empty cache, such as CI.@vitejs/plugin-reactand@storybook/addon-docsalready includereact/jsx-runtime, so the bug only shows up when neither is used, for examplenextjs-vitewithout addon-docs. This is the same reasonreact-dom/test-utilsis listed here.I used Claude Code to investigate the cause, build the reproduction and draft this PR. I reviewed the findings and the changes.
Checklist for Contributors
Testing
The changes in this PR are covered in the following automated tests:
Manual testing
npm install && npx playwright install chromium.npm run test-storybook:cold. It fails withdependency optimized: react/jsx-runtimefollowed byInvalid hook call."react/jsx-runtime"tooptimizeViteDepsinnode_modules/@storybook/nextjs-vite/node_modules/@storybook/react/dist/preset.js).npm run test-storybook:coldagain. It passes, and the log no longer showsoptimized dependencies changed. reloading.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-storybook/src/sandbox-templates.tsDeclare whether manual QA will be needed for this PR during the next release, through
qa:neededorqa:skipMake 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 - 🚫 Not run
This PR does not have a canary release associated.
In-repo PRs: add the
ci:canarylabel. Later pushes republish while the label remains.Fork PRs: the label does nothing (a later push must not auto-publish). A maintainer publishes from this repository with Run workflow and the
prinput.branchandshaare optional; if more than one is set, they must be the same commit. The fork author does not need to do anything.