fix(ui): relative time elements were reset on htmx swap (#7950)

Regression cf03286b5b

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/7950
Reviewed-by: Gusted <gusted@noreply.codeberg.org>
Co-authored-by: Beowulf <beowulf@beocode.eu>
Co-committed-by: Beowulf <beowulf@beocode.eu>
This commit is contained in:
Beowulf 2025-05-24 23:46:21 +02:00 committed by Gusted
parent 3ae188652a
commit 0e8d752d86
2 changed files with 42 additions and 1 deletions

View file

@ -141,4 +141,10 @@ function UpdateAllRelativeTimes() {
for (const object of document.querySelectorAll('relative-time')) UpdateRelativeTime(object);
}
document.addEventListener('DOMContentLoaded', UpdateAllRelativeTimes);
document.addEventListener('DOMContentLoaded', () => {
UpdateAllRelativeTimes();
// Also update relative-time DOM elements after htmx swap events.
document.body.addEventListener('htmx:afterSwap', () => {
for (const object of document.querySelectorAll('relative-time')) DoUpdateRelativeTime(object);
});
});