Custom elements with disconnectedCallback error
See original GitHub issueI have a drag item which contains a custom element (sl-button-group to be specific) and when I start dragging, it emits an error when running its disconnect logic.
Error
Uncaught TypeError: Cannot read property 'removeEventListener' of undefined at HTMLElement.disconnectedCallback
Code
disconnectedCallback() {
this.buttonGroup.removeEventListener('sl-focus', this.handleFocus);
this.buttonGroup.removeEventListener('sl-blur', this.handleBlur);
}
It seems that by the time this callback is fired, svelte-dnd-action has already removed its corresponding node from the DOM, causing the reference error. Is there a known workaround for this sort of thing?
Thanks!
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (9 by maintainers)
Top Results From Across the Web
Using custom elements - Web Components | MDN
disconnectedCallback : Invoked each time the custom element is disconnected from the document's DOM. adoptedCallback : Invoked each time the ...
Read more >custom-elements/disconnected-callbacks.html - external/w3c ...
'Removing a custom element from ' + documentName + ' must enqueue and invoke disconnectedCallback');. promise_test(function () {.
Read more >Failed to construct 'CustomElement' error when JavaScript file ...
The constructor for a custom element is not supposed to read or write ... to check for this, or undo changes in a...
Read more >Error in safari · Issue #8 · ungap/custom-elements-builtin
Hello! We are trying to use custom elements with this library in safari. We are trying to extends another custom element create and...
Read more >Custom elements - The Modern JavaScript Tutorial
We can create custom HTML elements, described by our class, ... times if an element is repeatedly added/removed) } disconnectedCallback() ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

You closed it as I was writing a similar comment 😄 the original comment below. pls let me know if I can help further.
looks like they use stencil. I think the ref on the child div in this line gets confused.
I think you’re exactly right. I’m running into a similar issue when trying to call a method on one of the shoelace components in
onMountbut it’s throwing an error because a ref is undefined. Hopefully I’ll get to the bottom of it. Thanks anyway for the help.