Skip to content

Commit d0b7593

Browse files
authored
fix(components): report silent limits, fix two notices, add real-app CD tests and an API canary (#380)
Refs #366, #367, #368, #369, #373.
1 parent 85e99ef commit d0b7593

38 files changed

Lines changed: 1033 additions & 84 deletions

‎app/src/__tests__/cd-recording-status.test.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,19 @@ describe('CdRecording status', () => {
110110
expect(live()).toBe('Could not reach the page.');
111111
expect(live()).not.toContain('Cleared');
112112
});
113+
114+
it('notes the classes and instances a recording checked past its caps', async () => {
115+
expect(host().querySelectorAll('.note')).toHaveLength(0);
116+
fixture.componentRef.setInput('page', {
117+
...page(false, 1),
118+
droppedClasses: 905,
119+
droppedHosts: 1,
120+
});
121+
await fixture.whenStable();
122+
const notes = [...host().querySelectorAll('.note')].map((n) => n.textContent!.trim());
123+
expect(notes).toEqual([
124+
'905 more component classes were checked than a recording keeps, so they are left out of these totals.',
125+
'1 component instance was checked past the 2000 a recording counts, so its tree row shows no check count.',
126+
]);
127+
});
113128
});

‎app/src/__tests__/component-tree-defer.test.ts‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,38 @@ describe('defer blocks', () => {
8686
await fixture.whenStable();
8787
expect(row.textContent).toContain('Unknown component');
8888
});
89+
90+
it('shows a + on the count when the page has more blocks than it reported', async () => {
91+
const block = (id: string) => ({
92+
id,
93+
state: 'complete',
94+
hydration: 'not-configured',
95+
triggers: [],
96+
rootIds: [],
97+
});
98+
const page = (deferTruncated?: boolean) => ({
99+
pageId: 'p1',
100+
roots: [{ id: 'c1', name: 'App', tag: 'app-root', children: [] }],
101+
count: 1,
102+
detail: null,
103+
reportedAt: 1000,
104+
deferBlocks: [block('d1'), block('d2')],
105+
...(deferTruncated ? { deferTruncated } : {}),
106+
});
107+
const pill = async (value: unknown) => {
108+
const fixture = TestBed.createComponent(ComponentTree);
109+
fixture.componentRef.setInput('rpc', client({ p1: value }));
110+
for (let i = 0; i < 3; i++) {
111+
await new Promise((resolve) => setTimeout(resolve));
112+
await fixture.whenStable();
113+
}
114+
const text = (fixture.nativeElement as HTMLElement)
115+
.querySelector('#ct-defer-title .pill')!
116+
.textContent!.trim();
117+
fixture.destroy();
118+
return text;
119+
};
120+
expect(await pill(page())).toBe('2');
121+
expect(await pill(page(true))).toBe('2+');
122+
});
89123
});

‎app/src/pages/cd-recording.ts‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ const SHOWN_CYCLES = 30;
4545
what="cycles"
4646
limit="cdCycles"
4747
/>
48+
@for (note of capNotes(); track note) {
49+
<p class="note">{{ note }}</p>
50+
}
4851
@if (slowest().length) {
4952
<div class="cd-grid">
5053
<div>
@@ -253,6 +256,23 @@ export class CdRecording {
253256
[...(this.page()?.components ?? [])].sort((a, b) => b.ms - a.ms).slice(0, SHOWN),
254257
);
255258
readonly latest = computed(() => this.cycles().slice(-SHOWN_CYCLES).reverse());
259+
/** Says when the recording checked more classes or instances than it keeps. */
260+
readonly capNotes = computed(() => {
261+
const classes = this.page()?.droppedClasses ?? 0;
262+
const hosts = this.page()?.droppedHosts ?? 0;
263+
const notes: string[] = [];
264+
if (classes > 0) {
265+
notes.push(
266+
`${classes} more component ${classes === 1 ? 'class was' : 'classes were'} checked than a recording keeps, so ${classes === 1 ? 'it is' : 'they are'} left out of these totals.`,
267+
);
268+
}
269+
if (hosts > 0) {
270+
notes.push(
271+
`${hosts} component ${hosts === 1 ? 'instance was' : 'instances were'} checked past the 2000 a recording counts, so ${hosts === 1 ? 'its tree row shows' : 'their tree rows show'} no check count.`,
272+
);
273+
}
274+
return notes;
275+
});
256276
readonly status = computed(() => {
257277
if (this.message()) return this.message();
258278
const count = this.cycles().length;

‎app/src/pages/component-tree.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ interface Page {
101101
title?: string;
102102
platform?: string;
103103
deferBlocks?: DeferBlock[];
104+
/** The page has more defer blocks than the ones in `deferBlocks`. */
105+
deferTruncated?: boolean;
104106
roots: LiveNode[];
105107
count: number;
106108
truncated?: boolean;
@@ -516,7 +518,8 @@ function bare(name: string): string {
516518
@if (deferBlocks().length) {
517519
<section class="defer" aria-labelledby="ct-defer-title">
518520
<h2 id="ct-defer-title" class="defer-title">
519-
Defer blocks <span class="pill">{{ deferBlocks().length }}</span>
521+
Defer blocks
522+
<span class="pill">{{ deferCount() }}</span>
520523
</h2>
521524
<ul class="defer-list">
522525
@for (block of deferBlocks(); track block.id) {
@@ -1469,6 +1472,10 @@ export class ComponentTree {
14691472
private readonly filtered = computed(() => filterTree(this.page()?.roots ?? [], this.query()));
14701473

14711474
readonly deferBlocks = computed(() => this.page()?.deferBlocks ?? []);
1475+
/** The block count, with a `+` when the page has more blocks than it reported. */
1476+
readonly deferCount = computed(
1477+
() => `${this.deferBlocks().length}${this.page()?.deferTruncated ? '+' : ''}`,
1478+
);
14721479

14731480
readonly countLabel = computed(() =>
14741481
countText(

‎app/src/pages/di-inspector.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,10 @@ function isTree(value: unknown): value is InjectorNode[] {
212212
<path d="M12 11v5M12 8h.01" />
213213
</svg>
214214
<span>
215-
<strong>This page has more than 2000 element injectors.</strong>
216-
Only the first 2000 are shown, so a lookup path or a provider can point to one that is
217-
not listed.
215+
<strong>The page reported only part of its injector tree.</strong>
216+
It keeps at most 2000 element injectors and 2500 in all, and leaves out injectors nested
217+
more than 1000 levels deep, so a lookup path or a provider can point to one that is not
218+
listed.
218219
</span>
219220
</p>
220221
}

‎app/src/pages/route-setup.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ import { SHARED_STYLES, type RouterPage } from './router-types';
77
@if (page().setup; as setup) {
88
@if (setup.mode === 'events-only') {
99
<p class="note" role="note">
10-
Events-only mode: this build has no debug utils (production build or unusual setup), so
11-
the route config, lint and actions are limited.
10+
Events-only mode: this build lacks the injector provider debug helper, so setup detection
11+
is limited. The preloader, the scroller and the router providers can't be found, and the
12+
features and options below can show defaults.
1213
</p>
1314
}
1415
<dl class="facts">

‎apps/docs/src/content/agents/resources.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ The signal graph of each page, under `pages[pageId]`. `graph` is the latest one.
6060

6161
### injector-tree
6262

63-
The injector hierarchy the page last reported, with the providers at each level. Each page is under `pages[pageId]`. `roots` and `environment` are the latest. Element injectors list what their components and directives inject in `dependencies`. Environment injectors list what the services they already created inject, with `from` naming the service or `InjectionToken`. `zone` is the change detection mode: `zoneless`, `zone` (zone.js) or `zone-unused` (zoneless, with zone.js still loaded). `truncated` is `true` when the page has more than 2000 element injectors and reported only the first 2000, or more than 2500 injectors in all. The server drops malformed nodes and clips long names.
63+
The injector hierarchy the page last reported, with the providers at each level. Each page is under `pages[pageId]`. `roots` and `environment` are the latest. Element injectors list what their components and directives inject in `dependencies`. Environment injectors list what the services they already created inject, with `from` naming the service or `InjectionToken`. `zone` is the change detection mode: `zoneless`, `zone` (zone.js) or `zone-unused` (zoneless, with zone.js still loaded). `truncated` is `true` when the tree was cut: it keeps at most 2000 element injectors and 2500 injectors in all, and leaves out injectors nested more than 1000 levels deep. The server drops malformed nodes and clips long names.
6464

6565
### ngrx-store
6666

‎apps/docs/src/content/agents/tools.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ The `@defer` blocks of each page: the component that holds each one, its state,
134134

135135
Without a development build, the page has no util to read defer blocks, and the answer says so.
136136

137-
Each page lists at most 50 blocks in the table and 50 under **Needs attention**, with a note on how many more are not shown. The whole answer stops at 20,000 characters. If several tabs report, pass `page` to read one. The **Defer blocks** list on the [Components](../inspectors/components.md#defer-blocks) page has every block.
137+
Each page lists at most 50 blocks in the table and 50 under **Needs attention**, with a note on how many more are not shown. The whole answer stops at 20,000 characters. If several tabs report, pass `page` to read one. The **Defer blocks** list on the [Components](../inspectors/components.md#defer-blocks) page has every block the page reported. A page reports its first 500 blocks. When it has more, the answer says so.
138138

139139
### change-detection <ngmd-badge variant="alpha">Action</ngmd-badge>
140140

@@ -145,7 +145,7 @@ Change detection cycles recorded with Angular's profiler: the slowest components
145145
| `record` | no | `start` starts a fresh recording on a page that is not recording and leaves a running one as it is, `stop` stops it and keeps the cycles, `clear` empties it. Leave out to read. |
146146
| `limit` | no | Rows per list. Default 10, at most 50. |
147147

148-
Without `page`, it reads the page that is recording, and `record` goes to every connected page. A `page` that names no connected tab gets the list of connected tabs. A connected tab that has not recorded yet gets a hint to start a recording there. The answer starts with the change detection mode of the page it reports on: zoneless, zone.js, or zoneless with zone.js still loaded. Recording is off until the panel or this tool starts it. Call it with `record: "start"`, use the app, then call it again without `record`. With `agent.readOnly`, the tool has no `record` argument and is marked read-only, so start the recording from the panel. When older cycles were dropped at [`limits.cdCycles`](../getting-started/configuration.md#limits), the answer says how many.
148+
Without `page`, it reads the page that is recording, and `record` goes to every connected page. A `page` that names no connected tab gets the list of connected tabs. A connected tab that has not recorded yet gets a hint to start a recording there. The answer starts with the change detection mode of the page it reports on: zoneless, zone.js, or zoneless with zone.js still loaded. Recording is off until the panel or this tool starts it. Call it with `record: "start"`, use the app, then call it again without `record`. With `agent.readOnly`, the tool has no `record` argument and is marked read-only, so start the recording from the panel. When older cycles were dropped at [`limits.cdCycles`](../getting-started/configuration.md#limits), the answer says how many. A recording lists at most 100 component classes and counts checks for up to 2000 instances. When it checked more, the answer says how many were left out.
149149

150150
### inspect-signals
151151

@@ -187,7 +187,7 @@ The injectors a page reported. Element injectors list what each component inject
187187

188188
A `selector` that names an element injector returns it with its lookup path resolved to names and provided tokens. One that names an environment injector, in any case, returns that injector's providers, what the services it already created inject, and its parent injectors. When nothing matches, the answer lists the tags and environment injector names on the page to retry with.
189189

190-
Without `selector` or `token`, the answer is the whole tree and says which change detection mode the page runs. The answer stays within 20,000 characters and its JSON always parses. A larger tree shows element injectors as an outline (id, name, type, component, and provider and dependency counts), and when that is still too long it leaves out the deepest injectors and says how many. The environment injectors are always there, as an outline when they are large, and without their deepest injectors when even that outline is too long. A `selector` or `token` answer that is too long keeps whole entries and says how many it shows. `selector` and `token` take at most 500 characters each. When the page has more than 2000 element injectors, the answer says that it holds only the first 2000.
190+
Without `selector` or `token`, the answer is the whole tree and says which change detection mode the page runs. The answer stays within 20,000 characters and its JSON always parses. A larger tree shows element injectors as an outline (id, name, type, component, and provider and dependency counts), and when that is still too long it leaves out the deepest injectors and says how many. The environment injectors are always there, as an outline when they are large, and without their deepest injectors when even that outline is too long. A `selector` or `token` answer that is too long keeps whole entries and says how many it shows. `selector` and `token` take at most 500 characters each. When the page reported only part of its injector tree (it keeps at most 2000 element injectors and 2500 in all, and leaves out injectors nested more than 1000 levels deep), the answer says so.
191191

192192
## NgRx
193193

‎apps/docs/src/content/inspectors/components.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ When the page renders `@defer` blocks, a **Defer blocks** list follows the tree.
8383

8484
Hover or focus a row to highlight the block in the page. Click it to select the component that holds it. The list is hidden when the page renders no defer blocks, or when its Angular version has no util to read them.
8585

86+
The list holds the first 500 blocks of a page. When the page has more, the count reads **500+**.
87+
8688
### Change detection
8789

8890
Below the tree and the defer blocks, the **Change detection** section records change detection cycles with Angular's profiler. Click **Record**, use the app, then click **Stop recording**. **Clear** empties the recording. Each new recording starts empty, but a start sent while the page records, such as an agent's `record: "start"`, keeps the cycles recorded so far.
@@ -91,6 +93,8 @@ Below the tree and the defer blocks, the **Change detection** section records ch
9193
- **Latest cycles**, newest first: the start time, the duration, how many components Angular checked, how many sync passes it ran, the output listener that ran just before the cycle (an output that ended more than 50 ms before the cycle is not counted), and the slowest component in it.
9294
- Tree rows show how many times each instance was checked while recording.
9395

96+
**Slowest components** shows the 100 component classes with the most self time among the first 1000 classes a recording checks. A class first checked after those 1000 has no totals, so it isn't ranked. Tree rows count checks for up to 2000 instances. When a recording checks more classes or instances, a note in the section says how many were left out.
97+
9498
Recording is off by default. While it is off, the page registers no profiler for it. The page keeps the last 200 cycles, set with [`limits.cdCycles`](../getting-started/configuration.md#limits). Recording needs Angular 20 or later. On older versions, the section says so. Times come from a development build, so they are higher than in production.
9599

96100
### Source mode

‎apps/docs/src/content/inspectors/injectors.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ See [Tools](../agents/tools.md) and [Resources](../agents/resources.md).
137137

138138
### Up to 2000 element injectors
139139

140-
The page reports at most 2000 element injectors. Past that, a notice above the tree says so, and a lookup path or a provider can point to an injector that isn't listed. `inspect-providers` says it too. Environment injectors are kept after them, up to 2500 injectors in all, so they never push element injectors out.
140+
The page reports at most 2000 element injectors. Environment injectors are kept after them, up to 2500 injectors in all, so they never push element injectors out. Injectors nested more than 1000 levels deep are left out too. When any of these limits cuts the tree, a notice above the tree says the page reported only part of its injector tree, and a lookup path or a provider can point to an injector that isn't listed. `inspect-providers` says it too.
141141

142142
### Some injectors can't be highlighted
143143

0 commit comments

Comments
 (0)