Skip to content

A platform for community discussion. Free, open, simple.

FIX: Preload user sidebar attrs when `?enable_sidebar=1` (#19843)

Alan Guo Xiang Tan5db72f8dafd0
diff --git a/app/assets/javascripts/bootstrap-json/index.js b/app/assets/javascripts/bootstrap-json/index.js
index a2087fdc162..87826a54f72 100644
--- a/app/assets/javascripts/bootstrap-json/index.js
+++ b/app/assets/javascripts/bootstrap-json/index.js
@@ -252,6 +252,11 @@ async function buildFromBootstrap(proxy, baseURL, req, response, preload) {
url.searchParams.append("safe_mode", reqUrlSafeMode);
}
+ const enableSidebar = forUrlSearchParams.get("enable_sidebar");
+ if (enableSidebar) {
+ url.searchParams.append("enable_sidebar", enableSidebar);
+ }
+
const reqUrlPreviewThemeId = forUrlSearchParams.get("preview_theme_id");
if (reqUrlPreviewThemeId) {
url.searchParams.append("preview_theme_id", reqUrlPreviewThemeId);
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 41bd4889bc7..7302867e75b 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -640,15 +640,25 @@ class ApplicationController < ActionController::Base
def preload_current_user_data
store_preloaded(
"currentUser",
- MultiJson.dump(CurrentUserSerializer.new(current_user, scope: guardian, root: false)),
+ MultiJson.dump(
+ CurrentUserSerializer.new(
+ current_user,
+ scope: guardian,
+ root: false,
+ enable_sidebar_param: params[:enable_sidebar],
+ ),
+ ),
)
+
report = TopicTrackingState.report(current_user)
+
serializer =
ActiveModel::ArraySerializer.new(
report,
each_serializer: TopicTrackingStateSerializer,
scope: guardian,
)
+
store_preloaded("topicTrackingStates", MultiJson.dump(serializer))
end
diff --git a/app/serializers/concerns/user_sidebar_mixin.rb b/app/serializers/concerns/user_sidebar_mixin.rb
index cd872195858..f70b97bec28 100644
--- a/app/serializers/concerns/user_sidebar_mixin.rb
+++ b/app/serializers/concerns/user_sidebar_mixin.rb
@@ -45,6 +45,6 @@ module UserSidebarMixin
private
def sidebar_navigation_menu?
- !SiteSetting.legacy_navigation_menu?
+ !SiteSetting.legacy_navigation_menu? || options[:enable_sidebar_param] == "1"
end
end
diff --git a/spec/system/page_objects/components/sidebar.rb b/spec/system/page_objects/components/sidebar.rb
new file mode 100644
index 00000000000..06fde5dc8cd
--- /dev/null
+++ b/spec/system/page_objects/components/sidebar.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+module PageObjects
+ module Components
+ class Sidebar < PageObjects::Components::Base
+ def visible?
+ page.has_css?("#d-sidebar")
+ end
+
+ def has_category_section_link?(category)
+ page.has_link?(category.name, class: "sidebar-section-link")
+ end
+ end
+ end
+end
diff --git a/spec/system/viewing_sidebar_spec.rb b/spec/system/viewing_sidebar_spec.rb
new file mode 100644
index 00000000000..4b9da86e9c4
--- /dev/null
+++ b/spec/system/viewing_sidebar_spec.rb
@@ -0,0 +1,22 @@
+# frozen_string_literal: true
+
+describe "Viewing sidebar", type: :system, js: true do
+ fab!(:admin) { Fabricate(:admin) }
+ fab!(:user) { Fabricate(:user) }
+ fab!(:category_sidebar_section_link) { Fabricate(:category_sidebar_section_link, user: user) }
+
+ describe "when using the legacy navigation menu" do
+ before { SiteSetting.navigation_menu = "legacy" }
+
+ it "should display the sidebar when `enable_sidebar` query param is '1'" do
+ sign_in(user)
+
+ visit("/latest?enable_sidebar=1")
+
+ sidebar = PageObjects::Components::Sidebar.new
+
+ expect(sidebar).to be_visible
+ expect(sidebar).to have_category_section_link(category_sidebar_section_link.linkable)
+ end
+ end
+end