This is an automated email from the ASF dual-hosted git repository. sadpandajoe pushed a commit to branch fix-report-dashboard-screenshot-whitespace in repository https://gitbox.apache.org/repos/asf/superset.git
commit 318e2cd652cad90625de1ffbe69795fb8aa430cb Author: Joe Li <[email protected]> AuthorDate: Mon Nov 16 01:08:13 2026 +0000 fix(reports): nominate the page colour from a rendered dashboard grid A tab that is not selected keeps its dashboard grid in the document, hidden and possibly first. Nominating the page background from the plain first match walked up from that hidden pane to the body and nominated the body colour instead of the colour of the visible dashboard shell, which could trim a footer painted in the body colour at the bottom edge of the capture. Nominate from the first dashboard grid that has a layout box and is not visibility: hidden, and decline when none is rendered. Add a regression for a hidden first grid with a display: none and a visibility: hidden wrapper on the standard and tiled capture paths. --- superset/utils/screenshot_utils.py | 12 +++++-- .../utils/test_report_screenshot_height.py | 40 ++++++++++++++++++++++ 2 files changed, 49 insertions(+), 3 deletions(-) diff --git a/superset/utils/screenshot_utils.py b/superset/utils/screenshot_utils.py index 7e24d7c1e8a..707f5a55012 100644 --- a/superset/utils/screenshot_utils.py +++ b/superset/utils/screenshot_utils.py @@ -820,15 +820,21 @@ async (maxWaitMs) => {{ # Nominates the colour of the page behind the dashboard, for trimming a capture. -# It is the opaque background of the innermost box, among the first +# It is the opaque background of the innermost box, among the first rendered # ``.dashboard-grid`` and its ancestors, whose border box covers the whole page # (``html`` always counts; ``body`` counts whenever ``html`` paints nothing, per # CSS canvas propagation). The body colour alone is not enough: the app shell # paints ``body`` one colour and covers it with layout boxes of another. The -# result is only a nomination; the image must confirm it row by row. +# result is only a nomination; the image must confirm it row by row. The grid is +# the first one that is rendered: a tab that is not selected keeps its grid in +# the document, hidden and possibly first, and walking up from it would nominate +# the body colour instead of the colour of the dashboard shell. PAGE_BACKGROUND_COLOR_JS = r""" () => { - const grid = document.querySelector('.dashboard-grid'); + const isRendered = (el) => el.getClientRects().length > 0 + && getComputedStyle(el).visibility !== 'hidden'; + const grid = Array.from(document.querySelectorAll('.dashboard-grid')) + .find(isRendered); if (!grid) { return null; } const root = document.documentElement; const pageWidth = root.scrollWidth; diff --git a/tests/unit_tests/utils/test_report_screenshot_height.py b/tests/unit_tests/utils/test_report_screenshot_height.py index 8712153f121..53b586ee904 100644 --- a/tests/unit_tests/utils/test_report_screenshot_height.py +++ b/tests/unit_tests/utils/test_report_screenshot_height.py @@ -400,6 +400,46 @@ def test_capture_keeps_a_footer_that_holds_a_dashboard_grid_node( assert _band(trimmed, RED) == (1800, 2000) +_UNRENDERED_GRIDS = { + "display_none": ( + '<div style="display:none"><div class="dashboard-grid"></div></div>' + ), + "visibility_hidden": ( + '<div style="visibility:hidden"><div class="dashboard-grid"></div></div>' + ), +} + + +@PATHS [email protected]("hidden_grid", list(_UNRENDERED_GRIDS)) +def test_capture_keeps_a_footer_when_the_first_grid_is_not_rendered( + app: Any, chromium: Any, tmp_path: Path, tiled: bool, hidden_grid: str +) -> None: + """A hidden pane (a tab that is not selected) can come first in the document. + + Nominating the page colour from it would walk up to ``body`` and pick the + body colour instead of the colour of the dashboard shell, and the footer + painted in the body colour would be trimmed away. + """ + footer = ( + f'<div style="{_FIXED};bottom:0;height:200px;background:{_rgb(WHITE)}"></div>' + ) + url = _write_page( + tmp_path, + _dashboard_page( + _chart_row(1, 400, BLUE), + before_app=_UNRENDERED_GRIDS[hidden_grid], + after_app=footer, + ), + ) + base = _capture(app, chromium, url, trim=False, tiled=tiled) + assert _band(base, WHITE) == (1800, 2000) + + trimmed = _capture(app, chromium, url, trim=True, tiled=tiled) + assert _size(trimmed) == (1600, 2000) + assert _band(trimmed, WHITE) == (1800, 2000) + + def test_capture_without_the_opt_in_keeps_the_window( app: Any, chromium: Any, tmp_path: Path ) -> None:
