Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

🐛 FieldArray incorrect rerender #84

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

Closed
chengcyber wants to merge 1 commit into final-form:master from chengcyber:master

Conversation

Copy link

@chengcyber chengcyber commented Jun 3, 2019
edited
Loading

What

When validate is not given to FieldArray, it always returns undefined, which flush the error came from Field-level validation, and then Field-level revalidate to generate a "new" error. This leads to a double wasting rerender on FieldArray

Sementcially, if validate is not given, it should return the meta.error which respects field level validation.

Workaround

<FieldArray
 validate={(value, allValue, meta) => meta && meta.error}
/>

Copy link

codecov bot commented Jun 3, 2019

Codecov Report

Merging #84 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@ Coverage Diff @@
## master #84 +/- ##
=====================================
 Coverage 100% 100% 
=====================================
 Files 6 6 
 Lines 58 58 
 Branches 10 10 
=====================================
 Hits 58 58
Impacted Files Coverage Δ
src/useFieldArray.js 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 12d02f2...2b8aee8. Read the comment docs.

Copy link
Member

erikras commented Jun 3, 2019

Interesting. It'd be awesome to have a test that demonstrated the problem.

Copy link
Author

chengcyber commented Jun 4, 2019
edited
Loading

Hi, @erikras. I am doing optimization on the forms in our project, The thinking from final-form is awesome, but I found it is kind of hard to leverage React.memo to do a deeper optimization. i.e. the helper function in fields props of FieldArray is always different in each render time. That leads to another kind of wasting rerender.

For now, a workaround for the FieldArray is used to handle wasting rerender.

const MyComponent = React.memo(
 (props) => {
 return () // sth
 },
 (prevProps, nextProps) => {
 // all props are immutable, except fields and meta. shallowEqual is enough.
 const ret = shallowEqual(
 _omit(prevProps, ['fields', 'meta']),
 _omit(nextProps, ['fields', 'meta'])
 );
 if (!ret) {
 return false;
 }
 // value should be cared
 if (prevProps.fields.value !== nextProps.fields.value) {
 return false;
 }
 // all meta changes should be cared
 return deepEqual(prevProps.meta, nextProps.meta);
 }
)
<FieldArray>{props => <MyComponent {...props} />}</FieldArray>

Do you think immutability can be used inside final-form to target this kind of shallowEqual optimization?
And the helper function such as push, pop, etc. should be always the same, till name or other field props dependencies change.

Copy link
Author

chengcyber commented Jun 4, 2019
edited
Loading

Here is an example to demonstrate the wasting render

Edit 🏁 React Final Form - Field Arrays

log out meta.error right now. You can see when the error occurs, it comes to undefined, then [Object]

2019年06月04日 at 09 52

Copy link
Member

erikras commented Jun 14, 2019

@kimochg That sandbox link is not the right one.

Copy link
Author

correct link (updated at last comment as well)

Edit 🏁 React Final Form - Field Arrays

Copy link
Author

I found the change causes a bug, which is the error can not be cleared via array item validation,I decide to close this PR now.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 27, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Reviewers
No reviews
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /