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

[Bug] storyStoreV7 is not compatible with framework: "@storybook/web-components" #370

Closed
1 task
boeto opened this issue May 7, 2022 · 2 comments · Fixed by #372
Closed
1 task

[Bug] storyStoreV7 is not compatible with framework: "@storybook/web-components" #370

boeto opened this issue May 7, 2022 · 2 comments · Fixed by #372
Labels
bug Something isn't working

Comments

@boeto
Copy link

boeto commented May 7, 2022

What version of vite are you using?

2.9.7

System info and storybook versions

Environment Info:

System:
OS: macOS 10.15.7
CPU: (12) x64 Intel(R) Core(TM) i7-8700B CPU @ 3.20GHz
Binaries:
Node: 16.14.0 - ~/.nvm/versions/node/v16.14.0/bin/node
Yarn: 3.2.0 - ~/.nvm/versions/node/v16.14.0/bin/yarn
npm: 8.3.1 - ~/.nvm/versions/node/v16.14.0/bin/npm
Browsers:
Chrome: 101.0.4951.54
Firefox: 100.0
Safari: 15.0
npmPackages:
@storybook/addon-actions: ^6.4.22 => 6.4.22
@storybook/addon-essentials: ^6.4.22 => 6.4.22
@storybook/addon-links: ^6.4.22 => 6.4.22
@storybook/builder-vite: ^0.1.33 => 0.1.33
@storybook/web-components: ^6.4.22 => 6.4.22

Describe the Bug

when not set storyStoreV7:

update /src/my-element.ts , got the Log : [vite] page reload src/my-element.ts

The expected result should be: [vite] hmr update /src/my-element.ts

when set storyStoreV7: true,

update /src/my-element.ts, then got the error Log:

Failed to execute 'define' on 'CustomElementRegistry': the name "my-element" has already been used with this registry
Error: Failed to execute 'define' on 'CustomElementRegistry': the name "my-element" has already been used with this registry
    at legacyCustomElement (http://localhost:6008/node_modules/.vite-storybook/deps/lit_decorators_js.js?v=53feff7d:16:25)
    at http://localhost:6008/node_modules/.vite-storybook/deps/lit_decorators_js.js?v=53feff7d:29:99
    at __decorateClass (http://localhost:6008/src/my-element.ts?t=1651908414168:7:57)
    at http://localhost:6008/src/my-element.ts?t=1651908414168:50:13

The expected result should be: [vite] hmr update /src/my-element.ts

Link to Minimal Reproducible Example

https://github.com/boeto/test-vite-lit-storybook-story-store-V7

Participation

  • I am willing to submit a pull request for this issue.
@boeto boeto added the bug Something isn't working label May 7, 2022
@IanVS
Copy link
Member

IanVS commented May 8, 2022

Web components cannot use HMR, according to https://github.com/storybookjs/storybook/tree/master/app/web-components#setup-page-reload-via-hmr. I'll take a look at the storyStoreV7 issue.

@IanVS IanVS changed the title [Bug] HMR & storyStoreV7 is not works with framework: "@storybook/web-components" [Bug] storyStoreV7 is not compatible with framework: "@storybook/web-components" May 8, 2022
@boeto
Copy link
Author

boeto commented May 8, 2022

@IanVS LGTM 🎉 Thank you !!!

@IanVS IanVS closed this as completed in #372 May 9, 2022
IanVS added a commit that referenced this issue May 9, 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants