-
-
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
Call to destroy() with invalid argument causes error in runtime #7836
Comments
@Conduitry <script>
import Child from './Child.svelte';
let checked = true;
</script>
<label>
<input type=checkbox bind:checked />
Show child
</label>
{#if checked}<Child />{/if} <!-- Child.svelte -->
<script>
import { onMount } from 'svelte';
let node;
onMount(() => node.remove());
</script>
Child component
<div bind:this={node}>
Detached node
</div> Uncheck the checkbox to cause the child component to be destroyed. Related or duplicate issues: |
Aside from checking export function detach(node: ChildNode) {
node.remove();
} Most if not all relevant APIs should return |
Just checked out the code and noticed that the |
Closing as there's no reproduction that isn't a "I removed this manually which I shouldn't have", and #6910 should silence the symptom. |
@dummdidumm |
@dummdidumm As an issue author, I can confirm that in my case there was no third-party library involved. In my case, the issue occurs during page navigation in SvelteKit application. While it seems to not cause any significant issues in my case - the fact of its existence is here and the code itself has no guarantee that it will work properly in runtime since it has two levels of chaining. It is also possible to avoid the issue by using optional chaining (which already has quite a good support level): export function detach(node: Node) {
node?.parentNode?.removeChild(node);
} To be true I can't understand the reasons for not including this trivial update which may improve code stability. There may be some performance reasons of course, but I'm not sure if there will be any measurable impact. |
Describe the bug
I've started receiving reports from Bugsnag for my application:
Application is built using SvelteKit, but the issue is in Svelte.
The issue seems to happen immediately after navigation between application's pages.
goto()
withreplaceState: true
is used. From my understanding (which I can't prove) at this moment Svelte cleans up DOM from the previous page's nodes in order to start rendering the new page.Stack traces from the reports clearly points to the
detach()
function:svelte/src/runtime/internal/dom.ts
Lines 200 to 202 in ed078e3
From the code of the function and the text of the error, it really looks like in some cases some wrong value is being passed to the
destroy()
. While the root cause of the issue is unknown to me - it seems quite obvious that the error in this particular method can be fixed by simple check thatnode.parentNode
is actually available:This check was already available in this method in the past as part of #6204, but was reverted by #6290.
The issue was also reported in #6313, but was closed.
Reproduction
I was unable to reproduce the issue by myself yet. The information given above came from Bugsnag reports and my own analysis of Svelte sources.
Logs
System Info
For now, I have reports about 10 incidents, all of them from Chrome on Android. Chrome versions vary from 80 to 104.
Svelte v3.49.0 is used in the application.
Severity
annoyance
The text was updated successfully, but these errors were encountered: