-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
fix: handle relative assets paths in server fetch correctly
#12113
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
fix: handle relative assets paths in server fetch correctly
#12113
Conversation
🦋 Changeset detectedLatest commit: e01efa1 The changes in this PR will be included in the next version bump. This PR includes changesets to release 4 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
packages/kit/test/apps/basics/src/routes/endpoint-output/fetch-asset/absolute/+server.js
Show resolved
Hide resolved
|
@eltigerchino thank you for the review :) I've corrected all the issues you've noted and tested the Cloudflare adapter again. I see some tests in CI have failed, but as far as I understand, two of them should fail (Vercel ones) Is there anything else I could/should do? |
|
Thank you! This is a really good contribution. Don't worry about some of the tests which are flaky and pass when re-run. cc: @dummdidumm do you mind taking another look at this? |
dummdidumm
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.
Fantastic work, and great PR description, was really easy to review because of that 👍
The Problem
Fixes #12081 (and maybe helps with #3850).
TL;DR:
works in dev and preview, but always returns
404with adapter-cloudflare and adapter-node.More details and exhaustive reproduction in #12081 and here
The Solution
I've extended all places that check
manifest.assetsto also checkmanifest._.server_assets.This has two benefits:
server_fetch(inpackages/kit/src/runtime/server/fetch.js) can return the file earlier (previously it fell through toresponse)This should always work because since #11649 all server assets should be copied to the output folder (source).
Other improvements
If
readimplementation is available,server_fetchwill use it to get the files directly — should be theoretically faster than a fetch.This PR is similar to what #3850 proposed, but because
state.read/options.readexpects a function that returns a buffer andread_implementationreturns a stream, they aren't compatible. Also, it still wouldn't work with Cloudflare, because there the “file read” is an async fetch.But this PR brings us as close as possible to #3850 as currently possible, because:
read— skips overhead of fetchand both of them (and maybe more adapters that I didn't test) will work with relative paths on the server.
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