File tree Expand file tree Collapse file tree 1 file changed +12
-3
lines changed
Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -142,9 +142,17 @@ function EditorComponent() {
142142 } , [ currentLanguage ] ) ;
143143
144144 useEffect ( ( ) => {
145- if ( code ) {
146- localStorage . setItem ( `code-${ currentLanguage } ` , code ) ;
147- }
145+ if ( isImportingRef . current ) return ;
146+
147+ const handler = setTimeout ( ( ) => {
148+ if ( code ) {
149+ localStorage . setItem ( `code-${ currentLanguage } ` , code ) ;
150+ }
151+ } , 500 ) ; // Debounce for 500ms
152+
153+ return ( ) => {
154+ clearTimeout ( handler ) ;
155+ } ;
148156 } , [ code , currentLanguage ] ) ;
149157
150158 const handleEditorThemeChange = async ( _ , theme ) => {
@@ -292,6 +300,7 @@ function EditorComponent() {
292300 // console.log("file code ", event.target.result);
293301 setOutput ( "" ) ;
294302 setIsImporting ( false ) ;
303+ isImportingRef . current = false ;
295304 } ;
296305 reader . onerror = ( ) => {
297306 console . error ( "Error reading file" ) ;
You can’t perform that action at this time.
0 commit comments