Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Thoughtspace: Temporarily disable IndexeddbPersistence when loading d…
Browse files Browse the repository at this point in the history
…oclog 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.
raineorshine committed Apr 16, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent e834448 commit 77a24a3
Showing 2 changed files with 49 additions and 43 deletions.
2 changes: 1 addition & 1 deletion src/data-providers/yjs/index.ts
Original file line number Diff line number Diff line change
@@ -58,7 +58,7 @@ export const clientIdReady = (
return s
})

// disable during tests because of TransactionInactiveError in fake-indexeddb
// Disable IndexedDB during tests because of TransactionInactiveError in fake-indexeddb.
if (process.env.NODE_ENV !== 'test') {
// eslint-disable-next-line no-new
new IndexeddbPersistence(encodePermissionsDocumentName(tsid), permissionsClientDoc)
90 changes: 48 additions & 42 deletions src/data-providers/yjs/thoughtspace.ts
Original file line number Diff line number Diff line change
@@ -290,54 +290,60 @@ export const init = async (options: ThoughtspaceOptions) => {
// bind blocks to providers on load
doclog.on('subdocs', ({ added, removed, loaded }: { added: Set<Y.Doc>; removed: Set<Y.Doc>; loaded: Set<Y.Doc> }) => {
loaded.forEach((subdoc: Y.Doc) => {
const persistence = new IndexeddbPersistence(subdoc.guid, subdoc)
persistence.whenSynced
.then(() => {
// eslint-disable-next-line no-new
new HocuspocusProvider({
// disable awareness for performance
// doclog doc has awareness enabled to keep the websocket open
awareness: null,
websocketProvider: websocket,
name: subdoc.guid,
document: subdoc,
token: accessToken,
// Disable IndexedDB during tests because of TransactionInactiveError in fake-indexeddb.
if (process.env.NODE_ENV !== 'test') {
const persistence = new IndexeddbPersistence(subdoc.guid, subdoc)
persistence.whenSynced
.then(() => {
// eslint-disable-next-line no-new
new HocuspocusProvider({
// disable awareness for performance
// doclog doc has awareness enabled to keep the websocket open
awareness: null,
websocketProvider: websocket,
name: subdoc.guid,
document: subdoc,
token: accessToken,
})
})
})
.catch(e => {
const errorMessage = `Error loading doclog block: ${e.message}`
onError?.(errorMessage, e)
})
.catch(e => {
const errorMessage = `Error loading doclog block: ${e.message}`
onError?.(errorMessage, e)
})
}
})
})

const doclogPersistence = new IndexeddbPersistence(encodeDocLogDocumentName(tsid), doclog)
doclogPersistence.whenSynced
.then(() => {
const blocks = doclog.getArray<Y.Doc>('blocks')
// 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.
// Do not create a starting block if this is shared from another device.
// We need to wait for the existing block(s) to load.
if (blocks.length === 0 && !tsidShared) {
const blockNew = new Y.Doc({ guid: encodeDocLogBlockDocumentName(tsid, nanoid(13)) })

blocks.push([blockNew])
}
// Disable IndexedDB during tests because of TransactionInactiveError in fake-indexeddb.
if (process.env.NODE_ENV !== 'test') {
const doclogPersistence = new IndexeddbPersistence(encodeDocLogDocumentName(tsid), doclog)
doclogPersistence.whenSynced
.then(() => {
const blocks = doclog.getArray<Y.Doc>('blocks')
// 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.
// Do not create a starting block if this is shared from another device.
// We need to wait for the existing block(s) to load.
if (blocks.length === 0 && !tsidShared) {
const blockNew = new Y.Doc({ guid: encodeDocLogBlockDocumentName(tsid, nanoid(13)) })

blocks.push([blockNew])
}

// eslint-disable-next-line no-new
new HocuspocusProvider({
// doclog doc has awareness enabled to keep the websocket open
// disable awareness for all other websocket providers
websocketProvider: websocket,
name: encodeDocLogDocumentName(tsid),
document: doclog,
token: accessToken,
// eslint-disable-next-line no-new
new HocuspocusProvider({
// doclog doc has awareness enabled to keep the websocket open
// disable awareness for all other websocket providers
websocketProvider: websocket,
name: encodeDocLogDocumentName(tsid),
document: doclog,
token: accessToken,
})
})
})
.catch(e => {
const errorMessage = `Error loading doclog: ${e.message}`
onError?.(errorMessage, e)
})
.catch(e => {
const errorMessage = `Error loading doclog: ${e.message}`
onError?.(errorMessage, e)
})
}

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

0 comments on commit 77a24a3

Please sign in to comment.