···148 */
149 const shouldHandleScroll = useRef(true)
150 /**
151- * Called any time the content size of the list changes, _just_ before paint.
00152 *
153 * We want this to fire every time we change params (which will reset
154 * `deferParents` via `onLayout` on the anchor post, due to the key change),
···193 * will give us a _positive_ offset, which will scroll the anchor post
194 * back _up_ to the top of the screen.
195 */
196- list.scrollToOffset({
197- offset: anchorOffsetTop - headerHeight,
198- })
199200 /*
201- * After the second pass, `deferParents` will be `false`, and we need
202- * to ensure this doesn't run again until scroll handling is requested
203- * again via `shouldHandleScroll.current === true` and a params
204- * change via `prepareForParamsUpdate`.
205 *
206 * The `isRoot` here is needed because if we're looking at the anchor
207 * post, this handler will not fire after `deferParents` is set to
208 * `false`, since there are no parents to render above it. In this case,
209- * we want to make sure `shouldHandleScroll` is set to `false` so that
210- * subsequent size changes unrelated to a params change (like pagination)
211- * do not affect scroll.
212 */
213- if (!deferParents || isRoot) shouldHandleScroll.current = false
214 }
215 })
216
···148 */
149 const shouldHandleScroll = useRef(true)
150 /**
151+ * Called any time the content size of the list changes. Could be a fresh
152+ * render, items being added to the list, or any resize that changes the
153+ * scrollable size of the content.
154 *
155 * We want this to fire every time we change params (which will reset
156 * `deferParents` via `onLayout` on the anchor post, due to the key change),
···195 * will give us a _positive_ offset, which will scroll the anchor post
196 * back _up_ to the top of the screen.
197 */
198+ const offset = anchorOffsetTop - headerHeight
199+ list.scrollToOffset({offset})
0200201 /*
202+ * After we manage to do a positive adjustment, we need to ensure this
203+ * doesn't run again until scroll handling is requested again via
204+ * `shouldHandleScroll.current === true` and a params change via
205+ * `prepareForParamsUpdate`.
206 *
207 * The `isRoot` here is needed because if we're looking at the anchor
208 * post, this handler will not fire after `deferParents` is set to
209 * `false`, since there are no parents to render above it. In this case,
210+ * we want to make sure `shouldHandleScroll` is set to `false` right away
211+ * so that subsequent size changes unrelated to a params change (like
212+ * pagination) do not affect scroll.
213 */
214+ if (offset > 0 || isRoot) shouldHandleScroll.current = false
215 }
216 })
217