Prevent loading spinner flicker on timeline (#895)

<!-- Please read
https://github.com/SableClient/Sable/blob/dev/CONTRIBUTING.md before
submitting your pull request -->

### Description

<!-- Please include a summary of the change. Please also include
relevant motivation and context. List any dependencies that are required
for this change. -->

Fixes the loading spinner resetting every time a chunk of messages loads
in, now, assuming there's still more to load in the current batch, it
should just continue spinning in one animation.

#### Type of change

- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] This change requires a documentation update

### Checklist:

- [ ] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my own code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [ ] My changes generate no new warnings

### AI disclosure:

- [ ] Partially AI assisted (clarify which code was AI assisted and
briefly explain what it does).
- [ ] Fully AI generated (explain what all the generated code does in
moderate detail).
<!-- Write any explanation required here, but do not generate the
explanation using AI!! You must prove you understand what the code in
this PR does. -->
This commit is contained in:
7w1 authored and GitHub committed 2026-05-21 20:48:57 -05:00
commit eebf97bc30
2 files changed
+20 -3

No files matched your search

@@ -0,0 +1,5 @@
---
default: patch
---
Fixed the message loading spinner flickering instead of continuing during large pagination chunks.
+15 -3
View File
@@ -186,18 +186,24 @@ const useTimelinePagination = (
// that countAfter/stillHasToken comparisons are meaningful.
const freshLTimelines = timelineRef.current.linkedTimelines;
const firstTimeline = freshLTimelines[0];
if (!firstTimeline) return;
if (!firstTimeline) {
(backwards ? setBackwardStatus : setForwardStatus)('idle');
return;
}
recalibratePagination(freshLTimelines);
(backwards ? setBackwardStatus : setForwardStatus)('idle');
const countAfter = getTimelinesEventsCount(getLinkedTimelines(firstTimeline));
const fetched = countAfter - countBefore;
let willContinue = false;
if (fetched > 0 && fetched < 5) {
const checkTimeline = backwards
? freshLTimelines[0]
: freshLTimelines[freshLTimelines.length - 1];
if (!checkTimeline) return;
if (!checkTimeline) {
(backwards ? setBackwardStatus : setForwardStatus)('idle');
return;
}
const checkDirection = backwards ? Direction.Backward : Direction.Forward;
const stillHasToken =
typeof getLinkedTimelines(checkTimeline)[0]?.getPaginationToken(checkDirection) ===
@@ -207,12 +213,18 @@ const useTimelinePagination = (
// so the finally block below does NOT reset it after inner claims.
fetchingRef.current[directionKey] = false;
continuing = true;
willContinue = true;
paginate(backwards);
// At this point the inner paginate has synchronously set
// fetchingRef.current[directionKey] = true before hitting its own
// await. The finally below will skip the reset.
}
}
// Stay in 'loading' across auto-continuation chunks so the spinner does not flicker.
if (!willContinue) {
(backwards ? setBackwardStatus : setForwardStatus)('idle');
}
}
} finally {
// Only release the lock if we did NOT hand it to a recursive continuation.