fix: prevent crash when takenBy is not an array (#92)

- Add Array.isArray() checks before calling .map() on dose.takenBy
- Fixes TypeError: dose.takenBy.map is not a function
- Affects AppContext missedPastDoseIds calculation
- Affects SchedulePage dose ID generation (3 locations)

This hotfix prevents the app from crashing when dose.takenBy
is null, undefined, or any non-array value.
This commit is contained in:
Daniel Volz
2026-02-03 05:57:11 +01:00
committed by GitHub
parent 9984392b76
commit 31a89356fe
2 changed files with 14 additions and 10 deletions
+2 -1
View File
@@ -480,7 +480,8 @@ export function AppProvider({ children }: { children: React.ReactNode }) {
return [];
}
return (dose.takenBy || []).length > 0 ? dose.takenBy.map((p: string) => `${dose.id}-${p}`) : [dose.id];
const takenByArray = Array.isArray(dose.takenBy) ? dose.takenBy : [];
return takenByArray.length > 0 ? takenByArray.map((p: string) => `${dose.id}-${p}`) : [dose.id];
});
})
);