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,33 @@ 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+ orgSettings : Promise < OrganizationWhitelabelSettings | null >
64+ }
65+
66+ interface WorkspaceLoadingProps {
67+ orgSettings : Promise < OrganizationWhitelabelSettings | null >
68+ }
69+
70+ export default async function WorkspaceLayout ( { children, params } : WorkspaceLayoutProps ) {
5171 const session = await getSession ( )
5272 if ( ! session ?. user ) {
5373 redirect ( '/login' )
@@ -60,6 +80,38 @@ export default async function WorkspaceLayout({
6080 return < WorkspaceAccessDenied />
6181 }
6282
83+ const orgSettings = hostContext . hostOrganizationId
84+ ? getOrgWhitelabelSettings ( hostContext . hostOrganizationId )
85+ : Promise . resolve ( null )
86+
87+ return (
88+ < Suspense fallback = { < WorkspaceLoading orgSettings = { orgSettings } /> } >
89+ < WorkspaceContent
90+ workspaceId = { workspaceId }
91+ session = { session }
92+ queryClient = { queryClient }
93+ hostContext = { hostContext }
94+ orgSettings = { orgSettings }
95+ >
96+ { children }
97+ </ WorkspaceContent >
98+ </ Suspense >
99+ )
100+ }
101+
102+ async function WorkspaceLoading ( { orgSettings } : WorkspaceLoadingProps ) {
103+ const brand = mergeOrgBrandConfig ( await orgSettings , getBrandConfig ( ) )
104+ return < ApplicationLoading brand = { brand } />
105+ }
106+
107+ async function WorkspaceContent ( {
108+ children,
109+ workspaceId,
110+ session,
111+ queryClient,
112+ hostContext,
113+ orgSettings,
114+ } : WorkspaceContentProps ) {
63115 const activeOrganizationId = getActiveOrganizationId ( session )
64116 const principal = {
65117 kind : 'session' ,
@@ -79,9 +131,7 @@ export default async function WorkspaceLayout({
79131 desktopExecutorRegistered ,
80132 ] = await Promise . all ( [
81133 cookies ( ) ,
82- hostContext . hostOrganizationId
83- ? getOrgWhitelabelSettings ( hostContext . hostOrganizationId )
84- : Promise . resolve ( null ) ,
134+ orgSettings ,
85135 prefetchWorkspaceSidebar (
86136 queryClient ,
87137 workspaceId ,
0 commit comments