FIX: correctly apply local dates on event dates (#671)

The next ensures `this.htmlDates` has correctly been set and a render is on going which is going to be awaited by the schedule render. Before this fix `querySelectorAll` could return an empty nodes list as the dates were not rendered yet.

Note next shouldn't have this effect here, so it's either a false positive or another side effect we were not expecting.
This commit is contained in:
Joffrey JAFFEUX 2024-12-23 13:02:05 +01:00 committed by GitHub
parent 0d13b05695
commit 46c93b81f0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 14 additions and 8 deletions

View File

@ -2,7 +2,7 @@ import Component from "@glimmer/component";
import { tracked } from "@glimmer/tracking";
import { action } from "@ember/object";
import didInsert from "@ember/render-modifiers/modifiers/did-insert";
import { schedule } from "@ember/runloop";
import { next, schedule } from "@ember/runloop";
import { service } from "@ember/service";
import { htmlSafe } from "@ember/template";
import { applyLocalDates } from "discourse/lib/local-dates";
@ -59,13 +59,19 @@ export default class DiscoursePostEventDates extends Component {
const result = await cook(this.datesBBCode.join("<span> → </span>"));
this.htmlDates = htmlSafe(result.toString());
schedule("afterRender", () => {
applyLocalDates(
element.querySelectorAll(
`[data-post-id="${this.args.event.id}"] .discourse-local-date`
),
this.siteSettings
);
next(() => {
schedule("afterRender", () => {
if (this.isDestroying || this.isDestroyed) {
return;
}
applyLocalDates(
element.querySelectorAll(
`[data-post-id="${this.args.event.id}"] .discourse-local-date`
),
this.siteSettings
);
});
});
} else {
let dates = `${this.startsAt.format(this.format)}`;