From 130abe43cef2cfbaf922aa16b20cbd4332a07c15 Mon Sep 17 00:00:00 2001 From: Simon H <5968653+dummdidumm@users.noreply.github.com> Date: Fri, 13 Jan 2023 04:19:03 +0100 Subject: [PATCH] fix: prerender page when prerender set to 'auto' and ssr set to true (#8481) fixes #8263 --- .changeset/nervous-socks-end.md | 5 +++++ packages/kit/src/core/prerender/prerender.js | 2 +- packages/kit/test/prerendering/basics/test/test.js | 2 +- .../ssr-false/src/routes/prerenderable-3/+page.js | 2 ++ .../ssr-false/src/routes/prerenderable-3/+page.svelte | 1 + packages/kit/test/prerendering/ssr-false/test/test.js | 7 ++++++- 6 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 .changeset/nervous-socks-end.md create mode 100644 packages/kit/test/prerendering/ssr-false/src/routes/prerenderable-3/+page.js create mode 100644 packages/kit/test/prerendering/ssr-false/src/routes/prerenderable-3/+page.svelte diff --git a/.changeset/nervous-socks-end.md b/.changeset/nervous-socks-end.md new file mode 100644 index 000000000000..eb690f87eff8 --- /dev/null +++ b/.changeset/nervous-socks-end.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/kit': patch +--- + +fix: prerender page when prerender set to 'auto' and ssr set to true diff --git a/packages/kit/src/core/prerender/prerender.js b/packages/kit/src/core/prerender/prerender.js index 0e6f86306fda..07d7f0136807 100644 --- a/packages/kit/src/core/prerender/prerender.js +++ b/packages/kit/src/core/prerender/prerender.js @@ -413,7 +413,7 @@ export async function prerender() { // People can opt out of this behavior by explicitly setting prerender to false (should_prerender !== false && get_option(nodes, 'ssr') === false && !page?.server?.actions ? 'auto' - : false); + : should_prerender ?? false); prerender_map.set(route.id, prerender); } diff --git a/packages/kit/test/prerendering/basics/test/test.js b/packages/kit/test/prerendering/basics/test/test.js index 5304db89018f..d205597f3446 100644 --- a/packages/kit/test/prerendering/basics/test/test.js +++ b/packages/kit/test/prerendering/basics/test/test.js @@ -139,7 +139,7 @@ test('decodes paths when writing files', () => { assert.equal(content, JSON.stringify({ path: 'path with encoded spaces' })); }); -test('prerendering is set to true in global code of hooks.js', () => { +test('prerendering is set to true in root +layout.js', () => { const content = read('prerendering-true.html'); assert.ok(content.includes('

prerendering: true/true

'), content); }); diff --git a/packages/kit/test/prerendering/ssr-false/src/routes/prerenderable-3/+page.js b/packages/kit/test/prerendering/ssr-false/src/routes/prerenderable-3/+page.js new file mode 100644 index 000000000000..f1b9bcf9eee4 --- /dev/null +++ b/packages/kit/test/prerendering/ssr-false/src/routes/prerenderable-3/+page.js @@ -0,0 +1,2 @@ +export const prerender = 'auto'; +export const ssr = true; diff --git a/packages/kit/test/prerendering/ssr-false/src/routes/prerenderable-3/+page.svelte b/packages/kit/test/prerendering/ssr-false/src/routes/prerenderable-3/+page.svelte new file mode 100644 index 000000000000..f844d12b1532 --- /dev/null +++ b/packages/kit/test/prerendering/ssr-false/src/routes/prerenderable-3/+page.svelte @@ -0,0 +1 @@ +

prerenderable shell

diff --git a/packages/kit/test/prerendering/ssr-false/test/test.js b/packages/kit/test/prerendering/ssr-false/test/test.js index 6b70952efcce..86912a8685ba 100644 --- a/packages/kit/test/prerendering/ssr-false/test/test.js +++ b/packages/kit/test/prerendering/ssr-false/test/test.js @@ -18,8 +18,13 @@ test('prerenders /prerenderable-2 shell', () => { assert.ok(!content.includes('prerenderable shell')); }); +test('prerenders /prerenderable-3 shell with ssr=true and prerender=auto', () => { + const content = read('prerenderable-3.html'); + assert.ok(content.includes('prerenderable shell')); +}); + test('does not prerender non prerenderable things', () => { - assert.equal(fs.readdirSync(build).length, 2); + assert.equal(fs.readdirSync(build).length, 3); }); test('keeps not-explicitly-prerendered routes in the manifest', () => {