Skip to content
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

support preserving state of children component when updating parent component #40

Open
bloody-ux opened this issue Sep 10, 2021 · 1 comment

Comments

@bloody-ux
Copy link

Describe the issue

When updating the code of parent component, the local state of children component is lost(with preserveLocalState: true). While the local state of parent component can be kept.

In below screenshot, the local state of Counter will reset to default when App is change. Because in svelte-hmr, when parent component is changed, it will recreate itself(can keep local state) and it's children components(without keeping local state).

image

Expected behavior

The local state of children is kept as well when updating parent component, just like react does. It's annoying when debugging between parent component and children components if the local state is lost.

And developer may think it's a bug of HMR because of the inconsistence.

@rixo
Copy link
Collaborator

rixo commented Dec 10, 2021

Hey! Some progress update...

I have studied how feasible this could be, and came up with some (dirty/incomplete) POC here: https://github.com/rixo/svelte-hmr/blob/poc-preserve-children/PRESERVE_CHILDREN_STATE.md#demo.

However, this is probably not something that can be done sanely by externally patching Svelte's compiler output like this package currently does. So HMR will have to be integrated into the compiler first. I have started looking into it, but that's probably still quite a long shot...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants