Skip to content

Commit 87d6465

Browse files
Merge pull request #75 from ShipFriend0516/fix/coldstart-blog-detail
fix: 블로그 초기로딩시 무한로딩 이슈 해결
2 parents c694224 + 07f52d8 commit 87d6465

5 files changed

Lines changed: 71 additions & 7 deletions

File tree

app/lib/dbConnect.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,12 @@ async function dbConnect(uri?: string, retries = 3): Promise<Mongoose> {
6666
const opts = {
6767
bufferCommands: false,
6868
maxPoolSize: 10,
69-
minPoolSize: 2,
70-
serverSelectionTimeoutMS: 5000,
71-
socketTimeoutMS: 45000,
69+
minPoolSize: 1,
70+
serverSelectionTimeoutMS: 10000,
71+
socketTimeoutMS: 20000,
7272
connectTimeoutMS: 10000,
73+
maxIdleTimeMS: 30000,
74+
waitQueueTimeoutMS: 5000,
7375
};
7476

7577
cached.promise = mongoose

app/posts/[slug]/error.tsx

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
'use client';
2+
3+
import Link from 'next/link';
4+
import { useEffect } from 'react';
5+
6+
export default function Error({
7+
error,
8+
reset,
9+
}: {
10+
error: Error & { digest?: string };
11+
reset: () => void;
12+
}) {
13+
useEffect(() => {
14+
console.error('Post detail error:', error);
15+
}, [error]);
16+
17+
return (
18+
<div className="flex flex-col items-center justify-center min-h-[60vh] px-4">
19+
<div className="max-w-md w-full text-center space-y-6">
20+
<h2 className="text-3xl font-bold text-gray-900 dark:text-gray-100">
21+
글을 불러오는데 실패했습니다
22+
</h2>
23+
<p className="text-gray-600 dark:text-gray-400">
24+
{error.message === 'Post not found'
25+
? '요청하신 글을 찾을 수 없습니다.'
26+
: '일시적인 오류가 발생했습니다. 잠시 후 다시 시도해주세요.'}
27+
</p>
28+
<div className="flex gap-4 justify-center">
29+
<button
30+
onClick={reset}
31+
className="px-6 py-2 bg-primary-mountain text-white rounded-lg hover:bg-primary-mountain-dark transition-colors"
32+
>
33+
다시 시도
34+
</button>
35+
<Link
36+
href="/posts"
37+
className="px-6 py-2 bg-gray-200 dark:bg-gray-700 text-gray-900 dark:text-gray-100 rounded-lg hover:bg-gray-300 dark:hover:bg-gray-600 transition-colors"
38+
>
39+
목록으로
40+
</Link>
41+
</div>
42+
{error.digest && (
43+
<p className="text-xs text-gray-500 dark:text-gray-600">
44+
오류 ID: {error.digest}
45+
</p>
46+
)}
47+
</div>
48+
</div>
49+
);
50+
}

app/posts/[slug]/loading.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import SVGLoadingSpinner from '@/app/entities/common/Loading/SVGLoadingSpinner';
2+
3+
export default function Loading() {
4+
return (
5+
<div className="flex flex-col items-center justify-center min-h-[60vh]">
6+
<SVGLoadingSpinner />
7+
<p className="mt-4 text-gray-600 dark:text-gray-400">
8+
글을 불러오는 중...
9+
</p>
10+
</div>
11+
);
12+
}

app/posts/[slug]/page.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export async function generateStaticParams() {
2121
}
2222

2323
// ISR 활성화하기
24-
export const revalidate = 60; // 60초마다 재검증
24+
export const revalidate = 300; // 300초(5분)마다 재검증
2525

2626
async function getPostDetail(slug: string) {
2727
await dbConnect();
@@ -60,7 +60,7 @@ export const generateMetadata = async ({
6060
authors: [post.author],
6161
},
6262
other: {
63-
'application-name': 'Shipfriend Tech Blog',
63+
'application-name': 'ShipFriend TechBlog',
6464
author: post.author,
6565
publish_date: new Date(post.date).toISOString(),
6666
'og:type': 'article',

app/posts/layout.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { Suspense } from 'react';
2-
import SVGLoadingSpinner from '@/app/entities/common/Loading/SVGLoadingSpinner';
2+
import Loading from './[slug]/loading';
33

44
interface LayoutProps {
55
children: React.ReactNode;
66
}
77
const Layout = ({ children }: LayoutProps) => {
8-
return <Suspense fallback={<SVGLoadingSpinner />}>{children}</Suspense>;
8+
return <Suspense fallback={<Loading />}>{children}</Suspense>;
99
};
1010

1111
export default Layout;

0 commit comments

Comments
 (0)