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

refactor: 마커 렌더링 방식을 개선한다 #924

Merged
merged 18 commits into from
Nov 9, 2023
Merged

Conversation

kyw0716
Copy link
Member

@kyw0716 kyw0716 commented Nov 9, 2023

📄 Summary

이전에 마커 렌더링 최적화를 위해 충전소 마커를 렌더링 하는 구조를 크게 수정했었습니다. 문제는 해결할 수 있었으나 다음의 문제점이 존재했습니다.

  • 마커 렌더링을 위한 커스텀 훅에 사용 방식이 강제되어 있어 마커를 렌더링하는 과정이 다소 복잡하다.
  • 기존의 리액트에서 렌더링을 하던 컴포넌트 구조와 다른 방식을 사용하므로 코드의 일관성이 떨어져 유지보수성이 좋지 못하다.

문제의 원인인 줄 알고 있었던 잦은 상태 변경을 최소화 하고자 구조를 수정했었지만 다시 한번 원인을 분석해본 결과 useEffect의 사용이 문제가 됨을 알 수 있었습니다. 테스트 해본 결과 useLayoutEffect를 사용해 개선할 수 있었던 문제였으므로 이를 개선했습니다.

개선 이후 다음과 같은 효과가 있을 것으로 기대합니다.

  • 기존의 리액트에서 렌더링을 하던 구조를 벗어나지 않고 마커를 렌더링할 수 있게 되어 코드의 유지보수성을 개선할 수 있다.
  • 변경된 방식에서 요청한 영역 밖의 마커들을 제거하기 위해 거쳤던 복잡한 연산이 리액트에 의해 제어될 수 있으므로 코드의 복잡도가 감소한다.

🕰️ Actual Time of Completion

4시간

🙋🏻 More

좀 무거운 구조 개선이 있어서 혹시 버그가 있을 수 있는지 한번 다른 기능들 사용해주시면 좋을 것 같습니다.

close #914

🚀 Storybook

https://storybook.carffe.in/

- 기본 마커 렌더링
- 카페인 마커 렌더링

[#914]
- 다음의 복잡한 처리들을 리액트에 위임하는 구조로 변경 (기존에는 훅이 이를 대체했음)
  - 중복 마커 생성 방지
  - 영역 밖 마커 삭제

[#914]
- 현재는 infoWindow를 특정 메서드를 통해 직접 제어하는 방식을 사용했지만, 마커 컴포넌트에 isOpen props를 넘겨 이를 제어하는 방식으로 해보고자 함.

[#914]
- 검색 결과로 화면에 존재하지 않는 마커를 생성할 때의 과정 수정
- 마커가 렌더링 될 때 마커 인스턴스 전역 상태에 지금 렌더링 하려는 마커가 포함되어 있다면 재생성을 하지 않는 로직 추가

[#914]
@kyw0716 kyw0716 added 🛠️ 리팩터링 개선사항입니다 FE 프론트엔드 관련 이슈입니다 labels Nov 9, 2023
@kyw0716 kyw0716 self-assigned this Nov 9, 2023
@@ -5,7 +5,9 @@ import DataDownloader from '@ui/DataDownloader';
import CarFfeineMapListener from './CarFfeineListener';

const UserFilterListener = lazy(() => import('./UserFilterListener'));
const MarkersContainers = lazy(() => import('@marker/MarkerContainers'));
const MarkersContainers = lazy(
() => import('@marker/components/MarkerContainers/MarkerContainers')
Copy link
Member

Choose a reason for hiding this comment

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

index.ts에서 접근할 수 있게 해주세용

Comment on lines 16 to 23
useLayoutEffect(() => {
// 검색 결과로 강제 생성한 마커에 대해선 새로운 마커 생성을 시도하지 않도록 한다.
if (markerInstanceStore.getState().every(({ id }) => id !== station.stationId)) {
const unMount = renderDefaultMarker(station);

return unMount;
}
}, []);
Copy link
Member

Choose a reason for hiding this comment

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

👍

Copy link
Member

@gabrielyoon7 gabrielyoon7 left a comment

Choose a reason for hiding this comment

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

기존의 단순한 구조로 돌아오면서 렌더링 방식 개선까지 되어서 좋은 것 같습니다. 어프룹 드립니다

@feb-dain feb-dain merged commit ce2f3b1 into develop Nov 9, 2023
3 checks passed
@feb-dain feb-dain deleted the refactor/914 branch November 9, 2023 06:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FE 프론트엔드 관련 이슈입니다 🛠️ 리팩터링 개선사항입니다
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

마커 렌더링 방식을 개선한다
3 participants