Title: fix(core): clear reactive consumer when creating node injectables by arturovt · Pull Request #72133 · angular/angular · GitHub
Open Graph Title: fix(core): clear reactive consumer when creating node injectables by arturovt · Pull Request #72133 · angular/angular
X Title: fix(core): clear reactive consumer when creating node injectables by arturovt · Pull Request #72133 · angular/angular
Description: Please note that this fixes a real production issue; it wasn't found speculatively through AI code analysis. R3Injector.hydrate clears the active reactive consumer before it runs a provider factory. getNodeInjectable does not. It already saves and restores four other things, but not the consumer. So creating an injectable is not reactive with the environment injector, but it is reactive with the node injector. This only shows up when a node-level provider or view provider is created late, after the view already exists. That happens through injector.get(), through runInInjectionContext(), and when a signal query reads a provider with read:. Components and directives are created in renderView, where the consumer is already null, and ɵɵpipe calls the pipe factory itself, so those do not go through this path. Here is a component with a node-level provider that is created late: @Component({ template: '{{ label }}', providers: [Lazy], }) class App { private injector = inject(Injector); get label() { return this.injector.get(Lazy).label(); } } Two problems come from this. First, a signal write in a constructor throws NG0600. The template consumer does not allow writes. A computed does not allow them either, which is how a signal query hits this too. Second, a signal read in a constructor becomes a dependency of the consumer around it. Another signal can then make that consumer dirty, and it keeps the consumer alive. There is no error, so nobody sees it. We saw the first problem in production. Lazy is our code with new names. A field initializer turned an observable into a signal: class Lazy { // field initializer, runs inside `getNodeInjectable` readonly label = toSignal(this.data.label$, { initialValue: '' }); } toSignal subscribes right away, inside its own call. It does not wait for an effect. Our source emitted a value during that subscribe. So the next handler of toSignal called .set before the constructor finished, and the template consumer of App was still active. Two things made this hard to find. The source did not look synchronous. It ends with a forkJoin, and forkJoin emits from its finalize handler. So the value came during teardown and not from a simple of(). Also, publishSignalConfiguration builds the message only when ngDevMode is on. In production it throws RuntimeError(-600, ''). Our report had only NG0600 and a short minified stack. The last frames were the toSignal callback and RxJS code. The stack did not show our class or our component. Now getNodeInjectable clears the consumer around the factory call and restores it in the finally block that is already there. This is what the environment injector does.
Open Graph Description: Please note that this fixes a real production issue; it wasn't found speculatively through AI code analysis. R3Injector.hydrate clears the active reactive consumer before it runs a provider fa...
X Description: Please note that this fixes a real production issue; it wasn't found speculatively through AI code analysis. R3Injector.hydrate clears the active reactive consumer before it runs a provide...
Opengraph URL: https://github.com/angular/angular/pull/72133
X: @github
Domain: github.com
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:b04ee101-ae23-5fad-d65f-166108fe4065 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | 800A:136CDA:DE69B1:126DB09:6B01D15B |
| html-safe-nonce | 58bee80417d5bd5e12f35f0689e2b90529ad602acf46e8cbf96f19d1345a380a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MDBBOjEzNkNEQTpERTY5QjE6MTI2REIwOTo2QjAxRDE1QiIsInZpc2l0b3JfaWQiOiIzNzE5NTE0NjI0ODMzNDk4NTIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | b1d908722e997f38e3512f6adf4b4713751b7bd954bdc2bdf48875f0d580d83c |
| hovercard-subject-tag | pull_request:5403020699 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/angular/angular/pull/72133/files |
| twitter:image | https://avatars.githubusercontent.com/u/7337691?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/7337691?s=400&v=4 |
| og:image:alt | Please note that this fixes a real production issue; it wasn't found speculatively through AI code analysis. R3Injector.hydrate clears the active reactive consumer before it runs a provider fa... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/angular/angular git https://github.com/angular/angular.git |
| octolytics-dimension-user_id | 139426 |
| octolytics-dimension-user_login | angular |
| octolytics-dimension-repository_id | 24195339 |
| octolytics-dimension-repository_nwo | angular/angular |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 24195339 |
| octolytics-dimension-repository_network_root_nwo | angular/angular |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width