HTML Parser fails if you have the same attribute twice
See original GitHub issueDescribe the bug
It seems that if you have the same attribute twice, the HTML parser to fail. (Tested it with class=
, data-a=
and x=
. It fails for all of them.)
Reproduction
(Repro on Stackblitz.)
<!DOCTYPE html>
<div class="a" class="b"></div>
Output:
[vite] Internal server error: Unable to parse {"file":"/index.html","line":2,"column":16}
1 | <!DOCTYPE html>
2 | <div class="a" class="b"></div>
| ^
3 |
at traverseHtml (/home/projects/vitejs-vite-wv2wbb/node_modules/vite/dist/node/chunks/dep-e0fe87f8.js:21240:15)
at async devHtmlHook (/home/projects/vitejs-vite-wv2wbb/node_modules/vite/dist/node/chunks/dep-e0fe87f8.js:57001:5)
at async applyHtmlTransforms (/home/projects/vitejs-vite-wv2wbb/node_modules/vite/dist/node/chunks/dep-e0fe87f8.js:21550:21)
at async viteIndexHtmlMiddleware (/home/projects/vitejs-vite-wv2wbb/node_modules/vite/dist/node/chunks/dep-e0fe87f8.js:57065:28)
System Info
Stackblitz.
Used Package Manager
npm
Logs
No response
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn’t already an issue that reports the same bug to avoid creating a duplicate.
- Make sure this is a Vite issue and not a framework-specific issue. For example, if it’s a Vue SFC related bug, it should likely be reported to https://github.com/vuejs/vue-next instead.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Issue Analytics
- State:
- Created 2 years ago
- Comments:11 (7 by maintainers)
Top Results From Across the Web
13.2 Parsing HTML documents - HTML Standard
This error occurs if the parser encounters an attribute in a tag that already has an attribute with the same name. The parser...
Read more >Chapter 3. The HTML parser
When the parser identifies something that is an error, it says that "it is a parse error". Some parse errors have an identifying...
Read more >Parsing Issues | Reference - Total Validator
If the value does appear to be present then this error may have been caused by a badly formatted tag possibly with single...
Read more >Parsing XML and HTML with lxml
To read from a file or file-like object, you can use the parse() function, ... XML forbids double hyphens in comments, which the...
Read more >Chapter 5. The Rule Language - JBoss.org
The parser will ignore anything in the line after the comment symbol. ... If you define a rule twice in the same DRL...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
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.