Skip to content

Fix/emitted events cache - #1449

Merged
cexbrayat merged 1 commit into
vuejs:mainfrom
BrettLargent:fix/emitted-events-cache
Apr 26, 2022
Merged

cexbrayat merged 1 commit into
vuejs:mainfrom
BrettLargent:fix/emitted-events-cache

Conversation

@BrettLargent

Copy link
Copy Markdown
Contributor

Refactoring attachEmitListener function to not clear entire emitted events history on every call. A new removeEventHistory has been exposed and added to the unmount method logic so that specific emit history will be cleared on wrapper unmount. Unit testing has been added as well to show that the bug has been fixed.

@netlify

netlify Bot commented Apr 25, 2022 •

Copy link
Copy Markdown

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

Name Link
🔨 Latest commit 193a0f4
🔍 Latest deploy log https://app.netlify.com/sites/vue-test-utils-docs/deploys/6267f3efa48af4000971fea4
😎 Deploy Preview https://deploy-preview-1449--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 site settings.

@lmiller1990 lmiller1990 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.

Just one question about a possible additional assertion. Also, you might need to run prettier to ensure all the files are formatted correctly - I think the command you want is yarn lint:fix (see package.json).

Comment thread tests/emit.spec.ts

const wrapper1 = mount(Foo)
await wrapper1.trigger('click')
expect(wrapper1.emitted('foo')).toHaveLength(1)

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.

Should we also assert

expect(wrapper2.emitted('foo')).toHaveLength(0)

Here as well?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We would have to wait until after wrapper2 is mounted. We can do that, but the ultimate point of the test is to ensure that subsequent mounts no longer clear the emit history for previously mounted components.

Comment thread src/emit.ts Outdated
}

let events: Events
let events: Events = {};

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.

Not directly relevant but as a refactor in the future, I wonder if we should use WeakMap instead of a record here 🤔

@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.

LGTM

The PR needs to be fixed for the linting issues.
I would also squash the commits, and mention that they fix issue #1445 in the commit message.

Refactoring attachEmitListener function to not clear entire emitted events history on every call. A new removeEventHistory has been exposed and added to the unmount method logic so that specific emit history will be cleared on wrapper unmount. Unit testing has been added as well to show that the bug has been fixed.

fixes issue vuejs#1445
@BrettLargent
BrettLargent force-pushed the fix/emitted-events-cache branch from 6ac9659 to 193a0f4 Compare April 26, 2022 13:30
@BrettLargent

BrettLargent commented Apr 26, 2022 •

Copy link
Copy Markdown
Contributor Author

LGTM

The PR needs to be fixed for the linting issues. I would also squash the commits, and mention that they fix issue #1445 in the commit message.

linting issues fixed, commits have been squashed, and has a footer mention that it fixes #1445 👍

@cexbrayat
cexbrayat merged commit c24aec0 into vuejs:main Apr 26, 2022
@cexbrayat

Copy link
Copy Markdown
Member

Thanks @BrettLargent !

@BrettLargent

Copy link
Copy Markdown
Contributor Author

Thanks @BrettLargent !

No problem! Thank you all for your responsiveness and feedback. Glad we got this squashed quickly 💯

@lmiller1990

Copy link
Copy Markdown
Member

I will release this soon! Please wait a few days.

@BrettLargent

Copy link
Copy Markdown
Contributor Author

Hey all!

It's been a while since this was merged, but I'm still having the same problems with v0.17.1. Can anyone confirm whether this was ever released for me?

Thanks!

@cexbrayat

Copy link
Copy Markdown
Member

Yes it has been released. Are you using VTU v2.0.2?

@BrettLargent

Copy link
Copy Markdown
Contributor Author

🤦‍♂️ nope, I was updating the wrong dependency. Sorry for that!

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