Skip to content

fix: treat loadMedia timeout of 0 as a zero-ms timeout instead of no timeout - #171

Open
razchiriac wants to merge 1 commit into
qq15725:mainfrom
razchiriac:fix/load-media-timeout-zero
Open

fix: treat loadMedia timeout of 0 as a zero-ms timeout instead of no timeout#171
razchiriac wants to merge 1 commit into
qq15725:mainfrom
razchiriac:fix/load-media-timeout-zero

Conversation

@razchiriac

Copy link
Copy Markdown

Fixes the timeout: 0 handling in loadMedia (#170).

Problem

if (timeout) is a truthy check, so timeout: 0 disarms the safety timer entirely and loadMedia waits forever for media that never fires load/error — the opposite of what a caller passing 0 wants, and inconsistent with the Options.timeout docs ("millisecond, default: 30000").

Change

timeout != null arms the timer for any numeric value including 0 (resolves on the next macrotask). undefined keeps the current wait-forever behavior for direct callers, and createContext still defaults to 30000, so nothing changes for the normal domTo* paths.

Test

Added a case to test/nodejs.test.ts: a happy-dom image never fires load/error, so before this change loadMedia(img, { timeout: 0 }) hangs (test fails via a 1s guard race); after it, the promise resolves immediately.

We've been running with this behavior while capturing full-page screenshots of a dashboard-style web app in production.

…timeout

Previously `if (timeout)` was a truthy check, so passing `timeout: 0`
disarmed the timer entirely and loadMedia waited forever for media that
never fires load/error — the opposite of what a caller passing 0 wants.

Now any non-nullish timeout arms the timer, so `timeout: 0` resolves on
the next macrotask while `undefined` keeps the previous wait-forever
behavior for direct callers (createContext still defaults to 30000).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant