Artifact
// Optimistic-update reconciliation. `serverSnapRef` holds the last raw // server snapshot; `pendingRef` holds actions the server has not acked yet. // The displayed `snap` is always serverSnap with every pending action // re-applied in order. const serverSnapRef = useRef(null); const pendingRef = useRef([]); const seqRef = useRef(0); const rebuild = useCallback(() => { let s = serverSnapRef.current; if (!s) return; for (const pend of pendingRef.current) s = optimisticSnap(s, pend.msg); setSnap(s); }, []);
cb4dcd9d-82d7-492d-81fc-71dc19f06be9
// Optimistic-update reconciliation. serverSnapRef holds the last raw
// server snapshot; pendingRef holds actions the server has not acked yet.
// The displayed snap is always serverSnap with every pending action
// re-applied in order.
const serverSnapRef = useRef(null);
const pendingRef = useRef([]);
const seqRef = useRef(0);
const rebuild = useCallback(() => { let s = serverSnapRef.current; if (!s) return; for (const pend of pendingRef.current) s = optimisticSnap(s, pend.msg); setSnap(s); }, []);