@@ -230,14 +230,37 @@ export function useFloatingTooltip(
230230const overflowMeasureByElement = new WeakMap < Element , ( ) => void > ( )
231231const observedOverflowElements = new Set < Element > ( )
232232let sharedOverflowObserver : ResizeObserver | null = null
233+ let sharedOverflowFontSet : FontFaceSet | null = null
234+
235+ function measureObservedOverflow ( ) {
236+ for ( const element of observedOverflowElements ) overflowMeasureByElement . get ( element ) ?.( )
237+ }
238+
239+ function observeOverflowFontChanges ( ) {
240+ if ( typeof document === 'undefined' || ! document . fonts || sharedOverflowFontSet ) return
241+ const fontSet = document . fonts
242+ sharedOverflowFontSet = fontSet
243+ fontSet . addEventListener ( 'loadingdone' , measureObservedOverflow )
244+ fontSet . addEventListener ( 'loadingerror' , measureObservedOverflow )
245+ void fontSet . ready . then ( ( ) => {
246+ if ( sharedOverflowFontSet === fontSet ) measureObservedOverflow ( )
247+ } )
248+ }
249+
250+ function unobserveOverflowFontChanges ( ) {
251+ sharedOverflowFontSet ?. removeEventListener ( 'loadingdone' , measureObservedOverflow )
252+ sharedOverflowFontSet ?. removeEventListener ( 'loadingerror' , measureObservedOverflow )
253+ sharedOverflowFontSet = null
254+ }
233255
234256function observeOverflow ( element : Element , measure : ( ) => void ) : boolean {
257+ overflowMeasureByElement . set ( element , measure )
258+ observedOverflowElements . add ( element )
259+ observeOverflowFontChanges ( )
235260 if ( typeof ResizeObserver === 'undefined' ) return false
236261 sharedOverflowObserver ??= new ResizeObserver ( ( entries ) => {
237262 for ( const entry of entries ) overflowMeasureByElement . get ( entry . target ) ?.( )
238263 } )
239- overflowMeasureByElement . set ( element , measure )
240- observedOverflowElements . add ( element )
241264 sharedOverflowObserver . observe ( element )
242265 return true
243266}
@@ -250,13 +273,14 @@ function unobserveOverflow(element: Element | null) {
250273 if ( observedOverflowElements . size === 0 ) {
251274 sharedOverflowObserver ?. disconnect ( )
252275 sharedOverflowObserver = null
276+ unobserveOverflowFontChanges ( )
253277 }
254278}
255279
256280/**
257281 * Tracks whether an element's text is horizontally clipped, re-measuring when
258- * `measurementKey` changes and via a shared `ResizeObserver` (or window resizes
259- * when the API is unavailable).
282+ * `measurementKey` or loaded fonts change and via a shared `ResizeObserver` (or
283+ * window resizes when the API is unavailable).
260284 *
261285 * Returns a callback `ref` to attach to the element — the observer follows the
262286 * element across mount, unmount, and reassignment, so it is safe to use on
0 commit comments