diff --git a/CHANGELOG.md b/CHANGELOG.md index 208a2577f8..e0be4c35b7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,11 @@ it according to semantic versioning. For example, if your PR adds a breaking cha should change the heading of the (upcoming) version to include a major version bump. --> +# 5.24.2 + +## @rjsf/utils + +- switch `lodash.isEqualWith` to `fast-equals.createCustomEqual` providing `areFunctionsEqual` assuming any functions are equal. # 5.24.1 diff --git a/package-lock.json b/package-lock.json index b307b27096..8dab2b68e8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16648,6 +16648,15 @@ "integrity": "sha512-VxPP4NqbUjj6MaAOafWeUn2cXWLcCtljklUtZf0Ind4XQ+QPtmA0b18zZy0jIQx+ExRVCR/ZQpBmik5lXshNsw==", "dev": true }, + "node_modules/fast-equals": { + "version": "5.2.2", + "resolved": "https://registry.npmjs.org/fast-equals/-/fast-equals-5.2.2.tgz", + "integrity": "sha512-V7/RktU11J3I36Nwq2JnZEM7tNm17eBJz+u25qdxBZeCKiX6BkVSZQjwWIr+IobgnZy+ag73tTZgZi7tr0LrBw==", + "license": "MIT", + "engines": { + "node": ">=6.0.0" + } + }, "node_modules/fast-glob": { "version": "3.3.2", "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.3.2.tgz", @@ -35236,6 +35245,7 @@ "version": "5.24.1", "license": "Apache-2.0", "dependencies": { + "fast-equals": "^5.2.2", "json-schema-merge-allof": "^0.8.1", "jsonpointer": "^5.0.1", "lodash": "^4.17.21", diff --git a/packages/utils/package.json b/packages/utils/package.json index 2d28c302c4..85593e311b 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -36,6 +36,7 @@ "react": "^16.14.0 || >=17" }, "dependencies": { + "fast-equals": "^5.2.2", "json-schema-merge-allof": "^0.8.1", "jsonpointer": "^5.0.1", "lodash": "^4.17.21", diff --git a/packages/utils/src/deepEquals.ts b/packages/utils/src/deepEquals.ts index 2e2538848e..99cb8779dd 100644 --- a/packages/utils/src/deepEquals.ts +++ b/packages/utils/src/deepEquals.ts @@ -1,19 +1,22 @@ -import isEqualWith from 'lodash/isEqualWith'; +import { createCustomEqual } from 'fast-equals'; -/** Implements a deep equals using the `lodash.isEqualWith` function, that provides a customized comparator that - * assumes all functions are equivalent. +/** Implements a deep equals using the `fast-equals.createCustomEqual` function, providing a customized comparator that assumes all functions are equivalent. * * @param a - The first element to compare * @param b - The second element to compare * @returns - True if the `a` and `b` are deeply equal, false otherwise */ -export default function deepEquals(a: any, b: any): boolean { - return isEqualWith(a, b, (obj: any, other: any) => { - if (typeof obj === 'function' && typeof other === 'function') { - // Assume all functions are equivalent - // see https://github.com/rjsf-team/react-jsonschema-form/issues/255 - return true; - } - return undefined; // fallback to default isEquals behavior - }); -} +const deepEquals = createCustomEqual({ + createCustomConfig: () => ({ + // Assume all functions are equivalent + // see https://github.com/rjsf-team/react-jsonschema-form/issues/255 + // + // Performance improvement: knowing that typeof a === function, so, only needs to check if typeof b === function. + // https://github.com/planttheidea/fast-equals/blob/c633c4e653cacf8fd5cbb309b6841df62322d74c/src/comparator.ts#L99 + areFunctionsEqual(_a, b) { + return typeof b === 'function'; + }, + }), +}); + +export default deepEquals;