a tool for shared writing and social publishing

cache homepage tokens to prevent unnessecary renders

+10 -6
+1 -5
app/home/LeafletList.tsx
··· 7 7 import { LeafletPreview } from "./LeafletPreview"; 8 8 import { useIdentityData } from "components/IdentityProvider"; 9 9 import type { Attribute } from "src/replicache/attributes"; 10 - import { getIdentityData } from "actions/getIdentityData"; 11 10 import { callRPC } from "app/api/rpc/client"; 12 11 import { StaticLeafletDataContext } from "components/PageSWRDataProvider"; 13 12 ··· 20 19 fallbackData: [], 21 20 }); 22 21 let { identity } = useIdentityData(); 23 - let { data: initialFacts, mutate } = useSWR( 22 + let { data: initialFacts } = useSWR( 24 23 "home-leaflet-data", 25 24 async () => { 26 25 if (identity) { ··· 34 33 }, 35 34 { fallbackData: props.initialFacts }, 36 35 ); 37 - useEffect(() => { 38 - mutate(); 39 - }, [localLeaflets.length, mutate]); 40 36 let leaflets: Array< 41 37 PermissionToken & { 42 38 leaflets_in_publications?: Array<{
+9 -1
app/home/storage.ts
··· 15 15 docs: [], 16 16 }; 17 17 const key = "homepageDocs-v1"; 18 + let tokenCache = new Map<string, PermissionToken>(); 18 19 export function getHomeDocs() { 19 20 let homepageDocs: HomeDocsStorage = JSON.parse( 20 21 window.localStorage.getItem(key) || JSON.stringify(defaultValue), 21 22 ); 22 - return homepageDocs.docs; 23 + return homepageDocs.docs.map((d) => { 24 + let cachedToken = tokenCache.get(d.token.id); 25 + if (!cachedToken) { 26 + cachedToken = d.token; 27 + tokenCache.set(d.token.id, d.token); 28 + } 29 + return { ...d, token: cachedToken }; 30 + }); 23 31 } 24 32 25 33 export function addDocToHome(doc: PermissionToken) {