Skip to content

Commit e94cb47

Browse files
author
Incharajayaram
committed
updated the fixes as copilot review
1 parent eaf0436 commit e94cb47

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/pages/EditorComponent.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff 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");

0 commit comments

Comments
 (0)