Skip to content

Commit 0cbd73c

Browse files
crisbetodylhunn
authored andcommitted
fix(core): add warning when using zoneless but zone.js is still loaded (#55769)
Users may be using zoneless, but are still loading Zone.js in which case they won't get the full benefits like reduced bundle size. These changes detect such a case and log a warning. PR Close #55769
1 parent e923a76 commit 0cbd73c

3 files changed

Lines changed: 15 additions & 1 deletion

File tree

goldens/public-api/core/errors.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ export const enum RuntimeErrorCode {
147147
// (undocumented)
148148
UNEXPECTED_ZONE_STATE = 909,
149149
// (undocumented)
150+
UNEXPECTED_ZONEJS_PRESENT_IN_ZONELESS_MODE = 914,
151+
// (undocumented)
150152
UNKNOWN_BINDING = 303,
151153
// (undocumented)
152154
UNKNOWN_ELEMENT = 304,

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {Injectable} from '../../di/injectable';
1313
import {inject} from '../../di/injector_compatibility';
1414
import {EnvironmentProviders} from '../../di/interface/provider';
1515
import {makeEnvironmentProviders} from '../../di/provider_collection';
16-
import {RuntimeError, RuntimeErrorCode} from '../../errors';
16+
import {RuntimeError, RuntimeErrorCode, formatRuntimeError} from '../../errors';
1717
import {PendingTasks} from '../../pending_tasks';
1818
import {
1919
scheduleCallbackWithMicrotask,
@@ -294,6 +294,17 @@ export class ChangeDetectionSchedulerImpl implements ChangeDetectionScheduler {
294294
*/
295295
export function provideExperimentalZonelessChangeDetection(): EnvironmentProviders {
296296
performanceMarkFeature('NgZoneless');
297+
298+
if ((typeof ngDevMode === 'undefined' || ngDevMode) && typeof Zone !== 'undefined' && Zone) {
299+
const message = formatRuntimeError(
300+
RuntimeErrorCode.UNEXPECTED_ZONEJS_PRESENT_IN_ZONELESS_MODE,
301+
`The application is using zoneless change detection, but is still loading Zone.js.` +
302+
`Consider removing Zone.js to get the full benefits of zoneless. ` +
303+
`In applcations using the Angular CLI, Zone.js is typically included in the "polyfills" section of the angular.json file.`,
304+
);
305+
console.warn(message);
306+
}
307+
297308
return makeEnvironmentProviders([
298309
{provide: ChangeDetectionScheduler, useExisting: ChangeDetectionSchedulerImpl},
299310
{provide: NgZone, useClass: NoopNgZone},

packages/core/src/errors.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ export const enum RuntimeErrorCode {
116116
VIEW_ALREADY_DESTROYED = 911,
117117
COMPONENT_ID_COLLISION = -912,
118118
IMAGE_PERFORMANCE_WARNING = -913,
119+
UNEXPECTED_ZONEJS_PRESENT_IN_ZONELESS_MODE = 914,
119120

120121
// Signal integration errors
121122
REQUIRED_INPUT_NO_VALUE = -950,

0 commit comments

Comments
 (0)