Skip to content

Commit 48d56e3

Browse files
committed
Thoughtspace: Temporarily disable IndexeddbPersistence when loading doclog in tests.
There is currently an issue where some y-indexeddb usage causes "TransactionInactiveError: A request was placed against a transaction which is currently not active, or which is finished." It is unclear what is causing this, although we are using an old version of fake-indexeddb, and the issue does not occur in normal app usage.
1 parent 689b5e4 commit 48d56e3

File tree

2 files changed

+49
-43
lines changed

2 files changed

+49
-43
lines changed

src/data-providers/yjs/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export const clientIdReady = (
5858
return s
5959
})
6060

61-
// disable during tests because of TransactionInactiveError in fake-indexeddb
61+
// Disable IndexedDB during tests because of TransactionInactiveError in fake-indexeddb.
6262
if (process.env.NODE_ENV !== 'test') {
6363
// eslint-disable-next-line no-new
6464
new IndexeddbPersistence(encodePermissionsDocumentName(tsid), permissionsClientDoc)

src/data-providers/yjs/thoughtspace.ts

Lines changed: 48 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -290,54 +290,60 @@ export const init = async (options: ThoughtspaceOptions) => {
290290
// bind blocks to providers on load
291291
doclog.on('subdocs', ({ added, removed, loaded }: { added: Set<Y.Doc>; removed: Set<Y.Doc>; loaded: Set<Y.Doc> }) => {
292292
loaded.forEach((subdoc: Y.Doc) => {
293-
const persistence = new IndexeddbPersistence(subdoc.guid, subdoc)
294-
persistence.whenSynced
295-
.then(() => {
296-
// eslint-disable-next-line no-new
297-
new HocuspocusProvider({
298-
// disable awareness for performance
299-
// doclog doc has awareness enabled to keep the websocket open
300-
awareness: null,
301-
websocketProvider: websocket,
302-
name: subdoc.guid,
303-
document: subdoc,
304-
token: accessToken,
293+
// Disable IndexedDB during tests because of TransactionInactiveError in fake-indexeddb.
294+
if (process.env.NODE_ENV !== 'test') {
295+
const persistence = new IndexeddbPersistence(subdoc.guid, subdoc)
296+
persistence.whenSynced
297+
.then(() => {
298+
// eslint-disable-next-line no-new
299+
new HocuspocusProvider({
300+
// disable awareness for performance
301+
// doclog doc has awareness enabled to keep the websocket open
302+
awareness: null,
303+
websocketProvider: websocket,
304+
name: subdoc.guid,
305+
document: subdoc,
306+
token: accessToken,
307+
})
305308
})
306-
})
307-
.catch(e => {
308-
const errorMessage = `Error loading doclog block: ${e.message}`
309-
onError?.(errorMessage, e)
310-
})
309+
.catch(e => {
310+
const errorMessage = `Error loading doclog block: ${e.message}`
311+
onError?.(errorMessage, e)
312+
})
313+
}
311314
})
312315
})
313316

314-
const doclogPersistence = new IndexeddbPersistence(encodeDocLogDocumentName(tsid), doclog)
315-
doclogPersistence.whenSynced
316-
.then(() => {
317-
const blocks = doclog.getArray<Y.Doc>('blocks')
318-
// The doclog's initial block must be created outside the replicationController, after IDB syncs. This is necessary to avoid creating a new block when one already exists.
319-
// Do not create a starting block if this is shared from another device.
320-
// We need to wait for the existing block(s) to load.
321-
if (blocks.length === 0 && !tsidShared) {
322-
const blockNew = new Y.Doc({ guid: encodeDocLogBlockDocumentName(tsid, nanoid(13)) })
323-
324-
blocks.push([blockNew])
325-
}
317+
// Disable IndexedDB during tests because of TransactionInactiveError in fake-indexeddb.
318+
if (process.env.NODE_ENV !== 'test') {
319+
const doclogPersistence = new IndexeddbPersistence(encodeDocLogDocumentName(tsid), doclog)
320+
doclogPersistence.whenSynced
321+
.then(() => {
322+
const blocks = doclog.getArray<Y.Doc>('blocks')
323+
// The doclog's initial block must be created outside the replicationController, after IDB syncs. This is necessary to avoid creating a new block when one already exists.
324+
// Do not create a starting block if this is shared from another device.
325+
// We need to wait for the existing block(s) to load.
326+
if (blocks.length === 0 && !tsidShared) {
327+
const blockNew = new Y.Doc({ guid: encodeDocLogBlockDocumentName(tsid, nanoid(13)) })
328+
329+
blocks.push([blockNew])
330+
}
326331

327-
// eslint-disable-next-line no-new
328-
new HocuspocusProvider({
329-
// doclog doc has awareness enabled to keep the websocket open
330-
// disable awareness for all other websocket providers
331-
websocketProvider: websocket,
332-
name: encodeDocLogDocumentName(tsid),
333-
document: doclog,
334-
token: accessToken,
332+
// eslint-disable-next-line no-new
333+
new HocuspocusProvider({
334+
// doclog doc has awareness enabled to keep the websocket open
335+
// disable awareness for all other websocket providers
336+
websocketProvider: websocket,
337+
name: encodeDocLogDocumentName(tsid),
338+
document: doclog,
339+
token: accessToken,
340+
})
335341
})
336-
})
337-
.catch(e => {
338-
const errorMessage = `Error loading doclog: ${e.message}`
339-
onError?.(errorMessage, e)
340-
})
342+
.catch(e => {
343+
const errorMessage = `Error loading doclog: ${e.message}`
344+
onError?.(errorMessage, e)
345+
})
346+
}
341347

342348
const replication = replicationController({
343349
// begin paused and only start after initial pull has completed

0 commit comments

Comments
 (0)