Content-Length: 479907 | pFad | https://github.com/angular/angular/commit/43cbc58254ecb8a1a6a938479b6c388cc00143d7

31 fix(core): remove `forceRoot` flag for effects (#60535) · angular/angular@43cbc58 · GitHub
Skip to content

Commit 43cbc58

Browse files
alxhubthePunderWoman
authored andcommitted
fix(core): remove forceRoot flag for effects (#60535)
This flag is effectively unused in Angular code that we've seen, and is only serving to complicate the mental model of effects. It could be reintroduced if needed. PR Close #60535
1 parent 8b5ba62 commit 43cbc58

File tree

3 files changed

+2
-61
lines changed

3 files changed

+2
-61
lines changed

goldens/public-api/core/index.api.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,6 @@ export interface CreateEffectOptions {
467467
// @deprecated (undocumented)
468468
allowSignalWrites?: boolean;
469469
debugName?: string;
470-
forceRoot?: true;
471470
injector?: Injector;
472471
manualCleanup?: boolean;
473472
}

packages/core/src/render3/reactivity/effect.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,6 @@ export interface CreateEffectOptions {
8282
*/
8383
manualCleanup?: boolean;
8484

85-
/**
86-
* Always create a root effect (which is scheduled as a microtask) regardless of whether `effect`
87-
* is called within a component.
88-
*/
89-
forceRoot?: true;
90-
9185
/**
9286
* @deprecated no longer required, signal writes are allowed by default.
9387
*/
@@ -122,7 +116,7 @@ export type EffectCleanupRegisterFn = (cleanupFn: EffectCleanupFn) => void;
122116
* Angular has two different kinds of effect: component effects and root effects. Component effects
123117
* are created when `effect()` is called from a component, directive, or within a service of a
124118
* component/directive. Root effects are created when `effect()` is called from outside the
125-
* component tree, such as in a root service, or when the `forceRoot` option is provided.
119+
* component tree, such as in a root service.
126120
*
127121
* The two effect types differ in their timing. Component effects run as a component lifecycle
128122
* event during Angular's synchronization (change detection) process, and can safely read input
@@ -159,7 +153,7 @@ export function effect(
159153

160154
const viewContext = injector.get(ViewContext, null, {optional: true});
161155
const notifier = injector.get(ChangeDetectionScheduler);
162-
if (viewContext !== null && !options?.forceRoot) {
156+
if (viewContext !== null) {
163157
// This effect was created in the context of a view, and will be associated with the view.
164158
node = createViewEffect(viewContext.view, notifier, effectFn);
165159
if (destroyRef instanceof NodeInjectorDestroyRef && destroyRef._lView === viewContext.view) {

packages/core/test/render3/reactivity_spec.ts

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -290,31 +290,6 @@ describe('reactivity', () => {
290290
expect(log).toEqual([0, 1]);
291291
});
292292

293-
it('should create root effects inside a component when specified', () => {
294-
TestBed.configureTestingModule({});
295-
const counter = signal(0);
296-
const log: number[] = [];
297-
298-
@Component({
299-
template: '',
300-
})
301-
class TestCmp {
302-
constructor() {
303-
effect(() => log.push(counter()), {forceRoot: true});
304-
}
305-
}
306-
307-
// Running this creates the effect. Note: we never CD this component.
308-
TestBed.createComponent(TestCmp);
309-
310-
TestBed.flushEffects();
311-
expect(log).toEqual([0]);
312-
313-
counter.set(1);
314-
TestBed.flushEffects();
315-
expect(log).toEqual([0, 1]);
316-
});
317-
318293
it('should check components made dirty from markForCheck() from an effect', async () => {
319294
TestBed.configureTestingModule({
320295
providers: [provideExperimentalZonelessChangeDetection()],
@@ -426,33 +401,6 @@ describe('reactivity', () => {
426401
});
427402

428403
describe('destruction', () => {
429-
it('should still destroy root effects with the DestroyRef of the component', () => {
430-
TestBed.configureTestingModule({});
431-
const counter = signal(0);
432-
const log: number[] = [];
433-
434-
@Component({
435-
template: '',
436-
})
437-
class TestCmp {
438-
constructor() {
439-
effect(() => log.push(counter()), {forceRoot: true});
440-
}
441-
}
442-
443-
const fix = TestBed.createComponent(TestCmp);
444-
445-
TestBed.flushEffects();
446-
expect(log).toEqual([0]);
447-
448-
// Destroy the effect.
449-
fix.destroy();
450-
451-
counter.set(1);
452-
TestBed.flushEffects();
453-
expect(log).toEqual([0]);
454-
});
455-
456404
it('should destroy effects when the parent component is destroyed', () => {
457405
let destroyed = false;
458406
@Component({})

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://github.com/angular/angular/commit/43cbc58254ecb8a1a6a938479b6c388cc00143d7

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy