React: Server rendering a tag attribute with no value

Created on 29 Nov 2017  路  4Comments  路  Source: facebook/react

Do you want to request a feature or report a bug?
Bug?

What is the current behavior?

When I server render this: <script src='https://www.googletagmanager.com/gtag/js?id=XXX' async />

The HTML has async="" instead of just async.

Using React 16.1.1 and node 8.9.1.

Is there a way to render <script src='...' async /> rather than <script src='...' async="" />..?

Not sure if browsers treat async="" as true or false.

All 4 comments

Not sure if browsers treat async="" as true or false.

React output is correct. By HTML spec, for boolean attributes, not specifying an attribute is the same as specifying it with ='' value.

https://stackoverflow.com/a/4139805/458193

How difficult would it be to just use the canonical name without a value? They're both semantically identical, but maybe we could save people a few bytes :)

@gaearon Thanks for that...

not specifying an attribute is the same as specifying it with ='' value

I think you mean not specifying an attribute value is the same as specifying it with =''.

@aweary At the moment, using both async and async='async' result in async="", which is fine so long as browsers follow the spec and treat it as true.

How difficult would it be to just use the canonical name without a value?

Happy to review a PR.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

zpao picture zpao  路  3Comments

MoOx picture MoOx  路  3Comments

UnbearableBear picture UnbearableBear  路  3Comments

varghesep picture varghesep  路  3Comments

zpao picture zpao  路  3Comments