Skip to content

Commit

Permalink
Fix clicking on already-opened thread post scrolling to the top of th…
Browse files Browse the repository at this point in the history
…e thread (mastodon#27331)
  • Loading branch information
ClearlyClaire authored and vmstan committed Jan 5, 2024
1 parent 53b2967 commit dd48c4d
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion app/javascript/mastodon/features/status/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,22 @@ class Status extends ImmutablePureComponent {
this.setState({ fullscreen: isFullscreen() });
};

shouldUpdateScroll = (prevRouterProps, { location }) => {
// Do not change scroll when opening a modal
if (location.state?.mastodonModalKey && location.state?.mastodonModalKey !== prevRouterProps?.location?.state?.mastodonModalKey) {
return false;
}

// Scroll to focused post if it is loaded
const child = this.node?.querySelector('.detailed-status__wrapper');
if (child) {
return [0, child.offsetTop];
}

// Do not scroll otherwise, `componentDidUpdate` will take care of that
return false;
};

render () {
let ancestors, descendants;
const { isLoading, status, ancestorsIds, descendantsIds, intl, domain, multiColumn, pictureInPicture } = this.props;
Expand Down Expand Up @@ -660,7 +676,7 @@ class Status extends ImmutablePureComponent {
)}
/>

<ScrollContainer scrollKey='thread'>
<ScrollContainer scrollKey='thread' shouldUpdateScroll={this.shouldUpdateScroll}>
<div className={classNames('scrollable', { fullscreen })} ref={this.setRef}>
{ancestors}

Expand Down

0 comments on commit dd48c4d

Please sign in to comment.