fix(ChatMessages): re-evaluate streaming indicator on each render#6673
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe Estimated code review effort: 2 (Simple) | ~10 minutes Changes
Sequence Diagram(s)sequenceDiagram
participant Test
participant ChatMessages
participant showIndicator
Test->>ChatMessages: mount with shallowRef(messages)
ChatMessages->>showIndicator: showIndicator()
showIndicator-->>ChatMessages: true (assistant, no parts)
Test->>Test: mutate message.parts in place
Test->>ChatMessages: triggerRef + nextTick
ChatMessages->>showIndicator: showIndicator()
showIndicator-->>ChatMessages: false (parts present)
Related issues: None specified. Related PRs: None specified. Suggested labels: bug, chat, tests Suggested reviewers: None specified. 🐰 A rabbit taps its little screen, 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
commit: |
🔗 Linked issue
❓ Type of change
📚 Description
When the server assigns an id to the assistant message (
toUIMessageStream({ generateMessageId }), common when persisting messages), theUChatMessagesloading indicator stayed visible below the streaming answer for the whole response instead of disappearing once the first content arrived.The cause was a stale
computed. With AI SDK v7,@ai-sdk/vuestores messages in ashallowRefand grows them via in place mutation plustriggerRef, so the array reference and the message objects never change identity.showIndicatorreadslastMessage.parts?.length, but that nested read is never tracked, so thecomputedcached its result on the firststreamingrender (when a server assigned id has already materialised an empty assistant message) and only recomputed once the status flipped toreadyat the end.The fix turns
showIndicatorinto a plain function evaluated on every render, which ties it to the same re-render that displays the streamed content. This is a v7 only regression: on v6@ai-sdk/vueuses a deep reactiverefand swaps the array on push, so thecomputedtracked correctly there, and the function stays correct under both models.Added a regression test that reproduces the reactivity model (
shallowRefplus in place mutation plustriggerRef) and fails against the previouscomputed.📝 Checklist