From e14880b6f01d82ed80e1946a789e732f5588c016 Mon Sep 17 00:00:00 2001 From: swxk19 Date: Mon, 4 Jul 2022 20:28:51 +0800 Subject: [PATCH] Fix for uninitialised 'Snapshot' field if using old IndexedDB (Closes Issue #105) --- src/components/Header/Header.tsx | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/components/Header/Header.tsx b/src/components/Header/Header.tsx index 7aaf06bd..c3d54e3e 100644 --- a/src/components/Header/Header.tsx +++ b/src/components/Header/Header.tsx @@ -30,8 +30,16 @@ export const Header = ({ title, setTitle, lastEditedOn, db }: Props) => { const textColor = theme === 'dark' ? 'white' : '#181414' const updateSnapshotsFromDb = async () => { - let allSnapshots = await db.snapshots.toArray() - setSnapshotArray(allSnapshots) + try { + let allSnapshots = await db.snapshots.toArray() + setSnapshotArray(allSnapshots) + } catch (e) { + //if 'snapshots' field is not initialised in db, it will be undefined, and 'toArray' causes a TypeError' + if (db.snapshots === undefined) { + await db.delete() + window.location.reload() + } + } } const saveSnapshot = () => {