react-component / react-component/trigger

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

Open
#264 2 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
391
Forks
245
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the getContainer entry point and the PortalComponent usage shown in the issue, then reproduce the behavior in React StrictMode with a development popup. Verify that opening and closing the popup repeatedly leaves only the intended container in the DOM and does not create orphaned div elements.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.