Repository navigation
Conversation
…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
|
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. |
mapStateToProps errors to console.error in dev (#1942)
|
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 "resolutions": {
"fflate": "0.8.2"
},This should unblock CI until the upstream issue is resolved. |
|
Thanks @aryaemami59 — totally missed your earlier comment, sorry about |
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 |
commit: |
mapStateToProps errors to console.error in dev (#1942)connect): log mapStateToProps errors to console.error in dev (#1942)
aryaemami59
left a comment
There was a problem hiding this comment.
Two small follow-ups on top of the dev-logging change:
- Name the component that threw — the message currently says "a
connect()-ed component", which isn't actionable.displayName(Connect(X)) is already computed in_connectand in scope at the call site, so threading it through is cheap and matches the existingmapStateToProps() in Connect(X) …style. - Make the test pin
NODE_ENV— it's titled "…in development" but never sets the env; it passes only because the runner isn'tproduction.
…or log Per review on reduxjs#1942: thread `displayName` into the dev console.error so it identifies which `connect()`-ed component threw, and harden the test to set NODE_ENV='development' explicitly and assert the component name is logged. Refs reduxjs#1942
…com/webdevelopersrinu/react-redux into fix/1942-log-mapstate-errors-in-dev
|
@aryaemami59 thanks for the review! Addressed all the feedback in 048188c:
Let me know if you'd like anything else. |
Co-authored-by: Arya Emami <[email protected]>
Co-authored-by: Arya Emami <[email protected]>
|
Thanks for the review @aryaemami59 |
|
Thanks! |
…r` in dev (reduxjs#1942) (reduxjs#2306)" This reverts commit b74ae3a.
Summary
Logs errors thrown in
mapStateToProps(or selectors) toconsole.errorin non-production environments, so they surface during development
instead of being silently swallowed.
Fixes #1942
Background
Since v8.0.0, errors thrown inside
mapStateToPropsare caught in thesubscription callback (connect.tsx#L133-L136) and stored in
lastThrownError. In v7, those errors surfaced because the componentunmounted on selector errors (the unmount path re-throws
lastThrownError). In v8+, the component no longer unmounts — it justre-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:
Changes
src/components/connect.tsx— log the caught error toconsole.errorwhen
process.env.NODE_ENV !== 'production', with a brief message anda link back to this issue
test/components/connect.spec.tsx— add a unit test that dispatchesan action which causes
mapStateToPropsto throw, then asserts theerror was logged via
console.errorBehavior
original error object, making it discoverable in DevTools
Test plan
yarn test— allconnecttests pass (65/65), new test passes,no regressions in code I touched
yarn lintruns as part ofpretestand passesvitest --typecheckreports no errors)