Skip to content

share useAsyncData state #13910

@SimonMarx

Description

@SimonMarx

Environment


  • Operating System: Linux
  • Node Version: v16.13.0
  • Nuxt Version: 3.0.0-rc.1
  • Package Manager: npm@8.1.0
  • Builder: vite
  • User Config: buildModules, modules, css, env, components, tailwindcss, meta, runtimeConfig
  • Runtime Modules: -
  • Build Modules: @nuxtjs/tailwindcss@5.0.3, @pinia/nuxt@0.1.8

Reproduction

Example using useAsyncData within a composable: https://stackblitz.com/edit/nuxt-starter-bf2vum?file=app.vue
Example using useAsyncData directly in components: https://stackblitz.com/edit/nuxt-starter-hhuack?file=app.vue

Describe the bug

Creating a state using useAsyncData within a custom composable, and using the custom composable in 2 different components does not share the state returned in {data} correctly.

One of these 2 components already has a state on SSR, while the second component has a true pending state and none data for a short time on client site rendering. When im using the composable in a component where both components are childs of that component and awaiting the fetch of the composable in the parent component, both child components do have the correct state in the same time thorugh the composable (on page load)

When i use useAsyncData directly in two components and assign the same key to useAsyncData it looks like the state is shared corrrectly.

In both examples using the refresh function within one of the components, not sharing the new collected state between these components.

Additional context

No response

Logs

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.x✨ enhancementNew feature or improvement to existing functionality🍰 p2-nice-to-haveNice to have, not blocking

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions