question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

HTML Parser fails if you have the same attribute twice

See original GitHub issue

Describe 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

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:11 (7 by maintainers)

github_iconTop GitHub Comments

5reactions
yyx990803commented, Dec 13, 2021

https://html.spec.whatwg.org/multipage/syntax.html#attributes-2

Quote:

There must never be two or more attributes on the same start tag whose names are an ASCII case-insensitive match for each other.

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.

4reactions
surmacommented, Dec 8, 2021

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found