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.

Ion-Router Not Firing Load/Update Events or Rerendering Stacked Component

See original GitHub issue

Ionic version:

[x] 4.x (4.3.1)

I’m submitting a …

[x] bug report [ ] feature request

Current behavior: When I browse to a page that has previously been loaded, the load/update events are not firing, nor is the component being re-rendered.

When I use an ion-button, the ion-router’s push method or even the back button a previously loaded component/page is loaded from the navigation stack by the looks of it but no events are fired and the page displays out of date data (so it’s not been re-rendered).

Expected behavior: All the usual events should be fired when a page is loaded or reloaded upon a URL change because data could have changed in the mean time.

I have checked the docs as well as open and closed issues on the repository. This is a Stencil PWA but relates to the ion-router. I think it’s to do with the ion-nav stack of pages because the previous page doesn’t seem to get Unloaded.

Steps to reproduce: Very basic steps. Create a new PWA using the npm stencil init command and select the PWA template which includes Ionic.

Add the following methods to both Home and Profile pages and check the console output on running the app (on the Profile page replace the word HOME with PROFILE).

componentWillLoad() {
  console.log('HOME: Component Will Load');
}
componentWillUpdate() {
  console.log('HOME: Component Will Update');
}
componentDidLoad() {
  console.log('HOME: Component Did Load');
}
componentDidUpdate() {
  console.log('HOME: Component Did Update');
}
componentDidUnload() {
  console.log('HOME: Component Did Unload');
}

If you wish you can add the following button to the Profile page too: <ion-button href="/" expand="block">Home page</ion-button>

Other information: There are other issues reported relating to Angular based routing as well. This may or may not be related if both forms share the same ion-nav component.

I think it’s related to the ion-nav component because the Unload event is not fired when going to the profile page but it is fired when moving to the Home page (using any type of routing change, Push method, Ion-Button or Ion-Back-Button)

I copied the button from the Home page to the Profile page and changed the href and description. It exhibited the issue. (No Unload on Home and no other events when going back to Home. The Profile page shows all events firing as expected.)

Ionic info: Going from Home to Profile, back to Home and then Profile a few times gives the following output in the console:

Start App >

HOME: Component Will Load
HOME: Component Did Load

Click Profile button >

PROFILE: Component Will Load
PROFILE: Component Did Load

Click Home button (or Back button) >

PROFILE: Component Did Unload

Click Profile button >

PROFILE: Component Will Load
PROFILE: Component Did Load

Click Home button (or Back button) >

PROFILE: Component Did Unload

So the Profile Unload is called upon navigation to Home, even when using the standard ion-button with a href of /. Which means that the Will-Load and Did-Load events fire on each visit to Profile. But the same does not happen for Home.

My actual app also exhibits this behaviour from multiple pages down the stack so it doesn’t seem to be related to just the / route.

I’ve updated to the latest versions of both Ionic and Stencil and it shows the same issue.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:6

github_iconTop GitHub Comments

5reactions
hhsm95commented, Nov 8, 2019

I have a similar issue with Ionic React, useEffect and Hooks. My app has a hook useState in the App Component (the root of all), in this component I have the Routes, and I use Route render to pass properties (the hook of my common state) and its shows fine in the children component called with the Route. But when I update the hook state with the passed hook, it update the original state in App Component (the root one) but It wont re-render the children component accesed by the Route. I already tested this in simple React with ReactRouterDom without Ionic and its works without any problem, so I think the problem is in IonReactRouter (generally the routing system that Ionic implements). Any help is apreciated, thanks.

1reaction
aa-telalicommented, May 30, 2019

Looks like the bot’s auto-ignoring this one 😦

I think this is definitely an Ionic Navigator issue instead of something wrong in Stencil. Surely this would affect Vue and React too?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Ion-Router Not Firing Load/Update Events or Rerendering ...
When I use an ion-button, the ion-router's push method or even the back button a previously loaded component/page is loaded from the navigation ......
Read more >
Ionic react component no rerendering upon (Hooks) state ...
I have a Main Component which defines couple of routes and IonTab, const MainMenu: React.FC = () => { return( <IonPage> <IonReactRouter> ...
Read more >
Re-rendering Components in ReactJS - GeeksforGeeks
A simple update of the state, from anywhere in the code, causes all the User Interface (UI) elements to be re-rendered automatically. However, ......
Read more >
Reconciliation - React
This article explains the choices we made in React's “diffing” algorithm so that component updates are predictable while being fast enough for high-performance ......
Read more >
How To Avoid Performance Pitfalls in React with memo ...
Either the component re-renders more than expected or the component has a data-heavy operation that can cause each render to be slow. Because...
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