-
Notifications
You must be signed in to change notification settings - Fork 8
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
When stacking modals, the previous ones get re-created, and lose their states. #24
Comments
If you could create a Svelte REPL showing this behaviour that would be very helpful. Internal state should be kept (ie variables), but since openModal is a function call, I’m curious how you’re updating those props? |
https://svelte.dev/repl/639f50925bd44794bbedce29d1161d45?version=3.49.0 REALLY ugly, but does the trick. Click the button, then click 'click first' -> 'open next' -> 'just close me'. This will reset the state of the first modal. |
Great, thank you! I'll take a look at this tonight. |
FWIW, the issue is, exported prop states reset to their initial value when opening the modal. You can work around it by storing the exported props as local variables in the component, but that's messy, it may be that the modals store needs to listen for those changes and update accordingly, just speculation, using workaround for now. |
Hm I see. Is it unreasonable to use a store for the prop that gets mutated? Like so: https://svelte.dev/repl/086aafb9027a4c8393c56130440bce74?version=3.49.0 This is the logic for applying the props to the modals. |
You would think the diff algo on the array wouldn't re-render / mutate the props for each modal. I know for actions there are hooks to see when values are updated, I am surprised we can't do the same for the generic component, because ideally, we could listen for changes on the components props, and update our spread values. |
I've been stuck on a similar bug for two days, and I thought this issue was the culprit (i.e. mutation of modals/isOpen causing spurious component rebuilds). I no longer believe that is the case. For posterity, here's what I found. My logical structure: ModalComponent1 => StatefulComponent => ModalComponent2 Dismissing ModalComponent2 (a confirmation dialog) was discarding the state of StatefulComponent. There were two fixes needed:
I still haven't completely fixed my bug (I have at least one more spurious rebuild), but I've at least convinced myself that this issue is not causing it, despite initial appearances. |
...and setting |
Going over this again as I work on #36 and seeing if anything has changed with Svelte 5.
|
Describe the bug
A clear and concise description of what the bug is.
When opening a modal over another modal, the previous modal gets recreated even though the only change is isOpen prop. This causes it to lose it's state and reset back to default, which is not optimal when doing something like 'Settings page -> Prompt' because the settings page will reset it's state.
Reproduction
Provide a reproduction URL or steps to reproduce. If a report is vague and no reproduction is provided within a reasonable time-frame, the issue will be closed.
Create a modal w/ a prop, change the prop at runtime, open a modal over the previous one, then close the new modal, the prop will reset to default value.
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: