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: keep-alive component data should not be updated #5188
Conversation
Codecov Report
@@ Coverage Diff @@
## dev #5188 +/- ##
==========================================
- Coverage 96.52% 95.05% -1.48%
==========================================
Files 72 72
Lines 2447 2447
Branches 620 620
==========================================
- Hits 2362 2326 -36
- Misses 70 100 +30
- Partials 15 21 +6
Continue to review full report at Codecov.
|
@@ -491,6 +491,7 @@ function fixPrepatch(to, ___) { | |||
if ( | |||
instance.constructor._dataRefresh && | |||
Components[i] === instance.constructor && | |||
instance.$vnode.data.keepAlive !== true && |
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.
Just to be sure, is the default value of keepAlive
, false
by default? If it is true, isn't this a minor breaking change?
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.
The default value is undefined
, it's just a flag in Vue for keepAlive
cached component.
I don't think it's a breaking change, it should be a bug because component
under keep-alive
should be cached and never reload data as Vue is doing.
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.
Just wondering, shouldn't it be data.props.keepAlive
instead of data.keepAlive
? Because in bunch of files (packages/vue-app/template/components/nuxt.js
, etc), keepAlive
property is being wrapped into props
object.
I ran into an issue when component is still trying to update its data() even though it has keep-alived
enabled.
Changing this line to data.props.keepAlive
solved problem for me.
PS: Nuxt v2.15.2 (seems like nothing have been changed with keep-alived behaviour ever since this commit)
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.
keepAlive here is checking vue keep-alive component which will add keepAlive to vnode.data https://github.com/vuejs/vue/blob/b51430f598b354ed60851bb62885539bd25de3d8/src/core/components/keep-alive.js#L120
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.
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.
I think the component in your screenshot is NuxtChild which has keep-alive prop for enabling keepAlive on it.
https://nuxtjs.org/docs/2.x/features/nuxt-components#keep-alive
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.
You right, it is NuxtChild component.
I thought it should work the same way for any components, but seems like it is not the case.
I'll try to investigate it a little bit further and maybe come back with new issue and/or PR.
Thanks for your comments 👍
Thanks, bro. |
Types of changes
Description
Fix #5166
Checklist: