Skip to content

Conversation

@pipisebastian
Copy link
Member

📝 변경 사항

  • 리스트 가상화 적용

🔍 변경 사항 설명

  • tanstack virtual 라이브러리 설치
  • 리스트 가상화 적용

📷 스크린샷 (선택)

2025-01-22.5.13.27.mov

✅ 작성자 체크리스트

  • Self-review: 코드가 스스로 검토됨
  • Unit tests 추가 또는 수정
  • 로컬에서 모든 기능이 정상 작동함
  • 린터 및 포맷터로 코드 정리됨
  • 의존성 업데이트 확인
  • 문서 업데이트 또는 주석 추가 (필요 시)

Comment on lines 265 to 266
estimateSize: () => 24,
overscan: 5,
Copy link
Member Author

Choose a reason for hiding this comment

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

estimateSize는 기본 블럭 사이즈 24px로 뒀습니다
overscan은 5정도가 되어야 자연스럽게 보였습니다!

Comment on lines 390 to 397
{virtualizer.getVirtualItems().map((virtualRow) => {
const block = editorState.linkedList.spread()[virtualRow.index];
return (
<Block
testKey={`block-${virtualRow.index}`}
virtualStart={virtualRow.start}
virtualIndex={virtualRow.index}
virtualRef={virtualizer.measureElement}
Copy link
Member Author

Choose a reason for hiding this comment

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

virtualizer.getVirtualItems()

원래는 map의 index를 기준으로 몇번째 block인지 접근했었는데
이번에는 virtualizer.getVirtualItems() 가 반환해주는 값이, 뷰포트에 보여지는 아이템 갯수들만 있기 때문에 map의 Index를 쓰면 안됩니다!

대신 virtual 라이브러리에서 제공해주는 index가 순서 index라, 그걸 사용해줘서 몇번째 block인지 뽑아왔습니다

Copy link
Member Author

Choose a reason for hiding this comment

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

virtualRef

이건 각 아이템이 가변적인 높이일때 ref로 넣어줘야합니다. 라이브러리에서 제공하는 measureElement 를 넣어줘야하는데, 처음에 props이름을 그냥 ref로 했었는데 props 전달이 안되더라구요..

ref={virtualizer.measureElement} // 이게 안됨

그래서 virtualRef라는 이름으로 넣어줬습니다

Comment on lines +286 to +288
data-id={id}
data-index={virtualIndex}
key={virtualIndex}
Copy link
Member Author

Choose a reason for hiding this comment

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

data-id는 caretUtil에서 특정 block을 찾기위해 넣어줬습니다.
data-index는 tanstack virtual 라이브러리에서 data-index를 기준으로 요소를 찾더라구요! 그래서 무조건 필요한 값입니다
key도 tanstack virtual 라이브러리에서 필요한 값입니다!

top: 0,
left: 0,
width: "100%",
transform: `translateY(${virtualStart}px)`,
Copy link
Member Author

Choose a reason for hiding this comment

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

해당 start를 통해 어디에 위치시킬지 보여줍니다!

Copy link
Collaborator

@Ludovico7 Ludovico7 left a comment

Choose a reason for hiding this comment

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

고생하셨습니다!

Copy link
Collaborator

@minjungw00 minjungw00 left a comment

Choose a reason for hiding this comment

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

수고많으셨습니다!

@github-actions github-actions bot merged commit 48310db into dev Feb 4, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants