Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
kongshu612 opened this issue May 23, 2021 · 1 comment

Comments

@kongshu612
Copy link

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

@liangxiwei
Copy link

have same problem,need author fix it...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants