Skip to content
Open
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
3 changes: 2 additions & 1 deletion packages/kit/src/runtime/app/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ export function read(asset) {
const file = decodeURIComponent(
DEV && asset.startsWith('/@fs') ? asset : asset.slice(base.length + 1)
);
const fileAsRoute = file.replace(/^\/?/, '/');

if (file in manifest._.server_assets) {
if (file in manifest._.server_assets || manifest._.prerendered_routes.has(fileAsRoute)) {
const length = manifest._.server_assets[file];
const type = manifest.mimeTypes[file.slice(file.lastIndexOf('.'))];
Comment on lines +60 to 64
Copy link
Member

@teemingc teemingc Jan 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be better to reimplement read rather than overloading the current implementation.

  1. Not all adapters support read so it'll be good if we can also fallback to a regular fetch if the adapter doesn't have support for it.
  2. Having the prerendered data added to the server manifest helps adapters such as the Vercel adapter automatically include the server asset in the serverless function bundle (this is different from the public assets that are uploaded separately from the serverless function). Note that this would increase the serverless function size and some platforms have a limit for this. Currently, server assets are recorded via export function find_server_assets(build_data, routes) { while remote function prerender data is simply saved to the public folder via const dest = ${config.outDir}/output/prerendered/${category}/${file};. This should also help determine the correct length rather than how it's implemented now (checks if it exists in prerendered_routes but tries to find the length from server_assets
  3. The type would always be json since that's how prerendered data is stored


Expand Down
24 changes: 10 additions & 14 deletions packages/kit/src/runtime/app/server/remote/prerender.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
parse_remote_response,
run_remote_function
} from './shared.js';
import { read } from '$app/server';
Copy link
Member

@teemingc teemingc Jan 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should import from an internal path rather than a user facing path such as $app/...


/**
* Creates a remote prerender function. When called from the browser, the function will be invoked on the server via a `fetch` call.
Expand Down Expand Up @@ -103,23 +104,18 @@ export function prerender(validate_or_fn, fn_or_options, maybe_options) {

// TODO adapters can provide prerendered data more efficiently than
// fetching from the public internet
Comment on lines 105 to 106
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// TODO adapters can provide prerendered data more efficiently than
// fetching from the public internet

const promise = (cache[key] ??= fetch(new URL(url, event.url.origin).href).then(
async (response) => {
if (!response.ok) {
throw new Error('Prerendered response not found');
}
const response = (cache[key] ??= read(url));
if (!response.ok) {
throw new Error('Prerendered response not found');
}

const prerendered = await response.json();
const prerendered = await response.json();

if (prerendered.type === 'error') {
error(prerendered.status, prerendered.error);
}
if (prerendered.type === 'error') {
error(prerendered.status, prerendered.error);
}

return prerendered.result;
}
));

return parse_remote_response(await promise, state.transport);
return parse_remote_response(prerendered.result, state.transport);
});
} catch {
// not available prerendered, fallback to normal function
Expand Down
Loading