mirror of
https://github.com/lunaisnotaboy/mastodon.git
synced 2024-12-21 12:47:58 +00:00
Revert 245816ab27
(fixes #348)
Since 245816ab27
, IntersectionObserverArticle
assumes that its children do not change unless the number of children changes.
This is not the case with the notification overlay, which resulted in the
checkmark of notification cleaning mode not updating unless scrolling to make
notifications appear/disappear.
This change may negatively impact performances.
This commit is contained in:
parent
3405ea6dd9
commit
fb6f131fa1
|
@ -1,15 +1,10 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
|
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';
|
|
||||||
|
|
||||||
// Diff these props in the "rendered" state
|
export default class IntersectionObserverArticle extends ImmutablePureComponent {
|
||||||
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,
|
||||||
|
@ -27,15 +22,18 @@ export default class IntersectionObserverArticle extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
shouldComponentUpdate (nextProps, nextState) {
|
shouldComponentUpdate (nextProps, nextState) {
|
||||||
const isUnrendered = !this.state.isIntersecting && (this.state.isHidden || this.props.cachedHeight);
|
if (!nextState.isIntersecting && nextState.isHidden) {
|
||||||
const willBeUnrendered = !nextState.isIntersecting && (nextState.isHidden || nextProps.cachedHeight);
|
// It's only if we're not intersecting (i.e. offscreen) and isHidden is true
|
||||||
if (!!isUnrendered !== !!willBeUnrendered) {
|
// that either "isIntersecting" or "isHidden" matter, and then they're
|
||||||
// If we're going from rendered to unrendered (or vice versa) then update
|
// the only things that matter (and updated ARIA attributes).
|
||||||
|
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 props
|
// Otherwise, diff based on "updateOnProps" and "updateOnStates"
|
||||||
const propsToDiff = isUnrendered ? updateOnPropsForUnrendered : updateOnPropsForRendered;
|
return super.shouldComponentUpdate(nextProps, nextState);
|
||||||
return !propsToDiff.every(prop => is(nextProps[prop], this.props[prop]));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount () {
|
componentDidMount () {
|
||||||
|
|
Loading…
Reference in a new issue