From 3dc3e4cd5e797a44f08b7eabb42a8baec89459f6 Mon Sep 17 00:00:00 2001
From: Alaister Young <10985857+alaister@users.noreply.github.com>
Date: Tue, 21 Apr 2026 16:12:32 +0800
Subject: [PATCH] chore(studio): port ProfileProvider + force SSR bundling of
next compat shims
- Wrap Outlet with ProfileProvider from @/lib/profile inside the
feature flag provider so profile state, auto-creation, and the 401
sign-out redirect work in the Vite build (same order as _app.tsx).
- ssr.noExternal for /^next(\/|$)/ so our nextCompat resolveId shims
beat Vite's SSR externalizer. Without this, next/* ids were resolved
to the shim at build time but left as external runtime imports under
Vite dev SSR, so Node would load Next's real module and ProfileProvider's
useRouter threw "NextRouter was not mounted".
---
apps/studio/routes/__root.tsx | 5 ++++-
apps/studio/vite.config.ts | 6 +++++-
2 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/apps/studio/routes/__root.tsx b/apps/studio/routes/__root.tsx
index 5f806a4a0a9..2bc92727fb5 100644
--- a/apps/studio/routes/__root.tsx
+++ b/apps/studio/routes/__root.tsx
@@ -35,6 +35,7 @@ import { GlobalErrorBoundaryState } from '@/components/ui/ErrorBoundary/GlobalEr
import { useSelectedOrganizationQuery } from '@/hooks/misc/useSelectedOrganization'
import { AuthProvider } from '@/lib/auth'
import { API_URL, IS_PLATFORM, useDefaultProvider } from '@/lib/constants'
+import { ProfileProvider } from '@/lib/profile'
interface RouterContext {
queryClient: QueryClient
@@ -105,7 +106,9 @@ function RootComponent() {
enabled={IS_PLATFORM}
getConfigCatFlags={getConfigCatFlags}
>
-
+
+
+
diff --git a/apps/studio/vite.config.ts b/apps/studio/vite.config.ts
index 335c2107df8..5e5fdfe41a2 100644
--- a/apps/studio/vite.config.ts
+++ b/apps/studio/vite.config.ts
@@ -56,7 +56,11 @@ export default defineConfig({
tsconfigPaths: true,
},
ssr: {
- noExternal: ['lodash'],
+ // `lodash` is CJS; its named-export interop fails in Node ESM unless bundled.
+ // `next/*` must be bundled so our nextCompat shim wins — otherwise Vite's
+ // SSR externalizer leaves `next/router` as a runtime package import and
+ // Node resolves it to Next's real module.
+ noExternal: ['lodash', /^next(\/|$)/],
},
plugins: [
nextCompat(),