From 8cba7449552e427b4c75e30149b5819513b59b9e Mon Sep 17 00:00:00 2001 From: Chew Tee Ming Date: Fri, 25 Oct 2024 16:11:22 +0800 Subject: [PATCH 1/3] revert server read for fetch --- packages/kit/src/runtime/server/fetch.js | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/packages/kit/src/runtime/server/fetch.js b/packages/kit/src/runtime/server/fetch.js index 7e2177d6661c..d21e7b10ee53 100644 --- a/packages/kit/src/runtime/server/fetch.js +++ b/packages/kit/src/runtime/server/fetch.js @@ -1,7 +1,6 @@ import * as set_cookie_parser from 'set-cookie-parser'; import { respond } from './respond.js'; import * as paths from '__sveltekit/paths'; -import { read_implementation } from '__sveltekit/server'; /** * @param {{ @@ -97,16 +96,6 @@ export function create_fetch({ event, options, manifest, state, get_cookie_heade return new Response(state.read(file), { headers: type ? { 'content-type': type } : {} }); - } else if (read_implementation) { - const length = manifest._.server_assets[file]; - const type = manifest.mimeTypes[file.slice(file.lastIndexOf('.'))]; - - return new Response(read_implementation(file), { - headers: { - 'Content-Length': '' + length, - 'Content-Type': type - } - }); } return await fetch(request); From e014cc6da7defb7c74896dc7ee3fdafbe73ec001 Mon Sep 17 00:00:00 2001 From: Chew Tee Ming Date: Fri, 25 Oct 2024 16:12:42 +0800 Subject: [PATCH 2/3] changeset --- .changeset/eight-insects-live.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/eight-insects-live.md diff --git a/.changeset/eight-insects-live.md b/.changeset/eight-insects-live.md new file mode 100644 index 000000000000..8853decf9940 --- /dev/null +++ b/.changeset/eight-insects-live.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/kit': patch +--- + +fix: revert reading assets directly when using the load function's fetch From 9a2fe16c672666c642737839f38c984f53f3c8de Mon Sep 17 00:00:00 2001 From: Simon H <5968653+dummdidumm@users.noreply.github.com> Date: Fri, 25 Oct 2024 11:49:03 +0200 Subject: [PATCH 3/3] check file existance instead --- .changeset/eight-insects-live.md | 2 +- packages/kit/src/runtime/server/fetch.js | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/.changeset/eight-insects-live.md b/.changeset/eight-insects-live.md index 8853decf9940..ad50fb22cd4f 100644 --- a/.changeset/eight-insects-live.md +++ b/.changeset/eight-insects-live.md @@ -2,4 +2,4 @@ '@sveltejs/kit': patch --- -fix: revert reading assets directly when using the load function's fetch +fix: don't try reading assets directly that aren't present diff --git a/packages/kit/src/runtime/server/fetch.js b/packages/kit/src/runtime/server/fetch.js index d21e7b10ee53..417b59c93063 100644 --- a/packages/kit/src/runtime/server/fetch.js +++ b/packages/kit/src/runtime/server/fetch.js @@ -1,6 +1,7 @@ import * as set_cookie_parser from 'set-cookie-parser'; import { respond } from './respond.js'; import * as paths from '__sveltekit/paths'; +import { read_implementation } from '__sveltekit/server'; /** * @param {{ @@ -96,6 +97,16 @@ export function create_fetch({ event, options, manifest, state, get_cookie_heade return new Response(state.read(file), { headers: type ? { 'content-type': type } : {} }); + } else if (read_implementation && file in manifest._.server_assets) { + const length = manifest._.server_assets[file]; + const type = manifest.mimeTypes[file.slice(file.lastIndexOf('.'))]; + + return new Response(read_implementation(file), { + headers: { + 'Content-Length': '' + length, + 'Content-Type': type + } + }); } return await fetch(request);