From 4d5089b7636a1013812a932c7169c81ac14f8561 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mihael=20Muti=C4=87?= <35368241+PH4NTOMiki@users.noreply.github.com> Date: Tue, 8 Feb 2022 17:56:00 +0100 Subject: [PATCH] Fix shadow endpoint when ending with slash (#3740) --- .changeset/mighty-cycles-double.md | 5 +++++ packages/kit/src/runtime/client/renderer.js | 11 +++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) create mode 100644 .changeset/mighty-cycles-double.md diff --git a/.changeset/mighty-cycles-double.md b/.changeset/mighty-cycles-double.md new file mode 100644 index 000000000000..ef15b25b4305 --- /dev/null +++ b/.changeset/mighty-cycles-double.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/kit': patch +--- + +fixes an error with fetching shadow endpoints if they are ending with '/' diff --git a/packages/kit/src/runtime/client/renderer.js b/packages/kit/src/runtime/client/renderer.js index 024fcc1451bb..c85fa5e23dd8 100644 --- a/packages/kit/src/runtime/client/renderer.js +++ b/packages/kit/src/runtime/client/renderer.js @@ -753,11 +753,14 @@ export class Renderer { let props = {}; if (has_shadow && i === a.length - 1) { - const res = await fetch(`${url.pathname}/__data.json`, { - headers: { - 'x-sveltekit-noredirect': 'true' + const res = await fetch( + `${url.pathname}${url.pathname.endsWith('/') ? '' : '/'}__data.json`, + { + headers: { + 'x-sveltekit-noredirect': 'true' + } } - }); + ); if (res.ok) { const redirect = res.headers.get('x-sveltekit-location');