From 6dfeb874a7523405b67820003709ce404d54eaf4 Mon Sep 17 00:00:00 2001 From: Mitchell McCaffrey Date: Thu, 24 Jun 2021 13:06:00 +1000 Subject: [PATCH] Handle db versionchange --- src/contexts/DatabaseContext.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/contexts/DatabaseContext.js b/src/contexts/DatabaseContext.js index 0ae94b1..fd5cfb3 100644 --- a/src/contexts/DatabaseContext.js +++ b/src/contexts/DatabaseContext.js @@ -39,6 +39,10 @@ export function DatabaseProvider({ children }) { db.on("ready", () => { setDatabaseStatus("loaded"); }); + db.on("versionchange", () => { + // When another tab loads a new version of the database refresh the page + window.location.reload(); + }); await db.open(); window.indexedDB.deleteDatabase("__test"); };