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

Svelte 5 Components Rendered After Destruction #488

Open
pingu-codes opened this issue Nov 25, 2024 · 2 comments
Open

Svelte 5 Components Rendered After Destruction #488

pingu-codes opened this issue Nov 25, 2024 · 2 comments

Comments

@pingu-codes
Copy link
Contributor

This error occurs when multiple x/y components are rendered then destroyed/unmounted for new components.

The error is caused by @unovis/ts attempting to render destroyed components in updateContainer. The error itself is Node.appendChild: Argument 1 is not an object. in the re-insertion loop within updateContainer:

  // Re-insert elements to the DOM
for (const c of this.components) {
    this.element.appendChild(c.element)
}

I believe this occurs due to svelte 5's deep reactivity once again. If you have more then one x/y component the first component is destroyed / unmounted and the component.destroyed function is called, this triggers the updateContainer typescript function with one component still remaining, while this is occuring the other component is destroyed but is still present in the config.components array, therefore this loop attempts to append an undefined object.

The fix for this as far as my testing is doing config.components = config.components?.filter((c) => !c.isDestroyed()); before calling updateContainer.

The other problem is the component lifecycle action's destroy function is called before the line.svelte onDestroy callback is called. Since the onDestroy callback is responsible for marking the component as destroyed the lifecycle action doesn't remove the destroyed component.

@lee00678
Copy link
Collaborator

@pingu-codes do you want to add these updates in your existing PR #487?

@pingu-codes
Copy link
Contributor Author

I've added it in!

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