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

What should adoptNode return for a DocumentFragment with a non-null host? #930

Closed
twilco opened this issue Nov 25, 2020 · 2 comments
Closed

Comments

@twilco
Copy link

twilco commented Nov 25, 2020

https://dom.spec.whatwg.org/#dom-document-adoptnode

Step 3 of the adoptNode algorithm states:

If node is a DocumentFragment node whose host is non-null, then return.

I'm assuming this means return nothing (null), where the other cases are either throwing a DOMException or returning a Node.

However, this is contrary to the Document interface IDL, which is:

[CEReactions] Node adoptNode(Node node);

instead of:

[CEReactions] Node? adoptNode(Node node);


Given this:

<html>
<body>
<script>
  const createTemplateElement = (doc) => {
    let template = doc.createElement('template')
    let p = doc.createElement('p')
    p.appendChild(doc.createTextNode('hello'))
    template.appendChild(p)
    return template
  }

  let newDoc = document.implementation.createHTMLDocument()
  newDoc.body.appendChild(createTemplateElement(newDoc))
  let template = newDoc.getElementsByTagName('template')[0]

  // `template.content` is a `DocumentFragment` with a non-null host (the host is the <template>)
  // <template> creation steps from https://html.spec.whatwg.org/multipage/scripting.html#the-template-element:
  //   1. Let doc be the template element's node document's appropriate template contents owner document.
  //   2. Create a DocumentFragment object whose node document is doc and host is the template element.
  //   3. Set the template element's template contents to the newly created DocumentFragment object.
  console.log(document.adoptNode(template.content))
</script>
</body>
</html>

Firefox, Chromium, and Safari all returned the DocumentFragment from adoptNode.

@annevk
Copy link
Member

annevk commented Dec 1, 2020

This is a duplicate of #813. Help with verifying the fix in #819 would be appreciated.

@annevk annevk closed this as completed Dec 1, 2020
@twilco
Copy link
Author

twilco commented Dec 1, 2020

Wow, I did search before creating this issue...not sure how I missed that! Thanks, I'll check out the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants