-
Notifications
You must be signed in to change notification settings - Fork 670
Bug 1798871: Fix formik low priority validation issues #4266
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
Bug 1798871: Fix formik low priority validation issues #4266
Conversation
|
@rohitkrai03: This pull request references Bugzilla bug 1798871, which is valid. The bug has been moved to the POST state. The bug has been updated to refer to the pull request using the external bug tracker. DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
|
@rohitkrai03: This pull request references Bugzilla bug 1798871, which is valid. DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
|
/kind bug |
andrewballantyne
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a couple tiny things.
Question though @rohitkrai03 - #4087 caused this, right? We upgraded to this version to get away from another issue due to an upgrade. And that upgrade, I assume, upgraded rc versions to get away from some issue they didn't want. This is sorta snowballing, no?
What is the real cost of adopting a more stable version? Type issues? Can we override the types or find a TS work around? Doing hacks to make TS work is a lot more comfortable than making hacks to get the JS to work properly - as JS errors can come back to haunt us in the next release. Whereas if we hack TS, we can do proper upgrades / fixes to that in the future without worrying about back ports.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| export const useDeepCompareMemoize = (value) => { | |
| export const useDeepCompareMemoize<T = any> = (value: T): T => { |
That way it is clear whatever you're giving is being returned from this method. If they want to type it, they can.
I do see later that this is a move of code, but I'd still like this done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The above suggestion throws error saying parsing error. I think it should be somthing like
| export const useDeepCompareMemoize = (value) => { | |
| export const useDeepCompareMemoize = <T = any>(value: T): T => { |
But this has issues with type T not matching with ref.current. Not sure how to correctly type it this way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah sorry, I didn't test it to see the issue. I just made the comment.
React Hooks have generics built into them.
export const useDeepCompareMemoize = <T = any>(value: T): T => {
const ref = React.useRef<T>();
if (!_.isEqual(value, ref.current)) {
ref.current = value;
}
return ref.current;
};
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| export const useFormikValidationFix = (value) => { | |
| export const useFormikValidationFix = (value: any) => { |
Not a huge fan of this idea, but I would prefer an explicit any instead of an implicit any. We, far too often, forget types. So I'd prefer to see an explicit any rather than nothing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fix a temporary solution or a permanent one? Removing functionality like this for our interim hack may be undesirable. I suppose we could just revert this commit if Formik provides an actual solution to this issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've removed use of validateForm from here because it was not doing anything productive anyway. Even after calling validateForm, the validation was running on old stale data which was causing the validation errors. Plus, the custom hook that i've added calls this same method but on the change of data and not right after setFieldValue which is an async action.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't have an issue with the other spots this change happened, because you were using the power of hooks to apply additional functionality additively. This however is you replacing current functionality with this new hook.
Is this hook something we intend to keep using? Or are we only doing this because of typing issues in upgrading. I assume Formik is fixing their own issues and this is not an issue on the latest Formik version, and we are just unable to upgrade due to the dependency cascade issue in the React types.
My only concern here is that we will have to take care to bring back the functionality as it were once we upgrade. We lack the proper safety net (I believe) that comes with unit tests & integration tests to be certain we will be safe with changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Latest version of Formik also doesn't fix the issue, Formik team is still in the process of figuring out the solution. So, its not an issue that can be fixed by just upgrading to the latest Formik. And use of validateForm here was redundant and not needed here since every time we call setFieldValue or setFieldTouched, formik also runs the validation. So, once the problem in Formik gets resolved this will automatically start to work without the need of extra call to validateForm or the custom hook. Unless they hange something in the API which will need us to update the code in some way anyways.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I see - I read your comments from top-down on your PR. I apologize for my ignorance :)
@andrewballantyne This is not an issue introduced by #4087. This is something that got introduced in Formik 2.0.1-rc2 due to the use of |
fa4673b to
2b0c325
Compare
As long as we are not taking duct tape and wrapping it around our Formik implementation and calling it a real fix. If this is something that Formik is having issues with then we sorta have no choice - we cannot upgrade out of it. I just want whatever we do to be a sound solution and not something that will cause us endless back-ports and "critical" 11th hour fixes to make a release go out the door. |
2b0c325 to
8894567
Compare
andrewballantyne
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
Changes look good to me now. Thanks Rohit.
|
/approve |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: andrewballantyne, christianvogt, rohitkrai03 The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
/retest Please review the full test history for this PR and help us cut down flakes. |
4 similar comments
|
/retest Please review the full test history for this PR and help us cut down flakes. |
|
/retest Please review the full test history for this PR and help us cut down flakes. |
|
/retest Please review the full test history for this PR and help us cut down flakes. |
|
/retest Please review the full test history for this PR and help us cut down flakes. |
|
@rohitkrai03: All pull requests linked via external trackers have merged. Bugzilla bug 1798871 has been moved to the MODIFIED state. DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
Fixes -
This PR -
useDeepCompareMemoizehook to deeply compare values. Also, moves the hook intoconsole/sharedsetFieldValue.Screencast -
