9.1.0: with zone.js, Promise continuations run on the background thread that resolved the promise (main thread in 9.0.3)
Les mainteneurs répondent en général sous 1 jour
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Accessibilité débutants
- 45/100
- Type d'issue
- Bug
- Clarté
- Plutôt claire
- Activité
- Active
- Stack technique
- ios, javascript, typescript
Piste de recherche
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.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
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.
- Langage dominant
- JavaScript
- Étoiles
- 154
- Forks
- 46
- Merge moyen
- 4 j 2 h
- PR mergées (30 j)
- 30
Préparer son environnement
- Aucun Dockerfile ni fichier Docker Compose
- Aucun modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de NativeScript/ios
-
Difficulté 2/5 1-3 heures Accessibilité débutants 76/100
NativeScript/ios#577 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 4/5 3-5 jours Accessibilité débutants 45/100
NativeScript/ios#572 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 12/100
NativeScript/ios#571 ·
Les mainteneurs répondent en général sous 1 jour
-
interop.FunctionReference function passed as a block, then as a function pointer, assertsPeut-être pris @edusperoni l’a pris il y a 39 jours. Ouverte
Difficulté 4/5 3-5 jours Accessibilité débutants 22/100
NativeScript/ios#503 ·
Les mainteneurs répondent en général sous 1 jour
-
isImplementedInClass leaks the losing sample instance on re-entrant or racing cache populationOuverte
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 38/100
NativeScript/ios#459 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
Toutes les issues de NativeScript/ios
Issues similaires
-
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
sfbrigade/pocket-gardens#60 ·
Les mainteneurs répondent en général sous 5 jours
-
The print preview leaves writing space short by the margins of hidden headers, footers and solutionsOuverte
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
PreTeXtBook/pretext#3329 ·
Les mainteneurs répondent en général sous 1 jour
-
could-have
Difficulté 1/5 Moins d'une heure Accessibilité débutants 88/100
-
01 type: bug
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
Les mainteneurs répondent en général sous 2 jours
-
accepted enhancement
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
Les mainteneurs répondent en général sous 1 jour