Title: feat(vite)!: thin dev mode, the device as a standard Vite client by edusperoni · Pull Request #11650 · NativeScript/NativeScript · GitHub
Open Graph Title: feat(vite)!: thin dev mode, the device as a standard Vite client by edusperoni · Pull Request #11650 · NativeScript/NativeScript
X Title: feat(vite)!: thin dev mode, the device as a standard Vite client by edusperoni · Pull Request #11650 · NativeScript/NativeScript
Description: PR Checklist The PR title follows our guidelines: https://github.com/NativeScript/NativeScript/blob/master/tools/notes/CONTRIBUTING.md#commit-messages. There is an issue for the bug/feature this PR is for. To avoid wasting your time, it's best to open a suggestion issue first and wait for approval before working on it. You have signed the CLA. All existing tests are passing: https://github.com/NativeScript/NativeScript/blob/master/tools/notes/DevelopmentWorkflow.md#unit-testing. Tests for the changes are included - https://github.com/NativeScript/NativeScript/blob/master/tools/notes/WritingUnitTests.md. Draft. This PR rebuilds @nativescript/vite dev mode ("thin mode") so the device behaves like a standard Vite client. The as-built design is in tools/vite-server-env-spike/DESIGN.md. The rest of the spike harness (fixtures, probes, crawls, findings log) is kept locally and is no longer tracked. Companion PRs: NativeScript/angular#183 (bootstrap after launch, per-component styles); NativeScript/nativescript-cli#6208 (app restart over IPC); NativeScript/nativescript-cli#6209 (single-process dev, debug cleartext for Android; stacked on #6208). What is the current behavior? Dev mode re-implements a lot of Vite on top of Vite, and has its own protocol for the device: Module serving: modules go through a custom /ns/m rewrite pipeline and /ns/* routes, with their own resolution, URL canonicalization and hot-context injection. The same file can be served under several URLs, which gives duplicate module instances: @nativescript/core through the /ns/core bridge plus two /ns/m spellings, and rxjs with and without its extension. HMR: a NativeScript-specific update protocol and socket bridge. Vite's stock payloads (for example css-update) never reach the device. Dependencies: a NativeScript dependency bundle and vendor layer instead of Vite's optimizer, plus a global require shim that turned unknown modules into {}. Boot: a placeholder root plus a patched first-boot Application.run, and scattered __NS_* / global.__x globals. Angular: custom build transforms (decorator synthesizers, extra linker layers) that also left release bundles unminified. Processes: two Vite processes per dev session. Android HMR: depends on files written to disk for the static binding generator. What is the new behavior? packages/vite: 420 files changed, +15.5k / −64.0k lines across 35 commits. The phase log is below. Device side: The device runs Vite's client-environment output on plain Vite URLs, served by Vite's own middleware. It joins Vite's HMR socket with a port of Vite's browser client. ?t= is part of module identity. There is no NativeScript-specific module or update protocol. NativeScript's own endpoints live under /__ns_dev__. Reload model: In place: hot updates apply where they can. Soft reboot: edits that reach the app entry soft-reboot through an entry HMR boundary, with nativescript:beforeReboot / beforeRerun / afterReboot / beforeRestart events for libraries. App restart: a Vite full reload, and any edit to once-per-process code (core, @nativescript/vite, Android's custom Application), restarts the app through CLI IPC. Compile errors: they never tear the app down. A withheld update is replayed as one soft reboot once the error is fixed (a stylesheet-only fix restyles in place). Dependencies: Vite's own optimizer pre-bundles dependencies; an installed core is pre-bundled by default. Served modules get a module-scoped require and never the global one. A strict shadow of the global require is on by default (NS_VITE_STRICT_REQUIRE=0 turns it off). --env.watchNodeModules only adds standard server.watch.ignored negations. Boot: Dev boots like release: bundle.mjs is a small loader, and the app's own run() launches. Lean fallback screens cover a dev server that can't be reached and boot errors (UIKit on iOS, an activity on Android). Each restarts the app when the server comes back or on the fixing save. The /__ns_dev__ action routes need a per-session token. The dev server listens on every interface, IPv6 included (server.host: true). NS_HMR_HOST only sets the host devices are told to use; a bare IPv6 address is bracketed. Single-process dev (iOS, visionOS, Android), with NativeScript/nativescript-cli#6209: vite serve alone writes bundle.mjs, package.json, the assets and, on Android, a custom Application chunk built with the app's own config. The package declares support under nativescriptCli.singleProcessDev. Every old/new package × CLI combination keeps a working path. Android: App components and core's NativeScriptActivity are served and imported by the boot module ahead of the entry. Their named classes are generated at runtime while the runtime holds Application.onCreate, so only a custom Application still needs a file on disk. One core instance. Angular: Analog does all the compilation; the custom transforms and the CommonJS shim are removed. Release bundles are minified again. --no-hmr works (the compilation API is off). A release guard fails the build on unlinked partial declarations. @analogjs/vite-plugin-angular ^2.7.1 is required. Vue and TS/XML: Vue uses plugin-vue's own HMR plus an entry soft reboot. TS/XML apps soft-reboot through the entry. app.css is a Vite CSS module. Verified: Unit tests: packages/vite vitest passes 921 tests, also through nx run vite:test from the workspace root. iOS simulator: Angular 22 + Analog 2.9.7 and nativescript-vue 3.1 fixtures, plus the toolbox through crawls. Physical devices: iPhone 11 Pro on iOS 26 and iPad Pro on iOS 27, for boot timing and HTTP caching against the runtime changes below. Android emulator: API 35, Vue and Angular. Release builds: iOS and Android. Runtime dependencies NativeScript/ios: #585 (HTTP cache + persistent connections) and #586 (specifier resolution from HTTP modules) are verified on device with this branch. Once they're released, thin mode requires them, and the device-imports origin rewrite and the HMR client's absolute URLs are removed. #584 (worker-teardown crash) is merged. NativeScript/android: #2124 (draft): after a blocked error screen, a stale error-report marker made the next launch skip runtime init. Known gaps Analog: any non-component .ts save clears Analog's classNames map, so the next Angular template edit soft-reboots instead of updating in place. This is upstream behaviour: analogjs/analog#2816, fixed by analogjs/analog#2817. Solid and React: unchanged (notes only). Toolbox: not run on Vite on a device. Removed assets: they stay on the device until reinstall. Android: A custom Application's new overridden methods or interfaces still need ns run again, as with webpack today: Application changes don't trigger a native rebuild. Body edits apply (rebuild → sync → restart). The inspector loads inspector_modules by bare name. The runtime holds startup on module fetches nobody awaits; the package works around this with a port probe. Phase log Phase Commit What 1 ed72bef83 Thin mode is unconditional; the /ns/m pipeline is deleted (≈17.8k lines) 2 6e6fe1e96 The device joins Vite's HMR socket and runs a port of Vite's client; ?t= is part of module identity; the NS update protocol is deleted 2b 28a8f5149 App restart for changes a hot update can't apply (IPC to the CLI: NativeScript/nativescript-cli#6208) 2c b2eb5959e Soft reboot through the app entry's HMR boundary; nativescript:beforeReboot / beforeRerun / afterReboot / beforeRestart events 2d 083d0ace4 Compile errors never tear the app down; load-time errors stay recoverable; error overlay with "Restart app"; boot catch-up 3a bcc327d77 config.define is the single source of defines; one namespaced Symbol.for('nativescript.dev') global 3b 883c6451b Plain Vite URLs through Vite's own middleware; NS endpoints under /__ns_dev__; no /ns/* routes left 3c 757e11380 NativeScript's own dev pre-bundling removed (deps bundle, vendor layer); zero duplicate module instances 4a 541e11cb9 TS/XML apps soft-reboot through the entry; app.css as a Vite CSS module for every flavor; workers owned by the module that created them 4b 690b27ecb Vue: plugin-vue HMR plus an entry-boundary soft reboot; a dev require miss throws a clear error; the dev type check never blocks the watch build 5a.1 d1509a553 Boot through a Vite-served module: bundle.mjs under 1 KB, no global require shim 5a.2 0a43ce9d1 Vite's optimizer pre-bundles dev deps; module-scoped require instead of the global one. Cold requests: Angular 707 → 332, Vue 481 → 327 watch 4937c3879, 77e2e3d21 --env.watchNodeModules = per-dependency server.watch.ignored negations; not watched by default 5c 54524c046 Dev boots like release; placeholder machinery deleted (−3,244 lines); UIKit fallback screen 5c.2 701162c3a One boot when the server returns; token on the action routes; installed core pre-bundled by default (iPhone 11 Pro: ~320 → ~80 requests, launch 1.6–2.0 s) 5c.3 71fa3dc44, 2acc6410d, 656f7d7ac Per-session dev token kept out of the served tree; device HTTP caching kept correct (/__ns_dev__ no-store, origin-tagged ETags, no immutable on non-pre-bundle ?v= files) fix 5e03cf963 Withheld updates replayed as one soft reboot; dependency scan survives an unresolvable import; entry boundary keeps a source map; root nx tests cleanup c74cfb274 Unused deps, exports, __NS_* globals and toolbox spike files removed tidy 192b0dcff, 2a1c7d3d2, ed6eb56c8, 50edfe7f7 Stylesheet-only fixes restyle in place; overlay position setting removed; strict global require on by default; spike harness untracked single 8a9e6e074 Single-process dev on iOS/visionOS (Android added in 14fcb7ddf) angular c5b62ddf3 Custom Angular build transforms and the CommonJS shim removed (−3.2k lines); release bundles minified; --no-hmr fixed; release guard; Analog peer ^2.7.1 android c96b9c688, 9f8b6300b Android dev: served app components + runtime-generated activity, one core, Android fallback screen; Angular HMR output from build mode android-single 14fcb7ddf, e41163ad1 Single-process dev on Android (the dev server builds the custom Application chunk with the app's own config); Application edits are an HMR rejection: rebuild → sync → restart ipv6 79c30e03c Dev server listens dual-stack; NS_HMR_HOST no longer sets the bind; bare IPv6 device hosts are bracketed
Open Graph Description: PR Checklist The PR title follows our guidelines: https://github.com/NativeScript/NativeScript/blob/master/tools/notes/CONTRIBUTING.md#commit-messages. There is an issue for the bug/feature this...
X Description: PR Checklist The PR title follows our guidelines: https://github.com/NativeScript/NativeScript/blob/master/tools/notes/CONTRIBUTING.md#commit-messages. There is an issue for the bug/feature this...
Opengraph URL: https://github.com/NativeScript/NativeScript/pull/11650
X: @github
Domain: github.com
| 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 | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:92da54be-bb12-753c-ed6e-731595d1557d |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | E09A:2F4BD9:1690573:1DC2836:6B01303A |
| html-safe-nonce | 935b43c83c656fda803b950f443cabb2380d639b6a0ae75aaedef62e2d47a1f0 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMDlBOjJGNEJEOToxNjkwNTczOjFEQzI4MzY6NkIwMTMwM0EiLCJ2aXNpdG9yX2lkIjoiODAwNDM5MTc4OTU0NzA0MDgyNiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | e9e3cec2b0eac0cb091577216be56de15e6392b50e365d73656249ab5042fc33 |
| hovercard-subject-tag | pull_request:5384863132 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,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/NativeScript/NativeScript/pull/11650/files |
| twitter:image | https://avatars.githubusercontent.com/u/4061767?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/4061767?s=400&v=4 |
| og:image:alt | PR Checklist The PR title follows our guidelines: https://github.com/NativeScript/NativeScript/blob/master/tools/notes/CONTRIBUTING.md#commit-messages. There is an issue for the bug/feature this... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/NativeScript/NativeScript git https://github.com/NativeScript/NativeScript.git |
| octolytics-dimension-user_id | 7392261 |
| octolytics-dimension-user_login | NativeScript |
| octolytics-dimension-repository_id | 31492490 |
| octolytics-dimension-repository_nwo | NativeScript/NativeScript |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 31492490 |
| octolytics-dimension-repository_network_root_nwo | NativeScript/NativeScript |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| 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 |
Links:
Viewport: width=device-width