Repository: sveltejs/kit (js)

Issue:
Pre-rendering using 'auto' broken since 1.0.0-next.587
### Describe the bug

Since [1.0.0-next.587](https://github.com/sveltejs/kit/releases/tag/%40sveltejs%2Fkit%401.0.0-next.587), PR [8131](https://github.com/sveltejs/kit/pull/8131) it seems that using `prerender = 'auto'` is broken and doesn't pre-render any files.

### Reproduction

[Stackblitz reproduction](https://stackblitz.com/edit/node-xi5xqn?file=src/routes/+layout.js)

`npm run build` and then inspect the `build` folder (there is no `prerendered` subfolder).   
Dropping back down to `1.0.0-next.586` works as expected.

### Logs

_No response_

### System Info

```Shell
  System:
    OS: Linux 5.0 undefined
    CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 16.14.2 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 7.17.0 - /usr/local/bin/npm
  npmPackages:
    @sveltejs/adapter-node: ^1.0.0 => 1.0.0 
    @sveltejs/kit: 1.0.0-next.587 => 1.0.0-next.587 
    svelte: ^3.54.0 => 3.55.0 
    vite: ^4.0.0 => 4.0.3 
```


### Severity

annoyance

### Additional Information

_No response_

Pull request description:
fix: prerender page when prerender set to 'auto' and ssr set to true
fixes #8263

### Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
- [x] It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
- [x] This message body should clearly illustrate what problems it solves.
- [x] Ideally, include a test that fails without this PR but passes with it.

### Tests
- [x] Run the tests with `pnpm test` and lint the project with `pnpm lint` and `pnpm check`

### Changesets
- [x] If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running `pnpm changeset` and following the prompts. Changesets that add features should be `minor` and those that fix bugs should be `patch`. Please prefix changeset messages with `feat:`, `fix:`, or `chore:`.


Patch:
diff --git a/.changeset/nervous-socks-end.md b/.changeset/nervous-socks-end.md
new file mode 100644
index 000000000..eb690f87e
--- /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/.changeset/strange-pens-pump.md b/.changeset/strange-pens-pump.md
new file mode 100644
index 000000000..6ed108939
--- /dev/null
+++ b/.changeset/strange-pens-pump.md
@@ -0,0 +1,5 @@
+---
+'@sveltejs/kit': patch
+---
+
+fix: check version on node fetch fail
diff --git a/documentation/docs/20-core-concepts/10-routing.md b/documentation/docs/20-core-concepts/10-routing.md
index 1646886d8..3ba58edf5 100644
--- a/documentation/docs/20-core-concepts/10-routing.md
+++ b/documentation/docs/20-core-concepts/10-routing.md
@@ -129,6 +129,10 @@ If an error occurs during `load`, SvelteKit will render a default error page. Yo
 
 SvelteKit will 'walk up the tree' looking for the closest error boundary — if the file above didn't exist it would try `src/routes/blog/+error.svelte` and then `src/routes/+error.svelte` before rendering the default error page. If _that_ fails (or if the error was thrown from the `load` function of the root `+layout`, which sits 'above' the root `+error`), SvelteKit will bail out and render a static fallback error page, which you can customise by creating a `src/error.html` file.
 
+If the error occurs inside a `load` function in `+layout(.server).js`, the closest error boundary in the tree is an `+error.svelte` file _above_ that layout (not next to it).
+
+If no route can be found (404), `src/routes/+error.svelte` (or the default error page, if that file does not exist) will be used.
+
 > `+error.svelte` is _not_ used when an error occurs inside [`handle`](/docs/hooks#server-hooks-handle) or a [+server.js](#server) request handler.
 
 You can read more about error handling [here](/docs/errors).
diff --git a/documentation/docs/30-advanced/25-errors.md b/documentation/docs/30-advanced/25-errors.md
index 249aa8dd2..24d4862f6 100644
--- a/documentation/docs/30-advanced/25-errors.md
+++ b/documentation/docs/30-advanced/25-errors.md
@@ -131,7 +131,7 @@ You can customise the fallback error page by adding a `src/error.html` file:
 
 SvelteKit will replace `%sveltekit.status%` and `%sveltekit.error.message%` with their corresponding values.
 
-If the error instead occurs inside a `load` function while rendering a page, SvelteKit will render the [`+error.svelte`](/docs/routing#error) component nearest to where the error occurred.
+If the error instead occurs inside a `load` function while rendering a page, SvelteKit will render the [`+error.svelte`](/docs/routing#error) component nearest to where the error occurred. If the error occurs inside a `load` function in `+layout(.server).js`, the closest error boundary in the tree is an `+error.svelte` file _above_ that layout (not next to it).
 
 The exception is when the error occurs inside the root `+layout.js` or `+layout.server.js`, since the root layout would ordinarily _contain_ the `+error.svelte` component. In this case, SvelteKit uses the fallback error page.
 
diff --git a/packages/adapter-netlify/package.json b/packages/adapter-netlify/package.json
index 13cd02a73..c6c0c6f64 100644
--- a/packages/adapter-netlify/package.json
+++ b/packages/adapter-netlify/package.json
@@ -44,7 +44,7 @@
 		"@sveltejs/kit": "workspace:^",
 		"@types/node": "^16.18.6",
 		"@types/set-cookie-parser": "^2.4.2",
-		"rimraf": "^3.0.2",
+		"rimraf": "^4.0.0",
 		"rollup": "^3.7.0",
 		"typescript": "^4.9.4",
 		"uvu": "^0.5.6"
diff --git a/packages/adapter-node/package.json b/packages/adapter-node/package.json
index a2297bb30..d6c224db0 100644
--- a/packages/adapter-node/package.json
+++ b/packages/adapter-node/package.json
@@ -36,7 +36,7 @@
 		"@types/node": "^16.18.6",
 		"c8": "^7.12.0",
 		"polka": "^1.0.0-next.22",
-		"rimraf": "^3.0.2",
+		"rimraf": "^4.0.0",
 		"sirv": "^2.0.2",
 		"typescript": "^4.9.4",
 		"uvu": "^0.5.6"
diff --git a/packages/kit/src/core/prerender/prerender.js b/packages/kit/src/core/prerender/prerender.js
index 0e6f86306..07d7f0136 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/src/runtime/client/client.js b/packages/kit/src/runtime/client/client.js
index ddc3a32c3..a669388e2 100644
--- a/packages/kit/src/runtime/client/client.js
+++ b/packages/kit/src/runtime/client/client.js
@@ -824,6 +824,12 @@ export function create_client({ target, base }) {
 						status = err.status;
 						error = err.body;
 					} else {
+						// Referenced node could have been removed due to redeploy, check
+						const updated = await stores.updated.check();
+						if (updated) {
+							return await native_navigation(url);
+						}
+
 						error = await handle_error(err, { params, url, route: { id: route.id } });
 					}
 
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index ff9c56b0d..69d62fe79 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -88,7 +88,7 @@ importers:
       '@types/node': ^16.18.6
       '@types/set-cookie-parser': ^2.4.2
       esbuild: ^0.16.3
-      rimraf: ^3.0.2
+      rimraf: ^4.0.0
       rollup: ^3.7.0
       set-cookie-parser: ^2.5.1
       typescript: ^4.9.4
@@ -105,7 +105,7 @@ importers:
       '@sveltejs/kit': link:../kit
       '@types/node': 16.18.6
       '@types/set-cookie-parser': 2.4.2
-      rimraf: 3.0.2
+      rimraf: 4.0.1
       rollup: 3.7.0
       typescript: 4.9.4
       uvu: 0.5.6
@@ -119,7 +119,7 @@ importers:
       '@types/node': ^16.18.6
       c8: ^7.12.0
       polka: ^1.0.0-next.22
-      rimraf: ^3.0.2
+      rimraf: ^4.0.0
       rollup: ^3.7.0
       sirv: ^2.0.2
       typescript: ^4.9.4
@@ -134,7 +134,7 @@ importers:
       '@types/node': 16.18.6
       c8: 7.12.0
       polka: 1.0.0-next.22
-      rimraf: 3.0.2
+      rimraf: 4.0.1
       sirv: 2.0.2
       typescript: 4.9.4
       uvu: 0.5.6
@@ -338,7 +338,7 @@ importers:
     specifiers:
       '@sveltejs/kit': workspace:^
       cross-env: ^7.0.3
-      rimraf: ^3.0.2
+      rimraf: ^4.0.0
       svelte: ^3.55.1
       svelte-check: ^3.0.2
       typescript: ^4.9.4
@@ -346,7 +346,7 @@ importers:
     devDependencies:
       '@sveltejs/kit': link:../../..
       cross-env: 7.0.3
-      rimraf: 3.0.2
+      rimraf: 4.0.1
       svelte: 3.55.1
       svelte-check: 3.0.2_svelte@3.55.1
       typescript: 4.9.4
@@ -356,7 +356,6 @@ importers:
     specifiers:
       '@sveltejs/kit': workspace:^
       cross-env: ^7.0.3
-      rimraf: ^3.0.2
       svelte: ^3.55.1
       svelte-check: ^3.0.2
       typescript: ^4.9.4
@@ -364,7 +363,6 @@ importers:
     devDependencies:
       '@sveltejs/kit': link:../../..
       cross-env: 7.0.3
-      rimraf: 3.0.2
       svelte: 3.55.1
       svelte-check: 3.0.2_svelte@3.55.1
       typescript: 4.9.4
@@ -408,7 +406,7 @@ importers:
     specifiers:
       '@sveltejs/kit': workspace:^
       cross-env: ^7.0.3
-      rimraf: ^3.0.2
+      rimraf: ^4.0.0
       svelte: ^3.55.1
       svelte-check: ^3.0.2
       typescript: ^4.9.4
@@ -416,7 +414,7 @@ importers:
     devDependencies:
       '@sveltejs/kit': link:../../..
       cross-env: 7.0.3
-      rimraf: 3.0.2
+      rimraf: 4.0.1
       svelte: 3.55.1
       svelte-check: 3.0.2_svelte@3.55.1
       typescript: 4.9.4
@@ -3736,6 +3734,12 @@ packages:
     dependencies:
       glob: 7.2.3
 
+  /rimraf/4.0.1:
+    resolution: {integrity: sha512-qwvb/Wzf8XJxdv8InnDtmijfbIk6gk576swPeogHbUh7AT4ezF42lvhXUdbIzMYrO4HbaXi1rYGhKTDyPF1AJw==}
+    engines: {node: '>=14'}
+    hasBin: true
+    dev: true
+
   /rollup-pluginutils/2.8.2:
     resolution: {integrity: sha512-EEp9NhnUkwY8aif6bxgovPHMoMoNr2FulJziTndpt5H9RdwC47GSGuII9XxpSdzVGM0GWrNPHV6ie1LTNJPaLQ==}
     dependencies:


Test patch:
diff --git a/packages/kit/test/apps/basics/package.json b/packages/kit/test/apps/basics/package.json
index 3c1ac04cd..6257ff4b4 100644
--- a/packages/kit/test/apps/basics/package.json
+++ b/packages/kit/test/apps/basics/package.json
@@ -14,7 +14,7 @@
 	"devDependencies": {
 		"@sveltejs/kit": "workspace:^",
 		"cross-env": "^7.0.3",
-		"rimraf": "^3.0.2",
+		"rimraf": "^4.0.0",
 		"svelte": "^3.55.1",
 		"svelte-check": "^3.0.2",
 		"typescript": "^4.9.4",
diff --git a/packages/kit/test/apps/dev-only/package.json b/packages/kit/test/apps/dev-only/package.json
index b4e3669c9..b5e510b23 100644
--- a/packages/kit/test/apps/dev-only/package.json
+++ b/packages/kit/test/apps/dev-only/package.json
@@ -12,7 +12,6 @@
 	"devDependencies": {
 		"@sveltejs/kit": "workspace:^",
 		"cross-env": "^7.0.3",
-		"rimraf": "^3.0.2",
 		"svelte": "^3.55.1",
 		"svelte-check": "^3.0.2",
 		"typescript": "^4.9.4",
diff --git a/packages/kit/test/apps/writes/package.json b/packages/kit/test/apps/writes/package.json
index 77c09f269..a4879d8c8 100644
--- a/packages/kit/test/apps/writes/package.json
+++ b/packages/kit/test/apps/writes/package.json
@@ -14,7 +14,7 @@
 	"devDependencies": {
 		"@sveltejs/kit": "workspace:^",
 		"cross-env": "^7.0.3",
-		"rimraf": "^3.0.2",
+		"rimraf": "^4.0.0",
 		"svelte": "^3.55.1",
 		"svelte-check": "^3.0.2",
 		"typescript": "^4.9.4",
diff --git a/packages/kit/test/prerendering/basics/test/test.js b/packages/kit/test/prerendering/basics/test/test.js
index 5304db890..d205597f3 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('<h1>prerendering: true/true</h1>'), 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 000000000..f1b9bcf9e
--- /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 000000000..f844d12b1
--- /dev/null
+++ b/packages/kit/test/prerendering/ssr-false/src/routes/prerenderable-3/+page.svelte
@@ -0,0 +1,1 @@
+<p>prerenderable shell</p>
diff --git a/packages/kit/test/prerendering/ssr-false/test/test.js b/packages/kit/test/prerendering/ssr-false/test/test.js
index 6b70952ef..86912a868 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', () => {