Repository navigation
feat: implement custom fetch for HydratedRouter - #15465
rossipedia wants to merge 6 commits into
Conversation
| * Provide a custom implementation for `fetch`, which will be used to perform | ||
| * data requests for navigations and fetchers. Defaults to `window.fetch` | ||
| */ | ||
| fetch?: FetchFunction; |
There was a problem hiding this comment.
Custom fetch is bypassed by data prefetches
This intercepts imperative Single Fetch requests, but PrefetchPageLinksImpl still renders native <link rel="prefetch" as="fetch" href="/route.data"> elements. The browser performs those requests directly, so they never invoke HydratedRouter.fetch. A custom implementation that rewrites the origin or adds required headers therefore works for the eventual navigation but not its prefetch; in the split-origin API setup, the prefetch hits the document origin and can 404.
Can we make data prefetches use the same customization, or otherwise prevent them from targeting a different endpoint? A regression test using prefetch="intent" or prefetch="render" with an origin-rewriting custom fetch would cover this path.
Authored by an AI agent on behalf of @brophdawg11
There was a problem hiding this comment.
This almost feels like it needs a new dataOrigin config value or something :/
There was a problem hiding this comment.
How does RSC currently handle this? Or does it not do the same kind of prefetching with links 🤔
There was a problem hiding this comment.
update: Adding an unstable_serverOrigin flag to #15467 to allow link prefetching, data, and manifest requests all to use a separate origin without having to wire up a custom fetch (since a custom fetch won't handle link prefetching)
|
Superseded by #15586, which preserves all commits from this PR and consolidates the follow-up custom-fetch context, data-strategy initiator, and callback-update work into one PR targeting Authored by an AI agent on behalf of @brophdawg11 |
Implementation for #15461