← 输入框|github.com|刷新
Skip to content

fix(vite): keep the ?raw query on HMR imports - #11541

Merged
NathanWalker merged 3 commits into
mainfrom
fix/vite-hmr-raw-query
Oct 21, 2026
Merged

NathanWalker merged 3 commits into
mainfrom
fix/vite-hmr-raw-query

Conversation

@triniwiz

Copy link
Copy Markdown
Member

PR Checklist

What is the current behavior?

Under HMR, import icon from './icon.svg?raw' gets the asset module instead of the text: rewriteImports routes a specifier by its path and drops the query (Vite emits ?import&raw), and the /ns/m route discards it too. A ?raw JSON import is inlined as the parsed object.

What is the new behavior?

  • A ?raw specifier is routed like the plain file, and ?raw is kept on the /ns/m URL.
  • The JSON-inline pass skips ?raw imports.
  • The /ns/m route serves ?raw requests from Vite's raw load (export default "<text>").
  • The match uses Vite's own pattern, so the raw=1 diagnostics flag doesn't trigger it. Imports without ?raw are unchanged.

Checked on a real dev server with svg, css and node_modules json/svg ?raw imports. Tests: rewrite-imports.spec.ts and websocket-ns-m.spec.ts.

Each new test fails without the change. The @nativescript/vite suite (163 files) and tsc -p tsconfig.lib.json pass on the branch.

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.
@nx-cloud

nx-cloud Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit b866a55

Command Status Duration Result
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-10-21 18:35:13 UTC

@pkg-pr-new

pkg-pr-new Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@nativescript/core@11541
npm i https://pkg.pr.new/@nativescript/vite@11541
npm i https://pkg.pr.new/@nativescript/webpack@11541

commit: b866a55

triniwiz and others added 2 commits October 15, 2026 16:26
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.
@NathanWalker
NathanWalker merged commit 6f1b807 into main Oct 21, 2026
9 of 10 checks passed
@NathanWalker
NathanWalker deleted the fix/vite-hmr-raw-query branch October 21, 2026 18:39
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.

2 participants