Skip to content

Commit 46c6887

Browse files
committed
duplicate editor data fixed
1 parent 002c5ad commit 46c6887

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

client/packages/lowcoder/src/comps/comps/jsonComp/jsonEditorComp.tsx

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ let JsonEditorTmpComp = (function () {
8080

8181
const wrapperRef = useRef<HTMLDivElement>(null);
8282
const view = useRef<EditorViewType | null>(null);
83+
const initialized = useRef(false);
84+
const state = useRef<EditorState | null>(null);
8385
const editContent = useRef<string>();
8486
const { extensions } = useExtensions({
8587
codeType: "PureJSON",
@@ -102,21 +104,20 @@ let JsonEditorTmpComp = (function () {
102104
});
103105

104106
useEffect(() => {
105-
if (wrapperRef.current && !view.current) {
106-
const state = EditorState.create({
107+
if (!initialized.current && wrapperRef.current) {
108+
state.current = EditorState.create({
107109
doc: JSON.stringify(props.value.value, null, 2),
108110
extensions,
109111
});
110-
view.current = new EditorView({state, parent: wrapperRef.current});
111-
}
112-
if (wrapperRef.current&&(props.showVerticalScrollbar||!props.showVerticalScrollbar)) {
113-
const state = EditorState.create({
114-
doc: JSON.stringify(props.value.value, null, 2),
115-
extensions,
116-
});
117-
view.current = new EditorView({state, parent: wrapperRef.current});
118112
}
119113
}, [wrapperRef.current, props.showVerticalScrollbar]);
114+
115+
useEffect(() => {
116+
if (state.current&&wrapperRef.current) {
117+
view.current = new EditorView({ state: state.current, parent: wrapperRef.current });
118+
initialized.current = true;
119+
}
120+
}, [props.showVerticalScrollbar])
120121

121122
if (wrapperRef.current && view.current && !editContent.current) {
122123
const state = EditorState.create({

0 commit comments

Comments
 (0)