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
brophdawg11
wants to merge
1
commit into
dev
Choose a base branch
from
brophdawg11/log-module-error
base: dev
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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:
|
||
|
||
return new Promise(() => { | ||
// check out of this hook cause the DJs never gonna re[s]olve this | ||
}); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 viaPreserve log
I'm curious through if they could be surfaced through Vite's overlay? @pcattori @markdalgleish