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

bug: cannot clone contents of rendered<template> elements #5979

Open
3 tasks done
nwhittaker opened this issue Sep 6, 2024 · 1 comment
Open
3 tasks done

bug: cannot clone contents of rendered<template> elements #5979

nwhittaker opened this issue Sep 6, 2024 · 1 comment
Labels
Bug: Validated This PR or Issue is verified to be a bug within Stencil

Comments

@nwhittaker
Copy link

nwhittaker commented Sep 6, 2024

Prerequisites

Stencil Version

4.21.0

Current Behavior

When rendering a <template> element inside a component, the template's subtree is appended to the <template> element. As a result, it is not possible to clone the template's contents with the standard approach of cloning its content document fragment1.

const contentClone = someTemplateElement.content.cloneNode(true);

In the rendered DOM, you can see the template's child node is a sibling to the template's document fragment instead of contained within the fragment:

Screenshot 2024-09-06 at 6 50 37 PM

Expected Behavior

The content document fragment can be cloned with the usual caveats around event handlers still applying. In the rendered DOM, the template's subtree is instead appended to the template's content document fragment:

Screenshot 2024-09-06 at 6 49 33 PM

System Info

System: node 20.17.0
    Platform: darwin (23.6.0)
   CPU Model: Apple M1 Max (10 cpus)
    Compiler: ~/sandbox/stencil-component/node_modules/@stencil/core/compiler/stencil.js
       Build: 1724698030
     Stencil: 4.21.0 🐷
  TypeScript: 5.5.3
      Rollup: 2.56.3
      Parse5: 7.1.2
      jQuery: 4.0.0-pre
      Terser: 5.31.1

Steps to Reproduce

  1. Clone https://github.com/nwhittaker/stencil-component.git
  2. Check out the @stencil-core/component-template-el branch
  3. Run npm i
  4. Run npm start
  5. Use dev tools to inspect the <template> element within the <my-component> shadow-root.

Code Reproduction URL

https://github.com/nwhittaker/stencil-component/tree/%40stencil-core/component-template-el

Additional Information

Older, related issue: #1169.

Footnotes

  1. https://developer.mozilla.org/en-US/docs/Web/API/HTMLTemplateElement/content#examples

@ionitron-bot ionitron-bot bot added the triage label Sep 6, 2024
@tanner-reits
Copy link
Member

@nwhittaker Looks like there is definitely something wrong here. We'll get this ingested in our backlog. Thanks!

@tanner-reits tanner-reits added Bug: Validated This PR or Issue is verified to be a bug within Stencil and removed triage labels Sep 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug: Validated This PR or Issue is verified to be a bug within Stencil
Projects
None yet
Development

No branches or pull requests

2 participants