Skip to content

Commit 92d2498

Browse files
hawkgsamishne
authored andcommitted
feat(core): add host node to DeferBlockData (#66546)
Add the host/container comment node to the `DeferBlockData`. This node can be used as a `@defer` block locator in the DOM tree in the absence of root nodes. PR Close #66546
1 parent 5dd17d7 commit 92d2498

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

packages/core/src/render3/util/defer.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import {assertLView} from '../assert';
2727
import {collectNativeNodes} from '../collect_native_nodes';
2828
import {getLContext} from '../context_discovery';
2929
import {CONTAINER_HEADER_OFFSET, NATIVE} from '../interfaces/container';
30-
import {INJECTOR, LView, TVIEW} from '../interfaces/view';
30+
import {HOST, INJECTOR, LView, TVIEW} from '../interfaces/view';
3131
import {getNativeByTNode} from './view_utils';
3232

3333
/** Retrieved information about a `@defer` block. */
@@ -65,6 +65,9 @@ export interface DeferBlockData {
6565
/** Stringified version of the block's triggers. */
6666
triggers: string[];
6767

68+
/** The comment host/container node next to which all of the root nodes are rendered. */
69+
hostNode: Node;
70+
6871
/** Element root nodes that are currently being shown in the block. */
6972
rootNodes: Node[];
7073
}
@@ -156,6 +159,7 @@ function findDeferBlocks(node: Node, lView: LView, results: DeferBlockData[]) {
156159
minimumTime: tDetails.placeholderBlockConfig?.[MINIMUM_SLOT] ?? null,
157160
},
158161
triggers: tDetails.debug?.triggers ? Array.from(tDetails.debug.triggers).sort() : [],
162+
hostNode: details.lContainer[HOST] as Node,
159163
rootNodes,
160164
};
161165

packages/core/test/acceptance/defer_utils_spec.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,26 @@ describe('@defer debugging utilities', () => {
301301
await block.render(DeferBlockState.Complete);
302302
});
303303

304+
it('should return the host comment node of the currently-rendered block', () => {
305+
@Component({
306+
template: `
307+
@defer (when false) {
308+
Loaded
309+
}
310+
`,
311+
})
312+
class App {}
313+
314+
const fixture = TestBed.createComponent(App);
315+
fixture.detectChanges();
316+
317+
const results = getDeferBlocks(fixture.nativeElement);
318+
319+
expect(results.length).toBe(1);
320+
expect(results[0].hostNode).toBeTruthy();
321+
expect(stringifyNodes([results[0].hostNode])).toEqual(['Comment(container)']);
322+
});
323+
304324
function stringifyNodes(nodes: Node[]): string[] {
305325
return nodes.map((node) => {
306326
switch (node.nodeType) {

0 commit comments

Comments
 (0)