Skip to content

feat(react): report the Chat lifecycle to content inside it and to the app - #1642

Open
blove wants to merge 1 commit into
mainfrom
blove/react-chat-lifecycle
Open

blove wants to merge 1 commit into
mainfrom
blove/react-chat-lifecycle

Conversation

@blove

@blove blove commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Summary

Angular's chat exposes four lifecycle values on its CHAT_LIFECYCLE token. React Chat had no equivalent. This adds them:

  • useChatLifecycle() returns componentReady, firstMessageSent, messageCount and inputSubmittedAt to content rendered inside a Chat (header, welcome, composer slots). It returns null outside a Chat.
  • onLifecycleChange on Chat reports the same four values to the app each time one changes, starting with componentReady after mount.

The values live in a small store read with useSyncExternalStore, so Chat itself does not render again when one changes. Nothing changes for apps that use neither.

Differences from Angular

React has no clearThread, so:

  • messageCount and inputSubmittedAt start again when the session prop changes.
  • Only composer submits are counted. A message the app sends with session.submit sets firstMessageSent when its run is seen running and leaves the other two alone.

Not included

  • The LangGraph agent lifecycle timestamps (AGENT_LIFECYCLE): they belong in the runtime session.
  • Website docs. libs/react/README.md documents the API.

Verification

  • nx run-many -t lint,type-tests,build -p react passes.
  • Full libs/react vitest suite: 100 files, 1530 tests pass. A first run had 13 timeouts on a heavily loaded machine; those files passed alone and the suite passed on a rerun with a longer per-test timeout.
  • 7 new tests; three deliberate breaks (no session reset, no running flip, no count) each fail one.
  • node --test scripts/react-parity/verify-packages.spec.mjs passes (103); verify-boundaries.mjs passes; inventory.mjs --check reports only baseline drift.
  • Not checked in a browser: the change has no visual output.

🤖 Generated with Claude Code

…e app

Chat now tracks componentReady, firstMessageSent, messageCount and
inputSubmittedAt. Content rendered inside the chat reads them with
useChatLifecycle(); an app outside it passes onLifecycleChange. The values
live in a small store, so Chat itself does not render again when one changes.

messageCount and inputSubmittedAt start again when the session prop changes.
firstMessageSent also turns true when a run the composer did not start is
seen running, and stays true while the Chat is mounted.
@blove
blove enabled auto-merge November 17, 2026 23:51

This branch has not been deployed

No deployments
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