@@ -1,9 +1,31 @@
1+import { Just, Nothing } from 'folktale/maybe';
2+import Result from 'folktale/result';
13import React, { createContext, forwardRef, useContext } from 'react';
24
35import useDeepEqualReference from 'lib/useDeepEqualReference';
46import usePointStore from './lib/usePointStore';
57
6−export const PointCacheContext = createContext(null);
8+/**
9+ * Avoid race condition by setting an initial dummy state. Previously, on
10+ * occasion the application would render before the points queries finished
11+ * loading data asynchronously from the roller and Infura. This would cause
12+ * a crash in Points.tsx when attempting to destructure the data.
13+*/
14+const initialContext = {
15+ details: Nothing(),
16+ rekeyDates: Nothing(),
17+ controlledPoints: Just(Result.Error('not yet loaded')),
18+ ecliptic: Nothing(),
19+ residents: Nothing(),
20+ syncDetails: () => [],
21+ syncRekeyDate: () => [],
22+ syncControlledPoints: () => [],
23+ syncDates: () => [],
24+ syncResidents: () => [],
25+ syncExtras: () => [],
26+}
27+
28+export const PointCacheContext = createContext(initialContext);
729
830export function PointCacheProvider({ children }) {
931 const cache = usePointStore();