fix(css): keep the emitted .map asset aligned when css.inject prepends the import - #1049
Open
NullVoxPopuli wants to merge 2 commits into
Open
fix(css): keep the emitted .map asset aligned when css.inject prepends the import#1049NullVoxPopuli wants to merge 2 commits into
NullVoxPopuli wants to merge 2 commits into
Conversation
…e import The inject plugin prepends `import './style.css';` to styled chunks in generateBundle and compensates chunk.map with a `;` mappings prefix -- but rolldown materializes the companion .map asset before generateBundle runs, and chunk.map mutations do not propagate into it (unlike rollup). The emitted map ended up one line behind the emitted code, so every mapping in every css.inject'd chunk pointed one line early. Extract the shared prepend logic into prependCssImport() and have it also refresh the .map asset from the mutated chunk.map. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
✅ Deploy Preview for tsdown-main ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
tsdown
create-tsdown
@tsdown/css
@tsdown/exe
tsdown-migrate
commit: |
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes sourcemap misalignment when css.inject prepends an import during generateBundle by ensuring the emitted companion .map asset is updated to match the mutated chunk.map (working around current rolldown behavior).
Changes:
- Extracted CSS import-prepend logic into
prependCssImport()and refreshed the emitted${chunk.fileName}.mapasset after adjusting mappings. - Added a sourcemap alignment regression test for
css.injectthat decodes VLQ mappings and verifies a specific statement maps back to the correct original line. - Added a new snapshot covering the injected import, emitted map, and CSS output.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| tests/css.test.ts | Adds a regression test that decodes mappings and asserts emitted map alignment after injected CSS import. |
| tests/snapshots/sourcemap/css-inject-keeps-the-emitted-map-aligned-with-the-injected-import.snap.md | Snapshot verifying the injected import and updated sourcemap mappings. |
| packages/css/src/plugin.ts | Refactors prepend logic into prependCssImport() and updates the .map asset to reflect chunk.map mutations. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Review feedback: indexOf() returning -1 was treated as a valid digit via the bitwise ops. The helper now throws on characters outside the base64 alphabet and on a dangling continuation bit at end of segment. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
Suppressed comments (1)
tests/css.test.ts:1871
generatedLinebecomes0iffindIndex()fails (returns-1), which makes the subsequent sourcemap assertion fail with a less helpful message. Capturing the index separately and asserting it was found improves test diagnostics and avoids silently passing an invalid line number intooriginalLineFor().
const generatedLine =
code.split('\n').findIndex((line) => line.includes('const value')) + 1
5 tasks
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.
css.injectprependsimport './style.css';to styled chunks ingenerateBundleand compensateschunk.mapwith a;mappings prefix. that compensation is correct — but rolldown materializes the companion.mapasset beforegenerateBundleruns and doesn't propagatechunk.mapmutations into it (rolldown/rolldown#10676). so the emitted map is one line behind the emitted code, and every mapping in every css-injecting chunk points one line early.found this while testing sourcemap alignment for ember-scoped-css's tsdown build — every component in the bundle was misaligned, cascading (in this kind of visualization, each statement highlights the line above itself).
the fix: extract the duplicated prepend logic into
prependCssImport(), which also refreshes the.mapasset from the mutatedchunk.map. works with today's rolldown; harmless if rolldown starts syncing the asset itself.the test decodes the mappings VLQ inline (no new dependency) and asserts
export const value = 42traces to its exact original line through the injected import. red without the fix, green with it.Disclosure: this investigation, fix, and write-up are AI-assisted exploration (Claude Fable 5 via Claude Code), directed and reviewed by me.
🤖 Generated with Claude Code