Frun1na opened a new pull request, #6802:
URL: https://github.com/apache/rocketmq-dashboard/pull/6802

   ### Which Issue(s) This PR Fixes
   
   - Fixes #6412
   
   ### Brief Description
   
   `useVisiblePolling` queues each poll as `Promise.resolve().then(poll)`, and 
the effect cleanup can only clear the interval and the listener: a poll queued 
by a timer tick or a `visibilitychange` event still ran when live refresh was 
disabled, the callback or interval changed, the page went hidden, or the 
component unmounted in between - the obsolete request started anyway. The 
visibility check was performed only before queueing.
   
   The queue now re-checks the effect's liveness (`active`) and 
`document.visibilityState` immediately before invoking `poll`, while a request 
that has already started keeps holding the shared in-flight guard (issue #6412: 
"keeping the existing shared in-flight guard for requests already started"). 
The `.finally` still releases that guard by identity, so a discarded queue 
leaves polling able to resume. Only this hook and its test change.
   
   This re-implements the approach of #6420, which the stale bot closed on 
2026-10-15 without review (credits to its author, Loyal-Young); the issue 
stayed open. As #6412 itself notes, the previous fixes cover overlap and timer 
cleanup, not an already queued Promise callback - the open #5194 is also a 
different surface (a page-level request staleness counter), so this is not a 
duplicate of it.
   
   ### How Did You Test This Change?
   
   ```
   $ cd web && npx vitest run src/hooks/useVisiblePolling.test.tsx
    ✓ src/hooks/useVisiblePolling.test.tsx (10 tests) 33ms
    Test Files  1 passed (1)
         Tests  10 passed (10)
   ```
   
   The mapped checks for the two changed files:
   
   ```
   $ npx eslint src/hooks/useVisiblePolling.test.tsx 
src/hooks/useVisiblePolling.ts   # clean
   $ npx prettier --check src/hooks/useVisiblePolling.test.tsx 
src/hooks/useVisiblePolling.ts
   Checking formatting...
   All matched files use Prettier code style!
   $ npx vitest related --run src/hooks/useVisiblePolling.test.tsx 
src/hooks/useVisiblePolling.ts
    Test Files  4 passed (4)
         Tests  47 passed (47)
   $ npx tsc -b        # clean
   ```
   
   The new tests fail without the fix (base hook, new tests kept), for the 
disabled, unmounted and hidden cases plus the resume case:
   
   ```
   $ git checkout -- web/src/hooks/useVisiblePolling.ts
   $ npx vitest run src/hooks/useVisiblePolling.test.tsx
    ❯ src/hooks/useVisiblePolling.test.tsx (10 tests | 4 failed) 33ms
        × discardsAQueuedPollAfterdisableTest 5ms
        × discardsAQueuedPollAfterunmountTest 2ms
        × discardsAQueuedPollAfterhiddenTest 1ms
        × keeps polling after a hidden poll is discardedTest 2ms
   AssertionError: expected "vi.fn()" to not be called at all, but actually 
been called 1 times
    Test Files  1 failed (1)
         Tests  4 failed | 6 passed (10)
   ```
   
   The parameterized case queues a poll synchronously and then disables, 
unmounts or hides the effect's world before draining the microtask; each 
assertion names the queued callback that must not run, and the hidden case then 
asserts that the guard is free again and the next visible tick polls. Restoring 
the fix turns all four green.
   
   ### Checklist
   
   - [x] One coherent change; unrelated modifications are not bundled in
   - [x] Commit subject follows Conventional Commits (`feat:` / `fix:` / 
`refactor:` / `chore:` / `docs:` / `perf:`)
   - [x] Tests added or updated for non-trivial changes, test methods named 
`...Test`
   - [ ] New UI text has both Chinese and English entries under `web/src/i18n/`
   - [ ] Architecture constraints stay green (`mvn test` runs the ArchUnit 
checks)
   - [ ] New source files carry the ASF license header
   - [ ] Documentation touched where behaviour changed (README / `docs/` / 
in-app help)
   


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

Reply via email to