Skip to content

Commit 317d9fd

Browse files
authored
Merge pull request #6 from pythonkr/fix/shop-signin-guard-not-suspensed
Shop 서버 응답을 기다리느라 전체 페이지 로딩이 느려지는 문제 해소
2 parents 7fac5b2 + 3a0ec30 commit 317d9fd

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

apps/pyconkr/src/debug/page/shop_component/product.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ const ShopProductItem: React.FC<{
160160
<Stack spacing={2}>
161161
{product.option_groups.map((group) => (
162162
<Shop.Components.OptionGroupInput
163+
key={group.id}
163164
optionGroup={group}
164165
options={group.options}
165166
defaultValue={group?.options[0]?.id || ""}
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)