From 10c25e9b862f6020ae2f005995287e5392485dd0 Mon Sep 17 00:00:00 2001 From: Krzysztof Kotlarek Date: Thu, 24 Aug 2023 08:39:30 +1000 Subject: [PATCH] FIX: sidebar URL full reload when anchor (#23121) Ember LinkTo is not accepting anchors. In that case, we should treat those links as external, which will trigger full reload. --- .../discourse/app/lib/sidebar/section-link.js | 3 ++- spec/system/custom_sidebar_sections_spec.rb | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/discourse/app/lib/sidebar/section-link.js b/app/assets/javascripts/discourse/app/lib/sidebar/section-link.js index e489222b5c1..33ab14900bb 100644 --- a/app/assets/javascripts/discourse/app/lib/sidebar/section-link.js +++ b/app/assets/javascripts/discourse/app/lib/sidebar/section-link.js @@ -22,6 +22,7 @@ export default class SectionLink { this.text = name; this.value = value; this.section = section; + this.withAnchor = value.match(/#\w+$/gi); if (!this.externalOrFullReload) { const routeInfoHelper = new RouteInfoHelper(router, value); @@ -36,7 +37,7 @@ export default class SectionLink { } get externalOrFullReload() { - return this.external || this.fullReload; + return this.external || this.fullReload || this.withAnchor; } @bind diff --git a/spec/system/custom_sidebar_sections_spec.rb b/spec/system/custom_sidebar_sections_spec.rb index b13d448c288..b55fa7460b7 100644 --- a/spec/system/custom_sidebar_sections_spec.rb +++ b/spec/system/custom_sidebar_sections_spec.rb @@ -95,6 +95,24 @@ describe "Custom sidebar sections", type: :system do ) end + it "allows the user to create custom section with anchor" do + sign_in user + visit("/latest") + sidebar.click_add_section_button + + expect(section_modal).to be_visible + expect(section_modal).to have_disabled_save + expect(sidebar.custom_section_modal_title).to have_content("Add custom section") + + section_modal.fill_name("My section") + section_modal.fill_link("Faq", "/faq#anchor") + section_modal.save + + expect(sidebar).to have_section("My section") + take_screenshot + expect(sidebar).to have_section_link("Faq", target: "_blank") + end + it "allows the user to edit custom section" do sidebar_section = Fabricate(:sidebar_section, title: "My section", user: user) sidebar_url_1 = Fabricate(:sidebar_url, name: "Sidebar Tags", value: "/tags")