The best way to control Claude Code, Codex and more from any computer or phone
fix(web): a failed reaction toggle no longer clears a newer reaction choice (#37853)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
Wout Stiens committed
Nov 17, 2026 at 03:42 UTC
26f70e72fa4ca3fb4144b46d3001f5584e030ebe
5 files changed
+64
-10
apps/mobile/src/features/pull-requests/PullRequestReactions.tsx
+6
-2
@@ -1,6 +1,7 @@
1
import { useNavigation } from "@react-navigation/native";
2
import {
3
applyPendingPullRequestReactions,
4
+ type PendingPullRequestReaction,
5
PULL_REQUEST_REACTION_ORDER,
6
pullRequestReactionEmoji,
7
pullRequestReactionName,
@@ -26,7 +27,8 @@ import { useAtomCommand } from "../../state/use-atom-command";
27
import { pullRequestTarget, type PullRequestParams } from "./usePullRequestDiff";
28
import { usePullRequestPermissions } from "./usePullRequestPermissions";
29
29
-const EMPTY_PENDING: ReadonlyMap<PullRequestReactionContent, boolean> = new Map();
30
+const EMPTY_PENDING: ReadonlyMap<PullRequestReactionContent, PendingPullRequestReaction> =
31
+ new Map();
32
const PILL = "min-h-8 flex-row items-center gap-1 rounded-full border px-2.5 active:opacity-70";
33
34
function ReactionPills(props: {
@@ -45,7 +47,8 @@ function ReactionPills(props: {
47
const values = pending.signature === signature ? pending.values : EMPTY_PENDING;
48
const shown = applyPendingPullRequestReactions(props.reactions, values);
49
const toggle = async (content: PullRequestReactionContent, reacted: boolean) => {
48
- setPending({ signature, values: new Map([...values, [content, reacted]]) });
50
+ const entry: PendingPullRequestReaction = { reacted };
51
+ setPending({ signature, values: new Map([...values, [content, entry]]) });
52
const result = await setReaction({
53
...target,
54
input: {
@@ -57,6 +60,7 @@ function ReactionPills(props: {
60
});
61
if (AsyncResult.isFailure(result)) {
62
setPending((current) => {
63
+ if (current.values.get(content) !== entry) return current;
64
const next = new Map(current.values);
65
next.delete(content);
66
return { signature: current.signature, values: next };
apps/web/src/components/pullRequest/PullRequestReactions.browser.test.tsx
new
+42
@@ -0,0 +1,42 @@
1
+import { EnvironmentId, ProjectId } from "@t3tools/contracts";
2
+import { expect, it, vi } from "vite-plus/test";
3
+import { userEvent } from "vite-plus/test/browser";
4
+
5
+import { act, render } from "../../../test/render";
6
+
7
+const state = vi.hoisted(() => ({ send: vi.fn() }));
8
+vi.mock("~/state/use-atom-command", () => ({ useAtomCommand: () => state.send }));
9
+vi.mock("~/state/pullRequests", () => ({ pullRequestEnvironment: { setReaction: {} } }));
10
+
11
+import { PullRequestReactionBar } from "./PullRequestReactions";
12
+
13
+it("keeps the latest reaction choice when an older toggle fails", async () => {
14
+ state.send.mockReset();
15
+ let failFirst = () => {};
16
+ let finishLater = () => {};
17
+ state.send
18
+ .mockReturnValueOnce(new Promise((resolve) => (failFirst = () => resolve({ _tag: "Failure" }))))
19
+ .mockReturnValue(
20
+ new Promise(
21
+ (resolve) => (finishLater = () => resolve({ _tag: "Success", value: undefined })),
22
+ ),
23
+ );
24
+ await using screen = await render(
25
+ <PullRequestReactionBar
26
+ environmentId={EnvironmentId.make("test")}
27
+ reference={{ projectId: ProjectId.make("project"), repository: "owner/repo", number: 1 }}
28
+ reactions={[{ content: "thumbs-up", count: 1, viewerHasReacted: false, actors: ["other"] }]}
29
+ canReact={true}
30
+ onRefresh={() => {}}
31
+ />,
32
+ );
33
+ await userEvent.click(screen.getByRole("button", { name: "thumbs up, 1", exact: true }));
34
+ await userEvent.click(screen.getByRole("button", { name: "thumbs up, 2", exact: true }));
35
+ await userEvent.click(screen.getByRole("button", { name: "thumbs up, 1", exact: true }));
36
+ const latest = screen.getByRole("button", { name: "thumbs up, 2", exact: true });
37
+ await expect.element(latest).toHaveAttribute("aria-pressed", "true");
38
+
39
+ await act(() => failFirst());
40
+ await expect.element(latest).toHaveAttribute("aria-pressed", "true");
41
+ await act(() => finishLater());
42
+});
apps/web/src/components/pullRequest/PullRequestReactions.tsx
+7
-3
@@ -16,6 +16,7 @@ import { toastManager } from "../ui/toast";
16
import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
17
import {
18
applyPendingPullRequestReactions,
19
+ type PendingPullRequestReaction,
20
PULL_REQUEST_REACTION_ORDER,
21
pullRequestReactionEmoji,
22
pullRequestReactionName,
@@ -26,7 +27,8 @@ import {
27
const PILL_CLASS =
28
"inline-flex h-6 shrink-0 items-center gap-1 rounded-full border px-2 text-xs outline-none transition-colors focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring";
29
29
-const EMPTY_PENDING: ReadonlyMap<PullRequestReactionContent, boolean> = new Map();
30
+const EMPTY_PENDING: ReadonlyMap<PullRequestReactionContent, PendingPullRequestReaction> =
31
+ new Map();
32
33
export function PullRequestReactionBar({
34
reactions,
@@ -49,7 +51,7 @@ export function PullRequestReactionBar({
51
const [pickerOpen, setPickerOpen] = useState(false);
52
const [pending, setPending] = useState<{
53
readonly signature: string;
52
- readonly values: ReadonlyMap<PullRequestReactionContent, boolean>;
54
+ readonly values: ReadonlyMap<PullRequestReactionContent, PendingPullRequestReaction>;
55
}>({ signature: "", values: EMPTY_PENDING });
56
const setReaction = useAtomCommand(pullRequestEnvironment.setReaction, {
57
reportFailure: false,
@@ -60,7 +62,8 @@ export function PullRequestReactionBar({
62
const shown = applyPendingPullRequestReactions(reactions, values);
63
64
const toggle = async (content: PullRequestReactionContent, reacted: boolean) => {
63
- setPending({ signature, values: new Map([...values, [content, reacted]]) });
65
+ const entry: PendingPullRequestReaction = { reacted };
66
+ setPending({ signature, values: new Map([...values, [content, entry]]) });
67
const result = await setReaction({
68
environmentId,
69
input: {
@@ -72,6 +75,7 @@ export function PullRequestReactionBar({
75
});
76
if (result._tag === "Failure") {
77
setPending((current) => {
78
+ if (current.values.get(content) !== entry) return current;
79
const next = new Map(current.values);
80
next.delete(content);
81
return { signature: current.signature, values: next };
packages/client-runtime/src/pullRequestReactions.test.ts
+2
-3
@@ -50,9 +50,8 @@ describe("comment reaction permissions", () => {
50
});
51
52
describe("pending reactions", () => {
53
- const pending = (
54
- entries: ReadonlyArray<readonly [PullRequestReactionContent, boolean]>,
55
- ): ReadonlyMap<PullRequestReactionContent, boolean> => new Map(entries);
53
+ const pending = (entries: ReadonlyArray<readonly [PullRequestReactionContent, boolean]>) =>
54
+ new Map(entries.map(([content, reacted]) => [content, { reacted }] as const));
55
56
it("adds a reaction nobody had yet, in picker order", () => {
57
const applied = applyPendingPullRequestReactions(
packages/client-runtime/src/pullRequestReactions.ts
+7
-2
@@ -89,13 +89,18 @@ export function pullRequestReactionsSignature(
89
.join(" ");
90
}
91
92
+/** One toggle awaiting the host. Its identity tells it apart from a later toggle of the same reaction. */
93
+export interface PendingPullRequestReaction {
94
+ readonly reacted: boolean;
95
+}
96
+
97
export function applyPendingPullRequestReactions(
98
reactions: ReadonlyArray<PullRequestReaction>,
94
- pending: ReadonlyMap<PullRequestReactionContent, boolean>,
99
+ pending: ReadonlyMap<PullRequestReactionContent, PendingPullRequestReaction>,
100
): ReadonlyArray<PullRequestReaction> {
101
if (pending.size === 0) return reactions;
102
const byContent = new Map(reactions.map((reaction) => [reaction.content, reaction] as const));
98
- for (const [content, reacted] of pending) {
103
+ for (const [content, { reacted }] of pending) {
104
const current = byContent.get(content);
105
if (current === undefined) {
106
if (reacted) {