Repository navigation
Description
What happens
One page whose class attribute holds more than about 638 K class tokens makes the HTML parse throw RangeError: Maximum call stack size exceeded. The throw isn't contained to that page: the whole audit fails and no report is written, so every other page's results are lost too.
The overflow is in linkedom 0.18.13. Its className setter spreads every token into one call, classList.add(...(String(value).split(/\s+/))) (esm/interface/element.js), reached from htmlparser2 during parseHTML. That means the limit is a count of tokens, not bytes. The tokens don't have to be distinct, so a 1.22 MB attribute is enough, far under the crawler's 10 MB page cap.
Evidence
Measured offline on Boat, with fixtures built at runtime and nothing external fetched.
- Parser alone (
linkedom.parseHTML,parser.parseDocument,parseHtmlForRules):- one-letter classes parse at 637,890 tokens and throw at 638,769 tokens (a 1.22 MB attribute);
- longer names (
c0 c1 …) parse at 500 K tokens (3.7 MB) and throw at 750 K (5.6 MB); - the same 1.28 M tokens in a
data-xattribute parse fine.
- Versions: v0.0.157 and v0.0.159 are identical, so this predates both.
- Real CLI audit (v0.0.159,
squirrel audit http://127.0.0.1:<port>/ --offline --passive --no-publish): a local three-page fixture site of normal home and B pages plus one page with a 7.5 MB class attribute. The audit exits 1 with✗ Audit failed: Maximum call stack size exceeded.and writes no report. - Not measured: the hosted worker. It uses the same engine parse, so the hosted audit most likely fails the same way. Check it.
Before changing anything
Check where a parse failure should be contained, the crawl-time parse and the rules parse alike. Find out whether another linkedom path (setAttribute("class"), classList.value) spreads tokens in the same way. Also decide whether to patch around it (cap or normalize the class token count before the setter sees it) or to contain any parse throw per page.
Acceptance Criteria
- On a site where one page's parse throws, the audit completes and writes a report. Every other page is audited normally, and the failing page is listed with a visible parse-failure notice instead of silently vanishing. This holds for the CLI and the hosted worker.
- A page with a
classattribute of 1 M or more tokens, distinct or repeated, no longer throws. The rest of the page (later elements, images, scripts) still reaches the rules, checked with a marker placed after the big element. - A test builds the fixture at runtime (no multi-MB fixture file in the repo) and fails if the RangeError or the whole-audit failure comes back.
- The PR states whether the fix is a workaround in our parser wrapper or an upstream linkedom change, and links any upstream report.
Activity
fix(parser): cut offset of an entity-led class token comes from the t…
fix(parser,rules): a class attribute that overflows the parse is cut …
fix(parser,rules): cut an oversized class by the tokenizer's own read…
docs(changelog): v0.0.161 release notes for the stacked fixes #1560 #…
fix(parser): cut offset of an entity-led class token comes from the t…
test(parser): reach the retry paths through an injected parse functio…
test(parser): reach the retry paths through an injected parse functio…
nc9 commentedon Nov 4, 2026
Acceptance check against v0.0.162 (7c31d5b). The fix shipped in v0.0.161: b7ea286, b576fa9, 50b3a74 (stacked from agent branches, no per-issue PR).
parseHTMLinpackages/parser/src/dom.ts(it is the only value import of linkedom in the repo; the rest are type imports), so the CLI, the engine and the hosted worker share it.packages/audit-engine/tests/huge-class-parse-1557.test.tsrunsrunStreamingRulesover a 1,000,000-token page and a normal page: both audited,crawl/html-sizehas anhtml-parsewarn on the big page only. I also ran the CLI from the v0.0.162 tree against a local three-page site with one 700,000-token class page (audit --offline --passive --no-publish --http -f json): exit 0, a report written, all 3 pages audited,html-parsewarn on the big page. The hosted worker itself was not run here.huge-class-1557.test.ts"1 million repeated tokens parse: the elements after it reach the document, with a notice" and "distinct tokens: the first 20,000 are kept, in order" (700,000); the engine test finds the image without alt placed after the big element.Array.fromin the tests; no multi-MB file in the repo; "which failures parseHTML retries" inparse-contained-1557.test.tscovers the retry and empty-document paths.dom.tsheader and the changelog entry state it is contained in our parser wrapper (the one place pages are parsed), with a retry cut and an empty-document fallback. No upstream linkedom report is linked, and none is referenced in the repo.Ran:
huge-class-1557.test.ts(12 pass),parse-contained-1557.test.ts(6),huge-class-parse-1557.test.ts(1),html-size-parse-notice-1557.test.ts(3).Ticked 1 to 4 and closing. Follow-up work that was split out of this fix stays on its own issues (a CLI end-to-end test and the empty-document findings are on #1570; the differential test is on #1569).
nik