-
-
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
Snippets using props will error if rendered outside the component after its unmounted #14878
Comments
This is the issue with setting state in an effect: it can get out of sync. In this case you are setting the snippet to null too late so for a split second the component unmount, the prop became null and the snippet is still rendered. You can technically fix this by setting the snippet to null before changing the route but i don't know if it's feasible in your project. |
Yeah, the issue is when you're setting the props for So, either what @paoloricciuti recommended to set the snippet before the route change, or the following solutions: Update {#snippet myHeaderSnippet()}
{data?.text}
{/snippet} The second issue is that you have a memory leak in the component that you're setting the That needs to be released when the component is destroyed. E.g. So once that is solved, you can first unload the component and then on the next To unload a component, just set I created a common function You could also pass in a callback property to each page component and let it fire when it's being destroyed and then the root component would load the next page component. It does require an additional prop to be passed in to each component. Next tick definitely seems more elegant. |
Describe the bug
We're trying to upgrade to Svelte 5 at my company, but we ran into this bug when trying to migrate our portals implementation.
In short, the goal with portals is to allow a child component to insert one of its elements into an element of another component via an imported reference, instead of prop drilling. I'll spare you the other details and get right into the issue.
This is the bug:
First we have a file with an exported object containing a snippet:
And our
App.svelte
renders this snippet, as well as containing a dynamic component:Then we have a component that sets
headerPortal.snippet
. The snippet has to contain a reference to a prop (2-levels deep):If we use our dynamic component in
App.svelte
to mount this one, and then unmount it, then we will get an error:Reproduction
Bug REPL
Open the console and click "Show page 2" and then "Show page 1". You should see an error, similar to the one above.
https://svelte.dev/playground/1175b32356ca41d4953c2896f71871ac?version=5.16.0
I haven't been able to reduce it any further.
Workaround REPL
https://svelte.dev/playground/c214d0b1cb5c4e6cba00c85a3704391f?version=5.16.0
It makes a change to the router:
It's a complete hack. I expected
{#key someKey }
to work the same way, but it doesn't. It has to be a keyed each blockLogs
No response
System Info
Severity
annoyance
The text was updated successfully, but these errors were encountered: