Skip to content
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

Merged
merged 13 commits into from
Apr 14, 2017

Conversation

arshabh
Copy link
Contributor

@arshabh arshabh commented Mar 12, 2017

Fixes 3726

@@ -603,6 +608,20 @@ ReactDOMComponent.Mixin = {
);
didWarnShadyDOM = true;
}

if (this._namespaceURI === DOMNamespaces.html) {
if (__DEV__) {
Copy link
Contributor

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
) {
) {
Copy link
Contributor

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' ?
Copy link
Contributor

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?

Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

aweary
aweary previously requested changes Mar 16, 2017
if (__DEV__) {
if (this._namespaceURI === DOMNamespaces.html) {
warning(
!(document.createElement(this._tag) instanceof window.HTMLUnknownElement) ||
Copy link
Contributor

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.

Copy link
Contributor Author

@arshabh arshabh Mar 16, 2017

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.)

Copy link
Contributor Author

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.

Copy link
Contributor Author

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 ?

@aweary
Copy link
Contributor

aweary commented Mar 16, 2017

Does JSDOM still return HTMLUnknownElement for elements it does not support yet (ref)?

@arshabh
Copy link
Contributor Author

arshabh commented Mar 16, 2017

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],
Copy link
Contributor

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.

Copy link
Contributor Author

@arshabh arshabh Mar 16, 2017

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 ?

Copy link
Contributor

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?).

Copy link
Contributor Author

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.

@syranide
Copy link
Contributor

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 el already created inside the same function just above?

@arshabh
Copy link
Contributor Author

arshabh commented Mar 16, 2017

Yes i agree - and understood now what you were saying about using the el. But i will check that only in the condition when there is html namespace - as svg elements cannot be tested

@aweary aweary self-assigned this Mar 24, 2017
@@ -583,6 +584,20 @@ ReactDOMComponent.Mixin = {
);
didWarnShadyDOM = true;
}

if (__DEV__) {
if (this._namespaceURI === DOMNamespaces.html) {
Copy link
Contributor

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?

Copy link
Contributor

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

Copy link
Collaborator

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!

@aweary aweary force-pushed the issue-3726 branch 2 times, most recently from 7910c19 to 0ee4ddc Compare April 9, 2017 20:09
Brandon Dail added 2 commits April 9, 2017 16:05
Since menuitem is treated as an unknown element in jsdom it triggers the unknown element warning.
@aweary
Copy link
Contributor

aweary commented Apr 9, 2017

@spicyj @arshabh I went ahead and made a couple changes to get this going:

  • Fix a spacing issue in the warning
  • Reduce the number of times we call isCustomComponent
  • Add the warning to Fiber
  • "Fix" a test that uses menuitem, which is considered an instance of HTMLUnkownElement

@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 ReactDOMServerIntegrations so hopefully we can look at that together.

if (namespaceURI === HTML_NAMESPACE) {
warning(
isCustomComponentTag ||
!(domElement instanceof window.HTMLUnknownElement),
Copy link
Collaborator

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.

@gaearon gaearon dismissed aweary’s stale review April 14, 2017 01:13

outdated review

@gaearon
Copy link
Collaborator

gaearon commented Apr 14, 2017

I think this should be ready now, and server related issues seem gone. Let's wait for CI to pass and merge?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants