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

issue: formState.isLoading always returns true #9934

Closed
1 task done
crashtech opened this issue Feb 14, 2023 · 14 comments
Closed
1 task done

issue: formState.isLoading always returns true #9934

crashtech opened this issue Feb 14, 2023 · 14 comments
Labels
question Further information is requested

Comments

@crashtech
Copy link

crashtech commented Feb 14, 2023

Version Number

7.43.1

Codesandbox/Expo snack

https://codesandbox.io/s/nice-gould-tzmvfo?file=/src/App.js

Steps to reproduce

  1. Just load the page
  2. Using FormProvider makes isLoading always return true
  3. Even trying to override using <FormProvider {...hook} formState={{ ...hook.formState, isLoading: false }}> doesn't work

Expected behaviour

The default value for isLoading should be false, especially if defaultValues hasn't been provided, or if it hasn't been assigned to a Promise.

What browsers are you seeing the problem on?

Chrome

Relevant log output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@Moshyfawn
Copy link
Member

Your sandbox link contains the default RHF template; no reproduction. Please update your sandbox with the reproduction code

@Moshyfawn Moshyfawn added the status: need more detail Please follow our issue template. label Feb 14, 2023
@crashtech
Copy link
Author

Done!

@Moshyfawn Moshyfawn removed the status: need more detail Please follow our issue template. label Feb 14, 2023
@Moshyfawn
Copy link
Member

Moshyfawn commented Feb 14, 2023

I'm a bit rusty with how the change to the formState due to the new async defaultvalues, but there's something going with how the default isLoading: true and it's never handled if defaultValues are not async.

@bluebill1049, I might need your help on this one 🤗

@bluebill1049
Copy link
Member

thanks @Moshyfawn i will look into this one.

@bluebill1049 bluebill1049 added the status: under investigation aware of this issue and pending for investigation label Feb 14, 2023
@bluebill1049
Copy link
Member

bluebill1049 commented Feb 14, 2023

@crashtech If you are not using async defaultValues, what's the use case for subscribing to isLoading?

@Moshyfawn
Copy link
Member

Moshyfawn commented Feb 14, 2023

@crashtech If you are not using async defaultValues, what's the use case for subscribing to isLoading?

That's a good question, actually. I guess, it feels like isSubmitting?

@bluebill1049
Copy link
Member

Yea, if you are providing static defaultValues, then you don't need isLoading, and we can save the extra byte in the lib to skip the logic check.

@crashtech
Copy link
Author

I'm connecting react hook forms with Semantic UI, so I'm forwarding this prop to the UI component. It should be consistent, regardless of using asynchronous default values.

Plus, a form here doesn't have default values, but select options are loaded asynchronously.

@Moshyfawn
Copy link
Member

Moshyfawn commented Feb 14, 2023

Plus, a form here doesn't have default values, but select options are loaded asynchronously.

Select options loading doesn't have anything to do with isLoading unless it's a part of defaultValues

@crashtech
Copy link
Author

crashtech commented Feb 14, 2023

Well, I assume "the form is loading if it can't be used yet". But regardless the reason, it should be undefined, or false at least.

The state is wrong, regardless of the motivation about using it.

The idea is to use the state to disable inputs while options are still loading.

@bluebill1049
Copy link
Member

I think this argument is going in a loop, the point is you don't need isLoading in the first place, whether we return the correct state for your UI or not is our responsibility. Yes, we can fix that, but you shouldn't use that in the first place. So I would suggest fixing your app logic first, while we patch this later on.

@bluebill1049
Copy link
Member

The idea is to use the state to disable inputs while options are still loading.

But you are not using async defaultValues, so the loading is not the valid usecase.

@bluebill1049 bluebill1049 added question Further information is requested and removed status: under investigation aware of this issue and pending for investigation labels Feb 14, 2023
@crashtech
Copy link
Author

crashtech commented Feb 14, 2023

So you should mention that is loading is a exclusive prop when using async default values. Or even rename it to make it clear that is not the form that is loading, is just the default values.

In order to add an external support to that, I would have to add an exclusive provider just so it can be captured down the tree.

Not even the override on the FormProvider works.

@bluebill1049
Copy link
Member

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants