Chat Messages Not Updating in Real-Time in Bolt App
Your Bolt.new chat feature saves messages to the database correctly, but other participants don't see new messages until they manually refresh the page. The chat feels like an email inbox rather than a live conversation, making real-time communication impossible.
Users expect chat to be instant - messages should appear within milliseconds of being sent. When they have to refresh the page to see responses, they assume the feature is broken and will abandon it for a working alternative. This is a fundamental functionality issue that undermines the entire purpose of a chat feature.
The root cause is that Bolt generated a working CRUD interface for messages (create, read, update, delete) but didn't implement the real-time subscription layer that pushes new messages to connected clients as they arrive.
Error Messages You Might See
Common Causes
- No real-time subscription — Messages are fetched on page load but there's no WebSocket or Supabase Realtime subscription to receive new messages
- Supabase Realtime not enabled — The Realtime feature is not turned on for the messages table in the Supabase dashboard
- Subscription filter too broad or narrow — The Realtime subscription listens to the wrong table, wrong event type, or wrong filter condition
- New messages not added to local state — The subscription receives events but the callback doesn't append the new message to the displayed list
- Channel not subscribed — The channel is created but .subscribe() was never called, so no events are received
- Cleanup function missing — Previous subscriptions aren't cleaned up on component unmount, causing duplicate messages or memory leaks
How to Fix It
- Enable Realtime on your table — In Supabase dashboard, go to Database > Replication and enable Realtime for your messages table
- Add a Realtime subscription — Subscribe to new messages: useEffect(() => { const channel = supabase.channel('messages').on('postgres_changes', { event: 'INSERT', schema: 'public', table: 'messages', filter: `chat_id=eq.${chatId}` }, (payload) => { setMessages(prev => [...prev, payload.new]); }).subscribe(); return () => { supabase.removeChannel(channel); }; }, [chatId])
- Handle all event types — Subscribe to INSERT, UPDATE, and DELETE events to handle new messages, edits, and deletions
- Auto-scroll to new messages — After adding a new message to state, scroll the chat container to the bottom: messagesEndRef.current?.scrollIntoView({ behavior: 'smooth' })
- Add optimistic updates — Show sent messages immediately in the UI before the database confirms, then reconcile when the Realtime event arrives
- Clean up subscriptions — Always remove channels in the useEffect cleanup function to prevent memory leaks and duplicate messages
Real developers can help you.
You don't need to be technical. Just describe what's wrong and a verified developer will handle the rest.
Get HelpFrequently Asked Questions
How do I enable Supabase Realtime for my messages table?
Go to Supabase dashboard > Database > Replication. Toggle on the messages table. Then in your code, subscribe to postgres_changes events on that table. Note that Realtime must be enabled per-table, it's not on by default.
Why do I see duplicate messages with Realtime?
This usually happens when the subscription callback adds the message but you also add it when sending. Either use optimistic updates (add on send, reconcile on subscription) or only add messages through the subscription callback. Also ensure you clean up subscriptions in useEffect cleanup to prevent duplicate listeners.