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

extraErrors continually getting merged into the internal state after calling mergeObjects with concatArrays true #3248

Closed
4 tasks done
dagda1 opened this issue Nov 15, 2022 · 1 comment
Labels
bug needs triage Initial label given, to be assigned correct labels and assigned

Comments

@dagda1
Copy link
Contributor

dagda1 commented Nov 15, 2022

Prerequisites

What theme are you using?

material-ui

Version

5.0.0-beta.12

Current Behavior

The extraErrors are continually merged into the <Form>'s internal state from the onChange handler.

I have narrowed it down to this line and this code:

      const errorSchema = extraErrors
        ? (mergeObjects(newErrorSchema, extraErrors, true) as ErrorSchema<T>)
        : newErrorSchema;

Here is a video of it happening

cccc.mp4

If I set the last argument of mergeObjects to false, then everything works as expected

const errorSchema = extraErrors ? mergeObjects(newErrorSchema, extraErrors, false) : newErrorSchema;

Setting it to false makes sense in my naive brain because of this line in mergeObjects

    } else if (concatArrays && Array.isArray(left) && Array.isArray(right)) {
      acc[key] = left.concat(right);

If newErrorSchema looks like this:

{{
    "repoOwner": {
        "__errors": [
            "Mandatory Field"
        ]
    }
}

And extraErrors looks like this:

{
    "repoName": {
        "__errors": [
            "Mandatory Field"
        ]
    },
    "repoOwner": {
        "__errors": [
            "Mandatory Field"
        ]
    }
}

Then the call to mergeObjects with the true third argument will produce this:

{
    "repoName": {
        "__errors": [
            "Mandatory Field"
        ]
    },
    "repoOwner": {
        "__errors": [
            "Mandatory Field",
            "Mandatory Field"
        ]
    }
}

And so on.

Should mergeObjects be called with false?

Expected Behavior

If the 3rd argument to mergeObjects is set to false:

mergeObjects(newErrorSchema, extraErrors, false)

Then it works as it should

bbbb.mp4

Steps To Reproduce

  1. Access this codesandbox
  2. click submit
  3. start typing in the last name field

Environment

- OS: osx monterry
- Node: v16.17.0
- npm: 8.19.

Anything else?

No response

@dagda1 dagda1 added bug needs triage Initial label given, to be assigned correct labels and assigned labels Nov 15, 2022
@dagda1 dagda1 changed the title <title> extraErrors continually getting merged into the internal state after calling mergeObjects with concatArrays true Nov 15, 2022
@heath-freenome
Copy link
Member

Duplicate of #3169

@heath-freenome heath-freenome marked this as a duplicate of #3169 Nov 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug needs triage Initial label given, to be assigned correct labels and assigned
Projects
None yet
Development

No branches or pull requests

2 participants