@@ -194,6 +194,15 @@ export function updatedTree(
194
194
return [ nextRoots , nextMap ] ;
195
195
}
196
196
197
+ function pathHasChanged ( currentPath : ElementAttributes [ ] , newPath : ElementAttributes [ ] ) {
198
+ return (
199
+ currentPath . length !== newPath . length ||
200
+ ! currentPath . every ( ( elem , index ) => {
201
+ return elem . elementUuid === newPath [ index ] . elementUuid && elem . elementName === newPath [ index ] . elementName ;
202
+ } )
203
+ ) ;
204
+ }
205
+
197
206
export default function TreeViewsContainer ( ) {
198
207
const dispatch = useDispatch ( ) ;
199
208
@@ -202,6 +211,9 @@ export default function TreeViewsContainer() {
202
211
const user = useSelector ( ( state : AppState ) => state . user ) ;
203
212
const selectedDirectory = useSelector ( ( state : AppState ) => state . selectedDirectory ) ;
204
213
const activeDirectory = useSelector ( ( state : AppState ) => state . activeDirectory ) ;
214
+ const currentPath = useSelector ( ( state : AppState ) => state . currentPath ) ;
215
+ const currentPathRef = useRef < ElementAttributes [ ] > ( [ ] ) ;
216
+ currentPathRef . current = currentPath ;
205
217
206
218
const uploadingElements = useSelector ( ( state : AppState ) => state . uploadingElements ) ;
207
219
const uploadingElementsRef = useRef < Record < string , UploadingElement > > ( { } ) ;
@@ -322,7 +334,12 @@ export default function TreeViewsContainer() {
322
334
323
335
/* Manage current path data */
324
336
useEffect ( ( ) => {
325
- dispatch ( setCurrentPath ( buildPathToFromMap ( selectedDirectoryRef . current ?. elementUuid , treeData . mapData ) ) ) ;
337
+ // Do not change currentPath everytime mapData changed
338
+ // if it's the same path (same uuids same names in order) then do not dispatch
339
+ const newPath = buildPathToFromMap ( selectedDirectoryRef . current ?. elementUuid , treeData . mapData ) ;
340
+ if ( pathHasChanged ( currentPathRef . current , newPath ) ) {
341
+ dispatch ( setCurrentPath ( newPath ) ) ;
342
+ }
326
343
} , [ dispatch , treeData . mapData , selectedDirectory ?. elementUuid ] ) ;
327
344
328
345
const insertContent = useCallback (
0 commit comments