Skip to content

Commit 9b3a69a

Browse files
committed
fix: enhance data source initialization and prevent state updates on unmounted components; update SimpleViewRenderer to accept dataSource prop
1 parent 988ad02 commit 9b3a69a

3 files changed

Lines changed: 40 additions & 29 deletions

File tree

apps/console/src/App.tsx

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -44,35 +44,46 @@ export function AppContent() {
4444
// Branding is now applied by AppShell via ConsoleLayout
4545

4646
useEffect(() => {
47-
initializeDataSource();
48-
}, []);
47+
let cancelled = false;
4948

50-
async function initializeDataSource() {
51-
try {
52-
const adapter = new ObjectStackAdapter({
53-
baseUrl: '',
54-
autoReconnect: true,
55-
maxReconnectAttempts: 5,
56-
reconnectDelay: 1000,
57-
cache: { maxSize: 50, ttl: 300_000 },
58-
});
49+
async function initializeDataSource() {
50+
try {
51+
const adapter = new ObjectStackAdapter({
52+
baseUrl: '',
53+
autoReconnect: true,
54+
maxReconnectAttempts: 5,
55+
reconnectDelay: 1000,
56+
cache: { maxSize: 50, ttl: 300_000 },
57+
});
5958

60-
// Monitor connection state
61-
adapter.onConnectionStateChange((event) => {
62-
setConnectionState(event.state);
63-
if (event.error) {
64-
console.error('[Console] Connection error:', event.error);
65-
}
66-
});
59+
// Monitor connection state
60+
adapter.onConnectionStateChange((event) => {
61+
if (cancelled) return;
62+
setConnectionState(event.state);
63+
if (event.error) {
64+
console.error('[Console] Connection error:', event.error);
65+
}
66+
});
6767

68-
await adapter.connect();
68+
await adapter.connect();
6969

70-
setDataSource(adapter);
71-
} catch (err) {
72-
console.error('[Console] Failed to initialize:', err);
73-
setConnectionState('error');
70+
if (!cancelled) {
71+
setDataSource(adapter);
72+
}
73+
} catch (err) {
74+
if (!cancelled) {
75+
console.error('[Console] Failed to initialize:', err);
76+
setConnectionState('error');
77+
}
78+
}
7479
}
75-
}
80+
81+
initializeDataSource();
82+
83+
return () => {
84+
cancelled = true;
85+
};
86+
}, []);
7687

7788
const allObjects = appConfig.objects || [];
7889

packages/plugin-dashboard/src/DashboardRenderer.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ const CHART_COLORS = [
2121
];
2222

2323
export const DashboardRenderer = forwardRef<HTMLDivElement, { schema: DashboardSchema; className?: string; [key: string]: any }>(
24-
({ schema, className, ...props }, ref) => {
24+
({ schema, className, dataSource, ...props }, ref) => {
2525
const columns = schema.columns || 4; // Default to 4 columns for better density
2626
const gap = schema.gap || 4;
2727

2828
return (
29-
<div
30-
ref={ref}
31-
className={cn("grid auto-rows-min", className)}
29+
<div
30+
ref={ref}
31+
className={cn("grid auto-rows-min", className)}
3232
style={{
3333
gridTemplateColumns: `repeat(${columns}, minmax(0, 1fr))`,
3434
gap: `${gap * 0.25}rem`

packages/plugin-view/src/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ ComponentRegistry.register('sort-ui', SortUI, {
165165
});
166166

167167
// Simple View Renderer (Container)
168-
const SimpleViewRenderer: React.FC<any> = ({ schema, className, children, ...props }) => {
168+
const SimpleViewRenderer: React.FC<any> = ({ schema, className, children, dataSource, ...props }) => {
169169
// If columns prop is present, use grid layout
170170
const style = schema.props?.columns
171171
? { display: 'grid', gridTemplateColumns: `repeat(${schema.props.columns}, 1fr)`, gap: '1rem' }

0 commit comments

Comments
 (0)