From e997d091b3a003d5fbd57085b48a4a46f79b6b48 Mon Sep 17 00:00:00 2001 From: George Gevoian Date: Mon, 22 Nov 2021 19:21:40 -0800 Subject: [PATCH] (core) Disable bfcache for all browsers Summary: Grist would get stuck in a broken state in certain browsers that enabled the bfcache when the browser back/forward buttons were clicked. Firefox automatically disabled the cache since we listen on the 'beforeunload' event, but Chrome and Safari did not. This change forces a page refresh on pageshow if we detect that Grist was loaded from the bfcache. Test Plan: Tested manually in various browsers. Reviewers: paulfitz Reviewed By: paulfitz Subscribers: paulfitz, jarek Differential Revision: https://phab.getgrist.com/D3151 --- app/client/app.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/client/app.js b/app/client/app.js index 6649fa9a..15ca0baa 100644 --- a/app/client/app.js +++ b/app/client/app.js @@ -20,6 +20,14 @@ const ko = require('knockout'); setupKoDisposal(ko); $(function() { + // Manually disable the bfcache. We dispose some components in App.ts on unload, and + // leaving the cache on causes problems when the browser back/forward buttons are pressed. + // Some browsers automatically disable it when the 'beforeunload' or 'unload' events + // have listeners, but not all do (Safari). + window.onpageshow = function(event) { + if (event.persisted) { window.location.reload(); } + }; + window.gristApp = App.create(null); // Set from the login tests to stub and un-stub functions during execution. window.loginTestSandbox = null;