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 <ReferenceInput> accepts a validate prop while it should not #9637

Merged
merged 1 commit into from Feb 9, 2024

Conversation

fzaninotto
Copy link
Member

Closes #9568

@@ -84,6 +84,11 @@ export const ReferenceInput = (props: ReferenceInputProps) => {
filter,
});

if (props.validate) {
Copy link
Contributor

Choose a reason for hiding this comment

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

We could also modify the ReferenceInputProps type:

extends Omit<InputProps, 'validate'>

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think that would be a better DX: Developers would see a failed compilation because of validate, without knowing what to do instead.

Choose a reason for hiding this comment

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

I would also suggest to remove the property from the type.

We just stumbled into a bug due to this change and it was not detected by our CI. We do not have tests of the edit form and only learnt about this through a bug report, because the types were still valid. However, when executing the code it is now throwing an error.

I think a type adjustment would be best to make this change visible, as it will break the application in any case:

image

Copy link
Contributor

Choose a reason for hiding this comment

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

If we change the type it will be a BC, right?
This two changes break something, so IMO we should update the types in V5 and revert this PR to put it in V5 too.

Copy link
Member Author

Choose a reason for hiding this comment

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

The bug in your code wasn't caused by this change, it was revealed by this change.

As explained, a type adjustments isn't a better DX IMO. Unless we add a "never" type and explain it with JSDoc?

Copy link

@digilist digilist Feb 28, 2024

Choose a reason for hiding this comment

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

Well, yes and no. You could say there was a bug, but defining the validation prop on the <ReferenceInput> did not have any effect and it was also defined on the <AutocompleteInput>. The validation was working and one validation prop was unnecessary, but that's not really a bug, is it? But now the application/page is crashing, which imho is more severe and I would call this a bug that was introduced by this change.

Copy link
Member Author

Choose a reason for hiding this comment

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

You're right. We shouldn't throw an error in production-only in development. I'll open a new PR to fix it. We won't introduce a type check until v5 though, as it is a breaking change.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done in #9690

Choose a reason for hiding this comment

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

Thank you 🎉

@slax57 slax57 added this to the 4.16.10 milestone Feb 9, 2024
@slax57 slax57 merged commit 19f982e into master Feb 9, 2024
11 checks passed
@slax57 slax57 deleted the referenceinput-validate branch February 9, 2024 14:50
fzaninotto added a commit that referenced this pull request Feb 29, 2024
## Problem

Since #9637, using `<ReferenceInput validate>` throws an error at runtime.

## Solution

Catch the problem at build time for TS users.
fzaninotto added a commit that referenced this pull request Feb 29, 2024
## Problem

Since #9637, using `<ReferenceInput validate>` fails at runtime. this is unexpected

## Solution

Fail at build time instead.

This may break existing apps, so I'm pulling against `next`.
fzaninotto added a commit that referenced this pull request Feb 29, 2024
## Problem

Since #9637, users see an error in production while the app isn't broken

## Solution

Only throw in development.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RFR Ready For Review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Using validate on ReferenceInput
5 participants