From 5738ef3fec4794b870d765dab6a125b2c97ad9bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BB=A3=E5=BC=BA?= Date: Thu, 31 Aug 2023 14:29:10 +0800 Subject: [PATCH 1/2] fix: fix portal not popup when in react18 strict mode --- packages/semi-ui/_portal/index.tsx | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/packages/semi-ui/_portal/index.tsx b/packages/semi-ui/_portal/index.tsx index 4880bf87d2..92282f0270 100644 --- a/packages/semi-ui/_portal/index.tsx +++ b/packages/semi-ui/_portal/index.tsx @@ -40,7 +40,7 @@ class Portal extends PureComponent { 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 { 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.state?.container || !this.el || !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(); From dc6f3f7feeb43ec4ec8886441b756991bba19cd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BB=A3=E5=BC=BA?= Date: Mon, 11 Sep 2023 19:27:03 +0800 Subject: [PATCH 2/2] fix: optimize code --- packages/semi-ui/_portal/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/semi-ui/_portal/index.tsx b/packages/semi-ui/_portal/index.tsx index 92282f0270..28b5e29c26 100644 --- a/packages/semi-ui/_portal/index.tsx +++ b/packages/semi-ui/_portal/index.tsx @@ -55,7 +55,7 @@ class Portal extends PureComponent { initContainer = (context: ContextValue, catchError = false) => { try { let container: HTMLElement | undefined = undefined; - if (!this.state?.container || !this.el || !Array.from(this.state.container.childNodes).includes(this.el)) { + 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();