Skip to content

Conversation

@sethfowler-datadog
Copy link
Contributor

What and why?

When multiple loaders transform a file, it's necessary to combine (or "chain") the source maps produced by each loader to produce an end-to-end source map that connects the bundled code to the original source. Failing to chain the source maps produced by intermediate loaders can produce source maps which are either broken, or which simply map to partially-transformed code. Either outcome can make debugging difficult.

Unfortunately, source map chaining behavior is inconsistent between the various bundlers that Unplugin supports, and Unplugin does not paper over those differences. For example:

  • Vite expects each loader to produce a source map including only its own changes, and handles chaining natively.
  • Esbuild expects each loader to chain its source map with the previous loader. However, Unplugin handles this internally, so from the perspective of a plugin author, the effect is similar to Vite.
  • Rspack and Webpack expect each loader to chain its source map with the previous loader. Unplugin does not handle this internally for these bundlers.

As a result of these differences, source map chaining is currently not working for Rspack and Webpack. As a result, early adopters of the RUM Privacy plugin are reporting incorrect source maps. This PR adds code to handle source map chaining within the RUM Privacy plugin for these bundlers, resolving the issue.

Ideally, Unplugin would provide consistent source map chaining behavior across all bundlers, and I expect we'll eventually see that happen. However, because that would be a backwards-incompatible change for some bundlers if implemented in the obvious way, it will probably take some time to get there.

How?

  1. Update to Unplugin 2.3.11, which includes this change we contributed upstream to Unplugin. This gives us access to a new property inputSourceMap on Unplugin's NativeBuildContext type. On Rspack and Webpack, this property is populated with the input source map, if there is one.
  2. Add code to the RUM Privacy plugin to grab the input source map on Rspack and Webpack and pass it to the instrument() function exposes by js-instrumentation-wasm. instrument() already supports source map chaining, so that's enough to fix the issue.

Copy link
Member

@yoannmoinet yoannmoinet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@sethfowler-datadog sethfowler-datadog merged commit 83b8ea4 into master Dec 2, 2025
5 checks passed
@sethfowler-datadog sethfowler-datadog deleted the seth.fowler/use-input-source-map-when-instrumenting-in-rum-privacy-plugin branch December 2, 2025 16:58
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.

4 participants