Skip to content

Commit

Permalink
FIX: correctly apply local dates on event dates (#671)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jjaffeux authored Dec 23, 2024
1 parent 0d13b05 commit 46c93b8
Showing 1 changed file with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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)}`;
Expand Down

0 comments on commit 46c93b8

Please sign in to comment.