From 053bbfe312d5b80cb78c29f8c8365fda6824331a Mon Sep 17 00:00:00 2001 From: ZiyamSanthosh Date: Fri, 14 Aug 2026 17:49:30 +0530 Subject: [PATCH] Stop the Nuxt SDK pulling @thunderid/node into the client bundle The universal Nuxt plugin imported `VendorConstants` from `@thunderid/node`, and the shared state-key util imported `getVendorPrefix` from it. Both files participate in the browser bundle, so the Node SDK reached Vite's client graph, which then failed on the named Fetch API exports it takes from `cross-fetch`: browser-ponyfill.js does not provide an export named Headers The app rendered but client hydration did not complete, leaving `ThunderIDSignInButton` inert. Consumers had to work around it by adding `@thunderid/node` to `vite.optimizeDeps.include` themselves. Take both values from the browser-safe `@thunderid/browser` layer instead, which re-exports the framework-agnostic JavaScript SDK APIs. Resolving the vendor through `getVendorPrefix()` also drops the inline `vendor ?? VendorConstants.VENDOR_PREFIX` fallback, keeping that default in one place. Type-only imports from `@thunderid/node` are erased at build time and stay as they are; `module.ts` runs in Node at build time and is unaffected. No `optimizeDeps.include` entry is needed: with this change the Node SDK is no longer part of the browser graph at all. Fixes #4905 Co-Authored-By: Claude Opus 5 (1M context) --- packages/nuxt/src/runtime/plugins/thunderid.ts | 5 ++--- packages/nuxt/src/runtime/utils/stateKeys.ts | 2 +- packages/nuxt/tests/unit/thunderid-root.test.ts | 1 + 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/nuxt/src/runtime/plugins/thunderid.ts b/packages/nuxt/src/runtime/plugins/thunderid.ts index 100c788e..b45de129 100644 --- a/packages/nuxt/src/runtime/plugins/thunderid.ts +++ b/packages/nuxt/src/runtime/plugins/thunderid.ts @@ -1,8 +1,7 @@ // Copyright 2025 The ThunderID Authors // SPDX-License-Identifier: Apache-2.0 -import {getRedirectBasedSignUpUrl} from '@thunderid/browser'; -import {VendorConstants} from '@thunderid/node'; +import {getRedirectBasedSignUpUrl, getVendorPrefix} from '@thunderid/browser'; import type {AttributeSchema, UserProfile} from '@thunderid/node'; import {ThunderIDPlugin, THUNDERID_KEY} from '@thunderid/vue'; import type {H3Event} from 'h3'; @@ -58,7 +57,7 @@ export default defineNuxtPlugin((nuxtApp: NuxtApp) => { vendor?: string; }; - const vendor: string = publicConfig.vendor ?? VendorConstants.VENDOR_PREFIX; + const vendor: string = getVendorPrefix(publicConfig.vendor); // Surface misconfiguration in the browser dev console only. The server // counterpart is handled by the thunderid-ssr Nitro plugin; doing both diff --git a/packages/nuxt/src/runtime/utils/stateKeys.ts b/packages/nuxt/src/runtime/utils/stateKeys.ts index 3a0b92c9..9c2b82e0 100644 --- a/packages/nuxt/src/runtime/utils/stateKeys.ts +++ b/packages/nuxt/src/runtime/utils/stateKeys.ts @@ -1,7 +1,7 @@ // Copyright 2025 The ThunderID Authors // SPDX-License-Identifier: Apache-2.0 -import {getVendorPrefix} from '@thunderid/node'; +import {getVendorPrefix} from '@thunderid/browser'; /** * Shared `useState` key for the ThunderID auth state (`ThunderIDAuthState`). diff --git a/packages/nuxt/tests/unit/thunderid-root.test.ts b/packages/nuxt/tests/unit/thunderid-root.test.ts index 80e2cca9..9fb0eab3 100644 --- a/packages/nuxt/tests/unit/thunderid-root.test.ts +++ b/packages/nuxt/tests/unit/thunderid-root.test.ts @@ -26,6 +26,7 @@ vi.mock('@thunderid/vue', () => ({ vi.mock('@thunderid/browser', () => ({ generateFlattenedUserProfile: vi.fn((_user: any, _schemas: any) => ({email: 'updated@example.com'})), + getVendorPrefix: vi.fn((vendor?: string) => vendor ?? 'thunderid'), })); // Stub Nuxt composables so the component's setup() can run in pure Node.