-
Notifications
You must be signed in to change notification settings - Fork 47.7k
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 warning if rendering and HTMLUnknownElement #9163
Conversation
@@ -603,6 +608,20 @@ ReactDOMComponent.Mixin = { | |||
); | |||
didWarnShadyDOM = true; | |||
} | |||
|
|||
if (this._namespaceURI === DOMNamespaces.html) { | |||
if (__DEV__) { |
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.
This should be one line up, outside the namespace-check.
@@ -458,7 +462,7 @@ ReactDOMComponent.Mixin = { | |||
hostParent, | |||
hostContainerInfo, | |||
context | |||
) { | |||
) { |
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.
Need to trim trailing spaces in your file.
@@ -391,6 +391,10 @@ var VALID_TAG_REGEX = /^[a-zA-Z][a-zA-Z:_\.\-\d]*$/; // Simplified subset | |||
var validatedTagCache = {}; | |||
var hasOwnProperty = {}.hasOwnProperty; | |||
|
|||
// In IE8 We dont have HTMLUnknownElement - thus we use the equivalent HTMLGenericElement | |||
var HTMLUnknownElement = typeof window.HTMLGenericElement !== 'undefined' ? |
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.
I don't believe React actually supports IE8 in DEV anymore so this should be redundant then. Devs?
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.
Correct, we do not need to explicitly support IE8 anymore.
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.
Done
if (__DEV__) { | ||
if (this._namespaceURI === DOMNamespaces.html) { | ||
warning( | ||
!(document.createElement(this._tag) instanceof window.HTMLUnknownElement) || |
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 just use the element that was already created above (stored in the el
variable)?
If there's some reason we need to create another element here, we should use ownerDocument
instead of document
to create the element.
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.
Well, we cant really test SVG elements using HTMLUnknownElement
. Thus i will use ownerDocument
as you suggested (Edit: Please ignore this.)
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.
Using el
instead of creating the element again.
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.
@aweary This is done. Can you please take a look into it ?
Does JSDOM still return |
Yes it still behaves the same. All tests were failing which created a SVG element. |
if (this._namespaceURI === DOMNamespaces.html) { | ||
warning( | ||
!(ownerDocument.createElement(this._tag) instanceof window.HTMLUnknownElement) || | ||
isCustomComponent(this._tag, props) || voidElementTags[this._tag], |
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.
It's not apparent to me why checking against voidElementTags
makes sense here.
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.
This was added to handle specific scenario of menuitem
tag. The <menuitem></menuitem>
is supported only on firefox. In all other browsers the instanceof window.HTMLUnknownElement
would throw a false positive. menuitem
is included in voidElementsTags
array.
My idea was that since all items in voidElementTags
are known elements it would be safe to check if the to be rendered element is in that array or not - because that array is guaranteed to contain only valid elements.
Maybe i can add a descriptive comment about that or do you have any other solution in mind on how to handle menuitem
?
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.
Intuitively you either have a whitelist of all the currently known elements and the warning is then used to raise awareness that you have made a typo. Or you don't have a whitelist and the warning is used to indicate that you're rendering an element that isn't understood by the current browser.
There are many tags not supported by every browser, whitelisting just menuitem
(and self-closing tags) seems like an arbitrary in-between. IMHO you should pick one or the other (@aweary?).
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.
ok - totally agree - which means while using menuitem
in chrome we should get the error message as expected. Fine but for that i will have to make some changes in the unit tests concerning menuitem
to make them pass with this implementation.
I'm a little curious about the performance implications of this, there probably needs to be caching as-is. This PR effectively causes every element to be created twice, which makes me wonder why it doesn't just check the actual element |
Yes i agree - and understood now what you were saying about using the |
@@ -583,6 +584,20 @@ ReactDOMComponent.Mixin = { | |||
); | |||
didWarnShadyDOM = true; | |||
} | |||
|
|||
if (__DEV__) { | |||
if (this._namespaceURI === DOMNamespaces.html) { |
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.
I'm not sure we should add the warning if it's not consistent. Users could still mess up inside an svg
tag and they wouldn't get any warnings, which is extra confusing since they would get warnings anywhere else. @spicyj what do you think?
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.
I see @gaearon did mention previously he'd be OK with that
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.
I'm also okay with that, thanks for checking!
7910c19
to
0ee4ddc
Compare
Since menuitem is treated as an unknown element in jsdom it triggers the unknown element warning.
@spicyj @arshabh I went ahead and made a couple changes to get this going:
@aickin this breaks a few of your SSR integration tests related to non-standard elements. I wasn't sure how to address this with the abstractions in |
if (namespaceURI === HTML_NAMESPACE) { | ||
warning( | ||
isCustomComponentTag || | ||
!(domElement instanceof window.HTMLUnknownElement), |
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 avoid instanceof
checks here? They don't work across iframes.
It is more resilient.
I think this should be ready now, and server related issues seem gone. Let's wait for CI to pass and merge? |
Fixes 3726