Skip to content

Conversation

@ammar-agent
Copy link
Collaborator

Summary

Fix two performance issues identified via Chrome DevTools profiling:

1. Fix Layout Shift (CLS = 0.39 β†’ <0.1)

The thinking indicator in ReasoningMessage was conditionally rendered, causing elements below to shift when it appeared/disappeared. This contributed 0.32 to the CLS score alone.

Fix: Always render the container and use CSS height/opacity transitions instead of conditional rendering. Track expanded height with useLayoutEffect for smooth animations.

2. Reduce React Long Tasks (719ms β†’ shorter, interruptible)

Chrome profiling showed performWorkUntilDeadline running for up to 719ms during message list updates, blocking the main thread.

Fix:

  • Wrap mergeConsecutiveStreamErrors in useMemo for memoization
  • Use useDeferredValue for the message list rendering
  • Allows React to defer heavy reconciliation during streaming, keeping UI responsive

Testing

  • make typecheck βœ…
  • make lint βœ…

Generated with mux

@chatgpt-codex-connector
Copy link

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

Fix two performance issues identified via Chrome DevTools profiling:

1. Fix layout shift (CLS = 0.39 β†’ <0.1) in ReasoningMessage
   - The thinking indicator was conditionally rendered, causing elements
     below to shift when it appeared/disappeared
   - Now always renders the container and uses CSS height/opacity transitions
   - Tracks expanded height with useLayoutEffect for smooth animations

2. Reduce React long tasks (719ms β†’ shorter, interruptible)
   - Wrap mergeConsecutiveStreamErrors in useMemo
   - Use useDeferredValue for the message list rendering
   - Allows React to defer heavy reconciliation during streaming

_Generated with mux_
@ammar-agent ammar-agent force-pushed the fix-cls-react-long-tasks branch from 3483583 to 69c3965 Compare December 9, 2025 03:13
@ammario ammario merged commit 5cc443d into main Dec 9, 2025
19 checks passed
@ammario ammario deleted the fix-cls-react-long-tasks branch December 9, 2025 03:32
ammario pushed a commit that referenced this pull request Dec 9, 2025
## Summary

Fixes a UX issue where there was an occasional delay between sending a
message and it appearing in the chat window. During this delay, the
input was cleared but the user message wasn't visible anywhere.

### Root Cause

`useDeferredValue` (added in #1004 to improve streaming performance) was
deferring **all** message list updates, including new user messages.
This is correct for streaming deltas (where rapid updates benefit from
deferral) but wrong for user-initiated messages (where immediate
feedback is expected).

### Fix

Compare the message counts between the current and deferred values:
- **Count differs** (new message added) β†’ Show immediately
- **Count same** (content changes in existing messages) β†’ Defer for
performance

This preserves the streaming optimization while ensuring user messages
appear instantly.

### Testing

- `make static-check` βœ…
- `make test` on WorkspaceStore βœ…

_Generated with `mux`_
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants