Skip to content

Commit c78e841

Browse files
fix(sdk): stop phantom undo snapshots from NodeProperties onChange (#18)
1 parent dc43056 commit c78e841

2 files changed

Lines changed: 19 additions & 7 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@workflowbuilder/sdk': patch
3+
---
4+
5+
fix: stop `NodeProperties` from pushing a phantom undo entry when JsonForms re-emits `onChange` after an external `data` change (e.g. just after `undo()`), which previously cleared `future` and broke redo.

packages/sdk/src/features/properties-bar/components/node-properties/node-properties.tsx

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { isDeepEqual } from 'remeda';
55

66
import { StatusType } from '../../../../node/common';
77
import type { WorkflowBuilderNode } from '../../../../node/node-data';
8+
import type { BaseNodeProperties } from '../../../../node/node-schema';
89
import { getStoreEdges, setStoreEdges } from '../../../../store/slices/diagram-slice/actions';
910
import { useStore } from '../../../../store/store';
1011
import { filterOutEdgesBySourceHandles } from '../../../../utils/edges/filter-out-edges-by-source-handles';
@@ -74,14 +75,20 @@ export const NodeProperties = memo(({ node }: Props) => {
7475

7576
const { schema, uischema } = nodeDefinition;
7677
const onChange: JsonFormsReactProps['onChange'] = ({ data, errors }) => {
77-
const flattenErrors = flatErrors(errors);
78-
79-
if (!isDeepEqual({ ...data, errors: flattenErrors }, properties)) {
80-
trackFutureChange('dataUpdate');
81-
setNodeProperties(id, { ...data, errors: flattenErrors });
82-
83-
removeEdgesForDeletedHandles(properties, data);
78+
// JsonForms also fires onChange when its `data` prop changes externally
79+
// (e.g. after undo) — not only on user edits. Ignore the derived `errors`
80+
// field when checking for a real edit; otherwise we'd push a phantom
81+
// snapshot that breaks undo/redo.
82+
const { errors: _newErrors, ...dataWithoutErrors } = (data ?? {}) as BaseNodeProperties;
83+
const { errors: _previousErrors, ...propertiesWithoutErrors } = properties;
84+
if (isDeepEqual(dataWithoutErrors, propertiesWithoutErrors)) {
85+
return;
8486
}
87+
88+
const flattenErrors = flatErrors(errors);
89+
trackFutureChange('dataUpdate');
90+
setNodeProperties(id, { ...data, errors: flattenErrors });
91+
removeEdgesForDeletedHandles(properties, data);
8592
};
8693

8794
return (

0 commit comments

Comments
 (0)