A platform for community discussion. Free, open, simple.
FIX: Allow `file-change` events soon after reloading (#13065)
Robin Ward32d6d8308c4b
diff --git a/app/assets/javascripts/discourse/app/initializers/live-development.js b/app/assets/javascripts/discourse/app/initializers/live-development.jsindex 2c15c2f7eee..e65724073e6 100644--- a/app/assets/javascripts/discourse/app/initializers/live-development.js+++ b/app/assets/javascripts/discourse/app/initializers/live-development.js@@ -8,6 +8,7 @@ export default {name: "live-development",initialize(container) {const messageBus = container.lookup("message-bus:main");+ const session = container.lookup("session:main");// Preserve preview_theme_id=## and pp=async-flamegraph parameters across pagesconst params = new URLSearchParams(window.location.search);@@ -48,32 +49,36 @@ export default {}// Observe file changes- messageBus.subscribe("/file-change", function (data) {- if (Handlebars.compile && !Ember.TEMPLATES.empty) {- // hbs notifications only happen in dev- Ember.TEMPLATES.empty = Handlebars.compile("<div></div>");- }- data.forEach((me) => {- if (me === "refresh") {- // Refresh if necessary- document.location.reload(true);- } else {- $("link").each(function () {- if (me.hasOwnProperty("theme_id") && me.new_href) {- const target = $(this).data("target");- const themeId = $(this).data("theme-id");- if (- target === me.target &&- (!themeId || themeId === me.theme_id)- ) {- refreshCSS(this, null, me.new_href);- }- } else if (this.href.match(me.name) && (me.hash || me.new_href)) {- refreshCSS(this, me.hash, me.new_href);- }- });+ messageBus.subscribe(+ "/file-change",+ function (data) {+ if (Handlebars.compile && !Ember.TEMPLATES.empty) {+ // hbs notifications only happen in dev+ Ember.TEMPLATES.empty = Handlebars.compile("<div></div>");}- });- });+ data.forEach((me) => {+ if (me === "refresh") {+ // Refresh if necessary+ document.location.reload(true);+ } else {+ $("link").each(function () {+ if (me.hasOwnProperty("theme_id") && me.new_href) {+ const target = $(this).data("target");+ const themeId = $(this).data("theme-id");+ if (+ target === me.target &&+ (!themeId || themeId === me.theme_id)+ ) {+ refreshCSS(this, null, me.new_href);+ }+ } else if (this.href.match(me.name) && (me.hash || me.new_href)) {+ refreshCSS(this, me.hash, me.new_href);+ }+ });+ }+ });+ },+ session.mbLastFileChangeId+ );},};diff --git a/app/assets/javascripts/discourse/app/pre-initializers/discourse-bootstrap.js b/app/assets/javascripts/discourse/app/pre-initializers/discourse-bootstrap.jsindex ceb7796a184..95e181f5003 100644--- a/app/assets/javascripts/discourse/app/pre-initializers/discourse-bootstrap.js+++ b/app/assets/javascripts/discourse/app/pre-initializers/discourse-bootstrap.js@@ -83,6 +83,10 @@ export default {session.disableCustomCSS = setupData.disableCustomCss === "true";session.markdownItURL = setupData.markdownItUrl;+ if (setupData.mbLastFileChangeId) {+ session.mbLastFileChangeId = parseInt(setupData.mbLastFileChangeId, 10);+ }+if (setupData.safeMode) {session.safe_mode = setupData.safeMode;}diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rbindex 624d3322315..17092306ab2 100644--- a/app/helpers/application_helper.rb+++ b/app/helpers/application_helper.rb@@ -539,6 +539,7 @@ module ApplicationHelperif ENV['DEBUG_PRELOADED_APP_DATA']setup_data[:debug_preloaded_app_data] = trueend+ setup_data[:mb_last_file_change_id] = MessageBus.last_id('/file-change')endif guardian.can_enable_safe_mode? && params["safe_mode"]