diff --git a/packages/core/src/application/application_ref.ts b/packages/core/src/application/application_ref.ts index 2281d3c4ea1..383a9327592 100644 --- a/packages/core/src/application/application_ref.ts +++ b/packages/core/src/application/application_ref.ts @@ -591,14 +591,21 @@ export class ApplicationRef { if (!this.zonelessEnabled) { this.dirtyFlags |= ApplicationRefDirtyFlags.ViewTreeGlobal; } - - // Run `_tick()` in the context of the most recent snapshot, if one exists. - this.tracingSnapshot?.run(TracingAction.CHANGE_DETECTION, this._tick) ?? this._tick(); + this._tick(); } /** @internal */ _tick = (): void => { - this.tracingSnapshot = null; + if (this.tracingSnapshot !== null) { + const snapshot = this.tracingSnapshot; + this.tracingSnapshot = null; + + // Ensure we always run `_tick()` in the context of the most recent snapshot, + // if one exists. Snapshots may be reference counted by the implementation so + // we want to ensure that if we request a snapshot that we use it. + snapshot.run(TracingAction.CHANGE_DETECTION, this._tick); + return; + } (typeof ngDevMode === 'undefined' || ngDevMode) && this.warnIfDestroyed(); if (this._runningTick) {