Skip to content

fix(dynamic): handle dynamically inserted time elements via MutationObserver (#22)#83

Merged
ralflang merged 1 commit into
horde:pr/83-relative-time-observerfrom
jcdelepine:fix/relative-time
Jun 27, 2026
Merged

fix(dynamic): handle dynamically inserted time elements via MutationObserver (#22)#83
ralflang merged 1 commit into
horde:pr/83-relative-time-observerfrom
jcdelepine:fix/relative-time

Conversation

@jcdelepine

Copy link
Copy Markdown
Contributor

Title: fix(dynamic): handle dynamically inserted time elements via MutationObserver (#22)

Description:

The patch f398f58 replaced time-elements.js with relative_time.js using Intl.RelativeTimeFormat for localization. However, it lost the MutationObserver that time-elements.js used to detect <time is="time-ago"> elements inserted dynamically via AJAX.

As a result, the relative time labels were never rendered for messages loaded dynamically in the mailbox view, leaving the <time> element empty and producing output like:

Yesterday, 4:05:55 PM CEST ()

This issue may be browser and timing dependent — connectedCallback fires reliably in some environments but not others, particularly under Firefox or when elements are inserted after script execution. The MutationObserver approach is robust regardless of browser or insertion timing.

Fix by replacing the one-shot DOMContentLoaded + sweep() with an init() function that runs sweep() for pre-existing elements and installs a MutationObserver to catch future insertions.

@ralflang ralflang changed the base branch from FRAMEWORK_6_0 to pr/83-relative-time-observer June 27, 2026 11:47
@ralflang

Copy link
Copy Markdown
Member

Thanks — retargeted to pr/83-relative-time-observer so we can pair this with a small fix at the AJAX insertion site in js/base.js.

@ralflang ralflang merged commit 0cdf5b5 into horde:pr/83-relative-time-observer Jun 27, 2026
0 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants