unjs / unjs/hookable

createDebugger leaks console timer when inspect: true

Open Beginner friendly
#142 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
TypeScript
Stars
960
Forks
43
Avg merge
19m
Merged PRs (30d)
1

Description

Environment
  • hookable: v6.1.1
  • Node.js: v22
  • Browser: Chrome / any Chromium browser
Reproduction

import { Hookable, createDebugger } from 'hookable'

const hooks = new Hookable()
createDebugger(hooks, { inspect: true })

await hooks.callHook('myHook') // timer started, never ended
await hooks.callHook('myHook') // browser warns: "Timer 'myHook' already exists"

Describe the bug

When inspect: true (the default in browsers), createDebugger calls
console.timeLog() in the afterEach handler but never calls
console.timeEnd(). The timer started by console.time() in beforeEach
leaks on every hook call.

On the second call to the same hook the browser warns:

Timer 'hookName' already exists

Root cause: in src/debugger.ts lines 69-72, console.timeEnd() is
inside the else branch of the inspect check, so it is never reached
when inspect: true.

Since inspect defaults to true in browsers, every browser user of
createDebugger is affected.

I have a fix ready and would like to submit a PR if confirmed.

Additional context

No response

Logs

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in src/debugger.ts around lines 69-72 and reproduce the issue with createDebugger configured with inspect: true and two calls to the same hook. Check the beforeEach and afterEach timer handling; done means the repeated call no longer triggers the browser's duplicate-timer warning and the timer is properly completed.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
78/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.