-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Inconsistency in SSR boolean and null attributes when using spread syntax #2916
Comments
On latest master (3.13.0-alpha.2) I'm currently getting
So spreading objects with I'm undecided whether
|
The double attribute issue is just a simple logic error, and can be fixed with diff --git a/src/runtime/internal/ssr.ts b/src/runtime/internal/ssr.ts
index 83e585a8..61f81016 100644
--- a/src/runtime/internal/ssr.ts
+++ b/src/runtime/internal/ssr.ts
@@ -21,7 +21,10 @@ export function spread(args, classes_to_add) {
const value = attributes[name];
if (value == null) return;
- if (value === true) str += " " + name;
+ if (value === true) {
+ str += " " + name;
+ return;
+ }
const escaped = String(value)
.replace(/"/g, '"') It's not specifically mentioned in this issue, but I'm not sure how we'd want to deal with something like |
Pushed what I have so far to this branch. One slight wrinkle is just that this introduces code that we want to have available at build time and at run time, which I don't think has precedent. I elected to stick this shared data in There are also still some differences between DOM and SSR mode in how non-boolean attributes that are explicitly given Another difference between DOM and SSR handling of boolean attributes is that in SSR mode, no checking is done to see whether this attribute is boolean for this element. There's just a list of boolean attributes. We can revisit this later if it becomes a problem, but in the meantime it would probably be prudent to update the list of boolean attributes according to the |
So, as with a couple of these spread-related issues, the scope of my in-progress PR ends up expanding beyond the original issue, oh well. Something that currently generates incorrect code in SSR mode is this: <script>
let autocomplete = 'no';
</script>
<input {autocomplete}> Since |
* in SSR, adjust spread with boolean attributes (#2916) * add tests * update changelog
will render
The duplication on line two could also be seen in REPL with:
The text was updated successfully, but these errors were encountered: