From 118803035f366acdffc577ec857b888f764bb338 Mon Sep 17 00:00:00 2001 From: arielbackenroth Date: Mon, 25 Nov 2024 17:21:39 +0000 Subject: [PATCH] fix(core): Ensure _tick is always run within the TracingSnapshot. (#58881) Fix a bug where calls to _tick are called without running through the snapshot. This helps ensure that all snapshots that are requested are resumed. PR Close #58881 --- packages/core/src/application/application_ref.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) 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) {