Skip to content

Commit 446de8f

Browse files
author
Theodore Li
committed
Simplify sublock values
1 parent 9e1d103 commit 446de8f

3 files changed

Lines changed: 14 additions & 19 deletions

File tree

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/hooks/use-editor-subblock-layout.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,29 +23,28 @@ import { useWorkflowStore } from '@/stores/workflows/workflow/store'
2323
function useReactiveConditions(
2424
subBlocks: SubBlockConfig[],
2525
blockId: string,
26-
activeWorkflowId: string | null,
27-
blockSubBlockValues: Record<string, unknown>
26+
activeWorkflowId: string | null
2827
): Set<string> {
2928
const reactiveSubBlock = useMemo(
3029
() => subBlocks.find((sb) => sb.reactiveCondition),
3130
[subBlocks]
3231
)
3332
const reactiveCond = reactiveSubBlock?.reactiveCondition
3433

35-
// Subscribe to watched field values — always called (stable hook count)
34+
// Subscribe to watched field values directly from the store (not via props,
35+
// which would destabilize the selector on every parent render).
3636
const watchedCredentialId = useSubBlockStore(
3737
useCallback(
3838
(state) => {
3939
if (!reactiveCond || !activeWorkflowId) return ''
4040
const blockValues = state.workflowValues[activeWorkflowId]?.[blockId] ?? {}
41-
const merged = { ...blockSubBlockValues, ...blockValues }
4241
for (const field of reactiveCond.watchFields) {
43-
const val = merged[field]
42+
const val = blockValues[field]
4443
if (val && typeof val === 'string') return val
4544
}
4645
return ''
4746
},
48-
[reactiveCond, activeWorkflowId, blockId, blockSubBlockValues]
47+
[reactiveCond, activeWorkflowId, blockId]
4948
)
5049
)
5150

@@ -98,8 +97,7 @@ export function useEditorSubblockLayout(
9897
const hiddenByReactiveCondition = useReactiveConditions(
9998
config?.subBlocks || [],
10099
blockId,
101-
activeWorkflowId,
102-
blockSubBlockValues
100+
activeWorkflowId
103101
)
104102

105103
return useMemo(() => {

apps/sim/blocks/types.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -357,16 +357,12 @@ export interface SubBlockConfig {
357357
}
358358
})
359359
/**
360-
* Reactive visibility condition evaluated via hooks at the layout level.
360+
* Credential-type visibility gate. The first non-empty string value from
361+
* `watchFields` is treated as a credential ID and fetched via the credentials
362+
* API. The subblock is hidden unless `credential.type` matches `requiredType`.
361363
*
362-
* - `watchFields`: subblock IDs whose values to watch. The first non-empty string
363-
* value is used as a credential ID to look up via the workspace credentials API.
364-
* - `requiredType`: the credential type that must match for the field to be visible
365-
* (e.g. `'service_account'`).
366-
*
367-
* The layout hook calls `useWorkspaceCredential` (always, for stable hook count)
368-
* and filters the subblock out if the type doesn't match. The serializer skips
369-
* this check — it always serializes the field if it has a value.
364+
* Only one subblock per block may use this. The serializer ignores it —
365+
* the field is always serialized when it has a value.
370366
*/
371367
reactiveCondition?: {
372368
watchFields: string[]

apps/sim/tools/params.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -990,8 +990,9 @@ export function getSubBlocksForToolInput(
990990
if (visibility === 'hidden' || visibility === 'llm-only') continue
991991

992992
// Evaluate condition against current values.
993-
// Skip sync condition check for subblocks with reactiveCondition — visibility
994-
// is handled at render time by the SubBlock component.
993+
// Subblocks with reactiveCondition are filtered at the UI layer via hooks
994+
// (useReactiveConditions) — skipping here avoids evaluating a condition
995+
// that has no sync field to check against.
995996
if (sb.condition && !sb.reactiveCondition) {
996997
const conditionMet = evaluateSubBlockCondition(
997998
sb.condition as SubBlockCondition,

0 commit comments

Comments
 (0)