@uppy/core: destroy() does not cancel the initial online-status timeout
Initial checklist
- I understand this is a bug report and questions should be posted in the Community Forum.
- I searched existing issues and linked relevant results below.
Link to runnable example
Proposed fix with regression tests
Steps to reproduce
Reproduced with @uppy/core 6.0.1, jsdom 26.1.0, and Node.js 26.5.0. The example requires no React or Vitest.
git clone --branch codex/uppy-destroy-timeout \
https://github.com/beaussan/github-repros.git uppy-destroy-timeout
cd uppy-destroy-timeout
pnpm install --frozen-lockfile
pnpm reproThe script creates an Uppy instance, immediately destroys it, then tears down the DOM:
import Uppy from '@uppy/core'
import { JSDOM } from 'jsdom'
const dom = new JSDOM('<!doctype html>')
globalThis.window = dom.window
const uppy = new Uppy()
uppy.destroy()
dom.window.close()
delete globalThis.windowApproximately three seconds later, the pending callback throws:
ReferenceError: window is not defined
at Uppy.updateOnlineStatus (.../@uppy/core/lib/Uppy.js:1135:24)To demonstrate the lifecycle issue without removing window, run:
pnpm controlThis retains the DOM and logs an is-online event emitted after destroy().
Expected behavior
destroy() cancels the pending initial online-status check. The destroyed instance should not execute that callback or emit its online-status events.
Actual behavior
The timeout remains scheduled after destruction.
In a browser environment, the callback still runs against the destroyed instance. When the DOM environment has been torn down, it throws because window is no longer available.
We originally encountered this intermittently in Vitest/jsdom with @uppy/core 5.2.0: all test assertions passed, but the delayed exception failed the task. The standalone reproduction confirms the same issue in 6.0.1. We have not established a user-visible production failure.
The initial check is scheduled without retaining its handle:
setTimeout(this.#updateOnlineStatus, 3000)Meanwhile, destroy() removes the online/offline event listeners but does not cancel this timeout.
Proposed fix: retain the timeout handle and clear it in destroy(). The patched reproduction includes that change and tests demonstrating:
| Test | Unpatched 6.0.1 | Patched |
|---|---|---|
| No exception after destruction and DOM teardown | Fails | Passes |
| No delayed online-status event after destruction | Fails | Passes |
| Live instances retain their initial check and event handling | Passes | Passes |
Both original real-timer reproduction commands also exit successfully with the patch.
Related: #3026 addressed online/offline event-listener cleanup. This report concerns the separately scheduled timeout.
Source: transloadit/uppy