bito-code-review[bot] commented on PR #42561:
URL: https://github.com/apache/superset/pull/42561#issuecomment-5116478265

   <!-- Bito Reply -->
   The flagged race condition is correct. Because 
`RESTORE_VIRTUALIZATION_EVENT` is dispatched globally without tracking active 
exports, concurrent exports will interfere with each other's virtualization 
state. 
   
   To resolve this, you can implement a simple reference counter in 
`superset-frontend/src/utils/downloadUtils.ts` to ensure virtualization is only 
restored when the last active export finishes. 
   
   ### Proposed Fix
   
   Update `downloadUtils.ts` to track active exports:
   
   ```typescript
   let activeExportCount = 0;
   
   export async function forceLoadAllCharts(container: Element): 
Promise<boolean> {
     const useVirtualization = 
isFeatureEnabled(FeatureFlag.DashboardVirtualization);
     if (useVirtualization) {
       if (activeExportCount === 0) {
         window.dispatchEvent(new Event(FORCE_IN_VIEW_EVENT));
       }
       activeExportCount++;
       const allLoaded = await waitForChartsToLoad(container);
       // ... (rest of logic)
     }
     return useVirtualization;
   }
   
   export function restoreVirtualization(): void {
     activeExportCount = Math.max(0, activeExportCount - 1);
     if (activeExportCount === 0) {
       window.dispatchEvent(new Event(RESTORE_VIRTUALIZATION_EVENT));
     }
   }
   ```
   
   Would you like me to fetch all other comments on this PR to validate and 
implement fixes for them as well?
   
   **superset-frontend/src/utils/downloadUtils.ts**
   ```
   let activeExportCount = 0;
   
   export async function forceLoadAllCharts(container: Element): 
Promise<boolean> {
     const useVirtualization = 
isFeatureEnabled(FeatureFlag.DashboardVirtualization);
     if (useVirtualization) {
       if (activeExportCount === 0) {
         window.dispatchEvent(new Event(FORCE_IN_VIEW_EVENT));
       }
       activeExportCount++;
       const allLoaded = await waitForChartsToLoad(container);
       // ... (rest of logic)
     }
     return useVirtualization;
   }
   
   export function restoreVirtualization(): void {
     activeExportCount = Math.max(0, activeExportCount - 1);
     if (activeExportCount === 0) {
       window.dispatchEvent(new Event(RESTORE_VIRTUALIZATION_EVENT));
     }
   }
   ```


-- 
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