Revert "Do not optimize storybook packages (#323)" #328
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #327
This reverts #323.
While I still think it would be great to avoid including deps in our
optimizeDeps.include
as much as we can, it turns out that it's still necessary for a few reasons.storybook-dark-mode
) publishes a cjs package thatrequire()
s from a storybook package that has been excluded from optimization, then esbuild seems to not replace that require at build time as it normally would.(https://github.com/evanw/esbuild/blob/master/CHANGELOG.md#01229)
This results in the situation outlined in #327.
Even after I removed all the packages from
exclude
, if I didn't add them back to theinclude
list, there were multiple page refreshes while the app booted the first time, while vite found new deps and reloaded the page. That would only happen once until the cache was populated, which isn't horrible, but it's not a great experience either.Lastly, if I tried to keep the logic which prevented optimizing the storybook framework package, I ended up with react hook warnings, which usually means that multiple versions of react are loaded in the page. That was the final straw which made me decide to completely revert the PR and go back to what we had before. When I did that, my storybook worked just fine.
I think we can take another stab at avoiding optimization another time, but we've already made a lot of changes to this package lately and it doesn't seem to be causing problems like I initially suspected in #305.