mirror of
https://github.com/multica-ai/multica.git
synced 2026-07-05 13:29:44 +02:00
In a new chat (no active session), the first send momentarily rendered ChatMessageSkeleton before the user's message appeared. Root cause: ensureSession called setActiveSession(newId) immediately after creating the session, *before* handleSend wrote the optimistic message to the chatKeys.messages(sessionId) cache. useQuery's first subscription to the new key saw no data → isLoading=true → showSkeleton rendered for one frame. Apply TanStack Query's "seed the cache before subscription" pattern: move setActiveSession out of ensureSession and into the callers, after they've primed the messages cache. handleSend writes the optimistic user message first, then flips activeSessionId; handleUploadFile seeds an empty array first, then flips. useQuery's first read hits cache synchronously and ChatMessageList mounts directly — no Skeleton frame. This is a distinct race from the chat-done flicker fixed in #2509 (unmount/mount on reply completion); both share the same prime-before- subscribe shape. Co-authored-by: multica-agent <github@multica.ai>