Skip to content

Commit

Permalink
fix(core): add warning when using zoneless but zone.js is still loaded
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
crisbeto committed May 13, 2024
1 parent 85ac2de commit 9c5be5a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
4 changes: 3 additions & 1 deletion goldens/public-api/core/errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,9 @@ export const enum RuntimeErrorCode {
// (undocumented)
VIEW_ALREADY_ATTACHED = 902,
// (undocumented)
VIEW_ALREADY_DESTROYED = 911
VIEW_ALREADY_DESTROYED = 911,
// (undocumented)
ZONELESS_REMOVE_ZONE = 914
}

// (No @packageDocumentation comment for this package)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {Injectable} from '../../di/injectable';
import {inject} from '../../di/injector_compatibility';
import {EnvironmentProviders} from '../../di/interface/provider';
import {makeEnvironmentProviders} from '../../di/provider_collection';
import {RuntimeError, RuntimeErrorCode} from '../../errors';
import {RuntimeError, RuntimeErrorCode, formatRuntimeError} from '../../errors';
import {PendingTasks} from '../../pending_tasks';
import {
scheduleCallbackWithMicrotask,
Expand Down Expand Up @@ -293,6 +293,16 @@ export class ChangeDetectionSchedulerImpl implements ChangeDetectionScheduler {
*/
export function provideExperimentalZonelessChangeDetection(): EnvironmentProviders {
performanceMarkFeature('NgZoneless');

if ((typeof ngDevMode === 'undefined' || ngDevMode) && typeof Zone !== 'undefined' && Zone) {
const message = formatRuntimeError(
RuntimeErrorCode.ZONELESS_REMOVE_ZONE,
`The application is using zoneless change detection, but is still loading Zone.js.` +
`Consider removing Zone.js to get the full benefits of zoneless.`,
);
console.warn(message);
}

return makeEnvironmentProviders([
{provide: ChangeDetectionScheduler, useExisting: ChangeDetectionSchedulerImpl},
{provide: NgZone, useClass: NoopNgZone},
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ export const enum RuntimeErrorCode {
VIEW_ALREADY_DESTROYED = 911,
COMPONENT_ID_COLLISION = -912,
IMAGE_PERFORMANCE_WARNING = -913,
ZONELESS_REMOVE_ZONE = 914,

// Signal integration errors
REQUIRED_INPUT_NO_VALUE = -950,
Expand Down

0 comments on commit 9c5be5a

Please sign in to comment.