From e1fe9ecffe05294becee1637971451d265ca9dc8 Mon Sep 17 00:00:00 2001 From: arturovt Date: Fri, 4 Dec 2020 01:00:05 +0200 Subject: [PATCH] perf(core): use `ngDevMode` to tree-shake `checkNoChanges` (#39964) This commit adds `ngDevMode` guard to run `checkNoChanges` only in dev mode (similar to how things work in other parts of Ivy runtime code). The `ngDevMode` flag helps to tree-shake this code from production builds (in dev mode everything will work as it works right now) to decrease production bundle size. PR Close #39964 --- goldens/size-tracking/aio-payloads.json | 2 +- goldens/size-tracking/integration-payloads.json | 2 +- packages/core/src/application_ref.ts | 7 +++---- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/goldens/size-tracking/aio-payloads.json b/goldens/size-tracking/aio-payloads.json index c9869baede..0f3cb254a5 100755 --- a/goldens/size-tracking/aio-payloads.json +++ b/goldens/size-tracking/aio-payloads.json @@ -12,7 +12,7 @@ "master": { "uncompressed": { "runtime-es2015": 3033, - "main-es2015": 447975, + "main-es2015": 447349, "polyfills-es2015": 52493 } } diff --git a/goldens/size-tracking/integration-payloads.json b/goldens/size-tracking/integration-payloads.json index a06f63162e..9022471479 100644 --- a/goldens/size-tracking/integration-payloads.json +++ b/goldens/size-tracking/integration-payloads.json @@ -3,7 +3,7 @@ "master": { "uncompressed": { "runtime-es2015": 1485, - "main-es2015": 141516, + "main-es2015": 140921, "polyfills-es2015": 36964 } } diff --git a/packages/core/src/application_ref.ts b/packages/core/src/application_ref.ts index 5f833bbdda..519d3af218 100644 --- a/packages/core/src/application_ref.ts +++ b/packages/core/src/application_ref.ts @@ -597,7 +597,6 @@ export class ApplicationRef { private _bootstrapListeners: ((compRef: ComponentRef) => void)[] = []; private _views: InternalViewRef[] = []; private _runningTick: boolean = false; - private _enforceNoNewChanges: boolean = false; private _stable = true; private _onMicrotaskEmptySubscription: Subscription; @@ -626,8 +625,6 @@ export class ApplicationRef { private _exceptionHandler: ErrorHandler, private _componentFactoryResolver: ComponentFactoryResolver, private _initStatus: ApplicationInitStatus) { - this._enforceNoNewChanges = isDevMode(); - this._onMicrotaskEmptySubscription = this._zone.onMicrotaskEmpty.subscribe({ next: () => { this._zone.run(() => { @@ -764,7 +761,9 @@ export class ApplicationRef { for (let view of this._views) { view.detectChanges(); } - if (this._enforceNoNewChanges) { + // Note that we have still left the `isDevMode()` condition in order to avoid + // creating a breaking change for projects that still use the View Engine. + if ((typeof ngDevMode === 'undefined' || ngDevMode) && isDevMode()) { for (let view of this._views) { view.checkNoChanges(); }