jenwitteng commented on code in PR #42561:
URL: https://github.com/apache/superset/pull/42561#discussion_r3673629123


##########
superset-frontend/src/utils/downloadUtils.ts:
##########
@@ -0,0 +1,84 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+import { FeatureFlag, isFeatureEnabled } from '@superset-ui/core';
+import { t } from '@apache-superset/core/translation';
+import { logging } from '@apache-superset/core/utils';
+import { addWarningToast } from 'src/components/MessageToasts/actions';
+import {
+  FORCE_IN_VIEW_EVENT,
+  RESTORE_VIRTUALIZATION_EVENT,
+} from 'src/dashboard/constants';
+
+/**
+ * Poll until all `.loading` spinners inside a container disappear,
+ * indicating that lazy-loaded charts have finished rendering.
+ * Returns true if all charts loaded, false if timed out.
+ */
+function waitForChartsToLoad(
+  container: Element,
+  timeoutMs = 60_000,
+): Promise<boolean> {
+  return new Promise(resolve => {
+    const startTime = Date.now();
+    const check = () => {
+      const loadingElements = container.querySelectorAll('.loading');
+      if (loadingElements.length === 0) {
+        resolve(true);
+        return;
+      }
+      if (Date.now() - startTime > timeoutMs) {
+        logging.warn(
+          `Timed out waiting for ${loadingElements.length} chart(s) to load`,
+        );
+        resolve(false);
+        return;
+      }
+      setTimeout(check, 500);
+    };
+    setTimeout(check, 1000);
+  });
+}
+
+/**
+ * When DASHBOARD_VIRTUALIZATION is enabled, forces all lazy-loaded
+ * charts to render and waits for them to finish loading.
+ * Returns true if virtualization was active (caller must restore it).
+ */
+export async function forceLoadAllCharts(container: Element): Promise<boolean> 
{
+  const useVirtualization = isFeatureEnabled(
+    FeatureFlag.DashboardVirtualization,
+  );
+  if (useVirtualization) {
+    window.dispatchEvent(new Event(FORCE_IN_VIEW_EVENT));
+    const allLoaded = await waitForChartsToLoad(container);
+    if (!allLoaded) {
+      addWarningToast(
+        t('Some charts did not finish loading. The export may be incomplete.'),
+      );
+    }
+  }
+  return useVirtualization;
+}
+
+/**
+ * Restores normal lazy loading behavior after a forced load.
+ */
+export function restoreVirtualization(): void {
+  window.dispatchEvent(new Event(RESTORE_VIRTUALIZATION_EVENT));
+}

Review Comment:
   REAL, but genuinely MINOR
   
   Confirmed reachable: restoreVirtualization() fires a global event with no 
ref-count, and the menu handlers (DownloadMenuItems/index.tsx:93-111) fire the 
exports without an isExporting guard. If you deliberately re-trigger a second 
export during the
     first's multi-second capture, RESTORE(A) can revert far-off rows to 
spinners mid-capture of export B.
   
     But it's bounded: requires DASHBOARD_VIRTUALIZATION + a tall (>4-viewport) 
dashboard + a deliberate second export in the capture window; only the second 
export degrades, the user gets an explicit "export may be incomplete" warning, 
and it self-heals
     (every exit path restores). Not a merge blocker.
   
     ⚠️  Important: the bots' proposed ref-count fix is the wrong fix — one 
missed decrement on any exit path (e.g. the ag-grid early-return) would pin 
virtualization forced-on for the entire session, a worse bug. The correct 
hardening is an in-flight guard
     that disables/early-returns the Export menu items while an export runs.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to