CodeNomad/packages
Dark 14dfd3e371
fix(ui): throttle SSE part deltas and prevent stale delta text duplication (#536)
## Problem

Streaming responses send many `message.part.delta` events per second.
Each event triggers a Solid store mutation + re-render, causing:

1. **Mobile freezes** — KaTeX/highlight.js re-renders on every delta
block the main thread
2. **Text duplication** — When `message.part.updated` replaces a part
with the server's complete state, previously enqueued deltas would flush
AFTER the replacement, concatenating stale text onto the fresh part

## Solution

### 1. Delta throttling (50ms buffer)
Accumulate deltas in a buffer and flush every 50ms instead of updating
on every event. This batches Solid mutations and cuts main-thread
blocking during streaming.

### 2. Stale delta cleanup
When a full `message.part.updated` arrives, clear any pending deltas for
that part before applying the update. The update already contains the
complete server state, so accumulated deltas are stale.

## Changes

- `packages/ui/src/stores/session-events.ts`: Added `enqueueDelta`,
`flushDeltas`, `clearPendingDeltasForPart`; updated
`handleMessagePartDelta` and `handleMessageUpdate`

## Verification

- Build passes: `npm run build:ui`
- Tested on mobile — eliminates visible freezes during long streaming
responses
- No duplicate text observed at end of assistant messages after part
updates

---------
2026-06-13 16:42:17 +02:00
..
cloudflare Minimum version to 0.17.0 2026-06-04 21:07:53 +01:00
electron-app Increment to v0.17.1 2026-06-08 21:10:57 +01:00
opencode-plugin Increment to v0.17.1 2026-06-08 21:10:57 +01:00
server Increment to v0.17.1 2026-06-08 21:10:57 +01:00
tauri-app Increment to v0.17.1 2026-06-08 21:10:57 +01:00
ui fix(ui): throttle SSE part deltas and prevent stale delta text duplication (#536) 2026-06-13 16:42:17 +02:00