From 5df6036c2c8bda0e2a43ebc7a22bc012fe4a0108 Mon Sep 17 00:00:00 2001 From: dan Date: Tue, 30 Sep 2025 16:46:31 +0100 Subject: [PATCH] [Web] Fix thread jumps (#9111) * [Web] Fix thread jumps * Comment formatting --------- Co-authored-by: Eric Bailey --- src/screens/PostThread/index.tsx | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/screens/PostThread/index.tsx b/src/screens/PostThread/index.tsx index c27f2c322d..1e646e1bbd 100644 --- a/src/screens/PostThread/index.tsx +++ b/src/screens/PostThread/index.tsx @@ -148,7 +148,9 @@ export function PostThread({uri}: {uri: string}) { */ const shouldHandleScroll = useRef(true) /** - * Called any time the content size of the list changes, _just_ before paint. + * Called any time the content size of the list changes. Could be a fresh + * render, items being added to the list, or any resize that changes the + * scrollable size of the content. * * We want this to fire every time we change params (which will reset * `deferParents` via `onLayout` on the anchor post, due to the key change), @@ -193,24 +195,23 @@ export function PostThread({uri}: {uri: string}) { * will give us a _positive_ offset, which will scroll the anchor post * back _up_ to the top of the screen. */ - list.scrollToOffset({ - offset: anchorOffsetTop - headerHeight, - }) + const offset = anchorOffsetTop - headerHeight + list.scrollToOffset({offset}) /* - * After the second pass, `deferParents` will be `false`, and we need - * to ensure this doesn't run again until scroll handling is requested - * again via `shouldHandleScroll.current === true` and a params - * change via `prepareForParamsUpdate`. + * After we manage to do a positive adjustment, we need to ensure this + * doesn't run again until scroll handling is requested again via + * `shouldHandleScroll.current === true` and a params change via + * `prepareForParamsUpdate`. * * The `isRoot` here is needed because if we're looking at the anchor * post, this handler will not fire after `deferParents` is set to * `false`, since there are no parents to render above it. In this case, - * we want to make sure `shouldHandleScroll` is set to `false` so that - * subsequent size changes unrelated to a params change (like pagination) - * do not affect scroll. + * we want to make sure `shouldHandleScroll` is set to `false` right away + * so that subsequent size changes unrelated to a params change (like + * pagination) do not affect scroll. */ - if (!deferParents || isRoot) shouldHandleScroll.current = false + if (offset > 0 || isRoot) shouldHandleScroll.current = false } })