GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(vite): serve HMR app modules with source maps by NathanWalker · Pull Request #11629 · NativeScript/NativeScript

Conversation

@NathanWalker

@NathanWalker NathanWalker commented Nov 9, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

PR Checklist

  • The PR title follows our guidelines.
  • There is an issue for the bug/feature this PR is for.
  • All existing tests are passing (packages/vite: 169 files / 1963 tests).
  • Tests for the changes are included.

What is the current behavior?

Under HMR, the /ns/m route 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 like http://<host>:5173/ns/m/src/app with an empty sourceMapURL, so a debugger (VS Code / js-debug, Chrome DevTools) cannot bind breakpoints in .ts/.tsx sources. This is why the NativeScript VS Code extension forces --no-hmr for Vite projects.

What is the new behavior?

App modules (not library/node_modules ones) served by /ns/m carry an inline source map:

  • hmr/server/served-module-sourcemap.ts aligns Vite's transform output with the served body using a Myers line diff (whitespace-insensitive), then carries Vite's mappings over:
    • Lines with the same text apart from indentation keep Vite's segments, with columns shifted by the indentation change. This covers the Babel re-print, which uses retainLines.
    • Hunks rewritten in place (same line count on both sides) map each line to the start of its original line.
    • Injected preamble and hoisted imports stay unmapped.
  • Sources are emitted as absolute file:// URLs, because the device URL doesn't mirror the project layout. js-debug and DevTools resolve them with no path overrides.
  • The map is appended before the response memo, so cached responses include it. Code that already has a sourceMappingURL is left as is.
  • New dependency: @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:

  • Breakpoints in app.tsx, state/ui.ts, and a Babel-normalized data/music.ts bind at the requested lines.
  • After an HMR edit, the breakpoint re-binds to the new module version and pauses in App at app.tsx:15, with scopes and evaluation working.
  • The iOS and Android inspector clients pass data: source map URLs through unchanged.

Cost

  • About 0.3 ms to build the map for a 600-line module, only for responses not already cached.
  • About 40% more bytes per app module. Library modules, core, and the deps bundle are unchanged.

Not covered

Vue SFCs are served by /ns/sfc / /ns/asm and still have no maps. That can follow separately.

Related: the VS Code extension stops forcing --no-hmr once this ships: nativescript-community/nativescript-vscode-extension#303.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@NathanWalker
fix(vite): serve HMR app modules with source maps
001db83
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.
@NathanWalker NathanWalker mentioned this pull request Nov 9, 2026
feat: debug Vite projects with HMR when @nativescript/vite serves source maps nativescript-community/nativescript-vscode-extension#303
Open
@nx-cloud

nx-cloud Bot commented Nov 9, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit 001db83

Command Status Duration Result
nx run-many -t build -p core,webpack5,vite ✅ Succeeded 10s View ↗

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


☁️ Nx Cloud last updated this comment at 2026-11-09 23:06:46 UTC

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@pkg-pr-new

pkg-pr-new Bot commented Nov 9, 2026

Copy link
Copy Markdown

Open in StackBlitz

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

commit: 001db83

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@NathanWalker
NathanWalker merged commit 49c0474 into main Nov 9, 2026
10 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@NathanWalker
NathanWalker deleted the fix/vite-hmr-sourcemaps branch November 9, 2026 23:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@NathanWalker
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.