-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
SSR boolean attributes #1109
Comments
The relevant code is here ... I'm not sure whether we want to simply make this so that it doesn't render the attribute at all when its value Would it be better to look up whether this is a boolean attribute and include or don't include it depending on its value's truthiness - and to always serialize the value of attributes that aren't boolean according to the spec? I had thought there was already a lookup somewhere in Svelte's source for which attributes were boolean, but either there's not or I can't find it. |
This is a bit messier than I thought. I didn't realize there were so many different boolean attributes. See here and do a text search for 'boolean attribute'. There are a couple things I don't know whether we need to worry about:
|
Finding a canonical list of boolean attributes is weirdly difficult. Might have to write a mini-parser that extracts them from https://www.w3.org/TR/html52/single-page.html#sec-boolean-attributes. I did find this list by @ArjanSchouten, though it's not clear where it's sourced from — Arjan, if you see this, can you help?! My suspicion is that it's okay to treat a particular attribute that we know to be boolean (such as |
If we're fine with treating attributes as static regardless of the element they're on, that sounds like it's probably a good enough solution for now. That would really only affect SSR stuff. (For DOM code, we'd continue to use the attributes-to-props lookup as it exists now, and rely on browsers to do the right thing.) Using the list from that gist (and rendering attributes in SSR according to whether they're in that list, not by whether their value Edit: Hm, looks like we'd also need to output the attribute as a boolean attribute when its value is |
I'm good with that approach 👍 |
fix handling of boolean attributes in SSR (#1109)
@Rich-Harris I created this list by going through w3schools.com's HTML tag list manually. I needed it for a side project from some time ago: https://github.com/ArjanSchouten/HtmlMinifier. In the meanwhile the list can be outdated. |
@ArjanSchouten thank you. The list is extremely helpful, and I'd wager it's still mostly correct. Released 1.54 with @Conduitry's fix — thanks @UnwrittenFun |
Svelte doesn't render boolean attributes properly on the server side.
For instance, for a button
This will render (when disabled = false)
which means the button actually is disabled
Here's a gist with an example and the ssr code it generates.
The text was updated successfully, but these errors were encountered: