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

Cannot properly destroy component after changing slotted node #5879

Closed
iltimasd opened this issue Jan 12, 2021 · 4 comments
Closed

Cannot properly destroy component after changing slotted node #5879

iltimasd opened this issue Jan 12, 2021 · 4 comments

Comments

@iltimasd
Copy link

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 REPL@3.31.2):

  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.

@pushkine
Copy link
Contributor

pushkine commented Jan 18, 2021

The text is a node on its own and rewriting h1.textContent replaces that node with another

Svelte cannot workaround the user replacing nodes, it could at best in dev mode warn that the node went missing

For your specific use case you can get the node reference by calling h1.firstChild

@stale
Copy link

stale bot commented Jun 26, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale-bot label Jun 26, 2021
@stale stale bot removed the stale-bot label Jun 26, 2021
@stale stale bot removed the stale-bot label Jun 27, 2021
@stale
Copy link

stale bot commented Dec 24, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@dummdidumm
Copy link
Member

Closing this due to #6910 which silences the error - that said, as pointed out manual manipulation of the DOM is almost always the wrong solution and can lead to errors like this. Svelte should be in control of manipulating the DOM.

@dummdidumm dummdidumm closed this as not planned Won't fix, can't repro, duplicate, stale Nov 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants