From c0624d45db9b249df6f794359b572bd66d25e48a Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Mon, 1 Mar 2021 14:04:02 -0500 Subject: [PATCH] FIX: Add appropriate classes to `html` element including `lang` (#12245) This was not working in the Ember CLI version of the application. --- .../discourse/public/assets/scripts/discourse-boot.js | 4 ++++ app/controllers/bootstrap_controller.rb | 2 ++ spec/requests/bootstrap_controller_spec.rb | 3 +++ 3 files changed, 9 insertions(+) diff --git a/app/assets/javascripts/discourse/public/assets/scripts/discourse-boot.js b/app/assets/javascripts/discourse/public/assets/scripts/discourse-boot.js index 1d943729380..6d53b78cf80 100644 --- a/app/assets/javascripts/discourse/public/assets/scripts/discourse-boot.js +++ b/app/assets/javascripts/discourse/public/assets/scripts/discourse-boot.js @@ -242,6 +242,10 @@ head.append(theme_ids); } + let htmlElement = document.getElementsByTagName("html")[0]; + htmlElement.classList = bootstrap.html_classes; + htmlElement.setAttribute("lang", bootstrap.html_lang); + let themeHtml = bootstrap.theme_html; let html = bootstrap.html; diff --git a/app/controllers/bootstrap_controller.rb b/app/controllers/bootstrap_controller.rb index e80b9777f05..5cd0edacdd0 100644 --- a/app/controllers/bootstrap_controller.rb +++ b/app/controllers/bootstrap_controller.rb @@ -60,6 +60,8 @@ class BootstrapController < ApplicationController preloaded: @preloaded, html: create_html, theme_html: create_theme_html, + html_classes: html_classes, + html_lang: html_lang } bootstrap[:extra_locales] = extra_locales if extra_locales.present? bootstrap[:csrf_token] = form_authenticity_token if current_user diff --git a/spec/requests/bootstrap_controller_spec.rb b/spec/requests/bootstrap_controller_spec.rb index 29aaa72a69d..9c240de72ca 100644 --- a/spec/requests/bootstrap_controller_spec.rb +++ b/spec/requests/bootstrap_controller_spec.rb @@ -41,6 +41,9 @@ describe BootstrapController do expect(preloaded['siteSettings']).to be_present expect(preloaded['currentUser']).to be_blank expect(preloaded['topicTrackingStates']).to be_blank + + expect(bootstrap['html_classes']).to eq("desktop-view not-mobile-device text-size-normal anon") + expect(bootstrap['html_lang']).to eq('en') end it "returns user data when authenticated" do