Repository navigation
feat(vite): single-process HMR dev and debug cleartext for Android - #6209
Draft
edusperoni wants to merge 4 commits into
Draft
edusperoni wants to merge 4 commits into
edusperoni wants to merge 4 commits into
Conversation
…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.
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
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. |
Draft
4 of 5 tasks
…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.
4 of 5 tasks
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Checklist
What is the current behavior?
vite servefor HMR andvite build --watchto producebundle.mjs,package.jsonand the app's static files that the CLI copies into the native project.127.0.0.1throughadb 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)
@nativescript/vitelists the platform undernativescriptCli.singleProcessDevin itspackage.json, the CLI spawns onlyvite servewithNS_VITE_SINGLE_PROCESS=1and does not start thevite build --watchchild.bundle.mjs,package.jsonand the app's static files into the staging directory itself and sends the same build messagesvite build --watchsends today. The CLI takes those messages from thevite servechild, copies and syncs on them as before, and launches the app on the first one. One Vite process instead of two.removedFileslist, which the CLI deletes from the native app folder (assets removed during a session).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=0in the CLI's environment opts out.Debug-only cleartext for Android Vite HMR runs
platforms/android/app/src/debug/AndroidManifest.xml) withandroid:usesCleartextTraffic="true"(andtools:replacefor it). An app that ships its own debug manifest inApp_Resourcesgets the attribute added to the copied file instead.App_Resourcesis 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.networkSecurityConfigtakes precedence over the attribute and has to allow the dev host itself.hostProjectPath) are skipped: native prepare doesn't write the manifest there, so the change check must not compare it.Verification
@nativescript/vite× new / old CLI, each combination takes a working path (single-process only when both sides are new).usesCleartextTrafficin its merged manifest (checked withaapt2).Stacked on #6208. Pairs with NativeScript/NativeScript#11650.