Skip to content

Commit 910d6f0

Browse files
committed
refactor: Remove optimistic update logic from bookmark toggle mutation
1 parent 665637d commit 910d6f0

File tree

1 file changed

+1
-17
lines changed

1 file changed

+1
-17
lines changed

src/components/BookmarkStatus.tsx

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,30 +32,14 @@ const BookmarkStatus: React.FC<Props> = ({
3232
mutationFn: () =>
3333
bookmarkAction.toggleResourceBookmark({ resource_id, resource_type }),
3434

35-
// Optimistic update before mutation
36-
onMutate: async () => {
37-
// Cancel any ongoing fetch to prevent race conditions
38-
await status.refetch(); // optional for consistency
39-
const previousBookmarked = bookmarked;
40-
41-
// Optimistically toggle state
42-
setBookmarked((prev) => !prev);
43-
44-
return { previousBookmarked };
45-
},
46-
47-
// Revert if there's an error
48-
onError: (_err, _vars, context) => {
49-
setBookmarked(context?.previousBookmarked ?? false);
50-
},
51-
5235
// Ensure state is accurate after success
5336
onSuccess: (data) => {
5437
setBookmarked(data?.bookmarked ?? false);
5538
},
5639
});
5740

5841
const toggle = () => {
42+
setBookmarked((state) => !state);
5943
mutation.mutate();
6044
};
6145

0 commit comments

Comments
 (0)