connect swallows errors in mapStateToProps (new bug in 8.0.0)
See original GitHub issueWhat 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
- 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
};
};
- Dispatch an action that changes the state so that it causes the error above
dispatch(updateFoo(undefined));
- 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
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:
- Created a year ago
- Comments:8 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@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 outuseSelector
and see what happens.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 thanconnect
, would that alleviate our issues?