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

[ShadyDOM] slot.insertBefore throws NotFoundError #96

Open
2 of 6 tasks
michael-england opened this issue Mar 28, 2019 · 4 comments
Open
2 of 6 tasks

[ShadyDOM] slot.insertBefore throws NotFoundError #96

michael-england opened this issue Mar 28, 2019 · 4 comments

Comments

@michael-england
Copy link

Description

Error thrown when calling insertBefore on a slot

Live Demo

https://jsfiddle.net/michael_england/uqvrcnks/

Steps to Reproduce

  1. Create my-element with the following:
customElements.define('my-element', class extends HTMLElement {
  constructor() {
    super();

    this.attachShadow({mode: 'open'});
    this.shadowRoot.innerHTML = '<button>click me!</button><slot><div /></slot>';
    
    var slot = this.shadowRoot.querySelector('slot');
    var count = 0;
    this.shadowRoot.querySelector('button').addEventListener('click', function () {
    	count++;
    
      var div1 = document.createElement('div');
      div1.innerHTML = count + ": first div";
      slot.insertBefore(div1, slot.firstChild);
      
      var div2 = document.createElement('div');
      div2.innerHTML = count + ": second div";
      slot.insertBefore(div2, slot.firstChild);
    });
  }
});
  1. Append my-element to document.body
  2. Click the click me! button
  3. Note only one element is inserted into the slot rather than two.

Expected Results

No error is thrown, code continues to run. In the case of this example, two divs should be added to the slot as children.

Actual Results

Error is thrown, code stops executing. In the case of this example, only one div is added to the slot as a child.

Browsers Affected

  • Chrome
  • Firefox
  • Edge
  • Safari 9
  • Safari 8
  • IE 11

Versions

  • webcomponents: v2.2.7
@dfreedm dfreedm transferred this issue from webcomponents/shadydom Jun 7, 2019
@dfreedm dfreedm changed the title slot.insertBefore throws NotFoundError [ShadyDOM] slot.insertBefore throws NotFoundError Jun 12, 2019
@dfreedm
Copy link
Contributor

dfreedm commented Jun 13, 2019

Duplicate of #144

@dfreedm dfreedm marked this as a duplicate of #144 Jun 13, 2019
@dfreedm dfreedm closed this as completed Jun 13, 2019
@dfreedm dfreedm reopened this Jun 13, 2019
@dfreedm
Copy link
Contributor

dfreedm commented Jun 13, 2019

Actually, this is probably about the <slot> element not existing in the composed DOM.

@benoitjchevalier
Copy link

benoitjchevalier commented Sep 23, 2020

@dfreedm do you have a sense of the scale of the fix? Happy to do a PR or fork but this doesn't look like a straightforward fix

Edit: Actually might have been fixed by #266 ?

@stale
Copy link

stale bot commented Sep 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.

@stale stale bot added the wontfix label Sep 24, 2021
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