Repository navigation
fix: container renderers empty under documented composition #2080
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
813b198
7514ee2
41c50ff
bb0e50a
0d98c4b
74627ee
2c70def
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@flow-state-dev/react": patch | ||
| --- | ||
|
|
||
| `ItemsRenderer` provides the session item list to nested stream-aware components when none is already in scope, and exports `SessionItemsProvider` / `useSessionItems` (FIX-1498). |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,14 @@ | ||
| "use client"; | ||
|
|
||
| import { createContext, useContext } from "react"; | ||
| import type { OutputItem } from "@flow-state-dev/core/items"; | ||
|
|
||
| const SessionItemsContext = createContext<OutputItem[]>([]); | ||
|
|
||
| export const SessionItemsProvider = SessionItemsContext.Provider; | ||
|
|
||
| export function useSessionItems(): OutputItem[] { | ||
| return useContext(SessionItemsContext); | ||
| } | ||
| /** | ||
| * Re-export of the session item list context from `@flow-state-dev/react`. | ||
| * | ||
| * `ItemsRenderer` mounts the provider with the list it renders. Import | ||
| * `useSessionItems` / `SessionItemsProvider` from here in copied registry | ||
| * components so they share that context. Mount the provider yourself only | ||
| * when rendering stream-aware cards outside `ItemsRenderer`. | ||
| */ | ||
| export { | ||
| SessionItemsProvider, | ||
| useSessionItems, | ||
| } from "@flow-state-dev/react"; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| /** | ||
| * Session item list for nested stream-aware renderers. | ||
| * | ||
| * Container and HITL cards (EventedActors, Debate, RoutedSpecialists, | ||
| * TaskPlan, Approval) read the current stream via {@link useSessionItems}. | ||
| * {@link ItemsRenderer} mounts {@link SessionItemsProvider} with the list it | ||
| * is rendering when no provider is already in scope, so the documented | ||
| * FlowProvider + ItemsRenderer composition supplies the items without a | ||
| * second provider. An ancestor provider is left in place: a caller such as | ||
| * RequestGroup passes a filtered subset, and TaskPlan still needs the | ||
| * fuller list above it. | ||
| * | ||
| * Mount {@link SessionItemsProvider} yourself when rendering those cards | ||
| * outside {@link ItemsRenderer} (tests, replayed snapshots). TaskPlan also | ||
| * accepts an explicit `items` prop for that case. | ||
| */ | ||
| import { | ||
| createContext, | ||
| createElement, | ||
| useContext, | ||
| type ReactNode | ||
| } from "react"; | ||
| import type { OutputItem } from "@flow-state-dev/core/items"; | ||
|
|
||
| const SessionItemsContext = createContext<OutputItem[] | null>(null); | ||
|
|
||
| /** | ||
| * Props for {@link SessionItemsProvider}. | ||
| */ | ||
| export type SessionItemsProviderProps = { | ||
| /** Session item list nested renderers should read. */ | ||
| value: OutputItem[]; | ||
| children?: ReactNode; | ||
| }; | ||
|
|
||
| /** | ||
| * Provides the session item list to {@link useSessionItems} consumers. | ||
| * | ||
| * {@link ItemsRenderer} mounts this automatically. Wrap a subtree yourself | ||
| * only when rendering stream-aware cards outside that helper. | ||
| */ | ||
| export function SessionItemsProvider( | ||
| props: SessionItemsProviderProps | ||
| ): ReactNode { | ||
| return createElement( | ||
| SessionItemsContext.Provider, | ||
| { value: props.value }, | ||
| props.children | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Reads the nearest session item list, or `[]` when no provider is mounted. | ||
| */ | ||
| export function useSessionItems(): OutputItem[] { | ||
| return useContext(SessionItemsContext) ?? []; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Simplify (optional):
Comment on lines
+55
to
+56
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When Useful? React with 👍 / 👎. |
||
| } | ||
|
|
||
| /** | ||
| * Mounts {@link SessionItemsProvider} only when none is already in scope. | ||
| * | ||
| * Used by {@link ItemsRenderer}. A filtered `items` prop must not hide a | ||
| * fuller list an ancestor already provided. | ||
| */ | ||
| export function SessionItemsGate(props: { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Simplify (optional): |
||
| value: OutputItem[]; | ||
| children?: ReactNode; | ||
| }): ReactNode { | ||
| const mounted = useContext(SessionItemsContext) !== null; | ||
| if (mounted) return props.children ?? null; | ||
|
Comment on lines
+69
to
+70
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When a child or background session's Useful? React with 👍 / 👎. |
||
| return createElement( | ||
| SessionItemsProvider, | ||
| { value: props.value }, | ||
| props.children | ||
| ); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using
props.itemshere (not the filteredstream) is the right call—container/HITL hooks need owned snapshots and suspension pairing from the same array you pass in, whileSessionItemsGateensures you do not replace a fuller ancestor list. Worth keeping that invariant obvious in code review because it is easy to “simplify” incorrectly tostreamitems.