-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Rule proposal: prevent some DOM elements from having children or dangerouslySetInnerHTML #709
Comments
This seems like an excellent idea, and one that's mostly enforceable with both jsx and |
Yeah, I think the 99% solution is great. |
What should this be called? |
Since it's just for DOM elements, what about |
I thought about that, but I think self-closing may refer to elements that are also able to accept children but happen to be rendered without children, such as |
In that case, maybe |
That works for me! |
There are some HTML elements that are only self-closing (e.g. `img`, `br`, `hr`). These are collectively known as void DOM elements. If you try to give these children, React will give you a warning like: > Invariant Violation: img is a void element tag and must neither have > `children` nor use `dangerouslySetInnerHTML`. This rule prevents this from happening. Since this is already a warning in React, we should add it to the recommended configuration in our next major release. Fixes #709
why is |
@kepi0809 because |
@ljharb https://developer.mozilla.org/en-US/docs/Web/HTML/Element/wbr it's not? |
@kepi0809 HTML5 permits self-closing elements to omit the closing slash; anything is a self-closing element if it can not contain children. See "Tag omission" on that page. |
There are some HTML elements that are normally self-closing (e.g.
img
,br
,hr
). If you try to give these children, React will give you a warning likeIt would be nice to have a rule enforcing this.
Bad:
Good:
The full list that React uses can be found:
Which comes out as:
area
base
br
col
embed
hr
img
input
keygen
link
menuitem
meta
param
source
track
wbr
The text was updated successfully, but these errors were encountered: