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

Disable HMR for web-components projects #372

Merged
merged 2 commits into from
May 9, 2022
Merged

Conversation

IanVS
Copy link
Member

@IanVS IanVS commented May 8, 2022

Fixes #370.

When using storyStoreV7, we configure HMR to swap out the importFn when stories change. However, this breaks web-components projects (see https://github.com/storybookjs/storybook/tree/master/app/web-components#setup-page-reload-via-hmr).

So, instead, this change checks if the framework is web-components and if so, refreshes the page instead of performing an HMR. It's still pretty quick, and not a full page reload.

You can test this out by starting up our lit-ts example (which I've configured to use storyStoreV7 now), open the story, and save the component or story file. It shouldn't blow up anymore.

One bummer is that MDX files also no longer HMR, though technically they could. But I can't find a way to detect which part of the importFn changed, in order to determine whether to HMR or not, and it's safer to just avoid it for all stories when using web-components.

@IanVS IanVS requested a review from joshwooding May 8, 2022 03:03
return `
if (import.meta.hot) {
import.meta.hot.accept((newModule) => {
const currentLocationHref = window.location.href;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we change this to import.meta.hot.decline() ? https://vitejs.dev/guide/api-hmr.html#hot-decline

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 I did a little benchmarking, and using decline is indeed a little faster. It was consistently taking 0.75 sec, vs 0.7 - 1.0 the other way I had it.

@IanVS IanVS requested a review from joshwooding May 9, 2022 01:27
@IanVS IanVS merged commit 7e5af52 into main May 9, 2022
@IanVS IanVS deleted the no-hmr-web-components branch May 9, 2022 20:19
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] storyStoreV7 is not compatible with framework: "@storybook/web-components"
2 participants