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

Avoid "no source" warning when theres a finalSource in useInput #10153

Conversation

GuilhermeCarra
Copy link

@GuilhermeCarra GuilhermeCarra commented Aug 20, 2024

Problem

Currently useInput is generating erroneous warnings when using ArrayInput with TextInput without source. The source is provided by useWrappedSource

        <ArrayInput source="users">
              <SimpleFormIterator>
                  <TextInput source="" />
              </SimpleFormIterator>
        </ArrayInput>

Solution

Change conditional check to finalSource

How To Test

Create an ArrayInput as indicated

Additional Checks

  • The PR targets master for a bugfix, or next for a feature
  • The PR includes unit tests (if not possible, describe why)
  • The PR includes one or several stories (if not possible, describe why) (N/A)
  • The documentation is up to date

Also, please make sure to read the contributing guidelines.

Comment on lines 51 to 55
if (
!source &&
!finalSource &&
props.label == null &&
process.env.NODE_ENV === 'development'
) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I agree we should change this condition, thanks for your report!

Actually I wonder if we should go even further. AFAICT this check was mainly added to make sure we won't call useController with an empty name (and also, to make TS happy).

So we should maybe replace it altogether by:

    if (
        !finalName &&
        process.env.NODE_ENV === 'development'
    ) { /* ... */ }

@fzaninotto wdyt?

Copy link
Member

Choose a reason for hiding this comment

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

You're right, an input with no source but with a name should not raise any warning!

Copy link
Author

@GuilhermeCarra GuilhermeCarra Aug 29, 2024

Choose a reason for hiding this comment

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

@slax57 @fzaninotto thanks for your feedback! Are you guys going to work on this? I saw the changes last week in useInput but I'm still getting the warnings which is making my application very slow when editing/creating
Thanks!

Copy link
Contributor

Choose a reason for hiding this comment

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

@GuilhermeCarra the changes you refer to are unrelated (you can have a look at the originating PR description to understand the context).

Regarding this PR, if you apply the changes I requested above we will be happy to merge it. Thanks!

Copy link
Author

Choose a reason for hiding this comment

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

@slax57 thanks! I've made the change 🙌

@fzaninotto fzaninotto merged commit ce5aa69 into marmelab:master Sep 2, 2024
13 checks passed
@fzaninotto
Copy link
Member

Thanks!

@fzaninotto fzaninotto added this to the 5.1.4 milestone Sep 2, 2024
@GuilhermeCarra GuilhermeCarra deleted the avoid-no-source-warning-when-theres-a-finalSource-in-useInput branch September 2, 2024 13:25
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.

3 participants