Skip to content

fix(rules): perf/dom-size dom-max-children counts body only - #550

Merged
nc9 merged 3 commits into
mainfrom
claude/483-dom-max-children
Oct 8, 2026
Merged

nc9 merged 3 commits into
mainfrom
claude/483-dom-max-children

Conversation

@nc9

@nc9 nc9 commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Summary

dom-max-children walked from <html>, so a <head> with many hreflang alternates or preload hints tripped the 60-children limit. It now walks <body> only, and the reported count reflects body descendants. Total nodes and depth are unchanged (tracked separately in #548). The sri part of the original report moved to #546 and is not touched here.

docs/rules/perf/dom-size.mdx and the max_children entry in docs/configuration/rule-options.mdx now state what is counted.

Closes #483

Verification

  • bun test packages/rules/tests/dom-size.test.ts: 4 pass (70 hreflang links, 70 preload links, ul with 61 li reported with value 61, no <body> does not throw and reports 0). The two head tests fail without the fix.
  • bun run typecheck in packages/rules: clean
  • make validate in docs/: passes

Agent skill

No change needed to the squirrelscan agent skill: it links to the rule pages, which are the reference and are updated here.

Checklist

  • I added or updated tests for behavioral changes.
  • I did not include secrets, customer data, or incompatible third-party material.
  • Every commit includes a DCO Signed-off-by line (git commit -s).

The widest-element check walked from <html>, so a <head> full of hreflang
alternates or preload hints tripped the 60-children limit. Walk <body>
instead. Total nodes and depth are unchanged.

Closes #483

Signed-off-by: Nik Cubrilovic <[email protected]>
@claude

claude Bot commented Oct 7, 2026

Copy link
Copy Markdown

Review of PR 550: skip <head> in dom-max-children.

The change is small and does what it says. Skipping <head> removes the false positives from hreflang and preload links. The docs are updated to match, and the tests cover the main cases. I only read the diff and didn't run the tests.

  • (low) packages/rules/tests/dom-size.test.ts: the no-body test only asserts not.toThrow(). It should also check that dom-max-children reports value 0 with status pass, since the docs now promise that.
  • (nit) The no-body test builds a fake document with body: null. Real HTML parsers always synthesize a <body>, so this branch is defensive. That's fine, but a short comment saying so would help.
  • (nit) dom-total-nodes and dom-depth still include <head>. The docs now say so, which is good. If the head is meant to be excluded for layout cost, consider doing that in a follow-up for consistency.

No blocking issues.

…ody result

Review follow-up for dom-size.

Signed-off-by: Nik Cubrilovic <[email protected]>
@claude

claude Bot commented Oct 7, 2026

Copy link
Copy Markdown

Review of PR 550 (perf/dom-size: skip <head> for max-children). I found no blocking issues.

The change is small and does what it says. findMaxChildren(body) still counts <body>'s own direct children and recurses from there. A missing body falls back to 0. Total nodes and depth still include <head>, and the docs say so.

  • (nit) docs/configuration/rule-options.mdx:503: the comment "Most children of one element" reads oddly. "Most children of one element inside " would be clearer.
  • (nit) packages/rules/tests/dom-size.test.ts: the no-body test builds a fake document object. That's fine for a unit test, but it doesn't show what the real parser returns for document.body on <html></html>. A <body> that is itself over the limit isn't covered either, though the code path is simple.
  • (nit) A page with no <body> now reports a passing 0 for dom-max-children. The docs mention this, so it's acceptable.

I didn't run the tests.

@claude

claude Bot commented Oct 8, 2026

Copy link
Copy Markdown

Reviewed the diff. The change is small and correct: findMaxChildren is now run on document.body, which still counts body's own direct children and its descendants. The no-body case falls back to 0 without throwing. The tests cover hreflang and preload links in <head>, a 61-item ul, and a missing body. I only read the code and did not run the tests.

  • (nit) docs/configuration/rule-options.mdx: the comment # Most children of one <body> element reads oddly. # Most children of one element in <body> would be clearer.
  • (nit) packages/rules/tests/dom-size.test.ts: the no-body test builds a fake document object. A real parsed document with no body (for example <html></html>) may be sturdier, if the parser leaves body null for it.
  • (low) Elements hoisted out of <body> by the HTML parser, and a <frameset> document where document.body is the frameset, now behave slightly differently. This is an edge case and acceptable.

No blocking issues.

nc9 commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor Author

Re the (low) parser-hoisting and frameset note: skipped deliberately, as the review says it is an edge case and acceptable.

@nc9
nc9 merged commit 5bf8306 into main Oct 8, 2026
15 checks passed
@nc9
nc9 deleted the claude/483-dom-max-children branch October 8, 2026 01:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

perf/dom-size: dom-max-children counts the children of <head>

1 participant