Skip to content

Refetch a feed's loaded data when the WebSocket reconnects - #253

Draft
gpunto wants to merge 3 commits into
developfrom
refetch-on-reconnect
Draft

gpunto wants to merge 3 commits into
developfrom
refetch-on-reconnect

Conversation

@gpunto

@gpunto gpunto commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Goal

Events sent while the WebSocket is down are never delivered, so loaded state can be out of date after a reconnection. Until now the SDK only watched feeds again. This PR makes a Feed load its data again, and adds the pieces the other state objects will use for the same.

It is the first of three PRs for parity with Swift (stream-feeds-swift#89). The paginated lists and Activity follow.

Closes AND-2060

Implementation

  • ReconnectionRefetchHandler keeps the registered state objects weakly and refetches them all when the connection comes back with a new connection id. A newer reconnection cancels a refetch that is still running, and one object failing does not stop the others.
  • refetchPages loads pages from the start, with the query's own limit, until they cover the number of loaded items. It stops early when a page adds nothing new.
  • PaginatedRefetchable is what a state object with a paginated list implements: its loaded count, how to fetch a page and how to apply the result. The loop is shared. It has the shape of StateRefetching in Swift, and the lists will use it in the next PR.
  • Feed refetches its feed data, followers, following, pinned activities and activities, and the follow requests if they were loaded. Activities are replaced once all their pages are loaded. Aggregated activities count as loaded items too.
  • FeedsConfig.refetchOnReconnect (default true) turns it off.

Good to know:

  • The refetch starts at the top of the feed, also after queryActivitiesAround. Swift does the same.
  • Members are left out of the feed refetch. The member list will refetch itself in the next PR, so until then members are not refreshed.
  • A watched feed is requested once on reconnection. The first page of its refetch also watches it again, with the retries and the error reporting of FeedWatchHandler, and the handler skips that feed. The handler still watches again on its own when the refetch is turned off, on the first connection, and for watched feeds that are not loaded. iOS and Flutter also send a single request here.
  • After stopWatching, the refetch no longer watches the feed again.

Testing

Unit tests cover the handler (first connection, reconnection, failures, cancellation, disabled), the paging loop, the feed refetch, and the watch handler skipping feeds that the refetch watches again.

On an emulator with the sample app: log in, send the app to the background and bring it back. The log shows Refetching 5 state objects after reconnection followed by the feed requests on the new connection.

The emulator run was done before the watch and the refetch were folded into one request, and was not repeated after.

Not checked on a device: a change made by another user while disconnected showing up after the refetch.

Checklist

  • Issue linked (if any)
  • Tests/docs updated
  • I have signed the Stream CLA (required for external contributors)

@gpunto gpunto added the pr:new-feature New feature label Nov 26, 2026
@github-actions

Copy link
Copy Markdown
Contributor

SDK Size Comparison 📏

SDK Before After Difference Status
stream-feeds-android-client 3.12 MB 3.13 MB 0.01 MB 🟢

@github-actions

Copy link
Copy Markdown
Contributor

PR checklist ✅

All required conditions are satisfied:

  • Title length is OK (or ignored by label).
  • At least one pr: label exists.
  • Sections ### Goal, ### Implementation, and ### Testing are filled, or the PR is bot-authored.
  • An issue is linked (Linear ticket or GitHub issue), or the PR is bot-authored.

🎉 Great job! This PR is ready for review.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr:new-feature New feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant