From b817810d466db3cbb689bc30b31985463563ee63 Mon Sep 17 00:00:00 2001 From: Joffrey JAFFEUX Date: Thu, 22 May 2025 12:08:43 +0200 Subject: [PATCH] FIX: ensures stream update object is scoped to its initial topic (#1359) * 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`. * we should have the topic --- .../discourse/lib/ai-streamer/updaters/post-updater.js | 8 +++++++- 1 file changed, 7 insertions(+), 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 6c709f15..3427eb4c 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) { 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(