diff --git a/.changeset/plenty-radios-turn.md b/.changeset/plenty-radios-turn.md new file mode 100644 index 000000000000..3601a1386c49 --- /dev/null +++ b/.changeset/plenty-radios-turn.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/kit': patch +--- + +Reset stack traces to avoid double-fix diff --git a/packages/kit/src/runtime/server/page/render.js b/packages/kit/src/runtime/server/page/render.js index fb6bc1bb4eac..4da30d4a6650 100644 --- a/packages/kit/src/runtime/server/page/render.js +++ b/packages/kit/src/runtime/server/page/render.js @@ -72,7 +72,9 @@ export async function render_response({ /** @type {import('types').NormalizedLoadOutputCache | undefined} */ let cache; - if (error) { + const stack = error?.stack; + + if (__SVELTEKIT_DEV__ && error) { error.stack = options.get_stack(error); } @@ -315,6 +317,11 @@ export async function render_response({ } } + if (__SVELTEKIT_DEV__ && error) { + // reset stack, otherwise it may be 'fixed' a second time + error.stack = stack; + } + return new Response(html, { status, headers diff --git a/packages/kit/test/apps/basics/src/routes/errors/stack-trace/_bad.js b/packages/kit/test/apps/basics/src/routes/errors/stack-trace/_bad.js new file mode 100644 index 000000000000..b8ab69cae788 --- /dev/null +++ b/packages/kit/test/apps/basics/src/routes/errors/stack-trace/_bad.js @@ -0,0 +1,6 @@ +const bad = foo().toUpperCase(); +export default bad; + +// @ts-expect-error +/** @returns {string} */ +function foo() {} diff --git a/packages/kit/test/apps/basics/src/routes/errors/stack-trace/index.svelte b/packages/kit/test/apps/basics/src/routes/errors/stack-trace/index.svelte new file mode 100644 index 000000000000..c186e7e4d227 --- /dev/null +++ b/packages/kit/test/apps/basics/src/routes/errors/stack-trace/index.svelte @@ -0,0 +1,5 @@ + + +