@@ -51,7 +51,7 @@ const fitZoomToNodes = debounce(
5151 (
5252 instance : PetrinautReactFlowInstance | null ,
5353 canvasContainer : React . RefObject < HTMLDivElement | null > ,
54- setMinZoom : ( minZoom : number ) => void ,
54+ setMinZoom : React . Dispatch < React . SetStateAction < number > > ,
5555 ) => {
5656 const minMaxCoords = instance ?. getNodesBounds ( instance . getNodes ( ) ) ;
5757 const viewportSize = canvasContainer . current ?. getBoundingClientRect ( ) ;
@@ -62,12 +62,17 @@ const fitZoomToNodes = debounce(
6262 viewportSize . width / minMaxCoords . width ,
6363 ) ;
6464 const currentZoom = instance ?. getViewport ( ) . zoom ;
65- // Don't reduce the zoom level below the users current zoom
66- const safeZoom = currentZoom
67- ? Math . min ( currentZoom , newZoom * ZOOM_PADDING )
68- : newZoom * ZOOM_PADDING ;
65+ setMinZoom ( ( currentMinZoom ) => {
66+ // Don't increase min zoom beyond the currently configured minimum.
67+ // On first initialization (min zoom still 0), cap to the user's current zoom.
68+ if ( currentMinZoom === 0 ) {
69+ return currentZoom
70+ ? Math . min ( currentZoom , newZoom * ZOOM_PADDING )
71+ : newZoom * ZOOM_PADDING ;
72+ }
6973
70- setMinZoom ( safeZoom ) ;
74+ return Math . min ( currentMinZoom , newZoom * ZOOM_PADDING ) ;
75+ } ) ;
7176 }
7277 } ,
7378 100 ,
0 commit comments