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

Fields re-render every time due to regression introduced with flow typings. #3758

Merged
merged 3 commits into from
Jan 18, 2018
Merged

Conversation

dagstuan
Copy link
Contributor

This PR fixes a regression introduced in #3138 where the shouldComponentUpdate method of createField.js no longer sent nextState as an argument to shallowCompare when checking if a component should update. This regression effectively made every field re-render every time since the default state of a react component is null and an unspecified argument is undefined, making shallowCompare do a null === undefined check to determine if the component should update.

… when determining if a Field should re-render
Copy link
Collaborator

@gustavohenke gustavohenke left a comment

Choose a reason for hiding this comment

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

Can we also have a test for this?

const propsEqual = isEqualWith(instance.props, nextProps, customizer)
const stateEqual = isEqualWith(instance.state, nextState, customizer)

return !propsEqual || !stateEqual
Copy link
Collaborator

Choose a reason for hiding this comment

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

I like how readable this function is now 💯

@dagstuan
Copy link
Contributor Author

@erikras is there any way to retry travis-ci? I dont really understand why it failed, since there seems to be no logs :)

@dagstuan
Copy link
Contributor Author

dagstuan commented Jan 17, 2018

@gustavohenke I attempted for a while to write a test for it. But for some reason the actual component specified to the <Field /> does not re-render, probably due to smart react-diffing or something. However, the render()-function of the <Field /> runs every time the form changes.

The test I wrote to check if is basically equal to https://github.com/erikras/redux-form/blob/878176b0e960d58a3277a2bd83703e8da3e82eb6/src/__tests__/Field.spec.js#L874 however I could not make the input-function render twice.

…ed multiple times if neither state nor props have changed
@dagstuan
Copy link
Contributor Author

@gustavohenke I figured out a way :) Had to make a sub-class of the Field-class to check it though, so the test is kind of hacky. If you know of any other way of testing this please let me know :)

@codecov-io
Copy link

codecov-io commented Jan 17, 2018

Codecov Report

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

Impacted file tree graph

@@          Coverage Diff           @@
##           master   #3758   +/-   ##
======================================
  Coverage     100%    100%           
======================================
  Files          70      70           
  Lines        1587    1589    +2     
======================================
+ Hits         1587    1589    +2
Impacted Files Coverage Δ
src/createField.js 100% <100%> (ø) ⬆️
src/util/shallowCompare.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 878176b...ee53455. Read the comment docs.

@erikras erikras merged commit 945cf37 into redux-form:master Jan 18, 2018
@erikras
Copy link
Member

erikras commented Jan 18, 2018

Published in v7.2.1.

@lock
Copy link

lock bot commented Jun 1, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 1, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants