one-chat’s frontend took 46 seconds to build for production, and a fresh clone needed 17 seconds to start the dev server. Both numbers came from Create React App (CRA). Switching to Vite was the first change in the frontend rework, and I expected a faster page out of it as well as a faster build.
The build got faster: 46.3 s became 2.22 s. The page did not. Its first paint arrived 1.7 s later than on CRA, and the largest page-load gain of the whole rework came from five lines of nginx config, unrelated to the build tool.
The rest of the rework replaced Redux with TanStack Query and Zustand, and pulled the call code out of React. One release had to be reverted. Calls became more reliable, and page load did not change.
The CRA baseline
I timed CRA first, while it still built: 4 cores, Node 22.23.1, headless Chrome, median of three runs per timing.
| metric | CRA |
|---|---|
production build (npm run build) | 46.3 s |
dev start (npm start, until the first “Compiled”) | 6.8 s warm, 17.4 s cold |
| rebuild after a one-line edit (watch mode) | 1.41 s |
| main bundle | 2,325,055 B, 684,928 B gzipped |
Everything ships in one JavaScript chunk; CRA was not set up for code splitting. The machine was busy (load average between 3 and 8), so the numbers in each table come from the same session.
Replacing CRA with Vite
Vite and vitest (Vite’s test runner) replaced react-scripts, its custom
webpack config and Jest.
vite.config.mts defines process.env from the existing REACT_APP_*
variables, which kept every source file unchanged.
| metric | CRA | Vite |
|---|---|---|
| production build | 46.3 s | 2.22 s |
| dev start | 6.8 s (17.4 s cold) | 1.0 s |
| rebuild after a one-line edit | 1.41 s | 1.43 s |
| gzipped bundle | 684,928 B | 672,428 B |
The build is about 21x faster, and the dev server is up in a second. The
rebuild row stayed flat: vite build --watch still rebuilds and minifies one
large chunk, as CRA did.
Page load did not get faster
My first runs of Lighthouse, Chrome’s page-audit tool, used the default mobile profile, the wrong profile for one-chat’s desktop users. The rerun used the desktop preset, five runs alternating CRA and Vite to spread load drift over both, and the bundle served uncompressed, as production served it (more on that below).
Lighthouse reports when the first text or image paints (FCP), when the largest element paints (LCP) and how long scripts block input (TBT); the score is a 0-to-1 weighted mix.
| median of 5 | CRA | Vite |
|---|---|---|
| Largest Contentful Paint (LCP) | 3584 ms | 3443 ms |
| Total Blocking Time (TBT) | 227 ms | 59 ms |
| First Contentful Paint (FCP) | 1244 ms | 2936 ms |
| score | 0.66 | 0.65 |
LCP changed by 4% and the score stayed flat. TBT fell 74%. FCP got worse by 1.7 s.
Three causes could explain the FCP loss. The HTML was ruled out: both pages
request the same files. So was the position of Vite’s module script; placing it
in <head> left FCP unchanged in the mobile runs. That left
lib-jitsi-meet.min.js, the client library for Jitsi (the open-source stack
used for one-chat’s group calls). It is a synchronous script, and Lighthouse
reported it as render-blocking (1669 ms on CRA, 3017 ms on Vite, in the first
mobile-profile runs). Adding defer (the script waits for the HTML to be
parsed) recovered 0.86 s of FCP (2936 ms to 2077 ms, 3 runs); I tested it on the
built page, not in a live call. Vite still painted 0.83 s after CRA, and I have
not found why.
The migration did not speed up the page. Its gain is in the developer loop: a 2-second build and a 1-second dev start, with a lower TBT on top.
Production sent the bundle uncompressed
The reruns served the bundle uncompressed to match production. A curl on
production showed no compression:
curl -sI -H 'Accept-Encoding: gzip, br' https://one-chat.eu/static/js/main.<hash>.js
The response had no Content-Encoding header, and none of the repo’s nginx
configs mentioned gzip or brotli. Every visitor downloaded the 2.3 MB
bundle and the 1 MB Jitsi library at full size.
The cause was already in the first CRA measurements.
I first served the build with Python’s http.server, which does not
compress: LCP came to about 21 s. Behind serve, which gzips by default,
the same page gave 6.9 s. That went into the notes as a test-server caveat. It wasn’t specific to the test
server. It was how production served the bundle.
Turning on gzip in nginx
The change goes in the static location / block of nginx/server.conf
(comments added):
gzip on;
gzip_comp_level 5; # 1 is fastest, 9 smallest
gzip_min_length 1024; # skip responses under 1 KB
gzip_vary on; # adds the Vary: Accept-Encoding header
gzip_types text/plain text/css application/javascript application/json image/svg+xml;
Level 5 was not tuned, and brotli was not tried.
gzip_proxied stays off: proxied API, Socket.IO and Jitsi responses stay
uncompressed.
On the wire, main.*.js went from 2,325,055 B to 693,461 B and
lib-jitsi-meet.min.js from 1,060,286 B to 278,104 B. Lighthouse, desktop
preset, CRA build, five alternating runs:
| median of 5 | gzip off | gzip on |
|---|---|---|
| LCP | 3576 ms | 1371 ms |
| TBT | 222 ms | 216 ms |
| FCP | 1224 ms | 603 ms |
| score | 0.67 | 0.88 |
LCP fell 62% and FCP 51%; TBT did not move, which fits a change that shortens downloads and leaves the main thread alone. That is 2.2 s of LCP, where the Vite migration gained 0.14 s, from a config file the migration never touched.
After the deploy, three runs on production gave a median LCP of 1642 ms and FCP of 777 ms. With no run before the deploy, that shows the same range, not a measured gain.
Vite with gzip on
With compression in place, the Vite comparison reran with all three builds behind the same nginx and gzip lines:
| median of 5 | CRA | Vite with defer | Vite without defer |
|---|---|---|---|
| LCP | 1360 ms | 1290 ms | 1300 ms |
| TBT | 169 ms | 70 ms | 35 ms |
| FCP | 599 ms | 817 ms | 1063 ms |
| score | 0.92 | 0.96 | 0.95 |
The FCP gap shrank from 1.7 s uncompressed to 0.22 s with defer and 0.46 s
without. Most of Vite’s first-paint regression scaled with download size.
At level 5, gzip goes on static files, and Vite keeps defer on the Jitsi
script.
Splitting the bundle
Compression shrank the bundle on the wire, and every visitor still downloaded all of it, including the call screen and the Excalidraw whiteboard that the login page never uses. The next step made the call, profile and register routes lazy (fetched on first visit, as separate chunks), and the whiteboard with them.
The first attempt did not shrink the main chunk. Excalidraw was still in it:
GroupCall.tsx imported a helper from the library at the top of the file, and
Recorder.tsx imported Whiteboard statically. A single static importer pins a library into that
importer’s chunk. The GroupCall.tsx change, trimmed to the two imports:
// before: both imports pull Excalidraw into this chunk
// (@jitsi/excalidraw: Jitsi's fork, patched to save scenes in MongoDB)
import Whiteboard from "../whiteboard/Whiteboard";
import { generateCollaborationLinkData } from "@jitsi/excalidraw";
// after
const Whiteboard = lazy(() => import("../whiteboard/Whiteboard"));
// ...when a whiteboard is created:
const { generateCollaborationLinkData } = await import("@jitsi/excalidraw");
On production, the initial load is 459,658 B on the wire, where the single Vite chunk had been about 683 kB. Excalidraw (222,847 B) arrives when a whiteboard opens. Lighthouse, five alternating runs of the release before and after splitting:
| median of 5 | before | after |
|---|---|---|
| entry chunk (gzip) | 691 kB | 123 kB |
| page weight at load | 1,129 kB | 742 kB |
| LCP | 1317 ms | 1057 ms |
| FCP | 808 ms | 741 ms |
| TBT | 95 ms | 91 ms |
| score | 0.95 | 0.97 |
LCP fell 20%, and TBT stayed within the run-to-run spread.
The gzip comparison used CRA behind local nginx; this table compares the releases before and after splitting. The 62% and 20% come from different setups and do not add up.
Redux to TanStack Query and Zustand
Most of the Redux store held server data: copies of data stored on the server (messages, groups, participants, recordings). A copy can go stale and needs a cache that can invalidate it; every fetch and socket patch to it was hand-written. TanStack Query (a data-fetching library) gives each result a key, shares one fetch between components, tracks loading and error status, and refetches when a key is invalidated.
RTK Query, the data-fetching add-on of Redux Toolkit, would have kept Redux in the app for the UI state (what is open or selected).
With server data in TanStack Query, the UI state was too small a job for Redux: the open conversation, the selected group, the modals and the sidebar. Zustand (a small state library) holds it in one store, with plain setter functions and no action types or reducers.
Redux kept server data and UI state in one store. A
fetch was a thunk that called the API and wrote the result there; each socket
event dispatched an action that patched the same store. A fetch could change
UI state too: fetchMessagesThunk set conversationId as a side effect, and
twelve files read it. Changing how messages load could therefore change which
conversation was open.
After the move, TanStack Query holds the server data. A hook such as
useMessages names its data with a key, fetches it once, keeps it in the cache
and reports loading and error status (trimmed):
export const messagesKey = (conversationId: string) =>
["messages", conversationId] as const;
const messagesQuery = (conversationId: string) =>
queryOptions({
queryKey: messagesKey(conversationId),
queryFn: async (): Promise<Message[]> => {
const { data } = await api.conversation.fetchMessages(conversationId);
return [...data].reverse();
},
staleTime: Infinity, // socket events keep the open conversation current
});
export const useMessages = (conversationId: string | null | undefined) =>
useQuery({
...messagesQuery(conversationId ?? ""),
enabled: !!conversationId,
});
Socket events update the same cache. An event that carries the full payload
writes it with setQueryData; addMessage does this for a new message. An
event that only signals a change calls invalidateQueries, and the data is
fetched again. After a reconnect, one invalidateQueries() refreshes every
active query; the Redux code had no equivalent step.
Zustand holds the UI state, in dashboardStore. Unlike the Redux store, it has
no server data: a fetch cannot write to it.
The gain is structural, not measured: fetchMessagesThunk can no longer set
conversationId. Page load did not move, as the call-view run below shows.
The table shows each area before and after:
| Area | Before | After | Example |
|---|---|---|---|
| Server data | Redux thunks and slices | TanStack Query hooks in queries/ | useMessages |
| UI state | Redux slices | Zustand dashboardStore | the open conversation, the profile modal |
| Socket events | actions dispatched to the store | setQueryData or invalidateQueries | groupEdited writes; a member change refetches |
| The 1:1 call | a React context | CallController and callStore | the diagram below |
Pulling the call out of React
The call code was still written as React state and effects. A 1:1 call lived in a React context: the peer connection, the local media and the socket listeners sat in that context, spread over two pages, one for the caller and one for the callee. The group call was a single 1,473-line component.
The caller’s offer went out from an effect (trimmed):
useEffect(() => {
const shareVideo = async () => {
// ...add tracks, create the offer
signaling.emit("call-offer", { offer, conversationId, ticket });
};
shareVideo();
}, [localStream, peerConnection, remoteStream]);
A change to any of the three dependencies sent the offer again.
The cause was the lifetime. A peer connection and a media stream live for the whole call, while an effect runs again whenever a dependency changes, so every re-run was a chance to send twice. The rework moved the call to a place where a render cannot re-run it.
The rework put the 1:1 call in a CallController class outside React. It
owns the peer connection and the local media, registers every socket listener
in one attach method, and writes the call state to a Zustand store. VideoChatContext, now 125
lines, passes that state to the components. The source describes the store as “the reactive view of the
call; the call itself lives in callController.” The two call pages merged;
the role prop tells caller from callee.
The offer is now a method that sends once per peer connection, instead of whenever a dependency changes (trimmed):
async joinAsOfferer() {
if (!pc || !signaling || !this.send("join")) return;
// ...add tracks, create the offer
signaling.emit("call-offer", { offer, conversationId, ticket });
this.send("offerSent");
}
The group call was broken into five hooks and two components, and the page itself dropped from 1,473 to 193 lines. The folders that changed:
frontend/src/
├── queries/ server state: group, messages, recordings, sider, transcript
├── stores/
│ ├── dashboardStore.ts UI state
│ └── callStore.ts the reactive view of the call
├── utils/
│ ├── callController.ts peer connection, media, listeners
│ └── callMachine.ts which event is allowed in which phase
├── context/
│ └── VideoChatContext.tsx adapter between controller and components
└── components/dashboard/
├── call/ CallVideo, CallControls
└── group-call/ GroupCall (193 lines), useJitsiConnection, useLocalTracks,
useRecording, useTranscription, useConferenceEvents
An event reaches CallController through attach. The controller asks
callMachine whether the current phase allows it, acts on the peer
connection and writes the phase and the streams to callStore. The 1:1 call
components reach all of this only through VideoChatContext, which exposes
six intents (initCall, joinAsOfferer, joinAsAnswerer, toggleVideo,
toggleAudio, hangupCall) and the store’s view.
Transitions go through a state machine, a table of which event may move the call to which phase (trimmed):
const transitions: Record<CallPhase, Partial<Record<CallEvent, CallPhase>>> = {
idle: { start: "connecting" },
// connecting, joining, inCall ...
ringing: {
answerReceived: "inCall",
peerDropped: "recovering",
peerOfferAnswered: "inCall",
end: "idle",
},
recovering: {
peerDropped: "recovering",
peerOfferAnswered: "inCall",
end: "idle",
},
};
// Returns the next phase, or null when the event is not allowed in this phase.
export const nextPhase = (
phase: CallPhase,
event: CallEvent,
): CallPhase | null => transitions[phase][event] ?? null;
The specs failed on the old code
Before the rewrite I wrote end-to-end specs with Playwright: two browser contexts act as two users, with a synthetic camera and microphone.
On the code then in production, three specs failed.
The caller sent call-offer twice: the spec counts offers per connection and
counted 2 on the old code. The machine’s join transition now allows one offer
per connection.
After a 1:1 peer rejoined, the side that stayed had no remote audio. The
disconnect handler cleared the audio element’s srcObject, and nothing set
it again, because the stream object never changes. The leaver’s side passed
the same assertion, which narrowed it to the stayer’s cleanup.
Leaving a group call during the join stranded the user on the call screen,
because lib-jitsi-meet emits “conference left” only once the join has
completed. Leave now navigates without waiting for that event, and the spec went
from 3 passes in 10 to 10 in 10.
The first release passed every unit test and 65 of 66 end-to-end specs on a production build, and production still showed three problems. I reverted it. The local suite used a synthetic camera and microphone, with no real network and no recording server. Each call release now ends with a real call and a real recording on production.
Lighthouse on a call in progress
The earlier Lighthouse runs all loaded the login page. This one loaded a group call in progress: a script starts the call in headless Chrome with generated media, clears the cache so each run is a cold load, and has Lighthouse load the call page with the desktop preset, behind nginx with the production gzip lines.
| call view, median | before the refactor (3 runs) | final (6 runs) |
|---|---|---|
| LCP | 1306 ms | 1324 ms |
| TBT | 71 ms | 154 ms |
| FCP | 920 ms | 904 ms |
| score | 0.94 | 0.91 |
| transferred | 759,005 B | 759,965 B |
LCP, FCP and bytes did not move. A change to state handling does not alter what the page downloads, and the bundle was already split.
TBT rose from 71 to 154 ms. The same build gave results from 46 to 128 ms before the refactor and from 60 to 184 ms in the final build, so the rise may be noise. Only three runs came before, and the machine was busy (load average 5.0 to 8.1). The 1:1 call page is unmeasured.
The refactor wasn’t a page-load change. It made calls more reliable.
The interface after the refactor
The refactor was invisible to users, who still saw hard-coded colors, an orange circle for every avatar and no product name.
Every color now lives in theme.ts, the theme file for antd, the app’s
component library.
Login got a redesign, and registering now signs the user in instead of leaving them on the form.

In a call, the group view stayed blank until Jitsi joined, a 1:1 call raised
a browser alert() on a missing camera or microphone permission, and every
remote stream showed a native audio player. Group and 1:1 calls now share the same
toolbar of icon buttons, and a status line says “Connecting…”,
“Reconnecting…” or who the call waits for. The recording pill is the one
solid red on screen. A spec ran the reconnecting state on a simulated Jitsi event,
never a dropped network.

Accessibility, in numbers
Of the UI changes, only accessibility has numbers. Lighthouse and axe-core (an automated rule checker) audited the screens before and after:
| Views | Lighthouse | axe rules failing | |
|---|---|---|---|
| Before | 4: home, 1:1 chat, 1:1 call waiting, 1:1 call live | 96 to 98 | 3 on each |
| After | 24: the same 4, plus 20 added later (group views, dialogs, profile, mobile) | 100 on each | 0 on 22 views, 1 on 2 |
The muted text color #6b7280 on the #f5f6f8 background measured 4.47:1,
and WCAG level AA needs 4.5:1; it is now #5b6472. Four more defects: the
user menu button had a name that omitted its visible text; several pages had
no h1 or main landmark; the microphone meter and three dialogs had no
accessible name; the links between login and register relied on color alone.
None of the five remain.
Automated rules check the markup, not the experience, and no screen reader was tried. Two views still fail one axe rule: antd’s message toast and dropdown menu render outside a page landmark.