Skip to content

bug: ionic vue transition gets incorrect view item on dynamic url #22654

Closed

Description

@torgnywalin

Bug Report

Ionic version:
[ ] 4.x
[x] 5.x

Current behavior:
When navigating between pages navigation breaks and page is not becoming visible.
The page we are navigating from is still in DOM as well as the new (even though router-direction is root), and have the same z-index.

We have experienced the issue when navigating with the help of sideMenu, but not sure if its only related to this.
We have also only experienced it while navigating from a dynamic url to a static url.

Link to video showing error occurring:
https://vimeo.com/488869055/6e4ba7b774

We are getting the following error:

Uncaught (in promise) TypeError: Cannot read property 'classList' of undefined
    at handlePageTransition (index.js?8a30:930)

it's related to this line of code:

leavingEl.classList.add('ion-page-hidden');

It looks like some sort of reference to the DOM object is lost.
leavingViewItem.ionPageElement seems to be undefined when the error occurrs.

Expected behavior:
Navigation not to break, and the page we are navigating from to be removed from DOM.

Steps to reproduce:
I have created a repo with minimal code to reproduce the error:
https://github.com/torgnywalin/ionic-vue-debug-routing

This repo is based on the starter template sidemenu and are created with this command:

ionic start ionic-vue-debug-routing sidemenu --type vue

All changes i have done is in this commit:
torgnywalin/ionic-vue-debug-routing@8683d13

Click randomly on the links in sidemenu, and go between the "folder" pages, and the test page.
After a while it should break when navigating to the test page. (See video link above)

Related code:
Full code:
https://github.com/torgnywalin/ionic-vue-debug-routing

Navigation in sideMenu:

<ion-menu-toggle auto-hide="false" v-for="(p, i) in appPages" :key="i">
  <ion-item @click="selectedIndex = i" router-direction="root" :router-link="p.url" lines="none" detail="false" class="hydrated" :class="{ selected: selectedIndex === i }">
    <ion-icon slot="start" :ios="p.iosIcon" :md="p.mdIcon"></ion-icon>
    <ion-label>{{ p.title }}</ion-label>
  </ion-item>
</ion-menu-toggle>
      
<ion-menu-toggle auto-hide="false">
  <ion-item  router-direction="root" :router-link="'/test'" lines="none" detail="false" class="hydrated">
    <ion-icon slot="start" name="home"></ion-icon>
    <ion-label>Test</ion-label>
  </ion-item>
</ion-menu-toggle>

Other information:
While troubleshooting i found some other issues that references the same console error:
#22286
#22166
Both are closed.

Ionic info:

Ionic:

   Ionic CLI       : 6.12.2 (/Users/torgnywalin/.nvm/versions/node/v14.7.0/lib/node_modules/@ionic/cli)
   Ionic Framework : @ionic/vue 5.5.1

Capacitor:

   Capacitor CLI   : 2.4.4
   @capacitor/core : 2.4.4

Utility:

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

System:

   NodeJS : v14.7.0 (/Users/torgnywalin/.nvm/versions/node/v14.7.0/bin/node)
   npm    : 6.14.7
   OS     : macOS Big Sur

Activity

  1. changed the title [-]bug: Serious navigation bug (ionic-vue)[/-] [+]bug: ionic vue transition gets incorrect view item on dynamic url[/+] on Dec 9, 2020
  2. added
    package: vue
    type: bug
    on Dec 9, 2020
  3. added this to the 5.5.3 milestone on Dec 9, 2020
  4. liamdebeasi commented on Dec 9, 2020

    @liamdebeasi
    Contributor

    Thanks for the issue. Can you try the following dev build and let me know if it resolves the issue?

    npm install @ionic/[email protected] @ionic/[email protected]
    
  5. torgnywalin commented on Dec 9, 2020

    @torgnywalin
    Author

    Thanks for the quick response. I've tested and was not able to reproduce within 5-10 minutes of testing.
    Before upgrading i was able to reproduce within 10-15 seconds, so seems like it's fixed.

  6. torgnywalin commented on Dec 10, 2020

    @torgnywalin
    Author

    @liamdebeasi I'm sorry to inform that we noticed another bug, that I think is related to this one.
    When we have navigated through some static and some dynamic urls, going back with IonBackButton is breaking.

    I have updated the example repo with code to reproduce:
    https://github.com/torgnywalin/ionic-vue-debug-routing

    Changes are in this commit:
    torgnywalin/ionic-vue-debug-routing@4da643a

    To reproduce
    All navigation is done with router.push(url)

    1. I start navigation from Home screen (static URL - /home)
    2. I navigate to dynamic URL /folder/start
    3. I navigate to dynamic URL /folder/page1
    4. I navigate to dynamic URL /folder/page2
    5. I navigate to static URL /test
    6. I use IonBackButton to go back through the stack

    When returning from the dynamic URLs to home, we end up with almost same problem as in original issue.
    Both pages are stuck in DOM and have same z-index.

    We have only seen it if we go from static URL -> dynamicURL -> dynamicURL -> staticURL.
    So a static before and after some dynamic pages.

    Video of it happening:
    https://vimeo.com/489404765/b21f0b5510

  7. torgnywalin commented on Dec 10, 2020

    @torgnywalin
    Author

    I didn't see #22658, they might be related.

  8. liamdebeasi commented on Dec 10, 2020

    @liamdebeasi
    Contributor

    Yeah looks like the same issue. I am close to finishing a fix for #22658, so I will post a new dev build here when that is ready.

  9. liamdebeasi commented on Dec 10, 2020

    @liamdebeasi
    Contributor

    Can you try the following dev build and let me know if it resolves the issue?

    npm install @ionic/[email protected] @ionic/[email protected]
    
  10. torgnywalin commented on Dec 10, 2020

    @torgnywalin
    Author

    Thanks for super quick response.

    Did a quick test on example repo and seems to work.
    Will try the new packages on more complex project tomorrow and test there as well.

    I have a question regarding the vue-router implementation in Ionic:
    I have asked on the forum, and understand if you dont have time to answer it, but thought i give it a try

    Is there a way to get the animation between pages when navigating between dynamic urls using the same component?

    For example:

    1. Start at /home
    2. Navigate to /folder/page1 (we get transition)
    3. Navigate to /folder/page2(we dont get transition)
    4. Navigate to /test (we get transition)

    Is there a way to get transitions on the navigation between page1 and page2?
    Or is there a plan to implement this?

    I have used Ionic-Angular for a long time, and there i think it was solved with IonicRouteStrategy.

  11. liamdebeasi commented on Dec 10, 2020

    @liamdebeasi
    Contributor

    Good question. Ionic Vue (correctly) reuses the view when going from /folder/page1 to /folder/page2, but since the component is already "visible" there is no transition. I think we need to do something similar to what Ionic React does. When transitioning to another version of the same component, Ionic React clones the element temporarily so there is a transition:

    // If a page is transitioning to another version of itself
    // we clone it so we can have an animation to show
    const match = matchComponent(leavingViewItem.reactElement, routeInfo.pathname, true);
    if (match) {
    const newLeavingElement = clonePageElement(leavingViewItem.ionPageElement.outerHTML);
    if (newLeavingElement) {
    this.routerOutletElement.appendChild(newLeavingElement);
    await runCommit(enteringViewItem.ionPageElement, newLeavingElement);
    this.routerOutletElement.removeChild(newLeavingElement);

  12. torgnywalin commented on Dec 10, 2020

    @torgnywalin
    Author

    Yeah, sound like that could work for Vue as well.

    I think with the fixes you have done in the last days, and if/when we get a fix for this as well, that would make for a really good and consistent navigation experience.

    We make a lot of apps with menus in tree structure, so we often navigate from /menu/:id to /menu/:id.
    So this would make the user experience even better.

  13. torgnywalin commented on Dec 11, 2020

    @torgnywalin
    Author

    As expected it worked fine in our larger project as well. Not able to reproduce.

  14. jofleck commented on Dec 13, 2020

    @jofleck

    Same problem. With the dev build which was posted by @liamdebeasi the problem is not reproducible for me anymore. Wuhuuu 👍

  15. added a commit that references this issue on Dec 16, 2020
    e3a05bf
  16. liamdebeasi commented on Dec 16, 2020

    @liamdebeasi
    Contributor

    Thanks for the issue. This has been resolved via #22655, and a fix will be available in an upcoming release of Ionic Framework.

  17. ionitron-bot commented on Jan 15, 2021

    @ionitron-bot

    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.

  18. locked and limited conversation to collaborators on Jan 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    package: vuetype: bug

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions