-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
HTML Parser fails if you have the same attribute twice #5966
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
Comments
Should we throw another error such as |
Maybe this will be fixed/improved by #5777 |
I wouldn’t expect this to error at all. Duplicate attributes are perfectly valid HTML. |
it will error because vue/compiler-dom is checking if the html is valid and it doesn't allow duplicate attributes. |
There was already an issue but was closed as in Vue it is preferred to error on duplicates vuejs/core#4883 |
I think probably it should still at least warn for this kind of low level error since duplicate attributes are still not valid syntax in HTML. Can just have list of error codes of the Vue HTML parser for which Vite just warns. Reference: https://www.w3.org/TR/WCAG20-TECHS/H94.html |
That’s not true. As far as I can tell from the HTML parser spec, it’s definitely not a syntactic error and I can’t find anything about it being a semantic error either. (edit: I was wrong, see below) What you linked to is a WCAG note, saying:
So while it is definitely advisable to not have duplicate attributes — esp. when they are relevant for assistive technologies — but as far as I can tell, it’s not invalid by any means, and should not cause an error imo. I have no strong opinions on whether or not to emit a warning, but I worry about it potentially being noise when it’s harmless (e.g. a duplicate |
I'm with you for Do you have currently a real world example / project where you need this? Depending on that, we could estimate the priority of this issue. Also as @Niputi mentioned, do we already have an issue for this in @vue/compiler-dom? |
If the same attribute is specified multiple times, the first one wins. I am running into this because I’m using vite to optimize and bundle the output from 11ty. Lots my HTML is programmatically generated and happens to have duplicate attributes. |
https://html.spec.whatwg.org/multipage/syntax.html#attributes-2 Quote:
If your markup contains duplicated attributes, you should fix it. If your tool is generating duplicated attributes, it's a bug in that tool and you should ask that tool to fix it. That said, browsers do silently allow duplicated attributes, so Vite should not break the build because of it. But still. |
TIL! I don’t know why I didn’t find that previously. Thanks for providing it. I have no spec-level leg to stand on, but I would consider Postel’s law here, as all browsers uniformly accept this markup. I’ll leave the final call up to you and whether or not to close this. |
Describe the bug
It seems that if you have the same attribute twice, the HTML parser to fail. (Tested it with
class=
,data-a=
andx=
. It fails for all of them.)Reproduction
(Repro on Stackblitz.)
Output:
System Info
Used Package Manager
npm
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: