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