11import * as cookie from 'cookie' ;
22import { AnimatePresence } from 'motion/react' ;
3- import { useState } from 'react' ;
3+ import { Suspense , lazy , useState } from 'react' ;
44import { Outlet , redirect } from 'react-router' ;
55
66import { CoinPriceWithName , api as coinApi } from '~/entities/coin' ;
@@ -10,13 +10,15 @@ import { CoinListWithSearchBar } from '~/features/coin-search-list';
1010import { OrderForm , OrderFormFallback } from '~/features/order' ;
1111import { ExecutionList } from '~/features/order-execution-list' ;
1212import useTradeNotification from '~/features/trade/hooks/useTradeNotification' ;
13- import { Orderbook , StockChart } from '~/features/tradeview' ;
1413import Container from '~/shared/ui/Container' ;
1514import ContainerTitle from '~/shared/ui/ContainerTitle' ;
1615import { NavBar , SideBar } from '~/widgets/navbar' ;
1716import { useUserId } from '../provider/UserInfoProvider' ;
1817import type { Route } from './+types/trade.$ticker' ;
1918
19+ const LazyStockChart = lazy ( ( ) => import ( '~/features/tradeview/ui/StockChart' ) ) ;
20+ const LazyOrderBook = lazy ( ( ) => import ( '~/features/tradeview/ui/Orderbook' ) ) ;
21+
2022export async function loader ( { request, params } : Route . LoaderArgs ) {
2123 const rawCookie = request . headers . get ( 'Cookie' ) ;
2224 const cookies = cookie . parse ( rawCookie || '' ) ;
@@ -79,12 +81,14 @@ export default function TradeRouteComponent({
7981 < div className = "h-auto md:col-span-full md:row-span-2 md:row-start-1 xl:col-span-full xl:row-span-1 xl:row-start-1 2xl:col-span-2 2xl:col-start-2 2xl:row-start-1" >
8082 < Container >
8183 < ContainerTitle > 실시간 차트</ ContainerTitle >
82- { coinInfo && (
83- < StockChart
84- key = { `chart-${ coinInfo . ticker } ` }
85- ticker = { coinInfo . ticker }
86- />
87- ) }
84+ < Suspense fallback = "차트데이터를 가져오고 있습니다." >
85+ { coinInfo && (
86+ < LazyStockChart
87+ key = { `chart-${ coinInfo . ticker } ` }
88+ ticker = { coinInfo . ticker }
89+ />
90+ ) }
91+ </ Suspense >
8892 </ Container >
8993 </ div >
9094 < div className = "md:col-span-1 md:col-start-2 md:row-span-2 md:row-start-3 xl:col-span-1 xl:col-start-3 xl:row-span-1 xl:row-start2 2xl:col-start-4 2xl:row-span-1 2xl:row-start-1" >
@@ -100,7 +104,9 @@ export default function TradeRouteComponent({
100104 < div className = "md:col-span-1 md:col-start-1 md:row-span-2 md:row-start-3 xl:col-span-1 xl:col-start-2 xl:row-span-1 xl:row-start-2 2xl:col-start-4 2xl:row-span-full 2xl:row-start-2" >
101105 < Container >
102106 < ContainerTitle > 실시간 호가</ ContainerTitle >
103- { coinInfo && < Orderbook ticker = { coinInfo . ticker } /> }
107+ < Suspense fallback = { null } >
108+ { coinInfo && < LazyOrderBook ticker = { coinInfo . ticker } /> }
109+ </ Suspense >
104110 </ Container >
105111 </ div >
106112 < div className = "md:col-span-full md:row-span-1 md:row-start-5 xl:col-span-1 xl:col-start-1 xl:row-span-1 xl:row-start-2 2xl:col-span-2 2xl:col-start-2 2xl:row-start-2" >
0 commit comments