layout.jsx 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // ---------------------------------------------------------------------------
  2. // Folder: app/(protected)
  3. // File: layout.jsx
  4. // Relative Path: app/(protected)/layout.jsx
  5. // ---------------------------------------------------------------------------
  6. import React, { Suspense } from "react";
  7. import { Loader2 } from "lucide-react";
  8. import AppShell from "@/components/app-shell/AppShell";
  9. import AuthProvider from "@/components/auth/AuthProvider";
  10. /**
  11. * Protected layout (RHL-020)
  12. *
  13. * Best practice for `useSearchParams()`:
  14. * - AuthProvider uses `useSearchParams()` (client hook).
  15. * - During production builds, static prerendering requires a Suspense boundary
  16. * above the component using `useSearchParams()`.
  17. *
  18. * This Suspense fallback will be part of the initial HTML for static rendering.
  19. * After hydration, AuthProvider takes over and performs the session check.
  20. */
  21. function AuthProviderFallback() {
  22. return (
  23. <div className="min-h-screen w-full px-4">
  24. <div className="mx-auto flex min-h-screen max-w-md items-center justify-center">
  25. <div className="flex items-center gap-3 text-sm text-muted-foreground">
  26. <Loader2 className="h-4 w-4 animate-spin" />
  27. <span>Preparing session...</span>
  28. </div>
  29. </div>
  30. </div>
  31. );
  32. }
  33. export default function ProtectedLayout({ children }) {
  34. return (
  35. <Suspense fallback={<AuthProviderFallback />}>
  36. <AuthProvider>
  37. <AppShell>{children}</AppShell>
  38. </AuthProvider>
  39. </Suspense>
  40. );
  41. }