fix(paginator): correct windows filled by hydration rather than by a query - #1860
Merged
MartinCupela merged 2 commits intoSep 10, 2026
Merged
Conversation
… items Server data reaches a window without a query on two paths: a seeded page (`setItems`) and a hydrate (`mergeNewestPage`, which `Thread.reload()` uses). `setItems` records the query shape that window corresponds to; the hydrate did not, so `_lastQueryShape` stayed undefined and `shouldResetStateBeforeQuery` read the next pagination as a shape CHANGE rather than a continuation. `executeQuery` then took its first-page branch and published `getStateBeforeFirstQuery()` — items `undefined` — before issuing the request. A response carrying items rebuilds the window from the surviving intervals, so that case only churns. An empty one has nothing to rebuild from: scrolling to the top of a thread whose replies are all loaded emptied the list. Extracts the shape recording `setItems` already did into `recordLoadedWindowQueryShape()` and calls it from the hydrate path too. The hydrate body returns early in several places, so the public `mergeNewestPage` is now a wrapper around the implementation and records on every exit. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…f trying to merge them into a list that doesn't exist
MartinCupela
requested review from
isekovanic,
oliverlaz,
santhoshvai,
szuperaz and
vishalnarkhede
as code owners
September 10, 2026 11:53
oliverlaz
approved these changes
Sep 10, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
Two defects with one root cause: a paginator window can be filled either by a query or by hydration (
setItems,mergeNewestPage), and the second path was mishandled in two different ways. Thread replies hit both, becauseThread.reload()— the only public method that fetches replies — hydrates.1. The first hydrate dropped its replies
A thread built from a message (rather than from
queryThreads) has never held a reply window.Thread.reload()fetches replies viaGET /threads/:id?reply_limit=50and hands them tomergeNewestPage, which deliberately no-ops in that state — it merges a newest page into an anchored head and leaves seeding to the query path:So the replies arrived and were discarded, leaving
itemsundefined.This went unnoticed because the message list separately issued
GET /messages/:id/replies, which seeded the window throughpostQueryReconcile. The thread request looked redundant while the reply request was the one doing the work. It surfaced when the React SDK suppressed that second request.Fix:
hydrateStateseeds when there is no window and merges when there is, reusing thesetItemscall the constructor already makes for a thread response'slatest_replies. Completeness is judged against the parent message'sreply_count(which includes soft-deleted replies) rather than the payload's top-level count (which does not).2. A hydrated window lost itself on the next pagination
setItemsrecords the query shape its window corresponds to;mergeNewestPagedid not. With_lastQueryShapeleft undefined,shouldResetStateBeforeQueryreads the next pagination as a shape change rather than a continuation, soexecuteQuerytakes its first-page branch and publishesgetStateBeforeFirstQuery()—items: undefined— before issuing the request.A response carrying items rebuilds the window from the surviving intervals, so that case only churns. An empty response has nothing to rebuild from: scrolling to the top of a thread whose replies are all loaded emptied the list.
Fix: the shape recording in
setItemsis extracted torecordLoadedWindowQueryShape()and called from the hydrate path too.mergeNewestPagereturns early in several places, so the public method is now a wrapper around the implementation and records on every exit.Scope
Not thread-specific. Any window filled by hydration is affected — a channel's messages restored after reconnect, then scrolled to the first message, hits defect 2 by the same mechanism. Threads are simply where both were found.
Tests
threads.test.ts— hydrating a thread built fromchannel + parentMessageseeds the replies and reports nothing older to fetch. Fails without the fix.MessagePaginator.test.ts— a hydrated window survives a continuation that returns no items. Fails without the fix.MessagePaginator.test.ts— a hydrated window paginates correctly when the continuation does return items. Passes before and after; included so the half that already worked can't be broken while fixing the other.Full unit suite passes.
Note for the React SDK
stream-chat-reacthas a companion change that stops the message list issuingGET /messages/:id/replieson thread open. That change depends on this one: without the seeding fix, suppressing the reply query leaves the thread panel empty. This should land and release first.