-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Hooks for granular HMR support #2377
Comments
Thanks, this is very useful. The Yep, One thing I haven't wrapped my head round is if there are any subtle timing considerations around |
I think the proposed The only thing I forgot mention in the OP is... |
Yep, no reason why not |
Couple of things here are very useful/desirable in live cases too:
If for some reason one or both of these are not surfaced as part of the public api, then to have them unofficially available would be very much appreciated, pretty please |
Any news on this issue? |
Using webpack I get sapper-dev-client.js errors on Edit: this is when using the Sapper template which sets hotReload: false and links to this issue. |
if clone sapper template webpack then run from command to start dev mod: Maybe update template a hotfix, but write note somehow so everyone can temporary avoid error until hotreload work in v3 ? |
I ask because this issue is referenced in sapper-template: https://github.com/sveltejs/sapper-template/blob/23b93f2c12dd387de62385bfafdaa89cd5f90430/webpack.config.js#L27 It seems like either: (1) the issue should be re-opened; (2) sapper-template comments should be updated to refer to a different blocking issue or explanation; or (3) hot-reload should be re-enabled. |
@mdempsky There is #3632 that is currently opened and tracks HMR support generally. The Sapper template should probably be updated. You can make a PR if you feel like it. There's no official HMR support for Svelte 3 yet, but I've got a prototype that's been doing pretty well. You can find links to all my relevant plugins & templates in this readme. This implementation is experimental because it relies on Svelte's internal APIs, and so it breaks sometimes with new versions of Svelte (currently the case with 3.16 unfortunately... fix is coming!). Some of the hooks needed to fix this were addressed by this issue, and work on the rest in ongoing. |
I think the FAQ needs to be updated: https://github.com/sveltejs/svelte/wiki/FAQ#why-isnt-hot-module-reloading-working |
Follow up to recent conversation on discord regarding v3 support for HMR.
Let me list out the steps we need for a successful hot reload, and then maybe we can discuss if the core needs to change, or whether we can just monkey-patch stuff.
I'm going to gloss over the component resolution part, as I think we already have that handled in the v2 HMR code.
These steps happen when a hot reload process starts:
Step 1
Get the current state of the component and keep it somewhere.
Looks like
component.$$.ctx
gives us the whole state.However, seems like it also returns computed properties, along with handlers and bindings?
Can we work out a way to just get the props (exported or otherwise)?
Step 2
Get the position in the DOM where the component is mounted
We normally add a comment marker just above the component, and store a reference to that comment node.
I think this can be achieved by the compiler using
mount_component_dev
.mount_component_dev
would first callmount_component
, and then store a reference totarget
andanchor
on$$
.Step 3
Destroy the old component
This can be easily achieved using
component.$destroy()
.We don't need any changes to support this.
Step 4
Render updated component in place of the old component
Here, we can mount the new component with
mount_component_dev
, using thetarget
andanchor
we collected on Step 2.Step 5
Apply state from old component on to the new component
This I'm not sure at all.
We need to find a way to set the state.
Then we need to ensure that all computeds are up to date.
Will calling
$$.update()
re-run the computations?I'll need your help/direction on step 1 and step 5.
I think I can do a PR for Step 2 and Step 4
The text was updated successfully, but these errors were encountered: