Kong / swrv

Stale-while-revalidate data fetching for Vue

Home Page:https://docs-swrv.netlify.app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

question : swrv and keep-alive

flrnt opened this issue · comments

commented
setup () {
   // ...
    const url = ref(`/teacher/classes?class_id=${query.class_id}`)
    const options = reactive({
      cache: new LocalStorageCache(),
      shouldRetryOnError: false
    })
    const { data, isValidating } = useSWRV(url.value, fetcher, options)
}

When navigating from page to page (back and forth) it seems that the cache is not retrieving its correct key, despite having a unique one. Have data from previous page before revalidation, then once revalidation done, its ok.
Does the searchParams are omitted when getting cached data ? I use keep-alive at page level, maybe it's related ?

Yea keep alive means you're not getting any of the reactivity of the component re-rendering. Is query reactive? You should pass the ref directly into the key or wrap it in a function since swrv keys are just watchers. e.g. () => /url?${query.value} as the swrv key. Excuse the brevity I'm typing this from my phone.