Skip to main content
With offline support turned on, the React UI Kit keeps working when the network drops. Chats and messages the user has already opened load from a cache on the device at once, messages sent while offline wait in a queue and go out when the connection returns, and every list says plainly when something needs a connection. The UI Kit builds on offline support in the JavaScript SDK. You turn it on once in UIKitSettings; the components handle the rest.

Overview

Works offline
  • Conversations, users, groups, group members, messages, reactions, notifications, and pinned and saved messages the user has already loaded appear straight away from the cache.
  • Text messages, stickers and custom messages the user sends are queued and sent automatically on reconnect.
  • Media that was downloaded while online is shown from the device.
  • Attachments (images, video, audio, files and voice notes) picked while offline are queued with the message and uploaded on reconnect, as long as the file fits in the media cache budget. A file that does not fit is refused at once with “File too large to send offline”.
  • When the connection returns, the SDK catches up on what was missed and the lists update in place.
Needs a connection
  • Anything the user has never opened while online, for example the first load of a chat or a list.
  • Keyword search with no saved match, and keyword search in the Search component.
  • Edits, deletes, reactions and other actions on messages that are already sent. They are not queued. (Retry and Delete on a message that is not sent yet work offline.)
  • Calls, call logs, message information and AI features such as streamed replies.

Requirements

The UI Kit’s peer dependency on the Chat SDK stays ^4.2.0, so upgrading the UI Kit does not force an SDK upgrade. On an SDK older than 4.3.1, setOfflineConfig() has no effect and the UI Kit works online as before. Install 4.3.1 or later to use offline support:
Offline support is for UI Kit v7 only. UI Kit v6 and earlier have no offline UI, and turning on the SDK’s offline support with them is not supported. For the browsers and storage the SDK uses for its cache, see Supported runtimes.

Enable Offline Support

Offline support is off by default. Call setOfflineConfig() on the UIKitSettingsBuilder before CometChatUIKit.init(), and set enabled: true.
src/main.tsx
The UI Kit passes the object to the SDK’s AppSettingsBuilder.setOfflineConfig() unchanged. Its type, CometChatOfflineConfig, is exported from @cometchat/chat-uikit-react and lists the same keys as the SDK’s OfflineConfig, so a misspelled key is a compile error. For what each key does and its default (cache size, outbox size, media caching, encryption and so on), see OfflineConfig options.
Offline turns on only for an explicit enabled: true. If you don’t call setOfflineConfig(), or pass a config without enabled: true, the UI Kit behaves exactly as it does today.
Whether offline support is actually running can change after init. For example, it is off before anyone logs in, and when the encrypted cache cannot open. To check it in your own code, call CometChat.isOfflineEnabled() at the moment you need the answer rather than reading back the config you passed. See Verify it is active.

How the Components Behave Offline

Lists

Conversations, Users, Groups, Group Members, Reaction List, Notification Feed, Pinned Messages and Saved Messages all load in two steps:
  1. The saved rows paint first, from the cache.
  2. The server’s page then replaces them in place when it arrives.
When a load can’t reach the server: Pinned Messages and Saved Messages have no onError prop; the onError column applies to the other lists. A list opened with only a filter (for example online users only, tags, or a request builder with no keyword) is a plain list, not a search. Offline with nothing saved, it says “Connect to load …”, never “Connect to search”. While the Reaction List shows “Connect to load reactions”, its tabs still show the message’s own counts (“All” and one tab per emoji). The reactors fill in once the list can load. If you pass your own errorView (or emptyView for a keyword search), your view is shown instead of the offline state. See Customization. The Search component needs a connection for keyword search:
  • Offline, with nothing shown, a keyword search shows “Connect to search” and “Search needs an internet connection.”
  • A search by filter alone is answered from the device. With nothing saved it shows the plain “No results” state, with no onError.
  • When both conversation and message results fail and at least one failure is a real error (not a lost connection), the error view shows and onError is called.

Message list and threads

  • A chat opens with its cached messages, then the server’s page merges in.
  • A chat opened offline with nothing saved shows “Connect to load messages”. It is read again once when the connection returns.
  • At an edge the cache can’t fill (older history, or newer messages after jumping to a message), the list shows a “Connect to load more” row. The row is a button, and it also loads by itself once when the connection returns.
  • Jumping to a message (from a search result, a quoted reply or the first unread message) works offline when that message is saved. If it isn’t, a jump inside an open chat leaves the messages on screen as they are; only an error other than a lost connection calls onError. A chat that opens at a message that isn’t saved opens on its newest saved messages instead.
  • After a long outage the catch-up may bring more than a page of new messages. While the user is reading older messages, a Jump to latest button appears instead of moving the list.
The default message list asks the server for pages in the form the SDK caches, then applies its message types, categories and hide-deleted setting on the device. If you pass your own messagesRequestBuilder, it is sent as you built it, and its pages are cached only when hideReplies is its only content filter.

Composer and sending

  • A message sent while offline appears in the list at once with a clock icon and the label “Not sent yet”. It is sent automatically when the connection returns, and its receipt then updates as usual.
  • A message that fails shows an error mark and a Not sent. Tap to retry button under the bubble. The failed state survives a page reload.
  • The message menu of an unsent or failed message offers only Retry and Delete. Actions that need a server copy (reply, edit, react and so on) are hidden until it is sent. Delete removes the message from this device. It is hidden when hideDeleteMessageOption is set. If the device no longer holds the message (for example after the user left the group), Retry and Delete remove it from the list. If it was in fact already sent, Retry leaves the row as it is, and Delete deletes the sent message as usual, which needs a connection.
  • Retry or Delete on a message whose send is already under way changes nothing and shows “Sending… try again in a moment”.
  • If the outbox is full, the send is refused and the list shows “Too many messages waiting to send”. Some sends are refused while offline with “File too large to send offline”. See Queue limits.
  • Stickers and the group call message are queued like any other send.

Media

With media caching on (the SDK default), images, videos, audio and files that were downloaded while online are shown from the device. A media bubble whose file is not saved shows “Available when online” while the device is offline. Tapping it asks the SDK to download the file, and the bubble updates once it is saved. See Media Caching.

Edits, deletes and reactions

These are not queued. They are sent as soon as the user acts, and they fail if there is no connection:
  • Reactions show at once, then roll back and call the message list’s onError if the request fails.
  • Deleting a sent message calls onError if it fails, and the message stays.
  • Editing a message: the composer clears and leaves edit mode when the user sends the edit. If the edit fails, the message keeps its old text and the message composer’s onError is called.
See Edits, Deletes, and Reactions Need a Connection.

Presence

While the SDK is disconnected, nobody shows as online: there is no online dot in any list or header, the header of a one-to-one chat shows no “Online” subtitle, and the header of a one-to-one or group chat shows no typing indicator. Screen readers are told the same. Presence comes back after the reconnect.

Logout, user switch and cache reset

The cache is per user. A logout or a switch to another user clears every list on screen, and the SDK deletes that user’s cached data and queued messages. If the SDK has to wipe and rebuild its cache (for example when the encryption key is lost), every mounted list reloads. If unsent messages were lost, a notice such as “2 unsent messages couldn’t be recovered” appears once, in the Conversations list or the open Message List. See When the cache resets.

Offline States and Texts

Override any of them with custom translations. Count texts have plural forms: the UI Kit picks <key>_one, <key>_other (and <key>_few / <key>_many where a language needs them) for the current language, and replaces {{count}} with the number.

Errors and Callbacks

onError

  • Rows on screen: offline, a failed load is silent (no error view, no onError). A real error calls onError once when the user or your app started the load (opening the list, refreshing, searching, paging), and stays silent when the UI Kit started it (reconnect, coming back to the foreground, sync).
  • Nothing on screen: see the Lists table.
  • Actions: a failed reaction, delete or edit calls onError, as above.

Send promises

CometChatUIKit.sendTextMessage(), sendMediaMessage() and sendCustomMessage() answer every send:
  • Queueing a message does not reject the promise. It resolves when the message is sent, and rejects once if the message fails or is removed before it is sent. A later Retry does not answer the same promise again.
  • Any removal of the message before it is sent rejects the promise with an error whose code is ERROR_OFFLINE_MESSAGE_DISCARDED. That covers a logout or user switch, a cache reset that lost (or may have lost) unsent messages, the user’s own Delete, and the outbox discarding the message or dropping it on overflow. The reason behind the removal is never the rejection’s code, so check err.code === "ERROR_OFFLINE_MESSAGE_DISCARDED" to tell a removal from a failure. The error carries the removed message as sentMessage.
  • A send that fails rejects with the SDK’s own error, or with an Error whose code is the failure reason. A send that is refused before it is queued also rejects: with the code ERROR_PENDING_QUEUE_LIMIT when the outbox is already full (details.maxPendingMessages holds the cap), or BYTE_OVERFLOW when a media file does not fit in the media cache budget.
  • The UI Kit shows nothing for an ERROR_OFFLINE_MESSAGE_DISCARDED rejection: no error toast, no onError, and the composer does not lock. Only your own .catch hears of it.
With offline off, these methods behave as before.

Events

Two UI events are added to the event system. Both fire only with offline support on. ui:message/sent keeps its meaning and still fires for each send.
These events are new members of the exported CometChatEvent union. If your TypeScript code has an exhaustive switch on event.type with no default, add one.

Customization

Hide the offline notices

Use your own offline view

The lists show your own errorView instead of “Connect to load …”, and your own emptyView instead of “Connect to search”. To tell the offline state apart inside your view, read connectToLoad or connectToSearch from the component’s context hook. They are true only while the offline state is shown, and never set with offline off. The Search component’s context does not expose these flags.

Style the offline UI

Each variable falls back to the UI Kit’s current theme value, so set only what you want to change. See Theming.

With Offline Support Turned Off

Apps that don’t call setOfflineConfig() get no offline UI, no offline events and no change to how sends work. A few behaviour changes in the same release apply to every app:
  • A message list that is empty when the connection returns loads again and shows its empty state.
  • On reconnect, a list whose newest message is still unsent fetches the messages missed during the outage.
  • Paging past a conversation that just received a message shows it once.
  • A messagesRequestBuilder you pass to CometChatMessageList or CometChatSavedMessages is no longer modified.
  • Saved Messages rows are no longer announced to screen readers as selectable options.
  • Message rows, conversation rows, notices, the composer input and the empty and error views carry new data-cc attributes for test automation. Existing data-testid and data-message-id attributes are kept, but DOM snapshot tests may change.

Limitations

  • Only what was loaded online is saved. A user who has never opened a chat or list while online has nothing to show offline.
  • Edits, deletes and reactions are not queued. They need a connection when the user makes them.
  • Need a connection: keyword search with no saved match, keyword search in the Search component, message information, call logs and AI streamed replies. Call logs have no saved copy and keep their own error view.
  • Encryption in the browser covers the cached content but not its lookup metadata, and downloaded media is stored unencrypted. See Encrypt the Cache.

Next Steps

SDK Offline Support

How the cache, outbox and catch-up sync work

Configuration & API Reference

Every OfflineConfig option, listener and error code

Send While Offline

Queued sends, retry, discard and queue limits

Event System

Subscribe to UI Kit events with useCometChatEvents

Localization

Override the offline texts

Core Features

See how the components power each chat feature