Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit73a7685

Browse files
committed
feat(core): RemoveprovideZonelessChangeDetection requirement when ZoneJS is not present
This change updates the internals to provide zoneless scheduling bydefault when ZoneJS. This change means that for most applications,simply omitting the ZoneJS polyfill will be enough to use zonelesschange detection.Developers may still need to use `provideZonelessChangeDetection` in the providers if the applicationexists alongside another one that uses ZoneJS (because ZoneJS would thenbe present and the zone-based change detection scheduler would then beselected).This is one step towards zoneless by default, but does not yet go as faras removing the `provideZoneChangeDetection` from the internals. Thatwould/will be larger breaking change since it will require existingZone-based applications to manually include `provideZoneChangeDetection`to the application providers (and for all tests).This approach works well because all existing Zone-based applications_must_ have ZoneJS already included on the page for them to work. Inaddition, this does not affect existing zoneless applications becausethey all must already manually use `provideZonelessChangeDetection`since the only scheduler provided by default prior to this change wasthe zone-based one. Only "custom" zoneless (zoneless apps prior to realzoneless support) may be affected.BREAKING CHANGE: Applications that configure a custom zoneless implementationnow and _do not_ want the Angular zoneless scheduler to be enabled willneed to include `provideZoneChangeDetection` as well as a providerfor `NgZone` in the application providers:```bootstrapApplication(App, {providers: [ provideZoneChangeDetection(), {provide: NgZone, useClass: MyNoopNgZone}]});```
1 parent4574095 commit73a7685

File tree

14 files changed

+79
-47
lines changed

14 files changed

+79
-47
lines changed

‎packages/core/src/application/create_application.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
* found in the LICENSE file at https://angular.dev/license
77
*/
88

9-
import{internalProvideZoneChangeDetection}from'../change_detection/scheduling/ng_zone_scheduling';
109
import{EnvironmentProviders,Provider,StaticProvider}from'../di/interface/provider';
1110
import{EnvironmentInjector}from'../di/r3_injector';
1211
import{Type}from'../interface/type';
@@ -15,12 +14,11 @@ import {assertStandaloneComponentType} from '../render3/errors';
1514
import{EnvironmentNgModuleRefAdapter}from'../render3/ng_module_ref';
1615

1716
import{ApplicationRef}from'./application_ref';
18-
import{ChangeDetectionScheduler}from'../change_detection/scheduling/zoneless_scheduling';
19-
import{ChangeDetectionSchedulerImpl}from'../change_detection/scheduling/zoneless_scheduling_impl';
2017
import{bootstrap}from'../platform/bootstrap';
2118
import{profiler}from'../render3/profiler';
2219
import{ProfilerEvent}from'../render3/profiler_types';
2320
import{errorHandlerEnvironmentInitializer}from'../error_handler';
21+
import{provideChangeDetectionScheduling}from'../change_detection/scheduling/default_scheduling_provider';
2422

2523
/**
2624
* Internal create application API that implements the core application creation logic and optional
@@ -52,8 +50,7 @@ export function internalCreateApplication(config: {
5250
// Create root application injector based on a set of providers configured at the platform
5351
// bootstrap level as well as providers passed to the bootstrap call by a user.
5452
constallAppProviders=[
55-
internalProvideZoneChangeDetection({}),
56-
{provide:ChangeDetectionScheduler,useExisting:ChangeDetectionSchedulerImpl},
53+
provideChangeDetectionScheduling(),
5754
errorHandlerEnvironmentInitializer,
5855
...(appProviders||[]),
5956
];
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
*@license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.dev/license
7+
*/
8+
9+
import{BootstrapOptions}from'../../application/application_ref';
10+
import{getNgZone}from'../../zone/ng_zone';
11+
import{getNgZoneOptions,internalProvideZoneChangeDetection}from'./ng_zone_scheduling';
12+
import{
13+
ChangeDetectionSchedulerImpl,
14+
internalProvideZonelessChangeDetection,
15+
}from'./zoneless_scheduling_impl';
16+
import{Provider}from'../../di/interface/provider';
17+
import{ChangeDetectionScheduler}from'./zoneless_scheduling';
18+
19+
exportfunctionprovideChangeDetectionScheduling(options?:BootstrapOptions):Provider[]{
20+
constscheduleInRootZone=(optionsasany)?.scheduleInRootZone;
21+
constngZoneFactory=()=>
22+
getNgZone(options?.ngZone,{
23+
...getNgZoneOptions({
24+
eventCoalescing:options?.ngZoneEventCoalescing,
25+
runCoalescing:options?.ngZoneRunCoalescing,
26+
}),
27+
scheduleInRootZone,
28+
});
29+
constignoreChangesOutsideZone=options?.ignoreChangesOutsideZone;
30+
constisZoneAvailable=typeofZone!=='undefined'&&!!Zone.root.run;
31+
return[
32+
isZoneAvailable
33+
?internalProvideZoneChangeDetection({
34+
ngZoneFactory,
35+
ignoreChangesOutsideZone,
36+
})
37+
:internalProvideZonelessChangeDetection(),
38+
{provide:ChangeDetectionScheduler,useExisting:ChangeDetectionSchedulerImpl},
39+
];
40+
}

‎packages/core/src/change_detection/scheduling/zoneless_scheduling_impl.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {Subscription} from 'rxjs';
1111
import{ApplicationRef,ApplicationRefDirtyFlags}from'../../application/application_ref';
1212
import{Injectable}from'../../di/injectable';
1313
import{inject}from'../../di/injector_compatibility';
14-
import{EnvironmentProviders}from'../../di/interface/provider';
14+
import{EnvironmentProviders,Provider}from'../../di/interface/provider';
1515
import{makeEnvironmentProviders}from'../../di/provider_collection';
1616
import{RuntimeError,RuntimeErrorCode,formatRuntimeError}from'../../errors';
1717
import{PendingTasksInternal}from'../../pending_tasks';
@@ -386,12 +386,17 @@ export function provideZonelessChangeDetection(): EnvironmentProviders {
386386
}
387387

388388
returnmakeEnvironmentProviders([
389-
{provide:ChangeDetectionScheduler,useExisting:ChangeDetectionSchedulerImpl},
390-
{provide:NgZone,useClass:NoopNgZone},
391-
{provide:ZONELESS_ENABLED,useValue:true},
392-
{provide:SCHEDULE_IN_ROOT_ZONE,useValue:false},
389+
internalProvideZonelessChangeDetection(),
393390
typeofngDevMode==='undefined'||ngDevMode
394391
?[{provide:PROVIDED_ZONELESS,useValue:true}]
395392
:[],
396393
]);
397394
}
395+
396+
exportfunctioninternalProvideZonelessChangeDetection():Provider[]{
397+
return[
398+
{provide:NgZone,useClass:NoopNgZone},
399+
{provide:ZONELESS_ENABLED,useValue:true},
400+
{provide:SCHEDULE_IN_ROOT_ZONE,useValue:false},
401+
];
402+
}

‎packages/core/src/core_private_export.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,8 @@ export {
3737
defaultIterableDiffersasɵdefaultIterableDiffers,
3838
defaultKeyValueDiffersasɵdefaultKeyValueDiffers,
3939
}from'./change_detection/change_detection';
40-
export{
41-
internalProvideZoneChangeDetectionasɵinternalProvideZoneChangeDetection,
42-
PROVIDED_NG_ZONEasɵPROVIDED_NG_ZONE,
43-
}from'./change_detection/scheduling/ng_zone_scheduling';
44-
export{ChangeDetectionSchedulerImplasɵChangeDetectionSchedulerImpl}from'./change_detection/scheduling/zoneless_scheduling_impl';
40+
export{provideChangeDetectionSchedulingasɵprovideChangeDetectionScheduling}from'./change_detection/scheduling/default_scheduling_provider';
41+
export{PROVIDED_NG_ZONEasɵPROVIDED_NG_ZONE}from'./change_detection/scheduling/ng_zone_scheduling';
4542
export{
4643
ChangeDetectionSchedulerasɵChangeDetectionScheduler,
4744
NotificationSourceasɵNotificationSource,

‎packages/core/src/platform/platform_ref.ts

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,14 @@
88

99
import{compileNgModuleFactory}from'../application/application_ngmodule_factory_compiler';
1010
import{BootstrapOptions,optionsReducer}from'../application/application_ref';
11-
import{
12-
getNgZoneOptions,
13-
internalProvideZoneChangeDetection,
14-
}from'../change_detection/scheduling/ng_zone_scheduling';
15-
import{ChangeDetectionScheduler}from'../change_detection/scheduling/zoneless_scheduling';
16-
import{ChangeDetectionSchedulerImpl}from'../change_detection/scheduling/zoneless_scheduling_impl';
11+
import{provideChangeDetectionScheduling}from'../change_detection/scheduling/default_scheduling_provider';
1712
import{Injectable,Injector}from'../di';
1813
import{errorHandlerEnvironmentInitializer}from'../error_handler';
1914
import{RuntimeError,RuntimeErrorCode}from'../errors';
2015
import{Type}from'../interface/type';
2116
import{CompilerOptions}from'../linker';
2217
import{NgModuleFactory,NgModuleRef}from'../linker/ng_module_factory';
2318
import{createNgModuleRefWithProviders}from'../render3/ng_module_ref';
24-
import{getNgZone}from'../zone/ng_zone';
2519
import{bootstrap,setModuleBootstrapImpl}from'./bootstrap';
2620
import{PLATFORM_DESTROY_LISTENERS}from'./platform_destroy_listeners';
2721

@@ -53,22 +47,8 @@ export class PlatformRef {
5347
moduleFactory:NgModuleFactory<M>,
5448
options?:BootstrapOptions,
5549
):Promise<NgModuleRef<M>>{
56-
constscheduleInRootZone=(optionsasany)?.scheduleInRootZone;
57-
constngZoneFactory=()=>
58-
getNgZone(options?.ngZone,{
59-
...getNgZoneOptions({
60-
eventCoalescing:options?.ngZoneEventCoalescing,
61-
runCoalescing:options?.ngZoneRunCoalescing,
62-
}),
63-
scheduleInRootZone,
64-
});
65-
constignoreChangesOutsideZone=options?.ignoreChangesOutsideZone;
6650
constallAppProviders=[
67-
internalProvideZoneChangeDetection({
68-
ngZoneFactory,
69-
ignoreChangesOutsideZone,
70-
}),
71-
{provide:ChangeDetectionScheduler,useExisting:ChangeDetectionSchedulerImpl},
51+
provideChangeDetectionScheduling(options),
7252
errorHandlerEnvironmentInitializer,
7353
];
7454
constmoduleRef=createNgModuleRefWithProviders(

‎packages/core/test/bundling/animations-standalone/bundle.golden_symbols.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,7 @@
524524
"getNearestLContainer",
525525
"getNextLContainer",
526526
"getNgDirectiveDef",
527+
"getNgZone",
527528
"getNgZoneOptions",
528529
"getNodeInjectable",
529530
"getNullInjector",
@@ -591,6 +592,7 @@
591592
"internalCreateApplication",
592593
"internalImportProvidersFrom",
593594
"internalProvideZoneChangeDetection",
595+
"internalProvideZonelessChangeDetection",
594596
"interpolateParams",
595597
"invalidCssUnitValue",
596598
"invalidDefinition",
@@ -747,6 +749,7 @@
747749
"profilerCallbacks",
748750
"projectNodes",
749751
"provideAnimations",
752+
"provideChangeDetectionScheduling",
750753
"provideZonelessChangeDetection",
751754
"providerToFactory",
752755
"providerToRecord",

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,7 @@
474474
"getNearestLContainer",
475475
"getNextLContainer",
476476
"getNgDirectiveDef",
477+
"getNgZone",
477478
"getNgZoneOptions",
478479
"getNodeInjectable",
479480
"getNullInjector",
@@ -543,6 +544,7 @@
543544
"internalCreateApplication",
544545
"internalImportProvidersFrom",
545546
"internalProvideZoneChangeDetection",
547+
"internalProvideZonelessChangeDetection",
546548
"invokeAllTriggerCleanupFns",
547549
"invokeDirectivesHostBindings",
548550
"invokeHostBindingsInCreationMode",
@@ -649,6 +651,7 @@
649651
"profiler",
650652
"profilerCallbacks",
651653
"projectNodes",
654+
"provideChangeDetectionScheduling",
652655
"provideZonelessChangeDetection",
653656
"providerToFactory",
654657
"providerToRecord",

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,7 @@
693693
"instructionState",
694694
"internalImportProvidersFrom",
695695
"internalProvideZoneChangeDetection",
696+
"internalProvideZonelessChangeDetection",
696697
"invokeDirectivesHostBindings",
697698
"invokeHostBindingsInCreationMode",
698699
"isAbstractControlOptions",
@@ -875,6 +876,7 @@
875876
"profiler",
876877
"profilerCallbacks",
877878
"projectNodes",
879+
"provideChangeDetectionScheduling",
878880
"providerToFactory",
879881
"providerToRecord",
880882
"providersResolver",

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,7 @@
695695
"instructionState",
696696
"internalImportProvidersFrom",
697697
"internalProvideZoneChangeDetection",
698+
"internalProvideZonelessChangeDetection",
698699
"invokeDirectivesHostBindings",
699700
"invokeHostBindingsInCreationMode",
700701
"isAngularZoneProperty",
@@ -874,6 +875,7 @@
874875
"profiler",
875876
"profilerCallbacks",
876877
"projectNodes",
878+
"provideChangeDetectionScheduling",
877879
"providerToFactory",
878880
"providerToRecord",
879881
"providersResolver",

‎packages/core/test/bundling/hydration/bundle.golden_symbols.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,7 @@
492492
"getNextLContainer",
493493
"getNgContainerSize",
494494
"getNgDirectiveDef",
495+
"getNgZone",
495496
"getNgZoneOptions",
496497
"getNoOffsetIndex",
497498
"getNodeInjectable",
@@ -563,6 +564,7 @@
563564
"internalCreateApplication",
564565
"internalImportProvidersFrom",
565566
"internalProvideZoneChangeDetection",
567+
"internalProvideZonelessChangeDetection",
566568
"invokeDirectivesHostBindings",
567569
"invokeHostBindingsInCreationMode",
568570
"isAngularZoneProperty",
@@ -688,6 +690,7 @@
688690
"profiler",
689691
"profilerCallbacks",
690692
"projectNodes",
693+
"provideChangeDetectionScheduling",
691694
"provideClientHydration",
692695
"providerToFactory",
693696
"providerToRecord",

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp