Skip to content

[BUGFIX] {{#in-element}} with DocumentFragment targets - #21551

Open
NullVoxPopuli wants to merge 1 commit into
mainfrom
nvp/in-element-document-fragment
Open

[BUGFIX] {{#in-element}} with DocumentFragment targets#21551
NullVoxPopuli wants to merge 1 commit into
mainfrom
nvp/in-element-document-fragment

Conversation

@NullVoxPopuli

@NullVoxPopuli NullVoxPopuli commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Continuation of:

Which is a continuation of:

This is required to unblock using shadow-dom with out whack hacks.

See:

Demo of this PR working (REPL)

test code for the repl
import Component from '@glimmer/component';
import { trackedObject } from '@ember/reactive/collections';

const state = trackedObject({
  count: 0,
  inc: () => state.count++,
});


const fragment = document.createDocumentFragment();

setInterval(() => {
    console.log(fragment.textContent)
}, 250);

<template>
  check the console 

  <hr>
  as a separate PR we need to make fragments renderable
  today, folks would need a modifier to append the fragment to the DOM, 
  which could cause Glimmer to get confused by someone else managing DOM:
  {{fragment}}

  {{#in-element fragment}}
    text in a fragment
    {{log "in-element body"}}
    {{state.count}}

    <button onclick={{state.inc}}>inc</button>
  {{/in-element}}

  <hr> 
  
  outside the fragement is useful for testing reactivity
  <button onclick={{state.inc}}>inc</button>
</template> 
REPL deploy info

CI run: https://github.com/NullVoxPopuli/limber/actions/runs/31221384086
Preview PR: NullVoxPopuli/limber#2211
REPL with this change: https://test-ember-source-nvp-in-ele.limber-glimdown.pages.dev/

Perf is good.


Out of scope

  • Making fragments renderable as values ({{this.fragment}}) — separate PR, per discussion.
  • Destroying rendered content when the fragment's host is imperatively removed from the DOM. Glimmer doesn't observe external DOM mutation; teardown is driven by template lifecycle (toggling/destroying the {{#in-element}}), which is tested.
  • insertBefore values other than null/undefined (unchanged from Element destinations).

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

📊 Size report

Tarball size1.2 MB1.2 MB

dist/dev   0.06%↑

File Before (Size / Brotli) After (Size / Brotli)
./packages/shared-chunks/api-{hash}.js 26.2 kB / 5.8 kB 3%↑26.8 kB / 3%↑6 kB
./packages/shared-chunks/normalize-{hash}.js 2.2 kB / 617 B 15%↑2.6 kB / 23%↑761 B
./packages/shared-chunks/serialize-{hash}.js 3.6 kB / 1 kB 4%↑3.8 kB / 0.9%↑1.1 kB
Total (Includes all files) 2 MB / 489.8 kB 0.06%↑2.1 MB / 0.07%↑490.2 kB

dist/prod   0.06%↑

File Before (Size / Brotli) After (Size / Brotli)
./packages/shared-chunks/api-{hash}.js 25.7 kB / 5.7 kB 3%↑26.3 kB / 3%↑5.9 kB
./packages/shared-chunks/normalize-{hash}.js 2.2 kB / 617 B 15%↑2.6 kB / 23%↑761 B
./packages/shared-chunks/serialize-{hash}.js 3.6 kB / 1 kB 4%↑3.8 kB / 0.9%↑1 kB
Total (Includes all files) 1.9 MB / 447.2 kB 0.06%↑1.9 MB / 0.07%↑447.5 kB

smoke-tests/v2-app-template/dist   0.1%↑

File Before (Size / Brotli) After (Size / Brotli)
./assets/api-{hash}.js 288.5 kB / 77.8 kB 0.1%↑288.9 kB / -0.08%↓77.7 kB
Total (Includes all files) 340.6 kB / 94.8 kB 0.1%↑341 kB / -0.08%↓94.7 kB

smoke-tests/v2-app-hello-world-template/dist   0.03%↑

File Before (Size / Brotli) After (Size / Brotli)
Total (Includes all files) 132.4 kB / 37 kB 0.03%↑132.5 kB / 0.1%↑37.1 kB

🤖 This report was automatically generated by wyvox/pkg-size

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

someone's editor doesn't strip unneeded invisible characters :P


`{{in-element}}` requires a single positional argument:

- `destinationElement` -- the DOM element to render into. It must exist at the time

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

meaningful change here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"a"

@NullVoxPopuli
NullVoxPopuli force-pushed the nvp/in-element-document-fragment branch from 7c8cb4e to 704c772 Compare August 12, 2026 14:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants