react-component / react-component/trigger
in StrictMode, getContainer has side effect, duplicated div will be attached to Dom, please fix it.
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.

Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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