2018-03-24 14:25:15 +00:00
|
|
|
import { debounce } from 'lodash';
|
2017-05-03 01:04:16 +01:00
|
|
|
import React from 'react';
|
2016-12-03 20:04:57 +00:00
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
2017-04-21 19:05:35 +01:00
|
|
|
import PropTypes from 'prop-types';
|
2016-12-03 20:04:57 +00:00
|
|
|
import StatusContainer from '../containers/status_container';
|
2017-05-03 01:04:16 +01:00
|
|
|
import ImmutablePureComponent from 'react-immutable-pure-component';
|
2018-04-10 16:12:10 +01:00
|
|
|
import LoadGap from './load_gap';
|
2017-08-28 21:23:44 +01:00
|
|
|
import ScrollableList from './scrollable_list';
|
2019-10-06 21:11:17 +01:00
|
|
|
import RegenerationIndicator from 'mastodon/components/regeneration_indicator';
|
2016-08-24 16:56:44 +01:00
|
|
|
|
2017-06-23 18:36:54 +01:00
|
|
|
export default class StatusList extends ImmutablePureComponent {
|
2017-04-21 19:05:35 +01:00
|
|
|
|
2017-05-12 13:44:10 +01:00
|
|
|
static propTypes = {
|
|
|
|
scrollKey: PropTypes.string.isRequired,
|
|
|
|
statusIds: ImmutablePropTypes.list.isRequired,
|
2018-03-04 08:19:11 +00:00
|
|
|
featuredStatusIds: ImmutablePropTypes.list,
|
2018-03-05 18:31:40 +00:00
|
|
|
onLoadMore: PropTypes.func,
|
2017-05-12 13:44:10 +01:00
|
|
|
onScrollToTop: PropTypes.func,
|
|
|
|
onScroll: PropTypes.func,
|
2017-06-05 14:20:46 +01:00
|
|
|
trackScroll: PropTypes.bool,
|
2017-05-12 13:44:10 +01:00
|
|
|
shouldUpdateScroll: PropTypes.func,
|
|
|
|
isLoading: PropTypes.bool,
|
2018-01-17 22:56:03 +00:00
|
|
|
isPartial: PropTypes.bool,
|
2017-05-12 13:44:10 +01:00
|
|
|
hasMore: PropTypes.bool,
|
|
|
|
prepend: PropTypes.node,
|
2017-05-20 16:31:47 +01:00
|
|
|
emptyMessage: PropTypes.node,
|
2018-05-29 01:01:04 +01:00
|
|
|
alwaysPrepend: PropTypes.bool,
|
2018-11-08 20:35:06 +00:00
|
|
|
timelineId: PropTypes.string,
|
Summary: fix slowness due to layout thrashing when reloading a large … (#12661)
* Summary: fix slowness due to layout thrashing when reloading a large set of status updates
in order to limit the maximum size of a status in a list view (e.g. the home timeline), so as to avoid having to scroll all the way through an abnormally large status update (see https://github.com/tootsuite/mastodon/pull/8205), the following steps are taken:
•the element containing the status is rendered in the browser
•its height is calculated, to determine if it exceeds the maximum height threshold.
Unfortunately for performance, these steps are carried out in the componentDidMount(/Update) method, which also performs style modifications on the element. The combination of height request and style modification during javascript evaluation in the browser leads to layout-thrashing, where the elements are repeatedly re-laid-out (see https://developers.google.com/web/fundamentals/performance/rendering/avoid-large-complex-layouts-and-layout-thrashing & https://developer.mozilla.org/en-US/docs/Mozilla/Firefox/Performance_best_practices_for_Firefox_fe_engineers).
The solution implemented here is to memoize the collapsed state in Redux the first time the status is seen (e.g. when fetched as part of a small batch, to populate the home timeline) , so that on subsequent re-renders, the value can be queried, rather than recalculated. This strategy is derived from https://github.com/tootsuite/mastodon/pull/4439 & https://github.com/tootsuite/mastodon/pull/4909, and should resolve https://github.com/tootsuite/mastodon/issues/12455.
Andrew Lin (https://github.com/onethreeseven) is thanked for his assistance in root cause analysis and solution brainstorming
* remove getSnapshotBeforeUpdate from status
* remove componentWillUnmount from status
* persist last-intersected status update and restore when ScrollableList is restored
e.g. when navigating from home-timeline to a status conversational thread and <Back again
* cache currently-viewing status id to avoid calling redux with identical value
* refactor collapse toggle to pass explicit boolean
2019-12-29 04:39:48 +00:00
|
|
|
currentlyViewing: PropTypes.number,
|
|
|
|
updateCurrentlyViewing: PropTypes.func,
|
2017-05-12 13:44:10 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
static defaultProps = {
|
2017-05-20 16:31:47 +01:00
|
|
|
trackScroll: true,
|
2017-05-12 13:44:10 +01:00
|
|
|
};
|
|
|
|
|
2018-04-20 17:14:21 +01:00
|
|
|
getFeaturedStatusCount = () => {
|
|
|
|
return this.props.featuredStatusIds ? this.props.featuredStatusIds.size : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
getCurrentStatusIndex = (id, featured) => {
|
|
|
|
if (featured) {
|
|
|
|
return this.props.featuredStatusIds.indexOf(id);
|
|
|
|
} else {
|
|
|
|
return this.props.statusIds.indexOf(id) + this.getFeaturedStatusCount();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
handleMoveUp = (id, featured) => {
|
|
|
|
const elementIndex = this.getCurrentStatusIndex(id, featured) - 1;
|
2019-05-03 05:20:36 +01:00
|
|
|
this._selectChild(elementIndex, true);
|
2017-10-06 00:07:59 +01:00
|
|
|
}
|
|
|
|
|
2018-04-20 17:14:21 +01:00
|
|
|
handleMoveDown = (id, featured) => {
|
|
|
|
const elementIndex = this.getCurrentStatusIndex(id, featured) + 1;
|
2019-05-03 05:20:36 +01:00
|
|
|
this._selectChild(elementIndex, false);
|
2017-10-06 00:07:59 +01:00
|
|
|
}
|
|
|
|
|
2018-03-24 14:25:15 +00:00
|
|
|
handleLoadOlder = debounce(() => {
|
2018-12-12 21:32:44 +00:00
|
|
|
this.props.onLoadMore(this.props.statusIds.size > 0 ? this.props.statusIds.last() : undefined);
|
2018-03-24 14:25:15 +00:00
|
|
|
}, 300, { leading: true })
|
|
|
|
|
Summary: fix slowness due to layout thrashing when reloading a large … (#12661)
* Summary: fix slowness due to layout thrashing when reloading a large set of status updates
in order to limit the maximum size of a status in a list view (e.g. the home timeline), so as to avoid having to scroll all the way through an abnormally large status update (see https://github.com/tootsuite/mastodon/pull/8205), the following steps are taken:
•the element containing the status is rendered in the browser
•its height is calculated, to determine if it exceeds the maximum height threshold.
Unfortunately for performance, these steps are carried out in the componentDidMount(/Update) method, which also performs style modifications on the element. The combination of height request and style modification during javascript evaluation in the browser leads to layout-thrashing, where the elements are repeatedly re-laid-out (see https://developers.google.com/web/fundamentals/performance/rendering/avoid-large-complex-layouts-and-layout-thrashing & https://developer.mozilla.org/en-US/docs/Mozilla/Firefox/Performance_best_practices_for_Firefox_fe_engineers).
The solution implemented here is to memoize the collapsed state in Redux the first time the status is seen (e.g. when fetched as part of a small batch, to populate the home timeline) , so that on subsequent re-renders, the value can be queried, rather than recalculated. This strategy is derived from https://github.com/tootsuite/mastodon/pull/4439 & https://github.com/tootsuite/mastodon/pull/4909, and should resolve https://github.com/tootsuite/mastodon/issues/12455.
Andrew Lin (https://github.com/onethreeseven) is thanked for his assistance in root cause analysis and solution brainstorming
* remove getSnapshotBeforeUpdate from status
* remove componentWillUnmount from status
* persist last-intersected status update and restore when ScrollableList is restored
e.g. when navigating from home-timeline to a status conversational thread and <Back again
* cache currently-viewing status id to avoid calling redux with identical value
* refactor collapse toggle to pass explicit boolean
2019-12-29 04:39:48 +00:00
|
|
|
updateCurrentlyViewingWithCache = (id) => {
|
|
|
|
if(this.cachedCurrentlyViewing === id) return;
|
|
|
|
this.cachedCurrentlyViewing = id;
|
|
|
|
this.props.updateCurrentlyViewing(id);
|
|
|
|
}
|
|
|
|
|
2019-05-03 05:20:36 +01:00
|
|
|
_selectChild (index, align_top) {
|
|
|
|
const container = this.node.node;
|
|
|
|
const element = container.querySelector(`article:nth-of-type(${index + 1}) .focusable`);
|
2017-10-06 00:07:59 +01:00
|
|
|
|
|
|
|
if (element) {
|
2019-05-03 05:20:36 +01:00
|
|
|
if (align_top && container.scrollTop > element.offsetTop) {
|
|
|
|
element.scrollIntoView(true);
|
|
|
|
} else if (!align_top && container.scrollTop + container.clientHeight < element.offsetTop + element.offsetHeight) {
|
|
|
|
element.scrollIntoView(false);
|
|
|
|
}
|
2017-10-06 00:07:59 +01:00
|
|
|
element.focus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
setRef = c => {
|
|
|
|
this.node = c;
|
|
|
|
}
|
|
|
|
|
2016-08-31 15:15:12 +01:00
|
|
|
render () {
|
2018-07-29 15:52:06 +01:00
|
|
|
const { statusIds, featuredStatusIds, shouldUpdateScroll, onLoadMore, timelineId, ...other } = this.props;
|
2018-01-17 22:56:03 +00:00
|
|
|
const { isLoading, isPartial } = other;
|
Summary: fix slowness due to layout thrashing when reloading a large … (#12661)
* Summary: fix slowness due to layout thrashing when reloading a large set of status updates
in order to limit the maximum size of a status in a list view (e.g. the home timeline), so as to avoid having to scroll all the way through an abnormally large status update (see https://github.com/tootsuite/mastodon/pull/8205), the following steps are taken:
•the element containing the status is rendered in the browser
•its height is calculated, to determine if it exceeds the maximum height threshold.
Unfortunately for performance, these steps are carried out in the componentDidMount(/Update) method, which also performs style modifications on the element. The combination of height request and style modification during javascript evaluation in the browser leads to layout-thrashing, where the elements are repeatedly re-laid-out (see https://developers.google.com/web/fundamentals/performance/rendering/avoid-large-complex-layouts-and-layout-thrashing & https://developer.mozilla.org/en-US/docs/Mozilla/Firefox/Performance_best_practices_for_Firefox_fe_engineers).
The solution implemented here is to memoize the collapsed state in Redux the first time the status is seen (e.g. when fetched as part of a small batch, to populate the home timeline) , so that on subsequent re-renders, the value can be queried, rather than recalculated. This strategy is derived from https://github.com/tootsuite/mastodon/pull/4439 & https://github.com/tootsuite/mastodon/pull/4909, and should resolve https://github.com/tootsuite/mastodon/issues/12455.
Andrew Lin (https://github.com/onethreeseven) is thanked for his assistance in root cause analysis and solution brainstorming
* remove getSnapshotBeforeUpdate from status
* remove componentWillUnmount from status
* persist last-intersected status update and restore when ScrollableList is restored
e.g. when navigating from home-timeline to a status conversational thread and <Back again
* cache currently-viewing status id to avoid calling redux with identical value
* refactor collapse toggle to pass explicit boolean
2019-12-29 04:39:48 +00:00
|
|
|
other.updateCurrentlyViewing = this.updateCurrentlyViewingWithCache;
|
2018-01-17 22:56:03 +00:00
|
|
|
|
|
|
|
if (isPartial) {
|
2019-10-06 21:11:17 +01:00
|
|
|
return <RegenerationIndicator />;
|
2018-01-17 22:56:03 +00:00
|
|
|
}
|
2017-08-28 21:23:44 +01:00
|
|
|
|
2018-03-04 08:19:11 +00:00
|
|
|
let scrollableContent = (isLoading || statusIds.size > 0) ? (
|
2018-03-24 14:25:15 +00:00
|
|
|
statusIds.map((statusId, index) => statusId === null ? (
|
|
|
|
<LoadGap
|
|
|
|
key={'gap:' + statusIds.get(index + 1)}
|
|
|
|
disabled={isLoading}
|
|
|
|
maxId={index > 0 ? statusIds.get(index - 1) : null}
|
|
|
|
onClick={onLoadMore}
|
|
|
|
/>
|
|
|
|
) : (
|
2017-10-06 00:07:59 +01:00
|
|
|
<StatusContainer
|
|
|
|
key={statusId}
|
|
|
|
id={statusId}
|
|
|
|
onMoveUp={this.handleMoveUp}
|
|
|
|
onMoveDown={this.handleMoveDown}
|
2018-06-29 14:34:36 +01:00
|
|
|
contextType={timelineId}
|
2018-11-08 20:08:57 +00:00
|
|
|
showThread
|
2017-10-06 00:07:59 +01:00
|
|
|
/>
|
2017-08-28 21:23:44 +01:00
|
|
|
))
|
|
|
|
) : null;
|
|
|
|
|
2018-03-04 08:19:11 +00:00
|
|
|
if (scrollableContent && featuredStatusIds) {
|
|
|
|
scrollableContent = featuredStatusIds.map(statusId => (
|
|
|
|
<StatusContainer
|
|
|
|
key={`f-${statusId}`}
|
|
|
|
id={statusId}
|
|
|
|
featured
|
|
|
|
onMoveUp={this.handleMoveUp}
|
|
|
|
onMoveDown={this.handleMoveDown}
|
2018-06-29 14:34:36 +01:00
|
|
|
contextType={timelineId}
|
2018-11-08 20:08:57 +00:00
|
|
|
showThread
|
2018-03-04 08:19:11 +00:00
|
|
|
/>
|
|
|
|
)).concat(scrollableContent);
|
|
|
|
}
|
|
|
|
|
2017-08-28 21:23:44 +01:00
|
|
|
return (
|
2018-11-08 20:35:06 +00:00
|
|
|
<ScrollableList {...other} showLoading={isLoading && statusIds.size === 0} onLoadMore={onLoadMore && this.handleLoadOlder} shouldUpdateScroll={shouldUpdateScroll} ref={this.setRef}>
|
2017-08-28 21:23:44 +01:00
|
|
|
{scrollableContent}
|
|
|
|
</ScrollableList>
|
|
|
|
);
|
2016-08-24 16:56:44 +01:00
|
|
|
}
|
2016-08-31 15:15:12 +01:00
|
|
|
|
2017-04-21 19:05:35 +01:00
|
|
|
}
|