You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 9fff774
Browse filesBrowse the repository at this point in the historyBrowse files
fix(injectors): tell apart DI tokens that share a name
Two tokens with the same name, such as two `new InjectionToken('config')`,
collided: the injected pairs were keyed `injector|name`, so injecting one
token let "Show value" and "Store as global" read (and create) the other,
and a provider value read checked only the name at its index.
Give each token object a stable id on the page through a WeakMap
(`token-id.ts`, `tok-N`) and carry it as `tokenId` on providers and
dependencies. Key the injected pairs and the provider value check by it,
and keep it through the server's report checks. The agent tools still take
a token name: `read-provider-value` and `explain-injection` answer a shared
name with the candidates and their ids and take `tokenId` to pick one, and
`inspect-providers` lists each match with its id and takes `tokenId` to keep
one. Reports without ids fall back to names. The panel keys provider rows
by id and sends it with value reads.
Refs #367
|`injector`| no | A tag name, a component or directive class name, an environment injector name like `Root`, `Platform` or `Route: admin`, an injector id, or a component instance id like `c12`. Returns only the matching injectors. |
501
501
|`token`| no | A token name, like `HttpClient`. Returns the injectors that provide it and the components or services that inject it. |
502
+
|`tokenId`| no | The id of one token, like `tok-3`, from `tokenId` in the tree. Keeps only that token when several share a name. |
502
503
503
504
An `injector` 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.
504
505
505
506
An element injector that belongs to a component carries `componentId`, the instance id that `inspect-component`, `list-components` and the `component-tree` resource use. `framework: true` marks the injectors and providers that come from the installed `@angular/*` packages; see [Framework injectors](../inspectors/injectors.md#framework-injectors).
506
507
507
-
Without `injector` 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. An `injector` or `token` answer that is too long cuts each injector's `providers` and `dependencies` lists, with `providersTotal` and `dependenciesTotal` giving the full counts, so a large injector such as `Root` still shows. An `@ngrx/signals` store that an environment injector created carries the name the NgRx tools use, such as `TravelStore`, in `token`, and its class name `SignalStore` in `tokenClass`; `token` finds it by either name, and so do `read-provider-value` and `explain-injection`. `injector` 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.
508
+
Without `injector` 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. An `injector` or `token` answer that is too long cuts each injector's `providers` and `dependencies` lists, with `providersTotal` and `dependenciesTotal` giving the full counts, so a large injector such as `Root` still shows. An `@ngrx/signals` store that an environment injector created carries the name the NgRx tools use, such as `TravelStore`, in `token`, and its class name `SignalStore` in `tokenClass`; `token` finds it by either name, and so do `read-provider-value` and `explain-injection`. `injector` and `token` take at most 500 characters each.
509
+
510
+
Each provider and dependency carries `tokenId`, the page's id for the token object, so two tokens with the same name, such as two `new InjectionToken('config')`, stay apart. A `token` that several tokens share lists every match with its `tokenId`, and `tokenId` keeps one of them. `read-provider-value` and `explain-injection` answer such a name with the candidates instead, and take `tokenId` to pick one. Ids last until the page reloads. A tree from an older overlay has no ids, and the tools match by name.
511
+
512
+
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.
508
513
509
514
### read-provider-value
510
515
@@ -513,6 +518,7 @@ The current value of a service or other provider that an injector on the page al
|`token`| yes | A class name like `CartStore` or an `InjectionToken` description like `API_URL`. |
521
+
|`tokenId`| no | The id of one token, like `tok-3`. Needed when several tokens share the name; the answer then lists them. |
516
522
|`injector`| no | An injector id, `Root`, `Platform`, `Route: admin`, a tag or a component class name. Defaults to the first injector that provides the token, environment injectors first. |
517
523
|`path`| no | A member, then keys or indexes, like `items` or `cart.items[0]`. Without it, the answer lists the members. |
518
524
|`depth`| no | With `path`, the levels to read below it, 1 to 5. |
@@ -528,6 +534,7 @@ How Angular resolves one token for one component, element or environment injecto
|`injector`| yes | Where the injection happens: a component or directive class name, a tag, a component instance id like `c12` (an error's owner id works), an injector id, or an environment injector name like `Root`. |
530
536
|`token`| yes | The token as the Injectors tab names it: a class name like `HttpClient` or an `InjectionToken` description like `API_URL`. |
537
+
|`tokenId`| no | The id of one token, like `tok-3`. Needed when several tokens share the name; the answer then lists them. |
531
538
|`self`| no |`true` asks only the first injector. |
532
539
|`skipSelf`| no |`true` starts at the parent injector. |
533
540
|`host`| no |`true` stops at the host element of the component that declares the start, where only its `viewProviders` and the component count. |
Copy file name to clipboardExpand all lines: apps/docs/src/content/inspectors/injectors.md
+3-1Lines changed: 3 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -81,6 +81,8 @@ For environment injectors, **Injected by its services** lists what the services
81
81
82
82
Each live provider row has a **Show value** button. It reads the provider's current value from the page and lists it like the properties of a component: its own fields, with signals and resources unwrapped (marked **signal** or **resource**), and methods left out. An object, array, Map or Set opens one level at a time, and each level is read from the page when you open it. A value without fields, such as a string or an array from `useValue`, shows whole. **Refresh** reads it again, since the list does not follow the app on its own. When several providers share a token, as `multi` providers do, their buttons and values are named with their position, such as **(2 of 2)**.
83
83
84
+
Two tokens can have the same name, such as two `new InjectionToken('config')`. The overlay gives each token object its own id (`tokenId` in the injector tree, such as `tok-3`), so the value, the **Injected here** rows and the check for whether something injected a token follow the token itself, not its name. Their buttons are named with their position, like the providers of one token.
85
+
84
86
Reading never creates a provider, with the same rules as **Store as global** below. A provider the app has not created yet says **… has not been created yet** instead. Getters never run, and secret-looking names and values are shown as `[redacted]`. See [what the devtools redact](../security.md).
85
87
86
88
### Store a provider as a global
@@ -222,7 +224,7 @@ If the selected injector leaves the page because its component or directive was
222
224
|`pangular:scan-providers`| tool | DI providers from source: `@Injectable` services, `inject()` calls, constructor parameters and `providers` arrays. |
223
225
|`pangular:explain-injection`| tool | The lookup of one token from a component, element or environment injector, step by step, with `self`, `skipSelf`, `host` and `optional`. Says at each injector whether it provides the token and why the lookup stops. See [Explain a lookup with flags](#explain-a-lookup-with-flags). |
224
226
|`pangular:inspect-providers`| tool | The injector tree a page reported, with what components and created services inject. `injector` narrows it to matching element or environment injectors (`Root`, `Platform`, `Route: admin`) or a component instance id, `token` to where a token is provided and injected. `componentId` and `framework` mark the owning component and Angular's own injectors and providers. |
225
-
|`pangular:read-provider-value`| tool | The current value of a provider an injector already created, by `token` and optional `injector`, with `path` to read deeper. See [Peek at a provider value](#peek-at-a-provider-value).|
227
+
|`pangular:read-provider-value`| tool | The current value of a provider an injector already created, by `token` and optional `injector`, with `path` to read deeper. When two tokens share the name, it lists them with their `tokenId`; pass `tokenId` to pick one. See [Peek at a provider value](#peek-at-a-provider-value). |
226
228
|`pangular:startup-timing`| tool | How the page started: milestones from navigation start to the first stable state, and the slowest providers to construct with own and total time. See [Startup timing](#startup-timing). |
227
229
|`pangular:injector-tree`| resource | The live tree last reported by a page. |
- Signal graph edges name their nodes instead of positions.
198
198
-`inspect-signals` reads the graph of a component the page is not showing: a `component` the component tree knows, or a component host matched by the new `selector` argument (CSS). A selector that matches no component host is refused at once (#367).
199
199
- A `Store` provided in a route is found, and the DI tools keep each signal store's name instead of `SignalStore`.
200
+
- Two DI tokens with the same name, such as two `new InjectionToken('config')`, no longer mix up provider values or which token something injected. The injector tree carries a `tokenId` for each token, `read-provider-value` and `explain-injection` list the candidates for a shared name and take `tokenId` to pick one, and `inspect-providers` takes `tokenId` to keep one (#367).
200
201
- The SSR hydration count is right, and a request is no longer reported as a transfer cache hit when it was not.
201
202
- A failed write answers with `isError: true`, and a failing call keeps its response body.
202
203
- The Express hub turns itself off with a warning on a Node.js that can't load it, instead of crashing the server.
0 commit comments