Skip to content

Commit eebf97b

Browse files
authored
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. -->
2 parents 451d9f9 + 6dac5bf commit eebf97b

2 files changed

Lines changed: 20 additions & 3 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
default: patch
3+
---
4+
5+
Fixed the message loading spinner flickering instead of continuing during large pagination chunks.

src/app/hooks/timeline/useTimelineSync.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,18 +186,24 @@ const useTimelinePagination = (
186186
// that countAfter/stillHasToken comparisons are meaningful.
187187
const freshLTimelines = timelineRef.current.linkedTimelines;
188188
const firstTimeline = freshLTimelines[0];
189-
if (!firstTimeline) return;
189+
if (!firstTimeline) {
190+
(backwards ? setBackwardStatus : setForwardStatus)('idle');
191+
return;
192+
}
190193
recalibratePagination(freshLTimelines);
191-
(backwards ? setBackwardStatus : setForwardStatus)('idle');
192194

193195
const countAfter = getTimelinesEventsCount(getLinkedTimelines(firstTimeline));
194196
const fetched = countAfter - countBefore;
195197

198+
let willContinue = false;
196199
if (fetched > 0 && fetched < 5) {
197200
const checkTimeline = backwards
198201
? freshLTimelines[0]
199202
: freshLTimelines[freshLTimelines.length - 1];
200-
if (!checkTimeline) return;
203+
if (!checkTimeline) {
204+
(backwards ? setBackwardStatus : setForwardStatus)('idle');
205+
return;
206+
}
201207
const checkDirection = backwards ? Direction.Backward : Direction.Forward;
202208
const stillHasToken =
203209
typeof getLinkedTimelines(checkTimeline)[0]?.getPaginationToken(checkDirection) ===
@@ -207,12 +213,18 @@ const useTimelinePagination = (
207213
// so the finally block below does NOT reset it after inner claims.
208214
fetchingRef.current[directionKey] = false;
209215
continuing = true;
216+
willContinue = true;
210217
paginate(backwards);
211218
// At this point the inner paginate has synchronously set
212219
// fetchingRef.current[directionKey] = true before hitting its own
213220
// await. The finally below will skip the reset.
214221
}
215222
}
223+
224+
// Stay in 'loading' across auto-continuation chunks so the spinner does not flicker.
225+
if (!willContinue) {
226+
(backwards ? setBackwardStatus : setForwardStatus)('idle');
227+
}
216228
}
217229
} finally {
218230
// Only release the lock if we did NOT hand it to a recursive continuation.

0 commit comments

Comments
 (0)