Skip to content

fix(build): shift index.js's source map past the bootstrap banner - #27336

Closed
outof-place wants to merge 1 commit into
stablyai:mainfrom
outof-place:fix/main-bootstrap-banner-sourcemap
Closed

outof-place wants to merge 1 commit into
stablyai:mainfrom
outof-place:fix/main-bootstrap-banner-sourcemap

Conversation

@outof-place

Copy link
Copy Markdown
Contributor

ELI5

A source map tells a debugger which line of our TypeScript each line of the built index.js came from. After the build writes index.js and its map, one build step adds 205 lines of start-up guard code to the top of index.js. The map was never told. So every line it describes is 205 lines off, and a crash in main gets traced back to the wrong source line, or to nothing. This PR moves the map down by the same 205 lines when the banner goes in.

What Changed

Before: createMainBootstrapPlugin did mainChunk.code = banner + mainChunk.code in generateBundle. By then Rolldown has already emitted index.js.map as its own asset, so the map still described index.js without the banner:

  • index.js has 9,373 lines; its map describes 9,169, starting at the banner's first line;
  • a position in index.js decoded to the source of the code 205 lines below it;
  • the last 205 lines decoded to nothing.

After: the plugin calls prependChunkBanner(bundle, chunk, banner) (config/build-plugins/prepend-chunk-banner.ts). It prepends the banner and puts one empty line (;) per banner line at the start of the .map asset's mappings. Every segment moves down to the line its code now sits on. Nothing changes at runtime: index.js is byte-identical.

Why

  • Why fix the map and keep the hook: the plugin's comment says the banner must run before the require prelude Rolldown generates, which is why it's added in generateBundle. Moving it to renderChunk or output.banner would change where it lands relative to that prelude. Fixing the map leaves that ordering exactly as it is.
  • Why only line offsets: the banner always ends with a newline, so no column on the chunk's original lines moves. The helper throws if a banner ends mid-line, rather than silently writing a wrong map.

Linked Issue

None. Found while decoding main-process profiles.

Visual Proof

N/A: build output only.

Testing

  • config/scripts/prepend-chunk-banner.test.ts:

    • a four-line banner puts four empty lines before the original mappings, and the chunk's first code line keeps its own segments;
    • a chunk without a map gets the banner and nothing else;
    • a banner that ends mid-line throws and leaves the map alone.
  • Built pnpm run build:electron-vite before and after this change, and decoded two string literals' positions in out/main/index.js through index.js.map:

    • after: 'journal_item_resolved_to_nothing' decodes to journal-item-appender.ts:11, and 'Refusing to start E2E outside its disposable home boundary' to configure-process.ts:204. Both are the lines that hold them.
    • before: both positions decode to no mapping. Line 9286 is past the 9,169 lines the old map covers. On line 8399, the old map has no segment at or before that column, because that map line holds the segments of what is now line 8604.
  • oxlint on the changed files, tsc -p config/tsconfig.node.json and pnpm run check:code-quality:changed pass. Full pnpm test, pnpm lint and pnpm build were left to CI.

  • I manually tested these changes locally (not done: only the builds, the map decode and the checks above ran)

  • Automated tests added/updated, or explained why not below

AI Disclosure

Implemented with Claude Opus 5.5 via Claude Code: investigation, code, tests and the map check. A human (outof-place) directed the work.

Review

  1. prependChunkBanner in config/build-plugins/prepend-chunk-banner.ts.
  2. Its one call site in electron.vite.config.ts.

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Trade-offs

  • Merge risk. Build-time only: index.js is byte-identical, and only index.js.map changes. If the shift were wrong, traces would still decode to wrong lines, as they do today.
  • CPU / build. One JSON parse and stringify of index.js.map (40.6 MB): 80–93 ms per build, measured on the real map.
  • Memory / disk. None at runtime. The map grows by 205 bytes.
  • Maintenance. One 44-line helper, a 65-line test file and a 6-line call-site change. Any future generateBundle banner can use the same helper.
  • Verdict: free win. Main-process crash traces decode to the right line again, for under 0.1 s of build time.

Notes

  • Cross-platform: build-time only.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

🤖 Generated with Claude Code

createMainBootstrapPlugin prepends the fatal-exit guard and startup
diagnostics banner (205 lines) to index.js in generateBundle, after
Rolldown has already emitted index.js.map. The map kept describing the
code without the banner, so every position in index.js decoded 205
lines too early, and the last 205 lines decoded to nothing. Crash
traces symbolicated through the uploaded map named the wrong source.

prependChunkBanner() now prepends the banner and adds one empty line
per banner line to the start of the .map asset's mappings. A banner
that ends mid-line throws, since it would shift columns too.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@coderabbitai

coderabbitai Bot commented Oct 10, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 8acb7d4b-e398-4e32-9d2e-9b017c8be03d

📥 Commits

Reviewing files that changed from the base of the PR and between 19f20c8 and 4d87fec.


📒 Files selected for processing (3)
  • config/build-plugins/prepend-chunk-banner.ts
  • config/scripts/prepend-chunk-banner.test.ts
  • electron.vite.config.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review.



📝 Walkthrough

Walkthrough

Adds prependChunkBanner to prepend a newline-terminated banner to chunk code and adjust mappings in string-backed source maps. The helper is tested with mapped and unmapped chunks, and with a banner that lacks a trailing newline. The main-bundle plugin uses the helper for the fatal-exit and startup-diagnostics banners in index.js.


Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to 4d87f

The reviewed change is mergeable after normal checks. Source-map shifting for byte-backed assets remains unverified, but no failure in the supported build was established.

Pre-merge checks | Passed 3 | Failed 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check Warning The description is detailed and covers the required change, rationale, testing, visual-proof status, AI disclosure, and checklist. However, the required Linked Issue section states "None" instead of p… Add the actual issue reference under "Fixes #". If the author is a maintainer and the repository permits omitting an issue, state that exception explicitly.
Docstring Coverage Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check Passed The title clearly identifies the primary change: correcting index.js source-map line offsets after the bootstrap banner is prepended.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.

Full details: Description check

Explanation

The description is detailed and covers the required change, rationale, testing, visual-proof status, AI disclosure, and checklist. However, the required Linked Issue section states "None" instead of providing an issue link.


  • Fix all pre-merge checks with AI
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@nwparker

Copy link
Copy Markdown
Contributor

Thanks so much @outof-place for tracking down the misaligned index.js source map! We couldn't push to your branch, so we've continued this in #33899, which keeps your diagnosis and switches the fix to Rolldown's native output.postBanner so the bundler shifts the map itself. Your authorship is preserved via Co-authored-by on the commit.

@nwparker nwparker closed this Oct 26, 2026
@outof-place
outof-place deleted the fix/main-bootstrap-banner-sourcemap branch November 7, 2026 08:26
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