Defer handleScroll
in componentDidUpdate
#265
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I was doing some profiling and I noticed that when Waypoint updates, we
call
this._handleScroll
synchronously, which eventually calls functionsthat force layout. Since this happens during render, the layout is
immediately invalidated and then triggered again once rendering is
completed.
We avoid this problem in
componentDidMount
by deferring this workuntil the next tick.
I think we should consider making two changes to Waypoint to help
address this:
Extend
React.PureComponent
instead ofReact.Component
. In theplace I saw this problem, we were rendering a waypoint with pure
props, so the update in this case could be completely avoided by
using PureComponent.
Defer
this._handleScroll
incomponentDidUpdate
usingonNextTick
, like we do incomponentDidMount
. This will stillrequire layout, but it will happen around the same time that the
browser was going to do layout anyway, avoiding the thrash.
This commit implements the second of these two interventions.
Fixes #263