Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

성능 최적화를 위한 리액트 쿼리 캐시정책 설정 및 불필요한 fetch하지 않기 #626

Merged
merged 20 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
ddc6b8b
chore: (#619) 리액트 쿼리 캐싱 확인을 위한 세팅
chsua Sep 14, 2023
adfd841
feat: (#619) 마감된 게시물 상세정보 1시간 캐싱하기
chsua Sep 14, 2023
88dea16
design: 에러 메세지 컴포넌트 어절 단위로 개행 및 상하 마진 수정
chsua Sep 15, 2023
891cb8f
feat: (#619) 통계 서버데이터 형식을 사용처가 아닌 불러오는 곳에서 형식 변경
chsua Sep 15, 2023
20ca82a
feat: (#619) 통계 페이지 리액트 쿼리로 수정 및 서스펜스, 에러바운더리 적용
chsua Sep 15, 2023
3c00764
fix: 통계 api msw에서 실서버로 요청 전환
chsua Sep 15, 2023
8a8506c
fix: thead, tbody가 없어서 발생하는 에러 해결
chsua Sep 15, 2023
e218541
Merge branch 'dev' into feat/#619
chsua Sep 15, 2023
e39f5c3
fix: (#627) 개발서버 오리진 url 수정 (#628)
aiaiaiai1 Sep 16, 2023
4e9d264
style: (#622) 선택지가 왼쪽으로 움직이는 버그 수정
Gilpop8663 Sep 15, 2023
4081b70
fix: (#629) https 로컬호스트 오리진 url 추가 (#630)
aiaiaiai1 Sep 18, 2023
65f999e
feat: (#602) 본문 이미지를 붙여넣기 이벤트로 이미지를 첨부할 수 있도록 구현
Gilpop8663 Sep 15, 2023
4693eea
refactor: (#602) 선택지 작성에서 중복되는 업로드 이미지 코드를 리팩터링한 것을 적용
Gilpop8663 Sep 15, 2023
2b8b602
refactor: (#602) 사용하지 않는 async 제거, 부자연스러운 함수명 변경
Gilpop8663 Sep 15, 2023
71a3830
refactor: (#619) 불분명한 변수명 수정
chsua Sep 18, 2023
8af09a4
feat: 열정유저 테이블 내 2개의 api 중 하나라도 로딩/에러 시 테이블 폴백처리
chsua Sep 18, 2023
8e9883b
refactor: (#619) 사용하지 않는 useFetch 삭제
chsua Sep 18, 2023
238562d
feat: (#619) 통계 페이지 에러바운더리/ 서스펜스 범위 수정
chsua Sep 18, 2023
856ef74
refactor: (#619) 서스펜스, 에러바운더리 감싸는 순서를 기존 코드와 통일
chsua Sep 18, 2023
f5e4a2b
feat: 리액트 쿼리 데브 툴 설정
chsua Sep 18, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
public class WebMvcConfig implements WebMvcConfigurer {

private static final String LOCALHOST_FRONTEND = "http://localhost:3000";
private static final String DEV_SERVER = "http://dev.votogether.com";
private static final String HTTPS_LOCALHOST_FRONTEND = "https://localhost:3000";
private static final String DEV_SERVER = "https://dev.votogether.com";
private static final String PROD_SERVER = "https://votogether.com";

private final JwtAuthorizationArgumentResolver jwtAuthorizationArgumentResolver;
Expand All @@ -30,7 +31,7 @@ public void addArgumentResolvers(final List<HandlerMethodArgumentResolver> resol
public void addCorsMappings(final CorsRegistry registry) {
registry.addMapping("/**")
.allowedHeaders("*")
.allowedOrigins(LOCALHOST_FRONTEND, DEV_SERVER, PROD_SERVER)
.allowedOrigins(HTTPS_LOCALHOST_FRONTEND, LOCALHOST_FRONTEND, DEV_SERVER, PROD_SERVER)
.allowedMethods("*")
.allowCredentials(true)
.exposedHeaders(HttpHeaders.LOCATION, HttpHeaders.SET_COOKIE);
Expand Down
160 changes: 146 additions & 14 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"@storybook/react": "^7.0.26",
"@storybook/react-webpack5": "^7.0.26",
"@storybook/testing-library": "^0.0.14-next.2",
"@tanstack/react-query-devtools": "^4.35.3",
"@testing-library/react": "^14.0.0",
"@types/jest": "^29.5.2",
"@types/react": "^18.2.14",
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Suspense } from 'react';
import { RouterProvider } from 'react-router-dom';

import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { ReactQueryDevtools } from '@tanstack/react-query-devtools';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이거 운영(prod) 환경에서는 필요 없을거 같아요! msw처럼 dev에서만 작동하도록 하는거 어떨까요

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can import the devtools like this:

tsx
import { ReactQueryDevtools } from '@tanstack/react-query-devtools'
By default, React Query Devtools are only included in bundles when process.env.NODE_ENV === 'development', so you don't need to worry about excluding them during a production build.


기본적으로 개발환경에서만 번들에 포함되서 빌드된대요

tsx
'@tanstack/react-query-devtools'에서 {ReactQueryDevtools} 가져오기
기본적으로 React Query Devtools는 process.env.Node_ENV === 'development'일 때 번들에만 포함되므로 프로덕션 빌드 시 제외할 걱정이 없습니다.


근데 import만 하고 ReactQueryDevtools가 작성된 곳은 보이지 않는데 확인해주실수 있으실까요?

https://tanstack.com/query/v4/docs/react/devtools#install-and-import-the-devtools

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

지금 로컬이랑 비교해보았는데 기본적으로 개발환경에서만 번들에 포함되서 빌드된대요라고 말씀 주셨던 것처럼 로컬에는 작성되어있는데 깃허브로 올라오면서 삭제되나봐요😅

스크린샷 2023-09-18 오후 5 12 25

import { ThemeProvider } from 'styled-components';

import { AuthProvider } from '@hooks/context/auth';
Expand Down Expand Up @@ -37,8 +38,10 @@ const App = () => (
</AuthProvider>
</PostOptionProvider>
</ThemeProvider>
<ReactQueryDevtools initialIsOpen={false} />
</QueryClientProvider>
</ErrorBoundaryForTopClass>

);

export default App;
17 changes: 12 additions & 5 deletions frontend/src/api/voteResult.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { VoteResultResponse } from '@components/VoteStatistics/type';
import { VoteResult, VoteResultResponse } from '@components/VoteStatistics/type';
import { transVoteStatisticsFormat } from '@components/VoteStatistics/util';

import { getFetch } from '@utils/fetch';

const BASE_URL = process.env.VOTOGETHER_BASE_URL;

export const getPostStatistics = async (postId: number): Promise<VoteResultResponse> => {
return await getFetch<VoteResultResponse>(`${BASE_URL}/posts/${postId}/options`);
export const getPostStatistics = async (postId: number): Promise<VoteResult> => {
const data = await getFetch<VoteResultResponse>(`${BASE_URL}/posts/${postId}/options`);

return transVoteStatisticsFormat(data);
};

export const getOptionStatistics = async ({
Expand All @@ -14,6 +17,10 @@ export const getOptionStatistics = async ({
}: {
postId: number;
optionId: number;
}): Promise<VoteResultResponse> => {
return await getFetch<VoteResultResponse>(`${BASE_URL}/posts/${postId}/options/${optionId}`);
}): Promise<VoteResult> => {
const data = await getFetch<VoteResultResponse>(
`${BASE_URL}/posts/${postId}/options/${optionId}`
);

return transVoteStatisticsFormat(data);
};
3 changes: 3 additions & 0 deletions frontend/src/components/PostForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ export default function PostForm({ data, mutate }: PostFormProps) {
const contentImageHook = useContentImage(
serverImageUrl && convertImageUrlToServerUrl(serverImageUrl)
);
const { handlePasteImage } = contentImageHook;

const writingOptionHook = useWritingOption(
serverVoteInfo?.options.map(option => ({
...option,
Expand Down Expand Up @@ -233,6 +235,7 @@ export default function PostForm({ data, mutate }: PostFormProps) {
placeholder={CONTENT_PLACEHOLDER}
maxLength={POST_CONTENT.MAX_LENGTH}
minLength={POST_CONTENT.MIN_LENGTH}
onPaste={handlePasteImage}
required
/>
<S.ContentLinkButtonWrapper>
Expand Down
14 changes: 11 additions & 3 deletions frontend/src/components/VoteStatistics/VoteStatistics.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import type { Meta, StoryObj } from '@storybook/react';

import { MOCK_VOTE_RESULT } from '@mocks/mockData/voteResult';

import { transVoteStatisticsFormat } from './util';

import VoteStatistics from '.';

const meta: Meta<typeof VoteStatistics> = {
Expand All @@ -12,13 +14,19 @@ export default meta;
type Story = StoryObj<typeof VoteStatistics>;

export const SizeSm: Story = {
render: () => <VoteStatistics size="sm" voteResultResponse={MOCK_VOTE_RESULT} />,
render: () => (
<VoteStatistics size="sm" voteResult={transVoteStatisticsFormat(MOCK_VOTE_RESULT)} />
),
};

export const SizeMd: Story = {
render: () => <VoteStatistics size="md" voteResultResponse={MOCK_VOTE_RESULT} />,
render: () => (
<VoteStatistics size="md" voteResult={transVoteStatisticsFormat(MOCK_VOTE_RESULT)} />
),
};

export const SizeLg: Story = {
render: () => <VoteStatistics size="lg" voteResultResponse={MOCK_VOTE_RESULT} />,
render: () => (
<VoteStatistics size="lg" voteResult={transVoteStatisticsFormat(MOCK_VOTE_RESULT)} />
),
};
Loading
Loading