From 7cd88ae2f489195d4868172e716baf0efc4a5d28 Mon Sep 17 00:00:00 2001 From: Claire Date: Thu, 4 Jan 2024 15:17:38 +0100 Subject: [PATCH] [Glitch] Fix scrolling to detailed status not always working Port d0fd14f851871659834ae600f043d81e352cdc1f to glitch-soc Signed-off-by: Claire --- .../flavours/glitch/features/status/index.jsx | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/app/javascript/flavours/glitch/features/status/index.jsx b/app/javascript/flavours/glitch/features/status/index.jsx index 266c974c4e..605919f670 100644 --- a/app/javascript/flavours/glitch/features/status/index.jsx +++ b/app/javascript/flavours/glitch/features/status/index.jsx @@ -610,7 +610,7 @@ class Status extends ImmutablePureComponent { this.setState({ isExpanded: value }); }; - setRef = c => { + setContainerRef = c => { this.node = c; }; @@ -618,12 +618,16 @@ class Status extends ImmutablePureComponent { this.column = c; }; + setStatusRef = c => { + this.statusNode = c; + }; + _scrollStatusIntoView () { const { status, multiColumn } = this.props; if (status) { - window.requestAnimationFrame(() => { - this.node?.querySelector('.detailed-status__wrapper')?.scrollIntoView(true); + requestIdleCallback(() => { + this.statusNode?.scrollIntoView(true); // In the single-column interface, `scrollIntoView` will put the post behind the header, // so compensate for that. @@ -661,9 +665,8 @@ class Status extends ImmutablePureComponent { } // Scroll to focused post if it is loaded - const child = this.node?.querySelector('.detailed-status__wrapper'); - if (child) { - return [0, child.offsetTop]; + if (this.statusNode) { + return [0, this.statusNode.offsetTop]; } // Do not scroll otherwise, `componentDidUpdate` will take care of that @@ -730,11 +733,11 @@ class Status extends ImmutablePureComponent { /> -
+
{ancestors} -
+