Skip to content

Commit

Permalink
Revert "Summary: fix slowness due to layout thrashing when reloading …
Browse files Browse the repository at this point in the history
…a large … (mastodon#12661)"

This reverts commit 31f7c3f.
  • Loading branch information
zunda committed Dec 30, 2019
1 parent 14a8c57 commit 1e7b5fb
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 74 deletions.
13 changes: 2 additions & 11 deletions app/javascript/mastodon/actions/statuses.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ export const STATUS_UNMUTE_REQUEST = 'STATUS_UNMUTE_REQUEST';
export const STATUS_UNMUTE_SUCCESS = 'STATUS_UNMUTE_SUCCESS';
export const STATUS_UNMUTE_FAIL = 'STATUS_UNMUTE_FAIL';

export const STATUS_REVEAL = 'STATUS_REVEAL';
export const STATUS_HIDE = 'STATUS_HIDE';
export const STATUS_COLLAPSE = 'STATUS_COLLAPSE';
export const STATUS_REVEAL = 'STATUS_REVEAL';
export const STATUS_HIDE = 'STATUS_HIDE';

export const REDRAFT = 'REDRAFT';

Expand Down Expand Up @@ -321,11 +320,3 @@ export function revealStatus(ids) {
ids,
};
};

export function toggleStatusCollapse(id, isCollapsed) {
return {
type: STATUS_COLLAPSE,
id,
isCollapsed,
};
}
8 changes: 0 additions & 8 deletions app/javascript/mastodon/actions/timelines.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,6 @@ export const TIMELINE_LOAD_PENDING = 'TIMELINE_LOAD_PENDING';
export const TIMELINE_DISCONNECT = 'TIMELINE_DISCONNECT';
export const TIMELINE_CONNECT = 'TIMELINE_CONNECT';

export const CURRENTLY_VIEWING = 'CURRENTLY_VIEWING';

export const updateCurrentlyViewing = (timeline, id) => ({
type: CURRENTLY_VIEWING,
timeline,
id,
});

export const loadPending = timeline => ({
type: TIMELINE_LOAD_PENDING,
timeline,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ export default class IntersectionObserverArticle extends React.Component {
cachedHeight: PropTypes.number,
onHeightChange: PropTypes.func,
children: PropTypes.node,
currentlyViewing: PropTypes.number,
updateCurrentlyViewing: PropTypes.func,
};

state = {
Expand Down Expand Up @@ -50,8 +48,6 @@ export default class IntersectionObserverArticle extends React.Component {
);

this.componentMounted = true;

if(id === this.props.currentlyViewing) this.node.scrollIntoView();
}

componentWillUnmount () {
Expand All @@ -64,8 +60,6 @@ export default class IntersectionObserverArticle extends React.Component {
handleIntersection = (entry) => {
this.entry = entry;

if(entry.intersectionRatio > 0.75 && this.props.updateCurrentlyViewing) this.props.updateCurrentlyViewing(this.id);

scheduleIdleTask(this.calculateHeight);
this.setState(this.updateStateAfterIntersection);
}
Expand Down
4 changes: 0 additions & 4 deletions app/javascript/mastodon/components/scrollable_list.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ export default class ScrollableList extends PureComponent {
emptyMessage: PropTypes.node,
children: PropTypes.node,
bindToDocument: PropTypes.bool,
currentlyViewing: PropTypes.number,
updateCurrentlyViewing: PropTypes.func,
};

static defaultProps = {
Expand Down Expand Up @@ -311,8 +309,6 @@ export default class ScrollableList extends PureComponent {
listLength={childrenCount}
intersectionObserverWrapper={this.intersectionObserverWrapper}
saveHeightKey={trackScroll ? `${this.context.router.route.location.key}:${scrollKey}` : null}
currentlyViewing={this.props.currentlyViewing}
updateCurrentlyViewing={this.props.updateCurrentlyViewing}
>
{React.cloneElement(child, {
getScrollPosition: this.getScrollPosition,
Expand Down
28 changes: 21 additions & 7 deletions app/javascript/mastodon/components/status.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ class Status extends ImmutablePureComponent {
onEmbed: PropTypes.func,
onHeightChange: PropTypes.func,
onToggleHidden: PropTypes.func,
onToggleCollapsed: PropTypes.func,
muted: PropTypes.bool,
hidden: PropTypes.bool,
unread: PropTypes.bool,
Expand Down Expand Up @@ -108,6 +107,14 @@ class Status extends ImmutablePureComponent {
this.didShowCard = !this.props.muted && !this.props.hidden && this.props.status && this.props.status.get('card');
}

getSnapshotBeforeUpdate () {
if (this.props.getScrollPosition) {
return this.props.getScrollPosition();
} else {
return null;
}
}

static getDerivedStateFromProps(nextProps, prevState) {
if (nextProps.status && nextProps.status.get('id') !== prevState.statusId) {
return {
Expand All @@ -134,6 +141,17 @@ class Status extends ImmutablePureComponent {
}
}

componentWillUnmount() {
if (this.node && this.props.getScrollPosition) {
const position = this.props.getScrollPosition();
if (position !== null && this.node.offsetTop < position.top) {
requestAnimationFrame(() => {
this.props.updateScrollBottom(position.height - position.top);
});
}
}
}

handleToggleMediaVisibility = () => {
this.setState({ showMedia: !this.state.showMedia });
}
Expand Down Expand Up @@ -178,11 +196,7 @@ class Status extends ImmutablePureComponent {

handleExpandedToggle = () => {
this.props.onToggleHidden(this._properStatus());
}

handleCollapsedToggle = isCollapsed => {
this.props.onToggleCollapsed(this._properStatus(), isCollapsed);
}
};

renderLoadingMediaGallery () {
return <div className='media-gallery' style={{ height: '110px' }} />;
Expand Down Expand Up @@ -452,7 +466,7 @@ class Status extends ImmutablePureComponent {
</a>
</div>

<StatusContent status={status} onClick={this.handleClick} expanded={!status.get('hidden')} onExpandedToggle={this.handleExpandedToggle} collapsable onCollapsedToggle={this.handleCollapsedToggle} />
<StatusContent status={status} onClick={this.handleClick} expanded={!status.get('hidden')} onExpandedToggle={this.handleExpandedToggle} collapsable />

{media}

Expand Down
25 changes: 11 additions & 14 deletions app/javascript/mastodon/components/status_content.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ export default class StatusContent extends React.PureComponent {
onExpandedToggle: PropTypes.func,
onClick: PropTypes.func,
collapsable: PropTypes.bool,
onCollapsedToggle: PropTypes.func,
};

state = {
hidden: true,
collapsed: null, // `collapsed: null` indicates that an element doesn't need collapsing, while `true` or `false` indicates that it does (and is/isn't).
};

_updateStatusLinks () {
Expand Down Expand Up @@ -62,16 +62,14 @@ export default class StatusContent extends React.PureComponent {
link.setAttribute('rel', 'noopener noreferrer');
}

if (this.props.status.get('collapsed', null) === null) {
let collapsed =
this.props.collapsable
&& this.props.onClick
&& node.clientHeight > MAX_HEIGHT
&& this.props.status.get('spoiler_text').length === 0;

if(this.props.onCollapsedToggle) this.props.onCollapsedToggle(collapsed);

this.props.status.set('collapsed', collapsed);
if (
this.props.collapsable
&& this.props.onClick
&& this.state.collapsed === null
&& node.clientHeight > MAX_HEIGHT
&& this.props.status.get('spoiler_text').length === 0
) {
this.setState({ collapsed: true });
}
}

Expand Down Expand Up @@ -180,15 +178,14 @@ export default class StatusContent extends React.PureComponent {
}

const hidden = this.props.onExpandedToggle ? !this.props.expanded : this.state.hidden;
const renderReadMore = this.props.onClick && status.get('collapsed');

const content = { __html: status.get('contentHtml') };
const spoilerContent = { __html: status.get('spoilerHtml') };
const directionStyle = { direction: 'ltr' };
const classNames = classnames('status__content', {
'status__content--with-action': this.props.onClick && this.context.router,
'status__content--with-spoiler': status.get('spoiler_text').length > 0,
'status__content--collapsed': renderReadMore,
'status__content--collapsed': this.state.collapsed === true,
});

if (isRtl(status.get('search_index'))) {
Expand Down Expand Up @@ -240,7 +237,7 @@ export default class StatusContent extends React.PureComponent {
</div>,
];

if (renderReadMore) {
if (this.state.collapsed) {
output.push(readMoreButton);
}

Expand Down
9 changes: 0 additions & 9 deletions app/javascript/mastodon/components/status_list.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ export default class StatusList extends ImmutablePureComponent {
emptyMessage: PropTypes.node,
alwaysPrepend: PropTypes.bool,
timelineId: PropTypes.string,
currentlyViewing: PropTypes.number,
updateCurrentlyViewing: PropTypes.func,
};

static defaultProps = {
Expand Down Expand Up @@ -60,12 +58,6 @@ export default class StatusList extends ImmutablePureComponent {
this.props.onLoadMore(this.props.statusIds.size > 0 ? this.props.statusIds.last() : undefined);
}, 300, { leading: true })

updateCurrentlyViewingWithCache = (id) => {
if(this.cachedCurrentlyViewing === id) return;
this.cachedCurrentlyViewing = id;
this.props.updateCurrentlyViewing(id);
}

_selectChild (index, align_top) {
const container = this.node.node;
const element = container.querySelector(`article:nth-of-type(${index + 1}) .focusable`);
Expand All @@ -87,7 +79,6 @@ export default class StatusList extends ImmutablePureComponent {
render () {
const { statusIds, featuredStatusIds, shouldUpdateScroll, onLoadMore, timelineId, ...other } = this.props;
const { isLoading, isPartial } = other;
other.updateCurrentlyViewing = this.updateCurrentlyViewingWithCache;

if (isPartial) {
return <RegenerationIndicator />;
Expand Down
5 changes: 0 additions & 5 deletions app/javascript/mastodon/containers/status_container.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import {
deleteStatus,
hideStatus,
revealStatus,
toggleStatusCollapse,
} from '../actions/statuses';
import {
unmuteAccount,
Expand Down Expand Up @@ -191,10 +190,6 @@ const mapDispatchToProps = (dispatch, { intl }) => ({
}
},

onToggleCollapsed (status, isCollapsed) {
dispatch(toggleStatusCollapse(status.get('id'), isCollapsed));
},

onBlockDomain (domain) {
dispatch(openModal('CONFIRM', {
message: <FormattedMessage id='confirmations.domain_block.message' defaultMessage='Are you really, really sure you want to block the entire {domain}? In most cases a few targeted blocks or mutes are sufficient and preferable. You will not see content from that domain in any public timelines or your notifications. Your followers from that domain will be removed.' values={{ domain: <strong>{domain}</strong> }} />,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { connect } from 'react-redux';
import StatusList from '../../../components/status_list';
import { scrollTopTimeline, loadPending, updateCurrentlyViewing } from '../../../actions/timelines';
import { scrollTopTimeline, loadPending } from '../../../actions/timelines';
import { Map as ImmutableMap, List as ImmutableList } from 'immutable';
import { createSelector } from 'reselect';
import { debounce } from 'lodash';
Expand Down Expand Up @@ -39,7 +39,6 @@ const makeMapStateToProps = () => {
isPartial: state.getIn(['timelines', timelineId, 'isPartial'], false),
hasMore: state.getIn(['timelines', timelineId, 'hasMore']),
numPending: getPendingStatusIds(state, { type: timelineId }).size,
currentlyViewing: state.getIn(['timelines', timelineId, 'currentlyViewing'], -1),
});

return mapStateToProps;
Expand All @@ -57,7 +56,6 @@ const mapDispatchToProps = (dispatch, { timelineId }) => ({

onLoadPending: () => dispatch(loadPending(timelineId)),

updateCurrentlyViewing: id => dispatch(updateCurrentlyViewing(timelineId, id)),
});

export default connect(makeMapStateToProps, mapDispatchToProps)(StatusList);
3 changes: 0 additions & 3 deletions app/javascript/mastodon/reducers/statuses.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
STATUS_UNMUTE_SUCCESS,
STATUS_REVEAL,
STATUS_HIDE,
STATUS_COLLAPSE,
} from '../actions/statuses';
import { TIMELINE_DELETE } from '../actions/timelines';
import { STATUS_IMPORT, STATUSES_IMPORT } from '../actions/importer';
Expand Down Expand Up @@ -74,8 +73,6 @@ export default function statuses(state = initialState, action) {
}
});
});
case STATUS_COLLAPSE:
return state.setIn([action.id, 'collapsed'], action.isCollapsed);
case TIMELINE_DELETE:
return deleteStatus(state, action.id, action.references);
default:
Expand Down
4 changes: 0 additions & 4 deletions app/javascript/mastodon/reducers/timelines.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
TIMELINE_CONNECT,
TIMELINE_DISCONNECT,
TIMELINE_LOAD_PENDING,
CURRENTLY_VIEWING,
} from '../actions/timelines';
import {
ACCOUNT_BLOCK_SUCCESS,
Expand All @@ -29,7 +28,6 @@ const initialTimeline = ImmutableMap({
hasMore: true,
pendingItems: ImmutableList(),
items: ImmutableList(),
currentlyViewing: -1,
});

const expandNormalizedTimeline = (state, timeline, statuses, next, isPartial, isLoadingRecent, usePendingItems) => {
Expand Down Expand Up @@ -170,8 +168,6 @@ export default function timelines(state = initialState, action) {
initialTimeline,
map => map.set('online', false).update(action.usePendingItems ? 'pendingItems' : 'items', items => items.first() ? items.unshift(null) : items)
);
case CURRENTLY_VIEWING:
return state.update(action.timeline, initialTimeline, map => map.set('currentlyViewing', action.id));
default:
return state;
}
Expand Down

0 comments on commit 1e7b5fb

Please sign in to comment.