Visitar URL original
fix: record emitted events once when a devtools hook is installed by ValentinYoushkevich · Pull Request #2965 · vuejs/test-utils · GitHub
Skip to content

fix: record emitted events once when a devtools hook is installed - #2965

Merged
cexbrayat merged 1 commit into
vuejs:mainfrom
ValentinYoushkevich:fix/emitted-once-with-devtools-hook
Oct 10, 2026
Merged

cexbrayat merged 1 commit into
vuejs:mainfrom
ValentinYoushkevich:fix/emitted-once-with-devtools-hook

Conversation

@ValentinYoushkevich

Copy link
Copy Markdown
Contributor

When __VUE_DEVTOOLS_GLOBAL_HOOK__ exists, every mount wraps hook.emit once more (#2311), so after N mounts a single $emit is recorded N times. And if the hook is replaced after Vue's renderer was created (Vue keeps the old one), emitted() is empty.

vi.stubGlobal('__VUE_DEVTOOLS_GLOBAL_HOOK__', { emit: vi.fn() })
mount(Comp)
const wrapper = mount(Comp)
wrapper.vm.$emit('foo')
wrapper.emitted('foo') // [[], []]

This always installs the VTU hook again, as before #2311, and forwards every event (and cleanupBuffer) to the current global hook, so devtools still receive everything (#2310). I checked this with @vue/devtools-kit: app:init, component:* and perf:* each arrive once.

Seen in ComfyUI_frontend, which stubs the hook in a beforeEach: emitted() counts depend on how many mounts ran before.

Repro on 2.5.1: playground

cc @webfansplz

With a global devtools hook, every mount wrapped hook.emit once more, so a single $emit was recorded once per previous mount, and nothing was recorded if the hook was replaced after the renderer was created. Always install the VTU hook and forward events to the current global hook instead.
@netlify

netlify Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for vue-test-utils-docs ready!

Name Link
🔨 Latest commit da9659c
🔍 Latest deploy log https://app.netlify.com/projects/vue-test-utils-docs/deploys/6ac729c681176c0008417b09
😎 Deploy Preview https://deploy-preview-2965--vue-test-utils-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@pkg-pr-new

pkg-pr-new Bot commented Oct 8, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@vue/test-utils@2965

commit: da9659c

@cexbrayat
cexbrayat requested a review from webfansplz October 8, 2026 13:39
@cexbrayat

Copy link
Copy Markdown
Member

LGTM, but I'd like to have @webfansplz 's opinion as they are the one who worked on this

@webfansplz

Copy link
Copy Markdown
Member

LGTM

@cexbrayat
cexbrayat merged commit e449126 into vuejs:main Oct 10, 2026
9 checks passed
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.

3 participants