fix: [#2222] Calculates the size in getBoundingClientRect() based on the computed style - #2308
Open
sahiljagtap08 wants to merge 1 commit into
Open
Conversation
…) based on the computed style Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
sahiljagtap08
force-pushed
the
fix/issue-2222-bounding-client-rect
branch
from
August 23, 2026 06:58
5c0d248 to
4a3012e
Compare
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 #2222
What it does
Implements the size calculation that @capricorn86 suggested in #1416:
getBoundingClientRect()now returns the width and height from the computed style of the element instead of always returning zeros.getClientRects()returns the same rect, as before.styleattribute, and font relative units (rem,em), since the computed style resolves those to pixels.box-sizingiscontent-box, padding and border widths are added to the size.display: none.Limitations (documented in the JSDoc)
Happy DOM has no layout engine, so values that depend on the layout of other elements (percentages,
auto,fit-content, transforms, grid tracks) can't be calculated and are treated as 0. The position (x/y) also stays 0.Tests
New tests cover the stylesheet case from the issue, the
styleattribute, unit conversion, bothbox-sizingmodes, disconnected elements,display: none, and non-resolvable values. Expected values were verified in a real browser.Claude Code assisted with this pull request. All code has been reviewed and tested by me.