fix for ekhaled/svelte-hot-loader#10 #44
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
See ekhaled/svelte-hot-loader#10 for a bit of background.
The problem was...
While components were wrapped up in a proxy on initial load, after a hot reload only the instances were re-rendered. The wrapped component was never exported.
This works fine for nested components. But, for top-level components, it caused webpack to update its reference of the component to the unwrapped component.
When the top-level component was being mounted later on, using
new Component
, the unwrapped component was mounted.The unwrapped component has no idea how to handle hot reloads... therefore it wasn't responding to HMR updates.
This PR fixes the immediate problem.
But it has opened my eyes to problems that I might have to tackle in the future.
For example:
When a new component comes in via hot reload, it's proxy needs to update it's pointers to the raw component's static properties, and static methods.
Right now these pointers/references are directed to the original.
For now, I think it's ok to expect people to do a full reload if they modify static properties and/or methods of a component.