Commit c4c3aee
authored
When mangling is disabled with `next build --no-mangling`, the function
names of `"use cache"` functions are currently still mangled.
The reason is that those functions are transformed to inline function
expressions whose names are removed by the SWC minifier even if `mangle`
is `false`.
Original:
```js
'use cache'
export async function getCachedData() {
return functionThatMightThrow()
}
```
Transformed by the Next.js compiler during `next dev`:
```js
export var $$RSC_SERVER_CACHE_0 = $$cache__("default", "<id>", 0, async function getCachedData() {
return functionThatMightThrow()
});
```
Transformed by the Next.js compiler during `next build`:
```js
export var $$RSC_SERVER_CACHE_0 = $$cache__("default", "<id>", 0, async function () {
return functionThatMightThrow()
});
```
By setting `keep_fnames` to `true` in SWC's `compress` options, we can
ensure that those function expression names are preserved when building
with `--no-mangling`, which is helpful when looking at error stacks or
traces.
1 parent 2086975 commit c4c3aee
File tree
5 files changed
+32
-1
lines changed- packages/next/src/build/webpack/plugins/minify-webpack-plugin/src
- test/production/app-dir/no-mangling
- app/use-cache
- turbopack/crates/turbopack-ecmascript/src
5 files changed
+32
-1
lines changedLines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
145 | 145 | | |
146 | 146 | | |
147 | 147 | | |
| 148 | + | |
| 149 | + | |
148 | 150 | | |
149 | 151 | | |
150 | 152 | | |
| |||
Lines changed: 6 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
5 | 10 | | |
6 | 11 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
49 | 65 | | |
50 | 66 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
85 | 85 | | |
86 | 86 | | |
87 | 87 | | |
| 88 | + | |
| 89 | + | |
88 | 90 | | |
89 | 91 | | |
90 | 92 | | |
| |||
0 commit comments