Skip to content

Commit be1e044

Browse files
committed
refactor: fix updating issue in json editor
1 parent 608e496 commit be1e044

3 files changed

Lines changed: 19 additions & 7 deletions

File tree

apps/web/src/components/workflow/fields/geojson-field.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,15 @@ export function GeoJSONField({
9393

9494
const formattedValue = hasValue ? formatGeoJSON(value) : "";
9595

96-
// Create CodeMirror editor once on mount
96+
// Determine if we should show the editor (not disabled state)
97+
const shouldShowEditor = !disabled;
98+
99+
// Create CodeMirror editor when needed
97100
useEffect(() => {
98-
if (!editorRef.current) return;
101+
if (!editorRef.current || !shouldShowEditor) return;
102+
103+
// Don't recreate if editor already exists
104+
if (viewRef.current) return;
99105

100106
const view = new EditorView({
101107
state: EditorState.create({
@@ -197,7 +203,7 @@ export function GeoJSONField({
197203
view.destroy();
198204
viewRef.current = null;
199205
};
200-
}, []); // Only run on mount
206+
}, [shouldShowEditor, formattedValue, readonly]); // Recreate when transitioning to showing editor
201207

202208
// Update editor content when external value changes
203209
useEffect(() => {

apps/web/src/components/workflow/fields/json-field.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,15 @@ export function JsonField({
5555
// If not valid JSON, show as-is
5656
}
5757

58-
// Create CodeMirror editor once on mount
58+
// Determine if we should show the editor (not showing placeholder)
59+
const shouldShowEditor = !(disabled && !hasValue);
60+
61+
// Create CodeMirror editor when needed
5962
useEffect(() => {
60-
if (!editorRef.current) return;
63+
if (!editorRef.current || !shouldShowEditor) return;
64+
65+
// Don't recreate if editor already exists
66+
if (viewRef.current) return;
6167

6268
const view = new EditorView({
6369
state: EditorState.create({
@@ -158,7 +164,7 @@ export function JsonField({
158164
view.destroy();
159165
viewRef.current = null;
160166
};
161-
}, []); // Only run on mount
167+
}, [shouldShowEditor, formattedValue, readonly]); // Recreate when transitioning to showing editor
162168

163169
// Update editor content when external value changes
164170
useEffect(() => {

apps/web/src/components/workflow/workflow-node-inspector.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export function WorkflowNodeInspector({
6363
setLocalName(node.data.name);
6464
setLocalInputs(node.data.inputs);
6565
setLocalOutputs(node.data.outputs);
66-
}, [node, node?.data.name, node?.data.inputs, node?.data.outputs]);
66+
}, [node]);
6767

6868
if (!node) return null;
6969

0 commit comments

Comments
 (0)