Skip to content

Commit

Permalink
fix: Add ClientBoundary component and wrap client components with Sus…
Browse files Browse the repository at this point in the history
…pense
  • Loading branch information
while-basic committed Dec 3, 2024
1 parent 94dd8c5 commit 1cedc12
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
16 changes: 16 additions & 0 deletions components/client-boundary.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use client';

import { Suspense } from 'react';

interface ClientBoundaryProps {
children: React.ReactNode;
fallback?: React.ReactNode;
}

export function ClientBoundary({ children, fallback }: ClientBoundaryProps) {
return (
<Suspense fallback={fallback || <div>Loading...</div>}>
{children}
</Suspense>
);
}
21 changes: 12 additions & 9 deletions components/root-layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import "@/styles/mdx.css"
import Navbar from "@/components/navbar"
import { LoadingScreen } from "@/components/loading-screen"
import { usePageView } from "@/hooks/use-page-view"
import { ClientBoundary } from "./client-boundary"

const geistSans = localFont({
src: "../app/fonts/GeistVF.woff",
src: "./fonts/GeistVF.woff",
variable: "--font-geist-sans",
})

const geistMono = localFont({
src: "../app/fonts/GeistMonoVF.woff",
src: "./fonts/GeistMonoVF.woff",
variable: "--font-geist-mono",
})

Expand All @@ -25,12 +26,14 @@ export function RootLayoutClient({
usePageView()

return (
<div className={`${geistSans.variable} ${geistMono.variable} font-sans antialiased flex min-h-screen flex-col`}>
<LoadingScreen />
<Navbar />
<main>
{children}
</main>
</div>
<ClientBoundary>
<div className={`${geistSans.variable} ${geistMono.variable} font-sans antialiased flex min-h-screen flex-col`}>
<LoadingScreen />
<Navbar />
<main>
{children}
</main>
</div>
</ClientBoundary>
)
}

0 comments on commit 1cedc12

Please sign in to comment.