fix(web): rollback optimistic feed state on failed transaction - #1414
Open
Olajcodes wants to merge 1 commit into
Open
fix(web): rollback optimistic feed state on failed transaction#1414Olajcodes wants to merge 1 commit into
Olajcodes wants to merge 1 commit into
Conversation
Capture a deep snapshot of like/follow/tip state before each optimistic mutation in optimizerStore and restore it when the on-chain transaction reports failed, emitting a rolled-back event so the Feed can clear its transient pending styling. Add unit tests covering success, failure, and partial rollback ordering.
|
@Olajcodes Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
|
Someone is attempting to deploy a commit to the Jaja's projects Team on Vercel. A member of the Team first needs to authorize it. |
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.
Summary
When the feed applies an optimistic like/follow/tip mutation, the UI updates immediately for an instant feel. However, if the underlying on-chain transaction reports
failed, the optimistic state was never reverted — the feed kept showing a "liked" heart, a "Following" label, or a bumped tip total that was never persisted, and a later unrelated refetch would snap the UI back to server truth, causing a visible flash/unsync.This PR adds snapshot/rollback support to
optimisticStore.tsand wiresFeed.tsxto clear its transient "pending" styling when a rollback happens, so the UI always reconciles back to the pre-mutation state on failure.Type of Change
Changes
apps/web/src/lib/optimisticStore.tssnapshotLikeState(key),snapshotFollowState(key),snapshotTipState(key)rolled-backevent:rollbackLikeState,rollbackFollowState,rollbackTipStateRolledBackEventtype{ kind: "follow" | "like" | "tip"; key: string }and anonRolledBack(listener)subscription (returns an unsubscribe function) so components can clear transient "pending" styling.clearLikeState/clearTipStatecounterparts for symmetry and test cleanup.apps/web/src/components/Feed.tsxpendingLikes) while an optimistic write is in flight, showing a transientLiking...label and pulse styling.OptimisticStore.onRolledBackand clears the pending styling for the affected post when a like/follow write is rolled back after a failed transaction.apps/web/src/lib/__tests__/optimisticStore.test.ts(new)rolled-backevent.onRolledBackunsubscribe stops delivering events.Testing Done
9unit tests inapps/web/src/lib/__tests__/optimisticStore.test.ts— all passing.tsc --noEmitfromapps/web— the only reported errors are pre-existing ones inpackages/sdk(generated client:scvU64/scvSymbol/bigint typing), which are out of scope of this issue; no errors in the files changed here.cargo testpasses — N/A (frontend-only change)Checklist
Related Issue
Closes #1191