@@ -3,7 +3,7 @@ import { memo, useCallback, useEffect, useRef, useState } from "react";
33import { Virtuoso } from "react-virtuoso" ;
44
55import { useAppTree } from "@/hooks/useAppTree" ;
6- import { useCallbackRef } from "@/hooks/useCallbackRef" ;
6+ // import { useCallbackRef } from "@/hooks/useCallbackRef";
77import { useSelectNode } from "@/hooks/useSelectNode" ;
88import { useDomSize } from "@/hooks/useSize" ;
99import { UISize , useUISize } from "@/hooks/useUISize" ;
@@ -56,22 +56,22 @@ const TreeViewImpl = memo(({ onScroll, data, onMount }: { onScroll: () => void;
5656
5757 const size = useUISize . useShallowStableSelector ( ( s ) => s . state ) ;
5858
59- const render = useCallbackRef ( ( index : number , _ : unknown ) => {
59+ const render = ( index : number , _ : unknown ) => {
6060 const node = data [ index ] ;
6161
6262 if ( ! node ) return null ;
6363
6464 return < TreeItem node = { node } className = { size === UISize . sm ? "text-[12px]" : size === UISize . md ? "text-[14px]" : "text-[16px]" } /> ;
65- } ) ;
65+ } ;
6666
6767 useEffect ( ( ) => {
68- onScroll ( ) ;
69-
7068 const cb = useSelectNode . subscribe (
7169 ( s ) => s . scroll ,
7270 ( ) => {
7371 const select = useSelectNode . getReadonlyState ( ) . select ;
72+
7473 const index = dataRef . current ?. findIndex ( ( item ) => item . i === select ) ;
74+
7575 if ( index !== - 1 ) {
7676 ref . current ?. scrollIntoView ( { index, align : "center" , done : onScroll } ) ;
7777 }
@@ -87,16 +87,6 @@ const TreeViewImpl = memo(({ onScroll, data, onMount }: { onScroll: () => void;
8787 return ( ) => onMount ( ) ;
8888 } , [ onMount ] ) ;
8989
90- useEffect ( ( ) => {
91- chrome . devtools ?. inspectedWindow ?. eval ?.( `(() => {
92- if (window['$$$$0'] !== $0) {
93- window.__MY_REACT_DEVTOOL_INTERNAL__?.setSelectDom?.($0);
94- window.__MY_REACT_DEVTOOL_INTERNAL__?.notifySelectSync?.();
95- window['$$$$0'] = $0;
96- }
97- })()` ) ;
98- } , [ ] ) ;
99-
10090 return < Virtuoso ref = { ref } increaseViewportBy = { 500 } onScroll = { onScroll } totalCount = { data . length } itemContent = { render } /> ;
10191} ) ;
10292
@@ -107,7 +97,7 @@ export const TreeView = memo(() => {
10797
10898 const nodes = useAppTree . useShallowStableSelector ( ( s ) => s . list ) as PlainNode [ ] ;
10999
110- const { width } = useDomSize ( { ref } ) ;
100+ const { width, height } = useDomSize ( { ref } ) ;
111101
112102 const [ r , setR ] = useState < VirtuosoHandle > ( ) ;
113103
@@ -125,7 +115,7 @@ export const TreeView = memo(() => {
125115
126116 useEffect ( ( ) => {
127117 onScroll ( ) ;
128- } , [ onScroll , width ] ) ;
118+ } , [ onScroll , width , height , nodes . length ] ) ;
129119
130120 return (
131121 < div className = "tree-view h-full p-1" >
0 commit comments