Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: Allow file-change events soon after reloading #13065

Merged
merged 1 commit into from May 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -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 pages
const params = new URLSearchParams(window.location.search);
Expand Down Expand Up @@ -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
);
},
};
Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions app/helpers/application_helper.rb
Expand Up @@ -539,6 +539,7 @@ def client_side_setup_data
if ENV['DEBUG_PRELOADED_APP_DATA']
setup_data[:debug_preloaded_app_data] = true
end
setup_data[:mb_last_file_change_id] = MessageBus.last_id('/file-change')
end

if guardian.can_enable_safe_mode? && params["safe_mode"]
Expand Down