-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
feat: use read to retrieve prerendered data
#15037
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat: use read to retrieve prerendered data
#15037
Conversation
|
read to retrieve prerendered data
| parse_remote_response, | ||
| run_remote_function | ||
| } from './shared.js'; | ||
| import { read } from '$app/server'; |
There was a problem hiding this comment.
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 a user facing path such as $app/...
| // TODO adapters can provide prerendered data more efficiently than | ||
| // fetching from the public internet |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| // TODO adapters can provide prerendered data more efficiently than | |
| // fetching from the public internet |
| 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('.'))]; |
There was a problem hiding this comment.
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.
- Not all adapters support
readso it'll be good if we can also fallback to a regular fetch if the adapter doesn't have support for it. - 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 - The
typewould always be json since that's how prerendered data is stored
teemingc
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR! I think this is worth pursuing but the concerns I highlighted would need to be addressed. You can also verify the solution by adding tests to each adapter's e2e test suite which should have a SvelteKit app built using the given adapter (we're only missing one for Vercel but we plan to set up some actual deployment mechanism to test against).
Resolves #15035
This PR is an attempt at hopefully guiding someone in the right direction. I made a best effort to put forward a solution to the issue but ultimately I'm not super confident of the approach here and I'm not knowledgeable enough about the codebase to come up with a better one at this time. Hopefully, someone who knows this area better can take this and run with it, or at least provide some suggestions on how I can improve this more.
This solution solves the problem for cloudflare adapters and locally, but could break other implementations.
Brief Restatement of Problem
when using cloudflare, and likely other adapters, Cloudflare Workers prevents us from making full fetch requests to the same worker, presumably to prevent untraceable infinite call loops? Instead, we're meant to use service bindings like
env.ASSETS.fetch().Solution
$app/server's read. (there was already a TODO to allow adapters to inject their own methods here, I thought this might be a step in that direction)$app/serverread function to allow prerendered routes as well as server assets found in the manifestProblems
manifest._.server_assetsobject but couldn't quite get there. Help!Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm testand lint the project withpnpm lintandpnpm checkChangesets
pnpm changesetand following the prompts. Changesets that add features should beminorand those that fix bugs should bepatch. Please prefix changeset messages withfeat:,fix:, orchore:.Edits