Fix stale image contexts after chat input removal by wgqqqqq · Pull Request #117 · GCWing/BitFun
Summary
Fix a chat input state sync bug where removing an image from the input UI did
not always remove the underlying image context from the store.
In the broken flow:
- A user attached an image without configuring an image understanding model
- Sending failed once as expected
- The user removed the image and tried sending text only
- The old image context was still included in the next request, so the same
error kept happening until app restart
Root Cause
RichTextInput and the global contextStore could get out of sync.
The image tag could be removed from the editor DOM, but the corresponding
context item could remain in store state. Later sends looked like text-only
messages in the UI, while the backend still received stale image contexts.
Changes
- Update RichTextInput to derive active contexts from the currently visible
DOM tags before propagating input changes - Update ChatInput to remove context-store entries that are no longer present
in the editor - Keep image/context state aligned after inline tag removal, including the
failed-send recovery path
Result
After an image-triggered send error, removing the image from the chat input
now fully clears its context. Users can continue with text-only messages
immediately, without restarting the app.