-
-
Notifications
You must be signed in to change notification settings - Fork 19
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
WebComponent HMR #26
Comments
Yes, this is the right place. Unfortunately, I have previously tried to fix support for WC myself, got burnt, gave up... iirc the first blocker was that Svelte registers successive versions of a web component under the same tag name, which doesn't go well with the browser... I believe I past this one, but then there were more... The code produced by Svelte for WC is very different from normal components. This is a legitimate request so I'm keeping the issue open, but I have no immediate plan on trying to solve that again, sorry. |
A general solution might be tough to implement for WC, but with the I've been playing around with the web dev server for the past bit, so far implemented it to resolve and return compiled files with just adding the file src as a script tag in html - adding hmr would be great |
Has there been any progress on this? I started seeing hmr-related errors while using the above, vite-plugin-svelte. |
No sorry. WebComponent HMR implementation would be very different from what we already have and, to be honest, it is far from the top of my TODO list... There are a few items to complete support and increase stability before it. |
Also very interested in this. I created Anyway, here's a proof of concept in plain Svelte 4 (if it's helpful)... git clone https://github.com/patricknelson/svelte-v4-custom-elements.git
cd svelte-v4-custom-elements
npm i
npm run dev ... and then a demo of it working with git checkout hmr-via-svelte-retag
npm i In both cases, if you edit |
In Svelte 3 the issue was that it got redeclared over and over. However, in Svelte 4 the issue is that HMR simply doesn't trigger at all. My hunch here is that it's working in |
Another hunch... after some research, it seems that if we can maybe have the compiled Deriving the This may in fact be a Svelte compiler issue but I'm not sure. Maybe the HMR adapter is able to ensure it's proxy is injected above this location? Edit: See also: sveltejs/svelte#8681 (comment) You can also try this yourself by setting import ExampleElement from './lib/ExampleElement.svelte';
import { create_custom_element } from 'svelte/internal';
window.ExampleElement = ExampleElement; // this is now proxied for HMR
window.create_custom_element = create_custom_element; Then later on: customElements.define('native-example-element', create_custom_element(ExampleElement, {}, [], [], false)); |
cc @rixo we cannot redefine the custom-element though, thats not how browsers work. so the best we can achieve would be to have the svelte-hmr proxy working for the svelte component that lives inside the wrapper. As soon as the interface of the custom element changes, you have to do a full reload. (eg adding or removing a prop). |
@dominikg are you addressing me? If so: I understand. 😄 The multiple calls to In fact, that’s how it already works (in So in this case, I’m just addressing the HMR boundary issue (which then cascades to the next issue of multiple definitions, again easily resolved) by just moving the proxy definition up a tad. Does that make sense? |
Also: Presumably this interface never changes (at least during dev runtime). That’s because this is just a wrapper already (both in Am I misunderstanding? |
This might not be the place for this, but it's the only work really out there with Svelte + HMR, so:
Any ideas on how to get the web component output working with HMR? I'm looking at https://open-wc.org/docs/development/hot-module-replacement/ which looks for a
hotReplacedCallback
on the outputted web component.Not particularly familiar with HMR, so any pointers here on how I could implement this would be awesome!
The text was updated successfully, but these errors were encountered: