Skip to content

[강대원] sprint11#140

Merged
pers0n4 merged 22 commits intocodeit-sprint-fullstack:next-강대원from
Daewony:next-강대원-sprint11
Feb 27, 2025

Hidden character warning

The head ref may contain hidden characters: "next-\uac15\ub300\uc6d0-sprint11"
Merged

[강대원] sprint11#140
pers0n4 merged 22 commits intocodeit-sprint-fullstack:next-강대원from
Daewony:next-강대원-sprint11

Conversation

@Daewony
Copy link
Collaborator

@Daewony Daewony commented Feb 9, 2025

요구사항

기본

  • Github에 위클리 미션 PR을 만들어 주세요
  • React 및 Express를 사용해 진행합니다
  • TypeScript를 활용해 프로젝트의 필요한 곳에 타입을 명시해 주세요
  • any 타입의 사용은 최소화해 주세요
  • 복잡한 객체 구조나 배열 구조를 가진 변수에 인터페이스 또는 타입 별칭을 사용하세요
  • Union, Intersection, Generics 등 고급 타입을 적극적으로 사용해 주세요
  • 타입 별칭 또는 유틸리티 타입을 사용해 타입 복잡성을 줄여주세요
  • 타입스크립트 컴파일러가 에러 없이 정상적으로 작동해야 합니다

프론트엔드

  • 기존 React(혹은 Next) 프로젝트를 타입스크립트 프로젝트로 마이그레이션 해주세요
  • TypeScript를 활용해 프로젝트의 필요한 곳에 타입을 명시해 주세요

주요 변경사항

  • 베스트 상품에 SSR 적용하여 기존 CSR방식보다 lighthoust 성능 점수 향상 85->90(No throttling)기준입니다.

스크린샷

멘토에게

  • 백엔드를 NestJS로 처음부터 다시하려니 시간이 많이 걸려 프론트에 신경을 많이 쓰지 못했지만, SSR을 통해 성능이 좋아졌다는 점과 lighthouse 성능 측정을 하면서 색상대비로 인해 점수가 깎일 수 있다는점을 이번주에 알게되었습니다!

  • CSR vs SSR 차이가 두드러지는 것 확인

  • CSR
    -> CSR보다 SSR이 SI(1.5s > 0.4s), LCP(2.5s > 2.1s) 가 좋게 나왔으나 TBT는 점수는 큰 차이가 없다는 것을 알게되었습니다.

  • SSR 후기
    장점

    • 성능 최적화에 효과적임
    • 쿠키를 통해서 유저 정보를 획득할 수 있음 → GNB,NAV의 유저 정보를 통해 깜빡임을 감소시킬 수있음

    단점

    • 팀프로젝트로 빠르게 개발하는데에 CSR로 일관성 있게 개발하는 것이 효율적임
  • 셀프 코드 리뷰를 통해 질문 이어가겠습니다.

Daewony and others added 19 commits December 23, 2024 00:12
@Daewony Daewony self-assigned this Feb 9, 2025
@Daewony Daewony added 매운맛🔥 뒤는 없습니다. 그냥 필터 없이 말해주세요. 책임은 제가 집니다. 최종 제출 스프린트미션 최종 제출본입니다. labels Feb 9, 2025
@Daewony Daewony requested a review from pers0n4 February 9, 2025 08:50
@Daewony Daewony changed the title Next 강대원 sprint11 [강대원] sprint11 Feb 9, 2025
Copy link
Contributor

Choose a reason for hiding this comment

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

빠르게 프로타이필을 하기에는 확실히 tailwind가 좋은 면이 있지만, 이처럼 arbitrary value가 자주 사용되는 경우 안 좋은 패턴을 양산할 수 있으므로 적당한 시점에 컴포넌트나 custom class 등으로 정리를 해보시면 좋을 것 같습니다.

Copy link
Contributor

Choose a reason for hiding this comment

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

productData가 마지막 리턴 구문에만 쓰이기 때문에
if return
if return
변수 할당
return
순으로 코드를 배치했을 수도 있겠다 싶은데요. 관점을 조금 전환해서

  1. 변수 할당
  2. 리던(렌더)
    순으로 섹션을 나눈다고 생각하면 return 꾸문 3개를 모아두는 게 가독성을 높이는 측면에서 더 좋은 선택일 수 있습니다.

Copy link
Collaborator Author

@Daewony Daewony Feb 18, 2025

Choose a reason for hiding this comment

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

@pers0n4
확실히 코드를 생각하면 return 구문을 3개를 모아두는 게 가독성을 높일 수 있다는 것에 공감됩니다.
하지만 조건식으로 리턴을 하지 않는다면 product가 없다고 타입 에러가 발생하는데 어떤식으로 해결하면 좋을까요?
그렇다고 productData : ProductCreateRequest | null 타입으로 하면 타입이 번잡해지고, props를 전달할때도 props를 전달하는 컴포넌트의 전달받는 타입에서도 옵셔널 체이닝으로 처리하게됩니다.
image

Copy link
Contributor

@pers0n4 pers0n4 Feb 27, 2025

Choose a reason for hiding this comment

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

대원님이 제기하신 2가지 우려점에 대한 관점을 한번 바꿔볼까요?

  1. ProductCreateRequest | null는 타입이 번잡해진다
    • ProductCreateRequest | null는 정말 번잡한 타입일까?
    • 타입의 복잡성을 조금 높이는 대신 코드의 밀집도를 높이는 선택 vs 타입의 단순함을 보장하기 위해 코드의 밀집도를 낮추는 선택 중 어떤 것이 진짜 번잡해지는 걸까?
  2. props를 전달할 때도 옵셔널 체이닝으로 처리하게 된다
    • 진짜 그런 문제가 있을까?
  const { data: product, isLoading } = useQuery({
    queryKey: ["product", productId],
    queryFn: () => getProduct(productId),
  });

  const productData: ProductCreateRequest | null = product && {}

  if (isLoading) return <LoadingSpinner />;
  if (!productData) return <div>상품을 찾을 수 없습니다.</div>;

  return (
    <section className="max-w-container mx-auto box-border px-6 pb-40 pt-6">
      <ProductForm
        { /* 위 라인에서 productData가 null인 조건을 배제했기 때문에 여기서는 항상 참임 */ }
        defaultValues={productData}
        productId={productId}
        isEdit={true}
      />
    </section>
  );


return (
<article className="px-6 py-7">
<section className="mx-auto flex max-w-[1200px] flex-col gap-10">
Copy link
Contributor

Choose a reason for hiding this comment

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

1280px은 계속해서 등장하고 있군요. 아예 경계해야 한다고 말씀드렸던 패턴이 바로 지금 이 상황이긴 합니다.
두세 번 반복됐을 때 반복을 줄일 수 있는 수단을 마련해두면 다음부터는 그걸 사용하면 되지만, 관성 때문에 이렇게 쓰던대로 쓰다 보면 나중에는 점점 더 고치기 힘들어지게 되겠죠?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@pers0n4
확인해보니 max-w-[1200px] 이렇게 사용한 페이지가 많았네요..항상 컬러와 폰트, 반응형에 따른 크기 설정만 tailwind custom class로 설정했는데 maxWidth로 해야겠다는 것을 덕분에 알게되었습니다!
max-w-container로 custom해서 적용했습니다!
고민했던 것: max-w-container이 나을지, max-w-1200 직관적으로 보이는 것이 좋을지에 대해 고민했었습니다.
저의 생각: 컴포넌트의 section 태그의 container처럼 활용하여 max-w-container로 하였습니다.

Copy link
Contributor

Choose a reason for hiding this comment

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

utils는 일반적으로 '널리 쓰일 수 있는 함수'를 의미하는데, 이 프로젝트에서는 전부 상수를 정의하는 용도로 사용되고 있군요. 이 경우는 1차 디렉터리 자체를 constants로 분류해보면 어떨까요?

Comment on lines +24 to +27
staleTime: 5 * MINUTES,
gcTime: 30 * MINUTES,
refetchOnWindowFocus: false,
refetchInterval: 1000 * 60 * 10,
refetchInterval: 10 * MINUTES,
Copy link
Contributor

Choose a reason for hiding this comment

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

상수 대신 함수를 만들어서 사용하는 방식도 괜찮을 것 같아요.

id: string;
};

type DropdownStates = { [key: string]: boolean };
Copy link
Contributor

Choose a reason for hiding this comment

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

Record 타입을 활용해보세요. 가독성이 더 향상될 겁니다.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@pers0n4
오! Record 타입을 활용하면 되군요 감사합니다!

Comment on lines +111 to +114
onEdit={() => {
// 댓글 수정 페이지로 이동
router.push(`/comments/${comment.id}/edit`);
}}
Copy link
Contributor

Choose a reason for hiding this comment

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

액션만 고려하면 이벤트로 라우트를 처리할 수 있겠지만, 웹의 본질과 접근성을 고려하면 anchor와 href 속성을 통해 링크를 나타내는 것이 좋습니다.

@Daewony Daewony requested a review from pers0n4 February 18, 2025 09:52
@pers0n4 pers0n4 merged commit fc165c5 into codeit-sprint-fullstack:next-강대원 Feb 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

매운맛🔥 뒤는 없습니다. 그냥 필터 없이 말해주세요. 책임은 제가 집니다. 최종 제출 스프린트미션 최종 제출본입니다.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants