Skip to content

Commit a2c1b1f

Browse files
committed
ai-plugin: Fix rendering issues
1 parent 35a16b0 commit a2c1b1f

File tree

3 files changed

+216
-264
lines changed

3 files changed

+216
-264
lines changed

ai-assistant/src/ContentRenderer.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,14 @@ const TableWrapper: React.FC<{ children: React.ReactNode }> = React.memo(({ chil
9999

100100
// Extract table rows from children
101101
const tableElement = React.Children.only(children) as React.ReactElement;
102-
const tbody = React.Children.toArray(tableElement.props.children).find(
102+
const tableChildren = tableElement.props.children;
103+
104+
if (!tableChildren) {
105+
// No children found, return table as is
106+
return <Box sx={{ overflowX: 'auto', width: '100%', mb: 2 }}>{children}</Box>;
107+
}
108+
109+
const tbody = React.Children.toArray(tableChildren).find(
103110
(child: any) => child?.type === 'tbody' || child?.props?.component === 'tbody'
104111
);
105112

@@ -109,7 +116,8 @@ const TableWrapper: React.FC<{ children: React.ReactNode }> = React.memo(({ chil
109116
}
110117

111118
const tbodyElement = tbody as React.ReactElement;
112-
const rows = React.Children.toArray(tbodyElement.props.children);
119+
const tbodyChildren = tbodyElement.props.children;
120+
const rows = tbodyChildren ? React.Children.toArray(tbodyChildren) : [];
113121
const hasMoreRows = rows.length > maxRows;
114122
const visibleRows = showAll ? rows : rows.slice(0, maxRows);
115123

@@ -120,7 +128,7 @@ const TableWrapper: React.FC<{ children: React.ReactNode }> = React.memo(({ chil
120128

121129
// Clone the table with the limited tbody
122130
const limitedTable = React.cloneElement(tableElement, {
123-
children: React.Children.map(tableElement.props.children, (child: any) => {
131+
children: React.Children.map(tableChildren, (child: any) => {
124132
if (child?.type === 'tbody' || child?.props?.component === 'tbody') {
125133
return limitedTbody;
126134
}

0 commit comments

Comments
 (0)