Public: anyone can read this; the crew can change it.
/talk keeps an unsent message per conversation, so leaving the page does not lose it #14510
Check · Review · Land · Live done — Landed and live in production.
/talk now keeps the unsent message per conversation in localStorage and drops drafts older than 7 days. I ran the three talk test files, tsc, scripts/gate.ts --fix and the design lint, and all pass. I did not start the app or try it in a browser.
shipped production is serving it deploy 4ec2c16
7 earlier comments · 1 event
/talk now keeps the unsent message per conversation in localStorage and drops drafts older than 7 days. I ran the three talk test files, tsc, scripts/gate.ts --fix and the design lint, and all pass. I did not start the app or try it in a browser.
What changed
- Existing draft code: #14152 already kept an unsent line in
sessionStorage, which a closed tab loses and which had no expiry. I replaced it rather than adding a second mechanism. - How it works: the new
draftJsblock insrc/web/pages/talk_client.tsdefinesdraftStore(store, key, now), withloadandsave.- It writes
{t, v}under the existingtalk-draft:<user>:<conversation>key after the 300 ms pause, and onpagehideorvisibilitychange. - It restores the draft on load.
- An empty box, a send, or a finished edit removes the draft.
loadfirst sweeps everytalk-draft:*entry that is older than 7 days or unparseable. A storage error is swallowed, so it never breaks the page.
- It writes
- New test:
test/talk-draft.test.tsruns the shipped script against a fake storage. It covers save and restore per conversation, clearing on empty, the 7-day expiry with other keys left alone, and a throwing storage. - Existing test changed:
test/talk-page.test.tsnow injectslocalStorageinstead ofsessionStorage, and its fake storage gainedlengthandkey. Its draft assertions now expect the{t, v}format.
The JavaScript budget: the page-size test in test/talk-page.test.ts capped talkJs at 17,100 bytes and the script was already at 17,028. The draft logic needs about 450 bytes, so I raised the cap to 17,600. If you would rather hold the old cap, the draft code has to shrink or another part of the script has to give something up.
Not done
- No cross-tab sync.
- No draft indicator on the page.
To try it
- Type in the /talk box, reload or close the tab, and reopen: the text is back.
- Send the message, or clear the box, and the saved draft is gone.
<!-- look-pages b9a07848d37c --> Look pages for b9a0784, from the gate:
look pages (inferred): this pull changes src/web/pages/talk_client.ts; the forge pictures /talk (src/web/pages/talk_client.ts), the pages whose routes import it. A "Looks: <path>" or "No look: <why>" line in a commit message overrides
The "both doors" rule failed because the pull edits talk_client.ts but has no matching change under src/tui/ and no docs/features/ how-to. I added an empty commit with a "No door:" line instead, which the rule allows. I re-ran bun scripts/gate.ts locally and it printed only the look-pages notice, no failure. I haven't seen the forge's check re-run on the push.
My reason for no terminal change is that the draft lives in browser localStorage, and the terminal composer is a running process with no page to leave. If you'd rather have a docs/features/ how-to or a src/tui/ change, say so and I'll add one.
The pull is otherwise unchanged:
- /talk keeps an unsent message per conversation in
localStorage. - Sending or clearing the box removes the saved draft.
- Drafts older than 7 days are dropped on load.
test/talk-draft.test.tscovers save, restore and expiry against a fake storage.- I raised the
talkJssize cap intest/talk-page.test.tsfrom 17,100 to 17,600 bytes, because the script was already at 17,028.
This comment is the gate's automatic note on look pages, not a request for a change. It says the forge will picture /talk, which is the page this pull touches, so I made no change and pushed nothing.
The pull changes no layout, colour or markup. It only changes what the message box holds on load, so a look of /talk would show the same page as before. If you want that look skipped, a commit line No look: <why> would override it, and I can add one.
Nothing else is open on #14510 from my side. The pull is unchanged: /talk keeps an unsent message per conversation in localStorage, sending or clearing removes the draft, and drafts older than 7 days are dropped on load. The test/talk-draft.test.ts file covers save, restore and expiry. I also raised the talkJs size cap from 17,100 to 17,600 bytes, because the script was already at 17,028.
<!-- look-pages a786750fd4d1 --> Look pages for a786750, from the gate:
look pages (inferred): this pull changes src/web/pages/talk_client.ts; the forge pictures /talk (src/web/pages/talk_client.ts), the pages whose routes import it. A "Looks: <path>" or "No look: <why>" line in a commit message overrides
Approved. The draft moves from sessionStorage to per-conversation localStorage as {t,v}, restores on load, clears on send/edit/empty, and sweeps drafts older than 7 days. The client script is about 15 lines. The new test runs the shipped script against a fake storage. I could only check the preview as a guest (/talk answers 303), so the signed-in behaviour is judged from source and tests. No markup, colour or layout changes, so the design principles are untouched. Two things I would do next: (1) the cap on talkJs went from 17,100 to 17,600 bytes; claw it back by trimming elsewhere in the script, since the page is meant to ship little JS. (2) The talk-page assertions now use toContain on the JSON string; parse it and assert on v so a format slip cannot pass. Also consider clearing talk-draft:* on sign-out, because localStorage outlives the session on a shared browser.
I took the second suggestion and left the other two. The talk-page tests and tsc pass locally; the forge's check hasn't run on the new push.
- Taken, assert on
v: the three draft assertions intest/talk-page.test.tsnow parse the stored JSON and checkv, so a format slip can't pass. My first push of this lefttscerrors from the missing non-null assertion. The follow-up commit fixes them, so the first of the two new commits was red for a short time. - Not taken, claw the cap back: the script was already 72 bytes under the old 17,100 limit and the draft logic needs about 450. Getting back under it means cutting unrelated /talk features, and I didn't want to do that on this pull. Trimming
talkJsis better done as its own change, and I can open it if you want. - Not taken, clear drafts on sign-out: draft keys already include the user id, so one account never reads another's draft. Sign-out lives in a different script, and wiping
localStoragethere would be a separate change. It's a fair follow-up.
The look-pages comment is the gate's automatic notice again. The change alters no markup or layout, so I did nothing for it.
<!-- look-pages a85388ca1b9b --> Look pages for a85388c, from the gate:
look pages (inferred): this pull changes src/web/pages/talk_client.ts; the forge pictures /talk (src/web/pages/talk_client.ts), the pages whose routes import it. A "Looks: <path>" or "No look: <why>" line in a commit message overrides
Nothing in this feedback asks for a code change, so I made no commit and pushed nothing. The look-pages note is the gate saying it will picture /talk, which is the right page, since it is the route that imports src/web/pages/talk_client.ts. I didn't add a Looks: or No look: override, because the inferred page is already correct.
What the pull does:
/talkkeeps the unsent message per conversation in the browser'slocalStorage.- Drafts older than 7 days are dropped.
- The tests parse the stored JSON and assert on its
vfield.
What I chose not to do: keep drafts on the server, or in the terminal composer. The terminal composer is a running process with no page to leave, so there is nothing to lose there.
To try it: open /talk, type a line, and reload. The line is still there.
Earlier asks: asserting on the stored v field is met (the three draft assertions parse the JSON). The two other asks were non-blocking and the builder declined them with reasons I accept: the 17,600 byte cap on talkJs, and clearing drafts on sign-out (keys already carry the user id). The no-door note is reasonable, since the draft lives in browser storage and the terminal composer has no page to leave. No design change: no markup, tokens or accent touched, and it works with JS off as before. A small module, a test against a fake storage, and no dependency.
Next, both non-blocking:
- Trim talkJs in its own pull so the cap can come back down.
- Clear talk-draft:* from localStorage on sign-out, which matters on shared devices.
/talk now keeps the unsent message per conversation in
localStorageand drops drafts older than 7 days. I ran the three talk test files,tsc,scripts/gate.ts --fixand the design lint, and all pass. I did not start the app or try it in a browser.What changed
sessionStorage, which a closed tab loses and which had no expiry. I replaced it rather than adding a second mechanism.draftJsblock insrc/web/pages/talk_client.tsdefinesdraftStore(store, key, now), withloadandsave.{t, v}under the existingtalk-draft:<user>:<conversation>key after the 300 ms pause, and onpagehideorvisibilitychange.loadfirst sweeps everytalk-draft:*entry that is older than 7 days or unparseable. A storage error is swallowed, so it never breaks the page.test/talk-draft.test.tsruns the shipped script against a fake storage. It covers save and restore per conversation, clearing on empty, the 7-day expiry with other keys left alone, and a throwing storage.test/talk-page.test.tsnow injectslocalStorageinstead ofsessionStorage, and its fake storage gainedlengthandkey. Its draft assertions now expect the{t, v}format.The JavaScript budget: the page-size test in
test/talk-page.test.tscappedtalkJsat 17,100 bytes and the script was already at 17,028. The draft logic needs about 450 bytes, so I raised the cap to 17,600. If you would rather hold the old cap, the draft code has to shrink or another part of the script has to give something up.Not done
To try it
Closes #14488