Skip to content

Commit a30ef8b

Browse files
committed
json patch in-place breaks some components
this is because React is checking object identity to determine if changes need to be applied. to resolve this we deep copy the subsection of the model which is changing to trigger updates
1 parent 310e749 commit a30ef8b

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

Diff for: idom/client/app/core_modules/layout.js

+21-4
Original file line numberDiff line numberDiff line change
@@ -193,17 +193,34 @@ function useInplaceJsonPatch(doc) {
193193

194194
const applyPatch = react.useCallback(
195195
(path, patch) => {
196-
jsonpatch.applyPatch(
197-
jsonpatch.getValueByPointer(ref.current, path),
198-
patch
199-
);
196+
applyPatchInplace(ref.current, path, patch);
200197
forceUpdate();
201198
},
202199
[ref, forceUpdate]
203200
);
201+
204202
return [ref.current, applyPatch];
205203
}
206204

205+
function applyPatchInplace(doc, path, patch) {
206+
if (!path) {
207+
jsonpatch.applyPatch(doc, patch);
208+
} else {
209+
jsonpatch.applyPatch(doc, [
210+
{
211+
op: "replace",
212+
path: path,
213+
value: jsonpatch.applyPatch(
214+
jsonpatch.getValueByPointer(doc, path),
215+
patch,
216+
false,
217+
false
218+
).newDocument,
219+
},
220+
]);
221+
}
222+
}
223+
207224
function useForceUpdate() {
208225
const [, updateState] = react.useState();
209226
return react.useCallback(() => updateState({}), []);

0 commit comments

Comments
 (0)