Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix(shell): remove the window blur listener leak, and guard it for real\n\nReview #5887 (YellowSnnowmann): test.fail() kept CI green on a shipping defect.\nThe annotation was honest inside the file, but the signal a maintainer sees is a\npassing suite, and the leak was recorded nowhere else. Fixing the source instead.\n\nThe drag teardown removed 'blur-sm' -- a Tailwind class name, not a DOM event --\nwhile the registration used 'blur', so removeEventListener never matched and a\nwindow listener leaked per drag at each of two sites:\n\n Sidebar.tsx:283 removeEventListener('blur-sm', detach) -> 'blur'\n RootShellLayout.tsx:185 removeEventListener('blur-sm', stop) -> 'blur'\n\nThese were the only two 'blur-sm' string literals in app/src, both inside\nremoveEventListener and neither in a className, which points at a Tailwind v4\nblur -> blur-sm class rename reaching into string arguments.\n\nThe reviewer also corrected my analysis, and he is right. I had written that the\nstale handlers were "near-silent" and their teardown "idempotent". They are not:\nRootShellLayout's stop() calls setDragWidth(null) and detach() mutates\ndocument.body.style, so every window blur fires a React state update and a style\nmutation per past drag. One nuance in his favour that neither of us stated:\ncommitWidth itself IS guarded after the first call, because dragWidthRef.current\nis nulled -- the state update and style mutation are not. The file now records\nthat precise account instead of either looser version.\n\napp-shell-listener-hygiene.spec.ts drops test.fail() and the KNOWN FAILING\nsuffix, so it is a live regression guard rather than a documented defect.\n\nVerification status, stated plainly: this exact fix was executed and green\n(8/8, including the previously-failing leak assertion) on the PRE-REBASE tree.\nIt has NOT been re-run since the rebase onto 9a631f963, because local builds and\ntest runs are now prohibited. The change is two string literals with no other\nedits, and CI is the check.\n

M3gA-Mind3869a418d6df
diff --git a/app/src/components/layout/shell/RootShellLayout.tsx b/app/src/components/layout/shell/RootShellLayout.tsx
index 8e15f7dc0c..bca788fe2d 100644
--- a/app/src/components/layout/shell/RootShellLayout.tsx
+++ b/app/src/components/layout/shell/RootShellLayout.tsx
@@ -182,7 +182,7 @@ export default function RootShellLayout({ sidebar, children, unframed }: RootShe
function detach() {
window.removeEventListener('pointerup', stop);
window.removeEventListener('pointercancel', stop);
- window.removeEventListener('blur-sm', stop);
+ window.removeEventListener('blur', stop);
document.body.style.removeProperty('cursor');
document.body.style.removeProperty('user-select');
draggingRef.current = false;
diff --git a/app/src/components/ui/Sidebar.tsx b/app/src/components/ui/Sidebar.tsx
index b4767d957e..eae4bb9451 100644
--- a/app/src/components/ui/Sidebar.tsx
+++ b/app/src/components/ui/Sidebar.tsx
@@ -280,7 +280,7 @@ export const SidebarRail = forwardRef<HTMLDivElement, SidebarRailProps>(
window.removeEventListener('pointermove', handleMove);
window.removeEventListener('pointerup', detach);
window.removeEventListener('pointercancel', detach);
- window.removeEventListener('blur-sm', detach);
+ window.removeEventListener('blur', detach);
detachRef.current = null;
};
diff --git a/app/test/playwright/specs/app-shell-listener-hygiene.spec.ts b/app/test/playwright/specs/app-shell-listener-hygiene.spec.ts
index df298ffa8c..cb7a03ee7d 100644
--- a/app/test/playwright/specs/app-shell-listener-hygiene.spec.ts
+++ b/app/test/playwright/specs/app-shell-listener-hygiene.spec.ts
@@ -26,10 +26,15 @@ test.describe.configure({ timeout: 180_000 });
* that is idempotent — so nothing fails today. What accumulates is window
* listeners, on a desktop window that is not reloaded for days.
*
+ * FIXED in this PR, at review's request: both removal sites now use `'blur'`.
* This spec instruments `add`/`removeEventListener` before the app boots and
- * counts. It is written to FAIL on `main` today: it describes the contract the
- * code intends, not the behaviour it has. See the note on the failing
- * assertion.
+ * counts, so it guards the fix rather than documenting the defect.
+ *
+ * The leak was not inert, which is what settled the disposition. Every stale
+ * handler still runs on the next window blur, and `RootShellLayout`'s `stop()`
+ * mutates `document.body.style` and calls `setDragWidth(null)` — a React state
+ * update per past drag, per blur. (`commitWidth` itself is guarded after the
+ * first call, since `dragWidthRef.current` is nulled, but the rest is not.)
*/
/** Wrap window listener registration so the test can count what is live. */
@@ -100,23 +105,16 @@ test.describe('App shell — the resize drag cleans up after itself (BUG-12)', (
await expect.poll(() => countOf(page, 'pointercancel')).toBe(before.pointercancel);
});
- test('blur listeners are balanced across a drag — KNOWN FAILING, W5 BUG-12', async ({ page }) => {
- // `test.fail()`: this asserts the contract the code intends, and that
- // contract is currently broken, so the expected outcome on `main` is a
- // failure. Playwright inverts the result — the spec is GREEN today and goes
- // RED the moment someone fixes the bug, which is the prompt to delete this
- // annotation and the note below.
- //
- // A plain red test would just be broken CI. A skipped one would say
- // nothing. This is the only form that both reports the defect and cleans
- // itself up.
+ test('blur listeners are balanced across a drag', async ({ page }) => {
+ // This was `test.fail()` until review (#5887, YellowSnnowmann): annotating
+ // it kept CI green on a shipping defect, and the only record of the leak
+ // was a prose comment in this file. Fixed at the source instead — the two
+ // `'blur-sm'` literals in `Sidebar.tsx:283` and `RootShellLayout.tsx:185`
+ // now match the `'blur'` they were registered under — so this is a live
+ // regression guard rather than a documented failure.
//
- // Measured on main: baseline 3, +2 per drag (one per leaking site), so
- // three drags end at 9. Verified fix — replace the two `'blur-sm'` string
- // literals with `'blur'` in Sidebar.tsx:283 and RootShellLayout.tsx:185 —
- // makes this pass and leaves the rest of the suite green.
- test.fail();
-
+ // Measured before the fix: baseline 3, +2 per drag (one per leaking site),
+ // so the three drags below ended at 9.
const before = await countOf(page, 'blur');
await dragRail(page, 40);