feat(vite): framework registration API - #11358
Draft
NathanWalker wants to merge 6 commits into
Draft
Conversation
…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.
|
View your CI Pipeline Execution ↗ for commit 1de8324
💡 Verify your cache is correct by running tasks in a sandbox. Read docs ↗ ☁️ Nx Cloud last updated this comment at |
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.
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
@nativescript/vite/frameworkAPI, exposing functions and types for registering and using custom framework flavors, including server and client strategy types and helpers likeregisterFrameworkFlavor,getFrameworkFlavor, andtypescriptServerStrategy. (packages/vite/framework.ts)package.json(vianativescript.vite.flavor), enabling automatic flavor selection and configuration scaffolding for third-party frameworks.Configuration and Runtime Integration
baseConfigto accept anhmrActiveparameter, supporting improved logging for HMR scenarios.