Skip to content

feat(vite): single-process HMR dev and debug cleartext for Android - #6209

Draft
edusperoni wants to merge 4 commits into
feat/vite-restart-ipcfrom
feat/vite-single-process
Draft

edusperoni wants to merge 4 commits into
feat/vite-restart-ipcfrom
feat/vite-single-process

Conversation

@edusperoni

Copy link
Copy Markdown
Collaborator

PR Checklist

Stacked on #6208 (feat/vite-restart-ipc); review that one first. Pairs with NativeScript/NativeScript#11650 (the @nativescript/vite side).

What is the current behavior?

  • A Vite HMR session runs two Vite processes per platform: vite serve for HMR and vite build --watch to produce bundle.mjs, package.json and the app's static files that the CLI copies into the native project.
  • On Android, a Vite HMR app loads its code from the dev server (127.0.0.1 through adb reverse) over plain HTTP. Android blocks cleartext HTTP by default since API 28, so the app cannot reach the dev server unless the project opts in by hand.

What is the new behavior?

Single-process HMR dev (iOS / visionOS)

  • When the installed @nativescript/vite lists the platform under nativescriptCli.singleProcessDev in its package.json, the CLI spawns only vite serve with NS_VITE_SINGLE_PROCESS=1 and does not start the vite build --watch child.
  • The dev server writes bundle.mjs, package.json and the app's static files into the staging directory itself and sends the same build messages vite build --watch sends today. The CLI takes those messages from the vite serve child, copies and syncs on them as before, and launches the app on the first one. One Vite process instead of two.
  • A build message may now carry an optional removedFiles list, which the CLI deletes from the native app folder (assets removed during a session).
  • The serve process is tracked as the platform's bundler process; a serve exit before its first message fails the run, and stopping the session terminates it once.
  • The capability is a handshake: a package without the field keeps the two-process session, and an older CLI never sets NS_VITE_SINGLE_PROCESS, so the package keeps its two-process behavior. Every old/new package + CLI combination stays on a working path. NS_VITE_SINGLE_PROCESS=0 in the CLI's environment opts out.

Debug-only cleartext for Android Vite HMR runs

  • For a debug build with HMR on and the Vite bundler, native prepare writes a debug source set manifest (platforms/android/app/src/debug/AndroidManifest.xml) with android:usesCleartextTraffic="true" (and tools:replace for it). An app that ships its own debug manifest in App_Resources gets the attribute added to the copied file instead.
  • App_Resources is never modified. Any other prepare (release, --no-hmr, another bundler) removes the file the CLI wrote, and the change check compares the wanted state with the native project so switching modes rebuilds the app.
  • Because it lives in the debug source set, the attribute never reaches release builds. An app's own networkSecurityConfig takes precedence over the attribute and has to allow the dev host itself.
  • Host projects (hostProjectPath) are skipped: native prepare doesn't write the manifest there, so the change check must not compare it.

Verification

  • iOS simulator, Vue and Angular apps in single-process mode: boot, edits, boot-error card, server-down fallback, and assets added / changed / removed.
  • Compatibility matrix: new / old @nativescript/vite × new / old CLI, each combination takes a working path (single-process only when both sides are new).
  • Android emulator API 35: debug HMR run reaches the dev server with cleartext enabled; a release build has no usesCleartextTraffic in its merged manifest (checked with aapt2).
  • CLI unit suite: 2179 tests passing, including new specs for the single-process session and the cleartext manifest.

Stacked on #6208. Pairs with NativeScript/NativeScript#11650.

…ports it

When the installed @nativescript/vite lists the platform under
`nativescriptCli.singleProcessDev` in its package.json, the CLI spawns
only `vite serve` with NS_VITE_SINGLE_PROCESS=1. The server writes
bundle.mjs, package.json and the app's static files into the staging
directory and sends the build messages `vite build --watch` sends today;
the CLI copies and syncs on them as before and launches the app on the
first. Packages without the field keep the two-process session, and
NS_VITE_SINGLE_PROCESS=0 in the CLI's environment opts out.

A build message may now carry `removedFiles`, which the CLI deletes from
the native app folder. The serve process is tracked as the platform's
bundler process, a serve exit before its first message fails the run,
and stopping the session terminates it once.
…MR builds

A Vite HMR app on Android loads its code from the dev server over plain
HTTP, which Android blocks by default from API 28. For a debug build with
HMR on and the Vite bundler, the native prepare now writes a debug source
set manifest (platforms/android/app/src/debug/AndroidManifest.xml) with
android:usesCleartextTraffic="true" and tools:replace for it. An app that
ships its own debug manifest in App_Resources gets the attribute added to
the copied file instead. App_Resources is never modified.

Any other prepare (release, --no-hmr, another bundler) removes the file the
CLI wrote. The Android project's change check compares the wanted state
with the native project and marks app resources changed when they differ,
so switching rebuilds the app. A networkSecurityConfig of the app's own
takes precedence over the attribute and has to allow the dev host itself.
Native prepare doesn't write the debug manifest under hostProjectPath, so comparing it there would mark app resources changed on every prepare.
@coderabbitai

coderabbitai Bot commented Nov 20, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

…yncs

Under Vite HMR every file the CLI syncs (bundle.mjs, a static file, a
custom Application chunk) is applied by restarting the app. With
useHotModuleReload set, the Android sockets live sync still marked every
file as a fast sync and asked the app to refresh first, which runs
__onLiveSync: it can't reload an app Vite serves, and on Angular it threw
"Main entry is missing". The uncaught exception then left the runtime's
hasError marker, so the restart crashed with ClassNotFoundException and
the CLI waited on the livesync socket.

Single-process dev on Android now sends static file and Application
changes to the CLI, which reaches this path.
@NathanWalker NathanWalker added this to the 9.2 milestone Nov 21, 2026

This branch has not been deployed

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

2 participants