Repository navigation
fix(react-router): improve error handling for module loading failures in lazyRouteComponent - #3262
Merged
Merged
Conversation
Contributor
|
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 <tannerlinsley@gmail.com> Co-authored-by: Tanner Linsley <tannerlinsley@users.noreply.github.com> Co-authored-by: Sean Cassiere <33615041+SeanCassiere@users.noreply.github.com> Co-authored-by: Flo <fpellet@ensc.fr> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Daniel Grant <1670902+djgrant@users.noreply.github.com>
3 tasks done
This file contains hidden or 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
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
ReactNodeused "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 nullthrow 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
sessionStoragecondition won't be met a 2nd time and we throw the error.If
Lazyre-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 initialerrorthat 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
isModuleNotFoundErrorimplementation needs to be updated to handle those 3 types of errors.The key used for
sessionStorageis 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 theErrorobject. 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:
lazyRouteComponentfunction 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,useIdinside theLazycomponent, since this is supposed to be stable across reloads IIRCuseIdis not stable in this context, so it's not a possible solution to this problem