Repository navigation
fix(web): keep an unsubmitted chat draft across a page reload - #663
Conversation
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
composer-draft.ts(new) —composerDraftKey/loadComposerDraft/saveComposerDraftbacked bywindow.sessionStorageunderpaca.composer-draft:<pathname>; every storage access is wrapped so a disabled or full store degrades to "no persistence" without breaking the composer.thread.tsx—useComposerDraft(aui, text)hooked into the sharedComposer. It restores viaaui.composer().setTexton the first effect run before persisting (so an empty first render does not wipe the draft), and persists/clears on every text change.composer-draft.test.ts(new) — round-trip + clear-on-empty, and per-page key separation.
The routing makes the pathname key safe: the project float is hidden on conversations pages (routes/_authenticated/projects/$projectId.tsx:66) and the global float is hidden on /projects/* and /conversations/* (routes/_authenticated.tsx:95-98), so at most one Composer is mounted per pathname and two live composers cannot clobber the same key. The restore-before-persist ordering and the clear-on-empty behavior are both correct for the reload flow this targets.
ℹ️ Draft key shifts when a persistent composer navigates
The project float lives in the project layout and ConversationView is reused across $conversationId changes, so those Composer instances stay mounted while the pathname changes. Because restored.current is never reset when key changes (thread.tsx:387-397), the hook does not restore the newly-navigated-to page's saved draft; instead the live text is re-saved under the new key. The same draft therefore gets persisted under every pathname that composer visits, and a stale per-page copy can resurface on a later reload at an earlier page.
This does not affect the targeted case (after a reload the composer mounts fresh, so restored is false and the draft restores correctly), and it is inherently hard to separate a single live composer's text from per-page keys. Flagging only so the per-page isolation claim is a conscious choice.
deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
The composer's text lives only in the assistant-ui runtime, so a reload throws it away. An expired session forces exactly that reload — Paca already refreshes its own access token silently, but a lapsed refresh token or an identity-proxy/SSO session bounces the whole document through sign-in, which no client code can keep the SPA alive across. Park the composer text in sessionStorage, keyed by pathname, and restore it when the composer mounts empty; clear it as soon as the composer empties so a sent message cannot come back as a ghost draft. The hook sits in the shared thread composer, so every chat surface (project float, global float, new-conversation page, conversation page) is covered by one change. Refs Paca-AI#662
b145b6a to
8547ff9
Compare
|
Thanks — the pathname-key observation was the useful one, and I've taken it rather than accepted the duplication. The draft key is now fixed at mount: Re-verified on 8547ff9: |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Pinned the composer draft-storage key to a
useRefcaptured at mount (thread.tsx), so a persistent composer (project float, reused conversation view) keeps writing to the page it mounted on rather than re-saving its live text under every pathname it passes. This resolves the prior note that a stale per-page copy could resurface on a later reload. - The
sessionStoragehelpers and their tests are unchanged from the prior review.
The reload-bounce target still restores correctly: after a full reload the composer mounts fresh, so key is the current pathname and restored.current is false. The deliberate trade-off (a persistent composer only writes to its mount pathname) is documented in the new comment and is outside this PR's scope.
deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
pikann
left a comment
There was a problem hiding this comment.
LGTM! Thank you for the contribution! 🚀

Summary
A chat message that has been typed but not sent is now kept in
sessionStorageand restored when the composer mounts empty, so the reload an expired session forces no longer discards it. Closes #662.The composer's text lives only in the assistant-ui runtime, which a page load throws away. Paca already refreshes its own access token silently (
lib/api-client.ts401 →/auth/refresh→ replay), so what forces the reload is a lapsed refresh token or a deployment identity-proxy/SSO session — a full-document sign-in bounce no client code can avoid. The reload cannot be prevented from inside the app, so it is made non-destructive instead.Type of Change
What changed
apps/web/src/lib/composer-draft.ts—composerDraftKey/loadComposerDraft/saveComposerDraft, keyed by pathname, with storage access wrapped so a disabled or full storage never breaks the composer.apps/web/src/components/assistant-ui/thread.tsx—useComposerDraft, called by the thread composer. That composer is what all four chat surfaces render (project floating chat, global floating chat, new-conversation page, conversation page), so the fix is one hook rather than four call-site changes. It restores before it persists on the first run (otherwise an empty first render would delete the draft it is about to restore), and clears the stored text whenever the composer empties — after a send, or after the user empties it.sessionStorage, notlocalStorage: the draft only has to outlive a reload in this tab, and a prompt should not be left on disk once the tab is gone. Pathname keying keeps pages apart and matches the URL a re-auth bounce returns to.Verification
npx vitest run src/lib/composer-draft.test.ts— 2 passed (round-trip + clear-on-empty, and per-page separation).setItemunconditionally) and re-ran:AssertionError: expected '' to be null, 1 failed | 1 passed — the test does catch the regression.cd apps/web && npx @biomejs/[email protected] check <the three files>— clean.npx esbuild --loader:.tsx=tsx src/components/assistant-ui/thread.tsx --outfile=/dev/null— parses.npx tsc -b— no diagnostics in the changed files. The 5 errors it reports are inroute-error-boundary.test.tsx,routes/__root.tsxandroutes/_authenticated.tsxand come from the newer@tanstack/react-routerthat npm resolves without the repo'sbun.lock; they are present onupstream/mastertoo.Local note for anyone re-running the suite on Node 26:
window.localStorageisundefinedbecause Node's ownlocalStorageshadows jsdom's, so every test file fails atsrc/test/setup.tsunlessNODE_OPTIONS=--localstorage-file=<path>is set. Not related to this change.Not covered (deliberately)