Skip to content

Commit 3a0ec30

Browse files
committed
fix: ShopSignInGuard에 Suspense가 적용되지 않아 전체 페이지 로딩이 느려지던 문제 수정
1 parent 2e50bd3 commit 3a0ec30

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed
Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,25 @@
11
import * as React from "react";
22

3-
import { Typography } from "@mui/material";
3+
import { CircularProgress, Typography } from "@mui/material";
4+
import { ErrorBoundary, Suspense } from "@suspensive/react";
45

56
import ShopHooks from "../hooks";
67

7-
export const ShopSignInGuard: React.FC<{
8+
type ShopSignInGuardProps = {
89
children: React.ReactNode;
910
fallback?: React.ReactNode;
10-
}> = ({ children, fallback }) => {
11+
};
12+
13+
const InnerShopSignInGuard: React.FC<ShopSignInGuardProps> = ({ children, fallback }) => {
1114
const { data } = ShopHooks.useUserStatus();
12-
const renderedFallback = fallback || (
13-
<Typography variant="h6" gutterBottom>
14-
로그인 후 이용해주세요.
15-
</Typography>
16-
);
17-
return data && data.meta.is_authenticated === true
18-
? children
19-
: renderedFallback;
15+
const renderedFallback = fallback || <Typography variant="h6" gutterBottom>로그인 후 이용해주세요.</Typography>;
16+
return data?.meta?.is_authenticated === true ? children : renderedFallback;
17+
};
18+
19+
export const ShopSignInGuard: React.FC<ShopSignInGuardProps> = ({ children, fallback }) => {
20+
return <ErrorBoundary fallback={<>로그인 정보를 불러오는 중 문제가 발생했습니다.</>}>
21+
<Suspense fallback={<CircularProgress />}>
22+
<InnerShopSignInGuard fallback={fallback}>{children}</InnerShopSignInGuard>
23+
</Suspense>
24+
</ErrorBoundary>
2025
};

0 commit comments

Comments
 (0)