Skip to content
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

Log route module errors prior to reloading the page #8932

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/log-module-error.md
@@ -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
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);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've never logged this error before since it's swallowed on the reload and (I think) it was much harder to run into this for import issues in dev when using esbuild. But using vite during dev, you don't find out about these module errors until runtime, so we can log them and they're available via Preserve log

I'm curious through if they could be surfaced through Vite's overlay? @pcattori @markdalgleish


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();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could also consider enhancing this behavior in the future too. Reloading the current page isn't necessarily what we want all the time. There's 2 usages of this method:

  • prefetching - in that case there's no real reason to hard reload since the user may not click on the link, so we could just let the prefetch no-op
  • navigating - ideally for the most seamless UX we'd hard-navigate to the next url instead of reloading the current URL in response to a clicked link. The issue here is that currently route.lazy (which calls this) isn't aware of the next location so we'd have to plumb that through in RR if we wanted to smooth out that flow.


return new Promise(() => {
// check out of this hook cause the DJs never gonna re[s]olve this
});
Expand Down