Repository: sveltejs/kit
Pull request #6248 (2022-08-25 00:15:11)

warn about `redirect` bug
pending a (hopefully swift) resolution of #5952

changeset-bot[bot]: ###  ⚠️  No Changeset found

Latest commit: 0e357e13b51fe2c08e3c43bd6d6aa5d186c377bb

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. **If these changes should result in a version bump, you need to add a changeset.**

<details><summary>This PR includes no changesets</summary>

  When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

</details>

[Click here to learn what changesets are, and how to add one](https://github.com/changesets/changesets/blob/master/docs/adding-a-changeset.md).

[Click here if you're a maintainer who wants to add a changeset to this PR](https://github.com/sveltejs/kit/new/redirect-warn?filename=.changeset/odd-avocados-mate.md&value=---%0A%0A---%0A%0Awarn%20about%20%60redirect%60%20bug%0A)



Patch:
diff --git a/.changeset/pre.json b/.changeset/pre.json
index c0c9e46af..273331419 100644
--- a/.changeset/pre.json
+++ b/.changeset/pre.json
@@ -976,6 +976,7 @@
     "strong-apples-walk",
     "strong-carrots-work",
     "strong-cats-wonder",
+    "strong-cooks-run",
     "strong-cooks-turn",
     "strong-cups-yell",
     "strong-files-obey",
diff --git a/.changeset/strong-cooks-run.md b/.changeset/strong-cooks-run.md
new file mode 100644
index 000000000..18b6984a3
--- /dev/null
+++ b/.changeset/strong-cooks-run.md
@@ -0,0 +1,5 @@
+---
+'@sveltejs/kit': patch
+---
+
+[fix] only generate blank non-SSR pages when prerendering is enabled
diff --git a/documentation/docs/01-project-structure.md b/documentation/docs/01-project-structure.md
index 93b637949..737c5b9f8 100644
--- a/documentation/docs/01-project-structure.md
+++ b/documentation/docs/01-project-structure.md
@@ -38,7 +38,7 @@ The `src` directory contains the meat of your project.
 - `routes` contains the [routes](/docs/routing) of your application
 - `app.html` is your page template — an HTML document containing the following placeholders:
   - `%sveltekit.head%` — `<link>` and `<script>` elements needed by the app, plus any `<svelte:head>` content
-  - `%sveltekit.body%` — the markup for a rendered page
+  - `%sveltekit.body%` — the markup for a rendered page. Typically this lives inside a `<div>` or other element, rather than directly inside `<body>`, to prevent bugs caused by browser extensions injecting elements that are then destroyed by the hydration process
   - `%sveltekit.assets%` — either [`paths.assets`](/docs/configuration#paths), if specified, or a relative path to [`paths.base`](/docs/configuration#base)
   - `%sveltekit.nonce%` — a [CSP](/docs/configuration#csp) nonce for manually included links and scripts, if used
 - `hooks.js` (optional) contains your application's [hooks](/docs/hooks)
diff --git a/documentation/docs/05-load.md b/documentation/docs/05-load.md
index f2f9f65fb..b38a211f2 100644
--- a/documentation/docs/05-load.md
+++ b/documentation/docs/05-load.md
@@ -327,6 +327,8 @@ If an _unexpected_ error is thrown, SvelteKit will invoke [`handleError`](/docs/
 
 To redirect users, use the `redirect` helper from `@sveltejs/kit` to specify the location to which they should be redirected alongside a `3xx` status code.
 
+> There is a known bug with `redirect`: it will currently fail during client-side navigation, due to [#5952](https://github.com/sveltejs/kit/issues/5952)
+
 ```diff
 /// file: src/routes/admin/+layout.server.js
 -import { error } from '@sveltejs/kit';
diff --git a/packages/kit/CHANGELOG.md b/packages/kit/CHANGELOG.md
index ea762d6e1..779dbb06a 100644
--- a/packages/kit/CHANGELOG.md
+++ b/packages/kit/CHANGELOG.md
@@ -1,5 +1,11 @@
 # @sveltejs/kit
 
+## 1.0.0-next.437
+
+### Patch Changes
+
+- [fix] only generate blank non-SSR pages when prerendering is enabled ([#6251](https://github.com/sveltejs/kit/pull/6251))
+
 ## 1.0.0-next.436
 
 ### Patch Changes
diff --git a/packages/kit/package.json b/packages/kit/package.json
index 152e8a89c..3d4ceb69c 100644
--- a/packages/kit/package.json
+++ b/packages/kit/package.json
@@ -1,6 +1,6 @@
 {
 	"name": "@sveltejs/kit",
-	"version": "1.0.0-next.436",
+	"version": "1.0.0-next.437",
 	"repository": {
 		"type": "git",
 		"url": "https://github.com/sveltejs/kit",
diff --git a/packages/kit/src/runtime/server/page/index.js b/packages/kit/src/runtime/server/page/index.js
index ebe1f005d..737943603 100644
--- a/packages/kit/src/runtime/server/page/index.js
+++ b/packages/kit/src/runtime/server/page/index.js
@@ -104,6 +104,27 @@ export async function render_page(event, route, page, options, state, resolve_op
 		const should_prerender_data = nodes.some((node) => node?.server);
 		const data_pathname = `${event.url.pathname.replace(/\/$/, '')}/__data.json`;
 
+		// it's crucial that we do this before returning the non-SSR response, otherwise
+		// SvelteKit will erroneously believe that the path has been prerendered,
+		// causing functions to be omitted from the manifesst generated later
+		const should_prerender =
+			leaf_node.shared?.prerender ?? leaf_node.server?.prerender ?? options.prerender.default;
+		if (should_prerender) {
+			const mod = leaf_node.server;
+			if (mod && (mod.POST || mod.PUT || mod.DELETE || mod.PATCH)) {
+				throw new Error('Cannot prerender pages that have endpoints with mutative methods');
+			}
+		} else if (state.prerendering) {
+			// if the page isn't marked as prerenderable (or is explicitly
+			// marked NOT prerenderable, if `prerender.default` is `true`),
+			// then bail out at this point
+			if (!should_prerender) {
+				return new Response(undefined, {
+					status: 204
+				});
+			}
+		}
+
 		if (!resolve_opts.ssr) {
 			return await render_response({
 				branch: [],
@@ -123,24 +144,6 @@ export async function render_page(event, route, page, options, state, resolve_op
 			});
 		}
 
-		const should_prerender =
-			leaf_node.shared?.prerender ?? leaf_node.server?.prerender ?? options.prerender.default;
-		if (should_prerender) {
-			const mod = leaf_node.server;
-			if (mod && (mod.POST || mod.PUT || mod.DELETE || mod.PATCH)) {
-				throw new Error('Cannot prerender pages that have endpoints with mutative methods');
-			}
-		} else if (state.prerendering) {
-			// if the page isn't marked as prerenderable (or is explicitly
-			// marked NOT prerenderable, if `prerender.default` is `true`),
-			// then bail out at this point
-			if (!should_prerender) {
-				return new Response(undefined, {
-					status: 204
-				});
-			}
-		}
-
 		/** @type {Array<Loaded | null>} */
 		let branch = [];
 
diff --git a/sites/kit.svelte.dev/src/lib/docs/client/docs.css b/sites/kit.svelte.dev/src/lib/docs/client/docs.css
index f6e9da40a..8688c0dae 100644
--- a/sites/kit.svelte.dev/src/lib/docs/client/docs.css
+++ b/sites/kit.svelte.dev/src/lib/docs/client/docs.css
@@ -210,7 +210,7 @@
 }
 
 .content ul > li {
-	margin: 0.5em 0;
+	margin: 0.5em 0 !important;
 }
 
 /** hacky overrides to allow filenames inside code blocks —


Test patch:
diff --git a/packages/kit/test/apps/amp/playwright.config.js b/packages/kit/test/apps/amp/playwright.config.js
index e83b1fd33..e97e615a6 100644
--- a/packages/kit/test/apps/amp/playwright.config.js
+++ b/packages/kit/test/apps/amp/playwright.config.js
@@ -1,6 +1,6 @@
 import { config } from '../../utils.js';
 
-config.webServer && (config.webServer.timeout = 15000); // AMP validator needs a long time to get moving
+config.webServer && (config.webServer.timeout = 45000); // AMP validator needs a long time to get moving
 
 // remove any projects with javaScriptEnabled
 const projects = config.projects || [];