Skip to content

Commit 6315cc1

Browse files
fix(wand): subblocks should not be overwritten after wand gen (#1946)
1 parent 61404d4 commit 6315cc1

File tree

2 files changed

+30
-0
lines changed
  • apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel-new/components/editor/components/sub-block/components

2 files changed

+30
-0
lines changed

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel-new/components/editor/components/sub-block/components/long-input/long-input.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { cn } from '@/lib/utils'
1515
import { formatDisplayText } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel-new/components/editor/components/sub-block/components/formatted-text'
1616
import { SubBlockInputController } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel-new/components/editor/components/sub-block/components/sub-block-input-controller'
1717
import { useSubBlockInput } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel-new/components/editor/components/sub-block/hooks/use-sub-block-input'
18+
import { useSubBlockValue } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel-new/components/editor/components/sub-block/hooks/use-sub-block-value'
1819
import type { WandControlHandlers } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel-new/components/editor/components/sub-block/sub-block'
1920
import { WandPromptBar } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/wand-prompt-bar/wand-prompt-bar'
2021
import { useAccessibleReferencePrefixes } from '@/app/workspace/[workspaceId]/w/[workflowId]/hooks/use-accessible-reference-prefixes'
@@ -94,6 +95,7 @@ export function LongInput({
9495
}: LongInputProps) {
9596
// Local state for immediate UI updates during streaming
9697
const [localContent, setLocalContent] = useState<string>('')
98+
const persistSubBlockValueRef = useRef<(value: string) => void>(() => {})
9799

98100
// Wand functionality - always call the hook unconditionally
99101
const wandHook = useWand({
@@ -110,9 +112,22 @@ export function LongInput({
110112
onGeneratedContent: (content) => {
111113
// Final content update (fallback)
112114
setLocalContent(content)
115+
if (!isPreview && !disabled) {
116+
persistSubBlockValueRef.current(content)
117+
}
113118
},
114119
})
115120

121+
const [, setSubBlockValue] = useSubBlockValue<string>(blockId, subBlockId, false, {
122+
isStreaming: wandHook.isStreaming,
123+
})
124+
125+
useEffect(() => {
126+
persistSubBlockValueRef.current = (value: string) => {
127+
setSubBlockValue(value)
128+
}
129+
}, [setSubBlockValue])
130+
116131
// Check if wand is actually enabled
117132
const isWandEnabled = config.wandConfig?.enabled ?? false
118133

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel-new/components/editor/components/sub-block/components/short-input/short-input.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { Button } from '@/components/ui/button'
66
import { cn } from '@/lib/utils'
77
import { formatDisplayText } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel-new/components/editor/components/sub-block/components/formatted-text'
88
import { SubBlockInputController } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel-new/components/editor/components/sub-block/components/sub-block-input-controller'
9+
import { useSubBlockValue } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel-new/components/editor/components/sub-block/hooks/use-sub-block-value'
910
import type { WandControlHandlers } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel-new/components/editor/components/sub-block/sub-block'
1011
import { WandPromptBar } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/wand-prompt-bar/wand-prompt-bar'
1112
import { useAccessibleReferencePrefixes } from '@/app/workspace/[workspaceId]/w/[workflowId]/hooks/use-accessible-reference-prefixes'
@@ -82,6 +83,7 @@ export function ShortInput({
8283
const [localContent, setLocalContent] = useState<string>('')
8384
const [isFocused, setIsFocused] = useState(false)
8485
const [copied, setCopied] = useState(false)
86+
const persistSubBlockValueRef = useRef<(value: string) => void>(() => {})
8587

8688
// Always call the hook - hooks must be called unconditionally
8789
const webhookManagement = useWebhookManagement({
@@ -105,9 +107,22 @@ export function ShortInput({
105107
onGeneratedContent: (content) => {
106108
// Final content update
107109
setLocalContent(content)
110+
if (!isPreview && !disabled && !readOnly) {
111+
persistSubBlockValueRef.current(content)
112+
}
108113
},
109114
})
110115

116+
const [, setSubBlockValue] = useSubBlockValue<string>(blockId, subBlockId, false, {
117+
isStreaming: wandHook.isStreaming,
118+
})
119+
120+
useEffect(() => {
121+
persistSubBlockValueRef.current = (value: string) => {
122+
setSubBlockValue(value)
123+
}
124+
}, [setSubBlockValue])
125+
111126
// Check if wand is actually enabled
112127
const isWandEnabled = config.wandConfig?.enabled ?? false
113128

0 commit comments

Comments
 (0)