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".
This commit is contained in:
Alaister Young committed 2026-04-21 16:12:32 +08:00
1 parent ec566018f5
commit 3dc3e4cd5e
2 files changed
+9 -2

No files matched your search

+4 -1
View File
@@ -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}
>
<Outlet />
<ProfileProvider>
<Outlet />
</ProfileProvider>
</FeatureFlagProviderWithOrgContext>
</AuthProvider>
</NuqsAdapter>
+5 -1
View File
@@ -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(),