1- import { dehydrate , HydrationBoundary } from '@tanstack/react-query'
1+ import { Suspense } from 'react'
2+ import { dehydrate , HydrationBoundary , type QueryClient } from '@tanstack/react-query'
23import { cookies } from 'next/headers'
34import { redirect } from 'next/navigation'
45import { SettingsNavigationProvider } from '@/components/settings/settings-navigation-provider'
6+ import type { WorkspaceHostContext } from '@/lib/api/contracts/workspaces'
57import { getSession } from '@/lib/auth'
68import { getActiveOrganizationId } from '@/lib/auth/session-response'
79import { isChangelogEnabled } from '@/lib/changelog/feature-flag'
@@ -13,6 +15,7 @@ import {
1315import { isMothershipModelSelectorEnabled , isPlanModeEnabled } from '@/lib/mothership/feature-flags'
1416import { resolveOrganizationEntryPath } from '@/lib/navigation/resolve-app-entry'
1517import { isWorkflowTestsEnabled } from '@/lib/workflow-tests/feature-flag'
18+ import { ApplicationLoading } from '@/app/_shell/application-loading'
1619import { getQueryClient } from '@/app/_shell/providers/get-query-client'
1720import { ImpersonationBanner } from '@/app/workspace/[workspaceId]/components/impersonation-banner'
1821import { SessionExpired } from '@/app/workspace/[workspaceId]/components/session-expired'
@@ -38,16 +41,29 @@ import { WorkspaceHostProvider } from '@/app/workspace/[workspaceId]/providers/w
3841import { WorkspacePermissionsProvider } from '@/app/workspace/[workspaceId]/providers/workspace-permissions-provider'
3942import { WorkspaceScopeSync } from '@/app/workspace/[workspaceId]/providers/workspace-scope-sync'
4043import { Sidebar } from '@/app/workspace/[workspaceId]/w/components/sidebar/sidebar'
44+ import {
45+ getBrandConfig ,
46+ mergeOrgBrandConfig ,
47+ type OrganizationWhitelabelSettings ,
48+ } from '@/ee/whitelabeling'
4149import { BrandingProvider } from '@/ee/whitelabeling/components/branding-provider'
4250import { getOrgWhitelabelSettings } from '@/ee/whitelabeling/org-branding'
4351
44- export default async function WorkspaceLayout ( {
45- children,
46- params,
47- } : {
52+ interface WorkspaceLayoutProps {
4853 children : React . ReactNode
4954 params : Promise < { workspaceId : string } >
50- } ) {
55+ }
56+
57+ interface WorkspaceContentProps {
58+ children : React . ReactNode
59+ workspaceId : string
60+ session : NonNullable < Awaited < ReturnType < typeof getSession > > >
61+ queryClient : QueryClient
62+ hostContext : WorkspaceHostContext
63+ initialOrgSettings : OrganizationWhitelabelSettings | null
64+ }
65+
66+ export default async function WorkspaceLayout ( { children, params } : WorkspaceLayoutProps ) {
5167 const session = await getSession ( )
5268 if ( ! session ?. user ) {
5369 redirect ( '/login' )
@@ -60,6 +76,34 @@ export default async function WorkspaceLayout({
6076 return < WorkspaceAccessDenied />
6177 }
6278
79+ const initialOrgSettings = hostContext . hostOrganizationId
80+ ? await getOrgWhitelabelSettings ( hostContext . hostOrganizationId )
81+ : null
82+ const brand = mergeOrgBrandConfig ( initialOrgSettings , getBrandConfig ( ) )
83+
84+ return (
85+ < Suspense fallback = { < ApplicationLoading brand = { brand } /> } >
86+ < WorkspaceContent
87+ workspaceId = { workspaceId }
88+ session = { session }
89+ queryClient = { queryClient }
90+ hostContext = { hostContext }
91+ initialOrgSettings = { initialOrgSettings }
92+ >
93+ { children }
94+ </ WorkspaceContent >
95+ </ Suspense >
96+ )
97+ }
98+
99+ async function WorkspaceContent ( {
100+ children,
101+ workspaceId,
102+ session,
103+ queryClient,
104+ hostContext,
105+ initialOrgSettings,
106+ } : WorkspaceContentProps ) {
63107 const activeOrganizationId = getActiveOrganizationId ( session )
64108 const principal = {
65109 kind : 'session' ,
@@ -68,7 +112,6 @@ export default async function WorkspaceLayout({
68112 } as const
69113 const [
70114 cookieStore ,
71- initialOrgSettings ,
72115 ,
73116 modelSelectorEnabled ,
74117 planModeEnabled ,
@@ -79,9 +122,6 @@ export default async function WorkspaceLayout({
79122 desktopExecutorRegistered ,
80123 ] = await Promise . all ( [
81124 cookies ( ) ,
82- hostContext . hostOrganizationId
83- ? getOrgWhitelabelSettings ( hostContext . hostOrganizationId )
84- : Promise . resolve ( null ) ,
85125 prefetchWorkspaceSidebar (
86126 queryClient ,
87127 workspaceId ,
0 commit comments