Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions chatkit/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,12 @@ def recurse(component: WidgetComponent | WidgetRoot):
components[component.id] = component

if hasattr(component, "children"):
children = getattr(component, "children", None) or []
for child in children:
recurse(child)
children = getattr(component, "children", None)
if isinstance(children, WidgetComponentBase):
recurse(children)
elif isinstance(children, list):
for child in children:
recurse(child)

recurse(component)
return components
Expand Down
22 changes: 22 additions & 0 deletions tests/test_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,28 @@
),
["widget.root.updated"],
),
# DynamicWidgetRoot with a single-child object
(
DynamicWidgetRoot(
type="Card",
children=DynamicWidgetComponent.model_validate({
"type": "Text",
"id": "text",
"value": "Hello",
"streaming": True,
}),
),
DynamicWidgetRoot(
type="Card",
children=DynamicWidgetComponent.model_validate({
"type": "Text",
"id": "text",
"value": "Hello, world!",
"streaming": True,
}),
),
["widget.streaming_text.value_delta"],
),
],
)
def test_diff(
Expand Down
Loading