Skip to content

Commit 0c4d902

Browse files
Harman-singh-waraichjaybuidl
authored andcommitted
fix(web-devtools): json-editor
1 parent d3180f7 commit 0c4d902

File tree

4 files changed

+227
-277
lines changed

4 files changed

+227
-277
lines changed

Diff for: package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@
7575
"@openzeppelin/contracts-upgradeable@npm:4.8.3": "npm:4.9.6",
7676
"@openzeppelin/contracts-upgradeable@npm:4.9.3": "npm:4.9.6",
7777
"elliptic@npm:6.5.4": "npm:6.6.1",
78-
"word-wrap@npm:~1.2.3": "npm:1.2.5"
78+
"word-wrap@npm:~1.2.3": "npm:1.2.5",
79+
"@codemirror/state": "npm:6.5.2"
7980
},
8081
"scripts": {
8182
"check-prerequisites": "scripts/check-prerequisites.sh",

Diff for: web-devtools/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
"typescript": "^5.6.3"
4848
},
4949
"dependencies": {
50+
"@codemirror/state": "^6.5.2",
5051
"@coinbase/wallet-sdk": "^4.3.2",
5152
"@kleros/kleros-sdk": "workspace:^",
5253
"@kleros/kleros-v2-contracts": "workspace:^",
@@ -69,7 +70,7 @@
6970
"react-use": "^17.5.1",
7071
"styled-components": "^5.3.3",
7172
"typewriter-effect": "^2.21.0",
72-
"vanilla-jsoneditor": "^0.23.0",
73+
"vanilla-jsoneditor": "^3.3.1",
7374
"viem": "^2.24.1",
7475
"wagmi": "^2.14.15"
7576
}

Diff for: web-devtools/src/components/JSONEditor.tsx

+20-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { useEffect, useRef } from "react";
22
import styled, { css } from "styled-components";
33

4-
import { JSONEditor as Editor } from "vanilla-jsoneditor";
4+
import { createJSONEditor, type JSONEditorPropsOptional, JsonEditor } from "vanilla-jsoneditor";
55

66
import { landscapeStyle } from "styles/landscapeStyle";
77

@@ -35,14 +35,13 @@ const Container = styled.div`
3535

3636
const JSONEditor = (props: any) => {
3737
const refContainer = useRef<HTMLDivElement | null>(null);
38-
const refEditor = useRef<Editor | null>(null);
38+
const refEditor = useRef<JsonEditor | null>(null);
39+
const refPrevProps = useRef<JSONEditorPropsOptional>(props);
3940

4041
useEffect(() => {
41-
refEditor.current = new Editor({
42-
target: refContainer.current!,
43-
props: {
44-
...props,
45-
},
42+
refEditor.current = createJSONEditor({
43+
target: refContainer.current as HTMLDivElement,
44+
props,
4645
});
4746

4847
return () => {
@@ -53,12 +52,25 @@ const JSONEditor = (props: any) => {
5352
};
5453
}, []);
5554

55+
// update props
5656
useEffect(() => {
5757
if (refEditor.current) {
58-
refEditor.current.updateProps(props);
58+
const changedProps = filterUnchangedProps(props, refPrevProps.current);
59+
refEditor.current.updateProps(changedProps);
60+
refPrevProps.current = props;
5961
}
6062
}, [props]);
6163

6264
return <Container ref={refContainer} className={props.className}></Container>;
6365
};
66+
67+
function filterUnchangedProps(
68+
props: JSONEditorPropsOptional,
69+
prevProps: JSONEditorPropsOptional
70+
): JSONEditorPropsOptional {
71+
return Object.fromEntries(
72+
Object.entries(props).filter(([key, value]) => value !== prevProps[key as keyof JSONEditorPropsOptional])
73+
);
74+
}
75+
6476
export default JSONEditor;

0 commit comments

Comments
 (0)