Skip to content

Commit

Permalink
Log route module errors prior to reloading the page (#8932)
Browse files Browse the repository at this point in the history
  • Loading branch information
brophdawg11 committed Jul 12, 2024
1 parent cb4dda0 commit 5bccd1e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/log-module-error.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@remix-run/react": patch
---

Log any errors encountered loading a route module prior to reloading the page
22 changes: 17 additions & 5 deletions packages/remix-react/routeModules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,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.isSpaMode &&
// @ts-expect-error
Expand All @@ -203,10 +214,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

0 comments on commit 5bccd1e

Please sign in to comment.