SSR Hydration Errors
Symptom
You see a React hydration mismatch error in the console when rendering your app with a server-side rendering framework (Next.js, Remix, Astro SSR):Root Cause
CometChatProvider uses browser-only APIs (WebSocket connections, window, localStorage). When a parent component renders on the server, it produces different output than the client, causing a hydration mismatch.
Solution
Mark the component boundary containingCometChatProvider as client-only. In Next.js App Router, add the 'use client' directive at the top of the file:
client:only="react" directive on the component that wraps CometChatProvider:
CometChatProvider only renders in the browser where its required APIs are available.
React StrictMode Double-Mount
Symptom
You notice duplicate SDK event listeners firing, causing messages to appear twice or callbacks triggering multiple times during development.Root Cause
React StrictMode intentionally mounts, unmounts, and remounts components in development to help detect side effects that aren’t properly cleaned up. If SDK listeners aren’t cleaned up on unmount, the remount adds a second listener.Solution
All v7 hooks handle cleanup automatically. If you’re writing custom hooks that attach SDK listeners, always return a cleanup function fromuseEffect:
- Use
useId()for unique listener IDs — it’s stable across StrictMode remounts within the same component instance. - Always remove listeners in the cleanup function returned from
useEffect. - The built-in
useCometChatEventshook already handles this correctly.
SDK Initialization Failures
Symptom
The chat UI shows an error state or nothing renders. The console displays:Root Cause
Invalid credentials: TheappId, region, or authKey passed to UIKitSettingsBuilder are incorrect, expired, or belong to a different environment (e.g., using production credentials in a development build).
Network issues: The client cannot reach CometChat’s servers due to network restrictions, firewall rules, or the CometChat service being temporarily unavailable.
Solution
Verify your credentials match your CometChat dashboard and add error handling to your init/login flow:- Confirm
appIdandregionmatch the values shown in your CometChat Dashboard - Ensure credentials are for the correct environment (development vs. production)
- Check that your network allows outbound WebSocket connections
- Verify the
authKeyhas not been rotated since you last copied it
Theme Not Applying
Symptom
Components render with default styling and ignore the theme you’ve configured. Colors, fonts, or spacing don’t match your custom theme.Root Cause
The theme is activated by thedata-theme attribute on a parent element, which CometChatProvider’s theme prop sets for you. If the theme prop is missing — or set to a custom theme with no matching variable definitions — the theme won’t apply.
Solution
Set thetheme prop on CometChatProvider:
[data-theme] selector: