From 390acfbd6f826092d2df74133ced38af3e043f15 Mon Sep 17 00:00:00 2001 From: SylvainDruaux Date: Fri, 27 Nov 2026 11:29:24 +0100 Subject: [PATCH 1/3] fix(design): a frame's page never loses width to its own scrollbar MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On a Mac that draws classic scrollbars (System Settings → Appearance → Show scroll bars: Always, or Automatic with a mouse connected), a Design mode frame whose page is taller than the frame's 30,000 px cap scrolls inside itself and shows Chromium's scrollbar. The page is then laid out 15 px narrower than the width on the frame's label: 781 px in a frame labelled 796. A phone-width frame makes a page much taller, so an ordinary long page can reach the cap there. The same narrowing is why designModeUnlinkSoak fails on such a Mac ("f1 drawn 796 pixels wide … last observed: 781") and passes with "Show scroll bars: When scrolling". The editor canvas already hides the page's own scrollbar and gives every frame its whole width (canvasScrollbar.ts), but it does so through a message that a script in the frame applies, and Design mode frames run no script. Each frame's document now gets the same rule, CANVAS_SCROLLBAR_CSS, when it loads and before its height is measured. Nothing is lost: the canvas takes every pointer, so a frame is never scrolled from inside. A new test checks that the rule is written once into the frame's and keeps the page's own styles; designModeUnlinkSoak holds the width itself on a Mac with classic scrollbars. --- src/app/designMode/DesignFrameDocument.tsx | 25 +++++++++++++ .../designFramePageScrollbar.test.js | 35 +++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 test/renderer/app/designMode/designFramePageScrollbar.test.js diff --git a/src/app/designMode/DesignFrameDocument.tsx b/src/app/designMode/DesignFrameDocument.tsx index e77139dc2..960a1f3d6 100644 --- a/src/app/designMode/DesignFrameDocument.tsx +++ b/src/app/designMode/DesignFrameDocument.tsx @@ -4,10 +4,13 @@ // processes. A new snapshot loads beside the shown one, hidden, and takes its place once loaded, so a frame never // flashes white while it is edited. The frame is as tall as its page. import { useEffect, useLayoutEffect, useRef, useState } from 'react'; +import { assert } from '../../../shared/core/assert'; import { DESIGN_FRAME_WINDOW_NAME } from '../../../shared/ipc/designSnapshot'; +import { CANVAS_SCROLLBAR_CSS } from '../../../shared/properties/canvasScrollbar'; /** The tallest a frame is drawn: past this a page is cut off on the canvas. */ export const FRAME_HEIGHT_PX_MAX = 30_000; +const PAGE_SCROLLBAR_STYLE_ID = 'dm-page-scrollbar'; /** A page's height settles as its pictures arrive: measured at load, then at these delays after it. */ const MEASURE_AGAIN_MS = [250, 1_000, 3_000] as const; @@ -83,6 +86,9 @@ export function DesignFrameDocument({ timers.current.forEach((timer) => window.clearTimeout(timer)); shownFrame.current = frame; measuredWidth.current = widthPx; + if (frame.contentDocument !== null) { + hideFramePageScrollbar(frame.contentDocument); + } measure(frame); timers.current = MEASURE_AGAIN_MS.map((delay) => window.setTimeout(() => latestMeasure.current(frame), delay)); }; @@ -107,3 +113,22 @@ export function DesignFrameDocument({ ); } + +/** + * The page's own scrollbar never takes width from a frame, as on the editor's canvas (shared/properties/canvasScrollbar.ts). + * A page taller than FRAME_HEIGHT_PX_MAX scrolls inside its frame, and on a computer that draws classic scrollbars + * (macOS "Show scroll bars: Always", or "Automatic" with a mouse) Chromium's bar would lay it out 15px narrower than + * the width on its label. The frame runs no script, so the canvas's message cannot reach it: the rule is written into + * its document here instead. Nothing is lost: the canvas takes every pointer, so a frame is never scrolled from inside. + */ +export function hideFramePageScrollbar(document: Document): void { + assert(document.head !== null, 'hideFramePageScrollbar: a loaded document has a '); + const existing = document.getElementById(PAGE_SCROLLBAR_STYLE_ID); + if (existing === null) { + const style = document.createElement('style'); + style.id = PAGE_SCROLLBAR_STYLE_ID; + style.textContent = CANVAS_SCROLLBAR_CSS; + document.head.appendChild(style); + } + assert(document.getElementById(PAGE_SCROLLBAR_STYLE_ID)?.textContent === CANVAS_SCROLLBAR_CSS, 'hideFramePageScrollbar: the frame draws no bar of its own'); +} diff --git a/test/renderer/app/designMode/designFramePageScrollbar.test.js b/test/renderer/app/designMode/designFramePageScrollbar.test.js new file mode 100644 index 000000000..9513a9447 --- /dev/null +++ b/test/renderer/app/designMode/designFramePageScrollbar.test.js @@ -0,0 +1,35 @@ +// Goal: a Design mode frame never lets the page's own scrollbar take width from it. A page taller than the frame's +// height cap scrolls inside its frame, and a computer that draws classic scrollbars would then lay it out 15px +// narrower than the width on its label. The rule written into the frame's document is the editor canvas's own +// (CANVAS_SCROLLBAR_CSS), written once however often the frame loads, and kept when the page already has styles. +// +// Method: the real helper, bundled by test/helpers/rendererModule.js, applied to jsdom documents. jsdom has no +// layout, so the width itself is held by designModeUnlinkSoak on a Mac set to "Show scroll bars: Always". +const test = require('node:test'); +const assert = require('node:assert/strict'); +const { JSDOM } = require('jsdom'); +const load = require('../../../helpers/rendererModule'); + +const { hideFramePageScrollbar } = load('src/app/designMode/DesignFrameDocument.tsx'); +const { CANVAS_SCROLLBAR_CSS } = load('shared/properties/canvasScrollbar.ts'); + +const documentOf = (html) => new JSDOM(html).window.document; +const ruleStyles = (document) => [...document.querySelectorAll('style')].filter((style) => style.textContent === CANVAS_SCROLLBAR_CSS); + +test("a frame's document gets the canvas's rule: no scrollbar on the page's scrolling root", () => { + const document = documentOf('Page

Text

'); + hideFramePageScrollbar(document); + const styles = ruleStyles(document); + assert.equal(styles.length, 1); + assert.equal(styles[0].parentElement, document.head, 'in , beside the page’s own styles'); + assert.match(CANVAS_SCROLLBAR_CSS, /scrollbar-width: none !important/, 'the rule outranks a page’s own scrollbar-width'); +}); + +test('a frame that loads again keeps one rule, and the page keeps its own styles', () => { + const document = documentOf(''); + hideFramePageScrollbar(document); + hideFramePageScrollbar(document); + assert.equal(ruleStyles(document).length, 1, 'written once'); + assert.equal(document.querySelectorAll('style').length, 2, 'the page’s style stays'); + assert.equal(document.head.lastElementChild.textContent, CANVAS_SCROLLBAR_CSS, 'last, so it is read after the page’s'); +}); From f356ec35f68c0e1bfa86613b63dd64718a8d009b Mon Sep 17 00:00:00 2001 From: SylvainDruaux Date: Fri, 27 Nov 2026 17:36:15 +0100 Subject: [PATCH 2/3] test(design): let the unlink soak pass a corner's anti-aliasing Once a frame's page keeps its whole width on a Mac with classic scrollbars, designModeUnlinkSoak reaches its pixel comparison there, and on an M1 Pro it failed every run with "the unlinked element is painted the same (largest channel difference 2)". The before and after captures of the probe differed in 16 pixels only, all on the anti-aliased edge of the scoped card's two left corners, 15 of them by one level and one by two; text, fills and every straight edge were identical, as were the boxes and computed styles the soak compares exactly. A GPU blends a curved edge slightly differently from one draw to the next, and the steady difference depends on the machine, so a one-level limit on every pixel cannot hold everywhere. The element check now allows up to 16 pixels past that level, each within the 8 levels the whole frame is already held to, and every other pixel within one level. A changed look still fails: shifting the same card's colour by 12 levels puts 452,144 pixels past the level. A failure now reports the largest difference and how many pixels were past it, and the report keeps both. --- .../designMode/designModeUnlinkSoak.test.js | 56 +++++++++++++++++-- 1 file changed, 50 insertions(+), 6 deletions(-) diff --git a/test/renderer/app/designMode/designModeUnlinkSoak.test.js b/test/renderer/app/designMode/designModeUnlinkSoak.test.js index 44432ec96..325099f55 100644 --- a/test/renderer/app/designMode/designModeUnlinkSoak.test.js +++ b/test/renderer/app/designMode/designModeUnlinkSoak.test.js @@ -15,6 +15,7 @@ // Screenshots go to STACKI_SCREENSHOT_DIR (default node_modules/.stacki-test/design-unlink). Run it by hand with // `node test/renderer/app/designMode/designModeUnlinkSoak.test.js`. +const assert = require('node:assert/strict'); const fs = require('node:fs'); const os = require('node:os'); const path = require('node:path'); @@ -226,6 +227,43 @@ const FRAME_CHANNEL_DELTA_MAX = 8; * exactly) were painted a level apart on a loaded machine, steadily, in a full gate run. */ const ELEMENT_CHANNEL_DELTA_MAX = 1; +/** + * Past that level, a few pixels may still differ, each by no more than a frame's picture may: a rounded corner's edge + * is anti-aliased by the GPU, and some machines blend it a level or two apart from one draw to the next. On an M1 Pro + * the probe's only differences were 16 pixels on the scoped card's two left corners, one of them 2 levels apart. A + * changed look (a lost class, another colour) moves thousands of pixels, so it still fails. + */ +const ELEMENT_EDGE_PIXELS_MAX = 16; + +/** How far two captures of one element are apart: its largest channel difference, and the pixels past the level. */ +function paintDifference(left, right) { + if (left.length !== right.length) { + return { largest: 255, pixelsOver: left.length }; + } + // A capture's bitmap holds four bytes a pixel (BGRA). + assert.equal(left.length % 4, 0, 'a capture holds whole pixels'); + let largest = 0; + let pixelsOver = 0; + for (let pixel = 0; pixel < left.length; pixel += 4) { + let pixelLargest = 0; + for (let channel = pixel; channel < pixel + 4; channel += 1) { + pixelLargest = Math.max(pixelLargest, Math.abs(left[channel] - right[channel])); + } + largest = Math.max(largest, pixelLargest); + if (pixelLargest > ELEMENT_CHANNEL_DELTA_MAX) { + pixelsOver += 1; + } + } + return { largest, pixelsOver }; +} + +/** Whether an element is painted as before: every pixel within a level, but for a corner's few, which stay close. */ +function paintedAsBefore(difference) { + if (difference.pixelsOver <= ELEMENT_EDGE_PIXELS_MAX) { + return difference.largest <= FRAME_CHANNEL_DELTA_MAX; + } + return false; +} function largestDifference(left, right) { if (left.length !== right.length) { @@ -425,27 +463,33 @@ async function runInElectron({ window, project, options }) { fs.writeFileSync(path.join(options.outDirectory, `${name}-after.png`), pixelsAfter.png); const sameRect = JSON.stringify(pixelsAfter.rect) === JSON.stringify(pixelsBefore.rect); // The visible frame: a picture elsewhere on the page may be resampled a level or two differently each time it is - // decoded, so the whole frame is held to a small difference per channel and the unlinked element to none. + // decoded, so the whole frame is held to a small difference per channel and the unlinked element to a level, but + // for a rounded corner's few anti-aliased pixels (paintedAsBefore). const delta = sameRect ? largestDifference(pixelsBefore.bitmap, pixelsAfter.bitmap) : 255; check(`${name}: the visible frame is the same before and after`, delta <= FRAME_CHANNEL_DELTA_MAX, `largest channel difference ${String(delta)}`); report.frameDelta = { ...(report.frameDelta ?? {}), [name]: delta }; // One capture may catch the redrawn frame part painted on a loaded machine: it is captured until it matches, and // an element that really differs never does. - let elementDelta = 255; + let elementDifference = { largest: 255, pixelsOver: 0 }; const painted = await waitFor({ what: `${name}: the element painted as before`, read: async () => { - elementDelta = largestDifference(regionBefore.bitmap, (await framePixels(elementRect(styledRoot))).bitmap); - return elementDelta; + elementDifference = paintDifference(regionBefore.bitmap, (await framePixels(elementRect(styledRoot))).bitmap); + return elementDifference; }, - until: (largest) => largest <= ELEMENT_CHANNEL_DELTA_MAX, + until: paintedAsBefore, pollIntervalMs: POLL_MS, pollCountMax: PAINT_POLLS_MAX, }).then( () => true, () => false, ); - check(`${name}: the unlinked element is painted the same`, painted, `largest channel difference ${String(elementDelta)}`); + check( + `${name}: the unlinked element is painted the same`, + painted, + `largest channel difference ${String(elementDifference.largest)}, ${String(elementDifference.pixelsOver)} pixels past ${String(ELEMENT_CHANNEL_DELTA_MAX)}`, + ); + report.elementDifference = { ...(report.elementDifference ?? {}), [name]: elementDifference }; return page; }; From ccd7abf0011af45e4b29bd80b3fc6efe93b7fdec Mon Sep 17 00:00:00 2001 From: SylvainDruaux Date: Fri, 27 Nov 2026 18:05:26 +0100 Subject: [PATCH 3/3] test(gate): run the Design mode soaks and screen recording alone The gate's own rule puts suites that measure timing or drive a real window in the alone phase, one at a time with nothing else running. Four Design mode soaks and the screen recording probe were in the shared pool instead. On a 10-core, 16 GB M1 Pro, the default full gate (four Electron windows at once among nine suites) failed designModeSoak, designModeControlsSoak, designModePagesSoak and designModeUnlinkSoak in two runs, on waits that ran out (a frame never drawn within 30 s, a page that never finished opening, a copy not drawn within 100 ms), and each passed on its own. With --electron-jobs=1 the three that had no other fault passed in three runs out of three. screenRecordingElectron failed the same way under load: its frame-rate checks fail outside CI, and e355e30c records a loaded macOS runner at 0.8 fps. They now run alone. CI's Linux and Windows runners skip all five (macOS only), so CI time does not change. On a Mac the alone phase grows by about 8 to 10 minutes (designModePagesSoak alone took 234 s), so a full gate there takes roughly 22 to 24 minutes, under the push hook's 30-minute bound. designModeResizeSoak and designModeCrashSoak passed in every run and stay in the pool. Four of those entries name Design mode's test files, so scripts/gate/testSuites.ts becomes one of its integration points: designModeBoundary lists it with its four lines, and docs/design-mode/REMOVE.md says to remove them with the feature. --- docs/design-mode/REMOVE.md | 1 + scripts/gate/testSuites.ts | 9 +++++++++ test/renderer/app/designMode/designModeBoundary.test.ts | 1 + 3 files changed, 11 insertions(+) diff --git a/docs/design-mode/REMOVE.md b/docs/design-mode/REMOVE.md index 06f5d0895..9b66cda00 100644 --- a/docs/design-mode/REMOVE.md +++ b/docs/design-mode/REMOVE.md @@ -208,6 +208,7 @@ byte-identical afterwards. - `test/shared/ipc/ipcPayloads.test.ts`: the `'design:session'` sample. - `test/electron/app/mainBoundaries.test.ts`: the Design mode comment line, and the channel count one lower (it counts `design:session`). - `test/electron/documents/singleWriter.test.ts`: the comment and the four `electron/handlers/designMode/` entries. + - `scripts/gate/testSuites.ts`: the comment and the four `test/renderer/app/designMode/` entries that run alone. 3. Optionally delete `design-drafts/` (and `design-sandboxes/`, which is empty unless the app crashed during a session) from Stacki's user data folder: once the feature is gone nothing reads or sweeps them. diff --git a/scripts/gate/testSuites.ts b/scripts/gate/testSuites.ts index cf39db4a9..bb7a97de9 100644 --- a/scripts/gate/testSuites.ts +++ b/scripts/gate/testSuites.ts @@ -43,6 +43,15 @@ export const TEST_SUITES: Readonly> = { // not this code's (331 ms on a macOS runner for slices that take about 30 ms alone). Alone, it measures the code. 'test/electron/handlers/projectScale.test.ts': { phase: 'alone' }, 'test/renderer/ui/astroEditorScale.test.js': { phase: 'alone' }, + // Each drives a real Design mode window through timed waits (a copy drawn within 100 ms, panels within 30 s). + // In the shared pool, up to four Electron windows share the CPU and the waits run out, on a 10-core Mac too. + 'test/renderer/app/designMode/designModeSoak.test.js': { phase: 'alone' }, + 'test/renderer/app/designMode/designModeControlsSoak.test.js': { phase: 'alone' }, + 'test/renderer/app/designMode/designModePagesSoak.test.js': { phase: 'alone' }, + 'test/renderer/app/designMode/designModeUnlinkSoak.test.js': { phase: 'alone' }, + // Measures a recording's frame rate; a loaded Mac records under the floor (0.8 fps on a runner, e355e30c), and + // its rate checks fail outside CI. + 'test/electron/handlers/ai/screenRecordingElectron.test.js': { phase: 'alone' }, // Loads an app page over the real `stacki-app:` scheme, which only Electron has. 'test/electron/handlers/appFrameFetch.test.js': { runner: 'electron' }, // Loads the UI kit inside an app frame over the real `stacki-app:` scheme, which only Electron has. diff --git a/test/renderer/app/designMode/designModeBoundary.test.ts b/test/renderer/app/designMode/designModeBoundary.test.ts index 22232a094..af8bb4d86 100644 --- a/test/renderer/app/designMode/designModeBoundary.test.ts +++ b/test/renderer/app/designMode/designModeBoundary.test.ts @@ -43,6 +43,7 @@ const INTEGRATION_POINTS: Readonly> = { 'src/features/style/model/inlineDefault.ts': 5, 'src/features/ai/AiPanel.tsx': 2, 'src/features/ai/aiHold.ts': 1, + 'scripts/gate/testSuites.ts': 4, }; function sourceFiles(): readonly string[] {