A platform for community discussion. Free, open, simple.
FIX: Decorate posts that are loaded after the initial render in post stream (#14600)
Osama Sayegh7f3468e7d507
diff --git a/app/assets/javascripts/discourse/app/components/user-stream.js b/app/assets/javascripts/discourse/app/components/user-stream.jsindex 3d1c1e6b9ec..0632ab424ee 100644--- a/app/assets/javascripts/discourse/app/components/user-stream.js+++ b/app/assets/javascripts/discourse/app/components/user-stream.js@@ -14,6 +14,7 @@ import { schedule } from "@ember/runloop";export default Component.extend(LoadMore, {tagName: "ul",+ _lastDecoratedElement: null,_initialize: on("init", function () {const filter = this.get("stream.filter");@@ -47,6 +48,7 @@ export default Component.extend(LoadMore, {$(this.element).on("click.discourse-redirect", ".excerpt a", (e) => {return ClickTrack.trackClick(e, this.siteSettings);});+ this._updateLastDecoratedElement();}),// This view is being removed. Shut down operations@@ -59,6 +61,18 @@ export default Component.extend(LoadMore, {$(this.element).off("click.discourse-redirect", ".excerpt a");}),+ _updateLastDecoratedElement() {+ const nodes = this.element.querySelectorAll(".user-stream-item");+ if (nodes.length === 0) {+ return;+ }+ const lastElement = nodes[nodes.length - 1];+ if (lastElement === this._lastDecoratedElement) {+ return;+ }+ this._lastDecoratedElement = lastElement;+ },+actions: {removeBookmark(userAction) {const stream = this.stream;@@ -123,7 +137,15 @@ export default Component.extend(LoadMore, {this.set("loading", true);const stream = this.stream;- stream.findItems().then(() => this.set("loading", false));+ stream.findItems().then(() => {+ this.set("loading", false);+ let element = this._lastDecoratedElement?.nextElementSibling;+ while (element) {+ this.trigger("user-stream:new-item-inserted", element);+ element = element.nextElementSibling;+ }+ this._updateLastDecoratedElement();+ });},},});diff --git a/app/assets/javascripts/discourse/app/lib/plugin-api.js b/app/assets/javascripts/discourse/app/lib/plugin-api.jsindex 7094c0a7b29..b11a07e811c 100644--- a/app/assets/javascripts/discourse/app/lib/plugin-api.js+++ b/app/assets/javascripts/discourse/app/lib/plugin-api.js@@ -311,12 +311,10 @@ class PluginApi {if (!opts.onlyStream) {decorate(ComposerEditor, "previewRefreshed", callback, opts.id);decorate(DiscourseBanner, "didInsertElement", callback, opts.id);- decorate(- this.container.factoryFor("component:user-stream").class,- "didInsertElement",- callback,- opts.id- );+ ["didInsertElement", "user-stream:new-item-inserted"].forEach((event) => {+ const klass = this.container.factoryFor("component:user-stream").class;+ decorate(klass, event, callback, opts.id);+ });}}