@@ -2,7 +2,7 @@ import { Position } from "@xyflow/react";
22import File from "lucide-react/icons/file" ;
33import Upload from "lucide-react/icons/upload" ;
44import XCircleIcon from "lucide-react/icons/x-circle" ;
5- import { useEffect , useState } from "react" ;
5+ import React , { useEffect , useState } from "react" ;
66
77import { Button } from "@/components/ui/button" ;
88import { Input } from "@/components/ui/input" ;
@@ -57,6 +57,9 @@ export function InputEditPopover({
5757 const [ isUploading , setIsUploading ] = useState ( false ) ;
5858 const [ uploadError , setUploadError ] = useState < string | null > ( null ) ;
5959
60+ // Debounce ref for text inputs
61+ const debounceTimeoutRef = React . useRef < number | null > ( null ) ;
62+
6063 // Helper function to create object URL for previews and downloads
6164 const getObjectUrl = ( objectRef : any ) : string | null => {
6265 if ( ! isObjectReference ( objectRef ) ) return null ;
@@ -87,12 +90,32 @@ export function InputEditPopover({
8790 setUploadError ( null ) ;
8891 } , [ input ] ) ;
8992
93+ // Cleanup debounce timeout on unmount
94+ useEffect ( ( ) => {
95+ return ( ) => {
96+ if ( debounceTimeoutRef . current !== null ) {
97+ clearTimeout ( debounceTimeoutRef . current ) ;
98+ }
99+ } ;
100+ } , [ ] ) ;
101+
90102 const handleInputChange = ( value : string ) => {
91103 if ( ! input || readonly || ! updateNodeData ) return ;
92104
105+ // Update local state immediately for responsive UI
93106 setInputValue ( value ) ;
94- const typedValue = convertValueByType ( value , input . type ) ;
95- updateNodeInput ( nodeId , input . id , typedValue , nodeInputs , updateNodeData ) ;
107+
108+ // Clear any pending debounce
109+ if ( debounceTimeoutRef . current !== null ) {
110+ clearTimeout ( debounceTimeoutRef . current ) ;
111+ }
112+
113+ // Debounce the actual node data update
114+ debounceTimeoutRef . current = window . setTimeout ( ( ) => {
115+ const typedValue = convertValueByType ( value , input . type ) ;
116+ updateNodeInput ( nodeId , input . id , typedValue , nodeInputs , updateNodeData ) ;
117+ debounceTimeoutRef . current = null ;
118+ } , 300 ) ;
96119 } ;
97120
98121 const handleClearValue = ( ) => {
0 commit comments