question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

keepalive `include`/`exclude` props don't work with `<NuxtPage>`

See original GitHub issue

Environment


  • Operating System: Windows_NT
  • Node Version: v16.16.0
  • Nuxt Version: 3.0.0-rc.11
  • Nitro Version: 0.5.4
  • Package Manager: npm@8.11.0
  • Builder: vite
  • User Config: -
  • Runtime Modules: -
  • Build Modules: -

Reproduction

https://stackblitz.com/edit/github-xnrjjn?file=pages%2Findex.vue,pages%2Fnotkeptalive.vue

Describe the bug

App has 2 pages, one page is set to be kept alive with definePageMeta({ keepalive: true }); the other one is not.

Changing some value in the first page, is not kept if you navigate away from it and if you come back. Also, there is a weird display bug, as if a new mounted component of the page was added under the first one in the page before the first one being added. It make the page flicker.

If you put the same page meta in the second one (by removing the comment is the reproduction link), now it works, but the two pages are now kept alive and this is not what I want.

In base vue3, I could do something like that :

<router-view v-slot="{ Component }">
      <keep-alive include="index">
        <component :is="Component" />
      </keep-alive>
    </router-view>

Additional context

No response

Logs

No response

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:2
  • Comments:11 (7 by maintainers)

github_iconTop GitHub Comments

5reactions
danielroecommented, Nov 28, 2022

Yes, this is definitely on the roadmap and needs to be fixed.

5reactions
Ilmioncommented, Oct 21, 2022

Feature implemented here: #7492.

You would do something like:

<NuxtPage :keepalive="{ include: 'index' }" />

@danielroe It does not work. I have inspected it with chrome vue dev tool and here is the problem. Under the KeepAlive there is a Anonymous element created around the Index element and because is it not exactly under the KeepAlive the include does not work. When the keepalive is setup globaly, it is the Anonymous object that are kept alive, not the one from the ./pages.

Two joint picture from the Chrome dev tool. With the include in the, ie <NuxtPage :keepalive="{ include : 'index' }"> KeepAliveWithInclude With the keepalive set globaly, you can see another Anonymous under the KeepAlive KeepAliveWithoutInclude

This bug isn’t closed IMHO.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[rc.8] keep alive components get destroyed when navigating to ...
I'm not sure if this behavior was done on purpose. But I can say that Vue handles include/exclude differently and does not destroy...
Read more >
How to exclude specific component from caching Using Nuxt ...
I have trouble with Nuxt.js keep-alive prop, I am trying to cache all components except one, and load dynamic data again.
Read more >
Built-in Components - Nuxt
Both, the <Nuxt> component and the <NuxtChild/> component, accept keep-alive and keep-alive-props. To learn more about keep-alive and keep-alive-props see the ...
Read more >
Migrate to Nuxt 3: Pages and Layouts
In Nuxt 3, these have been replaced with a single <NuxtPage> component. Page Keys and Keep-alive Props. If you were passing a custom...
Read more >
Nuxt Exclude page from keep-alive - StackBlitz
<nuxt-link to="/about">About</nuxt-link>. </nav>. <p>See browser console</p>. <Nuxt keep-alive :keep-alive-props=". {exclude: ['pages/basket.vue']}" />.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found