Skip to content

fix: honour explicit dependsOnOwnProps=false in getDependsOnOwnProps#2331

Open
JSap0914 wants to merge 1 commit into
reduxjs:masterfrom
JSap0914:fix/getDependsOnOwnProps-explicit-false
Open

fix: honour explicit dependsOnOwnProps=false in getDependsOnOwnProps#2331
JSap0914 wants to merge 1 commit into
reduxjs:masterfrom
JSap0914:fix/getDependsOnOwnProps-explicit-false

Conversation

@JSap0914

Copy link
Copy Markdown

Problem

getDependsOnOwnProps in src/connect/wrapMapToProps.ts uses a truthy check to decide whether the caller has explicitly set the dependsOnOwnProps flag:

// before
function getDependsOnOwnProps(mapToProps: MapToProps) {
  return mapToProps.dependsOnOwnProps
    ? Boolean(mapToProps.dependsOnOwnProps)
    : mapToProps.length !== 1
}

A truthy check treats false the same as undefined, so an explicitly-set dependsOnOwnProps = false falls through to the length heuristic and is silently overridden.

A concrete case: a mapStateToProps function with 2 parameters but .dependsOnOwnProps = false set (to opt out of ownProps-triggered re-renders) ends up with dependsOnOwnProps = true after the proxy initialises, causing the component to re-run mapStateToProps on every parent prop change even though the author explicitly disabled that.

Fix

Replace the truthy check with a != null check so that both false and true are treated as intentional signals, while undefined/null still falls back to the arity heuristic:

// after
function getDependsOnOwnProps(mapToProps: MapToProps) {
  return mapToProps.dependsOnOwnProps != null
    ? Boolean(mapToProps.dependsOnOwnProps)
    : mapToProps.length !== 1
}

Tests

Four unit tests added in test/connect/wrapMapToProps.spec.ts:

  • arity-2 with no explicit flag → inferred true
  • arity-1 with no explicit flag → inferred false
  • arity-2 with explicit falserespects false (was broken before this fix)
  • arity-1 with explicit true → respects true

All 189 existing tests continue to pass unchanged.

AI-assisted contribution.

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.
Copilot AI review requested due to automatic review settings June 22, 2026 10:17

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@pkg-pr-new

pkg-pr-new Bot commented Jun 22, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/react-redux@2331 -D
yarn add https://pkg.pr.new/react-redux@2331.tgz -D
pnpm add https://pkg.pr.new/react-redux@2331.tgz -D
bun add https://pkg.pr.new/react-redux@2331.tgz -D

commit: d659a4b

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants