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: vue modal refs opening 2 modals in stack after navigation

See original GitHub issue

Prerequisites

Ionic Framework Version

  • v4.x
  • v5.x
  • v6.x
  • Nightly

Current Behavior

Menu component on PageOne: Open Menu, Select “Connor Smith” item, then it dismisses modal and routed to Page2.

Menu component on PageTwo: I select the ion-back-button, then open Menu again, then I see the 2nd modal that is blank in the stack on top of the original one.

I do this all the time in Angular, unsure why it is behaving odd with a blank 2nd modal in Vue. I also did notice that upon inspecting the element, it is instantiation the 2nd modal in DOM with a higher index that the original one that was already dismissed.

Expected Behavior

I except to be able to open modal, then dismiss it and navigate to another page, then open it again, it is in a component so it should work just fine this way.

Steps to Reproduce

Menu component on PageOne:

<template>
  <ion-page>
      <ion-header :translucent="true">
      <ion-toolbar>
          <MenuModal/>
          <ion-title>
            PageOne
          </ion-title>
      </ion-toolbar>
      </ion-header>
      <ion-content :fullscreen="true">
      <ion-header collapse="condense">
          <ion-toolbar>
          <ion-title size="large">PageOne</ion-title>
          </ion-toolbar>
      </ion-header>
      </ion-content>
  </ion-page>
  </template>
      
  <script lang="ts">
      import MenuModal from '../components/MenuModal.vue';
      import { defineComponent } from 'vue';
      import {
          IonPage,
          IonHeader,
          IonToolbar,
          IonTitle,
          IonContent,
      } from '@ionic/vue';
  export default defineComponent({
      name: 'PageOne',
      components: {
          IonPage,
          IonHeader,
          IonToolbar,
          IonTitle,
          IonContent,
          MenuModal,
      },
  });
  </script>
  
  <script lang="ts">
  import { menu } from 'ionicons/icons';
  import {
    IonButtons,
    IonMenuButton,
    IonModal,
    IonContent,
    IonLabel,
    IonItem,
    IonList,
    IonBackButton,
   } from '@ionic/vue';
  import { defineComponent } from 'vue';
import { useRouter } from 'vue-router';
import router from '@/router';
  
  export default defineComponent({
    name: 'MainMenu',
    components: {
        IonButtons,
        IonMenuButton,
        IonModal,
        IonContent,
        IonLabel,
        IonItem,
        IonList,
        IonBackButton,
  },
  methods: {
      async dismiss() {
        await (this.$refs as any).menuModal.$el.dismiss().then(() => {
          router.push('/page2');
        });
      },
    },
  setup() {
    const router = useRouter();
      return { router, menu, };
    },
  });
  </script>

Menu component on PageTwo:

<template>
    <ion-page>
        <ion-header :translucent="true">
        <ion-toolbar>
            <MenuModal/>
            <ion-title>
                PageTwo
            </ion-title>
        </ion-toolbar>
        </ion-header>
        <ion-content :fullscreen="true">
        <ion-header collapse="condense">
            <ion-toolbar>
            <ion-title size="large">PageTwo</ion-title>
            </ion-toolbar>
        </ion-header>
        </ion-content>
    </ion-page>
    </template>
        
    <script lang="ts">
        import MenuModal from '../components/MenuModal.vue';
        import { defineComponent } from 'vue';
        import {
            IonPage,
            IonHeader,
            IonToolbar,
            IonTitle,
            IonContent,
        } from '@ionic/vue';
    export default defineComponent({
        name: 'PageTwo',
        components: {
            IonPage,
            IonHeader,
            IonToolbar,
            IonTitle,
            IonContent,
            MenuModal,
        },
    });
    </script>

Menu to Modal Component:

<template>
    <ion-buttons slot="start">
      <ion-back-button></ion-back-button>
    </ion-buttons>
    <ion-buttons slot="end">
        <ion-menu-button id="open-menu" autoHide="false"></ion-menu-button>
    </ion-buttons>
    <ion-modal ref="menuModal" trigger="open-menu" :initial-breakpoint="0.90" :breakpoints="[0, 0.25, 0.90]">
      <ion-content class="ion-padding">
        <ion-list>
          <ion-item lines="none" @click="dismiss()">
            <ion-label>
              <h2>Connor Smith</h2>
            </ion-label>
          </ion-item>
        </ion-list>
      </ion-content>
    </ion-modal>
  
  </template>
  
  <script lang="ts">
  import { menu } from 'ionicons/icons';
  import {
    IonButtons,
    IonMenuButton,
    IonModal,
    IonContent,
    IonLabel,
    IonItem,
    IonList,
    IonBackButton,
   } from '@ionic/vue';
  import { defineComponent } from 'vue';
  import { useRouter } from 'vue-router';
  import router from '@/router';
  
  export default defineComponent({
    name: 'MenuModal',
    components: {
        IonButtons,
        IonMenuButton,
        IonModal,
        IonContent,
        IonLabel,
        IonItem,
        IonList,
        IonBackButton,
  },
  methods: {
      async dismiss() {
        await (this.$refs as any).menuModal.$el.dismiss().then(() => {
          router.push('/pagetwo');
        });
      },
    },
  setup() {
    const router = useRouter();
      return { router, menu, };
    },
  });
  </script>

Code Reproduction URL

No response

Ionic Info

Ionic:

Ionic CLI : 6.20.1 (C:\Users\Admin\AppData\Roaming\npm\node_modules@ionic\cli) Ionic Framework : @ionic/vue 6.2.6

Utility:

cordova-res : 0.15.4 native-run : 1.7.0

System:

NodeJS : v14.17.0 (C:\Program Files\nodejs\node.exe) npm : 6.14.13 OS : Windows 10

Additional Information

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
ceotrammellcommented, Sep 12, 2022

Ah okay I see! Silly me. Apologies for wasting time. Is this transparent in the documentation on ionic or did I overlook that part?

0reactions
ionitron-bot[bot]commented, Oct 12, 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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

B-Modal is Opening Two Times Vue - Stack Overflow
I am using Bootstrap-vue and targeted a b-modal with the <li> like this. But it opens the modals two times with one click...
Read more >
How to Navigate in Ionic Modals with ion-nav in VueJS
The idea here is to show how to create a navigation stack in your Ionic VueJS Application that is specifically for a modal...
Read more >
Cancel a React Modal with Escape Key or External Click
Without this, an escape key pressed while a popup was open over a nested modal would close the stack of modals having a...
Read more >
Modal · Bootstrap v5.2
Use Bootstrap's JavaScript modal plugin to add dialogs to your site for lightboxes, user notifications, or completely custom content.
Read more >
ion-modal: Ionic Mobile App Custom Modal API Component
When using ion-modal with Angular, React, or Vue, the component you pass in will be destroyed when the modal is dismissed. As this...
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