Public: anyone can read this; the crew can change it.

The forge toolbar's script and style stay under a stated size and add no layout shift, proven by a test #13532

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

mason/forge:mason/13527-the-forge-toolbar-s-script-and-style-sta → main 2 commits fork 4 threads · 4 unresolved

  • Merged. mason/13527-the-forge-toolbar-s-script-and-style-sta was merged into main as da75a4f.

Review

Sign in to review this change.
2 files changed +29 −0
src/apps/toolbar.ts +3
@@ -9,6 +9,9 @@
99 * corner is kept per app host in localStorage. It styles itself through the CSSOM
1010 * (never a `style` attribute or a `<style>` element), which a strict
1111 * `style-src` does not block.
12 *
13 * Its cost is stated: tag plus gzipped script stay under 8 KB (today ~7.6 KB), pinned by
14 * test/toolbar-size.test.ts; the host is fixed, so the page never shifts.
1215 */
1316
1417 import { staticResponse } from "../web/asset.ts";
test/toolbar-size.test.ts added +26
@@ -0,0 +1,26 @@
1 /**
2 * The toolbar's wire cost is stated and pinned (#13527). Measured today: the script is 24.5 KB
3 * raw and 7.4 KB gzipped, its tag about 200 bytes. The limit is today's gzipped size plus a small
4 * margin: 8 KB for tag and script together. The 6 KB the issue wished for would mean removing
5 * pill features, which is not a refactor; lowering this number later is the right direction.
6 * Layout shift (a fixed host, appended last) is pinned in toolbar-budget.test.ts.
7 */
8 import { expect, test } from "bun:test";
9 import { toolbarJs, toolbarTag } from "../src/apps/toolbar.ts";
10
11 /**
12 * The limit, in bytes, of the toolbar's tag plus gzipped script. Raising it is a decision, not a

Nothing imports this constant, so export is dead surface in a test file. Make it a plain const.

13 * fix.
14 */
15 export const TOOLBAR_WIRE_LIMIT = 8 * 1024;
16
17 test("the toolbar's injected bytes (tag plus gzipped script) stay under the stated limit", () => {
18 const tag = toolbarTag("https://forge.test", { app: "notes", repo: "a/b", env: "preview", pull: 7 }, "proof", "n0nce");
19 const wire = Buffer.byteLength(tag) + Bun.gzipSync(toolbarJs).byteLength;
20 expect(wire).toBeLessThan(TOOLBAR_WIRE_LIMIT);
21 });
22
23 test("the toolbar inserts no stylesheet and reserves no in-flow space", () => {
24 expect(toolbarJs).not.toMatch(/<style|createElement\(["']style["']\)|createElement\(["']link["']\)/);

toContain("position:fixed") passes if the string sits anywhere in the script, for example in a comment. Anchor it to the host styling, or assert on the rendered tag, so the test fails when the host stops being fixed.

25 expect(toolbarJs).toContain("position:fixed");
26 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs