Repository navigation
Closed
Labels
vouch:trustedAuthor is trusted by repo permissions or the VOUCHED list.
Description
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
- Open a pull request with a thumbs-up reaction from another person and no thumbs-up from you.
- With requests delayed, click thumbs up to add your reaction.
- Click thumbs up again to remove it.
- Click thumbs up again to add it.
- 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.tsxWorkaround
No response
Metadata
Metadata
Assignees
Labels
vouch:trustedAuthor is trusted by repo permissions or the VOUCHED list.
Activity