From 7fa0a4915f5f4fbe19c1e8762c1bbfbba20f48b9 Mon Sep 17 00:00:00 2001 From: SylvainDruaux Date: Fri, 27 Nov 2026 20:20:18 +0100 Subject: [PATCH] fix(canvas): hide the page's scrollbar before the first paint Opening a project showed Chromium's scrollbar in each canvas frame for a moment before the canvas's own bar replaced it. The app tells a frame to hide its bar on the iframe's load, which fires after every picture and font, so on a Mac with classic scrollbars the page first painted with Chromium's bar and 15 px less width. A canvas frame now hides the bar itself as its preload starts. Its URL already says it is the canvas's (#avb-design, as markFrameMode reads it), and every canvas frame has the canvas's own bar beside it (SizedFrame.tsx, CanvasView.tsx), so no page is left without one. The rule goes into the document's adopted style sheets: no element is added to the page, so the column guide, the outlines and the canvas patcher see no change, and a document whose does not exist yet takes it too. A frame that is not the canvas's keeps Chromium's bar until the app's word, and a document without adopted style sheets (jsdom) waits for it as before. In Studio the preview client is a module script, so it hides the bar once the page is parsed rather than before the first paint, still earlier than on load. canvasScrollbarChromium now holds, in a real Electron window, that a canvas frame has hidden its bar and lays a 320 px page out at 320 px before the app's word, and that a frame without the canvas's mark keeps Chromium's bar; frameScrollbar.test.js holds that the rule adds no element to the page and is adopted once. --- electron/preload/frameScrollbar.ts | 31 +++++++- .../preload/canvasScrollbarChromium.test.js | 27 ++++--- test/electron/preload/frameScrollbar.test.js | 71 +++++++++++++++++-- 3 files changed, 111 insertions(+), 18 deletions(-) diff --git a/electron/preload/frameScrollbar.ts b/electron/preload/frameScrollbar.ts index 1a9997bff..2510744fc 100644 --- a/electron/preload/frameScrollbar.ts +++ b/electron/preload/frameScrollbar.ts @@ -2,9 +2,13 @@ // (frameQueries.ts) and Studio's preview client: hides the page's own scrollbar once the app says so, reports the // page's vertical scroll so the canvas can draw its own bar, and scrolls when that bar is dragged. // -// Until the app's word arrives, the page keeps Chromium's scrollbar and every report says so (`chromium: true`), -// so the canvas never draws a second bar beside a frame that still shows its own. A frame with no app (the phone -// preview, a page opened on its own) is never told and keeps its scrollbar. +// A canvas frame (its URL carries #avb-design, PreviewFrame.tsx) hides the page's bar before its first paint, without +// waiting for the app's word: the word comes on the frame's `load`, after every picture and font, and the page would +// show Chromium's bar until then. Every canvas frame has the canvas's own bar beside it (SizedFrame.tsx, +// CanvasView.tsx), so the page is never left without one. Any other frame keeps Chromium's scrollbar until the app's +// word arrives, and every report says so (`chromium: true`), so the canvas never draws a second bar beside a frame that +// still shows its own. A frame with no app (the phone preview, a page opened on its own) is never told and keeps its +// scrollbar. // // The scrolling root is (the document's scrolling element) on nearly every page. A page that holds still // and scrolls instead (`html { overflow: hidden } body { overflow: auto; height: 100% }`) is read and scrolled @@ -21,6 +25,8 @@ import { } from '../../shared/properties/canvasScrollbar'; const STYLE_ID = 'avb-canvas-scrollbar'; +/** The mark the app's canvas loads every page with (PreviewFrame.tsx), read the way markFrameMode reads it. */ +const CANVAS_HASH_MARK = 'avb-design'; /** The `overflow-y` values under which a taller than its box scrolls itself. */ const SCROLLING_OVERFLOWS: readonly string[] = ['auto', 'scroll', 'overlay']; @@ -38,6 +44,7 @@ export function installPageScrollReport(send: (message: unknown) => void): void return; } post = send; + hideCanvasPageScrollbarEarly(); // Capture on the document: a scrolling fires `scroll` at itself, and element scroll events do not bubble. document.addEventListener('scroll', scheduleReport, { capture: true, passive: true }); window.addEventListener('resize', scheduleReport); @@ -71,6 +78,24 @@ function observeRootWhenReady(): void { window.addEventListener('DOMContentLoaded', observe); } +// A canvas frame hides the page's bar now, before the page is parsed or painted. The rule goes into the document's +// adopted style sheets: no element is added to the page, so nothing that watches its DOM (the column guide, the +// outlines, the canvas patcher) sees a change, and a document whose does not exist yet takes it as well. The +// app's word on `load` still writes the ' + '' + '' + - '' + + '' + '