T
TanStack•4y ago
quickest-silver

When using KeepAlive

I'm experimenting with KeepAlive - is it possible to trigger a network fetch on activated ?
9 Replies
quickest-silver
quickest-silverOP•4y ago
Ah nevermind I can just check if it's stale in the activated hook and refetch the query
like-gold
like-gold•4y ago
Oooh, that's a good callout, I'm going to have to address this in my app at work too. On activated to refetch seems like a good approach, yeah.
quickest-silver
quickest-silverOP•4y ago
Yeah really trying to improve performance I'm not sure if KeepAlive is the solution But was just playing around with it and noticed it won't refresh when you visit that page again And KeepAlive was causing some issues elsewhere Have some chunky data tables
like-gold
like-gold•4y ago
In my app, we're really depending on invalidateQueries to make sure things are updated, but otherwise KeepAlive is kind of meant to cache things, so skipping some refetching may be okay in some cases. But as always, It depends 😆
quickest-silver
quickest-silverOP•4y ago
Yeah exactly. I mean once my broadcasting is set up across everything then it will be much nicer. I wish you could KeepAlive on individual routes - like somehow flag individual pages rather than include and exclude
like-gold
like-gold•4y ago
I'm keeping certain routes alive with this, but that means the route component and include/exclude names need to be kept in sync
<router-view v-slot="{ Component }">
<keep-alive include="Gallery" max="2">
<component :is="Component" />
</keep-alive>
</router-view>
<router-view v-slot="{ Component }">
<keep-alive include="Gallery" max="2">
<component :is="Component" />
</keep-alive>
</router-view>
quickest-silver
quickest-silverOP•4y ago
Are there any other considerations using KeepAlive with whole pages? I can see with child-components it could get tricky with props etc but with whole pages, I either watch the prop anyway to re-fetch or do it onMounted So KeepAlive could work I think for certain pages unless I'm missing something
like-gold
like-gold•4y ago
Yeah, I think it should work. This area of my app doesn't have a ton of Vue Query yet, so I haven't hit edge cases yet at this point.
quickest-silver
quickest-silverOP•4y ago
I have a couple of nested views too Not sure how that would be affected by KeepAlive

Did you find this page helpful?