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

fix: populate defaults for nested dependencies when formData is undefined #1313

Merged
merged 3 commits into from
Jun 8, 2019

Conversation

epicfaace
Copy link
Member

Reasons for making this change

Fixes #1311. It looks like the problem is that formData is not defaulted to {} when populating defaults for dependencies, so then when formData is undefined / null, it crashes.

Checklist

  • I'm updating documentation
  • I'm adding or updating code
    • I've added and/or updated tests
    • I've updated docs if needed
    • I've run npm run cs-format on my branch to conform my code to prettier coding style
  • I'm adding a new feature
    • I've updated the playground with an example use of the feature

@jrose-carecloud
Copy link

If formData is null this wont work as it wont default to the empty object

@epicfaace
Copy link
Member Author

@jrose-carecloud I added a test with null and it seems to work; was there something specifically that didn't work when you tried it?

@jrose-carecloud
Copy link

jrose-carecloud commented Jun 7, 2019

I'l admit that I didnt run the test, more of a just glancing sort of thing. But argument defaults only occur when the argument is undefined, not null.
Consider:

function foo(bar = {}) {
   console.log(bar);
}

If called like this:

foo();

We will log out {} as expected. But if called like this:

foo(null)

We will log out, null.

If null is not a possible/acceptable value to be received here then please disregard. I'm just keeping a close eye on this issue as its effecting our app at the moment.

IMO a safer approach would be:

function computeDefaults(schema, parentDefaults, definitions, rawFormData) {
  const formData = isObject(rawFormData) ? rawFormData : {}

@epicfaace
Copy link
Member Author

That's a good point, thanks. I don't think my null test accounted for that case, because it was still probably passing undefined down to the actual computeDefaults function. I'll fix this PR accordingly.

Copy link
Contributor

@glasserc glasserc left a comment

Choose a reason for hiding this comment

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

This feels kind of like a bandaid, but let's merge it so we can get a patch out.

@glasserc glasserc merged commit 8c81cc7 into master Jun 8, 2019
@glasserc glasserc deleted the fix/dependencies-formdata-undefined branch June 8, 2019 01:33
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.

Release 1.6.0 editor crashes when dependencies are used
3 participants