-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Conversation
β Deploy Preview for nuxt3-docs canceled.
|
With global state (this includes This issue exists anyway but it becomes particularly apparent when we start extracting page-specific payloads. Consider the following code in const { data } = useAsyncData(
() => $fetch(`https://api/users/${route.params.id}`),
{ initialCache: false }
)
// or
const pageData = useData()
if (!pageData.value) {
pageData.value = await $fetch(`https://api/users/${route.params.id}`)
} When the payload is loaded for the new page it will automatically trigger a re-render of the current one being displayed, before then resolving suspense and showing the new page. This can result in an unsightly flicker with the updated data being applied to the current page. The way we've resolved this with route based information is by ensuring that Creating this new For example, a conceptual implementation: const usePageData = (key?: string /* automatically injected by magic */) => {
const route = useRoute()
const nuxtApp = useNuxtApp()
// ... initialisation logic omitted for simplicity
return computed(() => nuxtApp.payload.data._page[route.path])
} This would ensure that we have a single data cache throughout the app, but also that each suspense fork shows the correct data.
It's important that we make a decision on this before merging this PR as a change to this (to make |
As mentioned in #7567 (comment), I don't like to make a different behavior of For the rest of the explanation, I fully agree with your reasoning. And honestly, it is the main reason in the initial implementation I made to make key mandatory. Key passed to useData should be unique to the route to avoid overriding. It wouldn't break if we introduce smart automated keys in the feature but also give users full control over key setting strategy. (nor enforcing one) To be honest, I really love the idea of route scoped
|
No matter what we do, I think it's important we communicate quite clearly what the purpose of these composables is (initial state vs page-specific info vs global state etc.). So far there has been no stated purpose attached to them (of course, it hasn't mattered until now, with payload extraction). Decisions, for good or ill, about global/local/page scope, need to be clearly explained and committed to so projects aren't broken in subsequent releases. |
I think you are confusing too many different topics over this PR. Extracted payload introduced in RC.10, is technically page data payload. Regardless of what we include in it and by what order or strategy apply updates on client-side navigation. The scope of On your suggestion about key fallback with route hash, there is no fallback key support at all if you read PR description! The key is explicit. I still believe All that said, I really see no blocker or potential breaking change for introducing |
Closing in favor of #9262 |
π Linked issue
Resolves nuxt/nuxt#14924
β Type of change
π Description
This PR introduces a new composable similar to
useState
but with different characteristics that makes one able to create their ownuseAsyncData
with full customization.useAsyncData
(instead of initial-data thatuseState
is meant for)Notes: Later, we can introduce auto key and actual shared state with
useAyncData
but it is minimum required to create a distinguished version ofuseState
and can support payload extraction.π Checklist