Skip to content

Commit 5cad5f8

Browse files
committed
Handle new client/old server
1 parent eb72a6f commit 5cad5f8

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

packages/react-router/lib/dom/ssr/fog-of-war.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,25 @@ export async function fetchAndApplyManifestPatches(
242242
try {
243243
let res = await fetch(url, { signal });
244244

245+
// To avoid issues during rolling deployments if we get back a 400 when
246+
// using `paths`, it's likely we hit an old server so retry the request
247+
// with the old `p` parameters
248+
if (res.status === 400) {
249+
let body = await res.text();
250+
if (body !== "Invalid Request") {
251+
throw new Error(`${res.status} ${res.statusText}`);
252+
}
253+
const retrySearchParams = new URLSearchParams();
254+
paths.sort().forEach((path) => retrySearchParams.append("p", path));
255+
retrySearchParams.set("version", manifest.version);
256+
let url = new URL(
257+
getManifestPath(manifestPath, basename),
258+
window.location.origin,
259+
);
260+
url.search = retrySearchParams.toString();
261+
res = await fetch(url, { signal });
262+
}
263+
245264
if (!res.ok) {
246265
throw new Error(`${res.status} ${res.statusText}`);
247266
} else if (

0 commit comments

Comments
 (0)