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

PopperContent memory leak #1669

Merged
merged 1 commit into from Oct 18, 2019
Merged

Conversation

phwebi
Copy link
Member

@phwebi phwebi commented Oct 17, 2019

  • Bug fix
  • New feature
  • Chore
  • Breaking change
  • There is an open issue which this change addresses
  • I have read the CONTRIBUTING document.
  • My commits follow the Git Commit Guidelines
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
    • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

When a tooltip or popover does not fit in the containing element, this causes the PopperContent component to get into an infinite loop of switching between placements in its state. This is because we attempt to update this.state.placement everytime popper.js flips the placement to find a better fit and pass it back as the placement property to ReactPopper.

This is a problem because the PopperContent component has two sources of truth for its placement. One coming from its own placement property, and one coming from the internal data of ReactPopper.

This commit fixes the issue by using PopperContent's placement property as the initial placement of the ReactPopper component and allowing ReactPopper to manage its own updates (i.e. if the popover needs to be flipped because there's not enough room for the specified placement.)

I manually tested this by reproducing the issues linked below at https://reactstrap.github.io/components/popovers/, and making sure that the page wouldn't crash when I followed the same steps on the changes in this branch.

Fixes #1482
Fixes #1488
Fixes #1664

…ining element

When a tooltip or popover does not fit in the containing element, this causes the `PopperContent` component to get into an infinite loop of switching between `placement`s in its state. This is because we attempt to update `this.state.placement` everytime popper.js flips the placement to find a better fit and pass it back as the `placement` property to `ReactPopper`.

This is a problem because the `PopperContent` component has two sources of truth for its placement. One coming from its own `placement` property, and one coming from the internal data of `ReactPopper`.

This commit fixes the issue by using `PopperContent`'s `placement` property as the initial placement of the `ReactPopper` component and allowing `ReactPopper` to manage its own updates (i.e. if the popover needs to be flipped because there's not enough room for the specified placement.)

Fixes reactstrap#1482
Fixes reactstrap#1488
@phwebi phwebi changed the title Popper memory leak PopperContent memory leak Oct 17, 2019
const popperClassName = mapToCssModules(classNames(
_popperClassName,
placementPrefix ? `${placementPrefix}-${placementFirstPart}` : placementFirstPart
placementPrefix ? `${placementPrefix}-auto` : ''
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This allows the arrow to inherit its style from the computed popper placement instead of the placement property passed into this component.

See https://github.com/twbs/bootstrap/blob/c1ee395f80c05de8317588b07f34a65c5b95c42c/scss/_popover.scss#L136

@TheSharpieOne TheSharpieOne merged commit 54d459c into reactstrap:master Oct 18, 2019
@phwebi phwebi deleted the popper-memory-leak branch October 18, 2019 16:57
phwebi added a commit to phwebi/reactstrap that referenced this pull request Oct 18, 2019
I accidentally left a debug statement in reactstrap#1669 that was merged. This commit removes the debug statement.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants