Compare commits

...

2 Commits

Author SHA1 Message Date
Eric Bailey 7bd25047d2 Comment formatting 2025-09-30 10:36:47 -05:00
Dan Abramov fef6b968c1 [Web] Fix thread jumps 2025-09-30 02:31:00 +01:00
+13 -12
View File
@@ -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
}
})