Repository navigation
Description
The swap watch, tests/swap_watch.js, runs on every page a browser test opens. It fails a test when a flex row grows or shrinks across its line as one occupant gives way to another ("Shared containers determine control dimensions" in browser/AGENTS.md). On main it judges 7 of 19 reproduction cases wrongly, as measured on Nov 6 against d9afcfcd5, whose watch differs from main's only in a comment. It misses five swaps that do resize their row, and in four cases its own ResizeObserver makes a valid page update report a "ResizeObserver loop" error that doesn't occur without the watch, in Chromium and Firefox. So it lets real regressions through, and it fails tests, and possibly nightly journeys, on loop errors the page doesn't cause.
The 19 cases come from #5617's review rounds 7–10, which went through six versions of the watch. Each version fixed some cases and broke others, and #5617 landed main's watch plus a 25-line wrapper (d9afcfcd5), the version that judged no case worse than main did before. The cases, a runner and the results are in /Users/maximilian/workspace/leaf.agent-acc9df77c8228a7db/.tmp/swap-watch-sensor/ on Max's machine, which lasts only as long as that worktree. table.py runs every case against any version of the watch, cost.py times a keystroke and a wheel step with it installed, and removed-tests.diff holds three tests the landed version fails. The table is below.
Each case against each version, both engines (C: Chromium, F: Firefox where they differ)
| case | before #5617 | 505b5da | main now (d9afcfc) | c9f6f5f | e1cb779 | 3375ff0 |
|---|---|---|---|---|---|---|
| rAF row grows next frame | ok | missed | ok | ok | ok | ok |
| drawn in delivery, grows | missed; loop error | missed | missed | ok | ok | ok |
| drawn 2 microtasks after delivery, grows | missed; loop error | missed | missed; loop error | ok | ok | ok |
| drawn in delivery, shrinks | missed; loop error | missed | missed | missed | ok | ok |
| drawn 2 microtasks after delivery, shrinks | missed; loop error | missed | missed; loop error | missed | ok | ok |
| second observer resizes before paint | loop error | ok | ok | false 24→40 | ok | ok |
| drawn after paint, swapped before next | ok | ok | ok | false 24→40 | ok | ok |
| scale(.96) row, equal swap | ok | ok | ok | ok | false 38.4→40 | ok |
| grown before first paint, then shrinks | missed | missed | missed | missed | missed | ok |
| page observer swaps a standing row | loop error | loop error | loop error | missed; loop error | missed; loop error | ok |
| page observer swaps, second restores before paint | loop error | loop error | loop error | loop error | loop error | ok |
| rAF grows, page IntersectionObserver shrinks back | ok | ok | ok | ok | ok | missed |
| image grows row, then equal swap | ok | ok | ok | ok | ok | false 24→40 |
| CSS hover swap grows row | ok | ok | ok | ok | ok | missed |
| finished .96 to 1 animation, then equal swap | ok | ok | ok | ok | ok | false 38.4→40 |
| padded row grows, no transform (control) | ok | ok | ok | ok | ok | ok |
| padded row grows under scale(2) | ok | ok | ok | ok | ok | missed |
| padded row grows under zoom:2 | ok | ok | ok | ok | ok | missed |
| sibling selector grows a distant row, then equal swap | ok | ok | ok | ok | ok | ok |
The versions don't converge because of how the watch measures. It observes flex rows, their occupants and the box around each row with one ResizeObserver (tests/swap_watch.js:55-60), and wraps the page's window.ResizeObserver to tell the page's deliveries from its own (lines 178-191). An observation on a shallow element changes the delivery depth of every page observer below it, so no rule for when a delivery ends keeps the page's own observers delivering as they would without the watch. The review's summary of what a replacement needs: a sensor that changes no page observer's delivery, measures every box in one coordinate system, and takes a row's first size and its appearance from one reading.
Unconfirmed direction: drop the ResizeObserver and observe the place and occupants a mutation touched with an IntersectionObserver, which reports the painted box of the update that follows. A reviewer found it gave the expected first box for a row inserted inside a resize callback, two microtasks after one, inside rAF, outside a scroller's scrollport and inside a shadow root, in both engines. A next-frame ResizeObserver is not equivalent: after a next-frame shrink it saw 20 px where the IntersectionObserver kept the 80 px before it. The open question is how to know the "before" box of a row that was already standing. Done means every row of the table right in both engines, with keystroke and wheel-step costs on leaf-dev bench's pages at main's. #5708, loop errors on corpus pages in nightly journeys since #5617, which changed this watch's wrapper, may come partly from here; #5751 is the runtime's own loop gap, which pages hit without the watch.
This was written by Claude Code on behalf of max-sixty
Activity
Stand a thread card clear of its subject's mark, not on its line (#5853)
test: read the swap watch's boxes without a ResizeObserver, so it rai…