Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Infinite $ref recursive error via computeDefaults #1160

Closed
3 tasks done
dok opened this issue Jan 30, 2019 · 4 comments · May be fixed by domharrington/react-jsonschema-form#1
Closed
3 tasks done

Infinite $ref recursive error via computeDefaults #1160

dok opened this issue Jan 30, 2019 · 4 comments · May be fixed by domharrington/react-jsonschema-form#1

Comments

@dok
Copy link

dok commented Jan 30, 2019

Prerequisites

Description

I'm able to consistently reproduce a maximum callstack error. Here is an image of the error.

screen shot 2019-01-30 at 10 55 21 am

I believe this is due to the utils.computeDefaults method, that recursively follows a $ref.

Steps to Reproduce

Copy and paste these snippets into their respective input fields in the playground.

JSONSchema

{
  "definitions": {
    "node": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string"
        },
        "children": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/node"
          }
        },
        "otherNode": {
          "$ref": "#/definitions/node"
        }
      }
    }
  },
  "type": "object",
  "properties": {
    "tree": {
      "title": "Recursive references",
      "$ref": "#/definitions/node"
    }
  }
}

UISchema

{
  "ui:order": [
    "tree"
  ]
}

FormData

{
  "billing_address": {
    "city": "Babel",
    "state": "Neverland"
  },
  "shipping_address": {
    "street_address": "221B, Baker Street",
    "city": "London",
    "state": "N/A"
  },
  "tree": {
    "name": "root",
    "children": []
  }
}

Expected behavior

I'm not sure what the expected behavior for this type of behavior is. Since the $ref object does not have a .default property, should it exit out of the recursive loop?

Actual behavior

Uncaught RangeError: Maximum call stack size exceeded
    at RegExp.exec (<anonymous>)
    at findSchemaDefinition (utils.js:489)
    at computeDefaults (utils.js:228)
    at utils.js:246
    at Array.reduce (<anonymous>)
    at computeDefaults (utils.js:243)
    at computeDefaults (utils.js:229)
    at utils.js:246
    at Array.reduce (<anonymous>)
    at computeDefaults (utils.js:243)

Version

1.2.0

@glasserc
Copy link
Contributor

glasserc commented Feb 4, 2019

This is an old weakness in rjsf. See #557 and #820. In principle it isn't necessary to instantiate the entire schema, but we do at the moment.

@dok
Copy link
Author

dok commented Feb 5, 2019

Thanks for the response @glasserc. Do you see a resolution to #557 anytime in the near future? Would it be possible to scope the issue down to a more manageable task and just focus on the circular reference within computeDefaults?

I'd be happy to help with this if you had a solution in mind!

@crubier
Copy link

crubier commented Aug 19, 2019

Gigantic blocker for me.

miscounting pushed a commit to miscounting/RewardBotJ that referenced this issue Jul 12, 2020
Due to rjsf-team/react-jsonschema-form#1160 there's some problem with recursive schemas.  Created a subtype of Action called AfterAction which (according to the schema) cannot have a timeout field, which allows the form to render.
@stale
Copy link

stale bot commented Apr 15, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Please leave a comment if this is still an issue for you. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants