Skip to content

fix(site/src/pages/AgentsPage): preserve chat input typed while loading - #26415

Merged
DanielleMaywood merged 2 commits into
mainfrom
danielle/codagt-538-typed-chat-input-is-lost-while-chat-loads
Jun 17, 2026
Merged

DanielleMaywood merged 2 commits into
mainfrom
danielle/codagt-538-typed-chat-input-is-lost-while-chat-loads

Conversation

@DanielleMaywood

Copy link
Copy Markdown
Collaborator

Problem

Typed chat input was lost when a chat was still loading. If the user started
typing in the message composer before the chat finished loading, their text was
discarded once the chat loaded.

Root cause

While the chat is loading, AgentChatPage renders a separate
AgentChatPageLoadingView whose AgentChatInput was wired with
initialValue="" and no onContentChange, so anything typed was never
persisted. When the queries resolved, that subtree unmounted and the loaded
editor mounted seeded from editing.editorInitialValue / initialEditorState,
which were captured (empty) at the page's first mount. The typed text was
therefore discarded.

Fix

  • Add handleLoadingDraftChange to useConversationEditingState. It persists
    the draft via the existing handleContentChange and also advances the seed
    state so the draft survives the loading-to-loaded editor swap. It is kept
    separate from handleContentChange, which runs on every keystroke in the
    loaded editor and must avoid re-renders.
  • Wire the loading branch to pass inputRef, initialValue,
    initialEditorState, remountKey, and
    onContentChange={editing.handleLoadingDraftChange} to the loading view.
  • AgentChatPageLoadingView now accepts and forwards those props to its
    AgentChatInput. As a side effect it also restores any pre-existing draft,
    which it previously ignored.

Testing

  • tsc --noEmit: clean
  • vitest (useConversationEditingState): passing, including a new regression
    test that a draft typed during loading is carried into the seed for the loaded
    editor
  • biome check: clean
  • Updated the 4 AgentChatPageLoadingView stories for the new props
Implementation notes

The seed update lives in a dedicated loading-only handler rather than in
handleContentChange because the latter is called on every keystroke in the
mounted loaded editor and deliberately avoids setState to prevent per-keystroke
re-renders. During loading there is no heavy editor mounted, so updating the seed
state there is cheap and the active Lexical instance is preserved (its
LexicalComposer key, remountKey, is unchanged and ValueSyncPlugin only seeds
once per mount).

Note

🤖 This PR was written by Coder Agent on behalf of Danielle Maywood

The loading view rendered its own AgentChatInput with initialValue=""
and no onContentChange, so text typed before the chat finished loading
was never persisted. When the queries resolved, that input unmounted and
the loaded editor mounted seeded from the mount-time draft snapshot
(empty), discarding the text.

Wire the loading input to the shared draft state and add
handleLoadingDraftChange, which persists the draft and advances the seed
state so the loaded editor mounts with the in-progress text.
@linear-code

linear-code Bot commented Jun 16, 2026

Copy link
Copy Markdown

CODAGT-538

@DanielleMaywood

Copy link
Copy Markdown
Collaborator Author

/coder-agents-review

@coder-agents-review

coder-agents-review Bot commented Jun 16, 2026 •

Copy link
Copy Markdown
Contributor

Chat: Review posted | View chat
Requested: 2026-06-16 17:01 UTC by @DanielleMaywood
Spend: $30.68 / $100.00

Review history
  • R1 (2026-06-16): 13 reviewers, 3 Nit, 1 P3, COMMENT. Review
  • R2 (2026-06-16): 4 reviewers, 3 Nit, 1 P3, APPROVE. Review

deep-review v0.7.1 | Round 2 | 894734a..9ccf830

Last posted: Round 2, 4 findings (1 P3, 3 Nit), APPROVE. Review

Finding inventory

Findings

# Sev Status Location Summary Round Reviewer Posted
CRF-1 P3 Author fixed (9ccf830) AgentChatPage.test.ts:316 Missing assertion that handleContentChange does NOT update seed state R1 Bisky P3, Chopper Note Yes
CRF-2 Nit Author fixed (9ccf830) AgentChatPage.tsx:572 Comment above handleLoadingDraftChange verbose; can be trimmed to 3 lines R1 Gon P2 (downgraded) Yes
CRF-3 Nit Author fixed (9ccf830) AgentChatPage.test.ts:342 Test comment restates test title and production comment R1 Gon P2 (downgraded) Yes
CRF-4 Nit Author fixed (9ccf830) AgentChatPage.tsx:573 Missing comma after "loading" creates garden-path sentence R1 Leorio Yes

Contested and acknowledged

(none)

Round log

Round 1

Panel (13 reviewers). Netero: no findings. 1 P3, 3 Nit. 2 Gon findings downgraded from P2 to Nit (comment verbosity is stylistic; Leorio explicitly praised the same comments). Reviewed against 894734a..9adab1f.

Round 2

Panel (4 reviewers: Bisky, Mafuuu, Gon, Chopper). Netero: no findings. CRF-1 through CRF-4 all verified fixed in 9ccf830. No new findings. APPROVE. Reviewed against 894734a..9ccf830.

About deep-review

CRF = Coder Review Finding (P0-P4, Nit, Note)

Reviewer Focus
Bisky tests
Chopper ops/errors
Churn-guard change verification
Ging language modernization
Gon naming
Hisoka edge cases
Killua perf
Kite change integrity
Knov contracts
Knuckle SQL
Kurapika security
Law decomposition
Leorio docs
Luffy product
Mafu-san process
Mafuuu contracts
Melody dispatch/pairing
Meruem structural
Nami frontend
Netero mechanical checks
Pariston premise testing
Pen-botter product gaps
Razor verification
Robin duplication
Ryosuke Go arch
Takumi concurrency
Zoro shape

🤖 Managed by Coder Agents.

@coder-agents-review coder-agents-review Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean, well-scoped fix. The diagnosis is accurate (loading view's input was disconnected from the editing state), the solution is proportional (a separate handler that bridges the gap without touching the per-keystroke path), and the test coverage is solid at 1:1 LOC ratio.

Pariston tried four alternative framings and could not build a case against the chosen approach. Meruem verified the structural correctness of the loading-to-loaded handoff, remountKey stability, and shared inputRef lifecycle. Mafu-san confirmed every factual claim in the PR description against the code.

1 P3, 3 Nits. The P3 is a missing negative assertion that would catch a future regression if someone merges the two handlers.

"I tried to build a case against this and could not. The problem is correctly understood, the solution is proportional, and the fix is at the right level of the causal chain." (Pariston)


site/src/pages/AgentsPage/AgentChatPage.test.ts:316

P3 [CRF-1] The existing test asserts localStorage after handleContentChange but never checks that editorInitialValue and initialEditorState remain unchanged. The two handlers differ by exactly one setDraftState call. If a future refactor adds setDraftState to handleContentChange, the full test suite passes while silently introducing per-keystroke re-renders in the loaded editor.

Two assertions after the localStorage check would close this:

// handleContentChange must NOT update the seed state, only localStorage.
// handleLoadingDraftChange exists for when the seed must advance.
expect(result.current.editorInitialValue).toBe("");
expect(result.current.initialEditorState).toBeUndefined();

(Bisky P3, Chopper Note)

🤖

🤖 This review was automatically generated with Coder Agents.

- Guard the handler separation: assert handleContentChange does not
  advance editorInitialValue/initialEditorState (CRF-1).
- Trim verbose comments on handleLoadingDraftChange and its test
  (CRF-2, CRF-3, CRF-4).

Copy link
Copy Markdown
Collaborator Author

🤖 This comment was written by Coder Agent on behalf of Danielle Maywood 🤖

CRF-1: Good guard. Added the two negative assertions in 9ccf830 so a future merge of handleContentChange and handleLoadingDraftChange fails the suite rather than silently reintroducing per-keystroke re-renders in the loaded editor.

@DanielleMaywood

Copy link
Copy Markdown
Collaborator Author

/coder-agents-review

@coder-agents-review coder-agents-review Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All four R1 findings verified fixed in 9ccf830.

CRF-1 (P3): Negative assertions added at test lines 327-329. handleContentChange now provably does not advance the seed. CRF-2/CRF-3: Comments trimmed to the essential content. CRF-4: Garden-path sentence eliminated by the CRF-2 rewrite.

Bisky verified both halves of the handler contract (positive and negative). Mafuuu traced the full loading-to-loaded lifecycle and checked adversarial scenarios (rapid typing then immediate load, navigation during loading, history-edit after load). Gon confirmed the rewritten comments are clean. Chopper found no operational concerns.

No new findings. Ship it.

🤖 This review was automatically generated with Coder Agents.

@DanielleMaywood
DanielleMaywood marked this pull request as ready for review June 16, 2026 17:53
@DanielleMaywood
DanielleMaywood merged commit cf0c9ce into main Jun 17, 2026
34 checks passed
@DanielleMaywood
DanielleMaywood deleted the danielle/codagt-538-typed-chat-input-is-lost-while-chat-loads branch June 17, 2026 08:58
@github-actions github-actions Bot locked and limited conversation to collaborators Jun 17, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants