Deliver Observable read values as microtasks instead of after a timer

Đang mở
#3,832 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 3 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
74/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
angular, typescript
Lĩnh vực
api

Hướng nghiên cứu

Start with src/zones.ts:82 and the ɵzoneWrap path described in the issue; check how schedulers.insideAngular is used by the Observable wrappers. Add or update tests for the timing behavior, including a wrapped Subject and the affected compat streams. Done means values reach subscribers in a microtask after the current task, not synchronously or after a timer.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

comp: compat 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 Observable-returning read waits one timer turn before its subscriber sees a value:

  • ɵzoneWrap pipes those reads (collectionData, docData, authState, user, objectVal, listVal, fromTask, the Remote Config get*Changes streams, 34 wrappers across the modular modules including Firestore Lite) through observeOn(schedulers.insideAngular).
  • That scheduler is built over rxjs asyncScheduler (src/zones.ts:82), which defers with setInterval, so each value reaches the subscriber one macrotask after Firebase handed it over.
  • For Firestore that is a second timer: the SDK already hands each snapshot to its callback inside a setTimeout(0).
  • The scheduler came in with #2243 (merged 2020), and the comment that PR added requires that emissions are never synchronous. rxjs's AsapScheduler, which defers with Promise.resolve().then, meets that requirement and delivers at the next microtask checkpoint, before any timer.

The compat layer is affected:

  • The AngularFireAuth streams authState, user and credential deliver through the same scheduler instance and inherit whichever timing it has.
  • AngularFireFunctions and AngularFireMessaging use it only to hand over the SDK instance before their work starts, so their results are not delivered through it.
  • Compat Database and Firestore deliver through schedulers.outsideAngular and are not part of this.
How to reproduce these conditions

On a fresh Angular 22.2 app with @angular/fire@next, wrap a Subject with the real ɵzoneWrap, subscribe, and at the moment the source emits register a setTimeout(0) and a queueMicrotask:

  • When the subscriber runs, the timer has already fired, in a zone.js app and a zoneless one, in Chrome and Firefox.
  • The real collectionData against the Firestore emulator and the compat authState against the Auth emulator behave the same way in Chrome.
  • With an AsapScheduler in place of asyncScheduler, the microtask has fired and the timer has not, in every one of those runs.
Expected behavior

A value Firebase produced is handed to the subscriber as soon as the current task finishes, without an extra timer turn.

Actual behavior

Every value waits for a setInterval callback.

Ngôn ngữ chính
TypeScript
Star
7.8k
Fork
2.2k
Merge trung bình
2 ngày 12 giờ
Pull request đã merge (30 ngày)
24

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của angular/angularfire

Tất cả issue của angular/angularfire

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.