Skip to content

fix(vite): await the client strategy before /ns/rt $navigateTo reports the navigator missing - #11424

Merged
NathanWalker merged 1 commit into
NativeScript:mainfrom
sitefinitysteve:fix/vite-ns-rt-navigate-await-strategy
Sep 10, 2026
Merged

NathanWalker merged 1 commit into
NativeScript:mainfrom
sitefinitysteve:fix/vite-ns-rt-navigate-await-strategy

Conversation

@sitefinitysteve

Copy link
Copy Markdown
Contributor

PR Checklist

What is the current behavior?

Under HMR the served /ns/rt bridge replaces nativescript-vue's $navigateTo with one that routes through globalThis.__nsNavigateUsingApp. That global is installed by the Vue client strategy's install(), which runs in the .then() of the dynamic import() in hmr/client/strategy-loader.ts — one HTTP fetch on device that nothing awaits before app code runs. Measured on an iOS simulator the navigator shows up ~400ms after root mount, so a root/loader component that navigates shortly after mount (auth check → $navigateTo(Home)) throws:

Error: $navigateTo unavailable: app navigator missing

The same code works with --no-hmr. Details and measurements in #11422.

What is the new behavior?

  • The /__ns_dev__/client bootstrap wrapper (createNsDevClientBootstrapCode) creates a deferred globalThis.__NS_CLIENT_STRATEGY_READY__ when it evaluates — that is before the app entry is imported, whereas the full client (and with it strategy-loader.ts) is only imported once __NS_HMR_BOOT_COMPLETE__ flips, i.e. after the entry has evaluated. strategy-loader.ts settles that deferred when CLIENT_STRATEGY_READY settles (or publishes its own promise on hosts without the wrapper). If the full client fails to start, the wrapper settles it too, so callers reject instead of hanging. The generated bridge can't import the loader; it only sees globalThis.
  • The bridge's $navigateTo still calls the navigator synchronously when it is already installed. When it isn't, it now returns __NS_CLIENT_STRATEGY_READY__.then(...), navigating once the strategy has installed the navigator, and only throws app navigator missing once the strategy has settled without installing one. With no readiness promise on the global (non-HMR hosts, tests) it throws synchronously exactly as before.
  • __navigateNow / __navigatorMissing are added to RESERVED_BRIDGE_LOCALS so a vendor export can't collide with the helpers.
  • A spec in vite-plugin-path.spec.ts pins the deferred to the wrapper, ahead of the socket connect, and the settle-on-failure path. Tests in ns-rt-bridge.spec.ts lift the generated $navigateTo out of the module text and evaluate it against a stub global: sync path, late-install path, settled-without-navigator path, no-promise path, and navigator errors surfacing unchanged.

Note on the return value: in the not-yet-ready case $navigateTo returns a Promise instead of undefined. The bridge's navigator already returns undefined (not the Page the stock helper returns), so no caller inside the package depends on the value; app code that awaits or ignores it is unaffected.

Verified on device (iOS simulator, blank ns create Vue app + nativescript-vite init): a root component navigating 150ms after mount fails with the published 8.0.5 and navigates with this build; live edits still hot-reload.

Fixes #11422.

@nx-cloud

nx-cloud Bot commented Sep 9, 2026

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit a95bc50

Command Status Duration Result
nx test apps-automated -c=android ✅ Succeeded 4m 33s View ↗
nx run-many --target=test --configuration=ci --... ✅ Succeeded 5s View ↗

💡 Verify your cache is correct by running tasks in a sandbox. Read docs ↗


☁️ Nx Cloud last updated this comment at 2026-09-09 23:33:35 UTC

@pkg-pr-new

pkg-pr-new Bot commented Sep 9, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@nativescript/core@11424
npm i https://pkg.pr.new/@nativescript/vite@11424
npm i https://pkg.pr.new/@nativescript/webpack@11424

commit: a95bc50

@NathanWalker
NathanWalker merged commit 0be657f into NativeScript:main Sep 10, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Vite, Vue, HMR] /ns/rt $navigateTo throws "app navigator missing" for ~400ms after mount because the client strategy install isn't awaited

2 participants