question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

bug: IonReactRouter re-renders each page multiple times when changing routes

See original GitHub issue

Bug Report

Ionic version:

[ ] 4.x [x] 5.x

Current behavior:

When navigating between routes, the old route and the new route get re-rendered multiple times. This is a major performance issue with large pages that contain many components.

Expected behavior:

The page being replaced should not re-render, and the new page should only render once.

Steps to reproduce:

  1. Create a new app using the ionic starter: ionic start myApp2 tabs --type react
  2. Add a console.log statement to each tab
  3. Open the inspector and click between the tabs. Observe that each tab gets re-rendered multiple times.

Related code:

Sample application on Github: https://github.com/lindadick/ionic-routing-issue-example

Other information:

Here is a screenshot of what appears in the log after loading the app and clicking on Tab 2 once: image

I confirmed that this same issue occurs if you navigate using IonRouterLink instead of tabs. The tabs were included in the example to make it easier to illustrate the problem.

Ionic info:

➜  myApp git:(master) ✗ ionic info

Ionic:

   Ionic CLI       : 6.10.1 (/usr/local/lib/node_modules/@ionic/cli)
   Ionic Framework : @ionic/react 5.2.2

Capacitor:

   Capacitor CLI   : 2.2.0
   @capacitor/core : 2.2.0

Utility:

   cordova-res : not installed
   native-run  : not installed

System:

   NodeJS : v12.18.1 (/usr/bin/node)
   npm    : 6.14.5
   OS     : Linux 5.3

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
puku0xcommented, Jul 29, 2020

@elylucas Oh no, this issue should keep being opened because the new IonReactRouter has the same bug.

1reaction
puku0xcommented, Jul 27, 2020

I’m facing the similar problem on a sample which has list and detail page that the previous page is rendered after the page transition. https://codesandbox.io/s/ionic-react-router-v530-render-should-not-be-called-twice-4hlu2?file=/src/pages/UserListPage.tsx

This is the biggest problem when implementing searching in the list page because it calls render function in the detail page and occurs unnecessary communication.

Read more comments on GitHub >

github_iconTop Results From Across the Web

bug: IonReactRouter re-renders each page multiple times ...
Current behavior: When navigating between routes, the old route and the new route get re-rendered multiple times. This is a major performance ...
Read more >
Ionic-react - so many render issues related to routing
I am trying to nest routes at different levels of my React component tree ... it causes the transition animation to trigger multiple...
Read more >
React Router V6 Re-renders on Route Change - Stack Overflow
When I navigate back and forth between routes, React Router re-renders memoized routes causing useEffect(() => []) to re-run and data to ...
Read more >
React Component Is Rendered 5 Times, Ionic 4 - ADocLib
Ask questionsbug: IonReactRouter rerenders each page multiple times when changing routes. <!. Observe that each tab gets rerendered multiple times. When ...
Read more >
How React Hooks can replace React Router - LogRocket Blog
Looking for an alternative form of routing in your React projects? Read more to find out how React Hooks can replace React Router....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found