Skip to content

Conversation

@un0211
Copy link
Contributor

@un0211 un0211 commented Jul 10, 2024

연관된 이슈

작업 내용

  • Query Cache 이용해 리다이렉션 깔끔하게 변경
  • 빠른 리다이렉션을 위해 retry 0 으로 변경..

코멘트 및 논의 사항

  • 재요청이 있었으면 좋겠다고 생각하시면 텀을 줄여서 1회 넣어보겠습니다.

@un0211 un0211 added the ♻️ refactor 코드 리팩토링 label Jul 10, 2024
@un0211 un0211 self-assigned this Jul 10, 2024
}, [currentPath, router.query.id]);

return children;
return <QueryClientProvider client={queryClient}>{children}</QueryClientProvider>;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

useModal 훅을 사용하기 위해서 QueryClientProvider가 Redirect 안으로 이동했습니다. (App에서는 사용불가)
App에서 QueryClientProvider를 바로 확인할 수 없어서 헷갈릴 수 있을 것 같습니다.
개선방안 있으면 말씀해주세요!

Copy link
Contributor

Choose a reason for hiding this comment

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

프로바이더를 내부에 넣은 건 어쩔 수 없을 거 같아서 괜찮을 거 같습니다 헷갈리진 않을거 같아요 🫡


useEffect(() => {
const handleRedirect = async () => {
const handleCheckMember = async () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

멤버인지 체크하는 원리는, 멤버만 할 수 있는 요청을 보내고 catch에서 실패할 경우 멤버가 아니라고 판단하는 것입니다.
이게 여전히 잘 동작하는 걸로 봐서, Query Cache의 onError는 모든 재요청 후, 실패에 대한 try catch까지 거친 뒤에도 핸들링되지 않은 요청을 받는 것 같습니다.
retry가 있는 경우 리다이렉션이 느려져서 실패한 경우에도 retry하지 않도록 설정했습니다.

Copy link
Contributor

Choose a reason for hiding this comment

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

리트라이는 더블체크용도 였어서 중요한 부분은 아니여서 없어도 괜찮을거 같아요 테스트해보다가 문제가 있다면 그때 다시 추가하면 될거 같습니다

headers: { memberTest: true },
});
} catch {
redirectIfNotMember();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

리다이렉션 관련 코드 다 지웠습니다!

if (id) handleInitIsPublic();
}, [id]);

useEffect(() => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

여기도 리다이렉션 관련 코드 다 지웠습니다.

return response.data;
} catch (error) {
throw new Error('데이터를 불러오는 중 에러 발생: ' + error);
throw error;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

원본 에러 보내주도록 했습니다.

throw error;
}
},
retry: 1,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

retry 하지 않도록 설정했습니다.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

리다이렉트 훅 깔끔하게 하나로 통일했습니다.

<ReactQueryDevtools initialIsOpen={false} />
</ThemeProvider>
</Redirect>
</QueryClientProvider>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

QueryClientProvider가 Redirect 내부로 이동했습니다.

Copy link
Contributor

@wjsdncl wjsdncl left a comment

Choose a reason for hiding this comment

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

고생하셨습니다! 완전 깔끔해졌네요 👍


useEffect(() => {
const handleRedirect = async () => {
const handleCheckMember = async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

리트라이는 더블체크용도 였어서 중요한 부분은 아니여서 없어도 괜찮을거 같아요 테스트해보다가 문제가 있다면 그때 다시 추가하면 될거 같습니다

}, [currentPath, router.query.id]);

return children;
return <QueryClientProvider client={queryClient}>{children}</QueryClientProvider>;
Copy link
Contributor

Choose a reason for hiding this comment

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

프로바이더를 내부에 넣은 건 어쩔 수 없을 거 같아서 괜찮을 거 같습니다 헷갈리진 않을거 같아요 🫡

Copy link
Contributor

@wayandway wayandway left a comment

Choose a reason for hiding this comment

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

코드가 많이 덜어내졌네요 ㅎㅎ 잘 읽었습니다!!
retry를 0으로 줄여서 빠르게 한 것 좋네요 혜원님 수고하셨습니다!

@un0211
Copy link
Contributor Author

un0211 commented Jul 10, 2024

image

리다이렉트는 잘 되는데 캐시가 안되네요 ㅠㅠ
그냥 queryClient 가 아니라, 우리가 만든 queryCache를 써서 그런 것 아닌가 싶은데, 기본적으로 다 잘 저장하게 하려면 queryCache를 어떻게 설정해야할 지 모르겠네요 ㅠㅠ

@un0211 un0211 merged commit 3a49902 into develop Jul 10, 2024
@un0211 un0211 deleted the refactor/redirect branch July 10, 2024 14:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

♻️ refactor 코드 리팩토링

Projects

None yet

Development

Successfully merging this pull request may close these issues.

♻️ Refactor: Query Cache를 이용한 리다이렉션 개선

4 participants