Skip to content

Generate reasonable markup even if tags have unexpected case. - #4188

Merged
jimfb merged 1 commit into
react:masterfrom
jisaacks:master
Jun 23, 2015
Merged

jimfb merged 1 commit into
react:masterfrom
jisaacks:master

Conversation

@jisaacks

Copy link
Copy Markdown
Contributor

Fixes #2756

@sophiebits

Copy link
Copy Markdown
Collaborator
  1. This should use the warning module, not a call to console.error.
  2. This shouldn't warn more than once per tag. Probably easiest to combine with validateDangerousTag (rename to just validateTagName) and take advantage of validatedTagCache.
  3. SVG tags like fontFace start with a lowercase letter and are valid. Let's only warn when the first letter is uppercase. Let's use the message: "DOM tag names should be lowercase but got: %s.".

When you're done, can you squash your commits?

@jisaacks

Copy link
Copy Markdown
Contributor Author

@spicyj I think that covers everything. Let me know if there is anything else :)

@sebmarkbage

Copy link
Copy Markdown
Contributor

I'm not sure this is the right solution. The HTML DOM allows case insensitive definitions and it might even be encouraged to use capitalization for certain custom elements.

Shouldn't we just make our omittedCloseTags check case-insensitive?

@jisaacks

Copy link
Copy Markdown
Contributor Author

@sebmarkbage while that would fix the actual bug, I think it would be confusing to users, that DIV, UL, A etc.. are all valid but BR, IMG, etc.. are not.

What would the error message say? Self closing elements must be lowercase!

...it might even be encouraged to use capitalization for certain custom elements.

Are custom elements even supported by React? I thought it was just these dom nodes

If so, maybe allow the different cases but downcase the tag name when checking it here and here. Or only check case sensitivity on the dom nodes defined in the linked above.

Either way, enforcing strict casing on a subset of the DOM, because of a bug feels wrong.

@sebmarkbage

Copy link
Copy Markdown
Contributor

I didn't mean that we should enforce a strict casing on a subset. We should not enforce it on anything.

I.e. downcase here https://github.com/facebook/react/blob/master/src/renderers/dom/shared/ReactDOMComponent.js#L533

@jisaacks

Copy link
Copy Markdown
Contributor Author

@sebmarkbage got it. Should I make that change now, or does @spicyj need to sign off? Just not sure how the process here works, and don't want to waste effort. Thanks!

@jimfb

jimfb commented Jun 23, 2015

Copy link
Copy Markdown
Contributor

@sebmarkbage is the ultimate authority; a go-ahead from him is generally enough to do anything :).

I'm fairly certain that @spicyj won't object to this proposed solution.

Go ahead and make the change :).

@sophiebits

Copy link
Copy Markdown
Collaborator

No objections here.

@sophiebits

Copy link
Copy Markdown
Collaborator

@sebmarkbage doesn't always win!

@jimfb

jimfb commented Jun 23, 2015

Copy link
Copy Markdown
Contributor

Haha, true, but he has a pretty good track record :P.

@sebmarkbage

Copy link
Copy Markdown
Contributor

$40 says I don't always win.

@jimfb

jimfb commented Jun 23, 2015

Copy link
Copy Markdown
Contributor

That's true too. // Note to self: never bet against @spicyj.

@sebmarkbage

Copy link
Copy Markdown
Contributor

I'm always right because I change my mind. Doesn't mean you should listen to my initial inclination. Unlike American politics I think we should value new input. :)

@jisaacks
jisaacks force-pushed the master branch 2 times, most recently from 54ccc22 to 43a4d77 Compare June 23, 2015 19:58
@jimfb

jimfb commented Jun 23, 2015

Copy link
Copy Markdown
Contributor

ok, ok, enough fun. New diff is up, back on topic.

@jisaacks
I think you missed this one:
https://github.com/facebook/react/blob/master/src/renderers/dom/shared/ReactDOMComponent.js#L224

And also lint requires a trailing comma on line 459.

@sophiebits

Copy link
Copy Markdown
Collaborator

All the switch statements too for custom form components (incl. this._tag === 'select').

@jisaacks

Copy link
Copy Markdown
Contributor Author

@jimfb I will fix that right now. Already fixed the trailing comma, which confuses me.

@spicyj um.. what?

@jimfb

jimfb commented Jun 23, 2015

Copy link
Copy Markdown
Contributor

@jisaacks: What @spicyj was trying to say is that there are other places in the codebase where we check the value of the tag. Since now we're supporting arbitrary case, we need to fix those also.

Eg: https://github.com/facebook/react/blob/c5fb3ff9870cc09a6ec82672e854ab54a412cef1/src/renderers/dom/shared/ReactDOMComponent.js#L715

@sophiebits

Copy link
Copy Markdown
Collaborator

@jisaacks

Copy link
Copy Markdown
Contributor Author

OK new commit coming in just a minute.

@sophiebits

Copy link
Copy Markdown
Collaborator

They should be insensitive according to spec.

TIL. I guess we might want to support XHTML though. Sigh. Browsers.

@sebmarkbage

Copy link
Copy Markdown
Contributor

Is XHTML really a thing yet? Are browsers even supporting it? Maybe we should have a special build for that. If we support XHTML then they aren't insensitive anymore.

@jisaacks
jisaacks force-pushed the master branch 2 times, most recently from 8479e96 to e28ea23 Compare June 23, 2015 21:30
@jisaacks

Copy link
Copy Markdown
Contributor Author

@sebmarkbage let me know if that looks good.

@jimfb

jimfb commented Jun 23, 2015

Copy link
Copy Markdown
Contributor

To keep things maximally general, it seems intuitively better to avoid mangling the input whenever possible. The more transparent we can be (ie. the closer we can be to passing inputs straight through) the better. I could see people wanting case sensitivity, as we see with things like SVG and XHTML and WebComponents.

That said, I'm not strongly attached to preserving case sensitivity. This one doesn't bother me quite as much as the unitless numbers bug does.

In this latest diff, it looks like we're using upper case for the open tag and lower case for the closing tag? That can't be right :P, unless I'm miss-reading something?

@sebmarkbage

Copy link
Copy Markdown
Contributor

Yea, we should probably use the same for the closing tag too. I figured it didn't matter because of case-insensitive parsing and we only really want to preserve the case for purposes of debugging since it shouldn't matter for anything else.

However, for safety, and our own well being we should probably use the same case in the closing case too.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yep Alright pushed that change up :)

@jisaacks

Copy link
Copy Markdown
Contributor Author

@sebmarkbage @jimfb closing tag should match now :)

@jimfb jimfb changed the title Warn if rendering an HTML tag with uppercase chars Generate reasonable markup even if tags have unexpected case. Jun 23, 2015
jimfb added a commit that referenced this pull request Jun 23, 2015
Generate reasonable markup even if tags have unexpected case.
@jimfb
jimfb merged commit 3dc4384 into react:master Jun 23, 2015
@jimfb

jimfb commented Jun 23, 2015

Copy link
Copy Markdown
Contributor

Ok, thanks @jisaacks! Sorry about all the back and forth, but this is a good change! Much appreciated!

@jisaacks

Copy link
Copy Markdown
Contributor Author

@jimfb no worries! Thanks! :)

mrizwanashiq pushed a commit to mrizwanashiq/react that referenced this pull request Jun 25, 2026
Generate reasonable markup even if tags have unexpected case.
hanzo-dev pushed a commit to hanzoai/react that referenced this pull request Sep 9, 2026
Generate reasonable markup even if tags have unexpected case.
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.

5 participants