Title: webpack/rspack: transform hook sourcemaps are dropped or not composed · Issue #616 · unjs/unplugin · GitHub
Open Graph Title: webpack/rspack: transform hook sourcemaps are dropped or not composed · Issue #616 · unjs/unplugin
X Title: webpack/rspack: transform hook sourcemaps are dropped or not composed · Issue #616 · unjs/unplugin
Description: Describe the bug The webpack and Rspack adapters do not preserve source maps returned by a transform hook correctly: When the loader has no input source map, the adapter discards res.map. When both an input map and res.map exist, the ada...
Open Graph Description: Describe the bug The webpack and Rspack adapters do not preserve source maps returned by a transform hook correctly: When the loader has no input source map, the adapter discards res.map. When both...
X Description: Describe the bug The webpack and Rspack adapters do not preserve source maps returned by a transform hook correctly: When the loader has no input source map, the adapter discards res.map. When both...
Opengraph URL: https://github.com/unjs/unplugin/issues/616
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"webpack/rspack: transform hook sourcemaps are dropped or not composed","articleBody":"### Describe the bug\n\nThe webpack and Rspack adapters do not preserve source maps returned by a `transform` hook correctly:\n\n1. When the loader has no input source map, the adapter discards `res.map`.\n2. When both an input map and `res.map` exist, the adapter forwards only `res.map` instead of composing both mapping layers, so mappings from earlier loaders are lost.\n\nAs a result, the generated bundle reports incorrect original source locations even though the transform hook returns a valid source map.\n\n### Reproduction\n\nhttps://github.com/SyMind/unplugin-rspack-sourcemap-repro\n\n```bash\npnpm install\npnpm repro\n```\n\nThe reproduction uses `unplugin@3.3.0` and `@rspack/core@2.2.1`. Both cases run an unplugin transform that prepends one generated line and returns the corresponding high-resolution source map. The second case also runs a preceding loader that prepends a line and returns its own source map.\n\nActual result:\n\n```text\nwithout-input-map: expected source line 1, received line 2\nwith-input-map: expected source line 1, received line 2\n```\n\n### Expected behavior\n\nThe map returned by the transform hook should be preserved. The generated statement should trace back to line 1 of `src/index.js` in both cases, so `pnpm repro` should succeed.\n\nWhen an input map is also present, the adapter should compose the transform map with the input map so the complete loader chain is retained.\n\n### Root cause\n\nBoth webpack-like transform loaders currently use this callback logic:\n\n```ts\ncallback(null, res.code, map == null ? map : (res.map || map))\n```\n\nThis explicitly passes a nullish input map when no input map exists, dropping `res.map`. When both maps exist, it selects one map without composing them.\n\nThis is related to #154 and follows up on #561 / #562: exposing `inputSourceMap` makes manual composition possible, but the adapter output still does not preserve the complete transform chain by default.\n\nA fix with regression tests is available in #615.","author":{"url":"https://github.com/SyMind","@type":"Person","name":"SyMind"},"datePublished":"2026-08-31T06:47:49Z","url":"https://github.com/unjs/unplugin/issues/616"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:070626ca-42e8-d78a-263a-4466c4d9bed5 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AE54:3E8F60:30683F:4489CD:6B006E06 |
| html-safe-nonce | 3754e8730668d8616b1101b0ba0922acd7bd4efa564793dd1f3d710e06e5199d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBRTU0OjNFOEY2MDozMDY4M0Y6NDQ4OUNEOjZCMDA2RTA2IiwidmlzaXRvcl9pZCI6IjgwMTI3ODkyMTk0MDk4MTcwOTQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 76d930aee8c22222b0849fea9fac6fb013dff4179c4c0d2173d841c0a2dc88ce |
| hovercard-subject-tag | issue:5297295562 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/unjs/unplugin/616/issue_layout |
| twitter:image | https://opengraph.githubassets.com/c0b5977eb29f77ba008f8d61753418391422aa152714278c4328f2e38363d99a/unjs/unplugin/issues/616 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/c0b5977eb29f77ba008f8d61753418391422aa152714278c4328f2e38363d99a/unjs/unplugin/issues/616 |
| og:image:alt | Describe the bug The webpack and Rspack adapters do not preserve source maps returned by a transform hook correctly: When the loader has no input source map, the adapter discards res.map. When both... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | SyMind |
| hostname | github.com |
| expected-hostname | github.com |
| None | 6527e91c60c0b29d16606ff32ac5df8ecdc37a2a62205ea057a14d7762c870fa |
| turbo-cache-control | no-preview |
| go-import | github.com/unjs/unplugin git https://github.com/unjs/unplugin.git |
| octolytics-dimension-user_id | 80154025 |
| octolytics-dimension-user_login | unjs |
| octolytics-dimension-repository_id | 385261169 |
| octolytics-dimension-repository_nwo | unjs/unplugin |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 385261169 |
| octolytics-dimension-repository_network_root_nwo | unjs/unplugin |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 46f1cd2ae3cd8ae1a81019b5d619742e76f13bbd |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width