Skip to content

Commit

Permalink
fix(vue): cache attached view reference (#26694)
Browse files Browse the repository at this point in the history
Resolves #26695
  • Loading branch information
sean-perkins authored and liamdebeasi committed Feb 1, 2023
1 parent e396545 commit a930c43
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 9 deletions.
13 changes: 10 additions & 3 deletions packages/vue/src/framework-delegate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const VueDelegate = (
// TODO(FW-2969): types
const attachViewToDom = (
parentElement: HTMLElement,
component: any,
componentOrTagName: any | string,
componentProps: any = {},
classes?: string[]
) => {
Expand All @@ -33,10 +33,17 @@ export const VueDelegate = (
const hostComponent = h(
Teleport,
{ to: div },
h(component, { ...componentProps })
h(componentOrTagName, { ...componentProps })
);

refMap.set(component, hostComponent);
/**
* Ionic Framework will use what is returned from `attachViewToDom`
* as the `component` argument in `removeViewFromDom`.
*
* We will store a reference to the div element and the host component,
* so we can later look-up and unmount the correct instance.
*/
refMap.set(div, hostComponent);

addFn(hostComponent);

Expand Down
10 changes: 9 additions & 1 deletion packages/vue/test/base/src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ const routes: Array<RouteRecordRaw> = [
path: '/navigation',
component: () => import('@/views/Navigation.vue')
},
{
path: '/components',
component: () => import('@/views/Components.vue'),
},
{
path: '/components/select',
component: () => import('@/views/Select.vue')
},
{
path: '/nested',
component: () => import('@/views/RouterOutlet.vue'),
Expand Down Expand Up @@ -140,7 +148,7 @@ const routes: Array<RouteRecordRaw> = [
component: () => import('@/views/Tab3Secondary.vue')
}
]
}
},
]

const router = createRouter({
Expand Down
20 changes: 20 additions & 0 deletions packages/vue/test/base/src/views/Components.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<template>
<ion-page>
<ion-content>
<ion-list>
<ion-item button router-link="/components/select">
<ion-label>Select</ion-label>
</ion-item>
</ion-list>
</ion-content>
</ion-page>
</template>

<script lang="ts">
import { defineComponent } from "vue";
import { IonPage, IonContent, IonList, IonItem, IonLabel } from "@ionic/vue";
export default defineComponent({
components: { IonPage, IonContent, IonList, IonItem, IonLabel },
});
</script>
23 changes: 18 additions & 5 deletions packages/vue/test/base/src/views/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,28 @@
<ion-item button router-link="/delayed-redirect" id="delayed-redirect">
<ion-label>Delayed Redirect</ion-label>
</ion-item>
<ion-item button router-link="/components">
<ion-label>Components</ion-label>
</ion-item>
</ion-list>

</ion-content>
</ion-page>
</template>

<script lang="ts">
import { IonButtons, IonBackButton, IonContent, IonHeader, IonItem, IonLabel, IonList, IonPage, IonTitle, IonToolbar } from '@ionic/vue';
import { defineComponent } from 'vue';
import {
IonButtons,
IonBackButton,
IonContent,
IonHeader,
IonItem,
IonLabel,
IonList,
IonPage,
IonTitle,
IonToolbar,
} from "@ionic/vue";
import { defineComponent } from "vue";
export default defineComponent({
components: {
Expand All @@ -74,7 +87,7 @@ export default defineComponent({
IonList,
IonPage,
IonTitle,
IonToolbar
}
IonToolbar,
},
});
</script>
52 changes: 52 additions & 0 deletions packages/vue/test/base/src/views/Select.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<template>
<ion-page>
<ion-header>
<ion-toolbar>
<ion-title>Select</ion-title>
</ion-toolbar>
</ion-header>
<ion-content>
<ion-item>
<ion-label>Select Popover</ion-label>
<ion-select
id="select-popover"
interface="popover"
placeholder="Select fruit"
>
<ion-select-option value="apples">Apples</ion-select-option>
<ion-select-option value="oranges">Oranges</ion-select-option>
<ion-select-option value="bananas">Bananas</ion-select-option>
</ion-select>
</ion-item>
</ion-content>
</ion-page>
</template>

<script lang="ts">
import {
IonPage,
IonHeader,
IonToolbar,
IonTitle,
IonContent,
IonItem,
IonLabel,
IonSelect,
IonSelectOption,
} from "@ionic/vue";
import { defineComponent } from "vue";
export default defineComponent({
components: {
IonPage,
IonHeader,
IonToolbar,
IonTitle,
IonContent,
IonItem,
IonLabel,
IonSelect,
IonSelectOption,
},
});
</script>
10 changes: 10 additions & 0 deletions packages/vue/test/base/tests/e2e/specs/select.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
describe("Components: Select", () => {
beforeEach(() => {
cy.visit("http://localhost:8080/components/select");
});

it("should open a popover overlay interface", () => {
cy.get("#select-popover").click();
cy.get("ion-popover").should("exist").should("be.visible");
});
});

0 comments on commit a930c43

Please sign in to comment.