-
-
Notifications
You must be signed in to change notification settings - Fork 758
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
fix(react-router): improve error handling for module loading failures in lazyRouteComponent #3262
Merged
Conversation
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
View your CI Pipeline Execution ↗ for commit b6a0690.
☁️ Nx Cloud last updated this comment at |
More templates
@tanstack/arktype-adapter
@tanstack/create-router
@tanstack/create-start
@tanstack/directive-functions-plugin
@tanstack/eslint-plugin-router
@tanstack/history
@tanstack/react-cross-context
@tanstack/react-router
@tanstack/react-router-with-query
@tanstack/router-cli
@tanstack/router-core
@tanstack/router-devtools
@tanstack/router-generator
@tanstack/router-plugin
@tanstack/router-vite-plugin
@tanstack/server-functions-plugin
@tanstack/start
@tanstack/start-api-routes
@tanstack/start-client
@tanstack/start-config
@tanstack/start-plugin
@tanstack/start-router-manifest
@tanstack/start-server
@tanstack/start-server-functions-client
@tanstack/start-server-functions-fetcher
@tanstack/start-server-functions-handler
@tanstack/start-server-functions-server
@tanstack/start-server-functions-ssr
@tanstack/valibot-adapter
@tanstack/virtual-file-routes
@tanstack/zod-adapter
commit: |
tannerlinsley
added a commit
that referenced
this pull request
Jan 29, 2025
* fix: scroll-restoration (especially on hydration mismatch) * fix: more fixes * fix canGoBack * release: v1.97.25 * chore(root): upgrade `vitest` to `3.0.4` (#3257) * chore(root): upgrade `nx` to `20.4.0` (#3259) * fix(react-router): improve error handling for module loading failures in lazyRouteComponent (#3262) Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> * fix(start-server): remove debugging timeout (#3258) * fix(start-plugin): invoke server implementation of createIsomorphicFn during SSR (#3268) * feat(react-router): add `remountDeps` (#3269) * fix: RELEASE_ALL RELEASE_ALL * examples: remove dep (#3270) * release: v1.98.0 * checkpoint * fix tests * tests: fix * fix: back to old onRendered * fix: scroll-restoration (especially on hydration mismatch) * fix: more fixes * fix canGoBack * checkpoint * fix tests * tests: fix * fix: back to old onRendered * Move utils to core * fix: backwards compat ScrollRestoration * fix: better versioning * fix: reenable hash scrolling and window reset even without scroll restoration * test(e2e): renable tests for router * fix: backwards compat and docs --------- Co-authored-by: Tanner Linsley <[email protected]> Co-authored-by: Tanner Linsley <[email protected]> Co-authored-by: Sean Cassiere <[email protected]> Co-authored-by: Flo <[email protected]> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Daniel Grant <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Issues currently on main for
lazyRouteComponent
:The placeholder
ReactNode
used "while we wait for the page to reload" is not a valid react nodeBased on the comment messages around, and the git history, I'm assuming this is a typo brought from when error handling was done at the module loading level instead of in-render (see e5e80af). There are 2 options now:
return null
throw new Promise(() => {})
My vote would go towards the suspense one, because this is the least likely to flash content before the page reloads, and instead will continue the loading state already triggered by the navigation that brought us here.
If the component re-renders "while we wait for the page to reload", the
sessionStorage
condition won't be met a 2nd time and we throw the error.If
Lazy
re-renders, this condition won't be met the 2nd time around because we wrote tosessionStorage
. This means that upon re-render, we're throwing the initialerror
that we were currently handling.I'm not 100% sure a re-render is possible here, so maybe there's not need to worry
The technique used to differentiate a "module loading error" vs any other kind of error is only compatible with chromium browsers. Each browser throws a different error, because the specs say "rejects with an implementation-defined error":
So the
isModuleNotFoundError
implementation needs to be updated to handle those 3 types of errors.The key used for
sessionStorage
is not always unique to a specific file. As per the previous point, Safari does not include the imported module name anywhere (that I could see) in theError
object. So in the case of Safari, a user session can span across 1 deployment, but not 2 as the 2nd time we encounter a module loading issue we won't reload the page.I do not have a good solution for this:
lazyRouteComponent
function would have to take in the module name as a 4th param, but then we have to play with bundler stuff to obtain the module name and that's complicated.Alternatively, maybe there's something to be done with aAfter inspection,useId
inside theLazy
component, since this is supposed to be stable across reloads IIRCuseId
is not stable in this context, so it's not a possible solution to this problem