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

fix(Sticky): prevent npe error after unmount of component #2854

Merged
merged 4 commits into from
May 31, 2018

Conversation

fracmak
Copy link
Member

@fracmak fracmak commented May 30, 2018

This fixes a simple problem where the event listeners call handleUpdate() which calls requestAnimationFrame to call the update function in the next tick, but if the component unmounts between the handleUpdate call and the requestAnimationFrame firing, we get an NPE error because the handleTriggerRef function has been fired with null as the ref ( reference: https://reactjs.org/docs/refs-and-the-dom.html#adding-a-ref-to-a-dom-element ).

This prevents that from happening by saving the requestId from requestAnimationFrame and clearing it on componentWillUnmount

@@ -217,7 +220,7 @@ export default class Sticky extends Component {
didReachContextBottom = () => {
const { offset } = this.props

return (this.stickyRect.height + offset) >= this.contextRect.bottom
Copy link
Member Author

Choose a reason for hiding this comment

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

I believe these lines changed because of prettier/eslint --fix

@codecov-io
Copy link

codecov-io commented May 30, 2018

Codecov Report

Merging #2854 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2854      +/-   ##
==========================================
+ Coverage   99.74%   99.74%   +<.01%     
==========================================
  Files         160      160              
  Lines        2777     2779       +2     
==========================================
+ Hits         2770     2772       +2     
  Misses          7        7
Impacted Files Coverage Δ
src/modules/Sticky/Sticky.js 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7e79cd3...6915f52. Read the comment docs.

@fracmak fracmak force-pushed the sticky-umount-bug branch from 692ad5f to def4afe Compare May 30, 2018 23:31
Copy link
Member

@layershifter layershifter left a comment

Choose a reason for hiding this comment

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

Made some style changes, LGTM 👍 @fracmak thanks for PR!

@layershifter layershifter merged commit 0ec84c9 into Semantic-Org:master May 31, 2018
@levithomason
Copy link
Member

Released in semantic-ui-react@0.81.0.

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

Successfully merging this pull request may close these issues.

4 participants