Skip to content

fix(client): restore page chat scope after StrictMode effect replay - #122

Open
HaningZS wants to merge 1 commit into
CopilotKit:mainfrom
HaningZS:fix/page-chat-strictmode
Open

HaningZS wants to merge 1 commit into
CopilotKit:mainfrom
HaningZS:fix/page-chat-strictmode

Conversation

@HaningZS

@HaningZS HaningZS commented Oct 9, 2026

Copy link
Copy Markdown

Workflow and problem

In development, open a page with an available specialist and assistant configuration, then select Send to page assistant without typing first. Opening page chat with an empty draft is supported by the component.

main.tsx enables React StrictMode. Its initial effect setup → cleanup → setup replay clears PageChatRequests' selected scope, but the previous setup never restored it. The submit handler sets busy=true, then run(scope) returns before beforeChat or the conversation API executes; no settled callback releases busy. The input and send button stay disabled.

An input change or parent rerender before submitting re-selects the scope and can mask the bug. This is a development StrictMode lifecycle bug; I am not claiming the production build or normal typed-message flow fails.

Change

  • Restore the current scope in the lifecycle effect's setup and run that setup when the page/specialist scope changes.
  • Retain the existing render-time selection and cleanup invalidation, so stale requests remain isolated.
  • Add 10 component regressions: first empty submit with and without StrictMode, save/API failure and retry, stale successes/errors after a page or available-specialist change without settling a newer request, and responses after unmount.

Only PageConversation.tsx and its new component test change. No dependency, configuration, SDK, or backend changes.

Verification

On Node 24.16.0, based on current upstream main:

  • Red → green: on unmodified main source, the StrictMode first-empty-submit regression fails because beforeChat is called zero times; the other 9 new component cases and 3 existing request-controller cases pass. With the fix, all 13 focused tests pass.
  • npm run check-format — passed.
  • npm run lint — passed.
  • npm run typecheck — passed.
  • npm test — 49 files, 312 tests passed.
  • npm run build — passed.
  • git diff --check — passed.

Actual Chrome browser checks used the real PageConversation, ReactDOM StrictMode and repository CSS in an isolated Vite fixture:

  • Before the fix: first empty click makes 0 conversation requests and leaves both controls disabled.
  • After the fix: 1280px click and 390px keyboard submission each make exactly 1 request and open the chat panel.
  • Keyboard check follows Tab → input → specialist selector → send button → Enter, without typing first.
  • A 390px fixture API failure shows the error, re-enables input/send, and permits keyboard retry; 2 total requests, then success.
  • No horizontal document overflow or browser page errors; narrow dock and error-state screenshots were inspected locally.

Verification limits

The component tests mock the API and child Chat. The browser fixture intercepts the conversation API and replaces only the child Chat; it validates setup lifecycle, controls, layout and the handoff, not a live Intelligence/model response. No live cloud chat, voice, Slack or Docker deployment was tested. Temporary fixture scripts and screenshots are not committed.

The build retains the existing Vite native-config and large-chunk warnings. Tests use the repository's existing react-test-renderer dependency.

AI-assisted investigation, implementation and independent code review; all reported commands and browser checks were executed locally.

Why:
- StrictMode cleanup clears the page-chat request scope without setup restoring it.
- A first empty submit then leaves the dock busy without reaching save or API work.

What:
- Restore the current request scope in effect setup and pair cleanup with that scope.
- Add component regressions for initial submit, retry, scope changes, and unmount.

Risk:
- Keep existing request-generation and render-time invalidation behavior unchanged.
- API and Chat are mocked in UI fixtures; live provider behavior was not tested.

Tests:
- Regression failed on unmodified source; focused suites now pass 13 tests.
- npm test: 312 tests passed across 49 files on Node 24.16.0.
- npm run check-format; npm run lint; npm run typecheck; npm run build.
- Chrome fixture: 1280px click, 390px Tab/Enter, and API-failure retry.

Live Docs:
- No setup, dependency, or public API change; no documentation update required.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant