@@ -1,9 +1,31 @@
1+import { Just, Nothing } from 'folktale/maybe';
2+import Result from 'folktale/result';
1import React, { createContext, forwardRef, useContext } from 'react';
3import React, { createContext, forwardRef, useContext } from 'react';
3import useDeepEqualReference from 'lib/useDeepEqualReference';
5import useDeepEqualReference from 'lib/useDeepEqualReference';
4import usePointStore from './lib/usePointStore';
6import usePointStore from './lib/usePointStore';
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.
14+const initialContext = {
16+ rekeyDates: Nothing(),
17+ controlledPoints: Just(Result.Error('not yet loaded')),
19+ residents: Nothing(),
20+ syncDetails: () => [],
21+ syncRekeyDate: () => [],
22+ syncControlledPoints: () => [],
24+ syncResidents: () => [],
25+ syncExtras: () => [],
6−export const PointCacheContext = createContext(null);
28+export const PointCacheContext = createContext(initialContext);
8export function PointCacheProvider({ children }) {
30export function PointCacheProvider({ children }) {
9 const cache = usePointStore();
31 const cache = usePointStore();