-
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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(nuxt): provide route component names to KeepAlive
cache
#24024
Conversation
Run & review this pull request in StackBlitz Codeflow. |
A test about HMR failed, working on it. |
c8506ad
to
0f1af65
Compare
All tests have passed now. |
Thanks for the quick review! All done. |
Tips:This branch is out-of-date with the base branchοΌYouβre not authorized to merge this pull request. |
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.
in further testing it seems that this change undoes the purpose of the route provider, which is to ensure a stably injected route
in a suspense fork.
I've created a test (#24195) which should show the behaviour we want to have - once merged to main and updated in this pr, you can test it with:
pnpm nuxi dev test/fixtures/basic
and navigate to http://localhost:3000/route-provider/foo
and then navigate to bar
Thanks! I will investigate it |
After some investigations, i found that the behavior of suspense and async component is heavily relying on the nested order of the components in Another solution that comes to my mind is to set the component name of In the long run, to address this issue, Do you have any better idea? @danielroe |
@Clarkkkk I think that would be a good solution. And I think we can only get rid of |
I revert the previous changes and set the component name dynamically. The test result is different because |
RouteProvider
for keepalive cache
RouteProvider
for keepalive cacheKeepAlive
cache
if I switch other layout, the keepalive will not work |
switch other layout, the keepalive of before layout will not work |
the include method still have bug. <template>
<NuxtPage :keepalive="{include:cacheList, max:20}" />
</template>
<script setup>
let cacheList = ref(['a','b','c'])
// the page a, b, c is cached.
const updateCacheList = ()=>{
cacheList.value = ['a','b']
router.push({path: '/c'})
// when chanage route, the page 'a', 'b' refreshed!
}
</script> this means it can't use a dynamic var to control the keepalive status. |
π Linked issue
#15214
β Type of change
π Description
Hi, this PR is aimed to make the
keepalive
works as expected and fix #15214Changes:
NuxtPage
, lettingKeepAlive
read the correct component nameThere is one problem I am not sure about. In
RouteProvider
, it usespreviousKey
andpreviousRoute
to "Prevent reactivity when the page will be rerendered in a different suspense fork" as the comment says, which I don't really understand. Sincesetup
inRouteProvider
will not rerun after all the changes, I use awatch
to updatepreviousKey
andpreviousRoute
. I don't know if it works the same way as before, and it seems there is no test case for this scenario.π Checklist