Skip to content

fix(core): Fix backwards pagination not working if channel was never opened#2789

Draft
VelikovPetar wants to merge 2 commits into
masterfrom
bug/FLU-547_fix_pagination_on_unread_channels
Draft

fix(core): Fix backwards pagination not working if channel was never opened#2789
VelikovPetar wants to merge 2 commits into
masterfrom
bug/FLU-547_fix_pagination_on_unread_channels

Conversation

@VelikovPetar

Copy link
Copy Markdown
Contributor

Submit a pull request

Linear: FLU-547

Github Issue: #

CLA

  • I have signed the Stream CLA (required).
  • The code changes follow best practices
  • Code changes are tested (add some information if not applicable)

Description of the pull request

When a user enters a channel with unread_count > 0 but the server-side read state has last_read_message_id = null and last_read = 0001-01-01T00:00:00Z (Go's time.Time{} zero value — the "never explicitly read" sentinel), StreamChannel._maybeInitChannel was unconditionally calling loadChannelAtTimestamp(currentUserRead.lastRead).

The backend silently ignores zero-time created_at_around (via IsZero()) and returns the channel tail. The client then mis-infers boundaries via _inferBoundariesFromAnchorTimestamp: because year-1 is before every loaded message, it concludes endOfPrependReached: true, sets _topPaginationEnded = true, and backwards pagination is permanently dead on the channel.

The fix guards the timestamp branch on lastRead.toUtc().isAfter(DateTime.utc(1970, 1, 1)). When it's the zero sentinel, the code falls through to the existing catch-all if (channel.state?.isUpToDate == false) loadChannelAtMessage(null) — i.e. stay on cached latest if up-to-date, otherwise reload latest.

Adds a _maybeInitChannel test group with three regression guards: idAround for lastReadMessageId, createdAtAround for real timestamps, and no query for the Go zero-time case.

Screenshots / Videos

Before After
pagin-before.mp4
pagin-after.mp4

@coderabbitai

coderabbitai Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 6abea6e9-783f-4a6d-9e44-753591181fc8

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch bug/FLU-547_fix_pagination_on_unread_channels

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant