From d78a2c615ca94d11ee851ecfb6dc72bf43cda69c Mon Sep 17 00:00:00 2001 From: Jared Pereira Date: Sun, 26 May 2024 20:54:59 +0100 Subject: [PATCH] use fallback if replicache hasn't initialized yet --- replicache/index.tsx | 6 ++++-- replicache/pull.ts | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/replicache/index.tsx b/replicache/index.tsx index c2c8b5ee..5b712e18 100644 --- a/replicache/index.tsx +++ b/replicache/index.tsx @@ -126,7 +126,9 @@ export function useEntity( ); let data = useSubscribe( rep, - (tx) => { + async (tx) => { + let initialized = await tx.get("initialized"); + if (!initialized) return null; return tx .scan>({ indexName: "eav", prefix: `${entity}-${attribute}` }) .toArray(); @@ -136,7 +138,7 @@ export function useEntity( dependencies: [entity, attribute], }, ); - let d = data || (attribute === "card/block" ? fallbackData : []); + let d = data || fallbackData; return Attributes[attribute].cardinality === "many" ? (d as CardinalityResult) : (d[0] as CardinalityResult); diff --git a/replicache/pull.ts b/replicache/pull.ts index fd2e498a..f4c29661 100644 --- a/replicache/pull.ts +++ b/replicache/pull.ts @@ -33,6 +33,7 @@ export async function Pull( lastMutationIDChanges: clientGroup, patch: [ { op: "clear" }, + { op: "put", key: "initialized", value: true }, ...facts.map((f) => { return { op: "put", -- 2.51.2