Repository: sveltejs/kit (js)

Issue:
SvelteKit ignores page directives in `+page.server.js`
### Describe the bug

I have an app with pre-rendered pages. I'm NOT explicitly listing the pre-rendered pages in the svelte config, I'm letting the crawler discover them automatically. After migrating to `1.0.0-next.408` with the new routing, the pre-render crawler seems to be skipping pages if both of the following are true:

1. the page is behind a redirect
2. the page URL has a [param]

It was working before the routing overhaul. See the stackblitz link below for a repro. The `/foo` route redirects to `/foo/bar` which is handled by `/foo/[slug]/+page.svelte`. The `/foo2` route redirects to `/foo2/bar2` which DOES NOT have a param, it just resolves to `/foo2/bar2/+page.svelte`. Both page options are `prerender = true`, and both are linked from the home. The first is NOT prerendering but the second is. In the repro, run `npm run build` to see that 1 is getting prerendered which the other is not.

## Before routing overhaul

This was working before the routing overhaul. Previously, I was doing my redirect within a standalone endpoint with something like
```
export async function GET() {
  return {
    headers: {
      location: `/newpath`
    },
    status: 302
  }
}
```

I also notice that the logs when I used to `npm run build` used to acknowledge my redirect:


```
10:05:52 AM: .svelte-kit/output/server/immutable/chunks/Container-0a471dd0.js             0.53 KiB
10:05:52 AM: .svelte-kit/output/server/immutable/chunks/EnrichedMarkdown-324634e1.js      11.89 KiB
10:05:52 AM: .svelte-kit/output/server/immutable/chunks/SchemaLabel-59931fc3.js           7.15 KiB
10:05:52 AM: .svelte-kit/output/server/immutable/chunks/hooks-3a5209ad.js                 1.72 KiB
10:05:52 AM: (node:1377) ExperimentalWarning: buffer.Blob is an experimental feature. This feature could change at any time
10:05:52 AM: (Use `node --trace-warnings ...` to show where the warning was created)
10:05:53 AM:   302 /course -> /course/lessons/what-is-sql
10:05:58 AM: 1/1 clients in student pool are ready
10:06:03 AM: 1/1 clients in student pool are ready
10:06:03 AM: vite v3.0.2 building for production...
10:06:03 AM: transforming...
10:06:03 AM: ✓ 2 modules transformed.
10:06:03 AM: rendering chunks...
```

But now this no longer seems to be happening.


### Reproduction

https://stackblitz.com/edit/sveltejs-kit-template-default-btjtae?file=src%2Froutes%2Ffoo2%2Fbar2%2F%2Bpage.js&terminal=dev

### Logs

_No response_

### System Info

```shell
System:
    OS: Linux 5.0 undefined
    CPU: (4) 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.10 - /bin/yarn
    npm: 7.17.0 - /bin/npm
  npmPackages:
    @sveltejs/adapter-auto: next => 1.0.0-next.64 
    @sveltejs/kit: next => 1.0.0-next.406 
    svelte: ^3.46.0 => 3.49.0
```


### Severity

blocking an upgrade

### Additional Information

_No response_

Pull request:
respect `export const prerender = false` in `+page.server.js`
closes #5926. also snuck in some adjacent type fixes

### 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. All changesets should be `patch` until SvelteKit 1.0


Patch:
diff --git a/.changeset/few-hornets-joke.md b/.changeset/few-hornets-joke.md
new file mode 100644
index 000000000..e1d391fa9
--- /dev/null
+++ b/.changeset/few-hornets-joke.md
@@ -0,0 +1,5 @@
+---
+'@sveltejs/kit': patch
+---
+
+Respect `export const prerender = false` in `+page.server.js`
diff --git a/.changeset/gold-rocks-hang.md b/.changeset/gold-rocks-hang.md
new file mode 100644
index 000000000..03fd306e9
--- /dev/null
+++ b/.changeset/gold-rocks-hang.md
@@ -0,0 +1,5 @@
+---
+'create-svelte': patch
+---
+
+update `app.d.ts` for library skeleton template
diff --git a/documentation/docs/15-configuration.md b/documentation/docs/15-configuration.md
index 844ba60b3..2f99bd282 100644
--- a/documentation/docs/15-configuration.md
+++ b/documentation/docs/15-configuration.md
@@ -72,9 +72,6 @@ const config = {
 		}
 	},
 
-	// options passed to svelte.preprocess (https://svelte.dev/docs#compile-time-svelte-preprocess)
-	preprocess: null,
-
 	// options passed to @sveltejs/package
 	package: {
 		source: 'value of kit.files.lib, if available, else src/lib',
@@ -83,7 +80,10 @@ const config = {
 		// excludes all .d.ts and files starting with _ as the name
 		exports: (filepath) => !/^_|\/_|\.d\.ts$/.test(filepath),
 		files: () => true
-	}
+	},
+
+	// options passed to svelte.preprocess (https://svelte.dev/docs#compile-time-svelte-preprocess)
+	preprocess: null
 };
 
 export default config;
diff --git a/packages/create-svelte/templates/libskeleton/src/app.d.ts b/packages/create-svelte/templates/libskeleton/src/app.d.ts
index b28d84056..66327cbb1 100644
--- a/packages/create-svelte/templates/libskeleton/src/app.d.ts
+++ b/packages/create-svelte/templates/libskeleton/src/app.d.ts
@@ -6,6 +6,6 @@
 declare namespace App {
 	// interface Locals {}
 	// interface Platform {}
-	// interface Session {}
-	// interface Stuff {}
+	// interface PrivateEnv {}
+	// interface PublicEnv {}
 }
diff --git a/packages/kit/src/runtime/server/page/index.js b/packages/kit/src/runtime/server/page/index.js
index a7f6acf2c..edaa42016 100644
--- a/packages/kit/src/runtime/server/page/index.js
+++ b/packages/kit/src/runtime/server/page/index.js
@@ -117,7 +117,8 @@ export async function render_page(event, route, options, state, resolve_opts) {
 			});
 		}
 
-		const should_prerender = leaf_node.shared?.prerender ?? options.prerender.default;
+		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)) {
diff --git a/packages/kit/types/index.d.ts b/packages/kit/types/index.d.ts
index 4e63561ca..44b15f463 100644
--- a/packages/kit/types/index.d.ts
+++ b/packages/kit/types/index.d.ts
@@ -106,7 +106,6 @@ export interface Config {
 	compilerOptions?: CompileOptions;
 	extensions?: string[];
 	kit?: KitConfig;
-	preprocess?: any;
 	package?: {
 		source?: string;
 		dir?: string;
@@ -114,6 +113,7 @@ export interface Config {
 		exports?: (filepath: string) => boolean;
 		files?: (filepath: string) => boolean;
 	};
+	preprocess?: any;
 	[key: string]: any;
 }
 
diff --git a/packages/kit/types/internal.d.ts b/packages/kit/types/internal.d.ts
index 9738ab5a0..4f386bab0 100644
--- a/packages/kit/types/internal.d.ts
+++ b/packages/kit/types/internal.d.ts
@@ -211,12 +211,11 @@ export interface SSRNode {
 		hydrate?: boolean;
 		prerender?: boolean;
 		router?: boolean;
-		ssr?: boolean;
 	};
 
 	server: {
 		load?: ServerLoad;
-		HEAD?: ServerLoad;
+		prerender?: boolean;
 		POST?: Action;
 		PATCH?: Action;
 		PUT?: Action;
diff --git a/packages/package/src/types.d.ts b/packages/package/src/types.d.ts
index f08999f8c..2350e43f3 100644
--- a/packages/package/src/types.d.ts
+++ b/packages/package/src/types.d.ts
@@ -18,10 +18,10 @@ export type RecursiveRequired<T> = {
 };
 
 export interface ValidatedConfig {
-	preprocess?: any;
 	extensions: string[];
-	package: RecursiveRequired<PackageConfig>;
 	kit?: any;
+	package: RecursiveRequired<PackageConfig>;
+	preprocess?: any;
 }
 
 export type Validator<T = any> = (input: T, keypath: string) => T;
diff --git a/packages/package/types/index.d.ts b/packages/package/types/index.d.ts
index 07670d36b..0e1ba39b6 100644
--- a/packages/package/types/index.d.ts
+++ b/packages/package/types/index.d.ts
@@ -29,6 +29,6 @@ export interface Config {
 	compilerOptions?: CompileOptions;
 	extensions?: string[];
 	kit?: any;
-	preprocess?: any;
 	package?: PackageConfig;
+	preprocess?: any;
 }


Test patch:
diff --git a/packages/kit/test/prerendering/basics/src/routes/page-server-options/+page.server.js b/packages/kit/test/prerendering/basics/src/routes/page-server-options/+page.server.js
new file mode 100644
index 000000000..d43d0cd2a
--- /dev/null
+++ b/packages/kit/test/prerendering/basics/src/routes/page-server-options/+page.server.js
@@ -0,0 +1,1 @@
+export const prerender = false;
diff --git a/packages/kit/test/prerendering/basics/src/routes/page-server-options/+page.svelte b/packages/kit/test/prerendering/basics/src/routes/page-server-options/+page.svelte
new file mode 100644
index 000000000..3c3d6df7a
--- /dev/null
+++ b/packages/kit/test/prerendering/basics/src/routes/page-server-options/+page.svelte
@@ -0,0 +1,1 @@
+<h1>This should not be visible</h1>
diff --git a/packages/kit/test/prerendering/basics/test/test.js b/packages/kit/test/prerendering/basics/test/test.js
index 6a213c913..e79573f0f 100644
--- a/packages/kit/test/prerendering/basics/test/test.js
+++ b/packages/kit/test/prerendering/basics/test/test.js
@@ -99,6 +99,11 @@ test('does not prerender page with shadow endpoint with non-load handler', () =>
 	assert.ok(!fs.existsSync(`${build}/shadowed-post/__data.json`));
 });
 
+test('does not prerender page with prerender = false in +page.server.js', () => {
+	assert.ok(!fs.existsSync(`${build}/page-server-options.html`));
+	assert.ok(!fs.existsSync(`${build}/page-server-options/__data.json`));
+});
+
 test('decodes paths when writing files', () => {
 	let content = read('encoding/path with spaces.html');
 	assert.ok(content.includes('<p id="a">path with spaces</p>'));