You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by jl...@apache.org on 2026/09/05 18:12:00 UTC
(superset) 03/05: fix(plugin-chart-table): verify sticky totals fix with real hit-testing, pin scrollBarStyles regression
This is an automated email from the ASF dual-hosted git repository.
sadpandajoe pushed a commit to branch fix-table-total-cutoff-on-resize
in repository https://gitbox.apache.org/repos/asf/superset.git
commit 0246d4599e034dba154553798f3881fe7534481d
Author: sadpandajoe <jc...@gmail.com>
AuthorDate: Sat Sep 5 17:44:03 2026 +0000
fix(plugin-chart-table): verify sticky totals fix with real hit-testing, pin scrollBarStyles regression
The previous round's RCA claimed clipping based on comparing clientWidth to
scrollWidth on an overflow:hidden element, but scrollbar-gutter's reserved
space is phantom for overflow:hidden (never rendered as a real scrollbar),
so it doesn't move the actual clip boundary. Real-browser hit-testing
(document.elementFromPoint sweeps in headed Chromium) shows that comparison
doesn't demonstrate clipping. Retract that claim in RCA.md and replace it
with the structural reason the fix is correct regardless of any browser's
scrollbar-probe accuracy: the shared colgroup is always bounded by the
sizer's clientWidth, which is always bounded by maxWidth, so an unconditional
width: maxWidth on header/footer can never be narrower than the table it
must display.
Also add a /** @jsxImportSource @emotion/react */ pragma to useSticky.tsx so
its css prop is observable in this repo's Jest/Babel setup the same way
webpack/SWC already observes it in production, and use that to extend the
regression test to assert header/footer actually receive the
scrollBarStyles-generated class (previously only the inline width/
scrollbarGutter half was pinned, so the test passed with or without the
scrollBarStyles addition).
Refs #21063
---
.../plugins/plugin-chart-table/RCA.md | 483 +++++++++++++--------
.../src/DataTable/hooks/useSticky.tsx | 2 +
.../test/DataTable/hooks/useSticky.test.tsx | 17 +
3 files changed, 319 insertions(+), 183 deletions(-)
diff --git a/superset-frontend/plugins/plugin-chart-table/RCA.md b/superset-frontend/plugins/plugin-chart-table/RCA.md
index b615e101ba6..a5f8cc53721 100644
--- a/superset-frontend/plugins/plugin-chart-table/RCA.md
+++ b/superset-frontend/plugins/plugin-chart-table/RCA.md
@@ -28,89 +28,143 @@ a brand new subsystem.
## Root Cause
-This section was revised after an independent review correctly challenged
-the first version's evidence. What follows separates what is directly
-verified from what remains inferred, including a place where deeper
-real-browser testing overturned my own first conclusion.
-
-**Verified — the defect class is real, and I have a genuine, non-forced
-reproduction of it, but not against unmodified master.**
-
-`useSticky.tsx`'s `StickyWrap` builds one shared `<colgroup>` (used by the
-header, body, and footer `<table>`s under `table-layout: fixed`) by measuring
-column widths inside a hidden "sizer" `<div>`. That sizer, and the real
-scrollable body `<div>`, both use `scrollbar-gutter: stable` *and* the same
-custom `::-webkit-scrollbar { width: 8px }` styling (`scrollBarStyles`,
-`useSticky.tsx:230-248`). Master's header/footer wrapper `<div>`s, however,
-computed their width as `maxWidth - scrollBarSize`, where `scrollBarSize`
-comes from a **separately JS-measured probe**, `getCustomScrollBarSize()`
-(`getScrollBarSize.ts:77-85`) — a different code path than the CSS
-`scrollbar-gutter` property the body/sizer rely on.
-
-Testing directly in a real, non-headless Chromium (via Playwright + a real
-Xvfb X11 display, not just headless — see "How this was verified"), I found
-that **`scrollbar-gutter: stable`'s reserved width depends on whether
-`::-webkit-scrollbar` custom styling is applied to that same element**: an
-element with the custom scrollbar styling reserves 8px (matching
-`CUSTOM_SCROLLBAR_SIZE`); the identical element *without* that styling
-reserves 15px (the browser's native scrollbar width). This held across six
-zoom levels (0.75×–1.5×) and both headless and headed rendering. This is the
-verified, non-obvious mechanism: **the amount of space `scrollbar-gutter:
-stable` reserves is not a fixed constant — it's contingent on scrollbar
-styling applied to that specific element**, so any two elements in this file
-that reserve gutter space must carry identical scrollbar styling or their
-reservations can differ.
-
-I confirmed this concretely by testing an intermediate, incomplete fix (see
-below): converging the header/footer onto `scrollbar-gutter: stable` *without*
-also giving them the same `scrollBarStyles` custom-scrollbar CSS the
-body/sizer carry reserves the *unstyled* 15px on header/footer while the
-sizer (styled) still computes the shared colgroup against its own 8px
-reservation. Real, non-forced consequence, measured with real DOM APIs in a
-real browser: header/footer wrapper `clientWidth` = 190px, footer `<table>`
-`scrollWidth` = 194px — a genuine 4px overflow of an `overflow: hidden`
-container, i.e. real clipping, with no mocked/forced values anywhere. This
-is a live demonstration that "two independently-computed reservations for
-the same scrollbar must be trusted to agree" is a real, reproducible failure
-mode in this exact file, not a hypothetical one — it's just not the
-failure mode present in unmodified master.
-
-**What I could NOT verify: that unmodified master's specific
-`getCustomScrollBarSize()`-based arithmetic diverges from the body/sizer's
-reservation under any real (non-forced) browser condition available in this
-sandbox.** My first pass at this RCA claimed this divergence based on
-*headless* Chromium alone, where the probe read 0px against a 15px
-"unstyled" gutter comparison — but that comparison was wrong on two counts,
-both caught in review:
-
-1. It compared the probe against an *unstyled* gutter reservation, but the
- body/sizer's actual reservation is the *styled* one (8px), which is what
- the probe is supposed to represent in the first place.
-2. Headless Chromium's synthetic scrollbar probe (an off-screen
- `overflow: scroll` div) reads 0px in this environment — but re-running
- the identical probe in a **real, headed** Chromium session (Playwright
- launched against a real Xvfb X11 display, not headless) gives 8px,
- *exactly* matching the styled `scrollbar-gutter` reservation. I swept
- chart widths from 260px down to 190px, the full shrink→grow→resize
- sequence, and six zoom levels, all against unmodified master code in the
- headed browser: header, body, and footer `clientWidth` were identical at
- every single step. Master's arithmetic and the body/sizer's CSS
- reservation agree in every real-browser condition this sandbox could
- produce.
-
-So: the specific numeric mismatch I originally proposed as "the" root cause
-does not reproduce against master in real (non-headless) Chromium. It's
-inferred, not verified, that some other real browser/OS/scrollbar-theme
-combination (not available in this sandbox — only one Linux/Chromium build
-plus a real X11 display were on hand) causes `getCustomScrollBarSize()` to
-diverge from `scrollbar-gutter`'s reservation against master's code
-specifically. One concrete, in-product example of a non-standard rendering
-path that could plausibly matter here: Superset's own Alerts & Reports
-feature renders dashboards through a headless browser to generate email
-screenshots, which is exactly the rendering mode where I *did* observe the
-probe read 0 — though even there, master's specific direction of mismatch
-(probe reading *lower* than the styled reservation) produces wasted space,
-not clipping, so it doesn't fully explain the report either.
+This section has been revised twice after independent review challenged the
+evidence, each time by doing more real-browser testing rather than defending
+the previous write-up. This third round **retracts a specific claim from
+round two** ("clientWidth=190 vs scrollWidth=194 proves real clipping") after
+directly falsifying it with hit-testing, and replaces it with a narrower,
+structurally-guaranteed argument for why the shipped fix is correct.
+
+**Retracted, this round — the 190px/194px `clientWidth`/`scrollWidth`
+comparison from round two is not evidence of clipping, and real hit-testing
+shows the content in question stays fully visible.**
+
+Round two's central claim was that converging header/footer onto
+`scrollbar-gutter: stable` *without* also giving them `scrollBarStyles`
+produces a header/footer wrapper `clientWidth` of 190px against a 194px-wide
+`<table>`, and that this constitutes real clipping. An independent reviewer
+challenged this directly: a scrollbar gutter reservation sits inside the
+padding edge, and `overflow: hidden` clips at the padding edge, not
+necessarily at the (gutter-reduced) `clientWidth`. Reproducing the same
+205px-wrapper/190px-`clientWidth`/194px-content geometry in real headed
+Chromium and testing it with `document.elementFromPoint` hit-testing across
+every pixel from the wrapper's left edge to well past its right edge — not
+just comparing two numbers — confirms the reviewer was right: the content
+remains hit-testable (i.e., actually painted, not clipped) all the way to
+its own true right edge, and only stops being hit-testable at the
+**wrapper's real, un-reduced border-box edge** (205px), never at the
+reduced 190px `clientWidth` `scrollbar-gutter` reports. In other words:
+
+> `scrollbar-gutter: stable` on an `overflow: hidden` box changes what
+> `clientWidth` *reports*, but does not move where the box actually clips
+> content. `overflow: hidden` clips at the box's real border-box edge,
+> whether or not `scrollbar-gutter` has "reserved" (phantom, since
+> `overflow: hidden` never renders a scrollbar to occupy that space) room
+> inside it.
+
+This was checked with a minimal, isolated repro (a plain `<div>` with the
+exact same `width`, `overflow: hidden`, `scrollbar-gutter: stable`, and
+`::-webkit-scrollbar` styling as the header/footer wrapper, containing a
+child sized to reproduce the exact 190/194 numbers from round two) so the
+result isn't an artifact of `react-table` or this specific component. It is
+a general, verified fact about how Chromium implements `overflow: hidden` +
+`scrollbar-gutter`, not something specific to this file. This means: **the
+round-two mechanism — a mismatched `scrollbar-gutter` reservation between
+header/footer and body/sizer — cannot, by itself, cause header/footer to
+visibly clip the total row.** The `scrollBarStyles` half of the shipped fix
+is not load-bearing for preventing clipping (see below for what it's
+actually for).
+
+**Verified, this round — a genuinely *narrower* box, from a real width
+subtraction rather than a phantom `scrollbar-gutter` reservation, does
+clip.**
+
+This matters because it's exactly what unmodified master does: master's
+header/footer compute `width: maxWidth - scrollBarSize`, where
+`scrollBarSize` comes from the separately JS-measured
+`getCustomScrollBarSize()` probe — a real, literal reduction of the
+wrapper's own CSS `width`, not a CSS-engine-internal reservation. Testing
+this class directly (two `overflow: hidden` boxes, one at the full width,
+one built by subtracting a deliberately-too-large amount from that same
+width, both containing identically-sized content that fits the full-width
+box but not the subtracted one) and hit-testing across the boundary: the
+full-width box does not clip the content at all (hit-testable to its own
+true edge, same as above), while the subtracted box clips it exactly at its
+own — genuinely narrower — border-box edge, with the DOM node's content
+completely un-hit-testable beyond that point. Unlike the `scrollbar-gutter`
+case, this clipping is real: the box is *actually* narrower, not just
+reporting a smaller `clientWidth` while remaining the same size. This
+confirms the general mechanism class master relies on (a wrapper narrowed by
+`maxWidth - <a JS-measured number>`) is capable of real clipping if that
+JS-measured number is ever larger than what the colgroup was actually sized
+against — it's just not the specific `scrollbar-gutter`-mismatch mechanism
+claimed in round two.
+
+**Verified, this round — the shipped fix (header/footer always
+`width: maxWidth`, never reduced) cannot be narrower than the `<colgroup>`
+it has to display, in any browser, regardless of what any scrollbar probe
+measures.** This is a structural argument, not a browser-specific empirical
+one:
+
+1. The shared `<colgroup>` widths come from measuring `<th>` elements inside
+ the sizer `<div>` (`useSticky.tsx`'s `useLayoutEffect`,
+ `ths.map(th => th.getBoundingClientRect()?.width)`).
+2. The sizer has no explicit `width` of its own — it's a plain block `<div>`
+ that takes the width of its containing block (the outermost wrapper,
+ which *is* `maxWidth` wide), then loses more of that to whatever real
+ vertical scrollbar it renders when its content needs to scroll (which is
+ exactly when column widths are being measured for `hasVerticalScroll:
+ true`). So `sizer.clientWidth <= maxWidth`, always, by construction —
+ this isn't contingent on any JS probe agreeing with anything.
+3. The sizer's own `<table>` is **not** given `table-layout: fixed` (only
+ header/body/footer's cloned tables get that via `mergeStyleProp(table,
+ fixedTableLayout)`), so it lays out with the browser's normal automatic
+ table layout, sizing each column from the *natural* content of
+ **all** of `thead`+`tbody`+`tfoot` together (the sizer renders all three
+ sections at once, unlike header/body/footer which each render only one).
+ That means the measured `<th>` widths already account for the total
+ row's actual content width whenever that content fits inside
+ `sizer.clientWidth` — which is the normal, in-scope case this fix
+ targets (see "Latent Bugs Found" for the narrow-chart case where it
+ doesn't fit at all, which is a separate, already-documented issue).
+4. Therefore the widths that end up in `<colgroup>` sum to at most
+ `sizer.clientWidth`, which is at most `maxWidth`.
+5. Header/footer's own `<table>` (with the same `<colgroup>`, under
+ `table-layout: fixed`, with no explicit table `width`) can only need up
+ to that same colgroup-derived width to render without visually
+ overflowing its own column boxes (browsers still let content wider than
+ its `<col>` spec expand a `table-layout: fixed` table when the table's
+ own `width` is `auto`, but the sizer already measured that expanded
+ need, so the colgroup value already includes it — the fixed-layout
+ tables don't need to grow further).
+
+Chaining these: the widest header/footer's own `<table>` will ever
+legitimately need to be is bounded by `sizer.clientWidth`, which is bounded
+by `maxWidth`. Setting header/footer's wrapper `width` to the full,
+never-reduced `maxWidth` (what the fix does) therefore can never be
+narrower than what the table needs — not "in the one browser tested," but
+as a consequence of where each number comes from. This is the actual reason
+the fix prevents the reported clipping, and it does not depend on
+`getCustomScrollBarSize()`'s accuracy in any browser, unlike master's
+subtraction-based width.
+
+**Still unverified/inferred — the exact browser condition that triggers the
+bug against unmodified master.** This is unchanged from round two and
+already accepted by review as a reasonable sandbox limit, so it is only
+summarized here: master's `width: maxWidth - scrollBarSize` is unsafe
+exactly when the JS-measured `scrollBarSize` is *larger* than whatever real
+reservation the sizer/body's own scrollbar actually took (see the previous
+paragraph's class-level demonstration for why that direction, specifically,
+causes real clipping). Sweeping chart widths (260px→190px) through the full
+shrink→grow-back sequence and six zoom levels (0.75×–1.5×) against
+unmodified master in real headed Chromium, `getCustomScrollBarSize()` and
+the sizer's real scrollbar reservation agreed at every single step in this
+sandbox — so the specific browser/OS/zoom condition that makes them disagree
+for the original reporter is not reproducible with the one Linux/Chromium
+build and X11 display available here. That the mechanism class itself is
+real (previous paragraph) is now on firmer ground than round two's specific
+(and now-retracted) numeric claim; that it's *master's* exact trigger
+remains an inference, not a reproduction.
**A more likely contributor to the exact reported persistence
("stays clipped after growing back"), inferred but grounded in a separately
@@ -118,78 +172,98 @@ verified defect:** see the `needScrollBar` height-comparison bug under
"Latent Bugs Found". It makes `hasVerticalScroll` switch on too easily and
switch back off only once the chart is grown by an extra
`theadHeight + tfootHeight` px beyond what's actually needed — i.e. it's
-easy for the scrollbar state, and the ~8px width reservation that comes with
-it, to stay "on" after a grow-back that should have turned it off. A Total
-value sized close to the chart's edge in the first place, combined with that
-stuck reservation, plausibly explains "shrink, then grow back, and it's
-still cut off" independent of whether the header/footer/body reservations
-agree with each other. This bug is real (verified by direct computation and
-by measurement) but left unfixed here — it's a distinct defect, and fixing
-it would change scrollbar-appearance behavior more broadly than this PR
-should.
-
-**Why the fix stands regardless of an unpinned master trigger:** master's
-approach relies on a JS probe built from a *synthetic, unrelated* DOM
-element correctly predicting what a browser's `scrollbar-gutter` CSS
-property will reserve on a *completely different* set of elements. I've
-shown this holds in the one real browser available here, but nothing
-guarantees it holds everywhere Superset runs — and I demonstrated, concretely
-and without forcing anything, that the moment any part of this file reserves
-gutter space through a path that isn't identical to the body/sizer's, real
-clipping results. The fix removes that reliance entirely: header, footer,
-body, and the sizer now all reserve scrollbar space through the exact same
-mechanism (`scrollbar-gutter: stable` plus the same custom scrollbar
-styling), so there is no longer a second, independently-measured number that
-could ever disagree.
+easy for the scrollbar state, and the width reservation that comes with it,
+to stay "on" after a grow-back that should have turned it off. Left unfixed
+here — a distinct defect, and fixing it would change scrollbar-appearance
+behavior more broadly than this PR should.
+
+**Why `scrollbarGutter`/`scrollBarStyles` are still applied to header/footer,
+even though they aren't what prevents the reported clipping (secondary,
+less rigorously verified rationale):** header/footer aren't purely
+decorative viewports — when `hasHorizontalScroll` is also true, their
+`<table>` is deliberately wider than the wrapper (the same over-wide
+`<colgroup>` as body), and `scrollLeft` is synced programmatically from body
+so header/footer scroll in lockstep as the user scrolls body horizontally
+(`onScroll` in `useSticky.tsx`). In that combined horizontal-and-vertical
+scroll case, body's *visible* content region is narrower than
+`maxWidth` by whatever its real, physically-rendered scrollbar occupies;
+if header/footer's clip viewport is the full, un-reduced `maxWidth` while
+body's real viewport is narrower, the same `scrollLeft` value would reveal a
+wider slice of the row in header/footer than what's actually visible in
+body, misaligning columns during horizontal scrolling. Matching
+`scrollbarGutter`/`scrollBarStyles` on header/footer keeps their reported
+`clientWidth` consistent with body's, which keeps that synced-scroll slice
+consistent too. I have not built a real-browser repro of this specific
+combined-scroll scenario (the reported bug, #21063, does not describe
+horizontal scrolling), so this is presented as a plausible, structurally
+motivated reason to keep the change, not a verified fix for a reproduced
+defect — unlike the `width: maxWidth` change above, which is verified.
+
+**Sizer/header/footer/body gutter symmetry is conditional, not
+unconditional.** The sizer's wrapper sets `scrollbarGutter: 'stable'`
+unconditionally (`useSticky.tsx`, sizer `<div>` style), while
+header/footer/body all set it conditionally —
+`hasVerticalScroll ? 'stable' : undefined`. So the four elements only agree
+on gutter reservation while `hasVerticalScroll` is `true`; while it's
+`false`, the sizer still reserves a gutter (it's `visibility: hidden` and
+only used for measurement, so this doesn't affect anything visible) while
+header/footer/body correctly reserve none, since there's no real scrollbar
+to make room for. This is existing, pre-fix behavior, not something this PR
+introduces or removes — it's noted here so this document doesn't claim an
+unconditional four-way symmetry that isn't actually there.
### How this was verified
jsdom (this repo's Jest environment) does not implement real CSS layout —
-`getBoundingClientRect`/`clientWidth` are stubbed — so this mechanism cannot
-be observed through a jsdom test. To avoid reasoning-only conclusions:
-
-1. Built a throwaway harness (`.scratch-repro/`, not part of this diff,
- removed before committing) that imports the **real, unmodified**
- `useSticky.tsx` through `react-table`, bundled with esbuild.
-2. Initially drove it with Playwright's default **headless** Chromium
- (already cached in this sandbox, no download needed). This is what
- produced the first (incorrect) conclusion above.
-3. On review pushback, re-ran the same harness against a **real, headed**
- Chromium session: started `Xvfb` directly (no `xauth` available in this
- sandbox, so `xvfb-run` didn't work; launched `Xvfb :99` manually and
- pointed `DISPLAY=:99` at a real `chromium.launch({ headless: false })`
- session) — genuine on-screen rendering, not headless approximation.
-4. Measured the same probe-vs-gutter comparison in both modes and found
- headless and headed Chromium disagree with each other on the probe's
- result (0px vs. 8px) even though they agree on the CSS-only
- `scrollbar-gutter` reservation (15px unstyled / 8px styled in both) —
- i.e. the divergence I first reported was an artifact of the headless
- probe technique, not a property of real rendering.
-5. Swept chart widths (260px→190px) through the full
- shrink→grow-back sequence, and six zoom levels, against unmodified
- master in the headed browser: no divergence between header/body/footer
- at any point.
-6. Reproduced real, non-forced clipping (190px container vs. 194px content)
- by testing an incomplete fix (`scrollbar-gutter` on header/footer without
- the matching `scrollBarStyles`) — in both headless and headed Chromium
- identically.
-7. Applied the corrected fix (`scrollBarStyles` + `scrollbar-gutter` on
- header/footer, matching body/sizer exactly) and reswept the same width
- range and resize sequence: header, body, and footer `clientWidth` are
- identical at every step, in both headless and headed Chromium.
-8. Also found (documented under Latent Bugs, not fixed): at chart widths
- narrow enough that the total's *unbreakable* natural width barely exceeds
- even the full, unreserved chart width, clipping occurs on **both** master
- and the fixed code, identically, at every resize step including before
- any scrollbar ever appears — this is a `table-layout: auto` sizer
- correctly refusing to shrink an unbreakable numeric string below its
- natural width, an orthogonal "chart is too narrow for this content at
- all" case, not the reservation-mismatch defect this fix addresses.
-
-This traces the defect through actual DOM state in a real, on-screen
-browser at each step, not just a prose description of what "should" happen
-— and this write-up says plainly where that tracing overturned an earlier,
-headless-only conclusion rather than smoothing over it.
+`getBoundingClientRect`/`clientWidth` are stubbed, and hit-testing APIs like
+`document.elementFromPoint` don't reflect real paint/clip behavior — so none
+of the claims above can be checked through a jsdom test. This round's
+verification used real, on-screen Chromium rendering plus explicit
+hit-testing (not just numeric comparisons) for exactly that reason:
+
+1. Started `Xvfb :99` directly (no `xauth` available in this sandbox, so
+ `xvfb-run` didn't work) and pointed `DISPLAY=:99` at
+ `chromium.launch({ headless: false })` via Playwright (already cached in
+ this sandbox) — genuine on-screen rendering.
+2. Built minimal, static HTML repros (not part of this diff, not committed)
+ reproducing the exact box models under dispute: (a) an `overflow: hidden`
+ wrapper with `scrollbar-gutter: stable` and the same
+ `::-webkit-scrollbar` styling as this file's `scrollBarStyles`,
+ containing content sized to reproduce round two's exact 190px/194px
+ `clientWidth`/content-width numbers; (b) the same comparison with the
+ *unstyled* (native, wider) scrollbar-gutter reservation, to match
+ header/footer's specific pre-fix state; (c) two `overflow: hidden`
+ wrappers differing only in whether their `width` is the full value or a
+ value reduced by subtraction, both containing identical over-wide
+ content, to isolate "phantom reservation" from "real narrowing."
+3. For each, measured `clientWidth`/`getBoundingClientRect()` as before,
+ but additionally swept `document.elementFromPoint(x, y)` across the
+ disputed boundary pixel-by-pixel to determine what is actually
+ hit-testable (i.e., actually painted and not clipped) at each point,
+ rather than inferring clipping from a comparison of two numbers.
+4. Result: the phantom-reservation repros (a) and (b) show content
+ hit-testable all the way to its own true edge, never clipped at the
+ reduced `clientWidth`; the real-narrowing repro (c) shows content
+ genuinely clipped, exactly at the narrower box's own true edge. This
+ directly falsifies round two's clipping claim while confirming the
+ mechanism class master's subtraction-based width relies on is capable of
+ real clipping when the subtracted amount is too large.
+5. Re-verified the structural `colgroup <= sizer.clientWidth <= maxWidth`
+ chain above by inspecting `useSticky.tsx` directly (this is a logical
+ argument about where each number is computed and from what container,
+ not something that needs a browser to check) rather than re-doing the
+ full chart-width sweep from round two, since round two's sweep already
+ established (and review already accepted) that master's own arithmetic
+ doesn't diverge from the sizer/body's reservation anywhere reproducible
+ in this sandbox — the open question was never "does the fixed code avoid
+ divergence," it's "does removing the subtraction entirely avoid the
+ *class* of bug regardless of divergence," which the structural argument
+ answers independently of any sweep.
+
+This traces both the retraction and the corrected argument through actual
+DOM state and hit-testing in a real, on-screen browser, and says plainly
+where it overturns round two's own conclusion rather than smoothing over
+it.
## Why It Wasn't Caught
@@ -214,31 +288,41 @@ condition this investigation had to build custom real-browser tooling
## The Fix
`superset-frontend/plugins/plugin-chart-table/src/DataTable/hooks/useSticky.tsx`,
-in `StickyWrap` (~lines 289-345):
+in `StickyWrap` (~lines 305-354), plus a
+`/** @jsxImportSource @emotion/react */` pragma added near the top of the
+file (see "Prevention" for why):
1. Removed the `headerContainerWidth = hasVerticalScroll ? maxWidth -
scrollBarSize : maxWidth` computation and the numeric
`width: headerContainerWidth` on the header/footer wrapper divs.
- Replaced with `width: maxWidth` plus
- `scrollbarGutter: hasVerticalScroll ? 'stable' : undefined` — the same
- CSS property the body div already uses.
-2. Also applied `css={scrollBarStyles}` (the same custom
- `::-webkit-scrollbar` styling the body/sizer already carry) to the
- header/footer wrapper divs. This step is required, not cosmetic:
- `scrollbar-gutter: stable`'s reserved width depends on this styling being
- present (verified above), so header/footer must carry it too or they
- reserve a different amount than the body/sizer just did.
-
-Header, body, footer, and the sizer that computes the shared `<colgroup>`
-widths now all derive their available width from the exact same mechanism,
-so they cannot disagree regardless of what any given browser's
-`::-webkit-scrollbar`-based JS probe measures. `getCustomScrollBarSize()` is
-untouched and still used for the separate, legitimate horizontal-scrollbar
-real-height reservation elsewhere in the same effect.
-
-This removes the divergent computation rather than compensating for it (e.g.
-no new "add a few px of buffer" fudge factor), because a buffer would itself
-be a browser/OS/zoom-dependent number with the exact same class of bug.
+ Replaced with an unconditional `width: maxWidth`. This is the change that
+ actually prevents the reported clipping: the shared `<colgroup>` is
+ always bounded by `sizer.clientWidth`, which is always bounded by
+ `maxWidth` (see Root Cause), so a header/footer wrapper that is *never*
+ narrowed below `maxWidth` can never be narrower than the table it has to
+ display, regardless of whether `getCustomScrollBarSize()` agrees with the
+ sizer/body's real scrollbar reservation in any given browser.
+2. Also added `scrollbarGutter: hasVerticalScroll ? 'stable' : undefined`
+ and `css={scrollBarStyles}` (the same custom `::-webkit-scrollbar`
+ styling the body/sizer already carry) to the header/footer wrapper divs.
+ **This step is not required to prevent the reported clipping** — real
+ hit-testing shows `scrollbar-gutter` on an `overflow: hidden` box changes
+ what `clientWidth` reports without moving where content actually clips
+ (see Root Cause) — but it is kept for a secondary, less rigorously
+ verified reason: keeping header/footer's reported `clientWidth`
+ consistent with body's keeps their synced `scrollLeft` viewport
+ consistent with body's real, physically-scrollbar-reduced viewport when
+ both horizontal and vertical scrolling are active simultaneously.
+
+`getCustomScrollBarSize()` is untouched and still used for the separate,
+legitimate horizontal-scrollbar real-height reservation elsewhere in the
+same effect.
+
+This removes the divergent, subtraction-based computation rather than
+compensating for it (e.g. no new "add a few px of buffer" fudge factor),
+because a buffer would itself be a browser/OS/zoom-dependent number with the
+exact same class of bug, and because the un-reduced `width: maxWidth` is
+already provably wide enough without needing to guess at a safety margin.
## Alternatives Considered
@@ -260,6 +344,16 @@ be a browser/OS/zoom-dependent number with the exact same class of bug.
*width-reservation-consistency* logic), fixing it changes when scrollbars
appear/disappear more broadly than this bug fix should, and the
independent review already agreed it should stay out of scope.
+- **Drop `scrollbarGutter`/`scrollBarStyles` from header/footer, keeping
+ only the unconditional `width: maxWidth` change.** Considered once real
+ hit-testing showed these aren't what prevents the reported clipping (see
+ Root Cause). Kept anyway: while unverified against a reproduced defect,
+ they're not free of purpose either — dropping them would let header/footer
+ report a wider `clientWidth` than body during simultaneous horizontal and
+ vertical scrolling, which is plausibly a real (if different) column
+ misalignment risk during synced horizontal scroll. Removing them, on the
+ evidence available here, would trade a proven-unnecessary line of CSS for
+ a plausible new alignment gap, which isn't a clear improvement.
## Latent Bugs Found
@@ -301,14 +395,37 @@ Added `plugins/plugin-chart-table/test/DataTable/hooks/useSticky.test.tsx`,
which mounts `useSticky`'s `StickyWrap` for real (via `react-table`) with
mocked DOM measurements that force `hasVerticalScroll: true`, and mocks
`getCustomScrollBarSize()` to return a value distinguishable from any
-CSS-computed one. It asserts the header/footer wrapper's `style.width` and
-`style.scrollbarGutter` match the body's — i.e. it pins the invariant
-("header, body, and footer must derive their available width from the same
-mechanism") rather than any specific pixel value. It fails against the
-pre-fix code (`258px` vs. expected `300px`, since
-`300 - 42 (mocked probe) = 258`) and passes after the fix. Note this jsdom
-test cannot verify the `scrollBarStyles`/`css` prop half of the fix (emotion's
-`css` prop doesn't resolve to an observable `className` in this repo's Jest
-setup — confirmed empirically before settling on this assertion shape), only
-the `style.width`/`style.scrollbarGutter` half; the `scrollBarStyles`
-requirement is verified instead by the real-browser harness described above.
+CSS-computed one. It asserts:
+
+1. The header/footer wrapper's `style.width` and `style.scrollbarGutter`
+ match the body's — i.e. it pins the invariant ("header, body, and footer
+ must derive their available width from the same mechanism") rather than
+ any specific pixel value. Fails against the pre-fix code (`258px` vs.
+ expected `300px`, since `300 - 42 (mocked probe) = 258`) and passes after
+ the fix.
+2. The header/footer wrapper's `className` is non-empty and matches the
+ body's — pinning the `css={scrollBarStyles}` half of the fix.
+
+The `className` assertion needed one more thing to be observable at all:
+`useSticky.tsx` now carries a `/** @jsxImportSource @emotion/react */`
+pragma (added just below the license header). Without it, this repo's
+Jest/Babel setup passes the `css` prop straight through to the DOM as an
+inert string attribute (`css="[object Object]"`, confirmed empirically —
+`headerDiv.getAttribute('css')` returned exactly that before the pragma was
+added) instead of resolving it through Emotion's JSX runtime into a real
+class, because — unlike the webpack/SWC production build, which sets
+`importSource: '@emotion/react'` globally for every file
+(`webpack.config.js`, `createSwcLoader`) — this repo's `babel.config.js`
+does not set the equivalent `importSource` for `@babel/preset-react` in its
+Jest (`test`) env, and no file in this codebase currently carries the
+per-file pragma that would substitute for it. Adding the pragma to this one
+file makes Babel treat it exactly the way SWC already treats every file in
+the real build (both resolve to the same `@emotion/react` JSX runtime): the
+per-file pragma specifies the identical import source SWC already applies
+globally, so it changes nothing about the shipped, webpack-built behavior —
+it only changes what Jest's separate Babel pipeline can observe. This test
+fails on the commit before
+`css={scrollBarStyles}` was added to header/footer (header/footer
+`className` is `''` while body's is populated) and passes on the fix
+(verified by temporarily reverting just the two `css={scrollBarStyles}`
+additions and re-running the test, then restoring them).
diff --git a/superset-frontend/plugins/plugin-chart-table/src/DataTable/hooks/useSticky.tsx b/superset-frontend/plugins/plugin-chart-table/src/DataTable/hooks/useSticky.tsx
index 17beb1afa9d..aa2848a3499 100644
--- a/superset-frontend/plugins/plugin-chart-table/src/DataTable/hooks/useSticky.tsx
+++ b/superset-frontend/plugins/plugin-chart-table/src/DataTable/hooks/useSticky.tsx
@@ -16,6 +16,8 @@
* specific language governing permissions and limitations
* under the License.
*/
+
+/** @jsxImportSource @emotion/react */
import {
Children,
cloneElement,
diff --git a/superset-frontend/plugins/plugin-chart-table/test/DataTable/hooks/useSticky.test.tsx b/superset-frontend/plugins/plugin-chart-table/test/DataTable/hooks/useSticky.test.tsx
index 2393c8b3df4..5913159d10d 100644
--- a/superset-frontend/plugins/plugin-chart-table/test/DataTable/hooks/useSticky.test.tsx
+++ b/superset-frontend/plugins/plugin-chart-table/test/DataTable/hooks/useSticky.test.tsx
@@ -167,5 +167,22 @@ test('sticky header/footer width matches the body, independent of the scrollbar-
expect(footerDiv.style.scrollbarGutter).toBe(bodyDiv.style.scrollbarGutter);
expect(bodyDiv.style.scrollbarGutter).toBe('stable');
+ // Pin the `css={scrollBarStyles}` addition to header/footer directly: this
+ // component carries `/** @jsxImportSource @emotion/react */`, which makes
+ // Babel route its `css` prop through Emotion's jsx runtime instead of
+ // passing `css` straight through as an inert DOM attribute (the default in
+ // this repo's Jest/Babel setup, which -- unlike the webpack/SWC build --
+ // doesn't set `importSource: '@emotion/react'` globally). With the pragma
+ // in place, an applied `css` prop is observable as a real, non-empty
+ // className, so this assertion actually fails without the fix instead of
+ // passing regardless of whether `scrollBarStyles` is wired up.
+ //
+ // Before `css={scrollBarStyles}` was added to header/footer, they had no
+ // emotion-generated class at all (`className === ''`) while the body kept
+ // its own -- so this fails pre-fix and passes post-fix.
+ expect(headerDiv.className).not.toBe('');
+ expect(headerDiv.className).toBe(bodyDiv.className);
+ expect(footerDiv.className).toBe(bodyDiv.className);
+
jest.restoreAllMocks();
});