a tool for shared writing and social publishing
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

add timeout to catch loose yjs updates

+18 -9
+18 -9
components/Blocks/TextBlock/index.tsx
··· 487 487 488 488 useEffect(() => { 489 489 if (!rep.rep) return; 490 + let timeout = null as null | number; 490 491 const f = async () => { 491 - const update = Y.encodeStateAsUpdate(ydoc); 492 - await rep.rep?.mutate.assertFact({ 493 - entity: entityID, 494 - attribute: "block/text", 495 - data: { 496 - value: base64.fromByteArray(update), 497 - type: "text", 498 - }, 499 - }); 492 + const updateReplicache = async () => { 493 + const update = Y.encodeStateAsUpdate(ydoc); 494 + await rep.rep?.mutate.assertFact({ 495 + entity: entityID, 496 + attribute: "block/text", 497 + data: { 498 + value: base64.fromByteArray(update), 499 + type: "text", 500 + }, 501 + }); 502 + }; 503 + if (timeout) clearTimeout(timeout); 504 + updateReplicache(); 505 + timeout = window.setTimeout(async () => { 506 + updateReplicache(); 507 + }, 20); 500 508 }; 509 + 501 510 yText.observeDeep(f); 502 511 return () => { 503 512 yText.unobserveDeep(f);