fix(react-router): sync child props through Routes wrapper on re-render#31226
Open
ShaneK wants to merge 1 commit into
Open
fix(react-router): sync child props through Routes wrapper on re-render#31226ShaneK wants to merge 1 commit into
ShaneK wants to merge 1 commit into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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.
Issue number: resolves #31157 (the RR6 version of this issue, anyway)
What is the current behavior?
When a parent re-renders with new props for a child rendered inside an
IonRouterOutlet, the child's props go stale.ReactRouterViewStackre-syncs the storedviewItem.reactElementby iteratingionRouterOutlet.props.childrendirectly withReact.Children.forEachand matching each child'spathagainst the stored view items.When the routes are wrapped in a
<Routes>element (the RR6 equivalent of the v5<Switch>), that wrapper has nopathof its own, so nothing matches and the child element is never refreshed. The storedreactElementkeeps its original props, so state passed down from the parent never reaches the child.What is the new behavior?
The sync now runs the outlet's children through
extractRouteChildren, which unwraps the<Routes>wrapper and returns the actual<Route>elements with their paths. Those match the stored view items, so thereactElementis refreshed on each re-render. This is the same unwrapping already used on the render path elsewhere in the file, so direct-child routes and<Routes>-wrapped routes now behave the same. Prop changes from a parent re-render reach the child in both shapes.Does this introduce a breaking change?
Other information
Preview (React Router test app):