-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
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:#6938 <keep-alive> should not cache anonymous components #6985
Conversation
@jkzing unit test added, please review |
src/core/components/keep-alive.js
Outdated
@@ -85,8 +85,8 @@ export default { | |||
const componentOptions: ?VNodeComponentOptions = vnode && vnode.componentOptions | |||
if (componentOptions) { | |||
// check pattern | |||
const name: ?string = getComponentName(componentOptions) | |||
if (name && ( | |||
const name: ?string = componentOptions && componentOptions.Ctor.options.name |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do you change the way of getting name? Plus doesn't need componentOptions &&
since it's already in the if branch.
IMO it should keep original logic opts.Ctor.options.name || opts.tag
even if you want an optimization here which may not necessary
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for review , already modified.
docs descripition:
The match is first checked on the component’s own name option, then its local registration name (the key in the parent’s components option) if the name option is not available. Anonymous components cannot be matched against.
Anonymous components always have a registered name( tag in code) , i think the descripition of docs may cause logical hole.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cuteyumiko IMO we may need to keep opts.tag
. For example:
const foo = {
template: `<div>foo</div>`
}
new Vue({
el: '#app',
components: {
foo
}
})
In above case, you'll find Ctor.options
doesn't have a name
property, but there actually is tag
in it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ehhh..i see
i have done another test for caching anonymous components , it turns out caching logic is ok
#6938 it's problem may be casued by vue-router , i tracked this issue in a wrong way
@cuteyumiko why close the pr ? |
@PanJiaChen it works fine in offical unit test .your issue may be casued by vue-router . |
may be is function getComponentName (opts) {
return opts && (opts.Ctor.options.name || opts.tag)
} this function will return undefined, so has some problems when use vue/src/core/components/keep-alive.js Lines 88 to 94 in 1e14603
detail:#6938 |
What kind of change does this PR introduce? (check at least one)
Does this PR introduce a breaking change? (check one)
If yes, please describe the impact and migration path for existing applications:
The PR fulfills these requirements:
dev
branch for v2.x (or to a previous version branch), not themaster
branchfix #xxx[,#xxx]
, where "xxx" is the issue number)Other information:
anonymous components aslo have tag , so func getComponentName can not be used anymore.