Skip to content
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

bug: Ionic Routing on currently active IonPage triggers transition and re-rendering, although it is rendered already #22426

Closed
phal0r opened this issue Nov 3, 2020 · 8 comments
Labels
package: react @ionic/react package triage

Comments

@phal0r
Copy link

phal0r commented Nov 3, 2020

Bug Report

Ionic version:
[ ] 4.x
[x] 5.x (particulary Ionic React 5.3.4)

Current behavior:
Given you have a Route element with an optional parameter, i.e.

<Route path="/locations/:locationId?" component={Map} />

Then using user events and history.replace() (from react-router package) to toggle between the routes /locations and locations/123. This is really slow (takes more than 2 seconds) and the chrome profiler indicates, that it always rerenders the component, which is not the expected behaviour.

Expected behavior:
Using history.replace() to toggle between routes of the same Route element and thus the same IonPage should not rerender the whole IonPage. It should go through the normal React lifecycle and pass down the new props (which in turn invoke sideeffects and other hooks to update the ui).

Steps to reproduce:
Set up an Ionic React project with a Route, which has an optional parameter. Add 2 buttons, which toggle the active route via history.replace() from react-router.

Performance Diagram
image

Other information:

Ionic info:

$ ionic info

Ionic:

   Ionic CLI       : 6.10.1 (*********\nvm\v12.16.0\node_modules\@ionic\cli)
   Ionic Framework : @ionic/react 5.3.4

Capacitor:

   Capacitor CLI   : 2.2.1
   @capacitor/core : 2.4.2

Utility:

   cordova-res : 0.15.1
   native-run  : 1.0.0

System:

   NodeJS : v12.16.0 (C:\Program Files\nodejs\node.exe)
   npm    : 6.13.4
   OS     : Windows 10

@ionitron-bot ionitron-bot bot added the triage label Nov 3, 2020
@liamdebeasi
Copy link
Contributor

Thanks for the issue. Can you please provide a full application we can use to reproduce the issue?

@liamdebeasi liamdebeasi added the needs: reply the issue needs a response from the user label Nov 3, 2020
@ionitron-bot ionitron-bot bot removed the triage label Nov 3, 2020
@phal0r
Copy link
Author

phal0r commented Nov 5, 2020

@liamdebeasi Thanks for your reply. Yes, I will prepare a full application.

@ionitron-bot ionitron-bot bot added triage and removed needs: reply the issue needs a response from the user labels Nov 5, 2020
@liamdebeasi liamdebeasi added the needs: reply the issue needs a response from the user label Nov 5, 2020
@ionitron-bot ionitron-bot bot removed the triage label Nov 5, 2020
@elylucas elylucas added the package: react @ionic/react package label Nov 10, 2020
@BerkeAras
Copy link

@phal0r I cannot reproduce this issue. The Routing of Ionic React is in my case very very fast (faster then ionic core routing).

@ionitron-bot ionitron-bot bot added triage and removed needs: reply the issue needs a response from the user labels Nov 19, 2020
@phal0r
Copy link
Author

phal0r commented Nov 20, 2020

@BerkeAras
Thanks for your answer and your effort. I think I need to rephrase my actual problem and give some more context:

In contrast to plain react-router, ionic router does much more work behind the scenes to enable page transitions, i.e. cloning elements, starting animations and so on. This is fine for most use cases, but for my case it is not suitable (and might be somewhat special?).

Given I have rendered an IonPage with a map and some markers on this map. Clicking a marker opens an overlay on the same component. So far this is easy to acomplish, but I would like to make the overlay deeplinkable, which means a click on a marker would not change some local state, but trigger a route change with an associated ID, that should be passed as a route param.
Now I don't want to rerender the IonPage, but just take advantage of the routing change and open the overlay in the same IonPage instance. For the IonPage this would mean, that only the routeParams would change and everything would work smoothly without having to wait for 2 seconds (in my case).

Is there a way to control this in such a detail? We use such a mechanism for routing, but only changing the optional state object. This does not trigger a rerender, but just passes the new params to the existing IonPage instance, but obviously the optional routing state can not be passed to another a browser by copying the link.

Does this clarify my problem? Maybe I should change the title of this issue to be more precise.

@phal0r phal0r changed the title bug: Ionic Routing slow bug: Ionic Routing on currently active IonPage triggers transition and re-rendering, although it is rendered already Nov 20, 2020
@liamdebeasi
Copy link
Contributor

Without a code reproduction it is hard to say why this may be happening. Can you create one and post a link to it here?

@liamdebeasi liamdebeasi added the needs: reply the issue needs a response from the user label Nov 20, 2020
@ionitron-bot ionitron-bot bot removed the triage label Nov 20, 2020
@phal0r
Copy link
Author

phal0r commented Nov 22, 2020

@liamdebeasi
I created a test repo here: https://github.com/phal0r/ionic-routing-test

It illustrates the difference while routing via route state and route params.

@ionitron-bot ionitron-bot bot added triage and removed needs: reply the issue needs a response from the user labels Nov 22, 2020
@averyjohnston
Copy link
Contributor

Thanks for the report. As it turns out, this issue has some overlap with #24107, and the PR fixing that (#24672) will cover this as well. As such, I'm going to go ahead and close this out. The fix will be available in a future release of Ionic 6 👍

@ionitron-bot
Copy link

ionitron-bot bot commented Mar 2, 2022

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.

@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Mar 2, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
package: react @ionic/react package triage
Projects
None yet
Development

No branches or pull requests

5 participants