Skip to content

Commit 72e148c

Browse files
committed
fix: portal error, close #6880 #6837 #6807
1 parent 6c13c96 commit 72e148c

File tree

2 files changed

+10
-18
lines changed

2 files changed

+10
-18
lines changed

components/_util/Portal.tsx

+6-14
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
11
import PropTypes from './vue-types';
2-
import {
3-
defineComponent,
4-
nextTick,
5-
onBeforeMount,
6-
onBeforeUnmount,
7-
onUpdated,
8-
Teleport,
9-
watch,
10-
} from 'vue';
2+
import { defineComponent, nextTick, onBeforeMount, onUpdated, Teleport, watch } from 'vue';
113
import { useInjectPortal } from '../vc-trigger/context';
124

135
export default defineComponent({
@@ -44,11 +36,11 @@ export default defineComponent({
4436
}
4537
});
4638
});
47-
onBeforeUnmount(() => {
48-
if (container && container.parentNode) {
49-
container.parentNode.removeChild(container);
50-
}
51-
});
39+
// onBeforeUnmount(() => {
40+
// if (container && container.parentNode) {
41+
// container.parentNode.removeChild(container);
42+
// }
43+
// });
5244
return () => {
5345
if (!shouldRender.value) return null;
5446
if (isSSR) {

components/_util/PortalWrapper.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,13 @@ export default defineComponent({
6161
const container = shallowRef<HTMLElement>();
6262
const componentRef = shallowRef();
6363
const rafId = shallowRef<number>();
64-
64+
const defaultContainer = canUseDom() && document.createElement('div');
6565
const removeCurrentContainer = () => {
6666
// Portal will remove from `parentNode`.
6767
// Let's handle this again to avoid refactor issue.
68-
container.value?.parentNode?.removeChild(container.value);
68+
if (container.value === defaultContainer) {
69+
container.value?.parentNode?.removeChild(container.value);
70+
}
6971
container.value = null;
7072
};
7173
let parent: HTMLElement = null;
@@ -82,8 +84,6 @@ export default defineComponent({
8284

8385
return true;
8486
};
85-
// attachToParent();
86-
const defaultContainer = canUseDom() && document.createElement('div');
8787
const getContainer = () => {
8888
if (!supportDom) {
8989
return null;

0 commit comments

Comments
 (0)