Repository navigation
feat(vite): restart the app when the Vite dev server asks for it - #6208
edusperoni wants to merge 2 commits into
Conversation
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
|
Verified end to end on an iOS 26.3 simulator. The Angular 22 fixture from NativeScript/NativeScript#11650 ran through this branch's CLI (
|
437a3bc to
acb5ec6
Compare
`vite serve` is now spawned with an IPC channel. When it sends
`{ type: 'nativescript:restart', reason }`, the CLI logs the reason and
restarts the app on that platform's devices in the running session,
without rebuilding or syncing. Requests that arrive within 300 ms
collapse into one restart. The restart joins the session's action chain,
so it runs after any sync or build already in progress. It reuses
RunController.restartApplication, which keeps debug sessions attached.
Other message shapes are ignored, and dev servers that never send one
behave as before.
Its stdin depends on whether the CLI's key shortcuts will read the terminal, which the startViteDevServer specs pin. The spawn comment no longer claims a silent server behaves as with plain inherit.
acb5ec6 to
8bb8f95
Compare
PR Checklist
What is the current behavior?
The CLI spawns
vite serve(the Vite HMR dev server) withstdio: "inherit", so the dev server has no channel back to the CLI. Some changes can't be applied as a hot update, and the dev server has no way to get the app process restarted for them.In
@nativescript/vitethin client mode (NativeScript/NativeScript#11650), most edits are applied in place: a hot update, or a soft reload that re-evaluates the app's own modules inside the running process. Some changes need a fresh process instead:node_modules, linked core, the dev client);vite.configchange, after which Vite restarts its server;import.meta.hot.decline();What is the new behavior?
vite serveis spawned with an IPC channel:stdio: ["inherit", "inherit", "inherit", "ipc"]. Its output still goes straight to the terminal.Contract. The dev server may send this message over that channel:
reasonis a human-readable string. One message may stand for several requests that the dev server already collapsed. Any other message shape is ignored without a log, so newer@nativescript/viteversions can add message types without breaking this CLI.Flow.
BundlerCompilerServicereceives the message and debounces per platform. Requests that arrive within 300 ms collapse into one, with their distinct reasons joined by;. It then emits the newBUNDLER_APP_RESTART_REQUESTEDevent with{ projectDir, platform, reason }.RunControllersubscribes to that event inrun()and unsubscribes instop(). It looks up the session's devices on that platform, logsRestarting the app on <platform>: <reason>at info level, and calls the existingrestartApplication({ projectDir, deviceIdentifiers }). That is the same path therkey shortcut uses: nothing is prepared, built or synced; it waits behind any sync or build already queued on the session's action chain; it goes throughrefreshApplication, so debug sessions get their debugger re-attached; and errors are reported per device. If the session has no device on that platform, nothing is restarted.Backwards compatibility.
@nativescript/viteversions never send anything over the channel, so behaviour is unchanged. The onlyprocess.senduse in released versions is thenativescript-cli-integrationplugin, which isapply: 'build'and doesn't run undervite serve. Vite itself doesn't use the channel.terminate()as before. A child with nomessagelistener exits normally, and the parent exits once the child does. The debounce timer isunref'd.vite serve, so nothing changes for them.Tests.
emittedFilesshape; a pending request is dropped when the dev server stops.Related to NativeScript/NativeScript#11650.
Summary by CodeRabbit