@@ -79,6 +79,7 @@ const dateObserver = new (class {
7979
8080export default class RelativeTimeElement extends HTMLElement implements Intl . DateTimeFormatOptions {
8181 #customTitle = false
82+ #updating = false
8283
8384 get #lang( ) {
8485 return this . closest ( '[lang]' ) ?. getAttribute ( 'lang' ) ?? 'default'
@@ -336,22 +337,24 @@ export default class RelativeTimeElement extends HTMLElement implements Intl.Dat
336337 // Internal: Refresh the time element's formatted date when an attribute changes.
337338 attributeChangedCallback ( attrName : string , oldValue : unknown , newValue : unknown ) : void {
338339 if ( oldValue === newValue ) return
339- if ( attrName === 'title' ) this . #customTitle = true
340- if ( ! this . #customTitle) this . update ( )
340+ if ( attrName === 'title' ) {
341+ this . #customTitle = newValue !== null && this . getFormattedTitle ( ) !== newValue
342+ }
343+ if ( ! this . #updating && ! ( attrName === 'title' && this . #customTitle) ) {
344+ this . update ( )
345+ }
341346 }
342347
343348 update ( ) {
349+ this . #updating = true
344350 const oldText : string = this . #renderRoot. textContent || ''
345351 const oldTitle : string = this . getAttribute ( 'title' ) || ''
346352 let newTitle : string = oldTitle
347353 let newText : string = oldText
348354 const now = new Date ( )
349355 if ( ! this . #customTitle) {
350356 newTitle = this . getFormattedTitle ( ) || ''
351- if ( newTitle ) {
352- this . setAttribute ( 'title' , newTitle )
353- this . #customTitle = false
354- }
357+ if ( newTitle ) this . setAttribute ( 'title' , newTitle )
355358 }
356359
357360 newText = this . getFormattedDate ( now ) || ''
@@ -374,5 +377,6 @@ export default class RelativeTimeElement extends HTMLElement implements Intl.Dat
374377 } else {
375378 dateObserver . unobserve ( this )
376379 }
380+ this . #updating = false
377381 }
378382}
0 commit comments