-
-
Notifications
You must be signed in to change notification settings - Fork 10.5k
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 descendant Routes rendering alongside RouterProvider errors #10374
Merged
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
fc705d3
Fix descendant Routes rendering alongside RouterProvider errors
brophdawg11 f1d1e93
Remove it.only
brophdawg11 90a1851
Remove fork from Routes in favor of new DataRoutes component
brophdawg11 146237a
Revert whitespace snapshot changes
brophdawg11 8602a25
bump bundle
brophdawg11 69e1f2d
Merge branch 'dev' into brophdawg11/routes-with-data-errors
brophdawg11 11a129a
Merge branch 'dev' into brophdawg11/routes-with-data-errors
brophdawg11 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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 @@ | ||
--- | ||
"react-router": patch | ||
--- | ||
|
||
Fix bug preventing rendering of descendant `<Routes>` when `RouterProvider` errors existed |
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
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 |
---|---|---|
|
@@ -319,6 +319,7 @@ export function useRoutes( | |
); | ||
|
||
let { navigator } = React.useContext(NavigationContext); | ||
let dataRouterContext = React.useContext(DataRouterContext); | ||
let dataRouterStateContext = React.useContext(DataRouterStateContext); | ||
let { matches: parentMatches } = React.useContext(RouteContext); | ||
let routeMatch = parentMatches[parentMatches.length - 1]; | ||
|
@@ -432,7 +433,10 @@ export function useRoutes( | |
}) | ||
), | ||
parentMatches, | ||
dataRouterStateContext || undefined | ||
// Only pass along the dataRouterStateContext when we're rendering from the | ||
// RouterProvider layer. If routes is different then we're rendering from | ||
// a descendant <Routes> tree | ||
dataRouterContext?.router.routes === routes ? dataRouterStateContext : null | ||
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. This is the root of the bug - export function useRoutes(
routes: RouteObject[],
locationArg?: Partial<Location> | string,
isDataRouterRender?: boolean, // New arg passed true from <DataRoutes>
) |
||
); | ||
|
||
// When a user passes in a `locationArg`, the associated routes need to | ||
|
@@ -613,7 +617,7 @@ function RenderedRoute({ routeContext, match, children }: RenderedRouteProps) { | |
export function _renderMatches( | ||
matches: RouteMatch[] | null, | ||
parentMatches: RouteMatch[] = [], | ||
dataRouterState?: RemixRouter["state"] | ||
dataRouterState: RemixRouter["state"] | null = null | ||
): React.ReactElement | null { | ||
if (matches == null) { | ||
if (dataRouterState?.errors) { | ||
|
@@ -635,7 +639,9 @@ export function _renderMatches( | |
); | ||
invariant( | ||
errorIndex >= 0, | ||
`Could not find a matching route for the current errors: ${errors}` | ||
`Could not find a matching route for errors on route IDs: ${Object.keys( | ||
errors | ||
).join(",")}` | ||
); | ||
renderedMatches = renderedMatches.slice( | ||
0, | ||
|
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.
This is a bit of an unusual use-case. Normally the presence of an error would mean we don't reach descendant
<Routes>
down inside childrenComponent
's. But if the<Routes>
is next to the<Outlet />
then both can render at the same time.