Skip to content

fix(connect): log mapStateToProps errors to console.error in dev (#1942)#2306

Open
webdevelopersrinu wants to merge 1 commit into
reduxjs:masterfrom
webdevelopersrinu:fix/1942-log-mapstate-errors-in-dev
Open

fix(connect): log mapStateToProps errors to console.error in dev (#1942)#2306
webdevelopersrinu wants to merge 1 commit into
reduxjs:masterfrom
webdevelopersrinu:fix/1942-log-mapstate-errors-in-dev

Conversation

@webdevelopersrinu

Copy link
Copy Markdown

Summary

Logs errors thrown in mapStateToProps (or selectors) to console.error
in non-production environments, so they surface during development
instead of being silently swallowed.

Fixes #1942

Background

Since v8.0.0, errors thrown inside mapStateToProps are caught in the
subscription callback (connect.tsx#L133-L136) and stored in
lastThrownError. In v7, those errors surfaced because the component
unmounted on selector errors (the unmount path re-throws
lastThrownError). In v8+, the component no longer unmounts — it just
re-renders in its pre-error state — so the error is silently swallowed.

This was diagnosed by @alexanderchr in
#1942 (Dec 12, 2024), and @markerikson approved the dev-only
logging approach in the same thread:

"logging this in dev seems like a passable fallback"

Changes

  • src/components/connect.tsx — log the caught error to console.error
    when process.env.NODE_ENV !== 'production', with a brief message and
    a link back to this issue
  • test/components/connect.spec.tsx — add a unit test that dispatches
    an action which causes mapStateToProps to throw, then asserts the
    error was logged via console.error

Behavior

  • Production: unchanged (the new branch is dead-code-eliminated)
  • Development: error is now logged to the console with the
    original error object, making it discoverable in DevTools

Test plan

  • yarn test — all connect tests pass (65/65), new test passes,
    no regressions in code I touched
  • yarn lint runs as part of pretest and passes
  • Type-check passes (vitest --typecheck reports no errors)

…uxjs#1942)

Errors thrown inside mapStateToProps (or selectors) are caught in the
subscription callback at connect.tsx and stored in lastThrownError, but
since v8 the component no longer unmounts on selector errors so the
captured error is silently swallowed during development.

This adds a console.error log gated by process.env.NODE_ENV !== 'production'
so the error surfaces in dev tools, aiding debugging without changing any
production behavior.

Diagnosed by @alexanderchr on the issue thread; approach approved by
@markerikson in Dec 2024.

Fixes reduxjs#1942
@codesandbox-ci

Copy link
Copy Markdown

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

@aryaemami59 aryaemami59 changed the title fix(connect): log mapStateToProps errors to console.error in dev (#1942) fix(connect): log mapStateToProps errors to console.error in dev (#1942) May 20, 2026
@aryaemami59

aryaemami59 commented May 20, 2026

Copy link
Copy Markdown
Member

The current CI failure is related to arethetypeswrong/arethetypeswrong.github.io#258 which is caused by 101arrowz/fflate#258.

As a temporary workaround, we can pin fflate to 0.8.2 via resolutions in package.json:

  "resolutions": {
    "fflate": "0.8.2"
  },

This should unblock CI until the upstream issue is resolved.

@webdevelopersrinu

Copy link
Copy Markdown
Author

Thanks @aryaemami59 — totally missed your earlier comment, sorry about
that. Happy to add the fflate resolutions pin to this PR if you'd
prefer, or wait if you're patching master directly. Just let me know.

@aryaemami59

aryaemami59 commented May 21, 2026

Copy link
Copy Markdown
Member

@webdevelopersrinu

Thanks @aryaemami59 — totally missed your earlier comment, sorry about that. Happy to add the fflate resolutions pin to this PR if you'd prefer, or wait if you're patching master directly. Just let me know.

Thanks. I'd prefer to wait and see whether this gets resolved upstream first. That also gives the rest of the team more time to review the PR.

Update: This has since been fixed upstream in @arethetypeswrong/core@0.18.3, so the fflate resolutions pin isn't needed here. I've opened #2307 to bump @arethetypeswrong/cli to 0.18.3 and unblock CI.

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.

connect swallows errors in mapStateToProps (new bug in 8.0.0)

2 participants