Skip to content

Commit c8e9c61

Browse files
committed
feat(preview): lightweight param
1 parent 2a0a9b6 commit c8e9c61

File tree

3 files changed

+37
-11
lines changed

3 files changed

+37
-11
lines changed

apps/sim/app/workspace/[workspaceId]/w/components/preview/components/preview-workflow/components/block/block.tsx

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ interface WorkflowPreviewBlockData {
5656
executionStatus?: ExecutionStatus
5757
/** Subblock values from the workflow state */
5858
subBlockValues?: Record<string, SubBlockValueEntry | unknown>
59+
/** Skips expensive subblock computations for thumbnails/template previews */
60+
lightweight?: boolean
5961
}
6062

6163
/**
@@ -270,25 +272,29 @@ function WorkflowPreviewBlockInner({ data }: NodeProps<WorkflowPreviewBlockData>
270272
isPreviewSelected = false,
271273
executionStatus,
272274
subBlockValues,
275+
lightweight = false,
273276
} = data
274277

275278
const blockConfig = getBlock(type)
276279

277280
const canonicalIndex = useMemo(
278-
() => buildCanonicalIndex(blockConfig?.subBlocks || []),
279-
[blockConfig?.subBlocks]
281+
() =>
282+
lightweight
283+
? { groupsById: {}, canonicalIdBySubBlockId: {} }
284+
: buildCanonicalIndex(blockConfig?.subBlocks || []),
285+
[blockConfig?.subBlocks, lightweight]
280286
)
281287

282288
const rawValues = useMemo(() => {
283-
if (!subBlockValues) return {}
289+
if (lightweight || !subBlockValues) return {}
284290
return Object.entries(subBlockValues).reduce<Record<string, unknown>>((acc, [key, entry]) => {
285291
acc[key] = extractValue(entry)
286292
return acc
287293
}, {})
288-
}, [subBlockValues])
294+
}, [subBlockValues, lightweight])
289295

290296
const visibleSubBlocks = useMemo(() => {
291-
if (!blockConfig?.subBlocks) return []
297+
if (lightweight || !blockConfig?.subBlocks) return []
292298

293299
const isStarterOrTrigger =
294300
blockConfig.category === 'triggers' || type === 'starter' || isTrigger
@@ -304,13 +310,21 @@ function WorkflowPreviewBlockInner({ data }: NodeProps<WorkflowPreviewBlockData>
304310
if (!subBlock.condition) return true
305311
return evaluateSubBlockCondition(subBlock.condition, rawValues)
306312
})
307-
}, [blockConfig?.subBlocks, blockConfig?.category, type, isTrigger, canonicalIndex, rawValues])
313+
}, [
314+
blockConfig?.subBlocks,
315+
blockConfig?.category,
316+
type,
317+
isTrigger,
318+
canonicalIndex,
319+
rawValues,
320+
lightweight,
321+
])
308322

309323
/**
310324
* Compute condition rows for condition blocks
311325
*/
312326
const conditionRows = useMemo(() => {
313-
if (type !== 'condition') return []
327+
if (lightweight || type !== 'condition') return []
314328

315329
const conditionsValue = rawValues.conditions
316330
const raw = typeof conditionsValue === 'string' ? conditionsValue : undefined
@@ -338,13 +352,13 @@ function WorkflowPreviewBlockInner({ data }: NodeProps<WorkflowPreviewBlockData>
338352
{ id: 'if', title: 'if', value: '' },
339353
{ id: 'else', title: 'else', value: '' },
340354
]
341-
}, [type, rawValues])
355+
}, [type, rawValues, lightweight])
342356

343357
/**
344358
* Compute router rows for router_v2 blocks
345359
*/
346360
const routerRows = useMemo(() => {
347-
if (type !== 'router_v2') return []
361+
if (lightweight || type !== 'router_v2') return []
348362

349363
const routesValue = rawValues.routes
350364
const raw = typeof routesValue === 'string' ? routesValue : undefined
@@ -367,7 +381,7 @@ function WorkflowPreviewBlockInner({ data }: NodeProps<WorkflowPreviewBlockData>
367381
}
368382

369383
return [{ id: 'route1', value: '' }]
370-
}, [type, rawValues])
384+
}, [type, rawValues, lightweight])
371385

372386
if (!blockConfig) {
373387
return null
@@ -582,11 +596,15 @@ function shouldSkipPreviewBlockRender(
582596
prevProps.data.horizontalHandles !== nextProps.data.horizontalHandles ||
583597
prevProps.data.enabled !== nextProps.data.enabled ||
584598
prevProps.data.isPreviewSelected !== nextProps.data.isPreviewSelected ||
585-
prevProps.data.executionStatus !== nextProps.data.executionStatus
599+
prevProps.data.executionStatus !== nextProps.data.executionStatus ||
600+
prevProps.data.lightweight !== nextProps.data.lightweight
586601
) {
587602
return false
588603
}
589604

605+
/** Skip subBlockValues comparison in lightweight mode */
606+
if (nextProps.data.lightweight) return true
607+
590608
const prevValues = prevProps.data.subBlockValues
591609
const nextValues = nextProps.data.subBlockValues
592610

apps/sim/app/workspace/[workspaceId]/w/components/preview/components/preview-workflow/components/subflow/subflow.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ interface WorkflowPreviewSubflowData {
1717
isPreviewSelected?: boolean
1818
/** Execution status for highlighting the subflow container */
1919
executionStatus?: ExecutionStatus
20+
/** Skips expensive computations for thumbnails/template previews (unused in subflow, for consistency) */
21+
lightweight?: boolean
2022
}
2123

2224
/**

apps/sim/app/workspace/[workspaceId]/w/components/preview/components/preview-workflow/preview-workflow.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ interface PreviewWorkflowProps {
160160
executedBlocks?: Record<string, { status: string }>
161161
/** Currently selected block ID for highlighting */
162162
selectedBlockId?: string | null
163+
/** Skips expensive subblock computations for thumbnails/template previews */
164+
lightweight?: boolean
163165
}
164166

165167
/**
@@ -252,6 +254,7 @@ export function PreviewWorkflow({
252254
cursorStyle = 'grab',
253255
executedBlocks,
254256
selectedBlockId,
257+
lightweight = false,
255258
}: PreviewWorkflowProps) {
256259
const containerRef = useRef<HTMLDivElement>(null)
257260
const nodeTypes = previewNodeTypes
@@ -379,6 +382,7 @@ export function PreviewWorkflow({
379382
kind: block.type as 'loop' | 'parallel',
380383
isPreviewSelected: isSelected,
381384
executionStatus: subflowExecutionStatus,
385+
lightweight,
382386
},
383387
})
384388
return
@@ -417,6 +421,7 @@ export function PreviewWorkflow({
417421
isPreviewSelected: isSelected,
418422
executionStatus,
419423
subBlockValues: block.subBlocks,
424+
lightweight,
420425
},
421426
})
422427
})
@@ -431,6 +436,7 @@ export function PreviewWorkflow({
431436
executedBlocks,
432437
selectedBlockId,
433438
getSubflowExecutionStatus,
439+
lightweight,
434440
])
435441

436442
const edges: Edge[] = useMemo(() => {

0 commit comments

Comments
 (0)