fix: honour explicit dependsOnOwnProps=false in getDependsOnOwnProps#2331
Open
JSap0914 wants to merge 1 commit into
Open
fix: honour explicit dependsOnOwnProps=false in getDependsOnOwnProps#2331JSap0914 wants to merge 1 commit into
dependsOnOwnProps=false in getDependsOnOwnProps#2331JSap0914 wants to merge 1 commit into
Conversation
getDependsOnOwnProps used a truthy check on `mapToProps.dependsOnOwnProps`, so an explicitly-set `false` fell through to the length-based heuristic and was silently overridden. A 2-arg mapToProps with `.dependsOnOwnProps = false` was therefore treated as depending on ownProps, causing unnecessary re-renders whenever parent props changed. Fix: check `!= null` instead so that `false` (and `true`) are both respected as intentional user signals, while `undefined` / `null` still falls back to the arity heuristic. Adds four unit tests covering all combinations.
commit: |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
getDependsOnOwnPropsinsrc/connect/wrapMapToProps.tsuses a truthy check to decide whether the caller has explicitly set thedependsOnOwnPropsflag:A truthy check treats
falsethe same asundefined, so an explicitly-setdependsOnOwnProps = falsefalls through to the length heuristic and is silently overridden.A concrete case: a
mapStateToPropsfunction with 2 parameters but.dependsOnOwnProps = falseset (to opt out of ownProps-triggered re-renders) ends up withdependsOnOwnProps = trueafter the proxy initialises, causing the component to re-runmapStateToPropson every parent prop change even though the author explicitly disabled that.Fix
Replace the truthy check with a
!= nullcheck so that bothfalseandtrueare treated as intentional signals, whileundefined/nullstill falls back to the arity heuristic:Tests
Four unit tests added in
test/connect/wrapMapToProps.spec.ts:truefalsefalse→ respectsfalse(was broken before this fix)true→ respectstrueAll 189 existing tests continue to pass unchanged.