From cead88748004af2988c3f1b51e9c306522d29756 Mon Sep 17 00:00:00 2001 From: Mark VanLandingham Date: Fri, 23 May 2025 13:30:08 -0500 Subject: [PATCH] FIX: Don't error when navigating from AI Bot topic to regular (#1366) We were getting an error in this logic causing Ember to fail to render the non-bot-topic that we navigate to. I believe this is because the getter of participants is re-calculating (due to this.header.topicInfo being updated) before the args to this connector changes. Adding some safe navigation here fixes the issue. --- .../ai-conversation-invite.gjs | 4 +-- spec/system/ai_bot/homepage_spec.rb | 27 +++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/assets/javascripts/discourse/connectors/topic-map-participants-after/ai-conversation-invite.gjs b/assets/javascripts/discourse/connectors/topic-map-participants-after/ai-conversation-invite.gjs index de01ef4f..9da032fc 100644 --- a/assets/javascripts/discourse/connectors/topic-map-participants-after/ai-conversation-invite.gjs +++ b/assets/javascripts/discourse/connectors/topic-map-participants-after/ai-conversation-invite.gjs @@ -18,8 +18,8 @@ export default class AiConversationInvite extends Component { get participants() { const participants = [ - ...this.header.topicInfo.details.allowed_users, - ...this.header.topicInfo.details.allowed_groups, + ...(this.header.topicInfo.details?.allowed_users ?? []), + ...(this.header.topicInfo.details?.allowed_groups ?? []), ]; return participants; } diff --git a/spec/system/ai_bot/homepage_spec.rb b/spec/system/ai_bot/homepage_spec.rb index eca810d1..3510c32f 100644 --- a/spec/system/ai_bot/homepage_spec.rb +++ b/spec/system/ai_bot/homepage_spec.rb @@ -109,6 +109,33 @@ RSpec.describe "AI Bot - Homepage", type: :system do before { SiteSetting.glimmer_post_stream_mode = value } context "when glimmer_post_stream_mode=#{value}" do + context "when mobile", mobile: true do + it "allows navigating from AI conversation to regular topic, and loads new post stream" do + regular_topic = Fabricate(:topic) + regular_post = Fabricate(:post, topic: regular_topic) + + post_url = Topic.relative_url(regular_topic.id, regular_topic.slug) + post_with_link = + Fabricate( + :post, + topic: pm, + user: user, + post_number: 4, + raw: "This is a second reply by the user [link](#{post_url})", + ) + + topic_page.visit_topic(pm) + page.find( + "article[data-post-id='#{post_with_link.id}'] .cooked a[href='#{post_url}']", + ).click + + try_until_success do + expect(topic_page.current_topic).to eq(regular_topic) + expect(page).to have_css("article[data-post-id='#{regular_post.id}']") + end + end + end + context "when `ai_bot_enable_dedicated_ux` is enabled" do it "allows uploading files to a new conversation" do ai_pm_homepage.visit