-
Notifications
You must be signed in to change notification settings - Fork 139
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
Issue with Webpack HMR (hot module reloading) #564
Comments
We are using it. Can you give us some more info?
This happens when you try and register the same component twice. I'm thinking this error might be causing the problem where the update can't be applied. Could it be possible that you're executing the |
this is my current setting package.json
webpack.config.js
|
@treshugart you was right. When webpack tried to update the module 'tiny-button', it went through the constructor skate('tiny-button', ...) then registered the component again. |
We just started a new project and it turns out we haven't enabled it yet, so I was wrong. That said, the issue will probably be because the browser keeps an internal registry of all custom elements that have been registered. When the module reloads it causes it to try and register again. What I suggest trying is exporting your Skate definition without registering the component and have a separate file import them and register them. I'm not sure if this will work, though, as I haven't tried it. Unfortunately this is a limitation of custom elements as you can't deregister them. One possible solution is to try and update the definitions in the registry, but I'm not sure I like the idea of them being mutable especially when it's not in the plans of the spec to allow such behaviour. Thoughts? |
I can confirm this is an issue and we want to try and find a way for it to work. There's some challenges, though. Even if we can update definitions, it's hard to know exactly how to update components on the page. For example, if you remove the
Given the Custom Element V1 spec doesn't have a way to re-register modules, the first step in solving this would be to figure out if there's even a workaround for that. From there, we'd have to answer the questions above. For now, though, to get full updates, you'll have to use standard reloading instead of HMR. |
One solution might be to mutate the existing definition. Something like: const OldCtor = window.customElements.get(name);
const NewCtor = Ctor;
if (OldCtor) {
Object.assign(OldCtor, getOwnPropertyDescriptors(NewCtor));
return OldCtor;
} Notes:
I spoke with @lukebatchelor about this IRL and he's going to PoC it in our stack and try to find a working solution for it. We'll keep this issue updated. |
@lukebatchelor can you provide details in how we were to get around this temporarily? |
Temporarily we have separated out the component definition and the actual call to
So that we can import the function to register OR import the definition itself. To use HMR we import the definition and when we register the component, we append a random string to the end of it to make sure it is unique. I will try to get around to taking a look at the above solution today though and see how we go. |
Addressing in #663. |
…name. If a component with the same name has already been registered, Skate will choose a different name and use the unique name. #564
@phamvuau A fix is now in 1.0.0-beta.9: https://github.com/skatejs/skatejs#multiple-component-names-and-hot-module-reloading-aka-webpack-hmr. |
Any recipe to enable Hot Module Replacement in a SkateJS webpack based project ? |
@Toilal have a look at the I think in order to accomplish this you'll have to use If you're building an app, not defining tag names is doable because you'll probably be writing JSX and / or just passing around constructors, as opposed to string tag names. However, it's harder when you're building sharable components as you want to make the available in HTML, which means defining a name. To get around this if you're building components, is to export the constructor from your component and let the consumer manually define them. In your tests, you can define them using Skate's define for HMR while still allowing the consumer to choose the name. |
Is there anyone here using webpack Hot Module Replacement successfully with skatejs components? I currently got this issue.
The text was updated successfully, but these errors were encountered: