fix(navigation): fix client-side navigation with reactive useAsyncData keys - #214
Merged
Merged
Conversation
Release v1.5.3
…vigation Replace static useAsyncData keys with function form (reactive) in [...slug].vue so that page data updates when the route changes without recreating the component. Change page-key from route.path to locale in app.vue so that [...slug].vue persists across in-locale navigation and is only recreated on language switch. Fixes #213
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #213
Root cause
app.vueused:page-key="route.path"which forced[...slug].vueto be destroyed and recreated on every navigation. Since[...slug].vuecontains<NuxtLayout name="docs">, this also destroyed and recreateddocs.vueviaNuxtLayoutProvider. The slot content from the new[...slug].vueinstance failed to propagate correctly into the newdocs.vueduring the Suspense transition — resulting in the sidebar remaining visible but the main content not updating.Additionally, the
useAsyncDatakeys were static strings computed once at component setup. Even though the component was being recreated, the async data mechanism had subtle timing issues with the Suspense boundary and KeepAlive that prevented content updates.Fix
app.vue: Changepage-keyfromroute.pathtolocale.[...slug].vuenow persists across navigation within the same locale.docs.vuesetup with the new locale's navigation data).pages/[...slug].vue: Change alluseAsyncDatakeys from static strings to reactive function form (() => 'key-...').slugorlocalechanges, the key function returns a different string, triggering a data refresh.[...slug].vue) stays alive; only the reactive data updates, which Vue re-renders in-place.watch: [locale]option from the navigation query (now handled by the reactive key function).Behaviour after fix