Skip to content

Commit 4b9bbbd

Browse files
committed
Shallow compare schema and uischema props
Use shallow compare to determine schema and uischema prop changes improving performance in almost all cases. The 'areEqual' check is used to determine whether the previous set of props is equal to the next set of props. Up until now lodash's deep equal was used for the schema and uischema props. This would only be beneficial if we changed the actual schema objects without changing their content and the comparison would take less time than a rerender. In practice we almost never change the schema and uischema objects and when we do we usually also change their content. A deep equal is therefore unnecessary and additionally harms performance for large objects.
1 parent 957c5d6 commit 4b9bbbd

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

packages/react/src/JsonFormsContext.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -359,12 +359,14 @@ const withContextToEnumProps =
359359
type JsonFormsPropTypes = ControlProps | CombinatorProps | LayoutProps | CellProps | ArrayLayoutProps | StatePropsOfControlWithDetail | OwnPropsOfRenderer;
360360

361361
export const areEqual = (prevProps: JsonFormsPropTypes, nextProps: JsonFormsPropTypes) => {
362-
const prev = omit(prevProps, ['handleChange', 'renderers', 'cells', 'uischemas']);
363-
const next = omit(nextProps, ['handleChange', 'renderers', 'cells', 'uischemas']);
362+
const prev = omit(prevProps, ['schema', 'uischema', 'handleChange', 'renderers', 'cells', 'uischemas']);
363+
const next = omit(nextProps, ['schema', 'uischema', 'handleChange', 'renderers', 'cells', 'uischemas']);
364364
return isEqual(prev, next)
365365
&& get(prevProps, 'renderers.length') === get(nextProps, 'renderers.length')
366366
&& get(prevProps, 'cells.length') === get(nextProps, 'cells.length')
367-
&& get(prevProps, 'uischemas.length') === get(nextProps, 'uischemas.length');
367+
&& get(prevProps, 'uischemas.length') === get(nextProps, 'uischemas.length')
368+
&& get(prevProps, 'schema') === get(nextProps, 'schema')
369+
&& get(prevProps, 'uischema') === get(nextProps, 'uischema');
368370
};
369371

370372
// top level HOCs --

0 commit comments

Comments
 (0)