-
-
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
Vite: Import preview runtime as ordinary module #29172
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.
LGTM
13 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings
☁️ Nx Cloud ReportCI is running/has finished running commands for commit 558d62d. 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 targetSent with 💌 from NxCloud. |
I suspect we likely won't want to do this for 2 reasons: The first being:
We prebundle, to minimize build-time, and optimize start-up time. And the second being how this would make the vite builder work very differently from how other builders work, which will cause unexpected maintenance problems. |
Did you confirm this locally? The benchmark results are varying very much for my PRs, so I don't know how reliable these numbers are. My expectation would be that there is indeed a very small increase in the cold startup time (because the very first time vite has to process one more file) but afterwards there is a small improvement in the warm startup time (because vite can optimize the import, cache it etc).
Webpack would very much profit from the same optimization. I just don't have the knowledge to do this. From the perspective of a downstream maintainer, this setup is a major headache and definily a source of "unexpected maintenance problems". For nuxt we essentially have 3 dev server running (nuxt, vite, express), all needing to be synchronized in subtitle ways to make the setup work. You might have a look at nuxt-modules/storybook#777 to get a feeling for these problems. |
@tobiasdiez Will look next week what the real perf impact is of this PR. Could you maybe describe explicitly the problem you are facing?
|
Thanks @kasperpeulen for looking into this. If I remember correctly, the problem was a bit vague in the first problem. The I'm not even totally sure the issue is fixed with this PR but in either case it should make the setup simpler and more reliable. |
…preview # Conflicts: # code/builders/builder-vite/package.json # code/builders/builder-vite/src/index.ts
Package BenchmarksCommit: The following packages have significant changes to their size or dependencies:
|
Before | After | Difference | |
---|---|---|---|
Dependency count | 6 | 6 | 0 |
Self size | 468 KB | 434 KB | 🎉 -33 KB 🎉 |
Dependency size | 832 KB | 832 KB | 0 B |
Bundle Size Analyzer | Link | Link |
@storybook/experimental-nextjs-vite
Before | After | Difference | |
---|---|---|---|
Dependency count | 87 | 87 | 0 |
Self size | 231 KB | 231 KB | 0 B |
Dependency size | 31.32 MB | 31.28 MB | 🎉 -33 KB 🎉 |
Bundle Size Analyzer | Link | Link |
@storybook/html-vite
Before | After | Difference | |
---|---|---|---|
Dependency count | 15 | 15 | 0 |
Self size | 5 KB | 5 KB | 0 B |
Dependency size | 1.94 MB | 1.90 MB | 🎉 -33 KB 🎉 |
Bundle Size Analyzer | Link | Link |
@storybook/preact-vite
Before | After | Difference | |
---|---|---|---|
Dependency count | 13 | 13 | 0 |
Self size | 6 KB | 6 KB | 0 B |
Dependency size | 1.34 MB | 1.30 MB | 🎉 -33 KB 🎉 |
Bundle Size Analyzer | Link | Link |
@storybook/react-native-web-vite
Before | After | Difference | |
---|---|---|---|
Dependency count | 102 | 102 | 0 |
Self size | 41 KB | 41 KB | 0 B |
Dependency size | 17.88 MB | 17.85 MB | 🎉 -33 KB 🎉 |
Bundle Size Analyzer | Link | Link |
@storybook/react-vite
Before | After | Difference | |
---|---|---|---|
Dependency count | 87 | 87 | 0 |
Self size | 12 KB | 12 KB | 0 B |
Dependency size | 16.03 MB | 15.99 MB | 🎉 -33 KB 🎉 |
Bundle Size Analyzer | Link | Link |
@storybook/svelte-vite
Before | After | Difference | |
---|---|---|---|
Dependency count | 134 | 134 | 0 |
Self size | 22 KB | 22 KB | 0 B |
Dependency size | 36.40 MB | 36.36 MB | 🎉 -33 KB 🎉 |
Bundle Size Analyzer | Link | Link |
@storybook/sveltekit
Before | After | Difference | |
---|---|---|---|
Dependency count | 142 | 142 | 0 |
Self size | 47 KB | 47 KB | 0 B |
Dependency size | 39.70 MB | 39.66 MB | 🎉 -33 KB 🎉 |
Bundle Size Analyzer | Link | Link |
@storybook/vue3-vite
Before | After | Difference | |
---|---|---|---|
Dependency count | 107 | 107 | 0 |
Self size | 16 KB | 16 KB | 🎉 -16 B 🎉 |
Dependency size | 42.57 MB | 42.54 MB | 🎉 -33 KB 🎉 |
Bundle Size Analyzer | Link | Link |
@storybook/web-components-vite
Before | After | Difference | |
---|---|---|---|
Dependency count | 16 | 16 | 0 |
Self size | 5 KB | 5 KB | 0 B |
Dependency size | 1.97 MB | 1.94 MB | 🎉 -33 KB 🎉 |
Bundle Size Analyzer | Link | Link |
} | ||
|
||
// TODO: In the future, remove this call to make the module side-effect free | ||
setup(); |
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.
Are you not calling this function twice now? Can we not just remove it, now we call it explicitly in codegen-modern-iframe-script.ts?
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 see, we can not remove it because of webpack.
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.
LGTM, one comment
code/core/src/preview/runtime.ts
Outdated
global.addEventListener('error', (args: any) => { | ||
const error = args.error || args; | ||
if (error.fromStorybook) { | ||
global.sendTelemetryError(error); | ||
} | ||
}); | ||
global.addEventListener('unhandledrejection', ({ reason }: any) => { | ||
if (reason.fromStorybook) { | ||
global.sendTelemetryError(reason); | ||
} | ||
}); | ||
} |
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.
Especially those 2 seem problematic, when called twice.
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.
Made sure we only call the listeners once
@kasperpeulen Thanks for the review! |
Closes nuxt-modules/storybook#777.
What I did
Currently, the preview runtime is manually exposed in the builder (in dev mode via
express.static
and in build mode via maual copying).This has several problems:
This PR improves the situation by just importing the preview runtime as an ordinary modue (for the vite builder). So it goes through the vite pipeline just as every other module. As a nice side-effect, express is now no longer needed for the vite builder.
Checklist for Contributors
Testing
The changes in this PR are covered in the following automated tests:
Manual testing
This section is mandatory for all contributions. If you believe no manual test is necessary, please state so explicitly. Thanks!
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
This pull request simplifies the handling of the preview runtime in the Vite builder for Storybook. Key changes include:
These changes aim to streamline the setup, reduce complexity, and improve integration with Vite's build process.