Open neongreen opened 2 years ago
My workaround has been to ask the user to reload the page manually:
// app.js
$(window).on("error", function(evt) {
var e = evt.originalEvent; // get the javascript event
if (e.message) {
alert("JavaScript error:\n " + e.message + "\n" +
"Line:\n " + e.lineno + "\n" +
"File:\n " + e.filename + "\n\n" +
"Please reload the page!");
} else {
alert("JavaScript error:\n " + e.type + "\n" +
"Element:\n " + (e.srcElement || e.target) + "\n\n" +
"Please reload the page!");
}
});
Scenario:
In this scenario, JS asset versions will change and Turbolinks will attempt to load the new versions of all assets without unloading the old versions:
This will lead to silent errors like those:
Any behavior relying on custom JS will silently break.
I propose detecting this with
window.onerror
and doing a full page reload or.. something. Not sure what exactly should be done.