Back to projects
Projectadvanced 9 steps ~100 min

Real-time Chat UI

Build a chat UI that survives real networks: optimistic sends with client ids, retry without duplicates, smart auto-scroll, reconnect-and-resume, accessible live updates, and a transport you can swap for WebSockets.

What you'll build

A chat UI where messages never vanish or duplicate, with reconnects, retries, and accessible live updates.

  • React
  • optimistic UI
  • WebSockets
  • idempotency
  • aria-live
Project briefrequirements and design decisions

Requirements

  • Message list with input; new messages appear without refresh
  • Sent messages appear instantly with a pending state
  • Auto-scroll only when the user is already at the bottom

Architecture decisions

  • Optimistic messages with client ids, reconciled with server ids
  • Transport hidden behind one interface so polling and WebSockets are swappable
  • Messages normalized by id to avoid duplicates on reconnect

Stretch goals

  • Typing indicators and read receipts
  • Reconnect with backoff and resume from the last message id
  • Virtualize long histories

Production checklist

  • Escape all user content (no innerHTML)
  • aria-live announcements for new messages
  • Delivery guarantees and retries for failed sends

1What we're building

Chat looks simple: a list and an input. The hard parts are everything around it, and they're the same problems you'll meet in any real-time product (comments, notifications, collaborative editors, trading screens):

  • Sends fail. Networks drop requests. A message can't just vanish, and it can't appear twice when the user retries.
  • The UI must feel instant. Waiting 800 ms for the server before showing your own message feels broken.
  • Messages arrive out of order and twice. Reconnects, retries, and echoes all deliver duplicates.
  • Scrolling is a UX minefield. Auto-scrolling while someone reads history is infuriating; not auto-scrolling while they're following the conversation is just as bad.
  • Connections drop. Whatever was said while you were offline must show up when you're back.

You'll build a chat UI that handles all of them, against a mock server that misbehaves on purpose: latency, 20% failed sends, other people talking, and a button to drop the connection.

1data.js sample messages (step 2 only) 2messages.js pure message-list logic: add, receive, dedupe, order, fail 3mockServer.js the misbehaving server (stands in for a WebSocket backend) 4useChat.js the data layer: history, live updates, sending, retry, resume 5useAutoScroll.js scroll only when the reader is following along 6MessageItem.jsx one message, with pending and failed states 7Composer.jsx the input form 8App.jsx wires it together

What you'll learn: optimistic UI with client ids, idempotent message handling, subscription effects and cleanup, scroll anchoring, reconnect-and-resume, and accessible live regions. At the end you'll swap the mock for a real WebSocket transport without touching the UI.

Real-time Chat UI project | Bloom