Skip to content

Commit 14b6fd0

Browse files
authored
Merge pull request #722 from BackplaneWorks/backplane/pr-sweep-timeline-count
Retain timeline size changes without subpixel loops and count plot bytes safely
2 parents 1ab3e98 + e552491 commit 14b6fd0

3 files changed

Lines changed: 35 additions & 2 deletions

File tree

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
const { test } = require('node:test');
2+
const assert = require('node:assert/strict');
3+
4+
async function measurement(previous) {
5+
const { TimelineScroller } = await import('../../src/web/timeline-scroller.js');
6+
const s = Object.create(TimelineScroller.prototype);
7+
let height = 100;
8+
Object.assign(s, { _measureAll: true, _observer: null, _dirty: new Set(),
9+
mounted: new Map([['row', { wrapper: { getBoundingClientRect: () => ({ height }) } }]]),
10+
_byKey: new Map([['row', {}]]), sizes: previous === undefined ? {} : { row: previous } });
11+
return { s, set: value => { height = value; } };
12+
}
13+
14+
test('alternating DOMRect rounding noise does not keep requesting plans', async () => {
15+
const { s, set } = await measurement(100);
16+
let changed = 0;
17+
for (let i = 0; i < 100; i++) { set(100 + (i % 2 ? 1 / 65536 : 0)); changed += Number(s._readSizes()); }
18+
assert.equal(changed, 0);
19+
assert.equal(s.sizes.row, 100);
20+
});
21+
test('genuine fractional-pixel changes and first measurements are retained', async () => {
22+
const { s, set } = await measurement();
23+
assert.equal(s._readSizes(), true);
24+
set(100.25); assert.equal(s._readSizes(), true); assert.equal(s.sizes.row, 100.25);
25+
assert.equal(s._readSizes(), false);
26+
});
27+
test('a retired row never restores a measured size', async () => {
28+
const { s } = await measurement(); s._byKey.clear();
29+
assert.equal(s._readSizes(), false); assert.equal(s.sizes.row, undefined);
30+
});

‎src/server/server.bend‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2335,7 +2335,7 @@ def Hub.push.bin(h: Hub, +client: U32, +bs: List<&2, U32>) -> IO(Hub):
23352335
match h:
23362336
case Hub{st, f, ls, cl, as, inbox, cfg, note}:
23372337
do IO<Hub>:
2338-
cl2 : List<&2, Client> <- Wire.to.raw(cl, client, WBin{bs}, List.length(&2, U32, bs))
2338+
cl2 : List<&2, Client> <- Wire.to.raw(cl, client, WBin{bs}, W.Http.count(bs))
23392339
return Hub{st, f, ls, cl2, as, inbox, cfg, note}
23402340

23412341
# a ping answered through the client's credit

‎src/web/timeline-scroller.js‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,10 @@ export class TimelineScroller {
193193
const { wrapper } = row;
194194
const height = wrapper.getBoundingClientRect().height;
195195
RR?.n("tl.measure.row");
196-
if (this.sizes[key] !== height) {
196+
const previous = this.sizes[key];
197+
// Translated DOMRects jitter by tiny fractions of a CSS pixel.
198+
// Preserve real size changes without feeding noise into the planner.
199+
if (previous === undefined || Math.abs(previous - height) > 0.001) {
197200
this.sizes[key] = height;
198201
changed = true;
199202
}

0 commit comments

Comments
 (0)