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
Check · Review · Land · Live done — Landed and live in production.
mason/forge:mason/13527-the-forge-toolbar-s-script-and-style-sta → main 2 commits fork 4 threads · 4 unresolved
2 files
changed +29
−0
src/apps/toolbar.ts +3
| @@ -9,6 +9,9 @@ | ||
| 9 | 9 | * corner is kept per app host in localStorage. It styles itself through the CSSOM |
| 10 | 10 | * (never a `style` attribute or a `<style>` element), which a strict |
| 11 | 11 | * `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. | |
| 12 | 15 | */ |
| 13 | 16 | |
| 14 | 17 | 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 | |
| 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["']\)/); | |
|
||
| 25 | expect(toolbarJs).toContain("position:fixed"); | |
| 26 | }); |
new above
offline
Nothing imports this constant, so
exportis dead surface in a test file. Make it a plainconst.