Repository navigation
fix(vite): serve a plugin module under one URL whether imported or re-exported - #11540
Merged
Merged
Conversation
…-exported
Under HMR the main realm serves a NativeScript plugin's modules under the
authored spelling of their imports: `import { x } from './framework-registry'`
reaches the device as `/ns/m/node_modules/<pkg>/framework-registry`. Re-exports
and dynamic imports kept Vite's resolved `.../framework-registry.js`. The
device caches modules by URL, so a module imported in one file and
re-exported from another was evaluated twice. MasonKit's entry re-exports
what its internals import, so its Vue adapter registered into one copy of
the framework registry while views read the other, and layout never ran.
Re-exports (`export * from`, `export { a } from`) and string-literal dynamic
imports now get the same specifier a static import of that module gets, and
the source scan that records the authored spellings includes them too.
Worker serves already use the resolved file for both and are unchanged.
|
View your CI Pipeline Execution ↗ for commit 636da11
💡 Verify your cache is correct by running tasks in a sandbox. Read docs ↗ ☁️ Nx Cloud last updated this comment at |
commit: |
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?
For NativeScript runtime-plugin modules,
ensureNativeScriptModuleBindingsswaps a static import's resolved specifier for the authored spelling, which becomes/ns/m/node_modules/<pkg>/framework-registry. Re-exports and dynamic imports keep Vite's.../framework-registry.js. The device caches modules by URL, so one module is loaded twice under two URLs: with MasonKit, the framework adapter registers in one copy of its registry while views read the other, and layout never runs.What is the new behavior?
In the main realm, value re-exports (
export … from,export * from) and string-literal dynamic imports get the same preserved specifier as static imports, and the source scan that builds the overrides includes them. Worker serves are unchanged. On a real dev server, the only change to MasonKit's served modules is that the re-export URLs now match the imports.Tests: a case in
hmr/server/websocket-source-intent.spec.tscovering import, re-export,export *and dynamic import.Each new test fails without the change. The
@nativescript/vitesuite (163 files) andtsc -p tsconfig.lib.jsonpass on the branch.