Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(runtime-core): use separate emits caches for components and mixins #11661

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

gcaaa31928
Copy link
Contributor

This seems to be the same issue as #11350, except that in this case, the emits cache is being reused by both mixins and components, which could lead to the emit validation being applied in the wrong context.

However, the fix here is the same: separate the emits cache from the appContext

Copy link

github-actions bot commented Aug 19, 2024

Size Report

Bundles

File Size Gzip Brotli
runtime-dom.global.prod.js 100 kB (+39 B) 38 kB (+11 B) 34.2 kB (+17 B)
vue.global.prod.js 159 kB (+39 B) 57.9 kB (+1 B) 51.4 kB (-58 B)

Usages

Name Size Gzip Brotli
createApp (CAPI only) 46.9 kB 18.3 kB 16.7 kB
createApp 55 kB (+39 B) 21.3 kB (+15 B) 19.4 kB (+36 B)
createSSRApp 59 kB (+39 B) 23 kB (+14 B) 20.9 kB (-11 B)
defineCustomElement 59.8 kB (+41 B) 22.8 kB (+6 B) 20.8 kB (-56 B)
overall 68.7 kB (+39 B) 26.4 kB (+13 B) 24 kB (+24 B)

Copy link

pkg-pr-new bot commented Aug 19, 2024

Open in Stackblitz

@vue/compiler-dom

pnpm add https://pkg.pr.new/@vue/compiler-dom@11661

@vue/compiler-sfc

pnpm add https://pkg.pr.new/@vue/compiler-sfc@11661

@vue/compiler-ssr

pnpm add https://pkg.pr.new/@vue/compiler-ssr@11661

@vue/runtime-dom

pnpm add https://pkg.pr.new/@vue/runtime-dom@11661

@vue/runtime-core

pnpm add https://pkg.pr.new/@vue/runtime-core@11661

@vue/reactivity

pnpm add https://pkg.pr.new/@vue/reactivity@11661

@vue/server-renderer

pnpm add https://pkg.pr.new/@vue/server-renderer@11661

@vue/shared

pnpm add https://pkg.pr.new/@vue/shared@11661

@vue/compat

pnpm add https://pkg.pr.new/@vue/compat@11661

vue

pnpm add https://pkg.pr.new/vue@11661

@vue/compiler-core

pnpm add https://pkg.pr.new/@vue/compiler-core@11661

commit: 60dd480

@edison1105
Copy link
Member

/ecosystem-ci run

@vue-bot
Copy link
Contributor

vue-bot commented Aug 20, 2024

📝 Ran ecosystem CI: Open

suite result latest scheduled
language-tools failure failure
nuxt success success
pinia success success
primevue success success
quasar success success
radix-vue success success
router success success
test-utils success success
vant success success
vite-plugin-vue success success
vitepress success success
vue-i18n success success
vue-macros success success
vuetify success success
vueuse success success
vue-simple-compiler success success

@edison1105 edison1105 added 🍰 p2-nice-to-have Priority 2: this is not breaking anything but nice to have it addressed. ready for review This PR requires more reviews labels Aug 20, 2024
Copy link
Contributor

@skirtles-code skirtles-code left a comment

Choose a reason for hiding this comment

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

The fix looks good to me. I've made some suggestions for the tests.

@@ -599,3 +600,76 @@ describe('component: emit', () => {
expect(renderFn).toHaveBeenCalledTimes(1)
})
})

test('merging emits for a component that is also used as a mixin', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

These tests are outside the describe block. All the other tests in this file are inside the describe. Is there a reason to have these outside?

expect(`event validation failed for event "one"`).not.toHaveBeenWarned()
})

test('merging props from global mixins and extends', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
test('merging props from global mixins and extends', () => {
test('merging emits from global mixins and extends', () => {


const CompB = {
mixins: [mixin, CompA],
created(this: ComponentPublicInstance) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Couldn't this use defineComponent, rather than explicitly typing the this value? That seems to be how the other tests in this file are handling it.

There's some similar code in the other new test where the typings could just be removed.

Comment on lines 673 to 714
expect(renderProxy._.emitsOptions).toMatchObject(emits)
expect(extendedRenderProxy._.emitsOptions).toMatchObject(emits)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason to grab things from internal properties here? Can't this be tested via the public API, like in the other test?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed, this part is redundant, so I have removed this.


const app = createApp({
render() {
return [h(CompA), ', ', h(CompB)]
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return [h(CompA), ', ', h(CompB)]
return [h(CompA), h(CompB)]

Given we aren't checking the rendered output, I think it'd be clearer to omit the separator string.


const root = nodeOps.createElement('div')
app.mount(root)
expect(`event validation failed for event "one"`).not.toHaveBeenWarned()
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps rather than using the warning to check for correctness we could check which validator functions are called? If the validators use vi.fn() we could test for toHaveBeenCalledTimes(1) and not.toHaveBeenCalled(), as appropriate?

@gcaaa31928 gcaaa31928 force-pushed the emits-cache branch 2 times, most recently from c508fc0 to ce27cfd Compare October 11, 2024 17:32
@gcaaa31928
Copy link
Contributor Author

The fix looks good to me. I've made some suggestions for the tests.

@skirtles-code Thank you for your review !

I have adjusted the testing code according to your suggestions. Please take a look at it when you have time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🍰 p2-nice-to-have Priority 2: this is not breaking anything but nice to have it addressed. ready for review This PR requires more reviews
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants