-
-
Notifications
You must be signed in to change notification settings - Fork 144
fix: end-aligned scroll completion — pendingTotalSize deadlock, watchdog bounding, moving-target slack, animated retries #485
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Nodonisko
wants to merge
8
commits into
LegendApp:main
Choose a base branch
from
Nodonisko:fix/end-aligned-scroll-completion
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
709d860
refactor: extract end-aligned scroll target helpers
Nodonisko 96286bf
fix: correct end-aligned scroll position after pendingTotalSize commits
Nodonisko b2c8748
fix: bound the scroll-completion fallback watchdog per session
Nodonisko 26e65ff
fix: complete end-aligned scrolls within slack instead of pixel-chasing
Nodonisko 354abe1
fix: keep end-aligned retries animated for animated scroll sessions
Nodonisko 6454e97
chore: drop unrelated bun.lock drift
Nodonisko d582751
refactor: carry the fallback check count on the scroll session
Nodonisko a7209ae
refactor: unify the end-aligned re-dispatch glide policy
Nodonisko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| import { calculateOffsetForIndex } from "@/core/calculateOffsetForIndex"; | ||
| import { calculateOffsetWithOffsetPosition } from "@/core/calculateOffsetWithOffsetPosition"; | ||
| import { clampScrollOffset } from "@/core/clampScrollOffset"; | ||
| import type { StateContext } from "@/state/state"; | ||
|
|
||
| type ActiveScrollTarget = NonNullable<StateContext["state"]["scrollingTo"]>; | ||
|
|
||
| export function isEndAlignedLastItemTarget(ctx: StateContext, scrollingTo: ActiveScrollTarget) { | ||
| return scrollingTo.index === ctx.state.props.data.length - 1 && scrollingTo.viewPosition === 1; | ||
| } | ||
|
|
||
| export function getCurrentTargetOffset(ctx: StateContext, scrollingTo: ActiveScrollTarget) { | ||
| const index = scrollingTo.index; | ||
| const shouldRecomputeEndTarget = isEndAlignedLastItemTarget(ctx, scrollingTo); | ||
| const requestedTargetOffset = | ||
| shouldRecomputeEndTarget && index !== undefined | ||
| ? calculateOffsetWithOffsetPosition(ctx, calculateOffsetForIndex(ctx, index), scrollingTo) | ||
| : (scrollingTo.targetOffset ?? | ||
| clampScrollOffset(ctx, scrollingTo.offset - (scrollingTo.viewOffset || 0), scrollingTo)); | ||
|
|
||
| return clampScrollOffset(ctx, requestedTargetOffset, scrollingTo); | ||
| } | ||
|
|
||
| export function scrollToFallbackOffset(ctx: StateContext, offset: number) { | ||
| ctx.state.refScroller.current?.scrollTo({ | ||
| animated: false, | ||
| x: ctx.state.props.horizontal ? offset : 0, | ||
| y: ctx.state.props.horizontal ? 0 : offset, | ||
| }); | ||
| } | ||
|
|
||
| // Committing pendingTotalSize in finishScrollTo can grow the content after an | ||
| // end-aligned scroll already settled: while the scroll was active the native | ||
| // container still had the previous committed size, so the dispatched target sat | ||
| // beyond the reachable range and retries could not move past it. Once the | ||
| // committed size lands natively (two frames), re-dispatch a single unanimated | ||
| // correction toward the end. One-shot and end-directed, so it cannot loop or | ||
| // fight the user. | ||
| export function maybeCorrectEndAlignedScrollAfterCommit(ctx: StateContext, scrollingTo: ActiveScrollTarget) { | ||
| const state = ctx.state; | ||
| if (!isEndAlignedLastItemTarget(ctx, scrollingTo)) { | ||
| return; | ||
| } | ||
|
|
||
| requestAnimationFrame(() => { | ||
| requestAnimationFrame(() => { | ||
| if (state.scrollingTo) { | ||
| return; | ||
| } | ||
| const correctedTarget = getCurrentTargetOffset(ctx, scrollingTo); | ||
| if (correctedTarget > state.scroll + 1) { | ||
| scrollToFallbackOffset(ctx, correctedTarget); | ||
| } | ||
| }); | ||
| }); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For horizontal RTL lists on native, the new post-commit correction path passes
correctedTargetas a logical offset directly toscrollTo. The normaldoScrollTopath converts horizontal RTL offsets withtoNativeHorizontalOffset; without that conversion, an inverted/negative RTL scroller can receive the wrong nativexvalue and jump away from the end when this delayed correction fires after an end-aligned scroll.Useful? React with 👍 / 👎.