Skip to content

bug: Tabs + React Router + Ionic lifecycle hooks combo causes inconsistent data #23388

Closed
@avalanche1

Description

@avalanche1

Bug Report

Ionic version:

[x] 5.6.8

Current behavior:

There is a problem with useIonViewWillEnter and useParams of react-router.
If I try to access the params object of useParams inside the useIonViewWillEnter callback WHILE I previously navigated using IonTabs - the params object will contain obsolete\erroneous data.
See the Steps to reproduce: section for a more understandable explanation.

Expected behavior:

Steps to reproduce:

In the linked repo app do the following:

  • In Customer List view click the 1st customer; it shows the data with id1.
  • Now go back with browser Back button and click another customer - the view will display other customer's data correctly. That is how it's supposed to work.
  • Now refresh the page and repeat the process, BUT instead of going Back on the 1st customer - click Customers IonTabButton below.
  • Go to another customer. You will see that in spite of the url having the correct id, the data displayed is still for the 1st customer. Whereas, the id that is used in the Header is correct - because it is set directly from useParams, avoiding useIonViewWillEnter.
    Related code:
    https://github.com/avalanche1/ionic-router-problem-app

The module in question is src\pages\CustomerForm.tsx.
It has console.log's in it, that show that useIonViewWillEnter uses incorrect customer id.

Ionic info:

Ionic:

   Ionic CLI       : 6.16.1 (/usr/local/lib/node_modules/@ionic/cli)
   Ionic Framework : @ionic/react 5.6.8

Capacitor:

   Capacitor CLI      : not installed
   @capacitor/android : not installed
   @capacitor/core    : not installed
   @capacitor/ios     : not installed

Utility:

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

System:

   NodeJS : v16.1.0 (/usr/local/bin/node)
   npm    : 7.11.2
   OS     : macOS Mojave

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions