Skip to content

fix(mock-doc): handle undefined delay in setTimeout/setInterval#6539

Merged
johnjenkins merged 1 commit intostenciljs:mainfrom
Jagget:mock-doc
Jan 9, 2026
Merged

fix(mock-doc): handle undefined delay in setTimeout/setInterval#6539
johnjenkins merged 1 commit intostenciljs:mainfrom
Jagget:mock-doc

Conversation

@Jagget
Copy link
Contributor

@Jagget Jagget commented Jan 9, 2026

This PR resolves the TimeoutNaNWarning that may be emitted by Node.js during SSR hydration when setTimeout or setInterval is called without a delay argument.

Problem

When components call setTimeout(callback) without specifying a delay during SSR, the MockWindow implementation could potentially pass NaN to the native setTimeout:

ms = Math.min(ms, this.__maxTimeout);  // Math.min(undefined, 0) → NaN

Node.js may then coerce NaN to 1ms and emit a warning:

(node:46) TimeoutNaNWarning: NaN is not a number.
Timeout duration was set to 1.

Proposed Solution

Use nullish coalescing to default undefined to 0 before the Math.min call:

ms = Math.min(ms ?? 0, this.__maxTimeout);

This should align with browser behavior where setTimeout(fn) and setTimeout(fn, undefined) both default to 0ms delay.

@Jagget Jagget requested a review from a team as a code owner January 9, 2026 20:22
@johnjenkins johnjenkins enabled auto-merge January 9, 2026 20:40
@johnjenkins johnjenkins added this pull request to the merge queue Jan 9, 2026
Merged via the queue into stenciljs:main with commit 0d3a068 Jan 9, 2026
69 checks passed
@Jagget Jagget deleted the mock-doc branch January 9, 2026 21:10
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.

2 participants