-
-
Notifications
You must be signed in to change notification settings - Fork 19
fix: validator infinite loops #46
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
Merged
erikras
merged 2 commits into
final-form:master
from
christophehurpeau:fix/validator-infinite-loops
Jul 12, 2019
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
So, one thing I have just tested, if you keep the
validate
variable here, the problem will appear again, and that makes sense. So I tested removing it, and then just use:getValidator: () => validate
again and tests are green.So what is the benefit of using the
useRef
in this case? As far as I understand useRef is good for keeping variables accessible inside the component (for example the interval id), but if at the end we are updating the pointer on each render (because validate is different), at the end, we are getting same results, doing more coding, right?Unless I am wrong the real fix is remove
validate
not theuseRef
, thoughts?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.
If you only remove validate and if validate changes, it will be the first validate that always will be called, not the last changed. However I'm not sure if it's something that can happen often ?
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.
Interesting, what I have done in the same test you have just updated in this PR is:
And then, called:
And for each change, the random string is different, so, what do you mean by "the first validate that always be called"? I thought you mean the validate's reference was stored/memoized, because the
useEffect
's content was not updated (because validate was not included in the useEffect's array).But the previous snippet of code demonstrates my guess was not correct, and that makes sense, because normally when you change the input, the component where the
useField
lives is re-rendered, making the useEffect to be executed/updated again.So... what am I missing?
Thanks for being part of this conversation!
Uh oh!
There was an error while loading. Please reload this page.
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 think randomString should always be different because it is called when validator() is called, not when validator is created.
I haven't tested, but it should be something like:
useEffect is only called when name, form or subscription props changed (or on mount) and I think the point is to only register the field when this props changes :)
What do you think ? Thanks for this conversation too :)