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.
Adds
preserveLocalState:'smart'
option.When enabled, components local state will be preserved, except if the initialisation code of their declaration (appears to) have changed, based on static code analysis. AFAICT this is similar to what React Fast Refresh does with
useState
.This option decides whether to preserve state or not at the individual variable level. This is different from React, that resets the whole state if any of them changes.
To try the option
Open the browser. Change the
src/routes/index.svelte
file (or anything you want, really) and note effect on HMR.Discussion
Reset whole state instead of individual variables?
Should we reset the state of the whole component (all variables) as soon as any one of them is reset? (Side note: if we ever get to preserve child components state, this means they would get reset too when a parent's state is reset.)
More aggressive intention detection?
Should we reset a variable for any assignment to it that happens at the root of the init function (but not in reactive expressions)?
For example, this would reset
foo
(even though the declaration has not changed):=>