Skip to content

fix(react): router creates new view instances of parameterized routes - #28616

Merged
sean-perkins merged 5 commits into
mainfrom
sp/FW-3083
Dec 1, 2023
Merged

fix(react): router creates new view instances of parameterized routes#28616
sean-perkins merged 5 commits into
mainfrom
sp/FW-3083

Conversation

@sean-perkins

@sean-perkins sean-perkins commented Nov 30, 2023

Copy link
Copy Markdown
Contributor

Issue number: Resolves #26524


Definitions

Parameterized routes: A route that includes one or more variables in the path segments, such as /form/:index.

What is the current behavior?

When an application routes from a parameterized route, to an intermediary route, to the same parameterized route, but with a different value/url, Ionic's routing logic is incorrectly reusing the view item from the first instance of the parameterized route instead of calculating that the matched path is different. This results in the wrong view item being recycled and rendered.

Another way of representing it:

  • User navigates to /form/0 which resolves FormPage
  • User enters 0 into the form and submits the form
  • User navigates to /link, which resolves LinkPage
  • User navigates to /form/1, which resolves FormPage
    • However, instead of creating a new instance of FormPage it is reusing the instance of FormPage from /form/0 which includes the form having 0 in the input.
    • The user now sees a "new view", but with cached data in the form.

This is not expected or desired.

What is the new behavior?

  • Ionic's routing logic will validate if the entering view item matches the match route data before reusing it. This results in new instances of the view item being constructed when using parameterized routes.
Kapture.2023-11-30.at.15.05.04.mp4

Does this introduce a breaking change?

  • Yes
  • No

Other information

Dev-build: 7.5.8-dev.11701383555.17254408

@github-actions github-actions Bot added the package: react @ionic/react package label Nov 30, 2023
@sean-perkins
sean-perkins marked this pull request as ready for review November 30, 2023 23:22

@aeharding aeharding left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeeted this into production for Voyager last night at it's working perfectly :)

@averyrousseau averyrousseau left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

@sean-perkins
sean-perkins added this pull request to the merge queue Dec 1, 2023
Merged via the queue into main with commit 1705d06 Dec 1, 2023
@sean-perkins
sean-perkins deleted the sp/FW-3083 branch December 1, 2023 22:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

package: react @ionic/react package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: Ionic React Router is not creating new instances of views with parameterized routes

3 participants