You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* perf(utils): switch deepEquals to fast-equals with cycle detection
Replaces lodash.isEqualWith with fast-equals.createCustomEqual
configured with circular: true so cyclic formData/extraErrors do not
crash with `Maximum call stack size exceeded`. Migrates the remaining
lodash.isEqual call sites in useDeepCompareMemo, isRootSchema and
findSelectedOptionInXxxOf to use deepEquals so the perf benefit is
shared across the package.
Adds regression tests for self-referential, mutually-referential and
cyclic-array inputs to pin cycle handling in place.
Refs #4291
* perf(validator-ajv8): cache rootSchema reference in handleSchemaUpdate
retrieveSchema invokes isValid (and therefore handleSchemaUpdate) once
per conditional or dependency branch evaluated during a render. On a
form with a large rootSchema and many branches this used to dominate
click cost because every call walked the entire rootSchema via
deepEquals to detect changes.
Cache the last-seen rootSchema reference and skip both the deepEquals
and the Ajv re-registration when the reference matches. Falls back to
the existing structural deepEquals when the reference changes,
preserving correctness for callers that legitimately rebuild the
schema.
Refs #4291
* Apply suggestions from code review
Co-authored-by: Heath C <51679588+heath-freenome@users.noreply.github.com>
---------
Co-authored-by: Heath C <51679588+heath-freenome@users.noreply.github.com>
Copy file name to clipboardExpand all lines: CHANGELOG.md
+8Lines changed: 8 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,6 +18,14 @@ should change the heading of the (upcoming) version to include a major version b
18
18
19
19
# 6.5.2
20
20
21
+
## @rjsf/utils
22
+
23
+
- Switched `deepEquals` from `lodash.isEqualWith` to `fast-equals.createCustomEqual` with cycle detection enabled, and replaced direct `lodash.isEqual` usage in `useDeepCompareMemo`, `isRootSchema`, and `findSelectedOptionInXxxOf` with `deepEquals`, fixing [#4291](https://github.com/rjsf-team/react-jsonschema-form/issues/4291).
24
+
25
+
## @rjsf/validator-ajv8
26
+
27
+
- Cached the most recent `rootSchema` reference in `handleSchemaUpdate` so repeated `isValid` calls with the same root schema skip the deep-equality check and Ajv re-registration, fixing [#4291](https://github.com/rjsf-team/react-jsonschema-form/issues/4291).
28
+
21
29
## Dev / docs / playground
22
30
23
31
- Cleaned up testing to make registry mocks simpler using `getTestRegistry()` function
/** Most recent `rootSchema` reference processed by `handleSchemaUpdate`.
48
+
*
49
+
* @private
50
+
*/
51
+
privatelastSeenRootSchema?: S;
52
+
53
+
/** True once a `rootSchema` has been registered with Ajv in this lifecycle.
54
+
*
55
+
* @private
56
+
*/
57
+
privatehasRegisteredRootSchema=false;
58
+
47
59
/** Constructs an `AJV8Validator` instance using the `options`
48
60
*
49
61
* @param options - The `CustomValidatorOptionsType` options that are used to create the AJV instance
@@ -75,6 +87,8 @@ export default class AJV8Validator<
75
87
*/
76
88
reset(){
77
89
this.ajv.removeSchema();
90
+
this.lastSeenRootSchema=undefined;
91
+
this.hasRegisteredRootSchema=false;
78
92
}
79
93
80
94
/** Runs the pure validation of the `schema` and `formData` without any of the RJSF functionality. Provided for use
@@ -181,9 +195,14 @@ export default class AJV8Validator<
181
195
182
196
/**
183
197
* This function checks if a schema needs to be added and if the root schemas don't match it removes the old root schema from the ajv instance and adds the new one.
198
+
* When called repeatedly with the same `rootSchema` reference the deep-equality check is skipped.
199
+
*
184
200
* @param rootSchema - The root schema used to provide $ref resolutions
0 commit comments