Skip to content

Commit e9949f8

Browse files
committed
fix(web): wrap pathname-aware AppChrome in Suspense for cacheComponents
The dynamic /chats/[chatId] route failed to prerender ("uncached data accessed outside <Suspense>") because AppChrome read usePathname() at the top level. Move the pathname-dependent frame into a Suspense-wrapped WorkspaceChrome so the dynamic read sits inside a boundary. Production build now emits the workspace routes as Partial Prerender (13/13).
1 parent dc095d6 commit e9949f8

1 file changed

Lines changed: 18 additions & 5 deletions

File tree

apps/web/src/components/shell/app-chrome.tsx

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,27 @@ import { AppSidebar } from "@/components/shell/app-sidebar";
66
import { cn } from "@/lib/ui/cn";
77

88
export function AppChrome({ children }: { children: ReactNode }) {
9-
const pathname = usePathname();
10-
const isWorkspace = pathname.startsWith("/projects") || pathname.startsWith("/chats");
11-
9+
// The chrome layout depends on `usePathname()` (dynamic) to tell workspace
10+
// routes (/projects, /chats) from the rest. Under Next's `cacheComponents`,
11+
// that dynamic read must live inside a <Suspense> boundary or the dynamic
12+
// `/chats/[chatId]` route fails to prerender. Keeping the whole pathname-aware
13+
// frame in WorkspaceChrome satisfies that without changing runtime behavior.
1214
return (
1315
<main className="min-h-screen bg-white text-thread-text-primary">
1416
<Suspense fallback={null}>
15-
<AppSidebar variant={isWorkspace ? "rail" : "full"} />
17+
<WorkspaceChrome>{children}</WorkspaceChrome>
1618
</Suspense>
19+
</main>
20+
);
21+
}
22+
23+
function WorkspaceChrome({ children }: { children: ReactNode }) {
24+
const pathname = usePathname();
25+
const isWorkspace = pathname.startsWith("/projects") || pathname.startsWith("/chats");
26+
27+
return (
28+
<>
29+
<AppSidebar variant={isWorkspace ? "rail" : "full"} />
1730
<div
1831
className={cn(
1932
"min-h-screen min-w-0",
@@ -25,6 +38,6 @@ export function AppChrome({ children }: { children: ReactNode }) {
2538
>
2639
{children}
2740
</div>
28-
</main>
41+
</>
2942
);
3043
}

0 commit comments

Comments
 (0)