Skip to content

Commit 1a989af

Browse files
committed
allow endpoints to be treated as prerender entry points - fixes #2541
1 parent 2813974 commit 1a989af

File tree

8 files changed

+19
-6
lines changed

8 files changed

+19
-6
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/kit': patch
3+
---
4+
5+
Allow endpoints to be treated as prerender entry points

packages/kit/src/core/adapt/builder.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ export function create_builder({ config, build_data, prerendered, log }) {
1717
/** @param {import('types').RouteData} route */
1818
// TODO routes should come pre-filtered
1919
function not_prerendered(route) {
20-
if (route.type === 'page' && route.path) {
21-
return !prerendered_paths.has(route.path);
20+
if (route.type === 'page' && !route.id.includes('[')) {
21+
const path = '/' + route.id.replace(/@.+$/, '');
22+
return !prerendered_paths.has(path);
2223
}
2324

2425
return true;

packages/kit/src/core/build/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export async function build(config, { log }) {
7979
const prerendered = await prerender({
8080
config,
8181
entries: options.manifest_data.routes
82-
.map((route) => (route.type === 'page' ? route.path : ''))
82+
.map((route) => (route.id.includes('[') ? '' : '/' + route.id.replace(/@.+$/, '')))
8383
.filter(Boolean),
8484
files,
8585
log

packages/kit/src/core/generate_manifest/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ export function generate_manifest({ build_data, relative_path, routes, format =
8585
pattern: ${pattern},
8686
names: ${s(names)},
8787
types: ${s(types)},
88-
path: ${route.path ? s(route.path) : null},
8988
shadow: ${route.shadow ? loader(`${relative_path}/${build_data.server.vite_manifest[route.shadow].file}`) : null},
9089
a: ${s(route.a.map(get_index))},
9190
b: ${s(route.b.map(get_index))}

packages/kit/src/core/sync/create_manifest_data/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,6 @@ export default function create_manifest_data({
234234
type: 'page',
235235
id: unit.id,
236236
pattern: unit.pattern,
237-
path: unit.id.includes('[') ? '' : `/${unit.id.replace(/@(?:[a-zA-Z0-9_-]+)/g, '')}`,
238237
shadow: unit.endpoint || null,
239238
a: unit.page.a,
240239
b: unit.page.b
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export function get() {
2+
return {
3+
body: 'prerendered endpoint'
4+
};
5+
}

packages/kit/test/prerendering/basics/test/test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,9 @@ test('fetching missing content results in a 404', () => {
114114
assert.ok(content.includes('<h1>status: 404</h1>'), content);
115115
});
116116

117+
test('prerenders an entry point endpoint', () => {
118+
const content = read('hello.txt');
119+
assert.equal(content, 'prerendered endpoint');
120+
});
121+
117122
test.run();

packages/kit/types/internal.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ export interface PageData {
126126
id: string;
127127
shadow: string | null;
128128
pattern: RegExp;
129-
path: string;
130129
a: Array<string | undefined>;
131130
b: Array<string | undefined>;
132131
}

0 commit comments

Comments
 (0)