Remove a callback read's pending task right after the callback instead of one `setTimeout(fn, 0)` later

未關閉 適合新手
#3,836 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 3 天內回覆

還沒有人認領這個 Issue。

評估

難度
2/5
預估耗時
1-3 小時
新手友好度
84/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
angular, firebase, typescript

研究方向

閱讀 src/zones.ts,特別查看第 123、153 和 190 行附近的回呼包裝及待處理工作的移除。追蹤第一次回呼和取消訂閱的路徑,接著檢查各路徑如何移除工作,以及回呼擲出錯誤時的行為。完成標準是:工作在第一次回呼後立即移除,或在取消訂閱時移除,不使用計時器,且符合所述的標記順序。

由索引模型根據 Issue 內容生成。

描述

comp: ssr comp: zones type: feature version: current (v17+)
Version info

Angular: 22.2

Firebase: 12.19.0

AngularFire: 22.0.0-rc.0, and main

Description

Every callback-taking read that holds a pending task keeps it one setTimeout(fn, 0) delay longer than it needs to:

  • ɵzoneWrap registers a pending task when a function wrapped with blockUntilFirst true, such as onSnapshot, onAuthStateChanged or onValue, is handed a callback, and removes it with setTimeout(taskDone, 0) scheduled right before the first callback runs (src/zones.ts:123) and again when the returned unsubscribe is called (:190).
  • So ApplicationRef.isStable can turn true only after that timer callback has run, one macrotask after the first value arrived. The comment next to the wrapping call, // TODO create a microtask to track callback functions (:153), asks for a microtask in its place.
  • #3833 moved the Observable-returning reads off their timer. The callback reads are the remaining branch.
  • Removing the task in a finally right after the callback body needs no timer and keeps a throwing callback from leaving its task behind.
How to reproduce these conditions

On a fresh Angular 22.2 app with @angular/fire@next, wrap a callback-taking function with the real ɵzoneWrap, invoke the callback from a setTimeout(fn, 0) outside Angular, and inside that same setTimeout callback, before invoking it, register a second setTimeout(fn, 0) and a queueMicrotask as markers. Observe the moment the wrapper calls the remover function that PendingTasks.add() returned:

  • The marker setTimeout callback has already run, in a zone.js app and a zoneless one, in Chrome and Firefox, for the first callback and for unsubscribe.
  • With the task removed in a finally after the callback body, the remover is called before either marker has run, in every one of those runs.
  • The real onSnapshot against the Firestore emulator, with the markers registered by a raw SDK listener attached first to the same document, reads the same way: the remover runs after the marker setTimeout callback today, and before it with the change.
Expected behavior

A callback read's pending task is removed as soon as its first callback has run, or as soon as it is unsubscribed.

Actual behavior

The task is removed one setTimeout(fn, 0) delay later.

主要語言
TypeScript
星號
7.8k
分支
2.2k
平均合併
2 天 21 小時
30 天內合併 PR
24

環境準備

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

angular/angularfire 的其他 Issue

查看 angular/angularfire 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。