trigger icon indicating copy to clipboard operation
trigger copied to clipboard

in StrictMode, getContainer has side effect, duplicated div will be attached to Dom, please fix it.

Open kongshu612 opened this issue 3 years ago • 1 comments

let see the code bellow. In strict mode and dev environment, getContainer will be called twice, so double div will be attached to Dom, if we enable autoDestory, only one div will be removed after popup closed. That means every popup open and close will lead to one orphaned div, we may have multi divs in dom if we open and close popup muti times.

 getContainer = () => {
      const { getDocument } = this.props;
      const popupContainer = getDocument(this.getRootDomNode()).createElement(
        'div',
      );
      // Make sure default popup container will never cause scrollbar appearing
      // https://github.com/react-component/trigger/issues/41
      popupContainer.style.position = 'absolute';
      popupContainer.style.top = '0';
      popupContainer.style.left = '0';
      popupContainer.style.width = '100%';
      this.attachParent(popupContainer);
      return popupContainer;
    };


if (popupVisible || this.popupRef.current || forceRender) {
        portal = (
          <PortalComponent
            key="portal"
            getContainer={this.getContainer}
            didUpdate={this.handlePortalUpdate}
          >
            {this.getComponent()}
          </PortalComponent>
        );
      }

here give a screenshot.

image

kongshu612 avatar May 23 '21 14:05 kongshu612

have same problem,need author fix it...

liangxiwei avatar Jul 15 '21 03:07 liangxiwei