-
Notifications
You must be signed in to change notification settings - Fork 50.4k
Warn when passing invalid containers to render and unmountComponentAtNode #2065
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
Conversation
|
(Kind of related #1912) |
src/browser/ui/ReactMount.js
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style nit - break function call onto its own line, splitting the arg like this is awkward.
var containerHasNonRootReactChild =
ReactMount.hasNonRootReactChild(container);|
A bunch of nits without a proper review! I think it mostly makes sense though. I'll give it a closer look soon. |
|
@zpao Addressed, thanks. (Was curious about the use of parens in ReactMountDestruction-test.js. What's an example where ASI would behave badly? Does it have to do with |
|
http://inimino.org/~inimino/blog/javascript_semicolons is probably a good thing to read. In the case of actually returns ensures that an expression is started (via the opening paren) and gets evaluated. So that would return 4. of course returns 4 because it's on the same line. The other example in the file has everything on the same line, so that works. Other cases in JSX work as long as you start it on the return line, but we don't like the way that looks so we prefer the explicit opening paren. You can see that the opening paren on the return line means that this works. |
|
@crm416 I agree that the parens in ReactMountDestruction-test look unnecessary. |
|
Ah, I was looking at the wrong file. Yea, the ones in the preceding test in ReactMountDestruction-test are unnecessary. |
|
@zpao Thanks for the explanation--really helpful. Rather than just remove the parens, I put the components in the preceding tests on a single line. Let me know if you prefer a different style. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add a "If you intended to update the children of this node, you should instead have the component that rendered the existing children update its state and render the new components instead of calling the top-level React.render to update a subtree."
Also, s/renderComponent/render/. :)
|
Sorry for the long delay on this, @crm416. A few last inline comments, and then I think we'll be good to go. You'll also need to rebase for a clean merge – you'll at least need to change renderComponent to render; not sure if there's anything else. |
Warn when passing invalid containers to render and unmountComponentAtNode
|
Merged in 10ab0c8. |
Resolves #1858 and #2045.
The
hasNonRootReactChildmethod checks if the container has a React-rendered child (i.e., is non-empty) with a non-root ID, which is used as the criteria for warning in bothrenderComponentandunmountComponentAtNode. Note that there's also a specific warning for when you pass in a root node, rather than a container.For example, if your markup is:
Then you see the following warnings (prepended with method name,
warning, etc.):Or:
Or:
The naming here got a little verbose, so I'm open to suggestions. I think the specific warning for passing in a root node as a container is also worth discussing, but I left it in for now as it's easy to remove.