Skip to content
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

Revert "Do not optimize storybook packages (#323)" #328

Merged
merged 1 commit into from
Apr 10, 2022
Merged

Conversation

IanVS
Copy link
Member

@IanVS IanVS commented Apr 10, 2022

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.

  1. If an addon (like storybook-dark-mode) publishes a cjs package that require()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.

Some background: esbuild's bundler emulates a CommonJS environment. The bundling process replaces the literal syntax require() with the referenced module at compile-time.

(https://github.com/evanw/esbuild/blob/master/CHANGELOG.md#01229)

This results in the situation outlined in #327.

  1. Even after I removed all the packages from exclude, if I didn't add them back to the include 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.

  2. 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.

@IanVS IanVS requested review from eirslett and joshwooding April 10, 2022 04:06
@IanVS IanVS force-pushed the back-to-prebundling branch from ccdbb6e to 4cc1fbd Compare April 10, 2022 15:00
@IanVS IanVS merged commit 49fc2bb into main Apr 10, 2022
@IanVS IanVS deleted the back-to-prebundling branch April 10, 2022 15:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug] Dynamic require of "@storybook/addons" is not supported
2 participants