When an effect is created in a component constructor, it might read signals which are derived from component inputs. These signals may be unreliable or (in the case of the proposed input signals) may throw if accessed before the component is first change detected (which is what makes required inputs available). Depending on the scenario involved, the effect may or may not run before this initialization takes place, which isn't a great developer experience. In particular, effects created during CD (e.g. via control flow) work fine, as do effects created in bootstrap thanks to the sync CD it performs. When an effect is created through dynamic component creation outside of CD though (such as on router navigations), it runs before the component is first CD'd, causing the issue. In fact, in the signal components RFC we described how effects would wait until ngOnInit for their first execution for exactly this reason, but this behavior was never implemented as it was thought our effect scheduling design made it unnecessary. This is true of the regular execution of effects but the above scenario shows that *creation* of the effect is still vulnerable. Thus, this logic is needed. This commit makes effects sensitive to their creation context, by injecting `ChangeDetectorRef` optionally. An effect created with an injector that's tied to a component will wait until that component is initialized before initially being scheduled. TestBed effect flushing is also adjusted to account for the additional interaction with change detection. PR Close #52473
Angular - The modern web developer's platform
Angular is a development platform for building mobile and desktop web applications
using TypeScript/JavaScript and other languages.
Contributing Guidelines
·
Submit an Issue
·
Blog
Documentation
Get started with Angular, learn the fundamentals and explore advanced topics on our documentation website.
Advanced
Development Setup
Prerequisites
- Install Node.js which includes Node Package Manager
Setting Up a Project
Install the Angular CLI globally:
npm install -g @angular/cli
Create workspace:
ng new [PROJECT NAME]
Run the application:
cd [PROJECT NAME]
ng serve
Angular is cross-platform, fast, scalable, has incredible tooling, and is loved by millions.
Quickstart
Ecosystem
Changelog
Learn about the latest improvements.
Upgrading
Check out our upgrade guide to find out the best way to upgrade your project.
Contributing
Contributing Guidelines
Read through our contributing guidelines to learn about our submission process, coding rules, and more.
Want to Help?
Want to report a bug, contribute some code, or improve the documentation? Excellent! Read up on our guidelines for contributing and then check out one of our issues labeled as help wanted or good first issue.
Code of Conduct
Help us keep Angular open and inclusive. Please read and follow our Code of Conduct.
Community
Join the conversation and help the community.
- X (formerly Twitter)
- Discord
- Gitter
- YouTube
- StackOverflow
- Find a Local Meetup
Love Angular? Give our repo a star ⭐ ⬆️.
