Repository navigation
fix(ui): send only one DELETE per message when leaving with pending deletes - #1075
Open
shivampwm2020 wants to merge 1 commit into
Open
shivampwm2020 wants to merge 1 commit into
shivampwm2020 wants to merge 1 commit into
Conversation
…eletes reactions.ts registers messagesStore.executePendingDeletes on both `pagehide` and `beforeunload`, and browsers fire both when a page is left. MessagesStore.removeSingle checked `pendingDeletes.has(id)` before awaiting the request and only removed the entry after the await resolved, so the second handler passed the guard and issued a second DELETE for the same id (which 404s with "message does not exist"). Claim the pending delete up front via cancelPendingDelete() so the guard is atomic; later invocations now no-op instead of firing again. The undo snackbar is closed at the same point as before. Adds a vitest regression test covering both the page-leave double event and the snackbar onExited race (RED on master, GREEN with this fix).
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1075 +/- ##
==========================================
+ Coverage 76.54% 76.57% +0.02%
==========================================
Files 68 68
Lines 3714 3714
==========================================
+ Hits 2843 2844 +1
+ Misses 658 657 -1
Partials 213 213 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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
Deleting messages in the WebUI and then leaving/closing the tab while the undo
snackbar is still open fires two
DELETE /message/{id}requests for the samemessage. The second one 404s:
Reported in #1068 (v3.1.1, Docker).
Root cause
ui/src/reactions.ts:8-9registers the same handler on both page-leave events:Browsers fire both, and
executePendingDeletescallsremoveSinglefor everyentry in
pendingDeletes. The guard inremoveSinglewas checked before theawaited request, while the entry was only removed after it resolved:
So the second invocation passed the guard while the first request was in flight
and sent another
DELETE. The same race exists between a page-leave event andthe snackbar's
onExitedcallback (Messages.tsx:49), which also callsremoveSinglefor the same id.Fix
removeSinglenow claims the pending delete up front, making the guard atomic —the entry (and its undo snackbar) is consumed before the request is awaited, so
any later invocation for the same id is a no-op:
The trailing
cancelPendingDelete(message)after the await is removedaccordingly (the snackbar is still closed at the same point).
Testing
Added
ui/src/tests/pendingDelete.test.tscovering both races:onExitedrace for the same id.Both assert exactly one DELETE per id.
tsc --noEmit,eslint "src/**/*.{ts,tsx}"andprettier --list-differentareall clean.
Fixes #1068