Skip to content

Commit

Permalink
fix: reload only active tab to prevent RockMigrations errors
Browse files Browse the repository at this point in the history
  • Loading branch information
BernhardBaumrock committed Mar 21, 2023
1 parent c82a1ff commit ea2426f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 32 deletions.
66 changes: 37 additions & 29 deletions livereload.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,41 +19,49 @@ setTimeout(() => {
evtSource = new EventSource(url, { withCredentials: true });
evtSource.onmessage = function (event) {
let changed = event.data;
if (changed && !reloading) {
console.log(changed);
// check if we are in the admin and have unsaved changes
if (document.querySelectorAll(".InputfieldStateChanged").length) {
console.log("detected change - unsaved changes prevent reload");
// show notification
// delay of 200ms prevents that the notification is shown
// when a page is saved that creates files in the background
setTimeout(() => {
UIkit.notification({
message: "Unsaved changes prevent reload",
status: "warning",
pos: "top-center",
timeout: 0,
});
}, 200);
return;
}
if (document.querySelectorAll("#pw-panel-shade").length) {
console.log("detected change - open panel prevents reload");
if (!changed) return;
if (reloading) return;

// check if the current tab is active
// if not, we do not reload
// this prevents multiple simultaneous reloads that can lead to errors
// when using RockMigrations
if (document.hidden) return;

console.log(changed);
// check if we are in the admin and have unsaved changes
if (document.querySelectorAll(".InputfieldStateChanged").length) {
console.log("detected change - unsaved changes prevent reload");
// show notification
// delay of 200ms prevents that the notification is shown
// when a page is saved that creates files in the background
setTimeout(() => {
UIkit.notification({
message: "Open panel prevents reload",
message: "Unsaved changes prevent reload",
status: "warning",
pos: "top-center",
timeout: 0,
});
return;
}
// all fine, reload page
console.log("detected change - reloading");
reloading = true;
setTimeout(() => {
document.location.reload(true);
}, redirecttimeout);
}, 200);
return;
}
if (document.querySelectorAll("#pw-panel-shade").length) {
console.log("detected change - open panel prevents reload");
UIkit.notification({
message: "Open panel prevents reload",
status: "warning",
pos: "top-center",
timeout: 0,
});
return;
}

// all fine, reload page
console.log("detected change - reloading");
reloading = true;
setTimeout(() => {
document.location.reload(true);
}, redirecttimeout);
};
};

Expand Down
4 changes: 1 addition & 3 deletions livereload.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ea2426f

Please sign in to comment.