question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

connect swallows errors in mapStateToProps (new bug in 8.0.0)

See original GitHub issue

What version of React, ReactDOM/React Native, Redux, and React Redux are you using?

  • React: 18.2
  • ReactDOM/React Native: react-dom 18.2
  • Redux: 4.2.0
  • React Redux: 8.0.2

What is the current behavior?

https://codesandbox.io/s/gifted-architecture-wr4f86?file=/src/App.js

  1. Have a code that can cause an error in mapStateToProps, e.g.
const mapStateToProps = (state) => {
  return {
    foo: state.foo.length, // when foo is undefined, causes an error
  };
};
  1. Dispatch an action that changes the state so that it causes the error above
dispatch(updateFoo(undefined));
  1. Rerender doesn’t happen, no errors emitted in console, componentDidCatch catches nothing. The error is swallowed.

What is the expected behavior?

This issue makes debugging code that’s using react-redux really hard. The expected behaviour is that the error is visible in console. It worked fine in 7.2.8: https://codesandbox.io/s/charming-firefly-coekps image

Which browser and OS are affected by this issue?

Windows, latest Chrome here. Probably affects all browsers.

Did this work in previous versions of React Redux?

  • Yes

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
markeriksoncommented, Nov 3, 2022

@rdonnelly : afraid I don’t have the brain bandwidth to answer this one further atm. The logic in connect is frankly very fragile, doubly so in v8, and we’re not going to make further changes to it. I’d suggest trying out useSelector and see what happens.

1reaction
rdonnellycommented, Nov 3, 2022

I think we’re running into something similar in our application. When we hit an error in a selector, the exception seems to get gobbled up here:

https://github.com/reduxjs/react-redux/blob/8cf538c05b21433eba2106a6609c6ccbfce471de/src/components/connect.tsx#L131-L141

We were previously relying on that thrown error to bubble up and get caught by an error handler, but now our app won’t re-render and won’t show an error. I won’t claim that this is the best pattern (the application code is pretty old at this point), but is there any way to let that error pass through? Or if we did switch to useSelector syntax rather than connect, would that alleviate our issues?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Issues · reduxjs/react-redux - GitHub
Connect can still swallow errors ... connect swallows errors in mapStateToProps (new bug in 8.0.0) ... Connect HOC misses store changes when "offscreen"....
Read more >
redux-form: Versions - Openbase
5 years ago. Bug Fixes. Don't swallow async errors when form is not valid. #3300 #1367. Flow Fixes. Fixed action creator flow type...
Read more >
Redux react-redux Issues - Giters
Type error when use bindActionCreators with async thunk action · connect swallows errors in mapStateToProps (new bug in 8.0. · Docs: i18n ·...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found