Skip to content

Commit 07d0265

Browse files
wesbillmanCarl
andauthored
fix(desktop): retire prepend mode on every reader wheel (#2913)
## Summary - retire Virtua prepend reconciliation on every ordinary reader wheel event, including events suppressed from its separate wheel-timing heuristic - keep Ctrl+wheel browser zoom excluded from reader ownership - arm the Ctrl+wheel prepend probe before pagination begins so it cannot miss the commit - preserve ESM/CJS patch parity and update the patch lock hash ## Why main was red PR #2855 added the reader-wheel retirement action after Virtua's existing suppression guard. Once the first event set that guard, later events in the same wheel burst returned before retiring prepend mode. A late ResizeObserver correction could then pull the viewport backward by 20–40px. The same test had failed twice on #2855 but passed its final retry, so the PR job appeared green; the merge commit lost all three retries. The separate Ctrl+wheel failure was a test race: its MutationObserver was registered after the request had already been triggered and could miss the prepend commit. ## Validation - desktop full unit suite: 3,515 passed - pre-push desktop check: passed - `git diff --check`: passed - CI is the E2E verification; no local E2E was run Fixes the main-branch failure in CI run 30180099007. Signed-off-by: Wes <[email protected]> Co-authored-by: Carl <c7ebe626f000404285d3686e1dc74cc07cc60a9754a150041ba132e14bd3e2ec@buzz.block.builderlab.xyz>
1 parent 25e7864 commit 07d0265

4 files changed

Lines changed: 49 additions & 33 deletions

File tree

‎desktop/src/features/messages/ui/virtuaWheelModePatch.test.mjs‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,17 @@ test("reader wheel retires Virtua shift mode without publishing scroll end", ()
2121
.filter(Boolean),
2222
);
2323
assert.deepEqual(addedActionBodies, [["I = 0;"], ["w = 0;"]]);
24-
assert.match(patch, /\+\s+e\.q\(9\);/);
25-
assert.match(patch, /\+\s+e\.B\(9\);/);
24+
assert.match(
25+
patch,
26+
/if \(!e\.M\(\) \|\| t\.ctrlKey\) return;\n\+\s+e\.q\(9\);\n\+\s+if \(f\) return;/,
27+
);
28+
assert.match(
29+
patch,
30+
/if \(!e\.M\(\) \|\| t\.ctrlKey\) return;\n\+\s+e\.B\(9\);\n\+\s+if \(c\) return;/,
31+
);
32+
assert.doesNotMatch(
33+
patch,
34+
/\+\s+if \((?:f|c) \|\| !e\.M\(\) \|\| t\.ctrlKey\) return;/,
35+
);
2636
assert.doesNotMatch(patch, /\+\s+e\.(?:q|B)\(2\);/);
2737
});

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

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,29 @@ test.describe("list virtualization", () => {
252252
});
253253
await page.waitForTimeout(150);
254254
const before = await sampleVisibleAnchor();
255+
const ctrlWheelPromise =
256+
pageIndex === 0
257+
? timeline.evaluate(
258+
(scroller) =>
259+
new Promise<boolean>((resolve) => {
260+
const s = scroller as HTMLElement;
261+
const observer = new MutationObserver(() => {
262+
observer.disconnect();
263+
// Ctrl+wheel is browser zoom, not reader scroll intent. Fire
264+
// it synchronously with the prepend DOM commit, before the
265+
// ResizeObserver measurement batch reconciles estimated rows.
266+
s.dispatchEvent(
267+
new WheelEvent("wheel", { ctrlKey: true, deltaY: -100 }),
268+
);
269+
resolve(true);
270+
});
271+
observer.observe(s.firstElementChild ?? s, {
272+
childList: true,
273+
subtree: true,
274+
});
275+
}),
276+
)
277+
: Promise.resolve(false);
255278
const wheelTracePromise = timeline.evaluate(async (scroller) => {
256279
const s = scroller as HTMLElement;
257280
let previousScrollTop = s.scrollTop;
@@ -297,25 +320,8 @@ test.describe("list virtualization", () => {
297320
});
298321
const committedAnchor = await sampleVisibleAnchor(before.id);
299322
const motion = await timeline.evaluate(
300-
async (scroller, { anchorId, anchorTop, oldHeight, testCtrlWheel }) => {
323+
async (scroller, { anchorId, anchorTop, oldHeight }) => {
301324
const s = scroller as HTMLElement;
302-
let ctrlWheelDispatched = false;
303-
const mutationObserver = testCtrlWheel
304-
? new MutationObserver(() => {
305-
if (ctrlWheelDispatched) return;
306-
ctrlWheelDispatched = true;
307-
// Ctrl+wheel is browser zoom, not reader scroll intent. Fire it
308-
// synchronously with the prepend DOM commit, before the
309-
// ResizeObserver measurement batch reconciles estimated rows.
310-
s.dispatchEvent(
311-
new WheelEvent("wheel", { ctrlKey: true, deltaY: -100 }),
312-
);
313-
})
314-
: null;
315-
mutationObserver?.observe(s.firstElementChild ?? s, {
316-
childList: true,
317-
subtree: true,
318-
});
319325
let maxDrift = 0;
320326
let sawPrepend = false;
321327
let sawAnchorAfterPrepend = false;
@@ -343,20 +349,16 @@ test.describe("list virtualization", () => {
343349
if (sawAnchorAfterPrepend && stableFrames >= 8) break;
344350
await new Promise((resolve) => requestAnimationFrame(resolve));
345351
}
346-
mutationObserver?.disconnect();
347-
return { ctrlWheelDispatched, maxDrift, sawPrepend };
352+
return { maxDrift, sawPrepend };
348353
},
349354
{
350355
anchorId: committedAnchor.id,
351356
anchorTop: committedAnchor.top,
352357
oldHeight: before.scrollHeight,
353-
// Exercise browser-zoom input once while a real prepend transaction
354-
// still owns its measurement reconciliation.
355-
testCtrlWheel: pageIndex === 0,
356358
},
357359
);
358360
expect(motion.sawPrepend).toBe(true);
359-
if (pageIndex === 0) expect(motion.ctrlWheelDispatched).toBe(true);
361+
if (pageIndex === 0) expect(await ctrlWheelPromise).toBe(true);
360362
expect(motion.maxDrift).toBeLessThan(5);
361363

362364
await expect

‎patches/[email protected]‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,13 @@ index e02dfd0b3db60faff2cc705d7ce0aa51cb958f5a..b12677a356f748ebccf6e16cb781efe1
5454
}
5555
l && (d = 1 + (2147483647 & d), o && z && ($ += z, z = 0), O.forEach(([e, t]) => {
5656
l & e && t(n);
57-
@@ -186,6 +198,7 @@ const r = null, {min: n, max: s, abs: i, floor: l} = Math, c = (e, t, o) => n(o,
57+
@@ -186,6 +198,8 @@ const r = null, {min: n, max: s, abs: i, floor: l} = Math, c = (e, t, o) => n(o,
5858
c = l(), d && (a = !0), i && e.q(6, i()), e.q(1, n()), h();
5959
}, p = t => {
60-
if (f || !e.M() || t.ctrlKey) return;
60+
- if (f || !e.M() || t.ctrlKey) return;
61+
+ if (!e.M() || t.ctrlKey) return;
6162
+ e.q(9);
63+
+ if (f) return;
6264
const r = l() - c;
6365
150 > r && 50 < r && (o ? t.deltaX : t.deltaY) && (f = !0);
6466
}, v = () => {
@@ -150,11 +152,13 @@ index 110ac3858a002a6cdb698da2b56350bc1bf609d2..db83efc83fb3b6d7aa07d83b7463d6ed
150152
}
151153
d && (i = 1 + (2147483647 & i), o && p && (g += p, p = 0), O.forEach(([e, t]) => {
152154
d & e && t(n);
153-
@@ -190,6 +202,7 @@ const u = null, {min: d, max: a, abs: h, floor: g} = Math, p = (e, t, o) => d(o,
155+
@@ -190,6 +202,8 @@ const u = null, {min: d, max: a, abs: h, floor: g} = Math, p = (e, t, o) => d(o,
154156
l = i(), d && (a = !0), s && e.B(6, s()), e.B(1, n()), h();
155157
}, p = t => {
156-
if (c || !e.M() || t.ctrlKey) return;
158+
- if (c || !e.M() || t.ctrlKey) return;
159+
+ if (!e.M() || t.ctrlKey) return;
157160
+ e.B(9);
161+
+ if (c) return;
158162
const n = i() - l;
159163
150 > n && 50 < n && (o ? t.deltaX : t.deltaY) && (c = !0);
160164
}, v = () => {

‎pnpm-lock.yaml‎

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)