Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/components/workbench/breadboard/Breadboard.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useState } from 'react';
import React, { useEffect, useState, useRef } from 'react';
import {
BreadboardActionsType,
BreadboardStateType,
Expand Down Expand Up @@ -500,13 +500,19 @@ type WorkbenchSourceCodeEditorProps = {

function WorkbenchSourceCodeEditor(props: WorkbenchSourceCodeEditorProps) {
const [code, setCode] = useState<string | undefined>(undefined);
const currentFileRef = useRef<string | undefined>(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);
Expand Down
Loading