@@ -181,7 +181,7 @@ export function useSubBlockValue<T = any>(
181181 triggerWorkflowUpdate = false ,
182182 options ?: UseSubBlockValueOptions
183183) : readonly [ T | null , ( value : T ) => void ] {
184- const { debounceMs = 150 , isStreaming = false , onStreamingEnd } = options || { }
184+ const { isStreaming = false , onStreamingEnd } = options || { }
185185
186186 const { collaborativeSetSubblockValue } = useCollaborativeWorkflow ( )
187187
@@ -202,8 +202,7 @@ export function useSubBlockValue<T = any>(
202202 // Previous model reference for detecting model changes
203203 const prevModelRef = useRef < string | null > ( null )
204204
205- // Debouncing refs
206- const debounceTimerRef = useRef < NodeJS . Timeout | null > ( null )
205+ // Streaming refs
207206 const lastEmittedValueRef = useRef < T | null > ( null )
208207 const streamingValueRef = useRef < T | null > ( null )
209208 const wasStreamingRef = useRef < boolean > ( false )
@@ -232,15 +231,6 @@ export function useSubBlockValue<T = any>(
232231 // Compute the modelValue based on block type
233232 const modelValue = isProviderBasedBlock ? ( modelSubBlockValue as string ) : null
234233
235- // Cleanup timer on unmount
236- useEffect ( ( ) => {
237- return ( ) => {
238- if ( debounceTimerRef . current ) {
239- clearTimeout ( debounceTimerRef . current )
240- }
241- }
242- } , [ ] )
243-
244234 // Emit the value to socket/DB
245235 const emitValue = useCallback (
246236 ( value : T ) => {
@@ -299,26 +289,12 @@ export function useSubBlockValue<T = any>(
299289 storeApiKeyValue ( blockId , blockType , modelValue , newValue , storeValue )
300290 }
301291
302- // Clear any existing debounce timer
303- if ( debounceTimerRef . current ) {
304- clearTimeout ( debounceTimerRef . current )
305- debounceTimerRef . current = null
306- }
307-
308292 // If streaming, just store the value without emitting
309293 if ( isStreaming ) {
310294 streamingValueRef . current = valueCopy
311295 } else {
312- // Detect large changes for extended debounce
313- const isLargeChange = detectLargeChange ( lastEmittedValueRef . current , valueCopy )
314- const effectiveDebounceMs = isLargeChange ? debounceMs * 2 : debounceMs
315-
316- // Debounce the socket emission
317- debounceTimerRef . current = setTimeout ( ( ) => {
318- if ( valueRef . current !== null && valueRef . current !== lastEmittedValueRef . current ) {
319- emitValue ( valueCopy )
320- }
321- } , effectiveDebounceMs )
296+ // Emit immediately - let the operation queue handle debouncing and deduplication
297+ emitValue ( valueCopy )
322298 }
323299
324300 if ( triggerWorkflowUpdate ) {
@@ -335,7 +311,6 @@ export function useSubBlockValue<T = any>(
335311 triggerWorkflowUpdate ,
336312 modelValue ,
337313 isStreaming ,
338- debounceMs ,
339314 emitValue ,
340315 ]
341316 )
@@ -412,26 +387,3 @@ export function useSubBlockValue<T = any>(
412387 // Return appropriate tuple based on whether options were provided
413388 return [ storeValue !== undefined ? storeValue : initialValue , setValue ] as const
414389}
415-
416- // Helper function to detect large changes
417- function detectLargeChange ( oldValue : any , newValue : any ) : boolean {
418- // Handle null/undefined
419- if ( oldValue == null && newValue == null ) return false
420- if ( oldValue == null || newValue == null ) return true
421-
422- // For strings, check if it's a large paste or deletion
423- if ( typeof oldValue === 'string' && typeof newValue === 'string' ) {
424- const sizeDiff = Math . abs ( newValue . length - oldValue . length )
425- // Consider it a large change if more than 50 characters changed at once
426- return sizeDiff > 50
427- }
428-
429- // For arrays, check length difference
430- if ( Array . isArray ( oldValue ) && Array . isArray ( newValue ) ) {
431- const sizeDiff = Math . abs ( newValue . length - oldValue . length )
432- return sizeDiff > 5
433- }
434-
435- // For other types, always treat as small change
436- return false
437- }
0 commit comments