fix: handle relative assets paths in server fetch
correctly
#12113
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The Problem
Fixes #12081 (and maybe helps with #3850).
TL;DR:
works in dev and preview, but always returns
404
with adapter-cloudflare and adapter-node.More details and exhaustive reproduction in #12081 and here
The Solution
I've extended all places that check
manifest.assets
to 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
read
implementation is available,server_fetch
will 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.read
expects a function that returns a buffer andread_implementation
returns 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 test
and lint the project withpnpm lint
andpnpm check
Changesets
pnpm changeset
and following the prompts. Changesets that add features should beminor
and those that fix bugs should bepatch
. Please prefix changeset messages withfeat:
,fix:
, orchore:
.Edits