Parcourir la source

perf: enable SSR for homepage content

- useWindowWidth defaults to 1280 for SSR (was undefined → rendered nothing)
- Remove `return null` guard so server renders full HTML with cards/images
- Enable SSR for AnimatedEmoji, CardStack, WebAgent, Chatbot (no browser APIs)
- Map, IconCloud, MiniModel keep ssr:false (need WebGL/Mapbox)
- Revert CardStack sizes to avoid mobile layout issues

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
rriecc il y a 9 mois
Parent
commit
390fed22ea
3 fichiers modifiés avec 7 ajouts et 18 suppressions
  1. 1 2
      components/card-stack.tsx
  2. 1 9
      components/home-client.tsx
  3. 5 7
      hooks/useWindowWidth.ts

+ 1 - 2
components/card-stack.tsx

@@ -74,8 +74,7 @@ const CardStack: React.FC<CardStackProps> = ({ photos }) => {
             containerClassName="rounded-2xl"
             height={200}
             loading={index === cards.length - 1 ? "eager" : "lazy"}
-            quality={60}
-            sizes="(max-width: 768px) 200px, 355px"
+            quality={70}
             src={card.imageUrl}
             width={355}
           />

+ 1 - 9
components/home-client.tsx

@@ -46,24 +46,20 @@ const MiniModel = dynamic(
   },
 );
 
-// Lazy load components that were previously eagerly imported
+// Lazy load for code splitting, but allow SSR (these don't need browser APIs)
 const AnimatedEmoji = dynamic(() => import("@/components/animated-emoji"), {
-  ssr: false,
   loading: LoadingPlaceholder,
 });
 
 const CardStack = dynamic(() => import("@/components/card-stack"), {
-  ssr: false,
   loading: LoadingPlaceholder,
 });
 
 const WebAgent = dynamic(() => import("@/components/webagent"), {
-  ssr: false,
   loading: LoadingPlaceholder,
 });
 
 const Chatbot = dynamic(() => import("@/components/chatbot"), {
-  ssr: false,
   loading: LoadingPlaceholder,
 });
 
@@ -102,10 +98,6 @@ export default function HomeClient({
     router.prefetch("/blog");
   }, [router]);
 
-  if (!width) {
-    return null;
-  }
-
   return (
     <div className="flex justify-center flex-col items-center">
       <Tabs

+ 5 - 7
hooks/useWindowWidth.ts

@@ -1,14 +1,12 @@
 import { useState, useEffect } from "react";
 
-function useWindowWidth(): number | undefined {
-  // Initialize width as undefined to indicate that the window size is not yet determined
-  const [width, setWidth] = useState<number | undefined>(undefined);
+// Default to 1280 (max container width) for SSR so server renders meaningful HTML
+const SSR_DEFAULT_WIDTH = 1280;
 
-  useEffect(() => {
-    if (typeof window === "undefined") {
-      return;
-    }
+function useWindowWidth(): number {
+  const [width, setWidth] = useState<number>(SSR_DEFAULT_WIDTH);
 
+  useEffect(() => {
     const handleResize = () => {
       setWidth(Math.min(window.innerWidth, 1280));
     };