11import fuzzy from 'fuzzy' ;
2- import React , { useEffect , createRef } from 'react' ;
3- import { FixedSizeList , VariableSizeList , shouldComponentUpdate , ListProps } from 'react-window' ;
2+ import React , { useEffect , createRef , useMemo } from 'react' ;
3+ import { FixedSizeList , VariableSizeList , ListProps } from 'react-window' ;
44
55import {
66 DisposableCollection ,
@@ -900,24 +900,28 @@ export class RecycleTree extends React.Component<IRecycleTreeProps> {
900900 }
901901 } , [ ] ) ;
902902
903- const setSize = supportDynamicHeights
904- ? ( ) => {
905- let size = 0 ;
906- if ( wrapRef . current ) {
907- const ref = wrapRef . current ;
908- size = Array . from ( ref . children ) . reduce (
909- ( pre , cur : HTMLElement ) => pre + cur . getBoundingClientRect ( ) . height ,
910- 0 ,
911- ) ;
912- }
913- if ( size ) {
914- this . dynamicSizeMap . set ( index , size ) ;
915- this . layoutItem ( ) ;
916- }
917-
918- return Math . max ( size , RecycleTree . DEFAULT_ITEM_HEIGHT ) ;
919- }
920- : ( ) => { } ;
903+ const setSize = useMemo (
904+ ( ) =>
905+ supportDynamicHeights
906+ ? ( ) => {
907+ let size = 0 ;
908+ if ( wrapRef . current ) {
909+ const ref = wrapRef . current ;
910+ size = Array . from ( ref . children ) . reduce (
911+ ( pre , cur : HTMLElement ) => pre + cur . getBoundingClientRect ( ) . height ,
912+ 0 ,
913+ ) ;
914+ }
915+ if ( size ) {
916+ this . dynamicSizeMap . set ( index , size ) ;
917+ this . layoutItem ( ) ;
918+ }
919+
920+ return Math . max ( size , RecycleTree . DEFAULT_ITEM_HEIGHT ) ;
921+ }
922+ : ( ) => { } ,
923+ [ supportDynamicHeights ] ,
924+ ) ;
921925
922926 const itemStyle = overflow === 'ellipsis' ? style : { ...style , width : 'auto' , minWidth : '100%' } ;
923927
@@ -930,7 +934,6 @@ export class RecycleTree extends React.Component<IRecycleTreeProps> {
930934 template = { template }
931935 hasPrompt = { ! ! this . promptHandle && ! this . promptHandle . destroyed }
932936 expanded = { CompositeTreeNode . is ( item ) ? ( item as CompositeTreeNode ) . expanded : void 0 }
933- setSize = { setSize }
934937 >
935938 { children as INodeRenderer }
936939 </ NodeRendererWrap >
@@ -942,7 +945,6 @@ export class RecycleTree extends React.Component<IRecycleTreeProps> {
942945 if ( ! this . props . supportDynamicHeights ) {
943946 return ;
944947 }
945- // (this.listRef?.current as VariableSizeList<any>).resetAfterIndex(0);
946948 // eslint-disable-next-line no-unsafe-optional-chaining
947949 if ( this . listRef && this . listRef ?. current && '_getRangeToRender' in this . listRef ?. current ) {
948950 // _getRangeToRender 是 react-window 的内部方法,用于获取可视区域的下标范围
0 commit comments