Where agent teams gather. Cross-platform team chat where AI agents are first-class teammates — with cloud or bring-your-own (Claude Code / Codex) brains.
TypeScript
fix(polls): a half-filled poll followed the conversation switch
zhuangxialiea570a3dd7b9c
diff --git a/src/desktop/ChatPane.tsx b/src/desktop/ChatPane.tsxindex b189b65..dccd256 100644--- a/src/desktop/ChatPane.tsx+++ b/src/desktop/ChatPane.tsx@@ -992,6 +992,13 @@ export function Composer({lastSyncedScopeRef.current = scopeKeysetMention(null)setEmojiOpen(false)+ // The poll composer is an overlay over the composer like the two above, and+ // it has to close for the same reason — except the cost of leaving it open+ // is higher. PollComposer keeps question/options in its own state and reads+ // `conversationId` from its props at submit time, so a half-filled poll that+ // survives the switch posts the OLD room's question into the NEW room, and+ // notifies everyone there.+ setPollComposerOpen(false)// Pull the just-loaded draft text for this scope (read via ref so// the effect doesn't re-fire on every keystroke) and hydrate the// contenteditable DOM.@@ -1017,6 +1024,10 @@ export function Composer({)}{pollComposerOpen && !isThread && (<PollComposer+ // Keyed so the draft can never straddle a conversation switch even if+ // another entry point forgets to close it: React remounts instead of+ // reconciling, and the internal question/options go with it.+ key={convoId}conversationId={convoId}onSubmitted={closePollComposer}onCancel={closePollComposer}diff --git a/tests/composer-overlays-scope.test.ts b/tests/composer-overlays-scope.test.tsnew file mode 100644index 0000000..2d25996--- /dev/null+++ b/tests/composer-overlays-scope.test.ts@@ -0,0 +1,54 @@+/**+ * Nothing the user half-typed may follow them into another conversation.+ *+ * ChatPane's composer has three overlays: the mention picker, the emoji picker+ * and the poll composer. The scope-change effect reset the first two and not+ * the third, and the third is the one that can do damage: `PollComposer` keeps+ * question/options in its own state and reads `conversationId` from its props+ * at submit time. So a half-filled poll that survived the switch posted the old+ * room's question into the new room — and notified everyone there.+ *+ * There is no React harness in this repo, so the source is what can be checked.+ * The invariant is that every overlay is reset together: the next one added has+ * to join them, and the poll composer is additionally keyed by conversation so+ * its draft cannot straddle a switch even if another entry point forgets.+ */+import assert from 'node:assert/strict'+import { readFile } from 'node:fs/promises'+import { describe, it } from 'node:test'++const CHAT_PANE = new URL('../src/desktop/ChatPane.tsx', import.meta.url)++/** The body of the effect that runs when the composer's scope changes. */+async function scopeEffect(): Promise<string> {+ const source = await readFile(CHAT_PANE, 'utf8')+ const start = source.indexOf('lastSyncedScopeRef.current = scopeKey')+ assert.notEqual(start, -1, 'the scope-change effect moved; this guard needs updating')+ return source.slice(start, start + 1200)+}++describe('composer overlays do not survive a conversation switch', () => {+ for (const [overlay, reset] of [+ ['mention picker', 'setMention(null)'],+ ['emoji picker', 'setEmojiOpen(false)'],+ ['poll composer', 'setPollComposerOpen(false)'],+ ] as const) {+ it(`the ${overlay} is reset`, async () => {+ assert.ok(+ (await scopeEffect()).includes(reset),+ `${overlay}: a draft left open in one conversation carries into the next one`,+ )+ })+ }++ it('the poll composer is keyed by conversation', async () => {+ // Without a key React reconciles the same element across the switch, so the+ // internal question/options stay while conversationId flips underneath them.+ const source = await readFile(CHAT_PANE, 'utf8')+ const render = source.slice(source.indexOf('<PollComposer'))+ assert.match(+ render.slice(0, 400), /key=\{convoId\}/,+ 'PollComposer is unkeyed — its draft can straddle a conversation switch and post to the wrong room',+ )+ })+})