-
Notifications
You must be signed in to change notification settings - Fork 47.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
Add better guard for nested renderings. #2277
Comments
Your code follows bad practices, first try declaring the initial state. Second, you don't need to re-render the component like this. Changing the state will re-render and you are doing it twice. Only render once initially... and your function to do that does nothing with the name parameter. Try looking at more examples to write better code. |
@cigzigwon thanks but I know it is bad practice. This is not the question. We have an internal framework heavily inspired by Om's concepts, which maintains all state outside of React and always rerenders from the top, injecting a global application state. You can read more here: http://stackoverflow.com/questions/25791034/om-but-in-javascript/25806145 This JsFiddle is just an oversimplification of the problem. Actually what happened in our application is that someone triggered an application event during the render phase. And this event triggered itself a render inside the render. From the beginning I suspected someone did something like that. That's not the point of this issue. In my case, I had to put a breakpoint on the React's warning statement to be able to find the appropriate stack entry and the concerned component. It would be easier to have an error instead of a warning, and to put the displayName of the component in the error. Anyway the warning is not appropriate because anyway there is another error that happens a little bit later with an obscure error message. It would be better to fail fast consistently in both exposed cases. |
Ok, I get the gist of what you are saying, someone else also wanted some sort of protection from the infinite loop mistake. But yes, I'm referring to standalone React. I have successfully used other libs internally to react and it works great. Sounds like an issue that code review/pair programming techniques can solve within your organization. |
I verified we now print sensible messages in both cases. They lack deduplication but I filed #11081 for this. |
This issue demonstrate the problem I had:
http://jsfiddle.net/kb3gN/6069/
As you can see, both cases are not handled the same way.
VS
Actually I encountered the 1st case, and it was quite difficult to see where the problem was in my real life application because there was only a warning, and the message were not very helpful. Is it possible to handle this consistantly or at least include the component name if available?
The text was updated successfully, but these errors were encountered: