Skip to content

Commit bd827d4

Browse files
committed
address bugbot comments
1 parent ae5c1bb commit bd827d4

File tree

2 files changed

+23
-13
lines changed
  • apps/sim
    • app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/code
    • hooks

2 files changed

+23
-13
lines changed

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

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -301,15 +301,14 @@ export const Code = memo(function Code({
301301
const updatePromptValue = wandHook?.updatePromptValue || (() => {})
302302
const cancelGeneration = wandHook?.cancelGeneration || (() => {})
303303

304-
const { recordChange, clearHistory, recordReplace, flushPending, startSession, undo, redo } =
305-
useCodeUndoRedo({
306-
blockId,
307-
subBlockId,
308-
value: code,
309-
enabled: isFunctionCode,
310-
isReadOnly: readOnly || disabled || isPreview,
311-
isStreaming: isAiStreaming,
312-
})
304+
const { recordChange, recordReplace, flushPending, startSession, undo, redo } = useCodeUndoRedo({
305+
blockId,
306+
subBlockId,
307+
value: code,
308+
enabled: isFunctionCode,
309+
isReadOnly: readOnly || disabled || isPreview,
310+
isStreaming: isAiStreaming,
311+
})
313312

314313
const [storeValue, setStoreValue] = useSubBlockValue(blockId, subBlockId, false, {
315314
isStreaming: isAiStreaming,

apps/sim/hooks/use-code-undo-redo.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ export function useCodeUndoRedo({
154154
)
155155

156156
const flushPending = useCallback(() => {
157-
if (!pendingBeforeRef.current) return
157+
if (pendingBeforeRef.current === null) return
158158
clearTimer()
159159
commitPending()
160160
}, [clearTimer, commitPending])
@@ -201,10 +201,21 @@ export function useCodeUndoRedo({
201201
}, [activeWorkflowId, applyValue, blockId, isEnabled, subBlockId])
202202

203203
useEffect(() => {
204-
if (!pendingBeforeRef.current && !isApplyingRef.current) {
205-
lastCommittedValueRef.current = value ?? ''
204+
if (isApplyingRef.current) return
205+
206+
const nextValue = value ?? ''
207+
208+
if (pendingBeforeRef.current !== null) {
209+
if (pendingAfterRef.current !== nextValue) {
210+
clearTimer()
211+
resetPending()
212+
lastCommittedValueRef.current = nextValue
213+
}
214+
return
206215
}
207-
}, [value])
216+
217+
lastCommittedValueRef.current = nextValue
218+
}, [clearTimer, resetPending, value])
208219

209220
useEffect(() => {
210221
return () => {

0 commit comments

Comments
 (0)