From ad6c737676909aa36adf434f8e2dcaafce0585bf Mon Sep 17 00:00:00 2001 From: dfahlander Date: Thu, 20 Jun 2024 00:42:03 +0200 Subject: [PATCH] Manipulate Y.js doc within a dexie transaction to avoid race condition --- test/tests-yjs.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/test/tests-yjs.js b/test/tests-yjs.js index 3ba852ba6..3d13ca3d2 100644 --- a/test/tests-yjs.js +++ b/test/tests-yjs.js @@ -59,8 +59,12 @@ promisedTest('Test DexieYProvider', async () => { /* @type {Y.Doc} */ let doc = row.content; let provider = new DexieYProvider(doc); - doc.getArray('arr').insert(0, ['a', 'b', 'c']); - await provider.whenLoaded; + // Await the transaction of doc manipulation to not + // bring down the database before it has been stored. + await db.transaction('rw', db.docs, () => { + doc.getArray('arr').insert(0, ['a', 'b', 'c']); + }); + //await provider.whenLoaded; doc.destroy(); db.close({disableAutoOpen: false}); await db.open();