[Web] Fix thread jumps (#9111)

* [Web] Fix thread jumps

* Comment formatting

---------

Co-authored-by: Eric Bailey <git@esb.lol>
This commit is contained in:
dan
2025-09-30 16:46:31 +01:00
committed by GitHub
parent 3e55e52858
commit 5df6036c2c
+13 -12
View File
@@ -148,7 +148,9 @@ export function PostThread({uri}: {uri: string}) {
*/ */
const shouldHandleScroll = useRef(true) 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 * 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), * `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 * will give us a _positive_ offset, which will scroll the anchor post
* back _up_ to the top of the screen. * back _up_ to the top of the screen.
*/ */
list.scrollToOffset({ const offset = anchorOffsetTop - headerHeight
offset: anchorOffsetTop - headerHeight, list.scrollToOffset({offset})
})
/* /*
* After the second pass, `deferParents` will be `false`, and we need * After we manage to do a positive adjustment, we need to ensure this
* to ensure this doesn't run again until scroll handling is requested * doesn't run again until scroll handling is requested again via
* again via `shouldHandleScroll.current === true` and a params * `shouldHandleScroll.current === true` and a params change via
* change via `prepareForParamsUpdate`. * `prepareForParamsUpdate`.
* *
* The `isRoot` here is needed because if we're looking at the anchor * The `isRoot` here is needed because if we're looking at the anchor
* post, this handler will not fire after `deferParents` is set to * post, this handler will not fire after `deferParents` is set to
* `false`, since there are no parents to render above it. In this case, * `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 * we want to make sure `shouldHandleScroll` is set to `false` right away
* subsequent size changes unrelated to a params change (like pagination) * so that subsequent size changes unrelated to a params change (like
* do not affect scroll. * pagination) do not affect scroll.
*/ */
if (!deferParents || isRoot) shouldHandleScroll.current = false if (offset > 0 || isRoot) shouldHandleScroll.current = false
} }
}) })