Skip to content

feat(react): stream generated UI elements as they arrive - #1647

Open
blove wants to merge 1 commit into
mainfrom
blove/react-genui-progressive-streaming
Open

blove wants to merge 1 commit into
mainfrom
blove/react-genui-progressive-streaming

Conversation

@blove

@blove blove commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

Summary

Angular's parse-tree-store.ts materializes the partial spec on every push, so generated-UI elements and their string props render while a message streams, and chat-generative-ui.component.ts seeds spec.state into the store path by path. React's generative-ui.tsx kept only elements whose JSON node was complete and seeded state only once the whole object finished, so elements popped in one at a time.

Gap check: this was not a stated safety decision. #1604, which introduced it, describes the behavior ("each element appears as its JSON finishes") but gives no reason, and no comment or doc explains it. The only related docs line says the cockpit example waits for a confirmed layout.

This adds an opt-in progressive flag to MessageGenerativeUi (Chat / MessageList generativeUi). It is opt-in because it changes what views receive mid-stream, and React library defaults stay unchanged.

With progressive: true:

  • An element renders once its type string has finished, so a half-typed type never flashes the fallback. String props grow in place. Other props, child IDs, visible and repeat apply once each has finished, and an element whose visible or repeat is still open waits.
  • on bindings apply only once the whole element has finished, so emit dispatches nothing against partial params.
  • spec.state seeds one top-level path at a time. The per-message store is rebuilt with the new paths under what is already there, so seeding emits no stateChange and a value a view already wrote is kept (Angular's untouched rule). A supplied shared store still does not receive spec state, as today.
  • Keys stay stable (element IDs), so the same DOM nodes update in place.
  • A finished spec renders the same HTML as the default path.

Docs: README section and one line in the React generative-UI guide (no contractions).

Verification

  • New tests (written first, seen failing): an element appears before the spec completes and its string prop grows in the same node; child IDs wait to finish; state is seeded path by path (read-only and per-message store, keeping an edit made between seeds, with no seed stateChange); no handler runs from an element whose JSON is open, including after its on closes; the finished render matches the default innerHTML.
  • Mutation check: letting an incomplete element keep its on bindings fails the handler test; restored.
  • NX_DAEMON=false npx nx run-many -t test lint type-tests -p react passes (1531 tests; lint 0 errors).
  • node scripts/react-parity/inventory.mjs --check --drift warn passes. There are no new exports or files, and MessageGenerativeUi is type-only.
  • node --test scripts/react-parity/verify-packages.spec.mjs: 103 pass, 0 fail.
  • npx vitest run in apps/website: 1967 pass, and the docs content rules pass. Two files fail for environment reasons and still fail when rerun alone with a 120s timeout: generate-api-docs.spec.ts (the symlinked node_modules resolves outside the worktree) and api/ingest/route.spec.ts (posthog-node is missing from the shared node_modules). Neither touches this change.

🤖 Generated with Claude Code

Angular materializes a streaming json-render spec on every chunk, so
elements and their string props render while the message streams, and
chat-generative-ui seeds spec.state path by path. React kept only elements
whose JSON had finished and seeded state once the whole object had, so
elements popped in one at a time. PR #1604 described that behavior but gave
no safety reason for it.

generativeUi.progressive (off unless set) renders an element once its type
has finished, lets its string props grow as they stream, and applies other
props, child IDs, visible and repeat only once each has finished. on
bindings apply only once the whole element has, so no action runs with
half-written params. A spec's own state is seeded one top-level path at a
time; the own store is rebuilt rather than written, so seeding reports no
stateChange, and a value a view already wrote is kept. A finished spec
renders the same either way.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@blove
blove enabled auto-merge November 18, 2026 01:19

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