Skip to content

fix(utils): resolve each dependencies oneOf branch against its own recurseList - #5435

Merged
heath-freenome merged 13 commits into
rjsf-team:mainfrom
charan-rathore:fix/shared-ref-oneof-dependencies
Oct 7, 2026
Merged

heath-freenome merged 13 commits into
rjsf-team:mainfrom
charan-rathore:fix/shared-ref-oneof-dependencies

Conversation

@charan-rathore

Copy link
Copy Markdown
Contributor

Reasons for making this change

fixes #5434

When a dependencies entry has a oneOf whose branches $ref definitions that themselves $ref the same shared definition, every branch after the first marks the shared property as a $ref cycle (RJSF_REF_CYCLE_KEY). The form then shows the "Circular reference ($ref cycle) detected" notice for that field. The schema has no recursion. This regressed in 6.7.0.

Cause: withDependentSchema() and withExactlyOneSubschema() passed the same recurseList array to every oneOf branch. The first branch pushed #/definitions/host into it, so the second branch saw the ref as already visited. A cycle should only count refs on the path from the root to the current node, not refs a sibling branch already resolved.

Fix: each oneOf branch now resolves against its own copy ([...recurseList]), in both places. Recursive schemas are unaffected because refs on the current path are still in the copy.

Tests: added a case to retrieveSchema() with the schema from the issue, formData { protocol: 'FTPS' }. It fails without the change (the host property comes back as a bare $ref with the cycle flag) and passes with it. I ran the full @rjsf/utils schema test file (733 tests, all pass). The full utils run also showed one utcToLocal failure that comes from this machine's timezone; it passes with TZ=UTC and is unrelated to this change. I did not run the other packages' tests, the build, or the playground.

Checklist

  • I'm updating documentation
  • I'm adding or updating code
    • I've added and/or updated tests. No snapshots needed updating by this change as far as I can tell; I did not run the build or test:update (see the notes above for what was run).
    • I've updated docs if needed
    • I've updated the changelog with a description of the PR
  • I'm adding a new feature
    • I've updated the playground with an example use of the feature

Prepared with AI assistance; Charan Rathore is directing and responsible for this PR.

@github-actions

github-actions Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Size limit report

Sizes are minified + brotli, measured by size-limit at 094d464.

A package listed twice is measured both as installed and, on the second row, as its own code with its dependencies excluded. Peer dependencies are always excluded.

Check Base PR Δ
@rjsf/antd 6.85 kB 6.85 kB =
@rjsf/antd (without dependencies) 6.44 kB 6.44 kB =
@rjsf/chakra-ui 18.87 kB 18.87 kB =
@rjsf/chakra-ui (without dependencies) 10.83 kB 10.83 kB =
@rjsf/core 83.18 kB 83.18 kB =
@rjsf/core (without dependencies) 22.79 kB 22.79 kB =
@rjsf/core: Form 47.46 kB 47.46 kB =
@rjsf/daisyui 51.55 kB 51.55 kB =
@rjsf/daisyui (without dependencies) 9.58 kB 9.58 kB =
@rjsf/fluentui-rc 5.54 kB 5.54 kB =
@rjsf/mantine 11.45 kB 11.45 kB =
@rjsf/mantine (without dependencies) 7.05 kB 7.05 kB =
@rjsf/mui 6.30 kB 6.30 kB =
@rjsf/primereact 6.14 kB 6.14 kB =
@rjsf/react-bootstrap 7.55 kB 7.55 kB =
@rjsf/react-bootstrap (without dependencies) 5.29 kB 5.29 kB =
@rjsf/semantic-ui 5.26 kB 5.26 kB =
@rjsf/semantic-ui (without dependencies) 5.26 kB 5.26 kB =
@rjsf/shadcn 42.95 kB 42.95 kB =
@rjsf/shadcn (without dependencies) 8.61 kB 8.61 kB =
@rjsf/utils 30.38 kB 30.57 kB +0.20 kB
@rjsf/utils (without dependencies) 17.18 kB 17.43 kB +0.25 kB
@rjsf/utils: getUiOptions 0.31 kB 0.31 kB =
@rjsf/validator-ajv8 36.35 kB 36.35 kB =
@rjsf/validator-ajv8 (without dependencies) 2.55 kB 2.55 kB =
@rjsf/validator-ata 86.09 kB 86.09 kB =
@rjsf/validator-ata (without dependencies) 2.32 kB 2.32 kB =
@rjsf/validator-cfworker 7.19 kB 7.19 kB =
@rjsf/validator-cfworker (without dependencies) 2.29 kB 2.29 kB =

@heath-freenome heath-freenome left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for picking this up. This fixes the exact schema in #5434, but the same false cycle flag still shows up for closely related schemas (see the inline comments), because the underlying problem is in resolveAllReferences, not just these two call sites.

Root cause (resolveAllReferences, around line 425): after resolving each property, it merges every child's refs (childrenLists) back into the caller's recurseList. That turns a path stack (refs from the root to the current node) into a visited set (every ref resolved anywhere so far). Any sibling traversal that shares the list then sees refs a sibling resolved. Besides the two places patched here, that affects:

  • processDependencies (line ~868): one shared recurseList across all dependency keys. With dependencies: { a: { properties: { x: { $ref: '#/definitions/host' } } }, b: { properties: { y: { $ref: '#/definitions/host' } } } } and formData { a: '1', b: '2' }, x resolves but y stays a bare { $ref }.
  • allOf entries in resolveSchema (line ~285): { allOf: [{ properties: { x: { $ref: '#/definitions/host' } } }, { properties: { y: { $ref: '#/definitions/host' } } }] } returns x resolved and y as a raw { $ref }.
  • then/else in resolveCondition under expandAllBranches, and anyOf/oneOf options inside resolveAllReferences.

Rather than adding a [...recurseList] copy at each of these, could the cycle check be made path-scoped? For example, stop pushing childrenLists back into recurseList, or have resolveReference/resolveAllReferences work on their own copy. That would fix all of these at once and make both copies in this PR unnecessary.

Comment thread CHANGELOG.md Resolved
Add tests for refs shared by a root property, dependencies, allOf and oneOf branches.

Signed-off-by: Charan Rathore <[email protected]>
@charan-rathore

Copy link
Copy Markdown
Contributor Author

You were right, thanks. The visited-ref list was shared between siblings, not just between oneOf branches. I added tests that failed on the previous commit and pass now: a $ref used by a root property and by a dependencies oneOf branch, by dependency properties and its oneOf branch, by two dependencies keys, and by two allOf entries. I also added one for expandAllBranches, which already passed.

Pushed ea25f77. A schema with dependencies, allOf or if now resolves its own properties against a copy of the list. The dependencies, allOf, then/else and branch resolutions each get their own copy too. I kept the per-branch copies in withDependentSchema, since the recursion still goes through them. The changelog bullet is in the existing @rjsf/utils section of 6.11.1.

Ran: the full @rjsf/utils vitest suite with TZ=UTC (1602 passed), tsc --noEmit on utils (clean). Not run: eslint (the config would not load in my setup), other packages' suites.

Prepared with AI assistance; Charan Rathore is directing and responsible for this PR.

@heath-freenome heath-freenome left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update. The dependencyValue, processDependencies and allOf cases are now fixed and tested. Unfortunately the isolate change introduces a blocker: recursive schemas under an allOf/dependencies/if root no longer terminate (inline at line 353).

Status of the earlier points:

Earlier point Now
dependencyValue leak Fixed and tested
processDependencies shared list Fixed and tested
allOf entries in resolveSchema Fixed and tested
Root-property leak Only when the root has no $ref (inline at line 349)
then/else Same root-$ref limit, and untested (inline at line 124)
anyOf/oneOf options in resolveAllReferences Not addressed, see below
Root cause (childrenLists merge) Not addressed, see below
Test gaps Partly (inline at test line 795)
Duplicate CHANGELOG heading Not addressed (inline)

Root cause, still unchanged (resolveAllReferences, lines 431-434): every child's childrenLists is still merged back into the caller's recurseList, which turns a path stack into a visited set. Each new traversal that shares the list needs its own copy, and the isolate heuristic is a workaround for that, which is what led to the recursion regression. Making the check path-scoped (stop pushing childrenLists back into recurseList, or have resolveReference/resolveAllReferences work on their own copy) would cover every case and make both isolate and the scattered [...recurseList] copies unnecessary.

anyOf/oneOf options, still unaddressed (line 471): options are resolved with one shared recurseList. retrieveSchemaInternal(v, { definitions: { host }, anyOf: [{ properties: { x: { $ref: host } } }, { properties: { y: { $ref: host } } }] }, root, {}, false, [], undefined, true) (the resolveAnyOfOrOneOfRefs path ObjectField uses) returns option 1 with x resolved and option 2 with y as a bare { $ref: '#/definitions/host' }.

Whatever approach you take, please add a test with a recursive definition under an allOf/dependencies/if root. That would have caught the crash.

Comment thread CHANGELOG.md Resolved
Replace the visited-ref list in resolveAllReferences, which merged
every child's refs back into the caller's list, with a stack that only
contains the refs being expanded on the current resolution path. A $ref
is a cycle only when it is already on that path, so a definition shared
by sibling properties, dependencies branches, allOf entries, then/else
branches or anyOf/oneOf options now resolves everywhere instead of
being cut as a false cycle. Expanded schemas keep their source ref on
the path through RJSF_REF_KEY, so re-walks still detect real cycles and
recursive schemas terminate. This drops the isolate heuristic and the
branch-local list copies, which are no longer needed.

Add tests for recursive definitions under allOf, dependencies and
if/then roots and behind array items, for shared refs under a $ref
root (dependencies, if/then and allOf variants) and for shared refs
across anyOf options, and merge the duplicate @rjsf/utils changelog
section.

Signed-off-by: Charan Rathore <[email protected]>
@charan-rathore

Copy link
Copy Markdown
Contributor Author

@heath-freenome Thanks for the detailed review. I confirmed the blocker first: your allOf repro never returned on the previous head (I killed it after 75s). Reworked the fix in fdd8905 along the lines you suggested.

What changed

  • Dropped the isolate heuristic and the merge-back of childrenLists in resolveAllReferences. The list is now a path stack: a $ref is a cycle only when it is already being expanded on the current resolution path. Pushes create a copy, so nothing is shared with sibling subtrees or back with the caller, and the scattered [...recurseList] copies are no longer load-bearing.
  • To keep re-walks terminating, an expanded schema keeps its source ref on the path through RJSF_REF_KEY. When the resolver walks a previously expanded node, it treats that ref as on the path, so a nested $ref back to it is still cut, one level down, exactly where the first pass cut it. This is what makes the retrieveSchemaInternal loop reach a fixpoint without the visited-set behavior.
  • anyOf/oneOf options in resolveAnyOfOrOneOfRefs mode now resolve each option against the path list, so your example returns option 1 with x resolved and option 2 with y resolved.
  • Root wrapped in a $ref: since nothing pollutes the list from the properties walk anymore, the dependencies/if/allOf branches of a $ref root resolve shared refs too.

Tests added (all asserting exact resolved shapes)

  • Your allOf repro, plus dependencies, if/then and array-items variants: all terminate, the recursive child is cut with the cycle marker.
  • Root-$ref schemas: shared w resolves in the dependencies oneOf, then and allOf[0] variants of your examples.
  • anyOf options with a shared $ref, both options resolved, via your exact retrieveSchemaInternal call.
  • The duplicate @rjsf/utils changelog heading is merged into the existing one.

Validation: full @rjsf/utils suite passes, 1610 tests including the 8 new ones (TZ=UTC). The 4 recursion tests complete in 12ms combined, against 45-94s to RangeError on the previous head. tsc --noEmit is clean for the package. I did not run the repo-wide eslint or the other packages' suites.

Comment thread CHANGELOG.md Resolved
@charan-rathore

Copy link
Copy Markdown
Contributor Author

@heath-freenome Done, the new entry now follows the merge-upgrade bullet (7b0e840).

@heath-freenome heath-freenome left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, the path-scoped list is the right approach. It fixes the recursion crash, the root-$ref case, the anyOf/oneOf options, the double walk and the duplicate CHANGELOG heading. Recursive schemas (direct property, array items, allOf/dependencies/if roots, root $ref, # self-reference, mutual A→B→A) all terminate quickly and are still flagged, and #5434's schema renders Host for both SFTP and FTPS.

Blocker: an existing core test now fails. packages/core/test/SchemaField.test.tsx:895 ("clicking the expand button shows the next level of the cycle") fails with expected null not to be null at line 906: the core suite reports 1 failed of 2106, so CI will be red. Clicking "Expand Cycle" now reveals one level instead of two. For { type: 'object', properties: { child: { $ref: '#' } } }, clicking #root_child_child-button on main renders root_child_child and root_child_child_child with the next button at root_child_child_child_child. With this PR only root_child_child renders, with the button at root_child_child_child. The same happens with a #/definitions/node tree. The cause is the sourceRef branch (lines 409-416), which keeps the expanded ref on the path when ObjectField re-retrieves the schema, so the next child is flagged immediately. Either keep the two-level behaviour or update the test, if one level per click is intended.

The remaining comments are inline.

@charan-rathore

Copy link
Copy Markdown
Contributor Author

Thanks for the careful review. Working through all five points: restore the two-level expand behaviour for cycles, fix the exponential growth in the anyOf/oneOf path, make the termination guarantee explicit in the comment with a fast-failing test, revert the dead recurseList copies and correct the docs, and pin the branch count in the dependencies test. Will update shortly.

Carry the refs expanded during a resolveAllReferences walk into the
follow-up retrieveSchemaInternal pass so recursive schemas reach a
fixpoint instead of expanding one level deeper per pass. Dependency,
condition and allOf branch resolutions start from the pre-carry list:
a ref is only a cycle on the path that is actually expanding it.

Within an anyOf/oneOf list, options resolved after an option that
already expanded a ref keep the plain ref, which keeps the
materialized schema linear on DAGs of shared refs and matches the
pre-regression output. A walk-local expansion cache makes the first
expansion of each ref O(1) per use.

Also adds the fast-failing termination test, the DAG size regression
test and review nits (docs, comments, toHaveLength(2)).

Signed-off-by: Charan Rathore <[email protected]>
@charan-rathore

Copy link
Copy Markdown
Contributor Author

Thanks for the careful read, everything here is addressed in the new head.

Root cause of the expand regression: the sourceRef path push I added in the last round. It is removed. Termination now works the way the old code effectively did: the refs expanded during a resolveAllReferences walk are carried into the follow-up retrieveSchemaInternal pass, so the resolveReference loop reaches a fixpoint instead of expanding one level deeper per pass. That restores the two-level expand click (SchemaField.test.tsx:895 passes again) and no longer relies on RJSF_REF_KEY surviving a walk; the mechanism is documented in resolveReference and there is a fast-failing test (500ms timeout) that pins the recursive-tree shape.

The DAG blowup: options are resolved in order, and an option that reuses a ref an earlier option already expanded keeps the plain $ref instead of materializing the subgraph again. That matches the pre-regression behavior and output size: your depth-14 repro now comes out around 1 KB rather than 902 KB, and a walk-local expansion cache keeps the first expansion of each ref O(1) per use. Added a regression test asserting the materialized size stays linear. One consequence worth knowing: when two distinct options share a ref, the later option shows the ref unresolved in the retrieveSchema output (as before this PR series); the chosen branch is resolved again when it renders, so the form still expands it.

Also done: the stale recurseList copies and their docs are reverted (nothing mutates the list anymore, so they were no-ops), the cycle-marking comment explains why anyOf resolution does not flag there, and the branch-count test now asserts toHaveLength(2).

Run locally: full @rjsf/utils suite 1615 passed with the 100% coverage gate, tsc and oxlint clean, and @rjsf/core SchemaField.test.tsx 47 passed including the expand-button test.

@heath-freenome heath-freenome left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, good progress. The "Expand Cycle" core test passes again and the anyOf DAG is linear (934 bytes in 0.2ms on the L0..L14 repro). Utils (1615/1615, 100% coverage), validator-ajv8 (2969/2969, 100%) and core (2106/2106) all pass. Recursive schemas (direct property, array items, allOf/dependencies/if roots, root $ref, # self-ref, mutual A→B→A) terminate in about 11ms or less and are flagged, and #5434's schema shows Host for both SFTP and FTPS. The root-$ref + dependencies variant, which main still flags, is fixed too.

However, the new expansionCache causes three wrong-output regressions (inline at lines 440, 524 and 533), and it isn't needed: with the cache lookup disabled, the DAG repro stays at 934 bytes, those regressions disappear, and utils still passes 1615/1615. The optionsPath collapse alone keeps the DAG linear. I'd suggest removing the cache and its "reuses the walk-local expansion" test (inline at line 435).

Status of the previous review's points:

# Point Now
1 Failing "Expand Cycle" core test Fixed
2 Exponential anyOf/oneOf growth Fixed
3 Termination comment and fast-failing test Partly: the comment is good, but the test doesn't fail fast (inline at test line 2980)
4 No-op copies and stale docs Mostly: the copies are gone, but retrieveSchemaInternal's @param [recurseList=[]] (line 645) still says "list of recursive references already processed", and the new parameters have no @param on retrieveSchemaInternal, resolveCondition or resolveAllReferences. The split between the list passed in and the carried list is what keeps #5434 fixed, but it's documented only on resolveSchema.
5 Stale resolveAnyOfOrOneOfRefs comment Not addressed, see my existing comment at line 455. The real reason is now that optionsPath collapses refs expanded by earlier options, so marking them would create false cycles.
6 toHaveLength(2) Fixed

@charan-rathore

Copy link
Copy Markdown
Contributor Author

Thanks for the careful re-review — on it. Confirmed on my side as well: the cache lookup disabled keeps the L0..L14 repro at 934 bytes, so I'm removing expansionCache and its test outright rather than re-keying it. The flagged-$ref re-walk on merged dependencies/if/then results is a real bug; I'm fixing it by never re-expanding an already cycle-flagged ref, and I'm restructuring the carry so the path is rebuilt from the RJSF_REF_KEY markers on materialized subtrees instead of a walk-global list, which keeps it limited to the current path. Will also fix the stale recurseList/param docs, the resolveAnyOfOrOneOfRefs comment, and replace the timeout-based termination test with a structural fast-fail. Update shortly.

Replaces the round-4 shared expansion cache and branch-carried recurse
list with a simpler structure: on fixpoint re-walks (passCount > 0)
resolveAllReferences puts a materialized subtree's source ref back on
the path, so an already-expanded ref never expands twice and the
resolveReference loop ends on deepEquals. First passes keep upstream
fresh-call semantics, so the cyclic-$ref expansion UI behavior is
unchanged. The pass counter remains only as a fail-fast backstop.

Signed-off-by: Charan Rathore <[email protected]>
@charan-rathore

Copy link
Copy Markdown
Contributor Author

Thanks for the careful round, @heath-freenome - this one is reworked along the lines you sketched:

  • Expansion cache removed, with its test. There is no per-walk cache anymore, so the local-keyword leak, the path-dependent cycle cut-offs, and the truncated anyOf copy are all gone by construction.
  • Carried list removed. branchRecurseList and the re-walk carry are gone; the path is limited to the current walk again. Instead, on fixpoint re-walks only (passCount > 0), resolveAllReferences puts a materialized subtree's source $ref back on the path, so an already-expanded ref never expands twice and the follow-up pass is a no-op. The loop still ends on deepEquals, not on the counter.
  • Fresh-call semantics preserved. The first pass of a fresh retrieveSchema call deliberately does not re-mark, so a $ref flagged as a cycle by an earlier call expands one more level - that keeps the cyclic-$ref / CyclicSchemaField behavior exactly as on main, including the two-level expansion in the SchemaField cycle test. The sticky early-return is removed.
  • Termination test replaced. The slow watch is gone; there is now a fast structural test (a deep shared-$ref graph must resolve in a bounded number of passes and make the follow-up pass a no-op), plus a backstop test that passCount past the limit throws. No reliance on vitest timeouts interrupting sync recursion.
  • dependencies re-walk now runs as a follow-up pass (passCount + 1), so the re-walk keeps {$ref, CYCLE: true} collapsed like main - verified against main's behavior. Same for the if/then merge re-walk.
  • Docs updated: the stale recurseList carry references are out, passCount and the marker mechanism are documented on resolveAllReferences, and the stale resolveAnyOf comment is fixed.

Suites: utils 1618/1619 (the one failure is utcToLocal, a timezone-env issue that fails identically on a clean checkout here), core 2106/2106, validator-ajv8 2989/2989; tsc and oxlint clean.

@heath-freenome heath-freenome left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the rework. Removing expansionCache was the right call, and most of the last round is resolved:

Previous point Status
Keywords next to a $ref leak through the cache (440) Fixed (cache removed)
Mutual A→B→A flagged one level too early (533) Fixed
Cut-short anyOf expansion cached and reused (524) Fixed (cache removed)
Re-walking dependencies/if results expands a flagged ref (297) Fixed (re-walk is now a follow-up pass)
Carry list grows to O(refs) (386) Carry removed, but see the comment on line 476
"Fails fast" test can't fail fast Partly: the timeout is gone but the name stayed (see line 902)
Stale/undocumented @params Partly: see lines 98 and 114

Blocking: schemas that refer back to themselves through allOf, if/then/else or dependencies overflow the stack on this head, and df332f425 (the base) returns normally for every one of them. These overflowed at a12d07e too, but the new MAX_RESOLUTION_PASSES backstop was added to catch exactly this, and it never triggers. I ran each schema below through retrieveSchema(validator, { $ref }, root, formData):

Schema f94967b df332f4
a: { allOf: [{ $ref: a }] } RangeError ok
a: { if: {...}, then: { $ref: a } } (if matches) RangeError ok
a: { allOf: [{ $ref: b }] }, b: { allOf: [{ $ref: a }] } RangeError ok
node: { dependencies: { k: { $ref: node } } } (k set) RangeError ok
Pet: { if: { petType const cat }, then: { $ref: Cat } }, Cat: { allOf: [{ $ref: Pet }, ...] } RangeError ok

The last one is the usual OpenAPI-style discriminator pattern, so this is likely to show up in real schemas. Details are inline on lines 313 and 1047; the call sites that drop the path and passCount (lines 125-170, 319-329 and 1024) aren't part of the diff, so I anchored there instead.

@charan-rathore

Copy link
Copy Markdown
Contributor Author

@heath-freenome Thank you for the precise repros - confirmed all five stack-overflowed on the previous head here too. Reworked in d915e4b.

Root cause and fix

The nested branch resolutions (the allOf map in resolveSchema, the then/else calls in resolveCondition, and the withDependentSchema/withExactlyOneSubschema calls under dependencies) restarted with the caller's recurseList and passCount = 0, so a definition reaching itself through those branches began each level with an empty path and recursed until the stack overflowed. Now:

  • A new enclosingRefPath helper keeps the enclosing $ref (the RJSF_REF_KEY recorded when it was expanded) on the path for exactly those branch resolutions, and passCount is threaded through resolveDependencies -> processDependencies -> withDependentSchema -> withExactlyOneSubschema and the resolveCondition branches. As with the marker walk, this applies on re-walks only (passCount > 0), so the first pass of a fresh call still expands a flagged ref one more level and CyclicSchemaField behavior is unchanged.
  • One more case sat behind your table: after a dependencies or if/then merge, the merged schema carries both the collapsed $ref and its RJSF_REF_KEY marker. Re-expanding it on the re-walk would repeat the earlier pass forever, so on re-walks a schema whose marker equals its $ref now stays collapsed. That is also what makes your second comment's case return child as the collapsed { $ref: '#/definitions/node' } instead of a one-level-deeper copy with unresolved dependencies.
  • The backstop no longer throws. Past MAX_RESOLUTION_PASSES it returns the schema resolved so far, flagged with RJSF_REF_CYCLE_KEY, so a non-terminating resolution degrades to a cycle indicator rather than unmounting the form.
  • The marker now joins expandedRefs at most once per walk, so re-walks no longer grow the walk-wide list (and the anyOf/oneOf options path built from it) with duplicates.
  • Docs: the six stale @param recurseList carry texts, the missing passCount params, the before/after comment wording, the "carry" comment in withDependentSchema, the expandedRefs test title/comment, and the misnamed termination test (now "collapses a self-referencing property after one level") are all fixed.

Regression tests: all five schemas from your summary, plus the dependent-child-points-back-at-parent schema from your inline comment. I ran each against the base (df332f425) first and the tests assert its exact output: the allOf and mutual-allOf cases collapse to { $ref }, the if/then, dependencies and Pet/Cat discriminator cases return the merged schema with the collapsed $ref re-attached, and the dependent child stays { $ref: '#/definitions/node' }. The backstop test now asserts the flagged-return behavior.

Suites: @rjsf/utils 1625/1625 with the 100% coverage gate (TZ=UTC), @rjsf/core 2106/2106 (including the two-level cycle expand test), @rjsf/validator-ajv8 3019/3019, tsc --noEmit and oxlint clean.

@heath-freenome

heath-freenome commented Oct 6, 2026 •

Copy link
Copy Markdown
Member

@charan-rathore Thanks for the update. It looks like d915e4b didn't make it onto this PR: it was pushed to fix/retrieve-schema-shared-ref-terminates on your fork, while this PR still points at f94967b on fix/shared-ref-oneof-dependencies. Could you push it to the PR branch, e.g.

git push origin d915e4b:fix/shared-ref-oneof-dependencies

Once it's on the PR I'll post the next round of review comments against it.

Also, please fix the build failures

@charan-rathore

Copy link
Copy Markdown
Contributor Author

@heath-freenome Right you were - it landed on the other branch by mistake. Pushed exactly as you suggested; the PR now points at d915e4b. Ready for the next round whenever you are.

@heath-freenome heath-freenome left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pushing it. d915e4b fixes everything from the last round except one test:

Previous point Status
allOf / then/else / dependencies cycles overflow the stack (313) Fixed: all five repros match main, both at the root and nested
childBack resolves differently from main (1047) Fixed
Backstop throws during render (371) Fixed: it now returns a schema flagged as a cycle
expandedRefs collects duplicates (476) Fixed
Stale carry docs, passCount JSDoc, before/after wording, name of test 902 Fixed
Backstop test reaches the limit with a real schema Not yet, see the comment on the test

#5434 is still fixed. There's one new behavioral issue (inline at 378), plus a nit.

FYI, not asking for a change: since the cache was removed, a diamond-shaped allOf (where each level's allOf refers to the next level twice) costs 2^depth. At depth 16 that's about 300ms, where main takes well under 1ms.

passCount = 0,
): S[] {
const updatedSchema = resolveAllReferences<S>(schema, rootSchema, recurseList, undefined, resolveAnyOfOrOneOfRefs);
if (passCount > MAX_RESOLUTION_PASSES) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Every pass of the fixpoint loop resolves its allOf, then/else and dependencies branches with the caller's passCount. Those branches then run their own passCount + 1 follow-up pass (414, 319, 194), so the count grows by one for each level of nesting rather than counting passes over a single schema. A finite, non-cyclic chain about 100 levels deep therefore hits this backstop and gets cut short, even though nothing in it repeats:

const mk = (kind: 'allOf' | 'deps' | 'then', n: number) => {
  const definitions: Record<string, RJSFSchema> = {};
  for (let i = 0; i < n; i++) {
    const next = i + 1 < n ? { $ref: `#/definitions/d${i + 1}` } : { properties: { leaf: { type: 'string' } } };
    const props = { k: { type: 'string' }, [`v${i}`]: { type: 'string' } } as const;
    definitions[`d${i}`] =
      kind === 'allOf'
        ? { allOf: [{ properties: { [`v${i}`]: { type: 'string' } } }, next] }
        : kind === 'deps'
          ? { type: 'object', properties: props, dependencies: { k: next } }
          : { type: 'object', properties: props, if: { properties: { k: { const: 'x' } } }, then: next };
  }
  return { definitions, $ref: '#/definitions/d0' } as RJSFSchema;
};
const s = mk('deps', 100);
retrieveSchema(validator, s, s, { k: 'x' });
Chain Smallest n that diverges main / f94967b d915e4b
allOf 102 103 properties 101 properties plus a leftover $ref: '#/definitions/d101', not flagged
dependencies 100 102 properties root flagged with RJSF_REF_CYCLE_KEY
if/then 100 102 properties root flagged with RJSF_REF_CYCLE_KEY

The flagged cases are the worse ones: when the root schema is flagged, SchemaField replaces the whole form with the cycle indicator. The allOf case quietly drops the rest of the chain.

Termination already comes from the path and the markers, so the branches only need to know whether they're on a re-walk, not how deep the re-walking has gone. Passing passCount > 0 ? 1 : 0 (or a boolean) to the nested branch resolutions should keep the counter local to one fixpoint loop. I haven't tried it, though. Once that's in, a test that builds a chain like the one above and expects it to resolve fully would guard against this.

The comment on MAX_RESOLUTION_PASSES (36-39) also needs updating. It says a resolution that's still changing after this many passes isn't terminating, but as shown above, a terminating resolution can get here through nesting alone.

expandAllBranches,
enclosingRefPath(schema, recurseList, passCount),
formData,
undefined,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: this passes undefined where the experimental_customMergeAllOf in scope could be passed, so a custom merge isn't applied inside the oneOf branches of dependencies. main drops it here too, so it's not a regression, but this PR already rewrites this call, so it's a cheap fix.

[RJSF_REF_KEY]: '#/definitions/node',
});
});
it('returns the schema resolved so far, flagged as a cycle, when the pass-count backstop is exceeded', () => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test still reaches the backstop by passing passCount 101 directly to retrieveSchemaInternal, so it only covers the early return. It would be stronger with a schema that hits the limit on its own, through the public retrieveSchema. If the nested-branch counter is fixed as suggested at line 378, though, no finite chain may reach the limit any more. In that case, a comment here saying the backstop can only be reached by passing passCount directly would make the intent clear.

Nested allOf, if/then/else and dependencies branch resolutions were
receiving the caller's passCount, so a finite non-cyclic chain about 100
levels deep could hit the MAX_RESOLUTION_PASSES backstop and be falsely
collapsed as a cycle (truncating the remaining levels). Branch calls now
receive only the caller's re-walk status (passCount > 0 ? 1 : 0), so each
fixpoint loop counts its own passes and nesting depth alone cannot reach
the limit. Also pass experimental_customMergeAllOf through to oneOf
branch resolution inside dependencies (pre-existing gap on main).

Adds public retrieveSchema tests resolving 100+ level non-cyclic chains
through allOf, dependencies and if/then fully (no cycle flag, every
level's properties present), and notes on the backstop test that the
backstop is now only reachable via direct passCount injection.

Signed-off-by: Charan Rathore <[email protected]>
@charan-rathore

Copy link
Copy Markdown
Contributor Author

Thanks for the detailed review — the passCount analysis was spot on. A finite ~100-level non-cyclic chain really was collapsing as a false cycle because every nested branch resolution inherited the caller's pass depth.

What I changed, following your suggestion:

  • All five branch-resolution sites (resolveCondition then/else/conditional x3, resolveSchema allOf elements, withDependentSchema dependency value and oneOf $ref resolution, withExactlyOneSubschema) now pass passCount > 0 ? 1 : 0, so each fixpoint loop counts its own passes. Nested branches only need the caller's re-walk status, not its depth, and nesting depth alone can no longer reach MAX_RESOLUTION_PASSES. Updated the comment on the constant to say so.
  • Nit: withDependentSchema's oneOf branch resolution now passes experimental_customMergeAllOf through instead of undefined (pre-existing on main, as you noted).
  • New public-path tests: retrieveSchema resolving non-cyclic ref chains through allOf (102 levels), dependencies (100) and if/then (100). Each asserts no cycle flag, the leaf property present at top level, and the full property count (103 / 102 / 102 respectively) — i.e. fully resolved, not truncated.
  • On the backstop test I took your fallback option: with the counter local to one fixpoint loop, no finite schema can reach the backstop through the public path anymore, so the test still calls the internal with passCount: 101 directly, now with a comment explaining that this is the only remaining way to reach it.

Red-to-green: the three chain tests fail on the previous head (allOf truncated with a leftover $ref, dependencies and if/then flagged as cycles) and pass with the fix. Full @rjsf/utils suite: 1628/1628 passing across 85 files, no regressions.

@heath-freenome

Copy link
Copy Markdown
Member

@charan-rathore your typechecks are failing

CI typecheck (tsc --build) flagged the tests added with the fixpoint work: annotate the standalone definitions records and the mkChain builder pieces as RJSFSchema so string literals narrow instead of widening, check the cycle flag with the in operator rather than symbol indexing, and narrow a JSONSchema7Definition union before reading anyOf. Type-only changes; the suite is unchanged (1628/1628 pass).

Signed-off-by: Charan Rathore <[email protected]>
@charan-rathore

Copy link
Copy Markdown
Contributor Author

Good catch, thanks - the failures were type errors in the test code this PR adds, not in the runtime change:

  • standalone definitions records and the mkChain builder pieces let string literals widen to string, so they no longer satisfied RJSFSchema - now annotated as Record<string, RJSFSchema> / RJSFSchema so the literals narrow
  • the cycle flag was read by symbol indexing (result[RJSF_REF_CYCLE_KEY]) - now checked with the in operator
  • a JSONSchema7Definition union needed narrowing before reading .anyOf

Type-only changes; the tests themselves are untouched. tsc --build is clean locally now (0 errors) and the utils suite still passes 1628/1628. Pushed as c85e4c2.

@heath-freenome

Copy link
Copy Markdown
Member

@charan-rathore and now the tests are failing

… passes

The 100% branch coverage gate flagged the two expandAllBranches recursions added with the pass-counter work (retrieveSchema.ts lines 140 and 159): no test resolved a conditional with expandAllBranches while already on a re-walk. Add a test that reaches an if/then/else through a $ref, which expands on the first pass so the conditional resolves on a follow-up pass, and asserts both branches expand. Suite still passes with the coverage gate green.

Signed-off-by: Charan Rathore <[email protected]>
@charan-rathore

Copy link
Copy Markdown
Contributor Author

Tracked it down: the test assertions all pass (1628/1628) - the failing piece was the 100% branch coverage gate in the utils test task. It flagged the two expandAllBranches recursions from the pass-counter change (retrieveSchema.ts lines 140 and 159): no test resolved a conditional with expandAllBranches while already on a re-walk, so the passCount > 0 side of those ternaries was uncovered.

Added a test that reaches an if/then/else through a $ref: the ref expands on the first pass, so the conditional resolves on a follow-up pass with the branch-local counter already past the first pass, and both branches expand. Verified locally: utils suite 1629/1629 with the coverage gate green, tsc --build clean. Pushed as c5f6a0a.

@heath-freenome heath-freenome left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the quick turnaround. All three points from the last round are addressed:

Previous comment Status
passCount grew with nesting, so finite chains were truncated or flagged as cycles ✅ Fixed. Nested allOf, then/else and dependencies branches now get passCount > 0 ? 1 : 0. The new it.each chain tests fail on d915e4b and pass here.
experimental_customMergeAllOf not passed to the dependencies oneOf resolution ✅ Fixed
Backstop test reached the limit only by passing passCount directly ✅ Addressed with a comment explaining why a direct call is the only way to reach it

What I checked on c5f6a0a:

  • Tests: all 1629 @rjsf/utils tests pass, with 100% statement, branch, function and line coverage.
  • Cycles: I compared main, d915e4b and this head on 9 cyclic schemas, including mixed three-way cycles (dependencies → if/then → allOf), a cycle through a dependencies oneOf, and a self-reference in both then and else. Nothing overflows the stack, and nothing that previously terminated through the nesting-driven count behaves differently.
  • Finite chains: chains of allOf, dependencies and if/then up to 600 levels deep resolve the same as on main. So do chains of $ref with sibling keywords, properties and items. None reaches the backstop, which supports the new test comment's claim.

The three inline comments are small nits. None of them blocks merging, so I'm approving.

});
});
}
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this closing } ended up indented by 12 spaces, so oxfmt --check fails on this file. CI doesn't run cs-check, so it would be merged as is. Running pnpm run cs-format fixes it.

Comment on lines +138 to +140
// Keep the counter local to this fixpoint loop: a nested branch only needs to
// know whether the caller is on a re-walk, not how deep the re-walking has gone.
passCount > 0 ? 1 : 0,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: passCount > 0 ? 1 : 0 now appears six times, each with an inline comment: this two-line one three times in resolveCondition, and a one-line "Branch-local counter" one in the other three places. The MAX_RESOLUTION_PASSES comment already explains the reason, and the repo leans toward no comments by default. Consider a small named helper with one JSDoc, something like:

/** A nested branch's fixpoint loop counts its own passes; it inherits only whether the caller is on a re-walk. */
function branchPassCount(passCount: number) {
  return passCount > 0 ? 1 : 0;
}

or just drop the six inline comments.

Comment on lines +1026 to +1028
// With the pass counter kept local to one fixpoint loop, no finite schema reaches the backstop through
// the public retrieveSchema path: nesting depth no longer counts as passes. The backstop now only fires
// when passCount is injected directly, as below, or if a regression breaks structural termination.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: "no longer counts" and "The backstop now only fires" describe the change rather than the code. The repo's CLAUDE.md asks to keep that kind of note in commit messages. Maybe:

// Nesting depth doesn't count as passes, so no finite schema reaches the backstop through the public
// retrieveSchema path; it fires only when passCount is injected directly, as below, or if a regression
// breaks structural termination.

Charan Rathore added 2 commits October 7, 2026 07:30
…op note

Review nits: the passCount > 0 ? 1 : 0 call sites no longer each carry the same inline comment (the MAX_RESOLUTION_PASSES note already explains the scheme), and the backstop test comment now describes the code rather than the change.

Signed-off-by: Charan Rathore <[email protected]>
oxfmt --check flagged the over-indented closing brace at the end of retrieveSchema.ts; formatting only, no code change.

Signed-off-by: Charan Rathore <[email protected]>
@charan-rathore

Copy link
Copy Markdown
Contributor Author

Thanks for the thorough check. On the nits:

  • Dropped the repeated inline comments at all seven passCount > 0 ? 1 : 0 call sites (the MAX_RESOLUTION_PASSES note already carries the explanation) - pushed
  • Fixed the over-indented closing brace in retrieveSchema.ts; oxfmt --check is clean on it now - pushed
  • The test file has the same stray-indent artifact on its last line, plus the backstop-note reword you suggested - both are staged and land with my next push shortly

@charan-rathore

Copy link
Copy Markdown
Contributor Author

Both follow-ups are pushed now (094d464): the test file's closing brace indentation is fixed and the backstop comment is reworded as you suggested. oxfmt --check is clean across the package, utils suite still 1629/1629 with retrieveSchema.ts at 100% on all four metrics.

@heath-freenome
heath-freenome merged commit 1280ca7 into rjsf-team:main Oct 7, 2026
6 checks passed
heath-freenome added a commit that referenced this pull request Oct 7, 2026
The rebase onto v7 brings in #5435, which replaced the visited-ref list
`resolveAllReferences()` kept with a path-scoped stack: entries are added
only for the refs being expanded on the current path, and are never
shared with siblings or merged back into the caller's list. Three of this
branch's changes were written against the merge-back and had to be
rewritten for the stack.

`parseSchema()` threaded a `recurseList` into `retrieveSchemaInternal()`
and read back what the resolution had added to it, which is how an option
a recursive node declares stopped being resolved a level deeper every
round. That list now comes back exactly as it went in, so the descent had
nothing to stop it again: the four `parses a recursive schema carrying
...` cases each ran for 26 to 80 seconds and then overflowed the stack.
What resolution expanded is read off the schema instead -- every subtree
it materializes is marked with its source ref as `RJSF_REF_KEY`, which is
the handle #5435 itself uses for the same question -- and that list seeds
the option resolution and the recursive parses. All four parse in 0ms
again, the file's 57 tests run in 399ms where they took 203 seconds, and
no `schemaParser()` snapshot moved.

`resolveDependencies()` and `retrieveSchemaInternal()`'s pattern merge
each copied their list for the same reason, which is now a no-op: the
copies are gone and the comments say what the remaining seed is for. One
test comment claimed the merge-back too.

The one textual conflict was in `resolveDependencies()`, where #5435 adds
`passCount` to the `processDependencies()` call this branch had wrapped.
Both sides kept.

#5435 also adds `does not flag a $ref shared by several oneOf branches
when expanding all branches`, which asserts two results. Expanding every
branch returns three here, since this branch also returns the schema with
the dependency unapplied -- what a form renders until the user picks a
protocol. Its point is unchanged and still asserted: the shared `$ref`
resolves in both branches.

lint, knip, build, test and cs-check green, 15 projects passing,
`@rjsf/utils` at 100% coverage across statements, branches, functions
and lines.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
jimmycallin pushed a commit to jimmycallin/react-jsonschema-form that referenced this pull request Oct 7, 2026
Brings in the main changes v7 did not already have from the earlier squashed
syncs (rjsf-team#5290, rjsf-team#5376, rjsf-team#5422):

- rjsf-team#5423: validate a falsy root formData (`false`, `0`, `''`) instead of
  treating it as missing, ported into v7's validateFormData()
- rjsf-team#5435: detect $ref cycles with a path-scoped recursion stack in
  retrieveSchema(), ported onto v7's SchemaContext signatures; its tests are
  adapted to `{ validator }` contexts and v7's stricter lint rules
- CHANGELOG.md taken from main (adds the 6.11.1 section)

Everything else main changed since 6.10.0 was already on v7, so those files
keep v7's content, including v7's theme snapshots. This is a real merge so
the merge base moves forward to main's tip.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
heath-freenome added a commit that referenced this pull request Oct 7, 2026
The rebase onto v7 brings in #5435, which replaced the visited-ref list
`resolveAllReferences()` kept with a path-scoped stack: entries are added
only for the refs being expanded on the current path, and are never
shared with siblings or merged back into the caller's list. Three of this
branch's changes were written against the merge-back and had to be
rewritten for the stack.

`parseSchema()` threaded a `recurseList` into `retrieveSchemaInternal()`
and read back what the resolution had added to it, which is how an option
a recursive node declares stopped being resolved a level deeper every
round. That list now comes back exactly as it went in, so the descent had
nothing to stop it again: the four `parses a recursive schema carrying
...` cases each ran for 26 to 80 seconds and then overflowed the stack.
What resolution expanded is read off the schema instead -- every subtree
it materializes is marked with its source ref as `RJSF_REF_KEY`, which is
the handle #5435 itself uses for the same question -- and that list seeds
the option resolution and the recursive parses. All four parse in 0ms
again, the file's 57 tests run in 399ms where they took 203 seconds, and
no `schemaParser()` snapshot moved.

`resolveDependencies()` and `retrieveSchemaInternal()`'s pattern merge
each copied their list for the same reason, which is now a no-op: the
copies are gone and the comments say what the remaining seed is for. One
test comment claimed the merge-back too.

The one textual conflict was in `resolveDependencies()`, where #5435 adds
`passCount` to the `processDependencies()` call this branch had wrapped.
Both sides kept.

#5435 also adds `does not flag a $ref shared by several oneOf branches
when expanding all branches`, which asserts two results. Expanding every
branch returns three here, since this branch also returns the schema with
the dependency unapplied -- what a form renders until the user picks a
protocol. Its point is unchanged and still asserted: the shared `$ref`
resolves in both branches.

lint, knip, build, test and cs-check green, 15 projects passing,
`@rjsf/utils` at 100% coverage across statements, branches, functions
and lines.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
heath-freenome added a commit that referenced this pull request Oct 7, 2026
…mMergeAllOf (#5371)

* Fix 5338: compile precompiled validators with the form's customMergeAllOf

A precompiled validator only has functions for the sub-schemas
schemaParser() collected, keyed by their hash. The parser had no way to
receive a customMergeAllOf, so a form whose merge produced different
sub-schemas threw "No precompiled validator function was found for the
given schema".

schemaParser() takes an optional SchemaParserOptions, holding the
customMergeAllOf, and parses with a SchemaContext built from it.
SchemaContext now extends SchemaParserOptions. compileSchemaValidators()
and compileSchemaValidatorsCode() in @rjsf/validator-ajv8 and
@rjsf/validator-ata take the same options as a trailing argument. When
given a customMergeAllOf, retrieveSchemaInternal()'s expand-all path also
returns each allOf merged with it and resolved the rest of the way, so
the parser collects the sub-schemas the form validates against.

Also fixed while here:
- schemaParser() took a schema as covered by the options it resolves to,
  so a property that every oneOf/anyOf option redefines was parsed only
  as each option spells it, never as the schema's own.
- Upgraded ata-validator to ^1.32.0. The ^1.23.0 v7 pins resolves to
  standalone bundles that throw "_re1 is not defined" for a schema with
  patternProperties, so the precompiled ata validator could not validate
  one.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* Fix 5338: merge an allOf when expanding all branches, as a form does

Addresses the review of #5371.

A form always merges an `allOf`, so the sub-schemas it validates against are
the merged schema's. `expandAllBranches` returned the unmerged branches
instead, which hold neither the sub-schemas a `customMergeAllOf` rewrote nor
the ones that only exist once the merge has brought a property together with
the `patternProperties` matching it. Gating a second, merge-aware path on
`customMergeAllOf`, as this branch did, left the second case broken whenever no
custom merge was passed, and re-resolved the merged schema in a way the form
does not, which is what made the recursion guard necessary.

Expanding all branches now merges the `allOf`, and drops one it cannot merge,
through the same code the form uses, so the two cannot diverge. The branch
variants were also what `resolveSchema()`'s permutation of the `allOf` members
multiplied: a root `allOf` of six three-item `allOf`s went from 15,631 merges
in 60.2s to 7 in under a millisecond. Every `schemaParser()` snapshot is
unchanged, so the branches were contributing nothing to the parsed map.

Also in the parser:

- Each `oneOf`/`anyOf` option is parsed rather than having its `properties`
  read off, so an option whose sub-schemas come from its own `allOf`,
  conditions or dependencies is reached. A parsed set held by identity keeps a
  property the options share from being resolved once per option.
- The `patternProperties` and `additionalProperties` schemas are parsed. A key
  they describe is only stubbed into `properties` once the form data has it,
  which a parse has none of, so nothing reached them.
- Every position of a tuple `items` is parsed, with `additionalItems` only for
  a tuple, matching what `ArrayField` renders.
- Two schemas that share an `$id` and differ no longer fail the parse. The
  first is compiled and answers for the rest, which is how both the
  precompiled and the regular validators look a schema up.

`SchemaParserOptions` is a `Pick` of `SchemaContext` rather than an interface
`SchemaContext` extends, leaving the context type as v7 has it.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* Fix 5338: parse a patternProperties key as the allOf a form merges for it

A form renders a key its `patternProperties` match with the merge of every
pattern matching it, which `stubExistingAdditionalProperties()` resolves as
`{ allOf: [...matching] }`. The parser pushed each pattern's own schema
instead, so a `customMergeAllOf` that rewrites a sub-schema of that merge
never saw it and the form threw `No precompiled validator function was
found for the given schema`. Each combination of patterns is now parsed as
that `allOf`, since a parse has no form data to tell it which key matches
which patterns.

Merging a property with the `patternProperties` matching it also resolved
that property with the branch expansion off, even while expanding all
branches for the parser, so its conditions collapsed to their `else` and
its dependencies were skipped. `expandAllBranches` is passed through and
the parent fans out over the property's variants.

`getFirstMatchingOption()` and `relaxOptionsForScoring()` kept the `$id` of
the option they derive a schema from. A validator caches the function it
compiles under that `$id`, so every variant was answered by the function
compiled for the first of them -- the relaxed variant validating as
strictly as the one it was meant to relax. Both drop it now, so each
variant is keyed by its content and each is compiled, and `ParserValidator`
goes back to failing loudly on a genuine key collision rather than keeping
the first and warning. The junk option keeps its `$id`, which the
precompiled validators answer it by.

A schema whose `$id` is the empty string was mapped under that `$id`, where
no validator looks for it: both the precompiled and the regular ones fall
back to the hash for one.

`compileSchemaValidators()` and `compileSchemaValidatorsCode()` take the
`customMergeAllOf` in their existing options rather than in a second
trailing bag, as the new `CompileValidatorOptionsType`.

The parser keys the schemas it has walked by content rather than scanning a
list with `deepEquals()`, which cost quadratically in a schema's properties
and options: 150 properties and 20 options parse in 32ms rather than 86ms,
to the same 471 sub-schemas.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* Fix 5338: parse an allOf both merged and as it stands, as a form reads both

A form does not validate only against the merge of an `allOf`:
`getObjectDefaults()` reads a nested object's unmerged `properties`, and
`omitExtraData()` reads the entries a merge leaves in place, scoring the
`oneOf` options it finds in each. Merging the `allOf` when expanding all
branches therefore stopped compiling sub-schemas a form still asks about,
which threw `No precompiled validator function was found for the given
schema` for a rewriting or a partial `customMergeAllOf`. `parseSchema()`
now parses the entries and the rest of the schema alongside the merge.

`resolveAnyOrOneOfSchemas()` scored only the options a schema declares,
where `MultiSchemaField` scores the ones it has retrieved, so an option
that is a `$ref` to an `allOf` definition was never compiled in the form
that gets validated. Each option's retrieved form is now scored too.

`withExactlyOneSubschema()` returned no schema at all when expanding a
dependency's `oneOf` that no option qualifies for, and the empty list
reached `getAllPermutationsOfXxxOf()` as `undefined`. Such a `oneOf` is
now ignored, as it already is when the form data picks no single option.

The variants of the properties merged with their matching
`patternProperties` are varied one property at a time rather than in
every combination, so `k` two-branch properties make `k + 1` variants
and not `2 ** k`, and the `properties` object is rebuilt once rather
than once per matched key, which had cost the form's own resolution
quadratically in them: 2000 properties went from 5.6ms to 603ms, and is
now 7.4ms.

`getFirstMatchingOption()` and `relaxOptionsForScoring()` derive the
`$id` of the variant they build rather than dropping the option's:
`<the option's>?rjsf=<the variant's hash>` names the variant while
keeping the option's as the base a relative `$ref` left inside it
resolves against, which dropping it broke.

`schemaParser()` reports a schema with more than 16 `patternProperties`
rather than enumerating the `2 ** n - 1` combinations of them.

The regular validators key a schema whose `$id` is the empty string by
its hash, as the precompiled ones do. For ajv8 that stopped two such
schemas sharing one compiled function; for ata and cfworker, which
re-check the cached schema, it stops them evicting each other, in
`rawValidation()` as well as `isValid()`.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* Fix 5338: register a root schema with an empty $id under the root prefix

`handleSchemaUpdate()` registered the root schema under `rootSchema[ID_KEY]
?? ROOT_SCHEMA_PREFIX`, so a root carrying `$id: ''` registered under the
empty name while `withIdRefPrefix()` went on rewriting every local `$ref`
to resolve against `__rjsf_rootSchema`. Nothing was registered there, so
each `$ref` into such a root failed to compile and `isValid()` answered
`false` after logging `can't resolve reference`. An empty `$id` names
nothing, so the root falls back to the prefix as one with no `$id` does.
`@rjsf/validator-cfworker` always used the prefix and was unaffected.

Each `oneOf`/`anyOf` option gets its own copy of the `recurseList` when
it is retrieved for scoring: a `$ref` one option resolves is not one a
sibling has already been through, which is why the `properties` loop of
`resolveAllReferences()` copies it too.

Drops the `ata-validator` changelog bullet: the rebase onto v7 brought
`^1.40.1` in through #5422, so this branch no longer bumps the dependency
and the versions the bullet named were both stale.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* Fix 5338: parse the sub-schemas reached only after resolution

Fourth review round. Six fixes, two narrowed claims and one cleanup.

An `allOf` is merged inside `retrieveSchemaInternal()`, so one reached
through a `then`/`else` or a dependency was merged before the parse saw
it and the entries `getObjectDefaults()` and `omitExtraData()` read
unmerged were never collected. They are now reached on what resolution
returns as well as on the schema the parse was handed.

`getFirstMatchingOption()` scored an option with no `properties` as it
stands, keeping the option's `$id`. `MultiSchemaField` scores the
options it has retrieved, so an option whose retrieval changes it is a
different schema under one key. Deriving the `$id` is also idempotent
now, so relaxing an option and then scoring the relaxed one names one
schema rather than stacking a second `?rjsf=` suffix on.

Merging a property with its matching `patternProperties` restarted the
list of resolved references, so a recursive `$ref` under a key one of
those patterns matches overflowed the stack, in the form's own
resolution as well as the parser's. The merge is seeded with the one
reference this schema was itself reached through, and with a fresh copy
of it per key. Not with `recurseList`: `resolveAllReferences()` merges
the references each property resolved back into the list it was given,
so that list -- and a list shared between the keys -- holds what another
key resolved, which reads as a cycle and leaves this key holding a
literal `$ref` in place of what it resolves to. Mutual recursion
between two schemas through their `patternProperties` still overflows,
as it does on v7; this makes no case worse than v7 and fixes the
self-recursive one.

Expanding all branches applied every dependency, where a form leaves one
unapplied until its key has a value and scores an option in that form.
The unapplied variant is returned alongside the applied ones. Doing this
per key, as suggested, is the product of the two states: 16 dependency
keys took 1ms -> 2147ms and produced no further schema, since the
intermediate merges reach no `isValid()` call. Only the all-unapplied
variant is added, which is 1ms again; the subsets in between are not
covered and the comment says so.

`omitExtraData()` scores the options of a dependency's `oneOf` itself,
where resolving the dependency only validates the conditions
`withExactlyOneSubschema()` builds out of them, so each schema
dependency is now parsed in its own right.

`schemaKey()` replaces the eight copies of `schema[$id] || hash` across
`ParserValidator` and the three validators, which is where the `??`
family of bugs came from, and `CompileValidatorOptionsType` is
`CustomValidatorOptionsType & SchemaParserOptions<S>` in both validators
rather than an interface restating the parser's options in each.

Two claims narrowed rather than fixed, both pre-existing. An option
whose `additionalProperties` stubs the keys a user adds into its
`properties` hashes differently per key, which no parse can enumerate;
the comment and the changelog say so instead of claiming retrieved
options are covered. The tuple-`items` casts are gone from the three
tests that had them, the option lists being exported from the fixtures.

Every new test fails when its fix is reverted. All 13 `schemaParser()`
snapshots are insertions only -- 11 byte-identical, 2 grown by exactly
the dependency `oneOf` options -- so nothing left a compiled map. lint,
knip, build, test and cs-check green, `@rjsf/utils` and all three
validators at 100% coverage.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* Fix 5338: validate a retrieved option under an $id that names it

Fifth review round. Seven fixes, one narrowed claim and two cleanups.

`MultiSchemaField` validates the option it retrieved as it stands, not
only as the scoring augments it, when a parent declines an option
switch: the data still fitting the chosen option is what keeps it. That
asked for the option under the `$id` it declares, which names the
option rather than its retrieved form, and nothing compiled that key
once the scoring derived its own. Both sides now derive it with
`withVariantId()`, which is exported for the purpose, and the parse
validates each retrieved option as it stands as well as scoring it. An
option carrying no `$id` was never compiled in that form either, on v7
as much as here, and is now.

More `patternProperties` than the combinations of them can be
enumerated for no longer fails the whole compile. Past the cap each
pattern alone and all of them together are parsed, and a warning names
what a key matching some other subset of them loses. 17 patterns of
`{ type: 'string' }` compiled on v7 and threw here, while producing no
schema the cap left out.

The `2 ** n - 1` combinations were rebuilt and stringified once per
object schema the parse visited, and an option merged into its parent
carries the parent's `patternProperties`, so each option multiplied the
cost: 14 patterns took 39ms alone and 323ms with 8 options, for the same
9 compiled schemas. They are enumerated once per distinct
`patternProperties` in a parse, which is 39ms either way.

`getFirstMatchingOption()` serialized every option carrying an `$id` on
every call, where it used to look a key up, and an option is re-scored
on every change to the form data. The schema an option is scored by is
memoized by the option it was derived from, which also folds the two
`isValid()` branches into one: 1000 calls over two 200-property options
took 330ms and now take 1ms.

A `dependencies` declared by an `if`'s `then` or `else` branch was never
parsed in its own right. `omitExtraData()` applies the branch it selects
by walking the branch's own schema, where resolution only merges the
branch into the schema it conditions, so a form whose data selected the
branch and filled the dependency key threw `No precompiled validator
function was found for the given schema`.

One `isSchemaObject()` next to `isObject()` replaces the copy in
`schemaParser` and the one inside `omitExtraData()`, and the marker read
is behind a typed `refOf()`, which takes two of the three new `as` casts
with it. The third stays: `Omit<S, 'allOf'>` is not assignable to `S`,
and a helper typed to take it only moves the cast inside.

The reference the `patternProperties` merge is seeded with is read off
the schema before its `allOf` is merged, since `mergeAllOf` drops the
Symbol keys and the re-apply recovers only the entries'. That does not
fix the `customMergeAllOf` case it was suggested for, which overflows
either way, and the changelog and the docs are narrowed to the
self-recursive case rather than claiming the mutual one. On v7 all six
cases of both probes overflow; this branch fixes two of them and makes
none worse. A seed that fixes five -- the whole list minus the
references the matching patterns exist to resolve -- leaves the suite
green but turns the mutual-recursion parse from a stack overflow into a
loop that does not terminate, because the growth is in `parseSchema`
itself, each level one nesting deeper than the last. A fast crash beats
a hang, so that waits for a parser-side bound.

Every new test fails when its fix is reverted, except the one pinning
that a `patternProperties` is enumerated once, which the `parsed` set
makes unobservable in the map. The `schemaParser()` snapshots are
insertions only. lint, knip, build, test and cs-check green, 15 projects
passing, `@rjsf/utils` and all three validators at 100% coverage.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* Fix 5338: score a boolean option without keying the memo by it

A `oneOf`/`anyOf` entry may be a boolean schema, and memoizing the
schema an option is scored by keyed the memo by the option itself, so
`WeakMap.set()` threw `Invalid value used as weak map key` on one.
`getFirstMatchingOption()` and `schemaParser()` both crashed, the latter
in place of emitting a map at all, where before the memo the boolean
fell through to `isValid()` and scored as it stands. A non-object option
is returned before the memo is reached, which is what scoring it as it
stands amounts to: a boolean declares no `properties` to augment and no
`$id` to derive.

`relaxOptionsForScoring()` builds the relaxed form of an option afresh
on every call, which derives an `$id` and so serializes the option, and
`omitExtraData()` relaxes the options of a `oneOf` on every change to
the form data. The fresh object also missed the scoring memo, which
keys by the option it is given, so a large option was serialized twice
per call rather than once. The relaxed form depends on nothing but the
option, so it is memoized the same way: 20 `omitExtraData()` calls over
two 200-property strict options take 12ms rather than 19ms.

The scoring memo's comment credited `MultiSchemaField` and
`omitExtraData()` without saying what keeps the options they hand over
the same objects, which reads as if the memo could not hit on either.
It names the two reasons now: `retrieveSchema()` answers from its own
cache while what it resolves is unchanged, and the relaxed option is
memoized as of this commit. Measured with the memo instrumented, the
options retrieved per data change hit 39 times out of 40 for options
that are a `$ref` to a 200-property definition.

Both new tests fail when their fix is reverted. lint, knip, build, test
and cs-check green, 15 projects passing, `@rjsf/utils` at 100% coverage
across statements, branches, functions and lines.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* Fix 5338: assert the scoring keys outside an option that has an $id

Sixth review round. One correctness fix, and the compilation contract
says what a capped parse costs.

An option carrying an `$id` names a document that a `$ref` inside it can
resolve back to -- `$ref: ''` names that document -- so merging the
`anyOf` of its property names into it applied that assertion to every
child the option described through such a reference. A recursive option
then rejected data it accepts: scoring `{ child: {} }` against an option
whose `child` is `$ref: ''` failed, because the child was validated
against the augmented form and `{}` holds none of the keys. The
assertion is held in an `allOf` around the option instead, and the
option it holds carries the derived `$id`, so the reference resolves to
the option rather than to what wraps it.

The report has this passing on v7, which it does, but not because v7
applies the assertion correctly: v7 keeps the option's own `$id` on the
augmented schema, `handleSchemaUpdate()` has already registered the root
schema, and AJV indexes the option's `$id` from inside it, so `isValid()`
is answered by the function compiled for the raw option and the
augmentation is discarded. Measured with a fresh validator per case, v7
returns true for `{}` against an option declaring `child` and `label` --
rejecting that is the whole purpose of the augmentation. So the behaviour
this restores was never there to regress; the cache collision hiding it
is what the fourth and fifth rounds fixed.

The derived `$id` is hashed over the option plus the assertion appended
to its `allOf`, not over the option alone. The option alone is what
`withVariantId()` already names for the retrieved form that
`MultiSchemaField` validates, and a precompiled validator compiles both,
so sharing that `$id` made AJV throw `schema with key or id "...?rjsf=
-435a3a9e" already exists` at compile time for an option declaring no
`required`. Appending to the `allOf` rather than merging also keeps an
`anyOf` the option declares in the hash, so two options alike but for
that still name different schemas.

Scoped to options that carry an `$id`, which are the only ones
`withVariantId()` touches. The same case without one behaves as it does
on v7: `withVariantId()` is a no-op there, the assertion is merged in,
and wrapping cannot help, since the held option needs an `$id` to be a
reference target of its own. Worth an issue, not a fix here.

Narrower than the report suggests, in one way worth recording:
`findSchemaDefinition()` resolves a non-fragment `$ref` only under draft
2020-12, and even there threads no base URI from the option's `$id`, so
`$ref: ''` throws `Could not find a definition for .` out of
`retrieveSchema()`, `getClosestMatchingOption()` and `schemaParser()`
alike. That file is unchanged since the branch point but for type
annotations and a rename, so this holds on v7 too: such a schema cannot
drive a form or be precompiled, and only a direct
`getFirstMatchingOption()` call reaches the fixed path. The fix is still
right -- the assertion should not depend on where a validator happens to
resolve a reference -- and that gap wants its own issue.

The compilation docs now say that a compile succeeding with the
16-`patternProperties` warning throws `No precompiled validator function
was found for the given schema` at runtime for a key matching an
uncovered subset, so a successful compile is not a guarantee of complete
coverage. That was the review's second design observation.

Every new test fails against both realistic alternatives: reverting to
v7's shape fails the empty-data and precompiled cases, reverting to this
branch's previous shape fails the three recursion cases. No
`schemaParser()` snapshot changed. lint, knip, build, test and cs-check
green, 15 projects passing, `@rjsf/utils` at 100% coverage across
statements, branches, functions and lines.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* Fix 5338: name the patterns an over-limit warning is about

`logOnce()` keys by the message it is given, and the warning for an
object with more `patternProperties` than the combinations of them can
be enumerated for named only how many it had. Two objects over the
limit in one parse produced the same text, so the second was deduped
away and that object shipped an incomplete compiled set with nothing
said about it; a form rendering a key that matches an uncovered subset
then throws `No precompiled validator function was found for the given
schema` at runtime. One `compileSchemaValidators` run over several
schemas lost every warning after the first the same way. `logOnce()`'s
own contract asks for this: a message that has to be told apart from
another must say so itself.

The patterns are listed in the message, which makes the key distinct per
offending object. The cap and its warning move to a
`patternCombinationsOf()` that takes the `patternProperties` and leaves
`combinationsOf()` as the combinatorics alone.

Found by a review of the branch rather than from the form's behaviour,
so the test is the evidence: two over-limit objects in one parse warn
twice, each naming its own patterns, and it fails when the names are
dropped from the message. Coverage would not have caught this -- the
existing 17-pattern test already executes the line, so `@rjsf/utils`
stays at 100% either way.

lint, knip, build, test and cs-check green, 15 projects passing,
`@rjsf/utils` at 100% coverage across statements, branches, functions
and lines.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* Fix 5338: say where the scoring memos hit and where they miss

Review follow-ups: one discarded copy, and three comments that claimed
more than the code does.

`withVariantId()` destructured the `$id` out of the schema before the
guard that returns a schema carrying none, so every option without one
paid a shallow copy that was thrown away. It is read first and the
schema copied only past the guard. That runs per option on every change
to the form data, through `getClosestMatchingOption()` and through
`MultiSchemaField`'s check for an option a parent declined to switch
away from.

The memo comments said a large option is no longer serialized per
keystroke, without saying where that holds. Measured with both memos
instrumented, 40 calls over two 200-property options: scoring hits
157/160 and relaxing 78/80 for options given inline, and 80/160 and
0/80 for the same options behind a `$ref`. Both memos key by the object
the caller hands over, and `getClosestMatchingOption()` and
`omitExtraData()` resolve each option per call, where
`resolveAllReferences()` returns a new object whenever it resolves
anything. So an option that is a `$ref` is derived once per call, and
the scoring memo hits only within a call rather than across them. The
comments now say which path each memo is for and which it misses.

The 39-of-40 hit rate reported for the fifth round stands but was
narrower than the comments then drawn from it: it measured the options
`MultiSchemaField` scores, which `retrieveSchema()` answers from its own
cache, not the two call sites that resolve per call.

Keying the relaxed form by the option as declared rather than as
resolved would hit across calls, but the relaxation of a `$ref` depends
on the `rootSchema` it resolves against and that key would not carry it.
Memoizing `resolveAllReferences()` per schema and root is the fix, in a
path far wider than this change, so the comment records the reason
instead.

`MAX_COMBINED_PATTERN_PROPERTIES`'s comment had the ones past 16 taking
minutes and implied 16 itself was cheap. Measured over a schema whose
patterns hold one string property each: 12ms at 8, 168ms at 12, 754ms at
14, 3718ms at 16, doubling per pattern and scaling with the size of each
pattern's sub-schema on top of that. So 16 is already seconds and
minutes arrive several patterns later. The comment says the limit is
where the doubling is cut off rather than a point where the work is
still cheap. The constant is left where it is: lowering it changes which
combinations a precompiled validator covers, which is a coverage
tradeoff rather than a correction.

No behaviour change beyond the skipped copy. lint, knip, build, test and
cs-check green, 15 projects passing, `@rjsf/utils` at 100% coverage
across statements, branches, functions and lines.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* Fix 5338: score an option describing a map as it stands

An option such as `{ type: 'object', additionalProperties: { type: 'string' } }`
made the whole compile throw. Scoring reaches it after
`stubExistingAdditionalProperties()` has given it `properties: {}` for
the keys the data holds, and the guard here tested that key for
truthiness, which `{}` passes. The augmentation then became `anyOf: []`,
which is not a stricter schema but an unsatisfiable one, and AJV refuses
it: `schema is invalid: data/anyOf must NOT have fewer than 1 items`,
failing `compileSchemaValidatorsCode()` for the whole root schema. The
property names are counted now rather than tested for.

The quiet half is the worse one. The regular validator hit the same
invalid schema, logged a compile warning and answered `false`, so an
option describing a map never matched by validation at all -- a wrong
answer rather than a failure. The test covers both: that the compile
succeeds, and that the runtime validator matches the map option with no
warning logged.

Only the parse reached this, which is why it is new here: v7 scored the
declared options, which carry no `properties` key, where this branch
also scores the retrieved ones, and retrieval is what adds the stub.

Reported by jimmycallin. I confirmed the path by removing the retrieved-
option capture, which makes the same schema compile, so the guard is
what has to change rather than what reaches it.

A JSON-value schema -- a `oneOf` of string, number, array and an object
whose `additionalProperties` is a `$ref` back to it -- was reported as
failing the same way. It no longer fails that way, but it still fails,
with `can't resolve reference #/definitions/json from id <hash>`: a
`$ref` to the root's `definitions` from a sub-schema the parse keys by
its own hash. That is a separate pre-existing limitation, confirmed by
reverting this change, and it wants its own issue rather than a claim
here that the shape now compiles.

lint, knip, build, test and cs-check green, 15 projects passing,
`@rjsf/utils` at 100% coverage across statements, branches, functions
and lines.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* Fix 5338: leave a recursive key's pattern merge for the level that renders it

The fourth round stopped a stack overflow and introduced a silent wrong
answer in its place, which is the worse of the two.

Merging a property with the `patternProperties` matching its key
resolves the result, and for a key holding a `$ref` back to the schema
being merged that never terminates, so that reference seeds the
resolution and stops it. Stopping it leaves the `$ref` a literal, and
the merge then produces `{ $ref, ...the patterns' keywords }`. When the
level holding that key is rendered, `resolveAllReferences()` reads it as
`{ ...target, ...local }` -- a shallow spread -- so a `properties` the
pattern contributed replaces the referenced schema's own rather than
joining it. For

    node: {
      properties: { name: ..., child: { $ref: '#/definitions/node' } },
      patternProperties: { '^child$': { properties: { extra: ... } } },
    }

`retrieveSchema(child).properties` was `['extra']`: `name` and `child`
both gone, the recursion silently terminated, and the form rendering one
field where three belong. No error anywhere.

The merge is left undone for such a key instead, as
`{ allOf: [property, ...patterns] }`, for the level that renders it to
resolve with the `allOf` semantics it asks for. The recursion still
ends, because that resolves one level at a time rather than all of them
at once, and both levels now answer `['child', 'extra', 'name']`.

The merge runs again at every level that resolves its way back here --
once where the root's `$ref` is resolved and once at the top -- so the
second pass would add the patterns to the `allOf` the first pass left
and resolve that, losing the properties exactly as before. A key whose
patterns already stand in its `allOf` is recognised by content and left
alone. Both halves are load-bearing: reverting either one fails the
regression test.

Reported by jimmycallin, along with the fix. The test asserts the
resolved child's `properties` rather than that the resolution does not
throw, since "does not overflow" is precisely the assertion that let
this through.

A boolean property under a matching pattern reaches the two new
`isObject()` guards, and is a shape JSON Schema allows, so it is covered
too: `true` leaves the pattern's constraint and an unmatched `false` is
left as it stands.

lint, knip, build, test and cs-check green, 15 projects passing,
`@rjsf/utils` at 100% coverage across statements, branches, functions
and lines.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* Fix 5338: carry the resolved references down into the parse

A recursive schema declaring an `anyOf` or a `oneOf` on the recursive
node overflowed the stack in `schemaParser()`, where v7 parses it in
3 keys and no time at all:

    { $ref: '#/definitions/Node', definitions: { Node: {
        type: 'object',
        properties: { child: { $ref: '#/definitions/Node' } },
        anyOf: [{ required: ['a'] }, { required: ['b'] }] } } }

Each option `resolveAnyOrOneOfSchemas()` returns is the option merged
into the schema as resolution has left it, which is one `child` deeper
every round, and `parsed` and `resolved` are both keyed by content, so
nothing ever repeated and the descent ran until the stack did -- 44
seconds of it. The references resolved on the way to a schema travel
with it now, so one already on the path stays a literal rather than
being resolved a level further. Each value gets its own copy of the
list, since `resolveAllReferences()` merges what a value resolved back
into the list it was given and a shared one would read a sibling's
reference as this value's cycle.

Reported by jimmycallin, with the reproduction and both candidate
fixes. I took the second, having confirmed the first was not sufficient
on its own: removing the retrieved-option capture leaves the overflow
exactly where it was, so the growth is the re-resolution rather than
that capture.

The same threading fixes two shapes that overflow on v7 as well, as he
expected it would: recursion reached through a property's `items`
alongside a node-level `oneOf`, and a root that is an array of the node.
All of the shapes he listed now parse in 0ms, and no `schemaParser()`
snapshot changed, so nothing dropped out of a compiled map.

lint, knip, build, test and cs-check green, 15 projects passing,
`@rjsf/utils` at 100% coverage across statements, branches, functions
and lines.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* Fix 5338: expand each subset of an option's schema dependencies

An option with two or more schema `dependencies` threw as soon as the
user filled one of them in. Expanding returned the form with none of
them applied and the one with all of them, and nothing in between, but
a form applies a dependency once its key has a value, so data holding
some of the keys retrieves the option with only those applied and
`MultiSchemaField` scores that form. With a precompiled validator the
keystroke that filled the first key in threw `No precompiled validator
function was found for the given schema` out of the `useState`
initializer or the update effect, which takes the form down rather than
failing a field.

Each proper subset is expanded now. Only the dependencies holding a
schema are varied: one holding a list of names adds them to `required`,
which scoring drops, so it describes nothing a validator has to have
compiled, and leaving those out keeps the subsets to the keys that
matter.

There are `2 ** k` subsets, so this takes the same cap the
`patternProperties` combinations have, and the enumeration they already
used is now shared between them as `combinationsOf()`, as the report
suggested, rather than written twice. The cap is its own constant at 8,
since a dependency subset resolves the schema afresh where a pattern
combination only builds an `allOf`: measured over a schema whose
dependencies each add one property, 8 keys take 12ms. Past it each
dependency alone and all of them together are expanded, with a warning
naming the keys, and the docs say what a form between those loses.

Reported by jimmycallin, who asked for either this or an admission in
the changelog. The fourth round had measured why the obvious version is
not affordable -- applying dependencies per key is the product of the
two states, and 16 keys went from 1ms to 2147ms -- which is what the cap
is for.

Both new tests fail when the expansion is removed, and the two that fail
are exactly the two partial fills from the report. lint, knip, build,
test and cs-check green, 15 projects passing, `@rjsf/utils` at 100%
coverage across statements, branches, functions and lines.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* Fix 5338: condense this PR's changelog entries

The twelve entries had grown into commit messages: each fix added its
mechanism, its measurement and its reasoning to the bullet it belonged
to, over seven review rounds. They are 36% shorter and say what changed
and what it fixes, which is what a changelog is read for. The mechanism
and the measurements stay in the commits and the PR.

Kept deliberately: every API change (`withVariantId()`, `schemaKey()`,
`SchemaParserOptions`, `CompileValidatorOptionsType`), the error strings
a user would search for, the two caps and what a schema past them
loses, and the limitations that are still open.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* Fix 5338: keep a derived $id out of an empty trailing fragment

An option whose `$id` ends in `#` got the suffix appended inside the
fragment -- `http://e.com/a.json#` became
`http://e.com/a.json#?rjsf=1a92e9e3` -- and the 2019-09 and 2020-12
meta-schemas require an `$id` to match `^[^#]*#?$`, so ajv refused to
compile every variant of such an option, logged `Error encountered
compiling schema`, and the match fell back to the first option. Both
drafts allow the empty fragment and it is common in schemas carried
over from draft-04. It is dropped before the suffix is appended.

Draft-07, the default, accepts the suffixed `$id` in all three
validators, so this only reached users on the newer drafts, and the
precompiled path already failed there on v7 for the duplicate `$id`.

Deriving stays idempotent, which is what the suffix regex was added for
in round four: the variant suffix is stripped before the fragment, so
`a.json#`, `a.json` and `a.json?rjsf=<hash>` all derive from the same
base. `a.json#` and `a.json` holding the same content now derive the
same `$id`, which is right -- an empty fragment names the document --
and two schemas differing in content still differ in hash.

Reported by jimmycallin with the suggestion, which I took, after
checking the idempotence the ordering depends on rather than only that
his case passes. Covered for both dialects.

lint, knip, build, test and cs-check green, 15 projects passing,
`@rjsf/utils` at 100% coverage across statements, branches, functions
and lines.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* Fix 5338: read a schema's reference through one pair of accessors

`refOf()` and the two reads in `resolveUiSchema()` each spelled out
`(schema as RJSFMarkedSchema)[RJSF_REF_KEY]` alongside `schema[REF_KEY]`,
so the cast was written three times -- and the two sites disagreed on
which key wins, with nothing saying that was deliberate.

`declaredRef()` and `resolvedFromRef()` hold the cast now, and each
caller composes them in the order it needs. The orders stay different,
because they are answering different questions, and each now says so:
`refOf()` takes a reference the schema still holds first, since that is
the one about to be resolved and so the one a merge would follow round
again, while `resolveUiSchema()` takes the marker first, since it is
naming where a resolved schema came from -- the definition name a
`ui:definitions` entry is keyed by -- rather than what it is about to
resolve.

Reported by jimmycallin as a nit. Unifying the precedence, which the
report leaves open as an option, would break one of the two, so what is
shared is the cast and what is documented is the divergence.

No behaviour change. lint, knip, build, test and cs-check green, 15
projects passing, `@rjsf/utils` at 100% coverage across statements,
branches, functions and lines.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* Fix 5338: condense this PR's changelog entries again

The three fixes since the last pass each appended a sentence to the
bullet they belonged to, which is how these grew into commit messages
the first time. Half the size of where they started, and the same rule:
what changed and what it fixes, with the mechanism in the commits.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* Fix 5338: narrow what the scoring memo is claimed to do

The performance entry still said the schema an option is scored by is
derived once per option, which holds only for an option with nothing to
resolve. `getClosestMatchingOption()` and `omitExtraData()` resolve each
option per call, and `resolveAllReferences()` returns a new object
whenever it resolves anything, so an option holding a `$ref` is derived
once per call and the memo never hits across calls: measured, 0 of 80
for the relaxed form.

The code comments were narrowed in `d77bbb773` and this line should
have gone with them. It survived two passes over these entries since.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* Fix 5338: expand each dependency subset from the references as they stood

The subset expansion only worked for a dependency holding its schema
inline. A dependency that is a `$ref` came back as a literal `$ref` in
every partial subset, so the forms it was added to cover were still
missing and a form using them still threw `No precompiled validator
function was found for the given schema` on the keystroke that filled
the first dependency key in. Expanding

    dependencies: { a: { $ref: '#/definitions/DepA' },
                    b: { $ref: '#/definitions/DepB' } }

gave `[{a,b,a2,b2}, {a,b,$ref:DepA}, {a,b,$ref:DepB}, {a,b}]` where it
should give `[{a,b,a2,b2}, {a,b,a2}, {a,b,b2}, {a,b}]`.

`resolveAllReferences()` merges what a resolution went through back into
the list it was given, so the list `processDependencies()` is handed
comes back holding every `$ref` the all-applied form resolved. Each
subset was then expanded from that list and read its own dependency's
reference as a cycle. The list is snapshotted before any dependency is
applied, and each subset gets its own copy.

The same sharing ran one level further out, which the first fix for this
left in place: the snapshot sat inside the loop over the schemas the
options expand into, so the second branch of an option's own `oneOf`
started from a list the first branch had already added to and lost its
dependencies entirely -- `a,b,y` where `a,a2,b,y`, `a,b,b2,y` and
`a,a2,b,b2,y` belong. It is taken once, before the loop.

This is the trap from round four, which the comments there and here both
warn about, walked into twice. The test I wrote for the subsets used an
inline dependency, which is the shape that cannot show it; both new
tests use a `$ref`, and the second fails against a fix for only the
inner sharing.

Found by a review of the branch. lint, knip, build, test and cs-check
green, 15 projects passing, `@rjsf/utils` at 100% coverage across
statements, branches, functions and lines. The `schemaParser()`
snapshots are still insertions only, 301 lines and no deletions.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* Bump size limit for utils to 23kb

* Fix 5338: share what this PR's tests and reads had duplicated

The precompiled coverage cases were written twice, once per validator
package, differing only in how each loads the compiled code, and the two
copies had already drifted -- `it` against `test`, and one of them missing
a `createPrecompiledValidator` argument the other passed. They move to one
`precompiledCoverageTests()` that each package calls with its own loader,
so both provably cover the same eleven cases.

The same again, smaller, elsewhere: one recording validator in place of six
copies, the exported `identityMergeAllOf` in place of four local ones, and
one `mergeAllOfEntries()` behind the three hand-written `allOf` reduces. The
helper that claimed to merge "as the default does" says what it does instead,
since the default is `shallowAllOfMerge`, not RJSF's deep merge.

On the source side, nothing changes about what is computed. The third `$ref`
read in `resolveUiSchema()` goes through the accessors the other two already
used, which is what lets `REF_KEY`, `RJSF_REF_KEY` and `RJSFMarkedSchema`
leave that file. `refOf()` takes a schema that may be absent, so a property
is asked once whether it is an object rather than twice. The stub check moves
out of the per-branch loop, where it was re-derived from schemas that only
ever differ in their `properties`. `augmentedForScoring()` strips `required`
one way rather than two, dropping the `delete` that followed the destructure
already doing it. `combinationsOf()` stops being exported, since only the file
it lives in calls it and the package's wildcard export made it public.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* Fix 5338: carry the parse's references on v7's new resolution path stack

The rebase onto v7 brings in #5435, which replaced the visited-ref list
`resolveAllReferences()` kept with a path-scoped stack: entries are added
only for the refs being expanded on the current path, and are never
shared with siblings or merged back into the caller's list. Three of this
branch's changes were written against the merge-back and had to be
rewritten for the stack.

`parseSchema()` threaded a `recurseList` into `retrieveSchemaInternal()`
and read back what the resolution had added to it, which is how an option
a recursive node declares stopped being resolved a level deeper every
round. That list now comes back exactly as it went in, so the descent had
nothing to stop it again: the four `parses a recursive schema carrying
...` cases each ran for 26 to 80 seconds and then overflowed the stack.
What resolution expanded is read off the schema instead -- every subtree
it materializes is marked with its source ref as `RJSF_REF_KEY`, which is
the handle #5435 itself uses for the same question -- and that list seeds
the option resolution and the recursive parses. All four parse in 0ms
again, the file's 57 tests run in 399ms where they took 203 seconds, and
no `schemaParser()` snapshot moved.

`resolveDependencies()` and `retrieveSchemaInternal()`'s pattern merge
each copied their list for the same reason, which is now a no-op: the
copies are gone and the comments say what the remaining seed is for. One
test comment claimed the merge-back too.

The one textual conflict was in `resolveDependencies()`, where #5435 adds
`passCount` to the `processDependencies()` call this branch had wrapped.
Both sides kept.

#5435 also adds `does not flag a $ref shared by several oneOf branches
when expanding all branches`, which asserts two results. Expanding every
branch returns three here, since this branch also returns the schema with
the dependency unapplied -- what a form renders until the user picks a
protocol. Its point is unchanged and still asserted: the shared `$ref`
resolves in both branches.

lint, knip, build, test and cs-check green, 15 projects passing,
`@rjsf/utils` at 100% coverage across statements, branches, functions
and lines.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* Fix 5338: expand a dependency subset at the pass it belongs to

Two review fixes in `retrieveSchema.ts`.

`partiallyApplied()` was called without the `formData` and `passCount`
the `processDependencies()` call right above it forwards, so every
partial subset restarted the fixpoint loop at pass zero. That is the
pass at which `enclosingRefPath()` deliberately leaves the enclosing
`$ref` off the path, so a recursive `$ref` inside a dependency expanded
one level further under a subset than under the all-applied form, and
the `MAX_RESOLUTION_PASSES` backstop counted from zero again. Both are
threaded through now.

The guard that recognises a pattern merge an inner recursion level left
undone matched the pattern subschemas anywhere in the property's `allOf`,
where the shape that level leaves is the property followed by them. A key
declaring one of the patterns itself therefore read as already merged and
came back with its `allOf` unresolved:

    { type: 'object',
      properties: { foo: { allOf: [{ minLength: 2 }] } },
      patternProperties: { '^f': { minLength: 2 } } }

rendered `foo` from `{ allOf: [{ minLength: 2 }] }` rather than from
`{ minLength: 2 }`. The patterns are matched as the trailing run of the
`allOf` with at least one entry before them, which is that shape and not
this one, and a test covers the difference.

Two further findings were checked and not acted on. One reads the
`RJSF_REF_KEY` the `allOf` merge is said to drop from the merged schema,
which would cost `materializedRefs()` the enclosing reference: the
re-apply above it does only restore the subschemas' symbols, but
`shallowAllOfMerge()` carries the schema's own across, so the marker
survives and a recursive node carrying an `allOf` parses to the same
schemas as one without. The other is that `parseUnmergedAllOf()` and the
`dependencies` and `if`-branch loops parse from an empty `recurseList`.
They do, and it compiles variants a form has no use for, but threading
the path through narrows what the parse covers, and an uncompiled
sub-schema throws on the keystroke that reaches it where a spare one
costs only bundle size. Left as it is deliberately.

lint, knip, build, test and cs-check green, 15 projects passing,
`@rjsf/utils` at 100% coverage across statements, branches, functions
and lines.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* Fix 5338: stop a recursive key a pattern matches at the cycle it is

Sixth review round from jimmycallin. All six findings reproduce; four
were real bugs, two of them regressions this branch introduced.

**A recursive key its own `patternProperties` match rendered forever.**
Leaving that merge undone returns `{ allOf: [{ $ref }, ...patterns] }`,
and `SchemaField` stops a cycle only on a `RJSF_REF_CYCLE_KEY` it reads
off the schema itself, never inside an `allOf`. So the key rendered,
retrieving it left the same `allOf` a level down, and the form nested
until the heap was gone -- worse than v7, which threw a `RangeError` an
error boundary could catch. The undone merge carries the flag now, since
the key refers back to the schema holding it and only the `allOf` hides
that, and the key renders the `Expand Cycle` indicator a recursive `$ref`
renders. The existing tests only called `retrieveSchema()`; the
regression test renders a `Form`, and without the fix it takes the whole
vitest worker down with `SIGABRT`.

**An option declaring `properties: {}` matched every object.** Scoring it
as it stands is right for an option describing a map, which carries an
empty `properties` until `stubExistingAdditionalProperties()` fills one
in, but it also picked up the common "None" option in front of the real
ones: selecting "Some", typing into a field and clearing it snapped the
selector back to "None" and took the input away. Measured against v7, the
three cases he lists went 1,1,1 -> 0,0,0.

His suggested predicate needed one correction: v7 gates on the *presence*
of `properties`, not on its being non-empty, so an option that declares
none -- `{ type: 'string' }`, or one whose `allOf` resolves to a string --
was never augmented at all. Testing only `additionalProperties` and
`patternProperties` scored every non-object option as unmatchable; two
existing tests caught it. An option with no `properties` is scored as it
stands, an empty one describing keys elsewhere likewise, and an empty one
describing nothing is scored by `{ not: {} }` -- what the unsatisfiable
`anyOf` said, and what `normalizeBooleanSchema()` reads `false` as, while
being a schema a validator accepts rather than one that fails a whole
precompile. No snapshot moved.

**Recognising the undone merge by its shape was a guess**, as his
altitude comment says. Matching the patterns as the trailing run of the
property's `allOf` narrowed the false positive without removing it: his
`p: { allOf: [{ $ref: Base }, { maxLength: 5 }] }` against `'^p'` still
came back unresolved, with no recursion involved. The branch that leaves
the merge undone marks it instead, which also drops a `deepEquals` per
pattern per property from every resolution.

A review of that change found the marker could not be the cycle flag:
`resolveAllReferences()` sets that on any property whose `$ref` closes a
cycle, and the property carries it through the expansion of that `$ref`,
so a mutually recursive key read as already merged and lost its patterns
silently. A module-private marker carries "I left this" and the cycle
flag still carries "stop here", which were never the same statement.

**`materializedRefs()` walked the whole document per parse node** and
handed every child the union of every marker under the schema, so a
reference a sibling expanded counted as on this child's path --
undoing the per-subtree scoping `resolveAllReferences()` keeps. Each
child now gets the caller's path plus the schema's own marker. Like him,
I could not turn the leak into a missing key, and the speed is only
64.0 -> 59.4 ms at depth 6 and 144.7 -> 136.5 ms at depth 10: resolution
dominates, not the walk. The scoping is the reason to take it.

Two were documentation, both confirmed against v7 first: a key matching
an *option's* `patternProperties` still throws
`No precompiled validator function was found for the given schema`, at
his hash `-6f094989` and identically on v7, so the changelog names
`patternProperties` alongside `additionalProperties` as the gap left; and
the `variantId()` comment said what the bug was rather than what the rule
is.

Two more findings are v7's behaviour, not this branch's, so they stand:
an option with an empty `properties` constrained only by `minProperties`
never matched on v7 either, and `{ type: 'object' }` with no `properties`
key matches every object there too. Augmenting that spelling is what
broke the scalar options above.

Also verified and left alone: a recursive key whose `properties` and
matching `patternProperties` sit in the *same* `allOf` entry overflows
the stack in `retrieveSchema()` and `schemaParser()`, identically on v7
and on this branch. Any other arrangement of the two resolves. `ownRef`
comes back undefined there, so nothing seeds the merge -- the mechanism
of round five's finding 2, from a shape where the `allOf` costs the
marker. The changelog bullet claimed mutual recursion was the only
overflow left, so it now names this one too.

lint, knip, build and test across 15 projects, plus cs-check, all green,
`@rjsf/utils` 2420 tests at 100% coverage across statements, branches,
functions and lines.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* Fix 5338: count an option's patterns rather than testing for the key

Review of the previous commit. Three findings, both of the real ones in
code it added.

`describesKeysOutsideProperties()` tested `PATTERN_PROPERTIES_KEY in
option`, so an empty `patternProperties` counted as describing keys and
the option was scored as it stands. That is the takeover the
`MATCHES_NOTHING` branch was added to stop:
`{ type: 'object', properties: {}, patternProperties: {} }` in front of
the real options matched every object and took the data from them. The
patterns are counted now, the way the property names are counted on the
line above, since an empty `patternProperties` describes no key. An empty
schema under `additionalProperties` is left as describing keys, because it
describes every key the `properties` does not name.

The review skipped this on the grounds that it would disagree with
`hasAdditionalProperties` in `retrieveSchema.ts`, which tests for the key
the same way. That function asks whether there may be keys the
`properties` does not name, which is a different question, and counting
here agrees with this function's own neighbour rather than disagreeing
with that one.

Four `[...recurseList]` copies went, with the comments that justified
them. They claimed resolution appends to the path it is given, which it
does not: `resolveAllReferences()` extends the path into a new list, and
its `properties` loop hands every property the same one for that reason.
The copies allocated per parse node and per option on the parse path, and
the comments had been read as license to add more.

Left alone, with a baseline the review did not take: a precompiled miss
on an option carrying an `$id` reports the content hash of the scoring
wrapper rather than the option's `$id`, so `ParserValidator`'s "try
adding an `$id`" advice says nothing to someone whose option has one.
The shape does not compile at all on v7 -- `schema with key or id
"myOption" already exists`, the collision this PR fixes -- so this is a
thin message where there was no message, not a regression. Naming the
wrapper would move the compiled key set and the parser snapshots, which
wants deciding rather than patching.

lint, knip, build and test across 15 projects, plus cs-check, all green,
`@rjsf/utils` 2418 tests at 100% coverage across statements, branches,
functions and lines.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
x0k added a commit to x0k/svelte-jsonschema-form that referenced this pull request Oct 20, 2026
x0k added a commit to x0k/svelte-jsonschema-form that referenced this pull request Oct 20, 2026
x0k added a commit to x0k/svelte-jsonschema-form that referenced this pull request Oct 21, 2026
x0k added a commit to x0k/svelte-jsonschema-form that referenced this pull request Oct 21, 2026
x0k added a commit to x0k/svelte-jsonschema-form that referenced this pull request Nov 2, 2026
x0k added a commit to x0k/svelte-jsonschema-form that referenced this pull request Nov 2, 2026
x0k added a commit to x0k/svelte-jsonschema-form that referenced this pull request Nov 2, 2026
* [core] Scope $ref cycle detection to the resolution path

Port rjsf-team/react-jsonschema-form#5435

* [form] Document resolution API changes

* [core] Complete the $ref cycle scoping port

- Pass the walk-local expandedRefs collector from resolveReference so anyOf/oneOf options stay linear on shared-ref DAGs.
- Scope the expandAllBranches then/else resolutions to the enclosing ref path and reset their pass counter.
- Add the MAX_RESOLUTION_PASSES backstop, collapsing to the schema resolved so far instead of overflowing the stack.
- Add regression tests for the anyOf DAG, recursive conditional expansion and the pass limit.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

False-positive $ref cycle when several dependencies/oneOf branches $ref the same definition

2 participants