Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fetch-prerendered-base.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

fix: correctly detect prerendered paths in server `fetch` when `paths.base` is set
2 changes: 1 addition & 1 deletion packages/kit/src/runtime/server/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export function create_fetch({ event, options, manifest, state, get_cookie_heade
return await fetch(request);
}

if (has_prerendered_path(manifest, paths.base + decoded)) {
if (has_prerendered_path(manifest, decoded)) {
// The path of something prerendered could match a different route
// that is still in the manifest, leading to the wrong route being loaded.
// We therefore bail early here. The prerendered logic is different for
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/** @type {import('./$types').PageServerLoad} */
export async function load({ fetch }) {
const response = await fetch('/basepath/fetch-prerendered/shadowed/static');
const text = await response.text();

return {
status: response.status,
found: text.includes('this page was prerendered')
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<script>
/** @type {import('./$types').PageProps} */
let { data } = $props();
</script>

<h1>{data.status} {data.found}</h1>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h1>catch-all</h1>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const prerender = true;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h1>this page was prerendered</h1>
5 changes: 5 additions & 0 deletions packages/kit/test/apps/options-2/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ test.describe('paths', () => {
expect(new URL(page.url()).pathname).toBe('/basepath/hello');
});

test('serves a prerendered page for a server-side fetch of its path', async ({ page }) => {
await page.goto('/basepath/fetch-prerendered');
expect(await page.textContent('h1')).toBe('200 true');
});

test('query remote function from client accounts for base path', async ({
page,
javaScriptEnabled
Expand Down