Skip to content

perf/dom-size: scope total node count and depth consistently with dom-max-children #548

Closed

Description

@nc9

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: packages/rules/tests/dom-size.test.ts (added by perf/dom-size: dom-max-children counts the children of <head> #483), a page with a 70-link <head> and a small body: total nodes and depth reflect the body
  • 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

Activity

  1. added
    enhancement
    P3
    size: S
    rules
    on Oct 7, 2026
  2. nc9 commented on Oct 11, 2026

    @nc9
    ContributorAuthor

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

  3. nc9 commented on Oct 16, 2026

    @nc9
    ContributorAuthor

    Decision: body-only, for all three checks.

    • 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3enhancementrulessize: S

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions