Skip to content

Commit fefbfd0

Browse files
wesbillmanPinky
andauthored
fix(messages): buffer both sides while the scroll direction is frozen (#481)
Signed-off-by: Pinky <5f5ab050ec58ae208332edd544ebf705221e24c1b86d82a6ca07038a7a8f6ac9@buzz.block.builderlab.xyz> Co-authored-by: Pinky <5f5ab050ec58ae208332edd544ebf705221e24c1b86d82a6ca07038a7a8f6ac9@buzz.block.builderlab.xyz>
1 parent 1a692d5 commit fefbfd0

4 files changed

Lines changed: 88 additions & 9 deletions

File tree

‎patches/README.md‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,28 @@ Installed-driver regressions cover both entry points and RTL; a browser regressi
2121
sets a fractional list height explicitly and requires the final row to be fully
2222
visible without a pixel tolerance.
2323

24+
## Buffer while the scroll direction is frozen
25+
26+
Virtua renders `bufferSize` only ahead of the scroll direction, and updates that
27+
direction only during native scrolling. A shift (prepended history) or imperative
28+
scroll freezes it until the 150ms inferred idle. Continuous trackpad flicks can
29+
keep it frozen: a downward flick after an upward prepend renders no rows below the
30+
viewport, and React commits one frame behind, so the leading edge stays blank for
31+
the rest of the gesture. The range therefore buffers both sides while the
32+
direction is frozen, as it already does when idle. Native directional buffering
33+
is unchanged, and the extra buffer is no larger than the idle buffer.
34+
35+
A shift otherwise counts every row resize as an anchoring correction. Rows wholly
36+
below the viewport are excluded, so a newly buffered row there that resizes (a
37+
video loading, say) cannot move the reading position. Rows above and in the
38+
viewport, including prepended history, are still corrected.
39+
40+
In an isolated WKWebView over real channel history (images, video, live relay),
41+
fast alternating flicks were measured per frame. In two instrumented runs, all 46
42+
DOM-coverage gap frames moved downward while shift mode held an upward direction.
43+
Stock showed 3–96 gap frames per run over ten runs; the patch showed none in six.
44+
Short main-thread stalls and image decode dips remain.
45+
2446
## Failure and chosen boundary
2547

2648
In a system WKWebView, native momentum can overwrite an instant programmatic

‎patches/[email protected]‎

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,29 @@ index a183cc7b1669aab25467840540ce3bd1c025fb47..d960e2ea2a9435296756a64fe3a3773b
1515
var {min: a, max: u, abs: d, floor: h} = Math, g = (e, t, n) => a(n, u(t, e)), v = e => [ ...e ].sort((e, t) => e - t), p = setTimeout, S = clearTimeout, m = "function" == typeof queueMicrotask ? queueMicrotask : e => {
1616
Promise.resolve().then(e);
1717
}, $ = () => {
18-
@@ -173,15 +177,37 @@ var {min: a, max: u, abs: d, floor: h} = Math, g = (e, t, n) => a(n, u(t, e)), v
18+
@@ -31,7 +35,9 @@ var {min: a, max: u, abs: d, floor: h} = Math, g = (e, t, n) => a(n, u(t, e)), v
19+
let n, o;
20+
if (z) [n, o] = k; else {
21+
let r = u(0, O()), i = r + S;
22+
- g || (t = u(0, t), 1 !== I && (r -= t), 2 !== I && (i += t)), [n, o] = k = e(u(0, r), u(0, i)),
23+
+ // Direction is frozen outside native scrolling, such as after a
24+
+ // shift until inferred idle; it cannot choose one buffered side.
25+
+ g || (t = u(0, t), (1 !== I || y) && (r -= t), (2 !== I || y) && (i += t)), [n, o] = k = e(u(0, r), u(0, i)),
26+
x && (n = a(n, x[0]), o = u(o, x[1]));
27+
}
28+
return [ u(n, 0), a(o, l() - 1) ];
29+
@@ -78,7 +84,9 @@ var {min: a, max: u, abs: d, floor: h} = Math, g = (e, t, n) => a(n, u(t, e)), v
30+
if (!e.length) break;
31+
L(e.reduce((e, [t, n]) => {
32+
let r;
33+
- if (2 === y) r = !0; else if (x && 1 === y) r = t < x[0]; else {
34+
+ // A shift corrects rows above the viewport end; buffered rows
35+
+ // wholly below it cannot move the reading position.
36+
+ if (2 === y) r = E(t) < M() + S; else if (x && 1 === y) r = t < x[0]; else {
37+
const e = M(), n = E(t), i = o(t);
38+
r = 1 !== I && 0 === y ? n + i <= e : n < e && n + i < e + S;
39+
}
40+
@@ -173,15 +181,37 @@ var {min: a, max: u, abs: d, floor: h} = Math, g = (e, t, n) => a(n, u(t, e)), v
1941
q: () => [ l.slice(), o ]
2042
};
2143
}, C = e => {
@@ -55,7 +77,7 @@ index a183cc7b1669aab25467840540ce3bd1c025fb47..d960e2ea2a9435296756a64fe3a3773b
5577
t && t.disconnect();
5678
}
5779
};
58-
@@ -249,10 +275,28 @@ var {min: a, max: u, abs: d, floor: h} = Math, g = (e, t, n) => a(n, u(t, e)), v
80+
@@ -249,10 +279,28 @@ var {min: a, max: u, abs: d, floor: h} = Math, g = (e, t, n) => a(n, u(t, e)), v
5981
o && o();
6082
} ];
6183
}, E = (e, t) => {
@@ -86,7 +108,7 @@ index a183cc7b1669aab25467840540ce3bd1c025fb47..d960e2ea2a9435296756a64fe3a3773b
86108
behavior: t ? "smooth" : "instant"
87109
});
88110
}), u = t ? "width" : "height", d = /* @__PURE__ */ new WeakMap, h = C(t => {
89-
@@ -263,10 +307,15 @@ var {min: a, max: u, abs: d, floor: h} = Math, g = (e, t, n) => a(n, u(t, e)), v
111+
@@ -263,10 +311,15 @@ var {min: a, max: u, abs: d, floor: h} = Math, g = (e, t, n) => a(n, u(t, e)), v
90112
}
91113
o.length && e.W(3, o);
92114
});
@@ -103,7 +125,7 @@ index a183cc7b1669aab25467840540ce3bd1c025fb47..d960e2ea2a9435296756a64fe3a3773b
103125
const e = u.style, t = e[c];
104126
e[c] = "hidden", p(() => {
105127
e[c] = t;
106-
@@ -274,7 +323,7 @@ var {min: a, max: u, abs: d, floor: h} = Math, g = (e, t, n) => a(n, u(t, e)), v
128+
@@ -274,7 +327,7 @@ var {min: a, max: u, abs: d, floor: h} = Math, g = (e, t, n) => a(n, u(t, e)), v
107129
}
108130
const r = e.T() + t;
109131
r <= 0 || r >= e.O() + e.t() - e.o() ? u.scrollTo({
@@ -112,7 +134,7 @@ index a183cc7b1669aab25467840540ce3bd1c025fb47..d960e2ea2a9435296756a64fe3a3773b
112134
behavior: "instant"
113135
}) : u.scrollBy({
114136
[l]: T(t, i),
115-
@@ -283,7 +332,9 @@ var {min: a, max: u, abs: d, floor: h} = Math, g = (e, t, n) => a(n, u(t, e)), v
137+
@@ -283,7 +336,9 @@ var {min: a, max: u, abs: d, floor: h} = Math, g = (e, t, n) => a(n, u(t, e)), v
116138
}), r[1](!0);
117139
},
118140
_() {
@@ -123,7 +145,7 @@ index a183cc7b1669aab25467840540ce3bd1c025fb47..d960e2ea2a9435296756a64fe3a3773b
123145
},
124146
P: (e, t) => (d.set(e, t), h.A(e), () => {
125147
d.delete(e), h.B(e);
126-
@@ -797,4 +848,3 @@ var {min: a, max: u, abs: d, floor: h} = Math, g = (e, t, n) => a(n, u(t, e)), v
148+
@@ -797,4 +852,3 @@ var {min: a, max: u, abs: d, floor: h} = Math, g = (e, t, n) => a(n, u(t, e)), v
127149
});
128150
-
129151
+

‎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.

‎src/features/messages/virtua-compensation.test.mjs‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,41 @@ it("does not defer while scrolling or interrupt without a correction", () => {
131131
expect(c.store.L()[0]).toBe(0);
132132
});
133133

134+
it("buffers both sides while a shift freezes the scroll direction", () => {
135+
const c = setup({ offset: 500 }); // native downward scrolling
136+
c.prepend();
137+
c.store.W(1, 2500); // compensated offset
138+
c.store.W(1, 2400); // upward movement cannot update the frozen direction
139+
expect(c.store.i(200)).toEqual([22, 31]);
140+
c.store.W(2); // inferred idle restores native direction tracking
141+
c.store.W(1, 2300);
142+
expect(c.store.i(200)).toEqual([21, 28]);
143+
});
144+
145+
it("buffers below a shift frozen upward without letting those rows move the reading position", () => {
146+
for (const [row, size, top] of [
147+
[32, 150, null], // wholly below the 2500–3000 viewport
148+
[32, 60, null],
149+
[23, 150, 50], // above it, as prepended rows are
150+
[29, 150, 50], // visible rows are still corrected
151+
[30, 150, null], // starts exactly at the viewport end
152+
]) {
153+
const c = setup({ offset: 500 });
154+
c.store.W(1, 400); // native upward scrolling
155+
c.prepend();
156+
c.store.W(1, 2400); // compensated offset
157+
c.store.W(1, 2500); // downward movement cannot update the frozen direction
158+
expect(c.store.i(200)).toEqual([23, 32]);
159+
c.calls.length = 0;
160+
c.store.W(3, [[row, size]]);
161+
c.driver.J();
162+
expect(c.calls.map((call) => call.options.top ?? null)).toEqual(
163+
top === null ? [] : [top],
164+
);
165+
c.driver._();
166+
}
167+
});
168+
134169
it("preserves absolute edge correction and RTL axis normalization", () => {
135170
for (const config of [
136171
{ offset: 1500 },

0 commit comments

Comments
 (0)