From 4af26abb13ad2c003cf24576fbd5e3441cd1cac8 Mon Sep 17 00:00:00 2001 From: Yoichiro Tanaka Date: Tue, 1 Jul 2025 13:16:18 +0900 Subject: [PATCH] fix: Prevent input content reset in Breadboard editor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add useRef to track current file ID in WorkbenchSourceCodeEditor - Only update local state when different file is selected - Prevent local state reset during Redux state updates for same file - Fixes issue where user input would disappear during typing 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- src/components/workbench/breadboard/Breadboard.tsx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/components/workbench/breadboard/Breadboard.tsx b/src/components/workbench/breadboard/Breadboard.tsx index d006c742..3fa72fc3 100644 --- a/src/components/workbench/breadboard/Breadboard.tsx +++ b/src/components/workbench/breadboard/Breadboard.tsx @@ -1,4 +1,4 @@ -import React, { useEffect, useState } from 'react'; +import React, { useEffect, useState, useRef } from 'react'; import { BreadboardActionsType, BreadboardStateType, @@ -500,13 +500,19 @@ type WorkbenchSourceCodeEditorProps = { function WorkbenchSourceCodeEditor(props: WorkbenchSourceCodeEditorProps) { const [code, setCode] = useState(undefined); + const currentFileRef = useRef(undefined); useEffect(() => { if (props.project === undefined || props.file === undefined) { setCode(undefined); + currentFileRef.current = undefined; return; } - setCode(props.file.code); + // Only update local state when file changes (different file selected) + if (currentFileRef.current !== props.file.id) { + setCode(props.file.code); + currentFileRef.current = props.file.id; + } }, [props.project, props.file]); const debounceCode = useDebounce(code, props.file, 1000);