fix(chat): stop the transcript settle effect from looping
Draft
PO
1mo ago+35+35+01234567890123456789-2-2-0123456789
Problem
- Every open chat thread burns CPU re-rendering the whole message list, and a thread left open long enough crashes the panel with React error #185.
- The settle effect in
useWorkspaceAiChat.tscallssetMessages(transcriptData)with no equality guard. The AI SDK copies the array on every set, somessagesidentity changes, the effect (which listsmessages) re-fires, and the two feed each other forever. experimental_throttle: 100paces the loop at roughly ten passive-effect updates per second, so React only throws once the nested passive-update count crosses fifty — about five seconds in.- The guard passes for any settled thread that has a transcript, so this is the normal idle state of the core chat surface, not an edge case. The recorded exception count is a floor: most sessions leave the thread before the limit trips and only pay the wasted renders.
Changes
- Deep-compare the server snapshot against the local messages before setting. After the first set the two match, so the next effect run returns early and the cycle breaks.
- Added
transcriptsEqualnext toserverTranscriptAdvanced, reusing the sameJSON.stringifycomparison the recovery path already relies on. - The compare runs only when the thread is settled and ready. During streaming the effect still returns early before the compare, so there is no per-chunk cost.
- Added two unit tests: a fresh copy of the same transcript reads equal (the effect stops), and durable metadata missing from the local row reads as a difference (the snapshot still wins).
Test plan
-
pnpm testfor the affected file (6 passed) -
pnpm check(format, lint, types — clean)
Why
Users with a chat thread open sit in a passive-effect render loop that wastes CPU on the product's core chat surface and eventually crashes the panel.
Created with PostHog Desktop from this inbox report.
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.