-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
fix(router-core): Prevents the app from crashing when a primitive value is thrown in beforeLoad #4724
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
base: main
Are you sure you want to change the base?
fix(router-core): Prevents the app from crashing when a primitive value is thrown in beforeLoad #4724
Changes from all commits
66eb642
e71f4fe
890c7a9
cb1a58d
b63d947
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -679,6 +679,8 @@ export type AnyRouterWithContext<TContext> = RouterCore< | |
|
||
export type AnyRouter = RouterCore<any, any, any, any, any> | ||
|
||
export type RouterCode = 'BEFORE_LOAD' | 'PARSE_PARAMS' | 'VALIDATE_SEARCH' | ||
|
||
export interface ViewTransitionOptions { | ||
types: | ||
| Array<string> | ||
|
@@ -2106,7 +2108,11 @@ export class RouterCore< | |
triggerOnReady() | ||
} | ||
|
||
const handleRedirectAndNotFound = (match: AnyRouteMatch, err: any) => { | ||
const handleRedirectAndNotFound = ( | ||
match: AnyRouteMatch, | ||
err: any, | ||
routerCode?: RouterCode, | ||
) => { | ||
if (isRedirect(err) || isNotFound(err)) { | ||
if (isRedirect(err)) { | ||
if (err.redirectHandled) { | ||
|
@@ -2145,7 +2151,7 @@ export class RouterCore< | |
err = this.resolveRedirect(err) | ||
throw err | ||
} else if (isNotFound(err)) { | ||
this._handleNotFound(matches, err, { | ||
this._handleNotFound(matches, err, routerCode, { | ||
updateMatch, | ||
}) | ||
throw err | ||
|
@@ -2175,7 +2181,7 @@ export class RouterCore< | |
const handleSerialError = ( | ||
index: number, | ||
err: any, | ||
routerCode: string, | ||
routerCode: RouterCode, | ||
) => { | ||
const { id: matchId, routeId } = matches[index]! | ||
const route = this.looseRoutesById[routeId]! | ||
|
@@ -2187,15 +2193,22 @@ export class RouterCore< | |
throw err | ||
} | ||
|
||
err.routerCode = routerCode | ||
firstBadMatchIndex = firstBadMatchIndex ?? index | ||
handleRedirectAndNotFound(this.getMatch(matchId)!, err) | ||
handleRedirectAndNotFound( | ||
this.getMatch(matchId)!, | ||
err, | ||
routerCode, | ||
Comment on lines
+2197
to
+2200
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. Passes the |
||
) | ||
|
||
try { | ||
route.options.onError?.(err) | ||
route.options.onError?.(err, routerCode) | ||
Comment on lines
-2195
to
+2204
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. Applies minimal changes to preserve compatibility for users accessing |
||
} catch (errorHandlerErr) { | ||
err = errorHandlerErr | ||
handleRedirectAndNotFound(this.getMatch(matchId)!, err) | ||
handleRedirectAndNotFound( | ||
this.getMatch(matchId)!, | ||
err, | ||
routerCode, | ||
) | ||
} | ||
|
||
updateMatch(matchId, (prev) => { | ||
|
@@ -3019,6 +3032,7 @@ export class RouterCore< | |
_handleNotFound = ( | ||
matches: Array<AnyRouteMatch>, | ||
err: NotFoundError, | ||
routerCode?: string, | ||
{ | ||
updateMatch = this.updateMatch, | ||
}: { | ||
|
@@ -3069,10 +3083,9 @@ export class RouterCore< | |
error: err, | ||
isFetching: false, | ||
})) | ||
|
||
if ((err as any).routerCode === 'BEFORE_LOAD' && routeCursor.parentRoute) { | ||
if (routerCode === 'BEFORE_LOAD' && routeCursor.parentRoute) { | ||
err.routeId = routeCursor.parentRoute.id | ||
this._handleNotFound(matches, err, { | ||
this._handleNotFound(matches, err, routerCode, { | ||
Comment on lines
-3075
to
+3088
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. Passes |
||
updateMatch, | ||
}) | ||
} | ||
|
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.
The app crashes at this point when
err
is a primitive type.