-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
selector error hiding in connect.js subscribeUpdates #1985
Comments
This is a React-Redux question, not Redux Toolkit :) Moving this issue over there. Also, I'm confused because you're showing a usage of Can you attach a CodeSandbox showing an actual example of this happening? |
You are right I'm going to close this issue and I'll create a new one in react-redux
|
@jrodriguesimg : I did already move this issue - we're in the React-Redux repo now :) |
And yes, our own That's part of why I'm asking for an actual example of this failing. |
I used the counter example as a base: Code Sandbox. On this code sand box the components are all unmounted when an error is thrown, but on my app they are not being unmounted. What is causing the unmouting of the components in the Code Sandbox? |
@jrodriguesimg that's why I'm asking for you to show me an example of where this isn't working the way you expect. But also, the selector function you're passing in doesn't seem like it's going to actually do anything meaningful, because it's always going to create a new instance of that selector every time |
@markerikson thanks a lot for your help so far. On my application the components do not unmount when the selectors throw an error. That means that the selector function is always the same. So when I add
Something on my app must be interacting with the mechanism used by react redux to unmount the components. My app is complex, so it is hard to know what exactly is stoping that process. Do you what is the mechanism used by react-redux to cause the unmounting? Is it the |
@jrodriguesimg : I really need you to provide an example of the code that you're trying to run. It doesn't have to be a complete app, just a minimal example of "I expected this to fail, and it doesn't", or something along those lines. But it needs to be realistic (and the way you were defining the selector with the closure for the sandbox earlier isn't realistic). In general, React will unmount components if an error is thrown while rendering a component. If no error is thrown while rendering, then React just keeps rendering normally. But in order to see what's happening in your app, I need an example that shows me what your code is actually doing so I can understand it. |
@markerikson: It is hard for me to give you an example. It is a complex application. The best I can do is to make the exemple more realistic CodSanbox. The only way for me to be able to reproduce my issue in code sandbox would be for me to know what is causing the issue. My issue is that the error is being caught by react-redux, but for some reason my app does not error.
But the re-render does not happen on my app. Can you provide more details of how that re-render is triggered? I think in here you are talking about the re-render:
Probably my app is doing something unexpected, and stopping that re-render from happening. Edit: How is react-redux provoking the re-render from the call to useSelector? Is it some interaction with the that is mounted as parent of the application? Is the error caught by useSelector thrown somewhere else? Did I miss the documentation where that process is explained? |
Now I'm really confused. If I open up that sandbox, the React component tree does indeed crash because the selector is unconditionally throwing an error. This is exactly the behavior I would expect, and matches what I said above: if an error is thrown while rendering, React unmounts the component tree. So at this point I don't know what you're trying to show me, because it sounds like you're trying to describe a case where the error is throwing and React/React-Redux do not crash. Note that React-Redux does have different behavior between |
The sand box does not replicate my issue. |
The only thing I could think about here is that you see a discrepancy between the shim that React 16.8 and 17 ship with and the final |
@jrodriguesimg : In general, both If the error occurs again while rendering, that will force React to crash and unmount the UI. If the selector succeeds while rendering, then everything's fine. We've asked several times for examples that actually show us something similar to what you're seeing. We're not asking you to solve the issue, but to show us code that "fails" (doesn't behave the way you want/expect) so that we can explain why it does that. I'm going to close this due to lack of reproduction. As far as I can see everything's behaving as expected. |
When a selector throws an error after the first time it is called, the error is being hidden by redux toolkit.
Example:
The expected console output would be:
However the last line never shows. It will cause the component where the selector is used to not render as long as it errors.
I found out that the reason for this is that the error is caught and never thrown. I know it should be thrown in
unsubscribeWrapper
but it is not being called on my app.It makes it hard to debug errors. Specially when the app has many selectors and because sometimes it is unnoticeable that a bug was introduced. Is there any reason to hide errors here?
The text was updated successfully, but these errors were encountered: