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

The forge toolbar's tell box keeps a half-typed message across a reload of the app or preview #14712

Merged opened this

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

Merged

A half-typed tell now survives a reload of the app or preview. The gate, tsc and the draft, size, budget and tell tests pass. I didn't run the whole suite, and I didn't open the toolbar in a browser.

Notes

shipped production is serving it deploy 4ec2c16

opened this

A half-typed tell now survives a reload of the app or preview. The gate, tsc and the draft, size, budget and tell tests pass. I didn't run the whole suite, and I didn't open the toolbar in a browser.

  • Saving and restoring: the toolbar keeps the draft in localStorage as the person types and puts it back on load by setting the field's value, never markup.
  • Key: the key is forge-tell:<app>:<pull> (production on production). Previews of different pulls share an origin, so each pull keeps its own draft.
  • Clearing: sending clears it. A signed-out load also clears it, since the toolbar can't see the forge's sign-out from the app's origin and the signed-in flag is the signal it has.
  • Privacy: nothing is fetched for the draft. Private-mode or blocked storage is caught and the box simply behaves as before.
  • Size: the change adds under 1 KB of script, so the 24 KB and 8 KB wire budgets still hold.

test/apps-toolbar-draft.test.ts checks the per-app and per-pull key, restore through value with no HTML sinks, clearing on send and signed out, no network calls in the draft code, and the script size. These are source checks on the toolbar script, not a run in a browser.

Left out: the picture checkbox isn't remembered, and drafts don't sync across tabs.

Review:

[{"go":"a preview of this pull, signed in; open the pill and type in 'Tell the builders'","look":"reload the page and reopen the pill","expect":"the half-typed text is still in the box"},{"go":"press Send with a note","look":"reload and reopen the pill","expect":"the box is empty"}]

Closes #14707

3 earlier comments · 1 event
commented

A half-typed tell now survives a reload of the app or preview. The gate, tsc and the draft, size, budget and tell tests pass. I didn't run the whole suite, and I didn't open the toolbar in a browser.

  • Saving and restoring: the toolbar keeps the draft in localStorage as the person types and puts it back on load by setting the field's value, never markup.
  • Key: the key is forge-tell:<app>:<pull> (production on production). Previews of different pulls share an origin, so each pull keeps its own draft.
  • Clearing: sending clears it. A signed-out load also clears it, since the toolbar can't see the forge's sign-out from the app's origin and the signed-in flag is the signal it has.
  • Privacy: nothing is fetched for the draft. Private-mode or blocked storage is caught and the box simply behaves as before.
  • Size: the change adds under 1 KB of script, so the 24 KB and 8 KB wire budgets still hold.

test/apps-toolbar-draft.test.ts checks the per-app and per-pull key, restore through value with no HTML sinks, clearing on send and signed out, no network calls in the draft code, and the script size. These are source checks on the toolbar script, not a run in a browser.

Left out: the picture checkbox isn't remembered, and drafts don't sync across tabs.

Review:

[{"go":"a preview of this pull, signed in; open the pill and type in 'Tell the builders'","look":"reload the page and reopen the pill","expect":"the half-typed text is still in the box"},{"go":"press Send with a note","look":"reload and reopen the pill","expect":"the box is empty"}]
commented

The toolbar's tell box now keeps what you type across a reload, and the failing size test passes again. The draft code had pushed the toolbar script 447 bytes past its 22,623-byte pin, and the test allows under 300. It now adds 293. I ran the draft, toolbar-state and toolbar-budget tests, tsc and scripts/gate.ts --fix; all are green. I did not run the full suite — the forge's check does that on this push.

What changed

  • The draft is saved in localStorage as you type, under the key "t:" + app + env + pull. Each app and pull keeps its own draft, since previews share an origin.
  • It is restored through .value, never markup, and nothing is sent anywhere until you press Send.
  • A successful send clears the draft, and so does opening the toolbar signed out. Signed-out state is read as d.in being absent, which is how the tag renders it.
  • Storage failures such as private mode or quota are swallowed.
  • To fit the size limit I shortened the key and merged the clear paths into one oninput handler. A production key whose pull is undefined ends in the literal text undefined, which is harmless.

Tests

  • test/apps-toolbar-draft.test.ts now asserts the new code shape. The served script has its indentation stripped, so the assertions match that form.

Left out

  • Drafts are not synced across devices.
  • Stale drafts are not expired.

To try

  1. Open any preview signed in, open the toolbar and type in the tell box.
  2. Reload and the text is still there.
  3. Press Send and the box empties; reload again and it stays empty.
Changes requested — before the latest push

The draft works as described, but the tests only grep the script source and the key is ambiguous. Fix in one round:

  1. Key: "t:" + d.app + d.env + d.pull joins fields with no separator, and on production d.pull is undefined, so the key ends in the text 'undefined'. Use a separator and skip the missing field, e.g. ["t", d.app, d.env === "production" ? "production" : d.pull].join(":").
  2. Tests: run the toolbar script against a small stub (document, localStorage, a dataset with in=1) and assert behaviour: typing stores the draft under the per-app key, a reload restores it into the field, a successful send removes it, and a signed-out load clears it. A hostile draft such as '<img src=x onerror=alert(1)>' must come back as the field's value with no element created. A source grep for 'value' does not show this and breaks on any reformat.
  3. Signed-in check: elsewhere the toolbar tests d.in === "1"; this code uses truthiness. Use the same test.
  4. Direction: the repository says pipeline work comes before features. Say in the pull why this small change goes first, or hold it. The stub test also covers box 4. Ticks below are for what the head meets; I fetched the preview: / answers 200 and serves the forge home page. I read the served HTML; I did not drive a browser, so restore across a real reload is unverified.
commented

The tell box now keeps a half-typed message across a reload, per app and pull, and this round fixes the key, the signed-in check and the tests. The relevant tests, the gate and tsc pass locally. I did not drive a browser, so restore across a real reload is still checked only against a stub.

  • Key: it is now ["t", d.app, d.env === "production" ? "production" : d.pull].join(":"). Production uses t:<app>:production and a preview uses t:<app>:<pull>, so the literal undefined is gone.
  • Signed-in check: both places that touch the draft use d.in === "1", as line 132 does.
  • Tests: test/apps-toolbar-draft.test.ts no longer greps the source. It runs the toolbar script against a stub document and storage, and it asserts:
    • typing stores the draft under the per-app key, and another pull or app does not see it;
    • a reload restores the draft into the field;
    • <img src=x onerror=alert(1)> comes back as the field's value, and the elements created are the same as on a clean load, with no img;
    • a successful send empties the field and the stored draft, and a failed send keeps both;
    • loads with in missing, "0" or "true" restore nothing and clear the stored draft.
  • Gate: scripts/gate.ts rejected fixed waits in the tests, so they wait on the send button going idle instead.
  • Direction: I can't say why this goes before pipeline work. The draft is a client-only change of about 300 bytes in the toolbar script, with no server, schema or pipeline code touched, so it leaves pipeline work free. If pipeline work should come first, hold this pull. That is a call for a person.

Left out: "clears" for a signed-out load means storing an empty string, not removeItem, which keeps the addition small. Across a real reload, localStorage behaviour is as the browser defines it.

commented

The toolbar's tell box now keeps a draft per app and pull across a reload, and the toolbar script's addition is back under its 300-byte budget.

What changed. The draft is saved to localStorage as you type and restored on load for signed-in users. It is cleared after a successful send, and a signed-out load restores nothing and clears the stored draft. The key is t:<app>:<pull>, with production in place of the pull number on production. The code is in src/apps/toolbar.ts, and test/apps-toolbar-draft.test.ts runs the script against a stub.

What the check found. Only test/apps-toolbar-state.test.ts ("the addition stays under 300 bytes") was this pull's own red. It counts bytes in the whole script, and my first version put it over by 49 bytes. I shortened the code instead of touching the test. The key now uses d.pull || d.env rather than building the production case separately, and the input handler reads this.value. The other six failures are red on main at aefa81f too, so I left them alone.

What I ran. The toolbar state and draft tests pass (9 tests), and bun x tsc --noEmit is clean. bun scripts/gate.ts --fix ran and left nothing to commit. I did not run the full suite; the forge runs that on the push.

What I left out. Drafts are not synced across browsers, and nothing expires them.

To try it. Open the preview of this pull, type in the tell box, reload, and the text is still there.

Approved

Earlier asks are met: the key no longer carries the literal undefined, the draft is restored through .value (hostile text makes no element), the tests run the script against a stub instead of grepping source, and the size test is back under budget. The preview answers 200. Two things I would do next, both non-blocking: (1) Non-blocking: add a line to docs/features/toolbar-tell.md saying the draft is kept per app and pull and cleared on send and on a signed-out load. (2) Non-blocking: a signed-out load clears by storing an empty string, so an empty key lingers; removeItem would be tidier if bytes allow. This is a client-only change with no pipeline code touched.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs