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): optimization the logic of setting __props (close #2651) #2654

Closed
wants to merge 8 commits into from

Conversation

edison1105
Copy link
Member

@edison1105 edison1105 commented Nov 21, 2020

close #2651

if app.mixin({}) called, app.mixins will be [{}] .
It will become [{__props:[]}] after normalizePropsOptions called.

@edison1105 edison1105 changed the title fix(runtime-core): skip apply mixins if mixinOption is empty #2651 fix(runtime-core): if raw is undefined should return null #2651 Nov 21, 2020
@edison1105 edison1105 changed the title fix(runtime-core): if raw is undefined should return null #2651 fix(runtime-core): if normalized is empty should return null #2651 Nov 21, 2020
@edison1105 edison1105 changed the title fix(runtime-core): if normalized is empty should return null #2651 fix(runtime-core): if normalized is empty and !raw should return null (close #2651) Nov 21, 2020
Copy link
Member

@posva posva left a comment

Choose a reason for hiding this comment

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

Can you also add a test?

packages/runtime-core/src/componentEmits.ts Outdated Show resolved Hide resolved
@edison1105 edison1105 changed the title fix(runtime-core): if normalized is empty and !raw should return null (close #2651) fix(runtime-core): optimization the logic of setting __props (close #2651) Nov 21, 2020
@edison1105 edison1105 requested a review from posva November 21, 2020 15:53
@@ -169,7 +169,11 @@ export function normalizeEmitsOptions(
extend(normalized, normalizeEmitsOptions(raw, appContext, true))
}
if (!asMixin && appContext.mixins.length) {
appContext.mixins.forEach(extendEmits)
appContext.mixins.forEach(raw => {
if (Object.keys(raw).length) {
Copy link
Member

Choose a reason for hiding this comment

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

I still think it makes more sense to add this check at componentEmits.ts where the warning is emitted. Or is there any reason not to adapt the warning?

Copy link
Member Author

Choose a reason for hiding this comment

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

I still think it makes more sense to add this check at componentEmits.ts where the warning is emitted. Or is there any reason not to adapt the warning?

if (__DEV__) {
    const {
      emitsOptions,
      propsOptions: [propsOptions]
    } = instance
    if (emitsOptions) {
      if (!(event in emitsOptions)) {
        if (!propsOptions || !(toHandlerKey(event) in propsOptions)) {
          warn(
            `Component emitted event "${event}" but it is neither declared in ` +
              `the emits option nor as an "${toHandlerKey(event)}" prop.`
          )
        }
      }

The normal logic is: if emitsOptions is null there is no warning.
if app.mixin({}) or mixin some object without emits property, the emitsOptions should be null.

I found emitsOptions is {} when I was debugging. Because in normalizeEmitsOptions

let normalized: ObjectEmitsOptions = {}
//...
const extendEmits = (raw: ComponentOptions) => {
  hasExtends = true
  extend(normalized, normalizeEmitsOptions(raw, appContext, true))
}
if (!asMixin && appContext.mixins.length) {
  // appContext.mixins is [{__props:[]}], it should be [{}] because we mixin `{}`
  appContext.mixins.forEach(extendEmits)
}

The value of app.mixins becomes [{__props:[]}] after normalizePropsOptions called.
It should be [{}]. in normalizePropsOptions

//...
if (!raw && !hasExtends) {
  return (comp.__props = EMPTY_ARR as any)
}
//...

I think comp.__props should not be defined if !raw && !hasExtends
So I did not modify the function emit() where the warning is emitted.
Instead, normalizePropsOptions and normalizeEmitsOptions are modified

Did I express it clearly enough ? Please correct me if my understanding is wrong.

@edison1105 edison1105 requested a review from posva November 24, 2020 10:03
@LinusBorg LinusBorg added the 🔨 p3-minor-bug Priority 3: this fixes a bug, but is an edge case that only affects very specific usage. label Dec 21, 2020
@LinusBorg
Copy link
Member

@posva can you take another look here?

@yyx990803
Copy link
Member

See better fix in 60d777d

@yyx990803 yyx990803 closed this Mar 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔨 p3-minor-bug Priority 3: this fixes a bug, but is an edge case that only affects very specific usage.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mixins trigger an emitted event warning
4 participants