Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Teleport component's DOM isn't unmounted when deactivated inside KeepAlive #5603

Open
07akioni opened this issue Mar 20, 2022 · 5 comments
Open
Labels
has workaround A workaround has been found to avoid the problem scope: keep-alive scope: teleport

Comments

@07akioni
Copy link
Contributor

Version

3.2.31

Reproduction link

codesandbox.io

Steps to reproduce

Click 'show modal' then click 'to tab2'.

What is expected?

Modal's DOM removed.

What is actually happening?

Modal's DOM isn't removed.

@07akioni 07akioni changed the title Teleport component isn't unmounted when deactivated inside KeepAlive Teleport component's DOM isn't unmounted when deactivated inside KeepAlive Mar 20, 2022
@runxc1
Copy link

runxc1 commented Jul 1, 2022

I'm running into the same issue if the app is mounted to a specific element and then later that element is removed from the page. The entire app goes away correctly but the Teleported item that is disabled then displays and is left on the page

@07akioni
Copy link
Contributor Author

07akioni commented Jul 2, 2022

I think this should be tagged as bug.

@ivanmem
Copy link

ivanmem commented Sep 6, 2023

Has anyone found a way to get around this problem?

@edison1105
Copy link
Member

@xeleoss
Manually disabled teleport is a workaround.
see

@edison1105 edison1105 added the has workaround A workaround has been found to avoid the problem label Sep 12, 2023
@ivanmem
Copy link

ivanmem commented Sep 12, 2023

The workaround works! I wrote a component that uses it.

FixedTeleport.vue

<script setup lang="ts">
import { useActivated } from "@/composables/useActivated";

const props = defineProps({
  to: String,
  disabled: Boolean,
});

const isActivated = useActivated();
</script>
<template>
  <Teleport :disabled="!isActivated || props.disabled" :to="props.to">
    <slot />
  </Teleport>
</template>

useActivated.ts

import { onActivated, onDeactivated, ref } from "vue";

export function useActivated() {
  const isActive = ref(true);

  onActivated(() => {
    isActive.value = true;
  });

  onDeactivated(() => {
    isActive.value = false;
  });

  return isActive;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has workaround A workaround has been found to avoid the problem scope: keep-alive scope: teleport
Projects
None yet
Development

No branches or pull requests

5 participants