From 05159d2f94b141a95afc6401e19d03b3d49e2c37 Mon Sep 17 00:00:00 2001 From: Claire Date: Mon, 9 Oct 2023 16:46:09 +0200 Subject: [PATCH] [Glitch] Fix clicking on already-loaded thread scrolling to the top of the thread Port 4c2aca777f6ae6942d0cf11aee56a925694ccdef to glitch-soc Signed-off-by: Claire --- .../flavours/glitch/features/status/index.jsx | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/app/javascript/flavours/glitch/features/status/index.jsx b/app/javascript/flavours/glitch/features/status/index.jsx index c8bb2c255..598f30a1f 100644 --- a/app/javascript/flavours/glitch/features/status/index.jsx +++ b/app/javascript/flavours/glitch/features/status/index.jsx @@ -217,6 +217,7 @@ class Status extends ImmutablePureComponent { componentDidMount () { attachFullscreenListener(this.onFullScreenChange); this.props.dispatch(fetchStatus(this.props.params.statusId)); + this._scrollStatusIntoView(); } static getDerivedStateFromProps(props, state) { @@ -614,10 +615,10 @@ class Status extends ImmutablePureComponent { this.column = 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); @@ -634,6 +635,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); }