Skip to content

Commit

Permalink
fix: prerender page when prerender set to 'auto' and ssr set to true (#…
Browse files Browse the repository at this point in the history
…8481)

fixes #8263
  • Loading branch information
dummdidumm authored Jan 13, 2023
1 parent 6870a0f commit 130abe4
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/nervous-socks-end.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

fix: prerender page when prerender set to 'auto' and ssr set to true
2 changes: 1 addition & 1 deletion packages/kit/src/core/prerender/prerender.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/kit/test/prerendering/basics/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('<h1>prerendering: true/true</h1>'), content);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const prerender = 'auto';
export const ssr = true;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>prerenderable shell</p>
7 changes: 6 additions & 1 deletion packages/kit/test/prerendering/ssr-false/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down

0 comments on commit 130abe4

Please sign in to comment.