Repository: sveltejs/kit (JavaScript)

Issue:
prerender=true and ssr=false mix build wrong
### Describe the bug

I build a site with static page and dynamic page both, this problem has broken dynamic pages

### Reproduction

```sh
# select Skeleton project
npm create svelte@latest test
cd test
npm i
echo 'export const prerender = true;export const ssr = false;export async function load() {};' > src/routes/+layout.server.ts
npm run build
npm run preview -- --open 
# got 500, expect Skeleton default page
```

### Logs

_No response_

### System Info

```Shell
System:
    OS: Linux 6.1 Debian GNU/Linux 12 (bookworm) 12 (bookworm)
    CPU: (16) x64 AMD Ryzen 7 5700G with Radeon Graphics
    Memory: 17.72 GB / 30.64 GB
    Container: Yes
    Shell: 5.2.15 - /bin/bash
  Binaries:
    Node: 18.17.1 - /usr/bin/node
    Yarn: 1.22.19 - /usr/bin/yarn
    npm: 9.6.7 - /usr/bin/npm
    pnpm: 7.18.0 - /usr/bin/pnpm
    bun: 1.0.2 - ~/.bun/bin/bun
  Browsers:
    Chrome: 119.0.6045.105
  npmPackages:
    @sveltejs/adapter-auto: ^2.0.0 => 2.1.1 
    @sveltejs/adapter-static: ^2.0.3 => 2.0.3 
    @sveltejs/kit: ^1.5.0 => 1.27.3 
    svelte: ^3.54.0 => 3.59.2 
    vite: ^4.0.0 => 4.5.0
```


### Severity

blocking all usage of SvelteKit

### Additional Information

I use `+layout.server.ts` to provide `{ navs: [ {name:"home",link: "/"} ] }` for breadcrumb nav

```log
src/routes/
├── +page.svelte
├── +layout.server.ts     # { navs: [ {name:"home",link: "/"] }
└── user
    ├── +layout.server.ts # { navs: [ {name:"home",link: "/"}, {name:"user center",link: "/user"}] }
    └── +page.svelte
```



Discussion:
miss generate `/__data.json`
#10332 the similar problem



Patch:
diff --git a/.changeset/eight-moons-kick.md b/.changeset/eight-moons-kick.md
new file mode 100644
index 000000000000..560517572200
--- /dev/null
+++ b/.changeset/eight-moons-kick.md
@@ -0,0 +1,5 @@
+---
+'@sveltejs/kit': patch
+---
+
+fix: generate `__data.json` for prerendered pages when SSR is turned off
diff --git a/packages/kit/src/runtime/server/page/index.js b/packages/kit/src/runtime/server/page/index.js
index 6ba98410d50f..f99391b1365f 100644
--- a/packages/kit/src/runtime/server/page/index.js
+++ b/packages/kit/src/runtime/server/page/index.js
@@ -99,7 +99,7 @@ export async function render_page(event, page, options, manifest, state, resolve
 		/** @type {import('./types').Fetched[]} */
 		const fetched = [];
 
-		if (get_option(nodes, 'ssr') === false) {
+		if (get_option(nodes, 'ssr') === false && !state.prerendering) {
 			return await render_response({
 				branch: [],
 				fetched,


Test patch:
diff --git a/packages/kit/test/prerendering/basics/src/routes/shadowed-get/ssr-off/+page.server.js b/packages/kit/test/prerendering/basics/src/routes/shadowed-get/ssr-off/+page.server.js
new file mode 100644
index 000000000000..ac41ba4b7e77
--- /dev/null
+++ b/packages/kit/test/prerendering/basics/src/routes/shadowed-get/ssr-off/+page.server.js
@@ -0,0 +1,7 @@
+export const ssr = false;
+
+export function load() {
+	return {
+		answer: 42
+	};
+}
diff --git a/packages/kit/test/prerendering/basics/src/routes/shadowed-get/ssr-off/+page.svelte b/packages/kit/test/prerendering/basics/src/routes/shadowed-get/ssr-off/+page.svelte
new file mode 100644
index 000000000000..a475b1237f27
--- /dev/null
+++ b/packages/kit/test/prerendering/basics/src/routes/shadowed-get/ssr-off/+page.svelte
@@ -0,0 +1,6 @@
+<script>
+	/** @type {import('./$types').PageData} */
+	export let data;
+</script>
+
+<h1>The answer is {data.answer}</h1>
diff --git a/packages/kit/test/prerendering/basics/test/tests.spec.js b/packages/kit/test/prerendering/basics/test/tests.spec.js
index 993f4f022dfd..3a830c97e96e 100644
--- a/packages/kit/test/prerendering/basics/test/tests.spec.js
+++ b/packages/kit/test/prerendering/basics/test/tests.spec.js
@@ -114,6 +114,21 @@ test('generates __data.json file for shadow endpoints', () => {
 	});
 });
 
+test('generates __data.json file for shadow endpoints with ssr turned off', () => {
+	const data = JSON.parse(read('shadowed-get/ssr-off/__data.json'));
+	expect(data).toEqual({
+		type: 'data',
+		nodes: [
+			null,
+			{
+				type: 'data',
+				data: [{ answer: 1 }, 42],
+				uses: {}
+			}
+		]
+	});
+});
+
 test('does not prerender page with shadow endpoint with non-load handler', () => {
 	assert.isFalse(fs.existsSync(`${build}/shadowed-post.html`));
 	assert.isFalse(fs.existsSync(`${build}/shadowed-post/__data.json`));