Repository navigation
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 done
Rich-Harris
approved these changes
Aug 17, 2026
dadezzz
added a commit
to dadezzz/events-cash-register
that referenced
this pull request
Oct 5, 2026
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