@@ -495,15 +495,21 @@ const getFocusedNodeData = (
495
495
}
496
496
497
497
const DisplayStructureTree : s . Component = ( ) => {
498
- const [ containerScroll , setContainerScroll ] = s . createSignal ( { top : 0 , height : 0 } )
498
+
499
+ const [ containerScroll , setContainerScroll ] = s . createSignal ( {
500
+ top : 0 ,
501
+ height : 0 ,
502
+ } , {
503
+ equals : ( a , b ) => a . top === b . top && a . height === b . height
504
+ } )
499
505
500
506
const remSize = useRemSize ( )
501
- const getContainerTopMargin = ( ) : number => remSize ( ) * v_margin_in_rem
502
- const getRowHeight = ( ) : number => remSize ( ) * row_height_in_rem
507
+ const getContainerTopMargin = ( ) => remSize ( ) * v_margin_in_rem
508
+ const getRowHeight = ( ) => remSize ( ) * row_height_in_rem
503
509
504
510
const updateScrollData = ( el : HTMLElement ) : void => {
505
511
setContainerScroll ( {
506
- top : Math . max ( el . scrollTop - getContainerTopMargin ( ) , 0 ) ,
512
+ top : Math . max ( el . scrollTop - getContainerTopMargin ( ) , 0 ) ,
507
513
height : el . clientHeight ,
508
514
} )
509
515
}
@@ -621,16 +627,14 @@ const DisplayStructureTree: s.Component = () => {
621
627
} )
622
628
623
629
// Seep the inspected or central node in view when the list is changing
624
- s . createEffect (
625
- defer ( collapsedList , ( ) => {
626
- if ( ! lastFocusedNodeData ) return
627
- const [ nodeId , lastPosition ] = lastFocusedNodeData
628
- const index = getNodeIndexById ( nodeId )
629
- if ( index === - 1 ) return
630
- const move = index - virtual ( ) . start - lastPosition
631
- if ( move !== 0 ) container . scrollTop += move * getRowHeight ( )
632
- } ) ,
633
- )
630
+ s . createEffect ( defer ( collapsedList , ( ) => {
631
+ if ( ! lastFocusedNodeData ) return
632
+ const [ nodeId , lastPosition ] = lastFocusedNodeData
633
+ const index = getNodeIndexById ( nodeId )
634
+ if ( index === - 1 ) return
635
+ const move = index - virtual ( ) . start - lastPosition
636
+ if ( move !== 0 ) container . scrollTop += move * getRowHeight ( )
637
+ } ) )
634
638
635
639
// Scroll to selected node when it changes
636
640
// listen to inspected ID, instead of node, because node reference can change
@@ -752,8 +756,17 @@ const DisplayStructureTree: s.Component = () => {
752
756
< ui . Scrollable
753
757
ref = { el => {
754
758
container = el
755
- setTimeout ( ( ) => updateScrollData ( el ) )
756
- createResizeObserver ( el , ( ) => updateScrollData ( el ) )
759
+ createResizeObserver ( el , ( ) => {
760
+ /*
761
+ Update data in timeout, after the ResizeObserver callback
762
+ To prevent this error:
763
+ > ResizeObserver loop completed with undelivered notifications
764
+ As changing scroll data can then change el.scrollTop
765
+ */
766
+ setTimeout ( ( ) => {
767
+ updateScrollData ( el )
768
+ } )
769
+ } )
757
770
} }
758
771
onScroll = { e => updateScrollData ( e . currentTarget ) }
759
772
>
0 commit comments