FIX: makes highlighting last viewed topic more resilient (#8624)

`highlight` was called from `didInsertElement` which technically doesn't ensure the list is rendered. By wrapping the highlighting code in `afterRender` we ensure it works more consistently.
This commit is contained in:
Joffrey JAFFEUX 2019-12-30 08:18:36 +01:00 committed by GitHub
parent 473e39f4a4
commit 6fa5725292
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,6 +1,7 @@
import discourseComputed from "discourse-common/utils/decorators"; import discourseComputed from "discourse-common/utils/decorators";
import { alias } from "@ember/object/computed"; import { alias } from "@ember/object/computed";
import Component from "@ember/component"; import Component from "@ember/component";
import { schedule } from "@ember/runloop";
import DiscourseURL from "discourse/lib/url"; import DiscourseURL from "discourse/lib/url";
import { bufferedRender } from "discourse-common/lib/buffered-render"; import { bufferedRender } from "discourse-common/lib/buffered-render";
import { findRawTemplate } from "discourse/lib/raw-templates"; import { findRawTemplate } from "discourse/lib/raw-templates";
@ -197,12 +198,18 @@ export const ListItemDefaults = {
navigateToTopic, navigateToTopic,
highlight(opts = { isLastViewedTopic: false }) { highlight(opts = { isLastViewedTopic: false }) {
const $topic = $(this.element); schedule("afterRender", () => {
$topic if (!this.element || this.isDestroying || this.isDestroyed) {
.addClass("highlighted") return;
.attr("data-islastviewedtopic", opts.isLastViewedTopic); }
$topic.on("animationend", () => $topic.removeClass("highlighted")); const $topic = $(this.element);
$topic
.addClass("highlighted")
.attr("data-islastviewedtopic", opts.isLastViewedTopic);
$topic.on("animationend", () => $topic.removeClass("highlighted"));
});
}, },
_highlightIfNeeded: on("didInsertElement", function() { _highlightIfNeeded: on("didInsertElement", function() {