nuxt icon indicating copy to clipboard operation
nuxt copied to clipboard

useRoute not correctly populated with async layout

Open Bobakanoosh opened this issue 2 years ago • 6 comments

Environment


  • Operating System: Linux
  • Node Version: v18.18.0
  • Nuxt Version: 3.8.2
  • CLI Version: 3.10.0
  • Nitro Version: 2.8.1
  • Package Manager: [email protected]
  • Builder: -
  • User Config: devtools
  • Runtime Modules: -
  • Build Modules: -

Reproduction

https://stackblitz.com/edit/github-bvoawn?file=pages%2Findex.vue,app.vue,layouts%2FTestLayout.vue,pages%2F[profileId].vue

I left a comment in "TestLayout.vue" that you should uncomment to see a fix

Describe the bug

Upon navigating to a layout that uses top-level await, useRoute().params is not populated correctly on the client side. Upon hard refresh, it is populated correctly

Additional context

I left a comment in "TestLayout.vue" that you should uncomment to see a fix

Logs

No response

Bobakanoosh avatar Dec 08 '23 02:12 Bobakanoosh

If you use <div>Route Data: {{ route }}</div> in the template, there won't be a hydration error.

TheAlexLichter avatar Dec 08 '23 09:12 TheAlexLichter

Where are you seeing a hydration error in my reproduction? Making that change doesn't fix the original issue either.

Bobakanoosh avatar Dec 08 '23 20:12 Bobakanoosh

Where are you seeing a hydration error in my reproduction? Making that change doesn't fix the original issue either.

When using $route in the template, there were hydration errors on the dynamic page when hard-reloading

image

TheAlexLichter avatar Dec 09 '23 21:12 TheAlexLichter

With regards to the issue mentioned, it seems to be a problem with the "top-level" const. If you use useRouter + currentRoute it works fine.

Updated stackblitz

TheAlexLichter avatar Dec 09 '23 21:12 TheAlexLichter

Any updates here? I see the MR for it hasn't had any activity for 3 weeks

Bobakanoosh avatar Jan 07 '24 22:01 Bobakanoosh

I think we likely could implement a fix for this, but it would have to be applied only for layouts that are newly instantiated for the route (i.e. we don't want the route data to be updated in a layout that is still rendering the old page)... And we would have to verify that it doesn't lead to a flash of stale data (first the current route, then the new route).

danielroe avatar Feb 04 '24 22:02 danielroe