Skip to content

fix: clear events emitted during unmount from the emitted history - #2985

Merged
cexbrayat merged 1 commit into
vuejs:mainfrom
ondrhn:fix/issue-2984-clear-events-emitted-during
Oct 26, 2026
Merged

cexbrayat merged 1 commit into
vuejs:mainfrom
ondrhn:fix/issue-2984-clear-events-emitted-during

Conversation

@ondrhn

@ondrhn ondrhn commented Oct 24, 2026

Copy link
Copy Markdown
Contributor

wrapper.unmount() clears the recorded emit history before it unmounts the app, but the devtools recording hook is still installed at that point. Any emit() that runs during teardown — from onBeforeUnmount, a watcher cleanup, an effect scope stop — goes back through recordEvent and recreates the events[uid] and recordedUidsByRoot[rootUid] entries that were just deleted. Nothing removes them afterwards, so when the payload is a DOM/custom event the detached DOM tree, the component instance and the app stay reachable for the lifetime of the module (the whole worker with isolate: false).

In VueWrapper.unmount() (src/vueWrapper.ts) the removeEventHistory(this.vm) call now runs after this.__app.unmount(), inside a finally so the history is still dropped if unmounting throws, as it was before. vm.$.root.uid is still readable after unmount, so removeEventHistory resolves the same root bucket and clears every uid recorded under it, including the ones added during teardown. Emits from onUnmounted were already dropped by Vue itself (instance.isUnmounted), so this only concerns the beforeUnmount phase.

This follows up on #2898, which introduced the recordedUidsByRoot map to clear child histories on unmount.

Note the one behaviour change: a test that reads wrapper.emitted('x') after unmount() to assert a teardown emit now gets undefined and needs a listener spy ({ onX: spy }) instead. Emits from before the unmount were already cleared, so keeping the ones from during it was accidental.

fix #2984

The emit recorder stays active while the app unmounts, so clearing the
history before app.unmount() let beforeUnmount emits repopulate it with
entries nothing ever released.
@netlify

netlify Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

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

Name Link
🔨 Latest commit 02a2aac
🔍 Latest deploy log https://app.netlify.com/projects/vue-test-utils-docs/deploys/6add142fc5b47f8e0ff8e86e
😎 Deploy Preview https://deploy-preview-2985--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 26, 2026

Copy link
Copy Markdown

Open in StackBlitz

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

commit: 02a2aac

@cexbrayat cexbrayat left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR @ondrhn !

@cexbrayat
cexbrayat merged commit 3f2c26a into vuejs:main Oct 26, 2026
9 checks passed
virgilchiriac added a commit to hpi-schul-cloud/nuxt-client that referenced this pull request Dec 1, 2026
@vue/test-utils 2.6.0 has two changes in behaviour that broke tests:

- wrapper.unmount() clears the emitted history after unmounting
  (vuejs/test-utils#2985), so events emitted in onBeforeUnmount are
  lost. The tests of LinkContentElementCreate and
  VideoConferenceContentElementCreate check them with listener spies.
- Props passed to mount() are no longer deeply reactive
  (vuejs/test-utils#2951). RoomForm changes its room prop in place, so
  the test wraps the room in reactive(), as the parent pages pass a ref.

Co-authored-by: Copilot <[email protected]>
madebyzan added a commit to madebyzan/knovum that referenced this pull request Dec 3, 2026
v2.6.0 clears events emitted during unmount from the emitted history
(vuejs/test-utils#2985), so assert the busy:false release via the
instance emit spy instead of emitted() after unmount.
madebyzan added a commit to madebyzan/knovum that referenced this pull request Dec 3, 2026
@vue/test-utils v2.6.0 clears events emitted during unmount from the
emitted history (vuejs/test-utils#2985), so assert the busy:false
release via the instance emit spy instead of emitted() after unmount.
virgilchiriac added a commit to hpi-schul-cloud/nuxt-client that referenced this pull request Dec 3, 2026
@vue/test-utils 2.6.0 has two changes in behaviour that broke tests:

- wrapper.unmount() clears the emitted history after unmounting
  (vuejs/test-utils#2985), so events emitted in onBeforeUnmount are
  lost. The tests of LinkContentElementCreate and
  VideoConferenceContentElementCreate check them with listener spies.
- Props passed to mount() are no longer deeply reactive
  (vuejs/test-utils#2951). RoomForm changes its room prop in place, so
  the test wraps the room in reactive(), as the parent pages pass a ref.
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.

Bug: events emitted during unmount() are recorded after the history is cleared, and never released

2 participants