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 are merged into errorSchema again and again #3169

Closed
4 tasks done
krebbl opened this issue Oct 3, 2022 · 5 comments · Fixed by #3288
Closed
4 tasks done

ExtraErrors are merged into errorSchema again and again #3169

krebbl opened this issue Oct 3, 2022 · 5 comments · Fixed by #3288
Assignees
Labels
bug p1 Important to fix soon

Comments

@krebbl
Copy link

krebbl commented Oct 3, 2022

Prerequisites

What theme are you using?

core

Version

5.x Beta.10

Current Behavior

The passed extraErrors are rendered multiple times when typing into an input field.

Expected Behavior

The extraErrors should only be displayed once.

Steps To Reproduce

See example: https://codesandbox.io/s/vigilant-violet-8txkdr

Given the following Form config:

import validator from "@rjsf/validator-ajv6";
import Form from "@rjsf/core";

const schema = {
    "$schema": "http://json-schema.org/draft-07/schema#",
    "type": "object",
    "properties": {
        "email": {
            "type": "string",
            "format": "email"
        },
        "password": {
            "type": "string"
        },
        "passwordConfirmation": {
            "type": "string"
        }
    },
    "required": [
        "email",
        "password",
        "passwordConfirmation"
    ],
    "additionalProperties": false
}
...
<Form
   validator={validator}
   extraErrors={{email: {__errors: ["test"]}}}
   schema={schema}
   onSubmit={handleSubmit}
>

When typing something into the password field, the extra errors are appended in the UI again and again.

image

Environment

- OS: MaxOS
- Node: 16.7
- npm: 8.15

Anything else?

No response

@krebbl krebbl added bug needs triage Initial label given, to be assigned correct labels and assigned labels Oct 3, 2022
@krebbl
Copy link
Author

krebbl commented Oct 3, 2022

The issue seems to be caused by this line

? (mergeObjects(newErrorSchema, extraErrors, true) as ErrorSchema<T>)

Here the newErrorSchema is merged with the extraErrors but instead of replacing the field errors the extraErrors.email.__errors are appended everytime it runs.

@krebbl
Copy link
Author

krebbl commented Oct 5, 2022

I'm not able to reproduce this issue on the main branch, so it seems to be fixed there. Waiting for the next beta release now.

@heath-freenome heath-freenome self-assigned this Oct 5, 2022
@heath-freenome heath-freenome added p1 Important to fix soon and removed needs triage Initial label given, to be assigned correct labels and assigned labels Oct 6, 2022
@heath-freenome
Copy link
Collaborator

@krebbl Beta 11 has been out for a few days... give it a try

@krebbl
Copy link
Author

krebbl commented Oct 14, 2022

@heath-freenome Thanks for letting me! I just tried it in the linked code sandbox and the issue unfortunately still exists.

https://codesandbox.io/s/vigilant-violet-8txkdr?file=/package.json

@dagda1
Copy link
Contributor

dagda1 commented Nov 15, 2022

@heath-freenome I am hitting this also in beta.12

heath-freenome added a commit to heath-freenome/react-jsonschema-form that referenced this issue Dec 8, 2022
Fixed rjsf-team#3169 by merging `extraErrors` in while preventing duplicates
- Updated `@rjsf/utils` to make the `mergeObjects()` function support a `preventDuplicates` mode when concatenating arrays
  - Updated the tests to verify this new feature
- Updated `@rjsf/core` to use the `preventDuplicates` mode when merging `extraErrors` when not live validating
- Updated `validation.md` to remove extraneous leading space to fix rjsf-team#3282
- Updated `utility-functions.md` to document the new mode
- Updated `index.md` to provide the proper `core.cjs.production.min.js` package name for `unpkg.com` fixing rjsf-team#3262
- Updated the `CHANGELOG.md` accordingly
heath-freenome added a commit that referenced this issue Dec 9, 2022
* fix: Prevent duplicated extraErrors when not live validating
Fixed #3169 by merging `extraErrors` in while preventing duplicates
- Updated `@rjsf/utils` to make the `mergeObjects()` function support a `preventDuplicates` mode when concatenating arrays
  - Updated the tests to verify this new feature
- Updated `@rjsf/core` to use the `preventDuplicates` mode when merging `extraErrors` when not live validating
- Updated `validation.md` to remove extraneous leading space to fix #3282
- Updated `utility-functions.md` to document the new mode
- Updated `index.md` to provide the proper `core.cjs.production.min.js` package name for `unpkg.com` fixing #3262
- Updated the `CHANGELOG.md` accordingly

* - Responded to reviewer feedback

* - Fixed url for unpkg directory
shijistar pushed a commit to shijistar/react-jsonschema-form that referenced this issue Jun 8, 2023
…m#3288)

* fix: Prevent duplicated extraErrors when not live validating
Fixed rjsf-team#3169 by merging `extraErrors` in while preventing duplicates
- Updated `@rjsf/utils` to make the `mergeObjects()` function support a `preventDuplicates` mode when concatenating arrays
  - Updated the tests to verify this new feature
- Updated `@rjsf/core` to use the `preventDuplicates` mode when merging `extraErrors` when not live validating
- Updated `validation.md` to remove extraneous leading space to fix rjsf-team#3282
- Updated `utility-functions.md` to document the new mode
- Updated `index.md` to provide the proper `core.cjs.production.min.js` package name for `unpkg.com` fixing rjsf-team#3262
- Updated the `CHANGELOG.md` accordingly

* - Responded to reviewer feedback

* - Fixed url for unpkg directory
shijistar pushed a commit to shijistar/react-jsonschema-form that referenced this issue Jun 8, 2023
…m#3288)

* fix: Prevent duplicated extraErrors when not live validating
Fixed rjsf-team#3169 by merging `extraErrors` in while preventing duplicates
- Updated `@rjsf/utils` to make the `mergeObjects()` function support a `preventDuplicates` mode when concatenating arrays
  - Updated the tests to verify this new feature
- Updated `@rjsf/core` to use the `preventDuplicates` mode when merging `extraErrors` when not live validating
- Updated `validation.md` to remove extraneous leading space to fix rjsf-team#3282
- Updated `utility-functions.md` to document the new mode
- Updated `index.md` to provide the proper `core.cjs.production.min.js` package name for `unpkg.com` fixing rjsf-team#3262
- Updated the `CHANGELOG.md` accordingly

* - Responded to reviewer feedback

* - Fixed url for unpkg directory
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug p1 Important to fix soon
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants