
Boost ops efficiency, drive revenue, & save big with omnichannel messaging
Virtualize React Chat History with the Sendbird Chat SDK



Boost ops efficiency, drive revenue, & save big with omnichannel messaging

Boost ops efficiency, drive revenue, & save big with omnichannel messaging
This recipe loads earlier messages in a React chat with a custom message list and keeps the reader on the same message as history loads.
Load earlier messages. Use the Sendbird Chat SDK’s
MessageCollectionto load earlier group-channel messages.Keep the reading position. Deduplicate messages by ID, then prepend the new rows and decrease React Virtuoso’s
firstItemIndexby the number of rows added in the same state update.
Local Chromium tests verified scroll position at desktop and narrow viewport widths using synthetic data. Pagination and scroll position in a connected Sendbird app still need to be verified.
Load an older page and update the virtual list
UIKit’s GroupChannel already includes a standard list. If your app renders its own rows, add this pattern to your existing React view.
The three snippets below are condensed. See collection.ts and history-view.tsx for the full code.
Initialize the message collection
Create the collection from the signed-in user’s group channel. Initialize it and show cached messages if available. When the initial API request succeeds, set the rows from the API result and read collection.hasPrevious to update the Load older messages button.
import { MessageCollectionInitPolicy, MessageFilter } from '@sendbird/chat/groupChannel';
const collection = channel.createMessageCollection({
filter: new MessageFilter(),
startingPoint: Date.now(),
prevResultLimit: 20,
});
collection.initialize(MessageCollectionInitPolicy.CACHE_AND_REPLACE_BY_API)
.onCacheResult(onCachedPage)
.onApiResult(onFirstPage);Load the previous page
In the Load older messages handler, check collection.hasPrevious before calling loadPrevious(). The handler runs after the initial page has loaded.
const older = collection.hasPrevious ? await collection.loadPrevious() : [];Prepend new rows and preserve the reading position
Keep one older-page request in flight. Sort by timestamp and ID, remove overlapping IDs, then prepend only the distinct earlier rows. Start firstItemIndex high enough to stay positive as history is prepended. The sample starts at 100_000. Update it in the same state change as the rows, subtracting only the number actually inserted. Use a bounded list height and key each row by its message ID, so the same row keeps its key when older messages are inserted.
<Virtuoso
data={rows}
firstItemIndex={firstItemIndex}
computeItemKey={(_, row) => row.id}
itemContent={(_, row) => <MessageRow message={row} />}
style={{ height: 480 }}
/>Dispose of the collection when the view closes or switches channels. Sendbird message collection · Virtuoso prepend example
Verify that the same row stays in view
Use Node.js 20.19 or a later 20.x release, or Node.js 22.12 or later. Run these commands from the chat-history-virtualization sample folder.
npm ci
npm run devOpen the local URL printed by Vite. The demo starts with 1,000 synthetic messages and runs without a Sendbird account or credentials. Select Jump to latest, then scroll up to an earlier message. Select Load older messages and check that the same message stays in place as the count rises to 1,020. Load one more page to reach 1,040. Each fixture page contains 20 earlier text messages and one overlapping ID.
The standalone sample uses React 19.3.1, Sendbird Chat SDK 4.22.17, and React Virtuoso 2.19.1. The original fixture capture used Node 26.12.1 and npm 11.20.0. Run npm run build, npm run browser:install, and npm run smoke from the standalone sample to check the production build in Chromium.


In a local production build tested in Chromium with synthetic text messages, the first prepend raised the loaded count from 1,000 to 1,020. Once scrolling settled, the same message was at the same vertical position, with 0 px of movement at viewport widths of 1280 px and 390 px. In a separate check after Jump to latest, the browser mounted 8 of the 1,000 loaded rows at each width. These results describe the measured positions and DOM row counts in that fixture.
In the revised standalone sample, add ?simulate-load-errors to the local URL to reproduce an initial-load failure and a rejected older-page request. Retry loading history recreates the collection after the initial failure. After the older-page failure, the existing rows remain visible and Load older messages retries the request.
| Requirement | How it was checked | Observed result | Checked by |
|---|---|---|---|
| Prepend only distinct earlier rows | Prepend a synthetic page containing 20 earlier messages and one overlapping ID | Loaded rows rise from 1,000 to 1,020 and the same row stays at the same vertical position. | Chromium at 1280 px and 390 px |
| Keep the list bounded | Count mounted text rows after jumping to the latest message | 8 rows are mounted out of 1,000 loaded at each viewport. | Chromium at both widths |
| Clean up the collection | Close and reopen the history view | The collection is disposed and the fixture loads again. | Chromium at both widths |
| Recover from simulated load errors | Run the standalone smoke test, which opens ?simulate-load-errors | Retry restores 1,000 initial rows. A failed older-page request keeps those rows visible, and its retry raises the count to 1,020. | Production-build Chromium smoke test at both widths |
Optional agent setup for Claude Code or Codex
Use the Sendbird Client Plugin if you want a coding agent to help adapt the history view to your existing React app. Add the Sendbird CLI plugin if you want the agent to run CLI checks against a connected test app.
claude plugin marketplace add sendbird/sendbird-plugins
claude plugin install sendbird-cli@sendbird
claude plugin install sendbird-client@sendbirdcodex plugin marketplace add sendbird/sendbird-plugins
codex plugin add sendbird-cli@sendbird
codex plugin add sendbird-client@sendbirdFind the official Sendbird plugins for Claude Code and Codex in the Sendbird Plugin Marketplace on GitHub.
Start a new coding-agent session after installation. For connected checks with the CLI plugin, follow its setup guide to sign in and select your test app. The Sendbird CLI and Plugins overview explains what each tool does.
The Sendbird Client Plugin guide explains how to run skills in your existing app.
Ask Claude Code to preserve the reading position
In my existing React chat, use the public Sendbird Chat SDK to load earlier
group-channel messages. Keep our app's message rows and add React Virtuoso
for rendering. Deduplicate overlapping pages by message ID. When an older
page is prepended, preserve the position of the same visible message.
Verify it in a local fixture at desktop and narrow widths. Report the
loaded and mounted counts separately, and list the connected checks
that still need a Sendbird test app.If you are choosing between UIKit and an app-owned list, start with /sendbird-client:choose-ui to compare the two approaches. The read-only setup check loaded Sendbird Client Plugin 1.0.7 and the Sendbird CLI plugin 0.6.1 in a fresh Claude Code session and identified the fixture entry point. This suggested prompt was not used to produce the sample.
Verify paging in an authorized test channel
Use a group channel in an authorized test app with at least 60 synthetic text messages, plus file and admin messages.
Install Sendbird CLI (@sendbird/cli) from npm. Sendbird CLI 0.6.1 requires Node.js 22.23.4 or later in the 22.x line, or 24.22.1 or later in the 24.x line. The sample’s own Node requirements are listed in the local setup above. Follow the sign-in steps in the Sendbird CLI Quickstart. Use a test user who belongs to the group channel and already has a valid Sendbird access token. Set the command variables for that test app. Use --before to read up to 20 messages created strictly before the oldest loaded message’s timestamp, in milliseconds. The lookup excludes messages created in the same millisecond. The app loads its previous page separately through MessageCollection.loadPrevious().
sendbird --json chat message list --type group \
--app-id "$TEST_APP_ID" --id "$TEST_CHANNEL_URL" --before "$FIRST_LOADED_CREATED_AT_MS" \
--limit 20 --as-user "$TEST_CHAT_USER"Use the CLI response to spot-check earlier message IDs and timestamps. The exclusive CLI timestamp lookup and the SDK page can select different rows. We checked the command against @sendbird/cli 0.6.1 metadata without running it against a live app. In the authenticated React view, load successive pages and verify chronological order, deduplication, and the position of the same visible message after each prepend. Confirm that the view skips file and admin messages. Live Sendbird pagination and offline behavior still need to be verified in that test app.
For a live conversation, register a message collection handler for additions, edits, and deletions, and handle recovery when the SDK detects a large gap. Check variable-height rows and keyboard navigation in your own app.
The local failure test simulates a rejected request. In Sendbird Chat SDK 4.22.17, loadPrevious() can resolve with cached messages or an empty page after a server request fails. Check how your connected app handles that result, including an empty page when hasPrevious is still true.
CLI message list · SDK pagination
Your app still owns authentication, server-side token issuance and channel membership. Keep those in your existing service.








