Fix embeds intermittently lost until page refresh#1
Closed
RobbyV2 wants to merge 1 commit into
Closed
Conversation
EmbedsResolved arrives as a separate ws event from the message it belongs to, with no ordering guarantee tying it to the message being present in the store. The handler applied embeds only via patchMessage, a silent no-op when the target message is not yet in any cache; merge also lets a later duplicate message echo (embeds: []) clobber embeds already applied. Both drop the embed until a refresh reloads history with embeds baked in. Buffer resolved embeds in a bounded map keyed by message id and enrich every recent-message insertion from it, so embeds survive regardless of event ordering. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Review these changes at https://app.gitnotebooks.com/RobbyV2/RChat/pull/1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Embeds occasionally never render until the page is refreshed.
Embed resolution is fully async on the backend: a fire-and-forget task fetches the link preview and broadcasts a separate
EmbedsResolvedws event, decoupled from theMessageevent with no ordering guarantee tying the embed to the message being present in the store.The
embeds_resolvedhandler applied embeds only throughpatchMessage, which silently no-ops when the target message isn't in any cache at that instant (message merged after the event, or the real id still sitting in the optimistic outbox). Separately,mergegives precedence to incoming messages, so a late duplicatemessageecho carryingembeds: [](the POST response / ws echo of a freshly sent message) clobbers embeds already applied. Either path drops the embed until a refresh reloads history with embeds baked in from the DB.Fix
Buffer resolved embeds in a bounded (256-entry FIFO) map keyed by message id, and enrich every recent-message insertion (
drain, wsmessagemerges for channel and thread,openChannel/openDm/openThreadfetches, poll refresh) from it via a smallapplyEmbedshelper. Embeds now survive regardless ofEmbedsResolvedvsMessageordering.embeds_removedkeeps the buffer consistent so a removed embed doesn't reappear on a later insert.Tests
Added two
store_reducercases: embed resolving before the message is inserted still lands, and a later duplicatemessageecho does not clobber resolved embeds. Full suite 47/47, eslint clean,tsc --noEmitclean.🤖 Generated with Claude Code