From 72e148cae8c55400884aafb58445cdb3bb501613 Mon Sep 17 00:00:00 2001 From: tangjinzhou <415800467@qq.com> Date: Wed, 30 Aug 2023 15:07:27 +0800 Subject: [PATCH] fix: portal error, close #6880 #6837 #6807 --- components/_util/Portal.tsx | 20 ++++++-------------- components/_util/PortalWrapper.tsx | 8 ++++---- 2 files changed, 10 insertions(+), 18 deletions(-) diff --git a/components/_util/Portal.tsx b/components/_util/Portal.tsx index 0aea311bc..8db5b96b7 100644 --- a/components/_util/Portal.tsx +++ b/components/_util/Portal.tsx @@ -1,13 +1,5 @@ import PropTypes from './vue-types'; -import { - defineComponent, - nextTick, - onBeforeMount, - onBeforeUnmount, - onUpdated, - Teleport, - watch, -} from 'vue'; +import { defineComponent, nextTick, onBeforeMount, onUpdated, Teleport, watch } from 'vue'; import { useInjectPortal } from '../vc-trigger/context'; export default defineComponent({ @@ -44,11 +36,11 @@ export default defineComponent({ } }); }); - onBeforeUnmount(() => { - if (container && container.parentNode) { - container.parentNode.removeChild(container); - } - }); + // onBeforeUnmount(() => { + // if (container && container.parentNode) { + // container.parentNode.removeChild(container); + // } + // }); return () => { if (!shouldRender.value) return null; if (isSSR) { diff --git a/components/_util/PortalWrapper.tsx b/components/_util/PortalWrapper.tsx index 0a0397cbc..1ef3d6e7c 100644 --- a/components/_util/PortalWrapper.tsx +++ b/components/_util/PortalWrapper.tsx @@ -61,11 +61,13 @@ export default defineComponent({ const container = shallowRef<HTMLElement>(); const componentRef = shallowRef(); const rafId = shallowRef<number>(); - + const defaultContainer = canUseDom() && document.createElement('div'); const removeCurrentContainer = () => { // Portal will remove from `parentNode`. // Let's handle this again to avoid refactor issue. - container.value?.parentNode?.removeChild(container.value); + if (container.value === defaultContainer) { + container.value?.parentNode?.removeChild(container.value); + } container.value = null; }; let parent: HTMLElement = null; @@ -82,8 +84,6 @@ export default defineComponent({ return true; }; - // attachToParent(); - const defaultContainer = canUseDom() && document.createElement('div'); const getContainer = () => { if (!supportDom) { return null;