From ac1c310f393519c7d3d48ec6024a681f54c8d96c Mon Sep 17 00:00:00 2001 From: "sentry-junior[bot]" <264270552+sentry-junior[bot]@users.noreply.github.com> Date: Fri, 30 Oct 2026 13:42:20 +0000 Subject: [PATCH] fix(nuxt): Keep storage instrumentation plugin synchronous Nitro v3 RC awaits async plugins and defers every later plugin until the promise settles. Our async (but never awaiting) storage plugin turned all subsequent plugins async, so a plugin throwing at startup became an unhandled rejection instead of crashing the server. Also opt the nuxt-5 e2e app into the `kv` cache driver: Nitro v3 RC's default `memory` cache driver no longer goes through KV storage, so cached functions/handlers are not visible to the storage instrumentation. Co-Authored-By: Francesco Gringl-Novy --- .../e2e-tests/test-applications/nuxt-5/nuxt.config.ts | 3 +++ packages/nuxt/src/runtime/plugins/storage-legacy.server.ts | 4 ++-- packages/nuxt/src/runtime/plugins/storage.server.ts | 4 ++-- packages/nuxt/src/runtime/utils/instrumentStorage.ts | 2 +- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/dev-packages/e2e-tests/test-applications/nuxt-5/nuxt.config.ts b/dev-packages/e2e-tests/test-applications/nuxt-5/nuxt.config.ts index 8016834d1167..78c559af3621 100644 --- a/dev-packages/e2e-tests/test-applications/nuxt-5/nuxt.config.ts +++ b/dev-packages/e2e-tests/test-applications/nuxt-5/nuxt.config.ts @@ -28,6 +28,9 @@ export default defineNuxtConfig({ }, }, nitro: { + // Nitro v3 only routes `defineCachedFunction`/`defineCachedHandler` through KV storage (which the SDK + // instruments) with the `kv` cache driver. The default `memory` driver bypasses KV storage entirely. + cache: { driver: 'kv' }, experimental: { database: true, }, diff --git a/packages/nuxt/src/runtime/plugins/storage-legacy.server.ts b/packages/nuxt/src/runtime/plugins/storage-legacy.server.ts index 77b6a390d0e9..ac445ad0c432 100644 --- a/packages/nuxt/src/runtime/plugins/storage-legacy.server.ts +++ b/packages/nuxt/src/runtime/plugins/storage-legacy.server.ts @@ -7,6 +7,6 @@ import { createStoragePlugin } from '../utils/instrumentStorage'; /** * Nitro plugin that instruments storage driver calls for Nuxt v3/v4 (Nitro v2) */ -export default (async _nitroApp => { - await createStoragePlugin(useStorage, userStorageMounts as string[]); +export default (_nitroApp => { + createStoragePlugin(useStorage, userStorageMounts as string[]); }) satisfies NitroAppPlugin; diff --git a/packages/nuxt/src/runtime/plugins/storage.server.ts b/packages/nuxt/src/runtime/plugins/storage.server.ts index f9763b51d47b..726857f037dd 100644 --- a/packages/nuxt/src/runtime/plugins/storage.server.ts +++ b/packages/nuxt/src/runtime/plugins/storage.server.ts @@ -7,6 +7,6 @@ import { createStoragePlugin } from '../utils/instrumentStorage'; /** * Nitro plugin that instruments storage driver calls for Nuxt v5+ (Nitro v3+) */ -export default (async _nitroApp => { - await createStoragePlugin(useStorage, userStorageMounts as string[]); +export default (_nitroApp => { + createStoragePlugin(useStorage, userStorageMounts as string[]); }) satisfies NitroAppPlugin; diff --git a/packages/nuxt/src/runtime/utils/instrumentStorage.ts b/packages/nuxt/src/runtime/utils/instrumentStorage.ts index f0dd1fb1b399..1055b4ca5876 100644 --- a/packages/nuxt/src/runtime/utils/instrumentStorage.ts +++ b/packages/nuxt/src/runtime/utils/instrumentStorage.ts @@ -89,7 +89,7 @@ const METHOD_SPAN_OPS = { * The `useStorage` parameter is typed as `() => unknown` because nitropack (Nitro v2) and nitro (Nitro v3+) define `StorageValue` differently. * Cast to `NitroStorage` is safe since all Nitro versions expose `getMounts()` at runtime. */ -export async function createStoragePlugin(useStorage: () => unknown, userStorageMounts: string[]): Promise { +export function createStoragePlugin(useStorage: () => unknown, userStorageMounts: string[]): void { // This runs at runtime when the Nitro server starts const storage = useStorage() as NitroStorage; // Mounts are suffixed with a colon, so we need to add it to the set items