Compare commits

..

2 Commits

Author SHA1 Message Date
Vikhyath Mondreti
0fb6d9d451 remove comments 2026-01-13 00:38:42 -08:00
Vikhyath Mondreti
77241a1220 fix 2026-01-13 00:36:12 -08:00
2 changed files with 48 additions and 16 deletions

View File

@@ -35,6 +35,7 @@ import { getDependsOnFields } from '@/blocks/utils'
import { useKnowledgeBase } from '@/hooks/kb/use-knowledge'
import { useMcpServers, useMcpToolsQuery } from '@/hooks/queries/mcp'
import { useCredentialName } from '@/hooks/queries/oauth-credentials'
import { useCollaborativeWorkflow } from '@/hooks/use-collaborative-workflow'
import { useSelectorDisplayName } from '@/hooks/use-selector-display-name'
import { useVariablesStore } from '@/stores/panel'
import { useWorkflowRegistry } from '@/stores/workflows/registry/store'
@@ -612,6 +613,34 @@ export const WorkflowBlock = memo(function WorkflowBlock({
[isDeploying, setDeploymentStatus, refetchDeployment]
)
const { collaborativeSetSubblockValue } = useCollaborativeWorkflow()
/**
* Clear credential-dependent fields when credential changes to prevent
* stale data from persisting with new credentials.
*/
const prevCredRef = useRef<string | undefined>(undefined)
useEffect(() => {
const activeWorkflowId = useWorkflowRegistry.getState().activeWorkflowId
if (!activeWorkflowId) return
const current = useSubBlockStore.getState().workflowValues[activeWorkflowId]?.[id]
if (!current) return
const credValue = current.credential
const cred =
typeof credValue === 'object' && credValue !== null && 'value' in credValue
? ((credValue as { value?: unknown }).value as string | undefined)
: (credValue as string | undefined)
if (prevCredRef.current !== cred) {
const hadPreviousCredential = prevCredRef.current !== undefined
prevCredRef.current = cred
if (hadPreviousCredential) {
const keys = Object.keys(current)
const dependentKeys = keys.filter((k) => k !== 'credential')
dependentKeys.forEach((k) => collaborativeSetSubblockValue(id, k, ''))
}
}
}, [id, collaborativeSetSubblockValue])
const currentStoreBlock = currentWorkflow.getBlockById(id)
const isStarterBlock = type === 'starter'

View File

@@ -1088,25 +1088,28 @@ export function useCollaborativeWorkflow() {
userId: session?.user?.id || 'unknown',
})
const currentValue = subBlockStore.getValue(blockId, subblockId)
const valueActuallyChanged = currentValue !== value
subBlockStore.setValue(blockId, subblockId, value)
try {
const visited = options?._visited || new Set<string>()
if (visited.has(subblockId)) return
visited.add(subblockId)
const blockType = useWorkflowStore.getState().blocks?.[blockId]?.type
const blockConfig = blockType ? getBlock(blockType) : null
if (blockConfig?.subBlocks && Array.isArray(blockConfig.subBlocks)) {
const dependents = blockConfig.subBlocks.filter(
(sb: any) => Array.isArray(sb.dependsOn) && sb.dependsOn.includes(subblockId)
)
for (const dep of dependents) {
if (!dep?.id || dep.id === subblockId) continue
collaborativeSetSubblockValue(blockId, dep.id, '', { _visited: visited })
if (valueActuallyChanged) {
try {
const visited = options?._visited || new Set<string>()
if (visited.has(subblockId)) return
visited.add(subblockId)
const blockType = useWorkflowStore.getState().blocks?.[blockId]?.type
const blockConfig = blockType ? getBlock(blockType) : null
if (blockConfig?.subBlocks && Array.isArray(blockConfig.subBlocks)) {
const dependents = blockConfig.subBlocks.filter(
(sb: any) => Array.isArray(sb.dependsOn) && sb.dependsOn.includes(subblockId)
)
for (const dep of dependents) {
if (!dep?.id || dep.id === subblockId) continue
collaborativeSetSubblockValue(blockId, dep.id, '', { _visited: visited })
}
}
}
} catch {
// Best-effort; do not block on clearing
} catch {}
}
},
[