From 415e9ea95684efe5ab1785302c110fea219663a9 Mon Sep 17 00:00:00 2001 From: Joffrey JAFFEUX Date: Thu, 22 May 2025 11:13:46 +0200 Subject: [PATCH 1/2] FIX: ensures stream update object is scoped to its initial topic Before this commit you could end up in this situation where a `post-updater` is constructed for a specific topic, but the user changes topic mid steam and it ends up updating the same post number but in a different topic as we were only checking for `post_number` and not the combination of `topic_id` + `post_number`. --- .../discourse/lib/ai-streamer/updaters/post-updater.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/assets/javascripts/discourse/lib/ai-streamer/updaters/post-updater.js b/assets/javascripts/discourse/lib/ai-streamer/updaters/post-updater.js index 6c709f153..6b94a4463 100644 --- a/assets/javascripts/discourse/lib/ai-streamer/updaters/post-updater.js +++ b/assets/javascripts/discourse/lib/ai-streamer/updaters/post-updater.js @@ -12,13 +12,15 @@ export default class PostUpdater extends StreamUpdater { constructor(postStream, postId) { super(); + this.postStream = postStream; this.postId = postId; this.post = postStream.findLoadedPost(postId); + const topicId = postStream.topic.id; - if (this.post) { + if (this.post && topicId) { this.postElement = document.querySelector( - `#post_${this.post.post_number}` + `.topic-area[data-topic-id="${topicId}"] #post_${this.post.post_number}` ); } } @@ -57,6 +59,10 @@ export default class PostUpdater extends StreamUpdater { } async setCooked(value) { + if (!this.postElement) { + return; + } + this.post.set("cooked", value); (await loadMorphlex()).morphInner( From 395311b0b685a5fe807b20ffe867452db11d5885 Mon Sep 17 00:00:00 2001 From: Joffrey JAFFEUX Date: Thu, 22 May 2025 11:20:21 +0200 Subject: [PATCH 2/2] we should have the topic --- .../discourse/lib/ai-streamer/updaters/post-updater.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets/javascripts/discourse/lib/ai-streamer/updaters/post-updater.js b/assets/javascripts/discourse/lib/ai-streamer/updaters/post-updater.js index 6b94a4463..3427eb4c3 100644 --- a/assets/javascripts/discourse/lib/ai-streamer/updaters/post-updater.js +++ b/assets/javascripts/discourse/lib/ai-streamer/updaters/post-updater.js @@ -18,7 +18,7 @@ export default class PostUpdater extends StreamUpdater { this.post = postStream.findLoadedPost(postId); const topicId = postStream.topic.id; - if (this.post && topicId) { + if (this.post) { this.postElement = document.querySelector( `.topic-area[data-topic-id="${topicId}"] #post_${this.post.post_number}` );