Repository navigation
fix(window): reflow via scale factor so terminals stop re-gridding - #10485
Conversation
The +1px emulated viewport changed the CSS box, so a terminal sitting one pixel under an xterm row boundary gained a row. The pane fit observer's two-frame stability check reads that transient grid as stable well inside the 32ms hold, forwards a real PTY resize, then reverses it on restore — two SIGWINCHes per reveal, measured on 3/54 window heights (~1/cellHeight). Nudging the device scale factor instead re-runs layout with byte-identical CSS geometry. Same reflow, 0/54 SIGWINCH, no WebGL atlas rebuild or context loss, and webview guests stop seeing spurious native resizes too. Co-authored-by: Orca <[email protected]>
8106701 to
d628ebc
Compare
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📥 CommitsReviewing files that changed from the base of the PR and between 810670108d0e61ba798a47a3acc6b185eb836738 and d628ebc. 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (3)
📝 WalkthroughWalkthroughUpdates macOS viewport repaint handling to use scale-aware Electron device emulation without changing native window bounds. Adds lifecycle guards, deferred execution, coalescing, failure recovery, and bounded restoration retries. Expands tests for scale calculations, destroyed windows, retry behavior, maximized/fullscreen repainting, and resume-from-sleep flows. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches📝 Generate docstrings
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
…tablyai#10485) The +1px emulated viewport changed the CSS box, so a terminal sitting one pixel under an xterm row boundary gained a row. The pane fit observer's two-frame stability check reads that transient grid as stable well inside the 32ms hold, forwards a real PTY resize, then reverses it on restore — two SIGWINCHes per reveal, measured on 3/54 window heights (~1/cellHeight). Nudging the device scale factor instead re-runs layout with byte-identical CSS geometry. Same reflow, 0/54 SIGWINCH, no WebGL atlas rebuild or context loss, and webview guests stop seeing spurious native resizes too. Co-authored-by: Orca <[email protected]>
Follow-up to #10473. That PR replaced the deadlock-prone frame jiggle with a
+1pxemulated viewport. The+1pxwas a real CSS-geometry change, and it re-grids terminals.The regression
renderer-viewport-reflow.tsemulatedheight + 1. For a terminal whose pane height sits one pixel under an xterm row boundary, that adds a row. The pane fit observer's two-frame stability check (pane-fit-resize-observer.ts:101-138) sees the same proposed grid on two consecutive animation frames — ~16.7ms apart, comfortably inside the 32ms hold — declares it stable, and fits.performSafeFit's no-op guard (pane-fit.ts:137) doesn't help, because the grid genuinely differs. The PTY gets a real resize, and the restore reverses it.Measured with real xterm + FitAddon + the real stability loop, sweeping window heights across a full cell height (cellH=16, 54 configs):
height + 1(#10473)setSizejiggleConcretely, at
paneH=655: rows 40 → 41 → 40, two SIGWINCHes per reveal.createMainWindow.ts's 250ms second repaint doubles that on show/restore.Worth being direct: #10473 made this worse than the code it replaced on this axis. The old jiggle changed window width, which doesn't cross row boundaries; the new one changed viewport height, which does.
The fix
Nudge
deviceScaleFactorby +0.25 instead, leavingviewSizeat the real content size. Layout re-runs,dvhrecomputes, and the CSS box is byte-identical, so no terminal re-grids.The delta is derived from
screen.getDisplayMatching(window.getBounds()).scaleFactorrather than a constant — a hardcoded 1.25 would equal the real factor on a 1.25x display and reflow nothing.|| 1guards a display reporting 0.Verification (real Electron 43.1.0, macOS 26.3.1)
Full 54-config sweep against the shipped logic, with the WebGL renderer (what Orca actually uses —
pane-webgl-renderer.ts) and a real PTY resize listener:Also fixes the third reported issue:
<webview>guests sat under the same100dvhchain and took two native resizes per reflow. No CSS geometry change means no guest resize.Tests
Four new tests in
renderer-viewport-reflow.test.tspin the mechanism: emulatedviewSize/screenSizemust equal the real content size, the delta must come from the window's own display, and the 0-scale-factor fallback. Mutation-tested — restoringheight + 1fails 4 tests.typecheck:nodeclean,oxlintclean, fullsrc/main/suite 15,003 passed | 47 skipped.Credit
Both the maximized/fullscreen gap (fixed in #10473) and this row-boundary SIGWINCH were surfaced by adversarial review agents. My original "no SIGWINCH" check used
paneH=544— exactly on a 32px row boundary, the safe case — so it passed while the bug was real. The boundary-crossing height is what exposes it.Limits
The stale-
dvhstate this reflow exists to fix still does not reproduce locally — I tried again here, manufacturing it by resizing the frame while the window was hidden, and layout was already correct on show, soinvalidate()had nothing to fix and the test couldn't discriminate. Carried forward from #10473: the reflow is verified at the mechanism level (it demonstrably drives a real layout recomputation with the frame untouched), not against a reproduced stale state.The 32ms restore still has no renderer acknowledgement, so a renderer blocked past the hold can coalesce the cycle away. That degrades to "no reflow this time," not to a wrong layout. A renderer-ack handshake is the principled fix and is not in this PR.