mirror of
https://github.com/hanzoai/next.js.git
synced 2026-10-30 14:46:38 +00:00
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.
7 lines
117 B
TypeScript
7 lines
117 B
TypeScript
'use cache'
|
|
|
|
export default async function CachedPage() {
|
|
throw new Error('Kaputt!')
|
|
return <p>hello world</p>
|
|
}
|