Skip to content

Commit 47b7ba0

Browse files
atscottpkozlowski-opensource
authored andcommitted
refactor(core): Remove hybrid mode flag and move scheduler provider location (#55722)
The flag is not used anymore and, as a result, is easier to move the scheduler provider. PR Close #55722
1 parent 6ddd1e4 commit 47b7ba0

File tree

14 files changed

+54
-32
lines changed

14 files changed

+54
-32
lines changed

packages/core/src/application/create_application.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@ import {NgZone} from '../zone/ng_zone';
2929

3030
import {ApplicationInitStatus} from './application_init';
3131
import {_callAndReportToErrorHandler, ApplicationRef} from './application_ref';
32-
import {PROVIDED_ZONELESS} from '../change_detection/scheduling/zoneless_scheduling';
32+
import {
33+
PROVIDED_ZONELESS,
34+
ChangeDetectionScheduler,
35+
} from '../change_detection/scheduling/zoneless_scheduling';
36+
import {ChangeDetectionSchedulerImpl} from '../change_detection/scheduling/zoneless_scheduling_impl';
3337

3438
/**
3539
* Internal create application API that implements the core application creation logic and optional
@@ -59,7 +63,11 @@ export function internalCreateApplication(config: {
5963

6064
// Create root application injector based on a set of providers configured at the platform
6165
// bootstrap level as well as providers passed to the bootstrap call by a user.
62-
const allAppProviders = [internalProvideZoneChangeDetection({}), ...(appProviders || [])];
66+
const allAppProviders = [
67+
internalProvideZoneChangeDetection({}),
68+
{provide: ChangeDetectionScheduler, useExisting: ChangeDetectionSchedulerImpl},
69+
...(appProviders || []),
70+
];
6371
const adapter = new EnvironmentNgModuleRefAdapter({
6472
providers: allAppProviders,
6573
parent: platformInjector as EnvironmentInjector,

packages/core/src/change_detection/scheduling/flags.ts

Lines changed: 0 additions & 10 deletions
This file was deleted.

packages/core/src/change_detection/scheduling/ng_zone_scheduling.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,16 @@ import {performanceMarkFeature} from '../../util/performance';
2525
import {NgZone} from '../../zone';
2626
import {InternalNgZoneOptions} from '../../zone/ng_zone';
2727

28-
import {alwaysProvideZonelessScheduler} from './flags';
2928
import {
3029
ChangeDetectionScheduler,
31-
ZONELESS_ENABLED,
3230
ZONELESS_SCHEDULER_DISABLED,
31+
ZONELESS_ENABLED,
3332
} from './zoneless_scheduling';
34-
import {ChangeDetectionSchedulerImpl} from './zoneless_scheduling_impl';
3533

3634
@Injectable({providedIn: 'root'})
3735
export class NgZoneChangeDetectionScheduler {
3836
private readonly zone = inject(NgZone);
39-
private readonly changeDetectionScheduler = inject(ChangeDetectionScheduler, {optional: true});
37+
private readonly changeDetectionScheduler = inject(ChangeDetectionScheduler);
4038
private readonly applicationRef = inject(ApplicationRef);
4139

4240
private _onMicrotaskEmptySubscription?: Subscription;
@@ -51,7 +49,7 @@ export class NgZoneChangeDetectionScheduler {
5149
// `onMicroTaskEmpty` can happen _during_ the zoneless scheduler change detection because
5250
// zone.run(() => {}) will result in `checkStable` at the end of the `zone.run` closure
5351
// and emit `onMicrotaskEmpty` synchronously if run coalsecing is false.
54-
if (this.changeDetectionScheduler?.runningTick) {
52+
if (this.changeDetectionScheduler.runningTick) {
5553
return;
5654
}
5755
this.zone.run(() => {
@@ -119,11 +117,6 @@ export function internalProvideZoneChangeDetection({
119117
// Always disable scheduler whenever explicitly disabled, even if another place called
120118
// `provideZoneChangeDetection` without the 'ignore' option.
121119
ignoreChangesOutsideZone === true ? {provide: ZONELESS_SCHEDULER_DISABLED, useValue: true} : [],
122-
// TODO(atscott): This should move to the same places that zone change detection is provided by
123-
// default instead of being in the zone scheduling providers.
124-
alwaysProvideZonelessScheduler || ignoreChangesOutsideZone === false
125-
? {provide: ChangeDetectionScheduler, useExisting: ChangeDetectionSchedulerImpl}
126-
: [],
127120
];
128121
}
129122

packages/core/src/core_private_export.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export {
2222
defaultKeyValueDiffers as ɵdefaultKeyValueDiffers,
2323
} from './change_detection/change_detection';
2424
export {internalProvideZoneChangeDetection as ɵinternalProvideZoneChangeDetection} from './change_detection/scheduling/ng_zone_scheduling';
25+
export {ChangeDetectionSchedulerImpl as ɵChangeDetectionSchedulerImpl} from './change_detection/scheduling/zoneless_scheduling_impl';
2526
export {
2627
ChangeDetectionScheduler as ɵChangeDetectionScheduler,
2728
NotificationSource as ɵNotificationSource,

packages/core/src/platform/platform_ref.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ import {
2020
internalProvideZoneChangeDetection,
2121
PROVIDED_NG_ZONE,
2222
} from '../change_detection/scheduling/ng_zone_scheduling';
23-
import {ZONELESS_ENABLED} from '../change_detection/scheduling/zoneless_scheduling';
23+
import {
24+
ChangeDetectionScheduler,
25+
ZONELESS_ENABLED,
26+
} from '../change_detection/scheduling/zoneless_scheduling';
27+
import {ChangeDetectionSchedulerImpl} from '../change_detection/scheduling/zoneless_scheduling_impl';
2428
import {Injectable, InjectionToken, Injector} from '../di';
2529
import {ErrorHandler} from '../error_handler';
2630
import {RuntimeError, RuntimeErrorCode} from '../errors';
@@ -89,11 +93,13 @@ export class PlatformRef {
8993
// created outside of the Angular zone.
9094
return ngZone.run(() => {
9195
const ignoreChangesOutsideZone = options?.ignoreChangesOutsideZone;
92-
const moduleRef = createNgModuleRefWithProviders(
93-
moduleFactory.moduleType,
94-
this.injector,
95-
internalProvideZoneChangeDetection({ngZoneFactory: () => ngZone, ignoreChangesOutsideZone}),
96-
);
96+
const moduleRef = createNgModuleRefWithProviders(moduleFactory.moduleType, this.injector, [
97+
...internalProvideZoneChangeDetection({
98+
ngZoneFactory: () => ngZone,
99+
ignoreChangesOutsideZone,
100+
}),
101+
{provide: ChangeDetectionScheduler, useExisting: ChangeDetectionSchedulerImpl},
102+
]);
97103

98104
if (typeof ngDevMode === 'undefined' || ngDevMode) {
99105
if (moduleRef.injector.get(PROVIDED_NG_ZONE)) {

packages/core/test/bundling/animations/bundle.golden_symbols.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,6 +1151,9 @@
11511151
{
11521152
"name": "internalImportProvidersFrom"
11531153
},
1154+
{
1155+
"name": "internalProvideZoneChangeDetection"
1156+
},
11541157
{
11551158
"name": "interpolateParams"
11561159
},

packages/core/test/bundling/cyclic_import/bundle.golden_symbols.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -914,6 +914,9 @@
914914
{
915915
"name": "internalImportProvidersFrom"
916916
},
917+
{
918+
"name": "internalProvideZoneChangeDetection"
919+
},
917920
{
918921
"name": "invokeDirectivesHostBindings"
919922
},

packages/core/test/bundling/defer/bundle.golden_symbols.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1430,9 +1430,6 @@
14301430
{
14311431
"name": "init_fields"
14321432
},
1433-
{
1434-
"name": "init_flags"
1435-
},
14361433
{
14371434
"name": "init_forward_ref"
14381435
},

packages/core/test/bundling/forms_reactive/bundle.golden_symbols.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1298,6 +1298,9 @@
12981298
{
12991299
"name": "internalImportProvidersFrom"
13001300
},
1301+
{
1302+
"name": "internalProvideZoneChangeDetection"
1303+
},
13011304
{
13021305
"name": "invokeDirectivesHostBindings"
13031306
},

packages/core/test/bundling/forms_template_driven/bundle.golden_symbols.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,6 +1262,9 @@
12621262
{
12631263
"name": "internalImportProvidersFrom"
12641264
},
1265+
{
1266+
"name": "internalProvideZoneChangeDetection"
1267+
},
12651268
{
12661269
"name": "invokeDirectivesHostBindings"
12671270
},

0 commit comments

Comments
 (0)