From d842d11a0cf6282e746205ebdce963d316bbca7a Mon Sep 17 00:00:00 2001 From: Lucas Date: Tue, 15 Jul 2025 17:12:58 +1000 Subject: [PATCH 1/2] More aggressively catch corrupted local storage --- client/src/utils/storage.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/client/src/utils/storage.ts b/client/src/utils/storage.ts index d4ed4f566..6b7215ab6 100644 --- a/client/src/utils/storage.ts +++ b/client/src/utils/storage.ts @@ -1,3 +1,4 @@ +import { useRef } from 'react'; import defaults from '../constants/defaults'; import migrateThemes from './migrations/colourTheme'; import migratePrimaryTimetables from './migrations/primaryTimetables'; @@ -5,6 +6,11 @@ import { createDefaultTimetable } from './timetableHelpers'; const STORAGE_KEY = 'data'; +// Something is not playing nice and causing local storage to corrupt across signing in/out +// We are in the process of migrating data to the backend, so this fix should catch people +// for now and prevent them from seeing a blank page. +const hasRunArrayCheck = useRef(false); + const storage = { get: (key: string): any => { const data: Record = storage.load(); @@ -64,7 +70,7 @@ const storage = { } // Un-break an existing issue with migrated data - if (migrated.version == null || migrated.version < 2) { + if (!hasRunArrayCheck.current) { Object.entries(migrated.timetables).forEach(([term, timetables]) => { if ( !Array.isArray(timetables) || @@ -73,6 +79,8 @@ const storage = { migrated.timetables[term] = createDefaultTimetable(''); } }); + + hasRunArrayCheck.current = true; } // only do this if version does not exist From a53e052becf1d8ff1b528b563d229d83e9844c60 Mon Sep 17 00:00:00 2001 From: Lucas Date: Fri, 29 Aug 2025 15:01:28 +1000 Subject: [PATCH 2/2] Address review comments --- client/src/utils/storage.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/client/src/utils/storage.ts b/client/src/utils/storage.ts index 6b7215ab6..97771af98 100644 --- a/client/src/utils/storage.ts +++ b/client/src/utils/storage.ts @@ -1,4 +1,3 @@ -import { useRef } from 'react'; import defaults from '../constants/defaults'; import migrateThemes from './migrations/colourTheme'; import migratePrimaryTimetables from './migrations/primaryTimetables'; @@ -9,7 +8,7 @@ const STORAGE_KEY = 'data'; // Something is not playing nice and causing local storage to corrupt across signing in/out // We are in the process of migrating data to the backend, so this fix should catch people // for now and prevent them from seeing a blank page. -const hasRunArrayCheck = useRef(false); +let hasRunArrayCheck = false; const storage = { get: (key: string): any => { @@ -70,7 +69,7 @@ const storage = { } // Un-break an existing issue with migrated data - if (!hasRunArrayCheck.current) { + if (!hasRunArrayCheck) { Object.entries(migrated.timetables).forEach(([term, timetables]) => { if ( !Array.isArray(timetables) || @@ -80,7 +79,8 @@ const storage = { } }); - hasRunArrayCheck.current = true; + storage.save(migrated); + hasRunArrayCheck = true; } // only do this if version does not exist