Skip to content

feat: implement custom fetch for HydratedRouter - #15465

Closed
rossipedia wants to merge 6 commits into
remix-run:mainfrom
rossipedia:feat/hydrated-router-fetch
Closed

rossipedia wants to merge 6 commits into
remix-run:mainfrom
rossipedia:feat/hydrated-router-fetch

Conversation

@rossipedia

Copy link
Copy Markdown
Contributor

Implementation for #15461

@brophdawg11 brophdawg11 self-assigned this Sep 11, 2026
* Provide a custom implementation for `fetch`, which will be used to perform
* data requests for navigations and fetchers. Defaults to `window.fetch`
*/
fetch?: FetchFunction;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This almost feels like it needs a new dataOrigin config value or something :/

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does RSC currently handle this? Or does it not do the same kind of prefetching with links 🤔

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

@brophdawg11

Copy link
Copy Markdown
Contributor

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 main. Thanks @rossipedia for the original implementation!

Authored by an AI agent on behalf of @brophdawg11

@brophdawg11 brophdawg11 closed this Oct 8, 2026
@rossipedia
rossipedia deleted the feat/hydrated-router-fetch branch October 8, 2026 23:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants