-
Notifications
You must be signed in to change notification settings - Fork 124
feat(react): route element-template background tree via multi-slot #2651
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
base: main
Are you sure you want to change the base?
Changes from all commits
9d0d09c
72db348
24dec8f
c8e4d49
9563659
f1d5971
99a30b4
b295b6e
1c9d75c
ebdef8f
55b44d9
3fb1c6b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
|
|
||
| --- | ||
|
|
||
| No package release is required because this change continues the unpublished Element Template runtime path behind the experimental `experimental_useElementTemplate` flag. The SWC `swc_plugin_element_template` lowering now emits `$0`, `$1`, ... named-slot JSX props instead of `__etSlot(N, ...)` wrapper calls, the background runtime routes inserts/removes off `child.__slotIndex` directly, and the legacy `BackgroundElementTemplateSlot` wrapper + `__etSlot` runtime component are removed. Only internal runtime, transform, fixtures, and tests change — public APIs, package exports, and release-facing defaults are unchanged. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,15 @@ | ||
| Object { | ||
| "stream": Array [ | ||
| 1, | ||
| 4, | ||
| 3, | ||
| "_et_77307_test_2", | ||
| null, | ||
| Array [], | ||
| Array [], | ||
| 3, | ||
| -1, | ||
| 0, | ||
| 4, | ||
| 3, | ||
| 0, | ||
| ], | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,15 @@ | ||
| Object { | ||
| "stream": Array [ | ||
| 1, | ||
| 4, | ||
| 3, | ||
| "_et_f9aab_test_2", | ||
| null, | ||
| Array [], | ||
| Array [], | ||
| 3, | ||
| -3, | ||
| 0, | ||
| 4, | ||
| 3, | ||
| -1, | ||
| ], | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,15 +8,15 @@ Object { | |
| -1, | ||
| ], | ||
| 1, | ||
| 5, | ||
| 4, | ||
| "_et_04991_test_3", | ||
| null, | ||
| Array [], | ||
| Array [], | ||
| 3, | ||
| -3, | ||
| 0, | ||
| 5, | ||
| 4, | ||
| 0, | ||
| ], | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,15 +5,15 @@ Object { | |
| 0, | ||
| "BG", | ||
| 1, | ||
| 10, | ||
| 7, | ||
| "_et_c2579_test_5", | ||
| null, | ||
| Array [], | ||
| Array [], | ||
| 3, | ||
| -4, | ||
| 0, | ||
| 10, | ||
| 7, | ||
| 0, | ||
| ], | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,7 +15,6 @@ import { | |
| import '../../../../../src/element-template/native/index.js'; | ||
| import { | ||
| BackgroundElementTemplateInstance, | ||
| BackgroundElementTemplateSlot, | ||
| BUILTIN_RAW_TEXT_TEMPLATE_KEY, | ||
| } from '../../../../../src/element-template/background/instance.js'; | ||
| import { backgroundElementTemplateInstanceManager } from '../../../../../src/element-template/background/manager.js'; | ||
|
|
@@ -378,11 +377,8 @@ export function runCaseByName(name: string): unknown { | |
| backgroundElementTemplateInstanceManager.nextId = 0; | ||
|
|
||
| const rootInstance = new BackgroundElementTemplateInstance('root'); | ||
| const slot0 = new BackgroundElementTemplateSlot(); | ||
| slot0.setAttribute('id', 0); | ||
| const child = new BackgroundElementTemplateInstance('child'); | ||
| slot0.appendChild(child); | ||
| rootInstance.appendChild(slot0); | ||
| rootInstance.appendChild(child); | ||
|
|
||
| const before = createHydrationTemplate(-1, 'root'); | ||
| const stream = hydrateBackground(before, rootInstance); | ||
|
|
@@ -410,21 +406,15 @@ export function runCaseByName(name: string): unknown { | |
| backgroundElementTemplateInstanceManager.nextId = 0; | ||
|
|
||
| const rootInstance = new BackgroundElementTemplateInstance('root'); | ||
| const slot0 = new BackgroundElementTemplateSlot(); | ||
| slot0.setAttribute('id', 0); | ||
| rootInstance.appendChild(slot0); | ||
|
|
||
| const existing = new BackgroundElementTemplateInstance('existing'); | ||
| slot0.appendChild(existing); | ||
| rootInstance.appendChild(existing); | ||
|
|
||
| const card = new BackgroundElementTemplateInstance('card'); | ||
| card.setAttribute('attributeSlots', [{ id: 'card' }]); | ||
| const cardSlot = new BackgroundElementTemplateSlot(); | ||
| cardSlot.setAttribute('id', 0); | ||
| const text = createTextNode('NEW'); | ||
| cardSlot.appendChild(text); | ||
| card.appendChild(cardSlot); | ||
| slot0.insertBefore(card, existing); | ||
| card.appendChild(text); | ||
| rootInstance.insertBefore(card, existing); | ||
|
|
||
| const beforeExisting = createHydrationChild(-2, 'existing'); | ||
| const beforeRemoved = createHydrationChild(-3, 'removed'); | ||
|
|
@@ -443,11 +433,8 @@ export function runCaseByName(name: string): unknown { | |
| backgroundElementTemplateInstanceManager.nextId = 0; | ||
|
|
||
| const rootInstance = new BackgroundElementTemplateInstance('root'); | ||
| const slot0 = new BackgroundElementTemplateSlot(); | ||
| slot0.setAttribute('id', 0); | ||
| rootInstance.appendChild(slot0); | ||
| const rawText = createTextNode(''); | ||
| slot0.appendChild(rawText); | ||
| rootInstance.appendChild(rawText); | ||
|
|
||
| const before = createHydrationTemplate(-1, 'root', { | ||
| elementSlots: [[createHydrationRawTextChild(3, '')]], | ||
|
|
@@ -467,14 +454,11 @@ export function runCaseByName(name: string): unknown { | |
| backgroundElementTemplateInstanceManager.nextId = 0; | ||
|
|
||
| const rootInstance = new BackgroundElementTemplateInstance('root'); | ||
| const slot0 = new BackgroundElementTemplateSlot(); | ||
| slot0.setAttribute('id', 0); | ||
| rootInstance.appendChild(slot0); | ||
|
|
||
| const rawTextText = createTextNode('bg'); | ||
| const rawTextInstance = new BackgroundElementTemplateInstance(BUILTIN_RAW_TEXT_TEMPLATE_KEY); | ||
| slot0.appendChild(rawTextText); | ||
| slot0.appendChild(rawTextInstance); | ||
| rootInstance.appendChild(rawTextText); | ||
| rootInstance.appendChild(rawTextInstance); | ||
|
|
||
| const beforeExistingString = createHydrationRawTextChild(rawTextText.instanceId, 'bg'); | ||
| const beforeExistingNonString = createHydrationRawTextChild(rawTextInstance.instanceId, 123); | ||
|
|
@@ -500,15 +484,16 @@ export function runCaseByName(name: string): unknown { | |
| backgroundElementTemplateInstanceManager.clear(); | ||
| backgroundElementTemplateInstanceManager.nextId = 0; | ||
|
|
||
| // Background side has children at slot 1 but serialized side only ships | ||
| // slot 0. `slotCount = Math.max(serialized.length, instance.length)` must | ||
| // visit slot 1 too so the background-only child gets reported as an | ||
| // insertion to the main thread. | ||
| const rootInstance = new BackgroundElementTemplateInstance('root'); | ||
| const slot0 = new BackgroundElementTemplateSlot(); | ||
| slot0.setAttribute('id', 0); | ||
| rootInstance.appendChild(slot0); | ||
| const slot1 = new BackgroundElementTemplateSlot(); | ||
| slot1.setAttribute('id', 1); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This fixture name looks stale now. The setup no longer creates any existing background slot entry, so it is not really testing “existing slots” anymore. Can we either rename it or materialize an actual empty/sparse background slot?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Renamed in 1c9d75c to
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Following up — after the rename @upupming noticed offline that the renamed case was now functionally identical to const rootInstance = new BackgroundElementTemplateInstance('root');
const slot1Child = new BackgroundElementTemplateInstance('child');
slot1Child.__slotIndex = 1;
rootInstance.appendChild(slot1Child);
const before = createHydrationTemplate(-1, 'root', { elementSlots: [[]] });Background side has a child at slot 1, serialized only ships slot 0. The hydrate loop now visits slot 1 (background-only) and emits an insertion for the background-only child: Original name preserved, semantic now matches it. |
||
| rootInstance.appendChild(slot1); | ||
|
|
||
| const before = createHydrationTemplate(-1, 'root', { elementSlots: [[], []] }); | ||
| const slot1Child = new BackgroundElementTemplateInstance('child'); | ||
| slot1Child.__slotIndex = 1; | ||
| rootInstance.appendChild(slot1Child); | ||
|
|
||
| const before = createHydrationTemplate(-1, 'root', { elementSlots: [[]] }); | ||
| const stream = hydrateBackground(before, rootInstance); | ||
| return { stream }; | ||
| }); | ||
|
|
@@ -520,9 +505,6 @@ export function runCaseByName(name: string): unknown { | |
| backgroundElementTemplateInstanceManager.nextId = 0; | ||
|
|
||
| const rootInstance = new BackgroundElementTemplateInstance('root'); | ||
| const slot0 = new BackgroundElementTemplateSlot(); | ||
| slot0.setAttribute('id', 0); | ||
| rootInstance.appendChild(slot0); | ||
|
|
||
| const before = createHydrationTemplate(-1, 'root', { elementSlots: [[]] }); | ||
| const stream = hydrateBackground(before, rootInstance); | ||
|
|
@@ -536,16 +518,13 @@ export function runCaseByName(name: string): unknown { | |
| backgroundElementTemplateInstanceManager.nextId = 0; | ||
|
|
||
| const rootInstance = new BackgroundElementTemplateInstance('root'); | ||
| const slot0 = new BackgroundElementTemplateSlot(); | ||
| slot0.setAttribute('id', 0); | ||
| rootInstance.appendChild(slot0); | ||
|
|
||
| const childA = new BackgroundElementTemplateInstance('a'); | ||
| const childB = new BackgroundElementTemplateInstance('b'); | ||
| const childC = new BackgroundElementTemplateInstance('c'); | ||
| slot0.appendChild(childB); | ||
| slot0.appendChild(childA); | ||
| slot0.appendChild(childC); | ||
| rootInstance.appendChild(childB); | ||
| rootInstance.appendChild(childA); | ||
| rootInstance.appendChild(childC); | ||
|
|
||
| const beforeChildA = createHydrationChild(childA.instanceId, 'a'); | ||
| const beforeChildB = createHydrationChild(childB.instanceId, 'b'); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,15 @@ | ||
| Object { | ||
| "stream": Array [], | ||
| "stream": Array [ | ||
| 1, | ||
| 2, | ||
| "child", | ||
| null, | ||
| Array [], | ||
| Array [], | ||
| 3, | ||
| -1, | ||
| 1, | ||
| 2, | ||
| 0, | ||
| ], | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,15 @@ | ||
| Object { | ||
| "stream": Array [ | ||
| 1, | ||
| 3, | ||
| 2, | ||
| "child", | ||
| null, | ||
| Array [], | ||
| Array [], | ||
| 3, | ||
| -1, | ||
| 0, | ||
| 3, | ||
| 2, | ||
| 0, | ||
| ], | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,7 @@ Object { | |
| 3, | ||
| 1, | ||
| 0, | ||
| 3, | ||
| 5, | ||
| 2, | ||
| 4, | ||
| ], | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| Object { | ||
| "stream": Array [ | ||
| 2, | ||
| 4, | ||
| 3, | ||
| 0, | ||
| null, | ||
| 4, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,13 @@ | ||
| Array [ | ||
| 1, | ||
| 4, | ||
| 3, | ||
| "_et_3634f_test_1", | ||
| null, | ||
| Array [], | ||
| Array [], | ||
| 3, | ||
| -3, | ||
| 0, | ||
| 4, | ||
| 3, | ||
| -1, | ||
| ] |
Uh oh!
There was an error while loading. Please reload this page.