Skip to content

[Bug]: A failed reaction toggle clears a newer reaction choice #37852

Closed

Description

@StiensWout

Before submitting

  • I searched existing issues and did not find a duplicate.
  • I included enough detail to reproduce or investigate the problem.

Area

apps/web

Steps to reproduce

  1. Open a pull request with a thumbs-up reaction from another person and no thumbs-up from you.
  2. With requests delayed, click thumbs up to add your reaction.
  3. Click thumbs up again to remove it.
  4. Click thumbs up again to add it.
  5. Let the first request fail while the later requests are still pending.

Expected behavior

Your latest choice stays selected with the count including your reaction while its request is pending.

Actual behavior

The thumbs-up becomes unselected and its count drops, even though your latest add request is still pending.

Impact

Minor bug or occasional failure. People toggling the same reaction repeatedly during a slow or failing connection see an older failure undo their latest displayed choice.

Version or commit

main at 959f422d45. The cause is at apps/web/src/components/pullRequest/PullRequestReactions.tsx:76.

Environment

Linux x64, the repository's own tests.

Logs or stack traces

AssertionError: expected 'false' to be 'true'
Automated repro

Fails in 2 of 2 runs on main: apply the patch with git apply, then run the command.

diff --git a/apps/web/src/components/pullRequest/PullRequestReactions.browser.test.tsx b/apps/web/src/components/pullRequest/PullRequestReactions.browser.test.tsx
new file mode 100644
index 0000000000..f474924449
--- /dev/null
+++ b/apps/web/src/components/pullRequest/PullRequestReactions.browser.test.tsx
@@ -0,0 +1,44 @@
+import { EnvironmentId, ProjectId } from "@t3tools/contracts";
+import { expect, it, vi } from "vite-plus/test";
+import { userEvent } from "vite-plus/test/browser";
+
+import { act, render } from "../../../test/render";
+
+const state = vi.hoisted(() => ({ send: vi.fn() }));
+vi.mock("~/state/use-atom-command", () => ({ useAtomCommand: () => state.send }));
+vi.mock("~/state/pullRequests", () => ({ pullRequestEnvironment: { setReaction: {} } }));
+
+import { PullRequestReactionBar } from "./PullRequestReactions";
+
+it("keeps the latest reaction choice when an older toggle fails", async () => {
+  state.send.mockReset();
+  const first = Promise.withResolvers<{ _tag: "Failure" }>();
+  const later = Promise.withResolvers<{ _tag: "Success"; value: undefined }>();
+  state.send.mockReturnValueOnce(first.promise).mockReturnValue(later.promise);
+  await using screen = await render(
+    <PullRequestReactionBar
+      environmentId={EnvironmentId.make("test")}
+      reference={{ projectId: ProjectId.make("project"), repository: "owner/repo", number: 1 }}
+      reactions={[{ content: "thumbs-up", count: 1, viewerHasReacted: false, actors: ["other"] }]}
+      canReact={true}
+      onRefresh={() => {}}
+    />,
+  );
+  await userEvent.click(screen.getByRole("button", { name: "thumbs up, 1", exact: true }));
+  await userEvent.click(screen.getByRole("button", { name: "thumbs up, 2", exact: true }));
+  await userEvent.click(screen.getByRole("button", { name: "thumbs up, 1", exact: true }));
+  await expect
+    .element(screen.getByRole("button", { name: "thumbs up, 2", exact: true }))
+    .toHaveAttribute("aria-pressed", "true");
+
+  await act(() => first.resolve({ _tag: "Failure" }));
+  expect(
+    screen.container
+      .querySelector('button[aria-label^="thumbs up,"]')
+      ?.getAttribute("aria-pressed"),
+  ).toBe("true");
+  expect(screen.container.querySelector('button[aria-label^="thumbs up,"]')?.textContent).toContain(
+    "2",
+  );
+  await act(() => later.resolve({ _tag: "Success", value: undefined }));
+});
cd apps/web && pnpm exec vp test run src/components/pullRequest/PullRequestReactions.browser.test.tsx

Workaround

No response

Activity

  1. added
    vouch:trusted
    on Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    vouch:trusted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions