Bläddra i källkod

Merge pull request #1792 from DouyinFE/fix_react18StrictMode

fix: fix portal not popup when in react18 strict mode
代强 2 år sedan
förälder
incheckning
0ff761faf3
1 ändrade filer med 2 tillägg och 5 borttagningar
  1. 2 5
      packages/semi-ui/_portal/index.tsx

+ 2 - 5
packages/semi-ui/_portal/index.tsx

@@ -40,7 +40,7 @@ class Portal extends PureComponent<PortalProps, PortalState> {
     context: ContextValue;
     constructor(props: PortalProps, context: ContextValue) {
         super(props);
-        this.state = { 
+        this.state = {
             container: this.initContainer(context, true)
         };
     }
@@ -55,10 +55,7 @@ class Portal extends PureComponent<PortalProps, PortalState> {
     initContainer = (context: ContextValue, catchError = false) => {
         try {
             let container: HTMLElement | undefined = undefined;
-            if (!this.el) {
-                this.el = document.createElement('div');
-            }
-            if (!this.state?.container) {
+            if (!this.el || !this.state?.container || !Array.from(this.state.container.childNodes).includes(this.el)) {
                 this.el = document.createElement('div');
                 const getContainer = this.props.getPopupContainer || context.getPopupContainer || defaultGetContainer;
                 const portalContainer = getContainer();