question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Custom elements with disconnectedCallback error

See original GitHub issue

I 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:closed
  • Created 3 years ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
isaacHagoelcommented, Feb 5, 2021

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.

      <div ref={el => (this.buttonGroup = el)} part="base" class="button-group" aria-label={this.label}>
0reactions
danny-andrewscommented, Feb 5, 2021

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 onMount but it’s throwing an error because a ref is undefined. Hopefully I’ll get to the bottom of it. Thanks anyway for the help.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found