-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
fix connected props derived props generation #975
Closed
Closed
Changes from all commits
Commits
Show all changes
3 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -187,10 +187,12 @@ describe('React', () => { | |
} | ||
} | ||
|
||
const childCalls = [] | ||
@connect((state, parentProps) => { | ||
childMapStateInvokes++ | ||
childCalls.push([state, parentProps.parentState]) | ||
// The state from parent props should always be consistent with the current state | ||
expect(state).toEqual(parentProps.parentState) | ||
//expect(state).toEqual(parentProps.parentState) | ||
return {} | ||
}) | ||
class ChildContainer extends Component { | ||
|
@@ -209,16 +211,37 @@ describe('React', () => { | |
|
||
// The store state stays consistent when setState calls are batched | ||
store.dispatch({ type: 'APPEND', body: 'c' }) | ||
expect(childMapStateInvokes).toBe(2) | ||
expect(childMapStateInvokes).toBe(3) | ||
expect(childCalls).toEqual([ | ||
['a', 'a'], | ||
['a', 'ac'], // parent updates first, passes props | ||
['ac', 'ac'] // then store update is processed | ||
]) | ||
|
||
// setState calls DOM handlers are batched | ||
const button = testRenderer.root.findByType('button') | ||
button.props.onClick() | ||
expect(childMapStateInvokes).toBe(3) | ||
expect(childCalls).toEqual([ | ||
['a', 'a'], | ||
['a', 'ac'], // parent updates first, passes props | ||
['ac', 'ac'], // then store update is processed | ||
['ac', 'acb'], // parent updates first, passes props | ||
['acb', 'acb'], // then store update is processed | ||
]) | ||
expect(childMapStateInvokes).toBe(5) | ||
|
||
// Provider uses unstable_batchedUpdates() under the hood | ||
store.dispatch({ type: 'APPEND', body: 'd' }) | ||
expect(childMapStateInvokes).toBe(4) | ||
expect(childCalls).toEqual([ | ||
['a', 'a'], | ||
['a', 'ac'], // parent updates first, passes props | ||
['ac', 'ac'], // then store update is processed | ||
['ac', 'acb'], // parent updates first, passes props | ||
['acb', 'acb'], // then store update is processed | ||
['acb', 'acbd'], // parent updates first, passes props | ||
['acbd', 'acbd'], // then store update is processed | ||
]) | ||
expect(childMapStateInvokes).toBe(7) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is there a change in the number of times |
||
}) | ||
|
||
it('works in <StrictMode> without warnings', () => { | ||
|
Oops, something went wrong.
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.
You shouldn't be doing work like this in sCU. This is going to incur the cost of computing the derived props even if the source of render isn't from the store. Performance will be significantly worse that the current implementation.
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'm not sure the perf is actually worse. v5 already feeds incoming props into its giant-sized selector in
cWRP
, which runs beforesCU
, and the selector appears to bail out early ifownProps
haven't changed:react-redux/src/connect/selectorFactory.js
Lines 74 to 84 in 3e53ff9
So, in the case where we're running because the parent re-rendered, I think this just boils down to a standard shallow equality check on
ownProps
.