sadpandajoe opened a new pull request, #35456:
URL: https://github.com/apache/superset/pull/35456

   <!---
   Please write the PR title following the conventions at 
https://www.conventionalcommits.org/en/v1.0.0/
   Example:
   fix(dashboard): load charts correctly
   -->
   
   ### SUMMARY
   
   Fixes intermittent test failure in DatasetUsageTab causing "document global 
was defined..." React error.
   
   **Problem**: PR #34707 introduced an unmanaged `setTimeout` in the 
`handlePageChange` callback that caused async updates after test cleanup. When 
the component unmounted before the 100ms timeout fired, React would throw an 
error about the missing document global.
   
   **Root Cause**: The pagination scroll behavior used a bare `setTimeout` 
without cleanup:
     ```typescript
     setTimeout(() => {
       const tableBody = 
tableContainerRef.current?.querySelector('.ant-table-body');
       if (tableBody) {
         tableBody.scrollTo({ top: 0, behavior: 'smooth' });
       }
     }, 100);
    ```
   
   **Solution:** Implement proper timeout cleanup using useRef + useEffect:
     - Track timeout IDs with scrollTimeoutRef
     - Clear timeout on component unmount via cleanup function
     - Clear pending timeouts before setting new ones (prevents duplicate 
scrolls)
     - Set ref to null after timeout executes
   
   ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
   <!--- Skip this if not applicable -->
   
   ### TESTING INSTRUCTIONS
   <!--- Required! What steps can be taken to manually verify the changes? -->
   1. Verify tests pass: `npm test -- DatasetUsageTab.test.tsx`
   2. Expected: All 12 tests pass, including the 3 new timeout cleanup tests
   3. Verify no intermittent errors: `npm test -- ExploreChartPanel 
DatasetUsageTab`
   4. Expected: All 20 tests pass without "document global was defined..." error
   5. Test manual pagination (if testing UI):
       - Navigate to a dataset with >25 charts
       - Click pagination rapidly (page 2 → page 3 → page 4)
       - Verify table scrolls to top smoothly without duplicate scroll 
operations
   
   ### ADDITIONAL INFORMATION
   <!--- Check any relevant boxes with "x" -->
   <!--- HINT: Include "Fixes #nnn" if you are fixing an existing issue -->
   - [ ] Has associated issue:
   - [ ] Required feature flags:
   - [ ] Changes UI
   - [ ] Includes DB Migration (follow approval process in 
[SIP-59](https://github.com/apache/superset/issues/13351))
     - [ ] Migration is atomic, supports rollback & is backwards-compatible
     - [ ] Confirm DB migration upgrade and downgrade tested
     - [ ] Runtime estimates and downtime expectations provided
   - [ ] Introduces new feature or API
   - [ ] Removes existing feature or API
   


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