From 4c2aca777f6ae6942d0cf11aee56a925694ccdef Mon Sep 17 00:00:00 2001 From: Claire Date: Mon, 9 Oct 2023 16:46:09 +0200 Subject: [PATCH] Fix clicking on already-loaded thread scrolling to the top of the thread (#27338) --- .../mastodon/features/status/index.jsx | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/app/javascript/mastodon/features/status/index.jsx b/app/javascript/mastodon/features/status/index.jsx index 482323e089..39823268b2 100644 --- a/app/javascript/mastodon/features/status/index.jsx +++ b/app/javascript/mastodon/features/status/index.jsx @@ -220,6 +220,8 @@ class Status extends ImmutablePureComponent { componentDidMount () { attachFullscreenListener(this.onFullScreenChange); + + this._scrollStatusIntoView(); } UNSAFE_componentWillReceiveProps (nextProps) { @@ -579,10 +581,10 @@ class Status extends ImmutablePureComponent { this.node = c; }; - componentDidUpdate (prevProps) { - const { status, ancestorsIds, multiColumn } = this.props; + _scrollStatusIntoView () { + const { status, multiColumn } = this.props; - if (status && (ancestorsIds.size > prevProps.ancestorsIds.size || prevProps.status?.get('id') !== status.get('id'))) { + if (status) { window.requestAnimationFrame(() => { this.node?.querySelector('.detailed-status__wrapper')?.scrollIntoView(true); @@ -599,6 +601,14 @@ class Status extends ImmutablePureComponent { } } + componentDidUpdate (prevProps) { + const { status, ancestorsIds } = this.props; + + if (status && (ancestorsIds.size > prevProps.ancestorsIds.size || prevProps.status?.get('id') !== status.get('id'))) { + this._scrollStatusIntoView(); + } + } + componentWillUnmount () { detachFullscreenListener(this.onFullScreenChange); }