9.1.0: with zone.js, Promise continuations run on the background thread that resolved the promise (main thread in 9.0.3)

Ouverte
#528 1 commentaire 0 réactions 0 personnes assignées Voir sur GitHub

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
Domaine
backend, mobile

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 in v8::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 with NSInternalInconsistencyException: Call must be made on main thread. The half-presented picker stays as presentedViewController, so every later presentViewController fails ("… whose view is not in the window hierarchy") until the app restarts.
  • HealthKit: HKHealthStore requestAuthorizationToShareTypes:readTypes:completion: (via nativescript-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/imagepicker 4.1.0 and @nativescript-community/perms 2.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

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de NativeScript/ios

Toutes les issues de NativeScript/ios

Issues similaires

Plus d'issues JavaScript

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.