Title: 9.1.0: with zone.js, Promise continuations run on the background thread that resolved the promise (main thread in 9.0.3) · Issue #528 · NativeScript/ios · GitHub
Open Graph Title: 9.1.0: with zone.js, Promise continuations run on the background thread that resolved the promise (main thread in 9.0.3) · Issue #528 · NativeScript/ios
X Title: 9.1.0: with zone.js, Promise continuations run on the background thread that resolved the promise (main thread in 9.0.3) · Issue #528 · NativeScript/ios
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...
Open Graph 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() cal...
X 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() cal...
Opengraph URL: https://github.com/NativeScript/ios/issues/528
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"9.1.0: with zone.js, Promise continuations run on the background thread that resolved the promise (main thread in 9.0.3)","articleBody":"### Summary\n\nIn `@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.\n\nIn 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.\n\n### Repro\n\nBlank app (`ns create repro --ts`), `zone.js@0.16.3`, `@nativescript/core` 9.1.3. Replace `app/app.ts` with:\n\n```ts\nimport 'zone.js'\nimport { Application } from '@nativescript/core'\n\nfunction check(label: string, P: PromiseConstructor) {\n const p = new P\u003cvoid>((resolve) => {\n dispatch_async(dispatch_get_global_queue(0, 0), () => resolve())\n })\n p.then(() => console.log(`[repro] ${label}: then() runs on main thread = ${NSThread.isMainThread}`))\n}\n\nsetTimeout(() => {\n check('zone.js Promise (global)', Promise)\n check('runtime Promise (__zone_symbol__Promise)', (globalThis as any).__zone_symbol__Promise)\n}, 2000)\n\nApplication.run({ moduleName: 'app-root' })\n```\n\nOutput, iOS 26.3 simulator:\n\n| `@nativescript/ios` | zone.js `Promise` | runtime `Promise` |\n|---|---|---|\n| 9.0.3 | `then() runs on main thread = true` | `true` |\n| 9.1.0 | `then() runs on main thread = false` | `true` |\n\nWithout zone.js, 9.1.0 behaves correctly: `.then()` and an `await` continuation both run on the main thread.\n\n### Impact in our app (9.1.0)\n\n- **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`.\n- **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.\n- **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\".\n- **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.\n\n### Environment\n\n`@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.\n\n### Possibly related\n\n#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.\n\n### Workaround\n\nPin `@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.\n","author":{"url":"https://github.com/VepretskiyD","@type":"Person","name":"VepretskiyD"},"datePublished":"2026-10-25T17:04:38Z","url":"https://github.com/NativeScript/ios/issues/528"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:75cab135-32e6-6e0d-4d7f-42c41dad1303 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | CE1E:296654:18C2914:21045C1:6B014C3D |
| html-safe-nonce | a10c9a2d3b7520c7c733ad11bc4171c4dd04ebe26ebdc4392aeb79fdc8202a1b |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDRTFFOjI5NjY1NDoxOEMyOTE0OjIxMDQ1QzE6NkIwMTRDM0QiLCJ2aXNpdG9yX2lkIjoiNzE0MjA5MTE3MTE2OTM4OTYyOSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 62c2ca21c1fdd424d85a0f4c72079fbdf8c04d945da9db2ad68f6e05301a3411 |
| hovercard-subject-tag | issue:6026999391 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/NativeScript/ios/528/issue_layout |
| twitter:image | https://opengraph.githubassets.com/9e6696ee3fa870279abc383aef0d874501161336d67b9ed4580575f3c1873413/NativeScript/ios/issues/528 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/9e6696ee3fa870279abc383aef0d874501161336d67b9ed4580575f3c1873413/NativeScript/ios/issues/528 |
| og:image:alt | 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() cal... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | VepretskiyD |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| go-import | github.com/NativeScript/ios git https://github.com/NativeScript/ios.git |
| octolytics-dimension-user_id | 7392261 |
| octolytics-dimension-user_login | NativeScript |
| octolytics-dimension-repository_id | 172934359 |
| octolytics-dimension-repository_nwo | NativeScript/ios |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 172934359 |
| octolytics-dimension-repository_network_root_nwo | NativeScript/ios |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width