9.1.0: with zone.js, Promise continuations run on the background thread that resolved the promise (main thread in 9.0.3)
Maintainer antworten meist innerhalb von 1 Tag
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 45/100
- Issue-Typ
- Bug
- Klarheit
- Größtenteils klar
- Aktivitätsstatus
- Aktiv
- Tech-Stack
- ios, javascript, typescript
Rechercherichtung
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.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
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.
- Vorherrschende Sprache
- JavaScript
- Sterne
- 154
- Forks
- 46
- Ø Merge
- 4 T. 2 Std.
- Gemergte PRs (30 T.)
- 30
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Keine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus NativeScript/ios
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
NativeScript/ios#577 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 45/100
NativeScript/ios#572 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 12/100
NativeScript/ios#571 ·
Maintainer antworten meist innerhalb von 1 Tag
-
interop.FunctionReference function passed as a block, then as a function pointer, assertsEvtl. vergeben @edusperoni hat das vor 39 Tagen übernommen. Offen
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 22/100
NativeScript/ios#503 ·
Maintainer antworten meist innerhalb von 1 Tag
-
isImplementedInClass leaks the losing sample instance on re-entrant or racing cache populationOffen
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 38/100
NativeScript/ios#459 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in NativeScript/ios
Ähnliche Issues
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
sfbrigade/pocket-gardens#60 ·
Maintainer antworten meist innerhalb von 5 Tagen
-
The print preview leaves writing space short by the margins of hidden headers, footers and solutionsOffen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
PreTeXtBook/pretext#3329 ·
Maintainer antworten meist innerhalb von 1 Tag
-
could-have
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 88/100
-
01 type: bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
Maintainer antworten meist innerhalb von 2 Tagen
-
accepted enhancement
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
Maintainer antworten meist innerhalb von 1 Tag