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

Inconsistent SSR of Boolean attributes #391

Open
axel-habermaier opened this issue Jan 10, 2025 · 6 comments
Open

Inconsistent SSR of Boolean attributes #391

axel-habermaier opened this issue Jan 10, 2025 · 6 comments

Comments

@axel-habermaier
Copy link

axel-habermaier commented Jan 10, 2025

Consider the following example code:

function Attr() {
  return (
    <>
    <input checked={true} />
    <input checked />
    </>
  );
}

In SSR mode, this gets transpiled to:

import { ssr as _$ssr } from "solid-js/web";
import { ssrHydrationKey as _$ssrHydrationKey } from "solid-js/web";
var _tmpl$ = ["<input", " checked=\"\">"],
  _tmpl$2 = ["<input", " checked>"];
function Attr() {
  return [_$ssr(_tmpl$, _$ssrHydrationKey()), _$ssr(_tmpl$2, _$ssrHydrationKey())];
}

While technically correct according to MDN, the two templates should not differ. I'd expect <input checked={true} /> to also result in the template ["<input", " checked>"] as opposed to the actual ["<input", " checked=\"\">"].

Furthermore, if the value of the checked property is computed at runtime, i.e., <input checked={Date.now() > 0} />, the rendered HTML string also is <input checked>, inconsistent with the <input checked=""> generated by the transpiler when the value is a constant.

@titoBouzout
Copy link
Contributor

Besides the different output, does it make any difference? There has been some effort into making all of this more predicable, which is a work in progress (so stuff is not as consistent as it should be); but my question still remains, besides the inconsistency does it make any difference?

@lxsmnsyc
Copy link
Collaborator

@titoBouzout probably just to shave off a few bytes

@titoBouzout
Copy link
Contributor

Yes, agree, what I wonder is if it changes behaviour in any noticeable way, think of CSS selectors and so on

@titoBouzout
Copy link
Contributor

titoBouzout commented Jan 14, 2025

This PR fixes the reproduction the issue is reporting #385, but that's just for the literal case, haven't looked what will happen in the dynamic case, having these to match would be good

@axel-habermaier
Copy link
Author

haven't looked what will happen in the dynamic case

As I mentioned in my original post, <input checked={Date.now() > 0} /> prints <input checked>, so this should be consistent with #385.

@edemaine
Copy link
Contributor

what I wonder is if it changes behaviour in any noticeable way, think of CSS selectors and so on

I don't think so. https://www.w3.org/TR/2012/WD-html-markup-20120329/syntax.html#syntax-attr-empty says

empty attribute syntax is exactly equivalent to specifying the empty string as the value for the attribute

But certainly nicer to be consistent and shorter.

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

No branches or pull requests

4 participants