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

Offen
#528 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

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

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 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.

Vorherrschende Sprache
JavaScript
Sterne
154
Forks
46
Ø Merge
4 T. 2 Std.
Gemergte PRs (30 T.)
30

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus NativeScript/ios

Alle Issues in NativeScript/ios

Ähnliche Issues

Weitere Issues zu JavaScript

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.