Quellcode durchsuchen

Merge pull request #1792 from DouyinFE/fix_react18StrictMode

fix: fix portal not popup when in react18 strict mode
代强 vor 2 Jahren
Ursprung
Commit
0ff761faf3
1 geänderte Dateien mit 2 neuen und 5 gelöschten Zeilen
  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;
     context: ContextValue;
     constructor(props: PortalProps, context: ContextValue) {
     constructor(props: PortalProps, context: ContextValue) {
         super(props);
         super(props);
-        this.state = { 
+        this.state = {
             container: this.initContainer(context, true)
             container: this.initContainer(context, true)
         };
         };
     }
     }
@@ -55,10 +55,7 @@ class Portal extends PureComponent<PortalProps, PortalState> {
     initContainer = (context: ContextValue, catchError = false) => {
     initContainer = (context: ContextValue, catchError = false) => {
         try {
         try {
             let container: HTMLElement | undefined = undefined;
             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');
                 this.el = document.createElement('div');
                 const getContainer = this.props.getPopupContainer || context.getPopupContainer || defaultGetContainer;
                 const getContainer = this.props.getPopupContainer || context.getPopupContainer || defaultGetContainer;
                 const portalContainer = getContainer();
                 const portalContainer = getContainer();