From 0e90e87ef78abb3023d3f96b8fbc6c66ffda7938 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Thu, 23 May 2024 17:40:23 +0100 Subject: [PATCH] fix(nuxt): defer shared asyncData promises to next tick (#27329) --- packages/nuxt/src/app/composables/asyncData.ts | 2 +- packages/schema/src/config/experimental.ts | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/nuxt/src/app/composables/asyncData.ts b/packages/nuxt/src/app/composables/asyncData.ts index 92e62b32f7..aafb729e14 100644 --- a/packages/nuxt/src/app/composables/asyncData.ts +++ b/packages/nuxt/src/app/composables/asyncData.ts @@ -229,7 +229,7 @@ export function useAsyncData< const value = nuxtApp.ssrContext!._sharedPrerenderCache!.get(key) if (value) { return value as Promise } - const promise = nuxtApp.runWithContext(_handler) + const promise = Promise.resolve().then(() => nuxtApp.runWithContext(_handler)) nuxtApp.ssrContext!._sharedPrerenderCache!.set(key, promise) return promise diff --git a/packages/schema/src/config/experimental.ts b/packages/schema/src/config/experimental.ts index 8d01cf72a4..b90a378ac3 100644 --- a/packages/schema/src/config/experimental.ts +++ b/packages/schema/src/config/experimental.ts @@ -393,7 +393,11 @@ export default defineUntypedSchema({ * }) * ``` */ - sharedPrerenderData: false, + sharedPrerenderData: { + async $resolve (val, get) { + return val ?? ((await get('future') as Record).compatibilityVersion === 4) + }, + }, /** * Enables CookieStore support to listen for cookie updates (if supported by the browser) and refresh `useCookie` ref values.