angular/packages/core/test/render3
Alex Rickabaugh ee9605f3c8 fix(core): effects wait for ngOnInit for their first run (#52473)
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
2023-11-01 08:07:35 -07:00
..
i18n refactor(core): remove debug data structures (#48281) 2022-11-30 09:27:59 -08:00
instructions refactor(core): decouple effects from change detection (#51049) 2023-09-12 08:12:56 -07:00
interfaces ci: add lint error for files with missing trailing new-line (#42478) 2021-06-04 13:31:03 -07:00
ivy refactor(core): remove unnecessary reflect-metadata import. (#49673) 2023-04-03 19:17:02 -07:00
jit build: align with internal tsconfig options (#51728) 2023-09-12 11:39:42 -07:00
styling_next refactor(core): Ensure that previousOrParentTNode always belongs to current TView. (#38707) 2020-09-28 16:15:58 -04:00
util refactor(core): add a new stringifier for runtime errors which includes debug info such as the file path and line number (#51919) 2023-10-09 15:57:03 -07:00
BUILD.bazel refactor(core): Synchronously emit the current signal value in toObservable (#49894) 2023-04-25 09:27:38 -07:00
change_detection_spec.ts refactor(core): drop unused fields from the RootContext (#46806) 2022-08-05 09:58:06 -07:00
component_ref_spec.ts fix(core): expose input transform function on ComponentFactory and ComponentMirror (#50713) 2023-06-22 09:47:15 -07:00
deps_tracker_spec.ts feat(core): show runtime error for orphan component rendering (#52061) 2023-10-10 15:30:26 -07:00
di_spec.ts refactor(core): decouple effects from change detection (#51049) 2023-09-12 08:12:56 -07:00
es2015-tsconfig.json fix(core): destroy hooks not set up for useClass provider using forwardRef (#44281) 2021-11-30 11:56:05 -05:00
global_utils_spec.ts feat(core): introduce getDirectiveMetadata global debugging utility (#41525) 2021-04-13 16:06:32 -07:00
i18n_debug_spec.ts build: bundle spec files for saucelabs legacy job (#44281) 2021-11-30 11:56:04 -05:00
imported_renderer2.ts refactor(core): Remove dead unit test code (#51223) 2023-08-01 12:10:57 -07:00
instructions_spec.ts refactor(core): handle #24571 todos. (#49221) 2023-06-14 12:33:44 +02:00
integration_spec.ts feat(core): support TypeScript 4.8 (#47038) 2022-08-16 16:02:47 +00:00
is_shape_of.ts refactor(core): Better use of Object.keys() (#51153) 2023-07-25 09:17:46 -07:00
is_shape_of_spec.ts ci: add lint error for files with missing trailing new-line (#42478) 2021-06-04 13:31:03 -07:00
jit_environment_spec.ts refactor(compiler): apply component metadata asynchronously when defer blocks are present (#51182) 2023-08-15 11:32:09 -07:00
list_reconciliation_spec.ts refactor(core): move key calculation in list reconciler (#52227) 2023-10-18 14:04:24 +02:00
load_domino.ts fix(platform-server): bundle @angular/domino in via esbuild (#49229) 2023-02-28 13:34:50 -08:00
matchers.ts refactor(core): Better use of Object.keys() (#51153) 2023-07-25 09:17:46 -07:00
matchers_spec.ts refactor(core): serialize info about templates used to create embedded views (#49382) 2023-03-14 14:22:08 -07:00
metadata_spec.ts build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00
node_selector_matcher_spec.ts build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00
providers_helper.ts test(core): convert providers test utility to TestBed (#46527) 2022-06-27 15:15:00 -07:00
providers_spec.ts test(core): use TestBed & JIT instead of handwritten defs in providers_spec (#46527) 2022-06-27 15:15:00 -07:00
query_spec.ts test(core): refactor tests to use TestBed instead of hand-written instructions (#46561) 2022-06-28 21:28:21 -07:00
reactivity_spec.ts fix(core): effects wait for ngOnInit for their first run (#52473) 2023-11-01 08:07:35 -07:00
testing_spec.ts test: update tests to account for karma-jasmine v5.0.0 2022-07-18 19:19:00 +02:00
utils.ts build: update to jasmine 4.0 (#45558) 2022-04-11 16:25:28 +00:00
view_fixture.ts refactor(core): decouple effects from change detection (#51049) 2023-09-12 08:12:56 -07:00
view_utils_spec.ts fix(core): Store ICU state in LView rather than in TView (#39233) 2020-10-21 18:33:00 -07:00