-
Notifications
You must be signed in to change notification settings - Fork 106
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
Long reload time and huge number of network requests when modify the files of stories. #87
Comments
Because of the vite's |
This could maybe be improved if Storybook delivered npm packages for addons that were already run through Rollup or some sort of bundler that only generated one single file... but the general weakness for Vite vs Storybook is the number of requests that the browser has to make. Vite should have added cache headers to all the files, to let the browser skip some of the heavy lifting. Usually, it should handle around 500 requests without a problem, but more than that, and things start to become sluggish. Workflow-wise, I recommend making as few changes to the stories as possible, and doing most of the changes in the components - then you get hot reloading, which improves the developer experience a lot. |
@ThinCats Your workaround is really good. Here's mine What should we look out for with this workaround? |
I have a very large project and noticed the same speed problems. That being said the problem of having a large module count is being exasperated by the storybook server itself. It's using the I did a little testing by modifying the server-init file in storybook/core-server and it's 2x faster to load 1600 modules when using spdy with storybook than it is with the current server implementation. I think it might be wise to see if we can get them to change. |
I guess
would help. All of these things have to be implemented in Storybook core. |
After converting our project and stories to vite I've noticed very long load times. It seems to be rebuilding vite cache for eveything. I can see |
I'm building a series of wrapped components on https://github.com/ant-design/ant-design. I encountered a huge loading time preboundling consumption, the iframe Vite hosted keeps reloading times and times. Is there any progress on large-scale components developing experience improvement? |
I've found that adding my stories glob as |
There is work ongoing right now to address #87 (comment).
Hang in there, things will improve a lot in storybook 7! We're working on getting the vite builder running with it, and we'll announce when there's an alpha version that you can try out. It will probably be in the next few weeks or so. |
The GIF above may suggest that a solution has been found but it has not. Here's what I tried : TL; DR subscribe to this issue and wait 🔔 |
@jjpxiii you're right that it can take some time for Vite to start up, and it is something I hope to spend more time investigating after 7.0 is released. If you are already using the 7.0 beta and experiencing long load times, there are some things you can do to investigate:
I hope some of these tips can help tide you over until we can spend more time to improve Vite startup performance in Storybook. |
Well, thanks for this great answer Ian, I wish I had complained earlier because this led to some huge improvements ! Yesterday morning, with SB 6.5.13 and Vite 4, the cold start took something between 55s and 1 minute. Preview time was between 9 and 10 seconds.
From your answer :
Thanks again Ian, you've been really helpful for us and I hope for everyone who'll stumble on this thread 🤩 |
Background
When diving into the example project (https://github.com/eirslett/storybook-builder-vite/tree/main/packages/example-react), I found that the page will have a long loading time when I modify the stories.
Using the devtools power by Chrome, you can see that there will be more than 500 network requests if the iframe is reloaded, and the number of requests will increase a lot with the addition of addons, which affects the development experience.
Trace
After debug, it was found that the
storybook addons
were imported using the absolute path in the vite-app.js generated by this builder.These absolute paths seem to confuse vite's auto dependency discovery (see vitejs/vite#1571 (comment)), resulting in the inability to bundle the
storybook addons
as external dependencies, which has a large number of internal package references.The related code is located in codegen-iframe-script.js, the
configEntries
here contains the user configuration and configuration injected by addons. It would be better to treat those injected configs to be external dependencies.Workaround
I still don't find a better way to solve this problem. But there is a workaround without modifying the builder's source code.
In the project's
.storybook/main.js
, manually writing a vite plugin to replace all the import path which are external dependencies invite-app.js
. At the same time, the builder's default configuration foroptimizeDeps.include
is replaced, because most of them will not be used.Note: This vite plugin is still experimental, and many edge cases are not considered.
After the optimization, only 90 network requests are required for one reload.
The external dependencies in vite-app.js are also bundled correctly.
Reproduction Repo
Slow loading repo (copied from example-react): https://github.com/ThinCats/storybook-builder-vite-reproduce-slow-reload/tree/main/packages/react-slow-reload
Workaround Modified repo: https://github.com/ThinCats/storybook-builder-vite-reproduce-slow-reload/tree/main/packages/react-slow-reload-workaround
The text was updated successfully, but these errors were encountered: