Skip to content

fix(vite): decode percent-encoded /ns/m request paths - #11483

Merged
NathanWalker merged 3 commits into
NativeScript:mainfrom
aleclarson:fix/vite-ns-m-decode-pathname
Sep 30, 2026
Merged

NathanWalker merged 3 commits into
NativeScript:mainfrom
aleclarson:fix/vite-ns-m-decode-pathname

Conversation

@aleclarson

Copy link
Copy Markdown
Contributor

PR Checklist

What is the current behavior?

In dev-session (HTTP ESM) mode, /ns/m/<path> module requests 404 when the device's HTTP layer percent-encodes the filename — e.g. file-based router params like app/demo/[id].tsrx fetched as /ns/m/.../%5Bid%5D.tsrx. The raw-bracket spelling resolves fine because URL.pathname preserves percent-encoding while searchParams.get('path') decodes it, so only path-style requests reached the file lookup still encoded.

What is the new behavior?

createNsMRequestContext now decodes the pathname-derived spec with decodeURIComponent before candidate expansion, so encoded and raw spellings resolve the same on-disk module. Two details handled deliberately:

  • The decode runs after the existing [?#] strip, so filenames containing encoded ?/# (%3F/%23) aren't mistaken for query delimiters.
  • Only the pathname-derived spec is decoded — the ?path= value is already decoded once by URLSearchParams, and decoding it again would corrupt filenames containing a literal %. Malformed sequences fall back to the raw spec.

The same class of bug existed in the /ns/sfc path-style spec (/ns/sfc/<path>.vue), which now decodes too — bracketed .vue files are the same dynamic-route scenario. Other handlers were audited: /ns/asm, /ns/sfc-meta, /ns/rt, /ns/entry, /ns/txn, and the deps-bundle/node-builtins routes either use ?path= (already decoded), fixed prefixes, or already decode.

Fixes #11455

Tests

Three regression specs in websocket-ns-m-request.spec.ts: encoded-vs-raw spec equivalence, no double-decode of ?path=, and %3F/%23 surviving the query-strip. Full @nativescript/vite suite: 1830 tests green.

URL.pathname preserves percent-encoding, so device-encoded module URLs
like /ns/m/app/demo/%5Bid%5D.tsrx reached the file lookup literally and
404'd while the raw-bracket spelling resolved. Decode the pathname-
derived spec before candidate expansion (after the ?# strip so encoded
%3F/%23 filename chars survive); the ?path= spec is already decoded by
URLSearchParams and is left untouched to avoid double-decoding. Apply
the same decode to the /ns/sfc path-style spec for bracketed .vue files.

Fixes NativeScript#11455
@nx-cloud

nx-cloud Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit 99e04d3

Command Status Duration Result
nx run-many --target=test --configuration=ci --... ✅ Succeeded 6s View ↗

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


☁️ Nx Cloud last updated this comment at 2026-09-30 20:59:58 UTC

@pkg-pr-new

pkg-pr-new Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

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

commit: 99e04d3

Comment thread packages/vite/hmr/frameworks/vue/server/sfc-route-serve.ts Outdated
Comment thread packages/vite/hmr/server/websocket-ns-m-request.ts Outdated
decodeURI still decodes brackets and spaces but leaves reserved characters (%2F, %3F, %23) encoded, as Vite's transform middleware does.
@NathanWalker
NathanWalker merged commit 648cff7 into NativeScript:main Sep 30, 2026
5 of 7 checks passed
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.

vite dev server: /ns/m doesn't decode percent-encoded filenames (bracketed route files 404)

2 participants