Skip to content

Commit b764298

Browse files
authored
fix: do not replace headers on fetch requests with error state (#13341)
Fixes #13340
1 parent 891429e commit b764298

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

.changeset/bright-scissors-grow.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/kit': patch
3+
---
4+
5+
fix: avoid overwriting headers for sub-requests made while loading the error page

packages/kit/src/runtime/server/respond.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -508,11 +508,11 @@ export async function respond(request, options, manifest, state) {
508508
}
509509

510510
if (state.error && event.isSubRequest) {
511-
return await fetch(request, {
512-
headers: {
513-
'x-sveltekit-error': 'true'
514-
}
515-
});
511+
// avoid overwriting the headers. This could be a same origin fetch request
512+
// to an external service from the root layout while rendering an error page
513+
const headers = new Headers(request.headers);
514+
headers.set('x-sveltekit-error', 'true');
515+
return await fetch(request, { headers });
516516
}
517517

518518
if (state.error) {

0 commit comments

Comments
 (0)