Skip to content

feat(vite): framework registration API - #11358

Draft
NathanWalker wants to merge 6 commits into
mainfrom
feat/vite-framework-flavors
Draft

feat(vite): framework registration API #11358
NathanWalker wants to merge 6 commits into
mainfrom
feat/vite-framework-flavors

Conversation

@NathanWalker

Copy link
Copy Markdown
Contributor

Support for third-party frameworks to define and register their own NativeScript Vite HMR "flavors," enabling any framework to provide custom HMR strategies through their own packages.

Framework Flavor Extensibility

  • Added @nativescript/vite/framework API, exposing functions and types for registering and using custom framework flavors, including server and client strategy types and helpers like registerFrameworkFlavor, getFrameworkFlavor, and typescriptServerStrategy. (packages/vite/framework.ts)
  • Introduced logic to detect and use flavors declared by dependencies in their package.json (via nativescript.vite.flavor), enabling automatic flavor selection and configuration scaffolding for third-party frameworks.

Configuration and Runtime Integration

  • Updated the Vite configuration and runtime seed values to include the client strategy module path for custom flavors, allowing the device to load the correct HMR client strategy.
  • Modified the logger instantiation in baseConfig to accept an hmrActive parameter, supporting improved logging for HMR scenarios.

…ooks for client strategies

The device hot registry kept `hot.accept` callbacks but nothing ever fired
them, and it had no dependency form. A framework strategy can now read a
module's accept callbacks before eviction (`getAcceptCallbacks`), find the
importers that accept a changed path by name (`accept('./dep', cb)` →
`getDepAcceptors` / `acceptsDep`), and hook the shared queue at the points
Vite's own client uses: `beforeBatchEvict` (snapshot accept, drain dispose),
`shouldQueueReimport` / `applyUnqueuedChanges` (modules this realm never
loaded — worker scripts, type-only files — must not evaluate here), and
`handleGraphResync` (one ordered reload instead of piecemeal re-imports
after a dev-server restart).

The JS full reload now drains `hot.dispose` first, evicts only app-owned
modules — evicting `/ns/core` minted a second `View` hierarchy the live tree
failed `instanceof` against — and reports `ns:full-reload-complete` /
`ns:full-reload-failed` so a strategy can finish what it deferred.

The shared hot-update prologue read a changed module's `importedModules`
before awaiting the transform that discovers them, so a newly added import
reached the client graph one save late; it reads them after the transform.
`cleanCode` stripped every `@nativescript/core/globals` import from served
modules. That is right for the main realm, where the entry installs the
globals once, and fatal for a worker realm: the worker script is that
isolate's only entry and the import is its only source of `setTimeout`,
`setInterval` and the other runtime globals. Worker-realm serves keep the
import, and a worker entry that does not carry one gets it added — the
production worker build bundles the module in, so the two paths agree.
Flavors were wired by name inside the package, so a framework could only
get device HMR by landing a PR here. `registerFrameworkFlavor({ flavor,
server, client })` from `@nativescript/vite/framework` registers a server
strategy and the specifier of a client strategy module shipped in the
framework's own package; `@nativescript/vite/hmr/client/framework.js` is
the device-side surface that module is written against.

The dev server looks registered strategies up next to the built-ins, seeds
the device bundle with the client module's `/ns/m/node_modules/<pkg>/…`
path (`__NS_CLIENT_STRATEGY_URL__`), and classifies the client package as
dev tooling — served per-module, never vendor-bundled or plugin-wrapped —
so its relative imports and its imports of the shared client resolve to the
running client's canonical URLs. `nativescript-vite init` and flavor
detection read a `nativescript.vite` declaration from the framework
package's package.json.

docs/framework-flavors.md is the walkthrough; @nativescript/vite-octane
(NativeScript/octane) is the worked example.
Vite's stock client never connects under device HMR, so its `page reload
<file>` / `hmr update <file>` lines describe a client that does not exist —
and `page reload` misleads while the device applies the same save in place
through a framework strategy.
@NathanWalker NathanWalker added this to the 9.2 milestone Aug 22, 2026
@nx-cloud

nx-cloud Bot commented Aug 22, 2026

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit 1de8324

Command Status Duration Result
nx test apps-automated -c=android ✅ Succeeded 3m 55s View ↗
nx run-many --target=test --configuration=ci --... ✅ Succeeded <1s View ↗

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


☁️ Nx Cloud last updated this comment at 2026-08-22 18:07:56 UTC

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.

1 participant