Skip to main content

Overview

With offline support on, the UI Kit keeps working when the network drops. The JavaScript Chat SDK keeps a cache on the device and an outbox of unsent messages. The UI Kit components read from that cache first, show each message’s send state, and catch up when the connection returns. Works offline:
  • Conversations, users, groups, group members, messages, threads, reactions, the notification feed, and pinned and saved messages that the user has already loaded appear at once from the device.
  • Text, media and custom messages can be sent. They are queued and go out by themselves when the connection returns. Photos, videos, audio files and documents picked in the composer are queued the same way; a file larger than the offline media budget is not queued and shows File too large to send offline.
  • Unsent messages can be retried or deleted.
  • Media the SDK has saved on the device plays and opens from the device.
Needs a connection:
  • The first load of anything the user has never opened while online.
  • A keyword search with no saved match.
  • Editing, deleting, reacting to, pinning or saving a sent message. These are not queued.
  • Message information, calls, and AI agent 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, and npm does not enforce the 4.3.1 requirement. With SDK 4.2.x or 4.3.0, setOfflineConfig() is ignored and the UI Kit works online only, with no error and no warning. The UI Kit needs the SCHEMA_RESET cache-reset reason, which first ships in 4.3.1. If offline support appears to do nothing, check npm ls @cometchat/chat-sdk-javascript, or call CometChat.isOfflineEnabled() after login. Install SDK 4.3.1 or later to use offline support:
The browser needs IndexedDB for the cache. Where it is missing or blocked (for example, in some private-browsing modes), offline support stays off for that session. See Supported runtimes.
UI Kit v4 has no offline support. Turning on the SDK’s offline support under UI Kit v4 is not supported.

Enable Offline Support

Offline support is off by default. Call setOfflineConfig() on the UIKitSettingsBuilder with enabled: true, before CometChatUIKit.init(). The UI Kit passes the object to the Chat SDK’s AppSettingsBuilder.setOfflineConfig() unchanged.
src/main.ts
The config is typed as CometChatOfflineConfig. It lists exactly the SDK’s options, so a misspelled key such as enable is a compile error. For what each option does and its default, see OfflineConfig options. For encryption and media caching, see Encrypt the Cache and Media Caching.
Offline support turns on only with an explicit enabled: true. A config without enabled leaves it off.
Whether offline support is running can change after init: it is off before anyone logs in, and the SDK can turn it off, for example when the encrypted cache cannot open. The components check CometChat.isOfflineEnabled() each time they need to. Do the same in your own code instead of reading back the config you passed. See Verify it is active.

How the Components Behave Offline

Lists

This applies to Conversations, Users, Groups, Group Members, Reaction List, Notification Feed, Pinned Messages and Saved Messages.
  • Saved rows first. The list paints the rows saved on the device straight away, then merges in the server page when it arrives.
  • Offline with nothing saved. The list shows its offline state: an icon and Connect to load chats (or users, groups, members, reactions, notifications, messages), with no Retry button. It loads once by itself when the connection comes back after a drop the SDK reported. If the app started with no connection at all, only the Message List loads by itself; these lists load the next time they are opened.
  • Rows on screen stay. If a load fails while rows are showing, the rows stay and nothing is drawn over them.
  • Reaction counts. Offline with no reactions loaded, the Reaction List shows Connect to load reactions and keeps its tabs, with the counts the message already carries.
  • Reconnect. The SDK catches every list up. The Message List and Conversations make no refresh fetch of their own, apart from the one-time reads above. Users, Groups and Group Members quietly re-read their first page, as they do with offline support off. Messages that arrived meanwhile appear without a sound and without extra unread counts.
  • Keyword search. A search with a keyword that cannot reach the server, and has no saved match, shows Connect to search with a second line, Search needs an internet connection. It runs again once by itself when the connection comes back after a drop the SDK reported; after a start with no connection at all, run the search again.
  • Filters only. A list opened with a filter and no keyword (online users, tags, a request builder with no search term) is a plain list, not a search. Offline with nothing saved, it shows that list’s Connect to load … text.
  • The Search component searches conversations and messages together:
    • It shows Connect to search only when every failed request was a not-connected one.
    • A search by filters alone is answered from the device. When nothing is saved, it shows the plain empty state (No Results), not Connect to search.
    • It waits for both scopes before it treats a failure as an error. See Errors and Callbacks.

Message List and Threads

Message List behaves as follows:
  • Cached history. A chat opens with the messages saved on the device, then updates with the server page. A chat opened offline with nothing saved shows Connect to load messages.
  • Connect to load more. Offline, scrolling past the saved messages shows a tappable Connect to load more row at that edge: at the top for older messages, at the bottom for newer ones. The list never ends there. When the connection is back, the page behind the row loads once by itself, older edge first. Tapping the row or scrolling to that end also loads it.
  • Jump to a message. A saved target opens with the saved messages around it.
    • When the chat opens on a target (goToMessageId, or the unread anchor) that is neither saved nor reachable offline, it opens on its newest saved page as a normal offline open, with no error.
    • From messages already on screen (a quoted reply, a search result), the messages on screen stay until the target is found. If it cannot be read offline, nothing changes and nothing is reported.
    • If the target cannot be read for another reason, for example it was deleted, (error) fires once. The messages on screen stay, or an opening chat shows its newest page; with nothing to show, the error view shows.
  • Start from unread. With startFromUnreadMessages, the chat opens on its newest page from the device, then moves to the unread divider.
  • Threads. A thread view shows the same offline states as the main list. See Limitations for what is saved for threads.
The message list’s default request lets the SDK save each page for offline use. If you pass your own messagesRequestBuilder with extra filters, the request is sent exactly as you built it. The SDK may then not save its pages, so that chat has less to show offline. See Cache-supported filters.

Composer and Sending

Message Composer and Message List handle sends as follows:
  • Queued sends. A message sent offline appears at once with a clock icon and Not sent yet. It is queued, not failed, and sends by itself when the connection returns.
  • Failed sends. A message the server refuses shows the error mark and Not sent. Tap to retry, whatever the reason. A failed message stays failed until the user taps it or chooses Retry.
  • Retry and Delete. Every own message that is waiting, sending, or failed offers only Retry and Delete in its menu. Reply, thread, react, edit, pin, save, info and copy all need a sent message, so they are hidden until it is sent.
    • Delete shows the usual confirmation, then removes the message from this device for good, offline too, and it stays removed after a restart.
    • Retry or Delete on a message whose send is already under way changes nothing, and a short Sending… try again in a moment notice shows.
    • If the SDK no longer holds an unsent message (for example, its chat was removed from the cache), Retry or Delete removes it from the screen.
  • Queue limits. When the outbox is full (maxPendingMessages), the message shows as not sent with the notice Too many messages waiting to send. Retry sends it once there is room.
  • Editing. An edit is sent straight to the server and is never queued. When it fails, for example offline, the composer has already left edit mode and cleared, and the error goes to the composer’s (error) output.
For how the SDK queues sends, see Send While Offline.

Media

  • Images, videos, audio, voice notes and files the SDK has saved open and play from the device when offline. By default the SDK saves incoming media as it arrives; with mediaCaching set to OFF it saves none and the UI Kit loads media from its URL. See Media Caching.
  • An image, video, audio file or file with no saved copy shows Available when online while offline.
  • Online, tapping an image, video or file the device has no copy of downloads and caches it. Playing an audio file does the same; the audio plays from its URL and uses the saved copy next time.

Edits, Deletes and Reactions

Editing, deleting, reacting to, pinning and saving a sent message need a connection. They are not queued: offline, each one fails with the SDK’s not-connected error. Edits, deletes and reactions made on other devices sync in when the connection returns.

Presence

Nobody shows as online while the connection is down, in any list or header, and screen readers do not announce anyone as online. Presence comes back with the connection.

Logout and Switching Users

The cache belongs to one user. Logging out, a session expiring, or logging in as a different user deletes the cache, including any unsent messages. You don’t clear anything yourself. See One cache per user.

Offline States and Texts

These are the texts the components show in their offline states. Each one is a localization key, so you can change the text with CometChatLocalize.addTranslation(), as for any other string. See Localization. The counted notices use plural keys: _one and _other, plus _few and _many in languages that need them. The UI Kit picks the form for the current language and falls back to _other, replacing {{count}} with the number.

Errors and Callbacks

The error output

The list components’ (error) output follows one rule while offline support is on: The Search component reports through its (searchError) output instead. With both scopes:
  • If both scopes fail, at least one for a real reason, the error view shows and (searchError) fires once for each scope that failed for a real reason.
  • If one scope fails and the other has results, the results stay and (searchError) fires once for the failed scope if it failed for a real reason.
  • If one scope fails and nothing is shown, the plain empty state (No Results, or your own empty view) shows, with no (searchError) and no run on reconnect.

Send promises

CometChatUIKit.sendTextMessage(), sendMediaMessage() and sendCustomMessage() behave as follows when offline support is on:
  • They resolve when the message is sent.
  • They reject on a final failure.
  • They never reject only because the message was queued.
  • Any removal of the message before it is sent rejects the promise once, quietly, with the code ERROR_OFFLINE_MESSAGE_DISCARDED: 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 (for example under a drop-oldest overflow policy). The code is always ERROR_OFFLINE_MESSAGE_DISCARDED, whatever the reason; the reason itself is not exposed on the rejection. The components show no error for it. Treat it as “dropped”, not as a failure to report.
See Error codes for the other offline codes.

Events

Two events on CometChatMessageEvents fire only while offline support is on:
ccMessageSent keeps its contract: one inprogress, then one success or error per message. A queued message stays inprogress until it is sent.
Group events can come from catch-up. With offline support on, group actions that happened while the user was away (a kick, a ban, a scope change, or the user leaving from another device) arrive in the SDK’s catch-up. The UI Kit then also emits CometChatGroupEvents.ccGroupMemberKicked, ccGroupMemberBanned, ccGroupMemberScopeChanged and ccGroupLeft, with the same payload as before. These events no longer always mean “this user just did it”. Check kickedBy or message.getActionBy() before you show a toast for the user’s own action, and handle the case where the kicked user is the signed-in user, for example by closing the chat.

Search service signals

SearchConversationsService and SearchMessagesService expose offline state as signals. Both are always false while offline support is off.

Customization

Hide the offline notices

cometchat-message-list and cometchat-conversations take a hideOfflineNotices input (default false):
The input has no effect while offline support is off.

Your own empty and error views

Your own views win over the built-in offline states:
  • An errorView you pass to a list shows instead of Connect to load … (on the Notification Feed, errorStateView).
  • An emptyView you pass to Conversations, Users, Groups or Group Members shows instead of Connect to search. It also shows when the server answers with an empty list, and in the Search component’s plain empty state.
  • On Conversations, Users, Groups, Group Members and Message List, hideError hides Connect to load … along with the error view.

Your own “Connect to load more” control

The built-in Connect to load more row calls the message list’s public retryOfflineRead() method, which reads the page behind the blocked edge. To trigger it from your own control, call it on a viewChild reference:

Message options on unsent messages

The Retry and Delete options on an unsent message use the ids CometChatUIKitConstants.MessageOption.retryMessage and CometChatUIKitConstants.MessageOption.discardMessage. Use them to find these options when you customize the message menu. hideDeleteMessageOption also hides Delete on unsent messages.

Theming

The offline states use the theme’s existing colors and fonts. Override them with these CSS variables:
See Theming for where to put overrides.

With Offline Support Turned Off

Apps that don’t turn offline support on keep today’s behavior: no cache, no outbox, no offline states, and neither offline event fires. UI Kit 5.3.0 still includes a few changes that apply with offline support off:
  • Behavior changes. On reconnect, the conversation list keeps the freshly fetched copy of a row. A failed send shows the error mark rather than the clock. The server copy of your own message keeps its quote and thread-subscribed flag. A messagesRequestBuilder you pass is left unchanged by the UI Kit.
  • Send error metadata. When CometChatUIKit.sendTextMessage(), sendMediaMessage() or sendCustomMessage() fails, metadata.error is merged into the message’s existing metadata instead of replacing it, so your own metadata keys survive.
  • Test identifiers. Message rows, the message menu, conversation rows, notices, the list footer, the composer input, attachment tray tiles, and the empty and error views carry data-testid and data-cc-* attributes. They hold no message text and are not read by screen readers, but DOM snapshot tests may change.
  • Bundle size. Chat SDK 4.3 adds about 0.54 MB to an app’s initial bundle, and UI Kit 5.3.0 about 0.12 MB, whether offline support is on or off.
  • Reconnect. As in 5.2.x, the message list makes no fetch of its own on reconnect. Messages missed during a drop appear when the chat is reopened.
  • Browser connectivity events. UI Kit 5.3.0 also treats the browser’s online and offline events as connection changes. After a drop the SDK did not report, Conversations, Users, Groups and Group Members each re-read their first page once when the connection returns. Nothing is re-read while the SDK reports its socket as connected, and a drop before the first connect is ignored.

Limitations

  • The cache holds only what the user has loaded while online, plus what syncs on reconnect. A user who has never used the app online has nothing to show offline.
  • Keyword search, message information, calls and AI agent streamed replies need a connection.
  • Edits, deletes and reactions on sent messages are not queued offline. They need a connection when the user makes them.
  • The browser cache encrypts message content but not lookup metadata, and downloaded media is stored unencrypted. See What gets encrypted.

Next Steps

SDK Offline Support

How the JavaScript SDK caches, queues and syncs

Configuration & API Reference

Every OfflineConfig option, listener and error code

Send While Offline

The outbox, retry, discard and queue limits

Stay in Sync

Catch-up on reconnect and cache resets

Message List

Inputs, outputs and custom views

Events

All UI Kit events, including the offline ones