fix: reuse cached fetch responses when a cross-origin url is not in canonical form - #16339
Merged
Rich-Harris merged 3 commits intoAug 17, 2026
Conversation
|
Install the latest version of pnpm add https://pkg.svelte.dev/@sveltejs/kit/c/5c0a735746fad6936592387352305ae163f19f4aOpen in Note This PR is from a fork. A maintainer must approve approve each commit before it can be built and installed. |
🦋 Changeset detectedLatest commit: 5c0a735 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
Nic-Polumeyv
force-pushed
the
fix-fetch-cache-url-normalization
branch
from
July 15, 2026 01:07
cb5e710 to
dc68d3f
Compare
6 tasks
Rich-Harris
approved these changes
Aug 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
closes #14781
During SSR, fetch responses are embedded as
<script data-sveltekit-fetched data-url=...>tags, and during hydration the client rebuilds the url to find them instead of hitting the network. The two sides build it differently. The server serializes the normalized href fromnew URL(input, event.url), while the client keeps the raw string, because prerendered pages may be served from any origin. That reasoning holds for same-origin urls, which are serialized path-relative, but cross-origin urls are absolute on both sides, so a raw string likehttp://localhost:8080without the trailing slash misses the cache and the request fires a second time from the browser.The fix normalizes
requestedtoresolved.hrefin the cross-origin case only. Normalizing inbuild_selectorinstead, as suggested in the issue, would break the same-origin case,new URL('/mock')throws without a base.requestedalso became aconstderived fromresolvedsince the mutation was no longer needed.The new test fails on main, rendering
count: 2after the hydration refetch overwrites the SSR data.Not fixed here: request bodies are hashed as strings on the server but dropped from the client hash when they are not strings, so POST-with-body fetches still miss the cache. Can follow up separately.
Caching under the normalized href also meant a non-GET fetch spelled without the trailing slash could no longer evict the entry, so the second commit derives the eviction key the same way.
Also not fixed: on prerendered pages the server classifies same-origin against
prerender.originwhile the client uses the live origin, so an absolute url pointing at the deploy origin still misses the cache.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