Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/small-countries-doubt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

Allow endpoints to be treated as prerender entry points
5 changes: 3 additions & 2 deletions packages/kit/src/core/adapt/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ export function create_builder({ config, build_data, prerendered, log }) {
/** @param {import('types').RouteData} route */
// TODO routes should come pre-filtered
function not_prerendered(route) {
if (route.type === 'page' && route.path) {
return !prerendered_paths.has(route.path);
if (route.type === 'page' && !route.id.includes('[')) {
const path = '/' + route.id.replace(/@.+$/, '');
return !prerendered_paths.has(path);
}

return true;
Expand Down
2 changes: 1 addition & 1 deletion packages/kit/src/core/build/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export async function build(config, { log }) {
const prerendered = await prerender({
config,
entries: options.manifest_data.routes
.map((route) => (route.type === 'page' ? route.path : ''))
.map((route) => (route.id.includes('[') ? '' : '/' + route.id.replace(/@.+$/, '')))
.filter(Boolean),
files,
log
Expand Down
1 change: 0 additions & 1 deletion packages/kit/src/core/generate_manifest/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ export function generate_manifest({ build_data, relative_path, routes, format =
pattern: ${pattern},
names: ${s(names)},
types: ${s(types)},
path: ${route.path ? s(route.path) : null},
shadow: ${route.shadow ? loader(`${relative_path}/${build_data.server.vite_manifest[route.shadow].file}`) : null},
a: ${s(route.a.map(get_index))},
b: ${s(route.b.map(get_index))}
Expand Down
1 change: 0 additions & 1 deletion packages/kit/src/core/sync/create_manifest_data/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,6 @@ export default function create_manifest_data({
type: 'page',
id: unit.id,
pattern: unit.pattern,
path: unit.id.includes('[') ? '' : `/${unit.id.replace(/@(?:[a-zA-Z0-9_-]+)/g, '')}`,
shadow: unit.endpoint || null,
a: unit.page.a,
b: unit.page.b
Expand Down
5 changes: 5 additions & 0 deletions packages/kit/test/prerendering/basics/src/routes/hello.txt.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export function get() {
return {
body: 'prerendered endpoint'
};
}
5 changes: 5 additions & 0 deletions packages/kit/test/prerendering/basics/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,9 @@ test('fetching missing content results in a 404', () => {
assert.ok(content.includes('<h1>status: 404</h1>'), content);
});

test('prerenders an entry point endpoint', () => {
const content = read('hello.txt');
assert.equal(content, 'prerendered endpoint');
});

test.run();
1 change: 0 additions & 1 deletion packages/kit/types/internal.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ export interface PageData {
id: string;
shadow: string | null;
pattern: RegExp;
path: string;
a: Array<string | undefined>;
b: Array<string | undefined>;
}
Expand Down