-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
[BUGFIX] Shadow DOM support — {{#in-element}} with ShadowRoot/DocumentFragment and declarative shadow DOM via compiler
#21217
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
Open
Copilot
wants to merge
15
commits into
main
Choose a base branch
from
copilot/quest-proper-shadowdom-support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
00d644e
Initial plan
Copilot 6f7260d
feat: Add Shadow DOM support for in-element and declarative shadow DOM
Copilot ae24ef8
fix: apply Prettier formatting to new test files
Copilot 69f7254
refactor: extract shadow root tests to in-element-shadow-root.ts and …
Copilot 9870259
refactor: address review feedback on in-element-shadow-root.ts and ad…
Copilot 81a7992
fix: reuse existing open shadow root on re-render when component root…
Copilot de3e085
refactor: improve closeElement comment and add conditional shadow DOM…
Copilot 0fd2b32
feat: compiler-based declarative shadow DOM support via ShadowRoot wi…
Copilot 2290f16
fix: remove unnecessary type assertion flagged by ESLint
Copilot a6d35d0
fix: address PR review comments - remove unnecessary cast and fix vac…
Copilot 15154be
plan: fix prettier lint and remove AI slop guards from ShadowDOMSuite…
Copilot 05dbbb1
fix: remove unnecessary Shadow DOM environment guards from ShadowDOMS…
Copilot b0fcb47
fix: remove dead @tracked property from Counter; add round-trip test …
Copilot afb21ff
test: add @tracked-owned counter test for shadow root re-render (no r…
Copilot 689ee5d
test: add sibling shadow root components re-render isolation test usi…
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
164 changes: 164 additions & 0 deletions
164
packages/@glimmer-workspace/integration-tests/lib/suites/in-element-document-fragment.ts
NullVoxPopuli marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,164 @@ | ||
| import { RenderTest } from '../render-test'; | ||
| import { test } from '../test-decorator'; | ||
|
|
||
| export class InElementDocumentFragmentSuite extends RenderTest { | ||
| static suiteName = '#in-element (DocumentFragment)'; | ||
|
|
||
| @test | ||
| 'Renders curlies into a detached DocumentFragment'() { | ||
| const fragment = document.createDocumentFragment(); | ||
|
|
||
| this.render('{{#in-element this.fragment}}[{{this.foo}}]{{/in-element}}', { | ||
| fragment, | ||
| foo: 'Hello Fragment!', | ||
| }); | ||
|
|
||
| this.assert.strictEqual( | ||
| fragment.textContent, | ||
| '[Hello Fragment!]', | ||
| 'content rendered in document fragment' | ||
| ); | ||
| this.assertHTML('<!---->'); | ||
| this.assertStableRerender(); | ||
|
|
||
| this.rerender({ foo: 'Updated!' }); | ||
| this.assert.strictEqual( | ||
| fragment.textContent, | ||
| '[Updated!]', | ||
| 'content updated in document fragment' | ||
| ); | ||
| this.assertHTML('<!---->'); | ||
|
|
||
| this.rerender({ foo: 'Hello Fragment!' }); | ||
| this.assert.strictEqual( | ||
| fragment.textContent, | ||
| '[Hello Fragment!]', | ||
| 'content reverted in document fragment' | ||
| ); | ||
| this.assertHTML('<!---->'); | ||
| } | ||
|
|
||
| @test | ||
| 'Renders curlies into a template.content fragment'() { | ||
| const templateEl = document.createElement('template'); | ||
| const fragment = templateEl.content; | ||
|
|
||
| this.render('{{#in-element this.fragment}}[{{this.foo}}]{{/in-element}}', { | ||
| fragment, | ||
| foo: 'Hello Template Content!', | ||
| }); | ||
|
|
||
| this.assert.strictEqual( | ||
| fragment.textContent, | ||
| '[Hello Template Content!]', | ||
| 'content rendered in template.content fragment' | ||
| ); | ||
| this.assertHTML('<!---->'); | ||
| this.assertStableRerender(); | ||
|
|
||
| this.rerender({ foo: 'Updated!' }); | ||
| this.assert.strictEqual( | ||
| fragment.textContent, | ||
| '[Updated!]', | ||
| 'content updated in template.content fragment' | ||
| ); | ||
| this.assertHTML('<!---->'); | ||
|
|
||
| this.rerender({ foo: 'Hello Template Content!' }); | ||
| this.assert.strictEqual( | ||
| fragment.textContent, | ||
| '[Hello Template Content!]', | ||
| 'content reverted in template.content fragment' | ||
| ); | ||
| this.assertHTML('<!---->'); | ||
| } | ||
|
|
||
| @test | ||
| 'Renders elements into a fragment that is later attached to the DOM'() { | ||
| const fragment = document.createDocumentFragment(); | ||
| const container = document.createElement('div'); | ||
|
|
||
| this.render('{{#in-element this.fragment}}<p id="frag-p">{{this.message}}</p>{{/in-element}}', { | ||
| fragment, | ||
| message: 'in fragment', | ||
| }); | ||
|
|
||
| this.assert.strictEqual( | ||
| fragment.querySelector('#frag-p')?.textContent, | ||
| 'in fragment', | ||
| 'content rendered in detached fragment' | ||
| ); | ||
| this.assertHTML('<!---->'); | ||
|
|
||
| // Attach fragment's children to the DOM | ||
| container.appendChild(fragment); | ||
| this.assert.strictEqual( | ||
| container.querySelector('#frag-p')?.textContent, | ||
| 'in fragment', | ||
| 'content is in the DOM after fragment is appended' | ||
| ); | ||
| // Fragment itself is now empty (children moved to container) | ||
| this.assert.strictEqual(fragment.childNodes.length, 0, 'fragment is empty after append'); | ||
| } | ||
|
|
||
| @test | ||
| 'Multiple in-element calls to the same DocumentFragment'() { | ||
| const fragment = document.createDocumentFragment(); | ||
|
|
||
| this.render( | ||
| '{{#in-element this.fragment}}[{{this.foo}}]{{/in-element}}' + | ||
| '{{#in-element this.fragment insertBefore=null}}[{{this.bar}}]{{/in-element}}', | ||
| { | ||
| fragment, | ||
| foo: 'first', | ||
| bar: 'second', | ||
| } | ||
| ); | ||
|
|
||
| this.assert.ok(fragment.textContent?.includes('[first]'), 'first block present in fragment'); | ||
| this.assert.ok(fragment.textContent?.includes('[second]'), 'second block present in fragment'); | ||
| this.assertHTML('<!----><!---->'); | ||
| this.assertStableRerender(); | ||
|
|
||
| this.rerender({ foo: 'updated-first', bar: 'updated-second' }); | ||
| this.assert.ok( | ||
| fragment.textContent?.includes('[updated-first]'), | ||
| 'first block updated in fragment' | ||
| ); | ||
| this.assert.ok( | ||
| fragment.textContent?.includes('[updated-second]'), | ||
| 'second block updated in fragment' | ||
| ); | ||
| this.assertHTML('<!----><!---->'); | ||
| } | ||
|
|
||
| @test | ||
| 'Multiple in-element calls to the same DocumentFragment with insertBefore=null'() { | ||
| const fragment = document.createDocumentFragment(); | ||
|
|
||
| this.render( | ||
| '{{#in-element this.fragment insertBefore=null}}<p id="a">{{this.foo}}</p>{{/in-element}}' + | ||
| '{{#in-element this.fragment insertBefore=null}}<p id="b">{{this.bar}}</p>{{/in-element}}', | ||
| { | ||
| fragment, | ||
| foo: 'first', | ||
| bar: 'second', | ||
| } | ||
| ); | ||
|
|
||
| // Use childNodes to query into the fragment since querySelector doesn't work on detached fragment nodes in all browsers | ||
| const nodes = Array.from(fragment.childNodes); | ||
| const pA = nodes.find((n) => (n as Element).id === 'a') as HTMLElement | undefined; | ||
| const pB = nodes.find((n) => (n as Element).id === 'b') as HTMLElement | undefined; | ||
|
|
||
| this.assert.strictEqual(pA?.textContent, 'first', 'first block appended to fragment'); | ||
| this.assert.strictEqual(pB?.textContent, 'second', 'second block appended to fragment'); | ||
| this.assertHTML('<!----><!---->'); | ||
| this.assertStableRerender(); | ||
|
|
||
| this.rerender({ foo: 'updated-first', bar: 'updated-second' }); | ||
| this.assert.strictEqual(pA?.textContent, 'updated-first', 'first block updated in fragment'); | ||
| this.assert.strictEqual(pB?.textContent, 'updated-second', 'second block updated in fragment'); | ||
| this.assertHTML('<!----><!---->'); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think these tests are all good