Skip to content

Commit 74c7919

Browse files
eunjin11claude
andcommitted
fix: 코드 리뷰 지적 사항 2건 수정
- useNetworkSearch: activeNodeRef를 success 콜백 내부가 아닌 effect 시작 시점에 캡처해 빠른 연속 이동 시 race condition 방지 - NetworkDetailSection: highlightQuery 변경 시 manualOpen을 null로 초기화해 새 검색어의 헤더 매치가 자동 펼침되도록 수정 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 06359f6 commit 74c7919

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

package/src/components/NetworkDetailSection.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { type RefObject, useState } from "@lynx-js/react";
1+
import { type RefObject, useEffect, useState } from "@lynx-js/react";
22
import type { NodesRef } from "@lynx-js/types";
33
import { matchNode } from "../hooks/useNetworkSearch";
44
import { useThemeColors } from "../styles/ThemeContext";
@@ -43,6 +43,10 @@ export const NetworkDetailSection = ({
4343
);
4444
// 헤더는 기본 접힘. 검색 결과가 헤더에 있으면 자동으로 펼치고, 탭하면 수동 토글
4545
const [manualOpen, setManualOpen] = useState<boolean | null>(null);
46+
// 검색어가 바뀌면 수동 상태를 초기화해 새 매치 여부를 자동으로 반영한다
47+
useEffect(() => {
48+
setManualOpen(null);
49+
}, [highlightQuery]);
4650
const headersOpen = manualOpen ?? headerHasMatch;
4751

4852
return (

package/src/hooks/useNetworkSearch.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,17 @@ export function useNetworkSearch(networks: NetworkEntry[]) {
131131
const activeEntryIndex = activeMatch?.entryIndex;
132132
useEffect(() => {
133133
if (activeEntryId === undefined || activeEntryIndex === undefined) return;
134+
// effect 시작 시점의 노드를 스냅샷으로 캡처 — 콜백 내부에서 읽으면
135+
// 빠른 연속 이동 시 이미 다른 노드를 가리킬 수 있다
136+
const nodeRef = activeNodeRef.current;
134137
// 1) 항목을 즉시 상단으로 스크롤(smooth:false → success 콜백 시점에 레이아웃 확정)
135138
listRef.current
136139
?.invoke({
137140
method: "scrollToPosition",
138141
params: { index: activeEntryIndex, alignTo: "top", smooth: false },
139142
success: () => {
140-
const nodeRef = activeNodeRef.current;
141143
if (!nodeRef) return;
144+
142145
// 2) 매치 노드의 뷰포트 기준 위치 조회
143146
nodeRef
144147
.invoke({

0 commit comments

Comments
 (0)