Skip to content

[Bug]: clearTimeout(undefined) throws TypeError instead of being a no-op #8641

Description

@hanxi

System Info

System:
OS: Linux 5.15 (ubuntu)
Node: 26.5.0
pnpm: 11.15.1

npmPackages:
@lynx-js/types: 4.0.0
@lynx-js/react: 0.123.2
@lynx-js/rspeedy: 0.16.2

Details

Lynx 4.0 中 clearTimeout(undefined) 抛出异常:

TypeError: param 0 should be Number

根据 WHATWG HTML Standard

If handle is not provided, the clearTimeout() method call does nothing.

所有其他 JavaScript 运行时行为一致:

运行时 clearTimeout(undefined) 行为
Chrome no-op
Firefox no-op
Safari no-op
Node.js no-op
Deno no-op
Bun no-op
Lynx 4.0 TypeError

影响:破坏所有传递可选 timer ID 的第三方库。例如 TanStack Router 的 offerPending 函数:

clearTimeout(session?.[3]); // undefined when session is null

目前需要 patch 每个受影响的库来包裹 clearTimeout 调用。

建议修复:在 clearTimeout 入口加类型守卫:

// pseudo-code
if (!handle || typeof handle !== 'number') return;

Reproduce link

No response

Reproduce Steps

  1. 在 Lynx 4.0 环境中执行:
clearTimeout(undefined);
  1. 观察:抛出 TypeError: param 0 should be Number
  2. 期望:无操作(no-op)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions