From c14b7842683c933ac0690ce6beaa9fb2eee1bfcb Mon Sep 17 00:00:00 2001 From: Sean Davis Date: Thu, 30 Nov 2023 19:45:08 +0000 Subject: [PATCH] Add alert when the page fails to load due to Knockout binding failure --- bundle.js | 13 +++++++++++++ scripts/notifications.js | 13 +++++++++++++ 2 files changed, 26 insertions(+) diff --git a/bundle.js b/bundle.js index ffa6f98d5..efec538d5 100644 --- a/bundle.js +++ b/bundle.js @@ -78188,6 +78188,19 @@ const alert = (message, type = 'primary', timeout = 5e3) => { }, timeout); } +window.addEventListener("error", (event) => { + // Handle KO binding errors, usually occur when knockout is trying to use functions that + // don't exist in the cached javascript, but could also be a genuine error that slipped through + if (event?.error?.message?.startsWith("Unable to process binding")) { + alert( + `There was an error loading the page. Hard Refresh (Ctrl+F5 or Cmd+Shift+R) to clear the cache. + If this persists please post in #wiki-general on discord.`, + 'danger', + 3600e3 + ); + } +}); + module.exports = { alert, }; diff --git a/scripts/notifications.js b/scripts/notifications.js index 9ae69b417..b92bcf8c3 100644 --- a/scripts/notifications.js +++ b/scripts/notifications.js @@ -16,6 +16,19 @@ const alert = (message, type = 'primary', timeout = 5e3) => { }, timeout); } +window.addEventListener("error", (event) => { + // Handle KO binding errors, usually occur when knockout is trying to use functions that + // don't exist in the cached javascript, but could also be a genuine error that slipped through + if (event?.error?.message?.startsWith("Unable to process binding")) { + alert( + `There was an error loading the page. Hard Refresh (Ctrl+F5 or Cmd+Shift+R) to clear the cache. + If this persists please post in #wiki-general on discord.`, + 'danger', + 3600e3 + ); + } +}); + module.exports = { alert, };