Skip to content

fix(rsc): fetch /path.manifest for single paths #13854

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 23, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions packages/react-router/lib/rsc/browser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -723,15 +723,32 @@ const discoveredPaths = new Set<string>();
// https://stackoverflow.com/a/417184
const URL_LIMIT = 7680;

function getManifestUrl(paths: string[]): URL | null {
if (paths.length === 0) {
return null;
}

if (paths.length === 1) {
return new URL(`${paths[0]}.manifest`, window.location.origin);
}

let basename = (window.__router.basename ?? "").replace(/^\/|\/$/g, "");
let url = new URL(`${basename}/.manifest`, window.location.origin);
paths.sort().forEach((path) => url.searchParams.append("p", path));

return url;
}

async function fetchAndApplyManifestPatches(
paths: string[],
decode: DecodeServerResponseFunction,
fetchImplementation: (request: Request) => Promise<Response>,
signal?: AbortSignal
) {
let basename = (window.__router.basename ?? "").replace(/^\/|\/$/g, "");
let url = new URL(`${basename}/.manifest`, window.location.origin);
paths.sort().forEach((path) => url.searchParams.append("p", path));
let url = getManifestUrl(paths);
if (url == null) {
return;
}

// If the URL is nearing the ~8k limit on GET requests, skip this optimization
// step and just let discovery happen on link click. We also wipe out the
Expand Down