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/18 05:10:56 UTC

(superset) 01/01: fix(dashboard): stop table charts bleeding over neighbours in image export

This is an automated email from the ASF dual-hosted git repository.

sadpandajoe pushed a commit to branch ultraset-fix-40428
in repository https://gitbox.apache.org/repos/asf/superset.git

commit c003968bbc6bd717cb346cbbb483409e0ebce8f2
Author: sadpandajoe <47...@users.noreply.github.com>
AuthorDate: Fri Sep 18 05:10:39 2026 +0000

    fix(dashboard): stop table charts bleeding over neighbours in image export
    
    The clone-based image export copies every computed style inline, including
    `overflow`, so `processCloneForVisibility`'s `[style*="overflow"]` selector
    matches effectively every node in the clone rather than just scroll
    containers. Each match had its `overflow` shorthand set to `visible`, which
    unclipped both axes.
    
    Unclipping the vertical axis is what makes the whole table paint (#34233):
    heights become `auto`, the chart holder grows and the dashboard grid reflows
    around it. The horizontal axis is different - the clone keeps every element's
    on-screen pixel width - so a table that scrolls sideways painted its off-slot
    columns straight across the charts sitting next to it in the same dashboard
    row.
    
    Keep the horizontal clip for dashboard captures, and only rewrite `overflow`
    on elements that actually clip, so elements that never clipped on screen are
    not newly clipped. Single-chart captures have no neighbours to overlap and
    keep expanding on both axes.
    
    Fixes #40428
    
    Co-Authored-By: Claude Opus 5 <no...@anthropic.com>
---
 .../src/utils/downloadAsImage.test.ts              | 60 +++++++++++++++++++++-
 superset-frontend/src/utils/downloadAsImage.tsx    | 34 ++++++++++--
 2 files changed, 89 insertions(+), 5 deletions(-)

diff --git a/superset-frontend/src/utils/downloadAsImage.test.ts b/superset-frontend/src/utils/downloadAsImage.test.ts
index 979a867a895..3bf68aafcc5 100644
--- a/superset-frontend/src/utils/downloadAsImage.test.ts
+++ b/superset-frontend/src/utils/downloadAsImage.test.ts
@@ -644,9 +644,34 @@ test('falls through to clone path for dashboard export with multiple ag-grid cha
   document.body.removeChild(dashboard);
 });
 
-test('captures JPEG for non-ag-grid elements via the clone path', async () => {
+// A chart holding a table that scrolls in both axes, in a slot that never clips
+function buildScrollableChartElement(rootClassName?: string) {
   const container = document.createElement('div');
+  if (rootClassName) {
+    container.className = rootClassName;
+  }
+  const slot = document.createElement('div');
+  slot.className = 'chart-slot';
+  slot.style.overflow = 'visible';
+  slot.style.width = '100px';
+  const scrollContainer = document.createElement('div');
+  scrollContainer.className = 'scroll-container';
+  scrollContainer.style.overflow = 'auto';
+  scrollContainer.style.width = '100px';
+  scrollContainer.style.height = '50px';
+  const wideContent = document.createElement('div');
+  wideContent.style.width = '400px';
+  wideContent.style.height = '300px';
+  wideContent.textContent = 'wide table content';
+  scrollContainer.appendChild(wideContent);
+  slot.appendChild(scrollContainer);
+  container.appendChild(slot);
   document.body.appendChild(container);
+  return { container, cleanup: () => document.body.removeChild(container) };
+}
+
+test('captures JPEG for non-ag-grid elements via the clone path', async () => {
+  const { container, cleanup } = buildScrollableChartElement();
 
   const handler = downloadAsImageOptimized('div', 'Bar Chart');
   await handler(syntheticEventFor(container));
@@ -655,9 +680,40 @@ test('captures JPEG for non-ag-grid elements via the clone path', async () => {
     expect.any(HTMLElement),
     expect.objectContaining({ quality: 0.95 }),
   );
+  // A single chart has no neighbours to overlap, so its scrollable content is
+  // expanded on both axes and the whole table makes it into the image
+  const clone = mockToJpeg.mock.calls[0][0] as HTMLElement;
+  const clonedScrollContainer = clone.querySelector(
+    '.scroll-container',
+  ) as HTMLElement;
+  expect(clonedScrollContainer.style.height).toBe('auto');
+  expect(clonedScrollContainer.style.overflow).toBe('visible');
   expect(mockAddWarningToast).not.toHaveBeenCalled();
 
-  document.body.removeChild(container);
+  cleanup();
+});
+
+test('dashboard clone path expands scrollable content vertically without unclipping it horizontally', async () => {
+  const { container, cleanup } = buildScrollableChartElement('dashboard');
+
+  const handler = downloadAsImageOptimized('div', 'My Dashboard');
+  await handler(syntheticEventFor(container));
+
+  const clone = mockToJpeg.mock.calls[0][0] as HTMLElement;
+  const clonedScrollContainer = clone.querySelector(
+    '.scroll-container',
+  ) as HTMLElement;
+  // Vertical: grows so every row is captured and the grid reflows around it
+  expect(clonedScrollContainer.style.height).toBe('auto');
+  expect(clonedScrollContainer.style.overflowY).toBe('visible');
+  // Horizontal: stays clipped, otherwise a sideways-scrolling table paints its
+  // off-slot columns over the charts next to it in the same dashboard row
+  expect(clonedScrollContainer.style.overflowX).toBe('hidden');
+  // The slot never clipped on screen, so the export must not start clipping it
+  const clonedSlot = clone.querySelector('.chart-slot') as HTMLElement;
+  expect(clonedSlot.style.overflowX).not.toBe('hidden');
+
+  cleanup();
 });
 
 test('shows warning toast when clone capture throws', async () => {
diff --git a/superset-frontend/src/utils/downloadAsImage.tsx b/superset-frontend/src/utils/downloadAsImage.tsx
index 61c7d34c512..3374f3702f6 100644
--- a/superset-frontend/src/utils/downloadAsImage.tsx
+++ b/superset-frontend/src/utils/downloadAsImage.tsx
@@ -159,7 +159,22 @@ const copyAllComputedStyles = (
   }
 };
 
-const processCloneForVisibility = (clone: HTMLElement) => {
+// True when the element clips its content on at least one axis. `copyAllComputedStyles`
+// writes the computed `overflow` inline on the whole tree, so `[style*="overflow"]` below
+// matches nearly every node; only the ones that actually clip should have their overflow
+// rewritten. Both the shorthand and the longhands are read because engines disagree on
+// which of them a computed style resolves.
+const clipsOverflow = (element: HTMLElement) => {
+  const computed = window.getComputedStyle(element);
+  return /auto|scroll|hidden/.test(
+    `${computed.overflow} ${computed.overflowX} ${computed.overflowY}`,
+  );
+};
+
+const processCloneForVisibility = (
+  clone: HTMLElement,
+  clipHorizontalOverflow = false,
+) => {
   const cloneStyle = clone.style;
   cloneStyle.height = 'auto';
   cloneStyle.maxHeight = 'none';
@@ -183,9 +198,20 @@ const processCloneForVisibility = (clone: HTMLElement) => {
   scrollableSelectors.forEach(selector => {
     clone.querySelectorAll(selector).forEach(el => {
       const element = el as HTMLElement;
-      element.style.overflow = 'visible';
       element.style.height = 'auto';
       element.style.maxHeight = 'none';
+      if (!clipsOverflow(element)) return;
+      if (clipHorizontalOverflow) {
+        // Unclipping the vertical axis lets the whole chart paint while the grid
+        // reflows around its now auto-height slot. The horizontal axis keeps its
+        // clip: the clone preserves every element's on-screen pixel width, so a
+        // table that scrolls sideways would otherwise paint its off-slot columns
+        // across the charts sitting next to it in the same dashboard row.
+        element.style.overflowX = 'hidden';
+        element.style.overflowY = 'visible';
+      } else {
+        element.style.overflow = 'visible';
+      }
     });
   });
 
@@ -302,6 +328,7 @@ const createEnhancedClone = (
   originalElement: Element,
   theme?: SupersetTheme,
   getInstanceByDom?: EChartsGetInstanceByDom,
+  clipHorizontalOverflow = false,
 ): { clone: HTMLElement; cleanup: () => void } => {
   const clone = originalElement.cloneNode(true) as HTMLElement;
   copyAllComputedStyles(originalElement, clone, theme);
@@ -319,7 +346,7 @@ const createEnhancedClone = (
   tempContainer.appendChild(clone);
   document.body.appendChild(tempContainer);
 
-  processCloneForVisibility(clone);
+  processCloneForVisibility(clone, clipHorizontalOverflow);
 
   const cleanup = () => {
     if (tempContainer.parentElement) {
@@ -583,6 +610,7 @@ export default function downloadAsImageOptimized(
         elementToPrint,
         theme,
         getInstanceByDom,
+        isDashboardCapture,
       );
       cleanup = cleanupFn;