Repository navigation
fix(js): clientWidth is the padding box, scrollWidth the scrolling area - #294
Merged
Merged
Conversation
client* and scroll* both returned the border box. CSSOM View defines clientWidth/Height as the padding edge (no borders, minus a scrollbar this engine never draws; 0 for an inline box) and scrollWidth/Height as the size of the element's scrolling area - its scrollable overflow area (CSS Overflow 3 §3.3): the padding box united with the line boxes and inline content it holds and its descendants' border boxes, a descendant being entered only when it does not clip its own overflow. So <h1 style="white-space:nowrap;width:10px">Short text here</h1> reported scrollWidth 10, the very measurement a fitting heading needs. js.BoxMetrics is a second optional Metrics extension the binder uses for client* and scroll*; the engine's metrics implement it from the box tree (after the same forced synchronous layout as every other read). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Problem
<h1 style="white-space:nowrap;width:10px">Short text here</h1>:scrollWidthreturned 10. All of client* and scroll* returned the border box.Spec read
scrollWidth: return the width of the element's scrolling area (0 with no box; the root uses the viewport).clientWidth: 0 for no box or an inline box; otherwise the width of the padding edge, minus any scrollbar.Root cause
js/dom.gomappedclientWidth/HeightandscrollWidth/HeighttoborderW/borderH, the border box.Change
js.BoxMetricsis an optional Metrics extension (ClientSize,ScrollSize) the binder uses for client* and scroll*. Without it they fall back to the border box, as before. The engine's metrics implement it from the box tree:Each read goes through the forced synchronous layout from #293. Not modelled: the root/body viewport cases of the spec, and end-side alignment padding.
Tests
TestScrollAndClientSize(engine, RenderHTML with JS): nowrap overflow; a 5px-border/2px-padding box with an overflowing 200×100 child → client 54, scroll 202×102; no overflow → padding box. Failed on main (false,10,64,64,64,34,56,26).TestSessionBoxMetrics(js): values come from BoxMetrics; unknown node → 0.🤖 Generated with Claude Code