Skip to content

Commit 366567a

Browse files
matt2eclaude
andauthored
fix(desktop): dedupe react-dismissable-layer to stop modal menu → dialog freezes (#1899)
Signed-off-by: Matt Toohey <[email protected]> Co-authored-by: Claude Fable 5 <[email protected]>
1 parent 40fe650 commit 366567a

6 files changed

Lines changed: 170 additions & 101 deletions

File tree

‎desktop/playwright.config.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ export default defineConfig({
6969
"**/threadpane-ultrawide.spec.ts",
7070
"**/animated-avatar.spec.ts",
7171
"**/reminders.spec.ts",
72+
"**/reminder-click-repro.spec.ts",
7273
"**/virtualization.spec.ts",
7374
"**/scroll-history.spec.ts",
7475
"**/channel-dense-second-reach.spec.ts",

‎desktop/src/features/sidebar/ui/CustomChannelSection.tsx‎

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -411,11 +411,7 @@ export function ChannelGroupSection({
411411
items.length > 0 ? (
412412
<SidebarMenu data-testid={listTestId}>
413413
{items.map((channel) => (
414-
// modal={false}: menu items (e.g. Leave channel) open a modal
415-
// AlertDialog. A modal ContextMenu would leave `pointer-events: none`
416-
// stuck on <body> when it closes as the dialog mounts, freezing the
417-
// whole app. Non-modal avoids installing that body guard entirely.
418-
<ContextMenu key={channel.id} modal={false}>
414+
<ContextMenu key={channel.id}>
419415
<ContextMenuTrigger asChild>
420416
<SidebarMenuItem className="content-visibility-auto-row">
421417
{draggable ? (
@@ -610,10 +606,7 @@ export function CustomChannelSection({
610606
)}
611607
data-section-actions-open={actionsMenuOpen || undefined}
612608
>
613-
{/* modal={false}: Rename/Delete section open a modal dialog;
614-
a modal ContextMenu would leave `pointer-events: none` stuck on
615-
<body> after it closes, freezing the app. */}
616-
<ContextMenu modal={false}>
609+
<ContextMenu>
617610
<ContextMenuTrigger asChild>
618611
<div className="relative" {...dragHandleProps}>
619612
<SidebarGroupLabel asChild>
@@ -702,10 +695,7 @@ export function CustomChannelSection({
702695
{channels.length > 0 ? (
703696
<SidebarMenu>
704697
{channels.map((channel) => (
705-
// modal={false}: see note on the other channel ContextMenu
706-
// above — avoids the pointer-events lockup when Leave
707-
// channel's AlertDialog opens.
708-
<ContextMenu key={channel.id} modal={false}>
698+
<ContextMenu key={channel.id}>
709699
<ContextMenuTrigger asChild>
710700
<SidebarMenuItem>
711701
<DraggableChannelRow channelId={channel.id}>
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
import { expect, test } from "@playwright/test";
2+
3+
import { waitForAnimations } from "../helpers/animations";
4+
import { installMockBridge } from "../helpers/bridge";
5+
6+
/**
7+
* Regression suite for the "app freezes after setting a reminder" bug.
8+
*
9+
* The app used to bundle two copies of @radix-ui/react-dismissable-layer
10+
* (react-menu resolved 1.1.11 while react-dialog resolved 1.1.15). Each copy
11+
* keeps its own module-level `originalBodyPointerEvents`, so when a *modal*
12+
* menu opened a *modal* dialog in the same React commit, the dialog's copy
13+
* saved the menu's `pointer-events: none` as the "original" body style and
14+
* restored it when the dialog closed — leaving `pointer-events: none` stuck
15+
* on <body> and deadening the whole app to the mouse.
16+
*
17+
* The inbox row context menu hit this: its "Remind me later" item opens
18+
* RemindMeLaterDialog synchronously. Fixed by deduplicating the layer via
19+
* the pnpm override in pnpm-workspace.yaml — a single copy coordinates
20+
* nested modal layers correctly, so the menu keeps its default modal
21+
* behavior.
22+
*
23+
* Each test drives one reminder entry point through a full set-reminder
24+
* cycle, then asserts <body> pointer-events is not stuck and that a real
25+
* click still lands. The inbox right-click test fails if the dismissable
26+
* layer ever duplicates again; the message-menu tests pin the already-safe
27+
* paths.
28+
*/
29+
30+
const GENERAL_MESSAGE_ROW = "message-row";
31+
// The default mock feed's mention row (from alice, in #general) has a
32+
// channel target, so its "Remind me later" context-menu item is enabled.
33+
const INBOX_MENTION_ROW = "home-inbox-item-mock-feed-mention";
34+
35+
/**
36+
* Assert the app survived the menu → dialog → close cycle.
37+
*
38+
* The stuck state is inline `pointer-events: none` left on <body>. The buggy
39+
* restore runs when the dialog's dismissable layer unmounts — after its exit
40+
* animation — so first wait for the dialog to leave the DOM, then check the
41+
* body style, then prove clicks still land by navigating via the sidebar.
42+
*/
43+
async function expectAppAliveAfterDialogClose(
44+
page: import("@playwright/test").Page,
45+
) {
46+
await expect(page.getByRole("dialog")).toHaveCount(0);
47+
await waitForAnimations(page);
48+
expect(await page.evaluate(() => document.body.style.pointerEvents)).not.toBe(
49+
"none",
50+
);
51+
await page.getByTestId("channel-random").click();
52+
await expect(page.getByTestId("chat-title")).toHaveText("random");
53+
}
54+
55+
/** Open the Remind-me-later dialog from a message row's More-actions menu. */
56+
async function openReminderDialogFromMessageMenu(
57+
page: import("@playwright/test").Page,
58+
) {
59+
await page.goto("/");
60+
await page.getByTestId("channel-general").click();
61+
await expect(page.getByTestId("chat-title")).toHaveText("general");
62+
63+
const messageRow = page.getByTestId(GENERAL_MESSAGE_ROW).first();
64+
await messageRow.hover();
65+
await messageRow.getByRole("button", { name: "More actions" }).click();
66+
67+
const remindItem = page.getByRole("menuitem", { name: "Remind me later" });
68+
await expect(remindItem).toBeVisible();
69+
await waitForAnimations(page);
70+
await remindItem.click();
71+
72+
const dialog = page.getByRole("dialog");
73+
await expect(dialog).toBeVisible();
74+
await waitForAnimations(page);
75+
return dialog;
76+
}
77+
78+
async function expectReminderSetToast(page: import("@playwright/test").Page) {
79+
await expect(
80+
page.locator("[data-sonner-toast]").filter({ hasText: "Reminder set" }),
81+
).toBeVisible();
82+
}
83+
84+
test.describe("reminder set → app stays clickable", () => {
85+
test.beforeEach(async ({ page }) => {
86+
await installMockBridge(page);
87+
});
88+
89+
test("01 — message menu → time preset", async ({ page }) => {
90+
const dialog = await openReminderDialogFromMessageMenu(page);
91+
92+
await dialog.getByRole("button", { name: "In 30 minutes" }).click();
93+
94+
await expectReminderSetToast(page);
95+
await expectAppAliveAfterDialogClose(page);
96+
});
97+
98+
test("02 — message menu → custom time via Set reminder footer button", async ({
99+
page,
100+
}) => {
101+
const dialog = await openReminderDialogFromMessageMenu(page);
102+
103+
// The custom timestamp must be strictly in the future or the Set
104+
// reminder button stays disabled — pick tomorrow at 09:00 local time.
105+
const tomorrow = new Date(Date.now() + 24 * 60 * 60 * 1000);
106+
const date = [
107+
tomorrow.getFullYear(),
108+
String(tomorrow.getMonth() + 1).padStart(2, "0"),
109+
String(tomorrow.getDate()).padStart(2, "0"),
110+
].join("-");
111+
await dialog.getByLabel("Reminder date").fill(date);
112+
await dialog.getByLabel("Reminder time").fill("09:00");
113+
await dialog.getByRole("button", { name: "Set reminder" }).click();
114+
115+
await expectReminderSetToast(page);
116+
await expectAppAliveAfterDialogClose(page);
117+
});
118+
119+
// The regression path: only the inbox right-click stacks a modal
120+
// ContextMenu under the modal dialog. Fails if two copies of the
121+
// dismissable layer are ever bundled again — body pointer-events stays
122+
// "none" after the dialog closes and the sidebar click below times out.
123+
test("03 — inbox row right-click → Remind me later", async ({ page }) => {
124+
await page.goto("/");
125+
await expect(page.getByTestId("home-inbox")).toBeVisible();
126+
127+
const row = page.getByTestId(INBOX_MENTION_ROW);
128+
await expect(row).toBeVisible();
129+
await row.click({ button: "right" });
130+
131+
const remindItem = page.getByRole("menuitem", { name: "Remind me later" });
132+
await expect(remindItem).toBeVisible();
133+
await waitForAnimations(page);
134+
await remindItem.click();
135+
136+
const dialog = page.getByRole("dialog");
137+
await expect(dialog).toBeVisible();
138+
await waitForAnimations(page);
139+
await dialog.getByRole("button", { name: "In 30 minutes" }).click();
140+
141+
await expectReminderSetToast(page);
142+
await expectAppAliveAfterDialogClose(page);
143+
});
144+
});

‎desktop/tests/e2e/sidebar.spec.ts‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@ async function storedSidebarWidth(page: Page) {
2222
);
2323
}
2424

25-
// Regression guard for the "Leave channel" lockup: opening a modal AlertDialog
26-
// from a modal Radix ContextMenu leaves `pointer-events: none` stuck on <body>
27-
// after the dialog closes, freezing the whole app. The fix makes the sidebar
28-
// context menus non-modal. This asserts the app is still interactive.
25+
// Regression guard for the "Leave channel" lockup: with two bundled copies of
26+
// @radix-ui/react-dismissable-layer, opening a modal AlertDialog from a modal
27+
// Radix ContextMenu left `pointer-events: none` stuck on <body> after the
28+
// dialog closed, freezing the whole app. Fixed by the pnpm override in
29+
// pnpm-workspace.yaml deduplicating the layer. This asserts the app is still
30+
// interactive.
2931
async function expectAppClickable(page: Page) {
3032
await expect
3133
.poll(() =>

0 commit comments

Comments
 (0)