You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
perf/dom-size: scope total node count and depth consistently with dom-max-children #548
Follow-up to #483. perf/dom-size measures from the document element, so <head> children are counted in three places: the widest element (dom-max-children, fixed in #483), the total node count and the depth. #483 only changes the widest-element check to walk <body>, because changing total nodes and depth shifts the numbers on every site and deserves its own decision.
Lighthouse measures its DOM size audit from the body as far as we know, and docs/rules/perf/dom-size.mdx currently says counting starts at <html> and includes it. This issue decides whether total nodes and depth should follow the same rule, so the three numbers are consistent.
Acceptance Criteria
The choice (body-only counting for total nodes and depth, or documented as intentionally whole-document) is recorded in a comment here before the change is made
If body-only: total node count and depth are measured from <body>, and a page with a large <head> and a small body reports the body numbers
If body-only: the thresholds in the rule are reviewed against the new numbers, and the docs page states the thresholds and what is counted
The three checks of perf/dom-size (widest element, total nodes, depth) agree on what part of the document they measure
Test: same file, a page with a deep body: depth still reported at the threshold
Existing benchmark mapping for the Lighthouse comparison still matches, or the mapping is updated in the same PR
The PR description states whether the squirrelscan agent skill needs a change (the skill links to the rule pages, which are the reference, so usually none); if it does, a follow-up is filed against squirrelscan/skills
Reproduced on 0.0.108 with a local fixture: a page with 1,600 <link rel="alternate"> elements in <head> and a small body gives perf/dom-size, check dom-total-nodes, warn, Large DOM (1609 nodes). The same body without the head links passes.
origin/main still counts total nodes and depth from document.documentElement in packages/rules/src/performance/dom-size.ts; only the widest-element check walks <body>.
Lighthouse's DOM size audit measures from <body>: its DOMStats gatherer walks document.body, reports totalBodyElements (the body's descendants, not the body itself), and counts the body as depth 1. dom-max-children already walks <body> (perf/dom-size: dom-max-children counts the children of <head> #483), so moving total nodes and depth there makes the three checks agree and makes them match the Lighthouse audit that apps/cli/src/benchmark/mapping.ts pairs with perf/dom-size.
<head> holds metadata (hreflang alternates, preload hints, meta tags) that costs no layout, and it is what made a small page with a big head read as a large DOM.
Thresholds stay at 1,500 / 3,000 nodes, 32 levels and 60 children. Body-only lowers a typical count by the head size plus <html>, <head> and <body> (roughly 20 to 100 nodes), which is small next to the 1,500 warning line. 1,500 is the figure the rule's guidance already quotes. Lighthouse's own warning line is lower (800), but moving the defaults would be a separate scoring change.
A document with no <body> gets one skipped check instead of three numbers.
Activity
nc9 commentedon Oct 11, 2026
Reproduced on 0.0.108 with a local fixture: a page with 1,600
<link rel="alternate">elements in<head>and a small body givesperf/dom-size, checkdom-total-nodes,warn,Large DOM (1609 nodes). The same body without the head links passes.origin/main still counts total nodes and depth from
document.documentElementinpackages/rules/src/performance/dom-size.ts; only the widest-element check walks<body>.nc9 commentedon Oct 16, 2026
Decision: body-only, for all three checks.
<body>: its DOMStats gatherer walksdocument.body, reportstotalBodyElements(the body's descendants, not the body itself), and counts the body as depth 1.dom-max-childrenalready walks<body>(perf/dom-size: dom-max-children counts the children of <head> #483), so moving total nodes and depth there makes the three checks agree and makes them match the Lighthouse audit thatapps/cli/src/benchmark/mapping.tspairs withperf/dom-size.<head>holds metadata (hreflang alternates, preload hints, meta tags) that costs no layout, and it is what made a small page with a big head read as a large DOM.<html>,<head>and<body>(roughly 20 to 100 nodes), which is small next to the 1,500 warning line. 1,500 is the figure the rule's guidance already quotes. Lighthouse's own warning line is lower (800), but moving the defaults would be a separate scoring change.<body>gets one skipped check instead of three numbers.fix(rules): perf/dom-size measures total nodes and depth from body #548
fix(rules): perf/dom-size measures total nodes and depth from body #548…