Public: anyone can read this; the crew can change it.
The feed composer keeps what you typed across a reload, and clears it once the tell is sent #5913
The home composer now keeps its draft across a reload, but I couldn't run the new browser test here. Chromium can't start in this sandbox, so the check on this push will be its first run. The unit tests I could run (test/offline.test.ts, test/home-feed.test.ts, test/feed-page.test.ts) pass, and tsc --noEmit is clean.
stopped parked by the crew deploy 210bdf9
5 earlier comments · 3 events
The home composer now keeps its draft across a reload, but I couldn't run the new browser test here. Chromium can't start in this sandbox, so the check on this push will be its first run. The unit tests I could run (test/offline.test.ts, test/home-feed.test.ts, test/feed-page.test.ts) pass, and tsc --noEmit is clean.
What changed
- Saving and restoring: the draft goes to localStorage under
draft.<user id><path>, at most once a second. It is put back on load into the same two-row textarea, so nothing shifts. It never overwrites a phone-share draft. - After a send: a successful send, or one queued while offline, clears the draft. A send the forge refuses (4xx) puts the words back into the box and the draft.
- Sign-out: the existing sign-out handler also removes every
draft.*key. - Outbox: it now reports a
refusedcount next tosent, so a refusal can be told from a success. I updatedtest/offline.test.tsto the new shape and to the case where one send is refused and one lands. - Browser test:
test/composer-draft.test.tsdrives Chromium through type, reload, find it, send, reload, find it empty, then a refused send keeping the text, then sign-out clearing the drafts. To get at Chromium I exportedwithPagefromsrc/release/axe.ts. It skips by name when there is no Chromium. - Size and scripts: the client grows by 599 bytes raw (about 230 gzipped). There is no new script and no dependency.
- README: it has a short section on the draft.
Left out
- The "the forge" thought target posts as a plain form, so its draft is dropped on submit, and a refusal there doesn't bring it back.
- The lean client home has no feed script, so it keeps no draft.
- A tell queued offline is gone from the box straight away, since the outbox owns it, so it comes back only if the forge refuses it when it lands.
To try it
- Open
/signed in. - Type in the composer and reload after a second. The text is back.
- Post it and reload. The box is empty.
The feature works as described and is small: no new script, no dependency, no markup change beyond data-draft, still a plain form with JS off, and the key carries the server-rendered user id. The preview answers 200. One thing to fix first: the browser test is built on fixed sleeps, and the direction asks for tests that stay fast and never flake. It spends about 6 s on Bun.sleep(300/1300/1000/1200/500) racing a 1 s debounce. Poll for the condition instead, e.g. a waitFor(expression) that re-evaluates until it is true or times out. Also, the only assertion that always runs (feedJs contains draft.) proves nothing about behaviour. Where there is no Chromium, the draft logic has no test at all. Pull the save/restore/clear logic into a small function like forgeOutbox, so test/offline.test.ts can drive it with a fake storage, as it does for the outbox. Smaller points are in the line comments.
I addressed the review on the same branch and pushed. The new unit tests pass here, but the Chromium test could not run in this sandbox, so the rewritten browser test is unverified.
- Draft logic moved out of
feed.ts. The save, restore, refuse, clear and forget-all logic now lives insrc/web/draft.tsasforgeDraft(storage, box, key, later), shipped to the page the same way asforgeOutbox. - Readable names. The one-letter globals are gone, and sign-out uses an explicit
startsWith("draft.")instead of the|| removeItemtrick. - Refusal no longer overwrites new typing. On a refused send the words are put back only if the box is still empty. Restore on load follows the same rule.
- New unit tests. Five tests in
test/composer-draft.test.tsdriveforgeDraftwith a fake storage and a fake timer, so the draft logic is tested without Chromium. They cover one save per typing burst, restore into an empty box only, clear, refusal keeping newer text, and forget-all leavingforge.outboxalone. The oldfeedJs contains draft.assertion now checks forforgeDraft(. - Browser test polls instead of sleeping. All the
Bun.sleepwaits are replaced by awaitFor(expression)that re-checks every 25 ms and times out at 8 s. - Issue reference. The header now cites #5913 instead of #5901.
bun x tsc --noEmit and the design lint are clean, and test/offline.test.ts still passes. The browser test failed here only because Chromium would not start in the sandbox ("did not offer a DevTools endpoint"); the forge's check will run it.
Behaviour change: the draft is now cleared as soon as the text passes validation, before the tell is queued. That also covers the no-script fallback where the form posts natively, which would otherwise bring the draft back after the redirect.
🤖 Generated with Claude Code
Good shape: draft.ts is small and tested through the code that ships, no new script or dependency, and the textarea keeps its size so nothing shifts. One miss against the issue ("clears it once the tell is sent"): the "the forge" target. In the submit handler the early return for FORGE_TARGET runs before draft.clear(), so the draft stays in localStorage, the form posts natively, and on the redirected page restore() puts the sent words back into the empty box. This is the only target for anyone with no writable app. The README says the draft is "dropped on submit" there; the code does not do that. Fix first: call draft.clear() (and cancel the pending save) before that early return, once the text passes the !text check, and add a browser-test step that sends to the forge target and reloads to an empty box. Smaller: withPage is now exported from src/release/axe.ts only for a test; move it to a shared helper if you can. Also the no-JS path has no draft (documented), which is fine.
The forge target now clears the draft, and I pushed the fix. The two Chromium tests could not run in this sandbox, so the new browser step is unrun. Chromium won't start here, which also fails the existing axe browser test, so it is not caused by this change. Type check, design lint and the other tests pass, including the new unit test.
- Forge target: in the submit handler,
draft.clear()now runs right after the!textcheck, before the early return for the forge target (src/web/studio/feed.ts). The native post no longer brings the sent words back on the redirected page. - Pending save:
clear()insrc/web/draft.tsnow also cancels a save that is still waiting. Without that, a save started by typing a second earlier could write the sent text back after the clear. A unit test with a fake timer covers it. - Browser test: a new step types text, sends to "the forge" (which posts natively), waits past the debounce, and checks the reloaded box and
localStorageare empty. withPage: moved intosrc/release/devtools.ts, imported by bothaxe.tsand the test, soaxe.tsno longer exports it just for a test.
My earlier summary said the draft was cleared before queueing for every target. That was wrong for the forge target, and this fixes it.
🤖 Generated with Claude Code
I merged main into the branch and pushed it. The merge now has no conflicts. The one test I couldn't run here is the real-browser composer test, because chromium won't start in this sandbox. The forge's check runs it on this push.
- What conflicted:
maincutREADME.mdfrom about 1,700 lines to about 700 and moved the long sections out todocs/. I tookmain's README as it stands. - Where my note went: the "composer keeps your draft" note is now at the end of
docs/FEED.md, and the README's existingdocs/FEED.mdlink line mentions it. - Tests: the composer draft unit tests and the feed, home-feed and feed-page suites pass. I did not run the type check or the full
bun test; the full run was too slow to wait on.
No code changed in this merge. src/web/studio/feed.ts auto-merged.
I merged main into this branch and pushed it. The only conflict was in src/web/studio/feed.ts, and I kept both sides there. main's changes to the feed stay, and the composer-draft changes still work on top of them. These two checks passed:
bun x tsc --noEmit- The draft and feed tests: 151 pass, 0 fail.
I did not run the whole suite; the forge's check runs that on the push.
The feature itself is unchanged. The feed composer keeps what you typed in the browser's localStorage, restores it when you come back, and clears it once you post.
To try it, open the feed, type in the composer, reload, and the text is still there.
Parked by the crew: the check stayed red through 2 automatic tries
The home composer now keeps its draft across a reload, but I couldn't run the new browser test here. Chromium can't start in this sandbox, so the check on this push will be its first run. The unit tests I could run (
test/offline.test.ts,test/home-feed.test.ts,test/feed-page.test.ts) pass, andtsc --noEmitis clean.What changed
draft.<user id><path>, at most once a second. It is put back on load into the same two-row textarea, so nothing shifts. It never overwrites a phone-share draft.draft.*key.refusedcount next tosent, so a refusal can be told from a success. I updatedtest/offline.test.tsto the new shape and to the case where one send is refused and one lands.test/composer-draft.test.tsdrives Chromium through type, reload, find it, send, reload, find it empty, then a refused send keeping the text, then sign-out clearing the drafts. To get at Chromium I exportedwithPagefromsrc/release/axe.ts. It skips by name when there is no Chromium.Left out
To try it
/signed in.Closes #5901