Repository navigation
fix(vite): keep the ?raw query on HMR imports - #11541
Merged
Merged
Conversation
Under HMR, `import svg from './icon.svg?raw'` reached the device without its query. The served-module rewriter routes a specifier by its path and drops the query, so the device fetched `/ns/m/src/icon.svg`, got the asset module (a URL) instead of the file's text, and `?raw` JSON imports were inlined as the parsed object. The /ns/m route also discarded the query on the way in, so it could not have served the text either. The rewriter now routes a `?raw` specifier like the plain file and keeps `?raw` on the resulting /ns/m URL, and leaves `?raw` JSON imports alone. The /ns/m route serves a `?raw` request straight from Vite's raw load (`export default "<text>"`). The `raw=1` diagnostics flag is not a `?raw` import. Imports without `?raw` are unchanged.
|
View your CI Pipeline Execution ↗ for commit b866a55
💡 Verify your cache is correct by running tasks in a sandbox. Read docs ↗ ☁️ Nx Cloud last updated this comment at |
commit: |
A ?raw import resolved outside the project and workspace roots stays a /@fs URL served by Vite itself, so it must keep ?import&raw rather than be stripped to the bare file.
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?
Under HMR,
import icon from './icon.svg?raw'gets the asset module instead of the text:rewriteImportsroutes a specifier by its path and drops the query (Vite emits?import&raw), and the/ns/mroute discards it too. A?rawJSON import is inlined as the parsed object.What is the new behavior?
?rawspecifier is routed like the plain file, and?rawis kept on the/ns/mURL.?rawimports./ns/mroute serves?rawrequests from Vite's raw load (export default "<text>").raw=1diagnostics flag doesn't trigger it. Imports without?raware unchanged.Checked on a real dev server with svg, css and node_modules json/svg
?rawimports. Tests:rewrite-imports.spec.tsandwebsocket-ns-m.spec.ts.Each new test fails without the change. The
@nativescript/vitesuite (163 files) andtsc -p tsconfig.lib.jsonpass on the branch.