Skip to content

Commit 67368c4

Browse files
committed
fix: ssr errors on deploying
1 parent f84453f commit 67368c4

4 files changed

Lines changed: 69 additions & 43 deletions

File tree

app/blog/[slug]/blog-post-client.tsx

Lines changed: 60 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,26 @@
11
"use client";
22

3-
import { motion } from "framer-motion";
3+
import { motion, LazyMotion, domAnimation } from "framer-motion";
44
import { ArrowLeft, Calendar, Clock, User } from "lucide-react";
55
import Link from "next/link";
66
import { MDXRemote, MDXRemoteSerializeResult } from "next-mdx-remote";
7+
import { serialize } from "next-mdx-remote/serialize";
78
import type { BlogPost } from "@/lib/mdx";
9+
import { useState, useEffect } from "react";
810

911
interface BlogPostClientProps {
1012
post: BlogPost;
11-
mdxSource: MDXRemoteSerializeResult;
1213
}
1314

14-
export default function BlogPostClient({ post, mdxSource }: BlogPostClientProps) {
15+
export default function BlogPostClient({ post }: BlogPostClientProps) {
16+
const [isMounted, setIsMounted] = useState(false);
17+
const [mdxSource, setMdxSource] = useState<MDXRemoteSerializeResult | null>(null);
18+
19+
useEffect(() => {
20+
setIsMounted(true);
21+
serialize(post.content).then(setMdxSource);
22+
}, [post.content]);
23+
1524
const formattedDate = new Date(post.date).toLocaleDateString("en-US", {
1625
year: "numeric",
1726
month: "long",
@@ -49,29 +58,37 @@ export default function BlogPostClient({ post, mdxSource }: BlogPostClientProps)
4958
),
5059
};
5160

61+
const MotionDiv = isMounted ? motion.div : 'div';
62+
const MotionHeader = isMounted ? motion.header : 'header';
63+
5264
return (
53-
<div className="min-h-screen bg-gradient-to-b from-[#0F172A] via-[#1e293b] to-[#0F172A] py-20">
54-
<article className="max-w-4xl mx-auto px-4 sm:px-6 lg:px-8">
55-
<motion.div
56-
initial={{ opacity: 0, y: 20 }}
57-
animate={{ opacity: 1, y: 0 }}
58-
transition={{ duration: 0.5 }}
59-
>
60-
<Link
61-
href="/blog"
62-
className="inline-flex items-center text-[#38BDF8] hover:underline mb-8"
65+
<LazyMotion features={domAnimation} strict>
66+
<div className="min-h-screen bg-gradient-to-b from-[#0F172A] via-[#1e293b] to-[#0F172A] py-20">
67+
<article className="max-w-4xl mx-auto px-4 sm:px-6 lg:px-8">
68+
<MotionDiv
69+
{...(isMounted && {
70+
initial: { opacity: 0, y: 20 },
71+
animate: { opacity: 1, y: 0 },
72+
transition: { duration: 0.5 }
73+
})}
6374
>
64-
<ArrowLeft className="w-4 h-4 mr-2" />
65-
Back to Blog
66-
</Link>
67-
</motion.div>
75+
<Link
76+
href="/blog"
77+
className="inline-flex items-center text-[#38BDF8] hover:underline mb-8"
78+
>
79+
<ArrowLeft className="w-4 h-4 mr-2" />
80+
Back to Blog
81+
</Link>
82+
</MotionDiv>
6883

69-
<motion.header
70-
initial={{ opacity: 0, y: 20 }}
71-
animate={{ opacity: 1, y: 0 }}
72-
transition={{ delay: 0.2, duration: 0.5 }}
73-
className="mb-12"
74-
>
84+
<MotionHeader
85+
{...(isMounted && {
86+
initial: { opacity: 0, y: 20 },
87+
animate: { opacity: 1, y: 0 },
88+
transition: { delay: 0.2, duration: 0.5 }
89+
})}
90+
className="mb-12"
91+
>
7592
<span className="inline-block px-3 py-1 text-sm font-medium rounded-full bg-[#38BDF8]/10 text-[#38BDF8] border border-[#38BDF8]/20 mb-4">
7693
{post.category}
7794
</span>
@@ -95,19 +112,26 @@ export default function BlogPostClient({ post, mdxSource }: BlogPostClientProps)
95112
</div>
96113
)}
97114
</div>
98-
</motion.header>
115+
</MotionHeader>
99116

100-
<motion.div
101-
initial={{ opacity: 0, y: 20 }}
102-
animate={{ opacity: 1, y: 0 }}
103-
transition={{ delay: 0.4, duration: 0.5 }}
104-
className="max-w-none"
105-
>
106-
<div className="p-8 rounded-xl glass mdx-content">
107-
<MDXRemote {...mdxSource} components={components} />
108-
</div>
109-
</motion.div>
110-
</article>
111-
</div>
117+
<MotionDiv
118+
{...(isMounted && {
119+
initial: { opacity: 0, y: 20 },
120+
animate: { opacity: 1, y: 0 },
121+
transition: { delay: 0.4, duration: 0.5 }
122+
})}
123+
className="max-w-none"
124+
>
125+
<div className="p-8 rounded-xl glass mdx-content">
126+
{mdxSource ? (
127+
<MDXRemote {...mdxSource} components={components} />
128+
) : (
129+
<div className="text-gray-400">Loading content...</div>
130+
)}
131+
</div>
132+
</MotionDiv>
133+
</article>
134+
</div>
135+
</LazyMotion>
112136
);
113137
}

app/blog/[slug]/page.tsx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
11
import { notFound } from "next/navigation";
2-
import { serialize } from "next-mdx-remote/serialize";
32
import { getPostBySlug, getAllPosts } from "@/lib/mdx";
43
import BlogPostClient from "./blog-post-client";
54

65
interface BlogPostPageProps {
7-
params: {
6+
params: Promise<{
87
slug: string;
9-
};
8+
}>;
109
}
1110

1211
export default async function BlogPostPage({ params }: BlogPostPageProps) {
13-
const post = getPostBySlug(params.slug);
12+
const { slug } = await params;
13+
const post = getPostBySlug(slug);
1414

1515
if (!post) {
1616
notFound();
1717
}
1818

19-
const mdxSource = await serialize(post.content);
20-
21-
return <BlogPostClient post={post} mdxSource={mdxSource} />;
19+
return <BlogPostClient post={post} />;
2220
}
2321

2422
// Pre-render all blog posts at build time

app/robots.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { MetadataRoute } from "next";
22

3+
export const dynamic = "force-static";
4+
35
export default function robots(): MetadataRoute.Robots {
46
return {
57
rules: {

app/sitemap.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { MetadataRoute } from "next";
22

3+
export const dynamic = "force-static";
4+
35
export default function sitemap(): MetadataRoute.Sitemap {
46
const baseUrl = "https://tiverse.dev";
57

0 commit comments

Comments
 (0)