Repository navigation
fix(vite): serve HMR app modules with source maps - #11629
Merged
Merged
Conversation
The /ns/m device route rewrites Vite's transform output (prepended guards, import rewrites, AST normalization) and dropped Vite's source map, so debuggers attached under HMR could not bind breakpoints in app sources. Carry Vite's map onto the served body by aligning the two texts line by line and append it inline, with absolute file:// sources. Library modules are left unchanged.
|
View your CI Pipeline Execution ↗ for commit 001db83
💡 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
packages/vite: 169 files / 1963 tests).What is the current behavior?
Under HMR, the
/ns/mroute serves app modules without a source map. Vite's transform does produce one, but the device pipeline then changes the code: it prepends guards and boot code, rewrites and hoists imports, and for some modules re-prints the whole file with Babel ([ast-normalized]). Then it sends the result without the map. The runtime reports scripts likehttp://<host>:5173/ns/m/src/appwith an emptysourceMapURL, so a debugger (VS Code / js-debug, Chrome DevTools) cannot bind breakpoints in.ts/.tsxsources. This is why the NativeScript VS Code extension forces--no-hmrfor Vite projects.What is the new behavior?
App modules (not library/
node_modulesones) served by/ns/mcarry an inline source map:hmr/server/served-module-sourcemap.tsaligns Vite's transform output with the served body using a Myers line diff (whitespace-insensitive), then carries Vite's mappings over:retainLines.file://URLs, because the device URL doesn't mirror the project layout. js-debug and DevTools resolve them with no path overrides.sourceMappingURLis left as is.@jridgewell/sourcemap-codec(already in the tree through Babel).Verified
On a Solid app (
ns debug ios --watch, iOS simulator), driving js-debug 1.140 (the version VS Code bundles) over DAP:app.tsx,state/ui.ts, and a Babel-normalizeddata/music.tsbind at the requested lines.Appatapp.tsx:15, with scopes and evaluation working.data:source map URLs through unchanged.Cost
Not covered
Vue SFCs are served by
/ns/sfc//ns/asmand still have no maps. That can follow separately.Related: the VS Code extension stops forcing
--no-hmronce this ships: nativescript-community/nativescript-vscode-extension#303.