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:
parent
0d13b05695
commit
46c93b81f0
|
|
@ -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)}`;
|
||||
|
|
|
|||
Loading…
Reference in New Issue