@@ -125,10 +125,11 @@ export function useTreeLoader<T>(
125
125
const activeTrailIdsIndex = Object . fromEntries ( activeTrailIds . map ( ( id ) => [ id , true ] ) ) ;
126
126
const expandedIdsIndex = expandedIds || { } ;
127
127
128
- function buildOutputNode ( node : TreeSourceNode < T > ) : TreeNode < T > {
128
+ function buildOutputNode ( node : TreeSourceNode < T > , depth : number ) : TreeNode < T > {
129
129
const nodeId = node . id ;
130
130
const current = statefulNodes . current [ nodeId ] ;
131
- const mappedChildren = ( children [ nodeId ] ? children [ nodeId ] . items : [ ] ) . map ( buildOutputNode ) ;
131
+ const mappedChildren = ( children [ nodeId ] ? children [ nodeId ] . items : [ ] )
132
+ . map ( ( child ) => buildOutputNode ( child , depth + 1 ) ) ;
132
133
const isActive = activeId === nodeId ;
133
134
const isActiveTrail = ! ! activeTrailIdsIndex [ nodeId ] ;
134
135
const isExpanded = expandedIdsIndex [ nodeId ] === true
@@ -138,6 +139,7 @@ export function useTreeLoader<T>(
138
139
&& current . isExpanded === isExpanded
139
140
&& current . isActiveTrail === isActiveTrail
140
141
&& current . isActive === isActive
142
+ && current . depth === depth
141
143
&& current . children . isLoading === isLoadingChildren
142
144
&& valuesEqual ( current . children . items , mappedChildren ) ) {
143
145
// Item is still up-to-date. Return the same instance to allow React.memo magic.
@@ -148,14 +150,15 @@ export function useTreeLoader<T>(
148
150
isExpanded,
149
151
isActive,
150
152
isActiveTrail,
153
+ depth,
151
154
children : { isLoading : isLoadingChildren , items : mappedChildren } ,
152
155
} ;
153
156
statefulNodes . current [ nodeId ] = outputNode ;
154
157
return outputNode ;
155
158
}
156
159
157
160
return {
158
- items : rootNodes . items . map ( buildOutputNode ) ,
161
+ items : rootNodes . items . map ( ( item ) => buildOutputNode ( item , 0 ) ) ,
159
162
isLoading : rootNodes . isLoading ,
160
163
allNodes : statefulNodes . current ,
161
164
} ;
0 commit comments