Files
supabase/packages/ui-patterns/src/Row/Row.utils.ts
T
Gildas Garcia 86a3f8b03d chore: upgrade to react-19 (#45886)
- Most changes are related to either types or `useRef` usages (it now
requires an initial value).
- also updated `vaul` to its latest version and haven't noticed any
change ([design-system
demo](https://design-system-git-react-19-supabase.vercel.app/design-system/docs/components/drawer))

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
  * Upgraded workspace to React 19.

* **Bug Fixes**
* Improved null-safety and ref handling across editors, UI components,
shortcuts, and markdown/image rendering to reduce runtime errors.
* Safer event/timeout/interval cleanup and more robust command/context
handling.

* **Chores**
  * Bumped vaul dependency versions.

* **Documentation**
* Type and TypeScript accuracy improvements for clearer developer
feedback.

<!-- review_stack_entry_start -->

[![Review Change
Stack](https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg)](https://app.coderabbit.ai/change-stack/supabase/supabase/pull/45886)

<!-- review_stack_entry_end -->
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-05-15 16:04:41 +02:00

39 lines
1.3 KiB
TypeScript

import { useLayoutEffect, useState } from 'react'
export const useMeasuredWidth = <T extends HTMLElement>(ref: React.RefObject<T | null>) => {
const [measuredWidth, setMeasuredWidth] = useState<number | null>(null)
useLayoutEffect(() => {
const element = ref.current
if (!element) return
const initial = element.getBoundingClientRect().width
setMeasuredWidth((prev) => (prev === initial ? prev : initial))
if (typeof ResizeObserver !== 'undefined') {
let frame = 0
const resizeObserver = new ResizeObserver((entries) => {
const width = entries[0]?.contentRect.width ?? 0
if (frame) cancelAnimationFrame(frame)
frame = requestAnimationFrame(() => {
setMeasuredWidth((prev) => (prev === width ? prev : width))
})
})
resizeObserver.observe(element)
return () => {
if (frame) cancelAnimationFrame(frame)
resizeObserver.disconnect()
}
} else {
const handleResize = () => {
const width = element.getBoundingClientRect().width
setMeasuredWidth((prev) => (prev === width ? prev : width))
}
window.addEventListener('resize', handleResize)
return () => window.removeEventListener('resize', handleResize)
}
}, [ref])
return measuredWidth
}