Commit c923953
committed
fix(plugin-rsc): use MagicString to preserve sourcemap chain in webpack-require transform
Returning `map: null` from a transform that changes string lengths breaks
the Rollup sourcemap chain. This causes Rollup/Vite to emit noisy
'Can't resolve original location of error' warnings for every file that
passes through this transform — in practice, every module that contains
'__webpack_require__', which includes all 'use client' component files
processed by the RSC pipeline.
Replace the manual string replacements + `map: null` with MagicString,
which generates a correct sourcemap that reflects the actual character
offset changes (`__webpack_require__` → `__vite_rsc_require__` is not
a same-length replacement). A single regex pass handles both the
`.u` variant and bare `__webpack_require__` without overlapping overwrites.
Fixes: 'Can't resolve original location of error' build warnings1 parent 377cfda commit c923953
1 file changed
Lines changed: 34 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
1 | 2 | | |
2 | 3 | | |
3 | 4 | | |
| |||
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
9 | | - | |
10 | | - | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | | - | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
16 | 18 | | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
24 | 39 | | |
25 | 40 | | |
26 | | - | |
27 | | - | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
28 | 46 | | |
29 | 47 | | |
30 | 48 | | |
| |||
0 commit comments