Skip to content

Commit

Permalink
Merge pull request #11810 from remix-run/brophdawg11/remix-2-10-3
Browse files Browse the repository at this point in the history
Bring over changes from Remix 2.10.3
  • Loading branch information
brophdawg11 authored Jul 16, 2024
2 parents e9923b9 + 56e1929 commit 9344272
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 13 deletions.
4 changes: 1 addition & 3 deletions packages/react-router-architect/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,7 @@ export function createReactRouterHeaders(
}

if (requestCookies) {
for (let cookie of requestCookies) {
headers.append("Cookie", cookie);
}
headers.append("Cookie", requestCookies.join("; "));
}

return headers;
Expand Down
5 changes: 3 additions & 2 deletions packages/react-router-cloudflare/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ export function createRequestHandler<Env = any>({
...cloudflare,
cf: cloudflare.request.cf!,
ctx: {
waitUntil: cloudflare.waitUntil,
passThroughOnException: cloudflare.passThroughOnException,
waitUntil: cloudflare.waitUntil.bind(cloudflare),
passThroughOnException:
cloudflare.passThroughOnException.bind(cloudflare),
},
caches,
},
Expand Down
22 changes: 17 additions & 5 deletions packages/react-router/lib/dom/ssr/routeModules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,21 @@ export async function loadRouteModule(
routeModulesCache[route.id] = routeModule;
return routeModule;
} catch (error: unknown) {
// User got caught in the middle of a deploy and the CDN no longer has the
// asset we're trying to import! Reload from the server and the user
// (should) get the new manifest--unless the developer purged the static
// assets, the manifest path, but not the documents 😬
// If we can't load the route it's likely one of 2 things:
// - User got caught in the middle of a deploy and the CDN no longer has the
// asset we're trying to import! Reload from the server and the user
// (should) get the new manifest--unless the developer purged the static
// assets, the manifest path, but not the documents 😬
// - Or, the asset trying to be imported has an error (usually in vite dev
// mode), so the best we can do here is log the error for visibility
// (via `Preserve log`) and reload

// Log the error so it can be accessed via the `Preserve Log` setting
console.error(
`Error loading route module \`${route.module}\`, reloading page...`
);
console.error(error);

if (
window.__remixContext &&
window.__remixContext.isSpaMode &&
Expand All @@ -218,10 +229,11 @@ export async function loadRouteModule(
// on dev-time errors since it's a vite compilation error and a reload is
// just going to fail with the same issue. Let the UI bubble to the error
// boundary and let them see the error in the overlay or the dev server log
console.error(`Error loading route module \`${route.module}\`:`, error);
throw error;
}

window.location.reload();

return new Promise(() => {
// check out of this hook cause the DJs never gonna re[s]olve this
});
Expand Down
7 changes: 4 additions & 3 deletions packages/react-router/lib/dom/ssr/single-fetch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,13 @@ function singleFetchLoaderStrategy(
m.resolve(async (handler): Promise<HandlerResult> => {
let result: unknown;
let url = stripIndexParam(singleFetchUrl(request.url));
let init = await createRequestInit(request);

// When a route has a client loader, it calls it's singular server loader
if (manifest.routes[m.route.id].hasClientLoader) {
result = await handler(async () => {
url.searchParams.set("_routes", m.route.id);
let { data } = await fetchAndDecode(url);
let { data } = await fetchAndDecode(url, init);
return unwrapSingleFetchResults(
data as SingleFetchResults,
m.route.id
Expand All @@ -204,7 +205,7 @@ function singleFetchLoaderStrategy(
matches.filter((m) => m.shouldLoad).map((m) => m.route),
url
);
singleFetchPromise = fetchAndDecode(url).then(
singleFetchPromise = fetchAndDecode(url, init).then(
({ data }) => data as SingleFetchResults
);
}
Expand Down Expand Up @@ -304,7 +305,7 @@ export function singleFetchUrl(reqUrl: URL | string) {
return url;
}

async function fetchAndDecode(url: URL, init?: RequestInit) {
async function fetchAndDecode(url: URL, init: RequestInit) {
let res = await fetch(url, init);
invariant(res.body, "No response body to decode");
try {
Expand Down

0 comments on commit 9344272

Please sign in to comment.