9.1.0: with zone.js, Promise continuations run on the background thread that resolved the promise (main thread in 9.0.3)
維護者通常 1 天內回覆
還沒有人認領這個 Issue。
評估
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 新手友好度
- 45/100
- Issue 類型
- 缺陷
- 描述清晰度
- 基本清楚
- 活躍度
- 活躍
- 技術堆疊
- ios, javascript, typescript
研究方向
Start by comparing the PromiseProxy change in #396 with the 9.0.3 and 9.1.0 behavior described here, using the supplied zone.js reproduction in app/app.ts. Check how zone.js schedules promise continuations after a background GCD queue resolves the promise, and verify whether the callback returns to the main thread. Done means zone.js promises and runtime promises both run continuations on the main thread in 9.1.0.
由索引模型根據 Issue 內容生成。
描述
Summary
In @nativescript/ios 9.1.0, when zone.js is loaded (as in every NativeScript Angular app), a promise created on the main thread and resolved from a background GCD queue runs its .then() callbacks on that background thread. In 9.0.3 they ran on the main thread. The runtime's own (non-zone) Promise is still marshalled correctly in 9.1.0, so only zone.js promises are affected.
In a real app this means UIKit calls made after a native completion handler run off the main thread. For example, @nativescript/imagepicker calls present() after PHPhotoLibrary.requestAuthorization's handler resolves a promise.
Repro
Blank app (ns create repro --ts), [email protected], @nativescript/core 9.1.3. Replace app/app.ts with:
import 'zone.js'
import { Application } from '@nativescript/core'
function check(label: string, P: PromiseConstructor) {
const p = new P<void>((resolve) => {
dispatch_async(dispatch_get_global_queue(0, 0), () => resolve())
})
p.then(() => console.log(`[repro] ${label}: then() runs on main thread = ${NSThread.isMainThread}`))
}
setTimeout(() => {
check('zone.js Promise (global)', Promise)
check('runtime Promise (__zone_symbol__Promise)', (globalThis as any).__zone_symbol__Promise)
}, 2000)
Application.run({ moduleName: 'app-root' })
Output, iOS 26.3 simulator:
@nativescript/ios |
zone.js Promise |
runtime Promise |
|---|---|---|
| 9.0.3 | then() runs on main thread = true |
true |
| 9.1.0 | then() runs on main thread = false |
true |
Without zone.js, 9.1.0 behaves correctly: .then() and an await continuation both run on the main thread.
Impact in our app (9.1.0)
- iOS 26.3 simulator: opening the photo picker after the Photos permission check aborts the app (
EXC_BREAKPOINT). The faulting thread is a background thread running-[UIViewController presentViewController:animated:completion:]←ffi_call←tns::Interop::CallFunctionInternal, while the main thread waits inv8::Locker::Locker. - iPhone 11, iOS 27.0.1: no crash. UIKit logs "Modifying properties of a view's layer off the main thread is not allowed", then
*** Assertion failure in … UIApplication.m:3444, and the promise rejects withNSInternalInconsistencyException: Call must be made on main thread. The half-presented picker stays aspresentedViewController, so every laterpresentViewControllerfails ("… whose view is not in the window hierarchy") until the app restarts. - HealthKit:
HKHealthStore requestAuthorizationToShareTypes:readTypes:completion:(vianativescript-health-data) shows the same thing: "Modifications to the layout engine must not be performed from a background thread". - Production build on 9.0.3 (same
@nativescript/imagepicker4.1.0 and@nativescript-community/perms2.3.6), same device, same steps: works, with no off-main-thread messages.
Environment
@nativescript/ios 9.1.0 vs 9.0.3, @nativescript/core 9.1.3, zone.js 0.16.3 (in the app: Angular 22.2, @nativescript/angular 22.0.2). NativeScript CLI 9.0.7, Xcode 26.3.
Possibly related
#396 ("only marshal promise resolution when created on the runtime loop", merged 2026-07-08, fixes #330) is the only PromiseProxy change we found between 9.0.3 and 9.1.0. zone.js keeps the original Promise and schedules its microtasks through it, so this change may affect zone's microtask drain. We haven't confirmed that #396 is the cause.
Workaround
Pin @nativescript/ios to 9.0.3 and keep @nativescript/core 9.1.3. On that combination core installs atob/btoa as getter-only globals, so app code that assigns them needs a guard.
- 主要語言
- JavaScript
- 星號
- 154
- 分支
- 46
- 平均合併
- 4 天 2 小時
- 30 天內合併 PR
- 30
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 沒有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
NativeScript/ios 的其他 Issue
-
難度 2/5 1-3 小時 新手友好度 76/100
NativeScript/ios#577 ·
維護者通常 1 天內回覆
-
難度 4/5 3-5 天 新手友好度 45/100
NativeScript/ios#572 ·
維護者通常 1 天內回覆
-
難度 5/5 一週以上 新手友好度 12/100
NativeScript/ios#571 ·
維護者通常 1 天內回覆
-
interop.FunctionReference function passed as a block, then as a function pointer, asserts可能已有人在做 @edusperoni 於 39 天前認領。 未關閉
難度 4/5 3-5 天 新手友好度 22/100
NativeScript/ios#503 ·
維護者通常 1 天內回覆
-
難度 5/5 一週以上 新手友好度 38/100
NativeScript/ios#459 · 1 則留言 ·
維護者通常 1 天內回覆
相似的 Issue
-
難度 2/5 1-3 小時 新手友好度 68/100
sfbrigade/pocket-gardens#60 ·
維護者通常 5 天內回覆
-
The print preview leaves writing space short by the margins of hidden headers, footers and solutions未關閉
難度 2/5 1-3 小時 新手友好度 78/100
PreTeXtBook/pretext#3329 ·
維護者通常 1 天內回覆
-
could-have
難度 1/5 1 小時以內 新手友好度 88/100
-
01 type: bug
難度 2/5 1-3 小時 新手友好度 72/100
維護者通常 2 天內回覆
-
accepted enhancement
難度 2/5 1-3 小時 新手友好度 78/100
維護者通常 1 天內回覆