sveltejs / svelte-devtools

A browser extension to inspect Svelte application by extending your browser devtools capabilities
https://chromewebstore.google.com/detail/svelte-devtools/kfidecgcdjjfpeckbblhmfkhmlgecoff
MIT License
1.45k stars 77 forks source link

Calling "component.$destroy()" will throw an error if the component does not have a parent #40

Closed wtachau closed 3 years ago

wtachau commented 3 years ago

Describe the bug My understanding is that the code here is designed to remove the Svelte node from the tree when component.$destroy() is called. This line is throwing an error for me in the case where the node doesn't have a parent, because it has been created with the new Component({ target: <domNode>}, { ... }) syntax.

To Reproduce Steps to reproduce the behavior:

  1. Create a new component:
    // Test.svelte
    <div>test</div>
  2. Create it programmatically, then destroy it

    // App.svelte
    onMount(() => {
    let div = document.createElement("div");  
    div.id = "bug_example";
    
    let component = new Test({ target: div });
    
    document.body.appendChild(div);
    
    component.$destroy();
    }
  3. You will get something like image image

Expected behavior I believe all that needs to be done is to return early if node.parent is null.

Environment

Additional context This has been a great tool so far! Let me know how else I can help.