-
Notifications
You must be signed in to change notification settings - Fork 0
[FIX] Drawer 각 자식에게 Key 지정 #113
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
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
🧹 Nitpick | 🔵 Trivial
🧩 Analysis chain
여러 Drawer 인스턴스가 동시에 렌더링될 경우 중복 키 문제가 발생할 수 있습니다.
정적 키 값(
"drawer-backdrop","drawer-panel")은 단일 Drawer 인스턴스에서는 잘 작동하지만, 동일한 페이지에서 여러 Drawer가 동시에 렌더링되면 중복 키 경고가 발생합니다.코드베이스에서 Drawer의 사용 패턴을 확인하여 여러 인스턴스가 동시에 존재할 가능성이 있는지 검증해주세요.
다음 스크립트를 실행하여 Drawer의 사용 패턴을 확인하세요:
만약 여러 Drawer 인스턴스가 동시에 존재할 수 있다면, 다음과 같이 Props에
id를 추가하여 고유한 키를 생성하는 것을 권장합니다:export type Props = { + /** + * Unique identifier for the drawer instance. + */ + id?: string; /** * The open state of the drawer. */ isOpen: boolean; /** * The function to call when the drawer is closed. */ onClose: () => void; } & PropsWithChildren; -export function Drawer({ isOpen, onClose, children }: Props) { +export function Drawer({ id, isOpen, onClose, children }: Props) { return ( <Portal isOpen={isOpen}> <motion.div - key="drawer-backdrop" + key={id ? `drawer-backdrop-${id}` : "drawer-backdrop"} onClick={onClose} className="fixed inset-0 bg-black/50" initial={FADE_IN_ANIMATION.initial} animate={FADE_IN_ANIMATION.animate} exit={FADE_IN_ANIMATION.exit} /> <div className="fixed top-0 right-0 z-50 h-full"> <motion.div - key="drawer-panel" + key={id ? `drawer-panel-${id}` : "drawer-panel"} className="h-full bg-white shadow-lg" initial={SLIDE_IN_ANIMATION.initial} animate={SLIDE_IN_ANIMATION.animate} exit={SLIDE_IN_ANIMATION.exit} transition={SLIDE_IN_ANIMATION.transition} > {children} </motion.div> </div> </Portal> ); }Also applies to: 43-43
🏁 Script executed:
Length of output: 164
🏁 Script executed:
Length of output: 983
🏁 Script executed:
Length of output: 269
🏁 Script executed:
Length of output: 2167
여러 Drawer 인스턴스 동시 렌더링 시 중복 키 위험은 실제 문제입니다.
코드베이스 분석 결과:
현재 상태: Drawer 컴포넌트는 하나의 인스턴스만 사용 중입니다(Drawer.stories.tsx).
잠재적 위험: Portal 컴포넌트가
createPortal로 document.body에 콘텐츠를 렌더링하므로, 만약 여러 Drawer가 동시에 열려있다면 동일한key="drawer-backdrop"과key="drawer-panel"이 document.body의 직접 자식으로 여러 개 존재하게 되어 React 경고가 발생합니다.현재 코드의 정상성: 단일 Drawer 인스턴스 패턴에서는 정상적으로 작동하며, AnimatePresence 설정도 적절합니다.
권장 사항: 향후 여러 Drawer를 동시에 지원할 가능성이 있다면, 제안된
id기반 키 생성 방식으로 리팩토링하는 것을 권장합니다. 현재는 필수 사항은 아니지만, 컴포넌트 재사용성을 높이기 위한 좋은 개선입니다.🤖 Prompt for AI Agents