Skip to content
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

useAsyncData clears out nested route data before leaving #13814

Closed
mvrlin opened this issue Apr 24, 2022 · 34 comments · Fixed by #20777
Closed

useAsyncData clears out nested route data before leaving #13814

mvrlin opened this issue Apr 24, 2022 · 34 comments · Fixed by #20777

Comments

@mvrlin
Copy link

mvrlin commented Apr 24, 2022

Environment


  • Operating System: Darwin
  • Node Version: v16.14.2
  • Nuxt Version: 3.0.0-rc.1
  • Package Manager: pnpm@6.32.8
  • Builder: vite
  • User Config: build, buildModules, components, css, srcDir, typescript, vite, server
  • Runtime Modules: -
  • Build Modules: @intlify/nuxt3@0.1.10, @pinia/nuxt@0.1.8, nuxt-windicss@2.3.1

Reproduction

https://stackblitz.com/edit/github-ypbf5b?file=app.vue
To reproduce the issue, load the website with the url /users/foo and click Go Home

Describe the bug

useAsyncData clears out nested route data before leaving. If the next route is still loading, it produces a blank page, which isn't great 😢 Maybe it is due to provide/inject.

Additional context

Untitled.mov

Logs

No response

@Aareksio
Copy link
Contributor

image
image

Works without provide/inject StackBlitz.

@mvrlin
Copy link
Author

mvrlin commented Apr 25, 2022

image image

Works without provide/inject StackBlitz.

Yes, the issue is happening, when provide inject is used. Passing props to deep nested routes is not convenient.

@danielroe
Copy link
Member

This looks like it might be the same issue as vuejs/core#5513.

@mvrlin
Copy link
Author

mvrlin commented May 9, 2022

@danielroe https://stackblitz.com/edit/github-kcptvx?file=app.vue same thing is happening, even without provide/inject, when the route is dynamically nested

Try going through /users/baz -> /users/baz/foo

@cinob
Copy link
Contributor

cinob commented May 16, 2022

Experiencing the same problem

@champ7champ
Copy link

Is the problem being solved? Or should I start inventing crutches?

@danielroe
Copy link
Member

The route-based data issue is resolved and is no longer reproducible, so I'm going to close this. Note that if you are using provide/inject to inject data based on the route, then this will cause this kind of issue because of how suspense works. You can track vuejs/core#5513 for support for freezing provide/inject through suspense forks...

@mvrlin
Copy link
Author

mvrlin commented Sep 14, 2022

@danielroe The problem is still there. Before route changes, it clears the page. It shouldn't be that way.

Screen.Recording.2022-09-14.at.12.58.07.mov

@danielroe
Copy link
Member

Did you check the reproduction I linked?

CleanShot 2022-09-14 at 11 06 35

@mvrlin
Copy link
Author

mvrlin commented Sep 16, 2022

@danielroe Please take a look a this
When leaving nested users/id, it clears out the page.

Screen.Recording.2022-09-16.at.14.54.59.mov

@danielroe
Copy link
Member

You should not share a key between the pages. Set it to user-${route.params.id} or something.

@mvrlin
Copy link
Author

mvrlin commented Sep 16, 2022

You should not share a key between the pages. Set it to user-${route.params.id} or something.

@danielroe I updated the keys, but nothing has changed.. Try out yourself, please.

@danielroe danielroe reopened this Sep 17, 2022
@danielroe danielroe self-assigned this Sep 17, 2022
@mvrlin
Copy link
Author

mvrlin commented Sep 19, 2022

@danielroe I think the problem is more deeper than asyncData itself. It's the way that Nuxt handles pages. Instead of loading one by one async page component, it should wait for all nested async pages to be loaded to fully show, like Nuxt2 does it.

@Luffyyy
Copy link

Luffyyy commented Sep 23, 2022

msedge_eW8BVcEJpZ.mp4

Not sure if this is the same issue, but I seem to experience something similar.

Reproduction; https://stackblitz.com/edit/github-f4gpfk-m2cxo3?file=app.vue

@mvrlin
Copy link
Author

mvrlin commented Sep 23, 2022

@Luffyyy Yes, as I said previously, it's the way that Nuxt handles async pages. It loads the root route component and then one by one loads the subroute component. Nuxt should wait until all nested pages is loaded before displaying everything.

@patrikalbertsson
Copy link

patrikalbertsson commented Nov 1, 2022

I have the same problem. @mvrlin did you find any workaround for this?

@mvrlin
Copy link
Author

mvrlin commented Nov 1, 2022

I have the same problem. @mvrlin did you find any workaround for this?

Unfortunately, no :(

@carlosmouracorreia
Copy link

carlosmouracorreia commented Jan 8, 2023

Could this be the base for a solution @mvrlin , @danielroe ? Based on the suspense feature? I'm pretty sure it's related to how Nuxt handles page changes - vuejs/core#6736

This is a pretty important feature for modular websites these days, to have your asyncData data linked to a specific sub route - you see Instagram case on Settings, Youtube, Bitbucket, Grafana etc..
Btw, nested page loads work fine on first render (SSR) but not on client-side routing.

@Luffyyy
Copy link

Luffyyy commented Jan 8, 2023

For some reason this pull was downgraded from important to minor when it is definitely not a minor bug, it makes nested pages undesirable. It seems to also sit without any updates. I really hope it gets pushed soon otherwise I'm gonna have to get rid of all of the nested routes.

@mvrlin
Copy link
Author

mvrlin commented Jan 8, 2023

@Luffyyy I saw Atinux post on the twitter using the definePageMeta function. https://twitter.com/atinux/status/1604857928913195009?s=46&t=15UnCrF1REX4Dk39M81dpA

But I have no clue how to use the result from data outside the definePageMeta

@carlosmouracorreia
Copy link

It would be helpful to have some more information about how page transitions are done with Nuxt engine so a temporary solution can be arranged - even if depends on the open PR from Vue3 - this way one could prepare the base ground with a fork and help to ease the mind of people wanting to continue using Nuxt with Vue tooling.

@danielroe danielroe added the 3.x label Jan 19, 2023
@danielroe danielroe transferred this issue from nuxt/framework Jan 19, 2023
@champ7champ
Copy link

Such an important problem has not been solved in a year, and there is not even a temporary fix. Probably have to say goodbye to nuxt

@danielroe
Copy link
Member

I'm sorry you feel that way. As you see, it is an upstream bug which we have created a PR to fix, but it depends on Vue itself merging it.

@champ7champ
Copy link

@danielroe How long do you think it will take to solve this problem? Week, month, year?

@manniL
Copy link
Member

manniL commented Feb 6, 2023

@champ7champ Whenever the linked PR will be merged, which is not in our hands.
You could probably monkey-patch Vue in the meantime as "workaround" if really necessary.

@mvrlin
Copy link
Author

mvrlin commented Feb 6, 2023

@champ7champ Whenever the linked PR will be merged, which is not in our hands. You could probably monkey-patch Vue in the meantime as "workaround" if really necessary.

The patch doesn't work. Maybe the problem is not only with Suspense, but KeepAlive also.

@danielroe
Copy link
Member

Once that PR is merged, we then have to update Nuxt's implementation to use the prop it adds.

@manniL
Copy link
Member

manniL commented Feb 6, 2023

Once that PR is merged, we then have to update Nuxt's implementation to use the prop it adds.

Whoops, good point 🙈

@champ7champ

This comment was marked as off-topic.

@danielroe
Copy link
Member

The implementation will be pretty much instant on the Nuxt end 😆 The best thing you can do is not comment on this issue as it pings everyone who is subscribed.

@mvrlin
Copy link
Author

mvrlin commented Feb 6, 2023

The implementation will be pretty much instant on the Nuxt end 😆 The best thing you can do is not comment on this issue as it pings everyone who is subscribed.

I patched the Vue with npx patch-package with the PR you provided. Can you give a little instruction what to change in the Nuxt package to make it work? I tried to update NuxtPage component by adding suspensible prop, but it doesn't seem to work.

@champ7champ
Copy link

Activity is falling, the problem is moving further and further away, or is something being solved there?

@Luffyyy
Copy link

Luffyyy commented May 11, 2023

msedge_eW8BVcEJpZ.mp4

Not sure if this is the same issue, but I seem to experience something similar.

Reproduction; https://stackblitz.com/edit/github-f4gpfk-m2cxo3?file=app.vue

@danielroe This still happens in the latest build, is this intended behavior? where you leave the route and the child gets detached first while the parent isn't? It just looks plain weird.

Updated repro: https://stackblitz.com/edit/github-f4gpfk-qhgrfy?file=pages/test.vue

@danielroe
Copy link
Member

It's definitely not intended behaviour, but I think it's also different from the original issue here. I've opened a new issue to keep track of it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants