T
TanStack•3y ago
rising-crimson

When using KeepAlive

I'm experimenting with KeepAlive - is it possible to trigger a network fetch on activated ?
9 Replies
rising-crimson
rising-crimsonOP•3y ago
Ah nevermind I can just check if it's stale in the activated hook and refetch the query
modern-teal
modern-teal•3y 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.
rising-crimson
rising-crimsonOP•3y 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
modern-teal
modern-teal•3y 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 😆
rising-crimson
rising-crimsonOP•3y 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
modern-teal
modern-teal•3y 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>
rising-crimson
rising-crimsonOP•3y 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
modern-teal
modern-teal•3y 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.
rising-crimson
rising-crimsonOP•3y ago
I have a couple of nested views too Not sure how that would be affected by KeepAlive

Did you find this page helpful?