-
Notifications
You must be signed in to change notification settings - Fork 1
Refactor/#008 블록 렌더링 로직 수정 #12
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
The head ref may contain hidden characters: "refactor/#008_\uBE14\uB85D_\uB80C\uB354\uB9C1_\uB85C\uC9C1_\uC218\uC815"
Conversation
Co-authored-by: minjungw00 <minjungw00@naver.com> Co-authored-by: Jang seo yun <pipisebastian@users.noreply.github.com>
| setInnerHTML({ element: blockRef.current, block }); | ||
| } | ||
| }, [block.crdt.serialize()]); | ||
| }, [getTextAndStylesHash(block)]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JSON형태로 문자열로 바꿔주면, 자주바뀔 수 있는 요소를 불필요한 렌더를 줄일 수 있게 되군요!
좀더 최적화 관련해서 알아보니 memo를 사용해서
- 직접 JSON.stringify 를 매번 실행할 것인지
- memo를 활용해서 메모리 비용을 소모할 것인지
두가지가 있더라구요.
내부 요소의 값이 복잡하면, memo를 선호하고 값이 적으면 매번 stringify를 한다고 하네요.
블럭 내부에 다루는 값이 4개 밖에 안되니, 이경우에는 stringify 가 좀더 비용이 적겠네요..!
const serializedContent = useMemo(() => getTextAndStylesHash(block), [block]);
useEffect(() => {
if (blockRef.current) {
console.log(block.crdt.serialize());
setInnerHTML({ element: blockRef.current, block });
}
}, [serializedContent]);There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
수고많으셨습니다!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
수고하셨습니다.
| if (styleChanged) { | ||
| const className = getClassNames(targetState); | ||
| html += `<span class="${className}" style="white-space: pre;">`; | ||
| spanOpen = true; | ||
| flushCurrentText(); | ||
|
|
||
| // 새로운 스타일 상태 설정 | ||
| currentState = targetState; | ||
|
|
||
| // 새로운 스타일이 있는 경우에만 span 생성 | ||
| if (hasStylesApplied(targetState)) { | ||
| currentSpan = document.createElement("span"); | ||
| currentSpan.className = getClassNames(targetState); | ||
| currentSpan.style.whiteSpace = "pre"; | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이전에는 'span' 태그가 진짜 문자열로 들어갔는데, 이번에는 dom API 사용해서 createElement 수정한거 너무 좋습니다!! 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
수고하셨습니다!!

📝 변경 사항
documentFragment를 통해 DOM Api를 사용하는 방식으로 수정했습니다.🔍 변경 사항 설명
🙏 질문 사항
📷 스크린샷 (선택)
✅ 작성자 체크리스트