Skip to content

Cannot properly destroy component after changing slotted node #5879

Closed as not planned
@iltimasd

Description

@iltimasd

Describe the bug
Components are unable to destroy properly when component contains a slot whose text was changed via node.textContext. Please refer to REPL link below for repro. This bug/error can prevent further interaction with the Svelte app.

Logs
After destroying component, Svelte throws the following error:

Error:
message: "Uncaught (in promise): Cannot read property 'removeChild' of null"

To Reproduce
https://svelte.dev/repl/f9cc573c14a943098f68964dc5496fd7?version=3.31.2

Expected behavior
This may be an expected behavior of the current version of Svelte, but ideally I would be able to manipulate the DOM within a component and still destroy components in the usual Svelte-y way.

Stacktraces
If you have a stack trace to include, we recommend putting inside a <details> block for the sake of the thread's readability:

Stack trace

Uncaught (in promise) TypeError: Cannot read property 'removeChild' of null
at detach (eval at handle_message (VM950 about:srcdoc:13), :81:25)
at detach_dev (eval at handle_message (VM950 about:srcdoc:13), :344:9)
at Object.destroy [as d] (eval at handle_message (VM950 about:srcdoc:13), :594:23)
at Object.destroy [as d] (eval at handle_message (VM950 about:srcdoc:13), :455:39)
at destroy_component (eval at handle_message (VM950 about:srcdoc:13), :235:40)
at Object.destroy [as d] (eval at handle_message (VM950 about:srcdoc:13), :567:8)
at eval (eval at handle_message (VM950 about:srcdoc:13), :203:31)
at run (eval at handle_message (VM950 about:srcdoc:13), :24:16)
at Array.forEach ()
at run_all (eval at handle_message (VM950 about:srcdoc:13), :30:13)

detach @ VM953:81
detach_dev @ VM953:344
destroy @ VM953:594
destroy @ VM953:455
destroy_component @ VM953:235
destroy @ VM953:567
eval @ VM953:203
run @ VM953:24
run_all @ VM953:30
check_outros @ VM953:184
update @ VM953:696
update @ VM953:169
flush @ VM953:137
Promise.then (async)
schedule_update @ VM953:119
make_dirty @ VM953:245
eval @ VM953:281
click_handler @ VM953:745

Information about your Svelte project:
This is my dev env (but this also happen on [email protected]):

  System:
    OS: macOS Mojave 10.14.6
    CPU: (8) x64 Intel(R) Core(TM) i7-8557U CPU @ 1.70GHz
    Memory: 87.06 MB / 16.00 GB
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 14.15.1 - /usr/local/bin/node
    Yarn: 1.22.4 - /usr/local/bin/yarn
    npm: 6.14.8 - /usr/local/bin/npm
  Browsers:
    Chrome: 87.0.4280.141
    Edge: 87.0.664.75
    Firefox: 81.0.1
    Safari: 13.0.4
  npmPackages:
    rollup: ^2.3.4 => 2.35.1 
    svelte: ^3.31.2 => 3.31.2 

Severity
How severe an issue is this bug to you? Is this annoying, blocking some users, blocking an upgrade or blocking your usage of Svelte entirely?

The bug itself is game-breaking, triggering the bug will stop some, if not all, of the Svelte app. I've refactored to not use slots and to pass in as a variable instead, so at worst the code readability drops a little bit, but there may be more complex/necessary use cases that would be implicated by this bug that I haven't considered.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions