Using Vuestorefront's SSR with Nuxt 3 useAsyncData to Fetch Product Data
Learn how to leverage Vuestorefront's server‑side rendering with Nuxt 3's useAsyncData to fetch product data reliably, see a minimal setup, and avoid common pitfalls.
16 Dec 2025, 16:05 UTC

Useful answer
\nVuestorefront projects are Nuxt 3 applications, so enabling server‑side rendering (SSR) is automatic when you start the app with nuxt start or npm run dev. The page HTML is generated on the server, then hydrated on the client.
Mechanism: fetching product data with useAsyncData
\nTo get product information during the initial render, create a composable that calls the VSF API inside useAsyncData. The composable ensures the request runs only on the server for the first request and is reused on the client after hydration.
Example composable
\n// composables/useProduct.ts\nimport { useAsyncData } from '#app'\nexport function useProduct(productId: string) {\n return useAsyncData(\n `product-${productId}`,\n () => $vsf.api.getProduct(productId),\n { server: true }\n )\n}\n\n\nMinimal page usage
\nWhen the page is requested, Nuxt executes the composable on the server, fetches the product via $vsf.api.getProduct, injects the result into the rendered HTML, and sends the HTML to the browser. After hydration, the same composable returns the cached data, preventing a second request.
Limits and common mistakes
\n- \n
- Placing
useAsyncDatainside a component that only renders on the browser means the server will not run the fetch, leading to a request after hydration and a possible mismatch. \n - Fetching after navigation without resetting the key causes Nuxt to reuse stale data for different product IDs. Always include the ID in the key. \n
- Relying on default caching without headers can lead to stale product data when the backend updates inventory frequently. Add a custom
defaultorgetCachedDatastrategy, or set appropriateCache-Controlheaders on the API responses. \n
Verification
\n- \n
- Create a fresh project:
npm create @vuestorefront/ui my-shop. \n - Run
npm run devand open the network tab; the initial HTML response should contain the product name. \n - Disable JavaScript in the browser and reload; the product name remains visible, confirming SSR. \n
- Check the server console: you should see a single line like
getProduct called for id=XYZper page load. \n
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.