Skip to content

Commit 8a395ad

Browse files
Copilothotlong
andcommitted
Fix table component SSR error by making useDataScope context-safe
- Modified useDataScope to handle missing SchemaRendererProvider gracefully - Updated table renderer to support both inline data and data binding - Added support for both accessorKey and key column properties - Ensured compatibility with Next.js static generation Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent d317ceb commit 8a395ad

2 files changed

Lines changed: 18 additions & 10 deletions

File tree

packages/components/src/renderers/data-display/table.tsx

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ import {
2020
import { cn } from '../../lib/utils';
2121

2222
export const SimpleTableRenderer = ({ schema, className }: any) => {
23-
const data = useDataScope(schema.bind);
24-
const columns = schema.props?.columns || [];
23+
// Try to get data from binding first, then fall back to inline data
24+
const boundData = useDataScope(schema.bind);
25+
const data = boundData || schema.data || schema.props?.data || [];
26+
const columns = schema.columns || schema.props?.columns || [];
2527

2628
// If we have data but it's not an array, show error.
2729
// If data is undefined, we might just be loading or empty.
@@ -36,8 +38,10 @@ export const SimpleTableRenderer = ({ schema, className }: any) => {
3638
<Table>
3739
<TableHeader>
3840
<TableRow>
39-
{columns.map((col: any) => (
40-
<TableHead key={col.key}>{col.label}</TableHead>
41+
{columns.map((col: any, index: number) => (
42+
<TableHead key={col.key || col.accessorKey || index}>
43+
{col.label || col.header}
44+
</TableHead>
4145
))}
4246
</TableRow>
4347
</TableHeader>
@@ -51,11 +55,14 @@ export const SimpleTableRenderer = ({ schema, className }: any) => {
5155
) : (
5256
displayData.map((row: any, i: number) => (
5357
<TableRow key={row.id || i}>
54-
{columns.map((col: any) => (
55-
<TableCell key={col.key}>
56-
{row[col.key]}
57-
</TableCell>
58-
))}
58+
{columns.map((col: any, index: number) => {
59+
const accessor = col.key || col.accessorKey;
60+
return (
61+
<TableCell key={col.key || col.accessorKey || index}>
62+
{row[accessor]}
63+
</TableCell>
64+
);
65+
})}
5966
</TableRow>
6067
))
6168
)}

packages/react/src/context/SchemaRendererContext.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ export const useSchemaContext = () => {
3535
};
3636

3737
export const useDataScope = (path?: string) => {
38-
const { dataSource } = useSchemaContext();
38+
const context = useContext(SchemaRendererContext);
39+
const dataSource = context?.dataSource;
3940
if (!path) return dataSource;
4041
// Simple path resolution for now. In real app might be more complex
4142
return path.split('.').reduce((acc, part) => acc && acc[part], dataSource);

0 commit comments

Comments
 (0)