Repository navigation
fix: document body/head shortcut getters when documentElement is body/head - #362
Open
johnhldiver-beep wants to merge 1 commit into
Open
johnhldiver-beep wants to merge 1 commit into
johnhldiver-beep wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #283.
document.bodyloses its children:parseHTML('<body><div class="whatever"></div></body>')makes the<body>element itself thedocumentElement, and the shortcut getters inesm/html/document.jsthen misfire:headprepends a new empty<head>inside the real body, andbodycreates a new empty<body>after it. Result: two<body>elements,document.bodyis the fake empty one, and merely accessing it mutates the real body.Fix (root cause, one concern): the
head/bodygetters now returndocumentElementdirectly when it already isHEAD/BODY, before any create/prepend/after logic. Both mirrors updated identically.titleuntouched (not affected by this root cause). No existing tests modified.Tests: regression tests in
test/html/document.jsfor the body case and the symmetric head case. New tests failed before the fix and pass after;test/html/document.jsand the fullnode test/index.jssuite both exit 0 with no failures. Repros verified in both ESM and CJS:body === document.bodytrue, exactly 1 body, children still justDIV(no mutation), bare-<head>docheadidentity true, and a normal full document (head/body/title) unaffected. Honest limits: this suite prints no numeric assertion totals, so counts are reported as exit codes + failure-grep counts; eslint/c8 were not run (devDeps deliberately skipped for disk).Notes: prior PR #108 (2022, "Fix document.body not including content from DOMParser parsed ") was closed unmerged because the maintainer incorporated a related fix for #106 directly — and his stated guidance there ("The
bodygetter is likely the place to look for a change") is exactly the approach taken here. Residual, pre-existing, out of scope: callingdocument.headdirectly on a bare-<body>document still prepends an empty<head>inside the body (the old ensure-a-head fallback); the issue's repro is aboutbody, and changing head-on-bare-body semantics would be a separate behavior decision.