Skip to content

Commit 930f982

Browse files
Fix deepEquals import in rjsf v5 (#464)
* clone deepEquals impl form @rjsf/utils v5 beta * stop relying on deepEquals presence in @rjsf/core/utils * might cause backwards compatibility issues on older rjsf version as the deepEquals implementation is different to the new one, but all tests pass 🤷‍♂️
1 parent 9cfd296 commit 930f982

File tree

5 files changed

+40
-14
lines changed

5 files changed

+40
-14
lines changed

package-lock.json

Lines changed: 18 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"mavarazy <[email protected]>",
77
"Aivaras Prudnikovas <[email protected]>"
88
],
9-
"version": "1.4.0",
9+
"version": "1.5.0",
1010
"scripts": {
1111
"build": "rimraf dist lib && npm run build:umd && npm run build:cjs && npm run build:es && npm run build:es:lib",
1212
"build:umd": "cross-env NODE_ENV=production BABEL_ENV=umd webpack --config webpack.config.dist.js",
@@ -57,6 +57,7 @@
5757
},
5858
"dependencies": {
5959
"deepcopy": "^2.0.0",
60+
"lodash.isequalwith": "^4.4.0",
6061
"selectn": "^1.1.2"
6162
},
6263
"devDependencies": {

src/applyRules.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
import React, { Component } from 'react';
22
import PropTypes from 'prop-types';
3-
import { toError } from './utils';
3+
import { toError, deepEquals } from './utils';
44
import rulesRunner from './rulesRunner';
55

66
import { DEFAULT_ACTIONS } from './actions';
77
import validateAction from './actions/validateAction';
88
import env from './env';
99

10-
const { utils } = require('@rjsf/core');
11-
const { deepEquals } = utils;
12-
1310
/**
1411
* Intended to be used internally through applyRules(...)
1512
* but it also needs to be tested

src/rulesRunner.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import execute from "./actions";
22
import deepcopy from "deepcopy";
3-
const { utils } = require("@rjsf/core");
4-
const { deepEquals } = utils;
3+
import { deepEquals } from './utils';
54

65
function doRunRules(engine, formData, schema, uiSchema, extraActions = {}) {
76
let schemaCopy = deepcopy(schema);

src/utils.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
11
import { extractRefSchema } from "json-rules-engine-simplified/lib/utils";
22
import env from "./env";
3+
import isEqualWith from "lodash/isEqualWith";
4+
5+
/** Cloned from @rjsf/utils v5 to make it work in older rjsf versions
6+
*
7+
* @param a - The first element to compare
8+
* @param b - The second element to compare
9+
* @returns - True if the `a` and `b` are deeply equal, false otherwise
10+
*/
11+
export const deepEquals = (a, b) => {
12+
return isEqualWith(a, b, (obj, other) => {
13+
if (typeof obj === "function" && typeof other === "function") {
14+
// Assume all functions are equivalent
15+
// see https://github.com/rjsf-team/react-jsonschema-form/issues/255
16+
return true;
17+
}
18+
return undefined; // fallback to default isEquals behavior
19+
});
20+
};
321

422
export const toArray = (field) => {
523
if (Array.isArray(field)) {

0 commit comments

Comments
 (0)