mirror of
https://github.com/mastodon/mastodon.git
synced 2024-11-24 06:46:29 +00:00
Revert to using upstream's optimisations
This *does* break things, as `shouldComponentUpdate` assume the children to never change!
This commit is contained in:
parent
0ef6a114e7
commit
c0b5ee315d
|
@ -3,8 +3,14 @@ import PropTypes from 'prop-types';
|
||||||
import ImmutablePureComponent from 'react-immutable-pure-component';
|
import ImmutablePureComponent from 'react-immutable-pure-component';
|
||||||
import scheduleIdleTask from 'flavours/glitch/util/schedule_idle_task';
|
import scheduleIdleTask from 'flavours/glitch/util/schedule_idle_task';
|
||||||
import getRectFromEntry from 'flavours/glitch/util/get_rect_from_entry';
|
import getRectFromEntry from 'flavours/glitch/util/get_rect_from_entry';
|
||||||
|
import { is } from 'immutable';
|
||||||
|
|
||||||
export default class IntersectionObserverArticle extends ImmutablePureComponent {
|
// Diff these props in the "rendered" state
|
||||||
|
const updateOnPropsForRendered = ['id', 'index', 'listLength'];
|
||||||
|
// Diff these props in the "unrendered" state
|
||||||
|
const updateOnPropsForUnrendered = ['id', 'index', 'listLength', 'cachedHeight'];
|
||||||
|
|
||||||
|
export default class IntersectionObserverArticle extends React.Component {
|
||||||
|
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
intersectionObserverWrapper: PropTypes.object.isRequired,
|
intersectionObserverWrapper: PropTypes.object.isRequired,
|
||||||
|
@ -22,20 +28,18 @@ export default class IntersectionObserverArticle extends ImmutablePureComponent
|
||||||
}
|
}
|
||||||
|
|
||||||
shouldComponentUpdate (nextProps, nextState) {
|
shouldComponentUpdate (nextProps, nextState) {
|
||||||
if (!nextState.isIntersecting && nextState.isHidden) {
|
const isUnrendered = !this.state.isIntersecting && (this.state.isHidden || this.props.cachedHeight);
|
||||||
// It's only if we're not intersecting (i.e. offscreen) and isHidden is true
|
const willBeUnrendered = !nextState.isIntersecting && (nextState.isHidden || nextProps.cachedHeight);
|
||||||
// that either "isIntersecting" or "isHidden" matter, and then they're
|
if (!!isUnrendered !== !!willBeUnrendered) {
|
||||||
// the only things that matter (and updated ARIA attributes).
|
// If we're going from rendered to unrendered (or vice versa) then update
|
||||||
return this.state.isIntersecting || !this.state.isHidden || nextProps.listLength !== this.props.listLength;
|
|
||||||
} else if (nextState.isIntersecting && !this.state.isIntersecting) {
|
|
||||||
// If we're going from a non-intersecting state to an intersecting state,
|
|
||||||
// (i.e. offscreen to onscreen), then we definitely need to re-render
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// Otherwise, diff based on "updateOnProps" and "updateOnStates"
|
// Otherwise, diff based on props
|
||||||
return super.shouldComponentUpdate(nextProps, nextState);
|
const propsToDiff = isUnrendered ? updateOnPropsForUnrendered : updateOnPropsForRendered;
|
||||||
|
return !propsToDiff.every(prop => is(nextProps[prop], this.props[prop]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
componentDidMount () {
|
componentDidMount () {
|
||||||
const { intersectionObserverWrapper, id } = this.props;
|
const { intersectionObserverWrapper, id } = this.props;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue