Skip to content

Commit 2d18411

Browse files
fix(rsc): fetch /path.manifest for single paths (#13854)
1 parent ab92583 commit 2d18411

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

packages/react-router/lib/rsc/browser.tsx

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -723,15 +723,32 @@ const discoveredPaths = new Set<string>();
723723
// https://stackoverflow.com/a/417184
724724
const URL_LIMIT = 7680;
725725

726+
function getManifestUrl(paths: string[]): URL | null {
727+
if (paths.length === 0) {
728+
return null;
729+
}
730+
731+
if (paths.length === 1) {
732+
return new URL(`${paths[0]}.manifest`, window.location.origin);
733+
}
734+
735+
let basename = (window.__router.basename ?? "").replace(/^\/|\/$/g, "");
736+
let url = new URL(`${basename}/.manifest`, window.location.origin);
737+
paths.sort().forEach((path) => url.searchParams.append("p", path));
738+
739+
return url;
740+
}
741+
726742
async function fetchAndApplyManifestPatches(
727743
paths: string[],
728744
decode: DecodeServerResponseFunction,
729745
fetchImplementation: (request: Request) => Promise<Response>,
730746
signal?: AbortSignal
731747
) {
732-
let basename = (window.__router.basename ?? "").replace(/^\/|\/$/g, "");
733-
let url = new URL(`${basename}/.manifest`, window.location.origin);
734-
paths.sort().forEach((path) => url.searchParams.append("p", path));
748+
let url = getManifestUrl(paths);
749+
if (url == null) {
750+
return;
751+
}
735752

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

0 commit comments

Comments
 (0)