@@ -11,6 +11,7 @@ import type { defaultSnapProps, ResizeSource, snapPoints } from '../types'
11
11
import { processSnapPoints , roundAndCheckForNaN } from '../utils'
12
12
import { useReady } from './useReady'
13
13
import { ResizeObserverOptions } from '@juggle/resize-observer/lib/ResizeObserverOptions'
14
+ import { useLayoutEffect } from './useLayoutEffect'
14
15
15
16
export function useSnapPoints ( {
16
17
contentRef,
@@ -187,13 +188,16 @@ function useElementSizeObserver(
187
188
188
189
useDebugValue ( `${ label } : ${ size } ` )
189
190
190
- const handleResize = useCallback ( ( entries : ResizeObserverEntry [ ] ) => {
191
- // we only observe one element, so accessing the first entry here is fine
192
- setSize ( entries [ 0 ] . borderBoxSize [ 0 ] . blockSize )
193
- resizeSourceRef . current = 'element'
194
- } , [ ] )
191
+ const handleResize = useCallback (
192
+ ( entries : ResizeObserverEntry [ ] ) => {
193
+ // we only observe one element, so accessing the first entry here is fine
194
+ setSize ( entries [ 0 ] . borderBoxSize [ 0 ] . blockSize )
195
+ resizeSourceRef . current = 'element'
196
+ } ,
197
+ [ resizeSourceRef ]
198
+ )
195
199
196
- useEffect ( ( ) => {
200
+ useLayoutEffect ( ( ) => {
197
201
if ( ! ref . current || ! enabled ) {
198
202
return
199
203
}
@@ -232,7 +236,7 @@ function useMaxHeight(
232
236
}
233
237
} , [ ready , setReady ] )
234
238
235
- useEffect ( ( ) => {
239
+ useLayoutEffect ( ( ) => {
236
240
// Bail if the max height is a controlled prop
237
241
if ( controlledMaxHeight ) {
238
242
setMaxHeight ( roundAndCheckForNaN ( controlledMaxHeight ) )
0 commit comments