mirror of
https://github.com/toeverything/AFFiNE.git
synced 2024-12-24 19:22:49 +03:00
fix: indexeddb provider (#1827)
This commit is contained in:
parent
ee8f6a760e
commit
164d357487
@ -196,7 +196,6 @@ __metadata:
|
||||
react: ^18.2.0
|
||||
react-dom: ^18.2.0
|
||||
ws: ^8.13.0
|
||||
y-indexeddb: ^9.0.10
|
||||
y-protocols: ^1.0.5
|
||||
yjs: ^13.5.52
|
||||
zod: ^3.21.4
|
||||
@ -12007,7 +12006,7 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"lib0@npm:^0.2.35, lib0@npm:^0.2.42, lib0@npm:^0.2.68, lib0@npm:^0.2.72, lib0@npm:^0.2.73":
|
||||
"lib0@npm:^0.2.42, lib0@npm:^0.2.68, lib0@npm:^0.2.72, lib0@npm:^0.2.73":
|
||||
version: 0.2.73
|
||||
resolution: "lib0@npm:0.2.73"
|
||||
dependencies:
|
||||
@ -17045,17 +17044,6 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"y-indexeddb@npm:^9.0.10":
|
||||
version: 9.0.10
|
||||
resolution: "y-indexeddb@npm:9.0.10"
|
||||
dependencies:
|
||||
lib0: ^0.2.35
|
||||
peerDependencies:
|
||||
yjs: ^13.0.0
|
||||
checksum: 6a57825b599cdf77da7c9857b1acc0f782492fc41531618bd7392bdfbcf11c783ff1a30b82ae080b050a5ebafd54754a978de7a6ac42144ec59eb1fbdebd090b
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"y-protocols@npm:^1.0.5":
|
||||
version: 1.0.5
|
||||
resolution: "y-protocols@npm:1.0.5"
|
||||
|
@ -39,7 +39,6 @@
|
||||
"react-dom": "^18.2.0",
|
||||
"react-is": "^18.2.0",
|
||||
"swr": "^2.1.2",
|
||||
"y-indexeddb": "^9.0.10",
|
||||
"y-protocols": "^1.0.5",
|
||||
"yjs": "^13.5.52",
|
||||
"zod": "^3.21.4"
|
||||
|
@ -27,7 +27,6 @@
|
||||
"lib0": "^0.2.73",
|
||||
"react": "^18.2.0",
|
||||
"react-dom": "^18.2.0",
|
||||
"y-indexeddb": "^9.0.10",
|
||||
"y-protocols": "^1.0.5",
|
||||
"yjs": "^13.5.52",
|
||||
"zod": "^3.21.4"
|
||||
|
@ -8,7 +8,10 @@ import type {
|
||||
} from '@affine/workspace/type';
|
||||
import type { Workspace as BlockSuiteWorkspace } from '@blocksuite/store';
|
||||
import { assertExists } from '@blocksuite/store';
|
||||
import { IndexeddbPersistence } from 'y-indexeddb';
|
||||
import {
|
||||
createIndexedDBProvider as create,
|
||||
EarlyDisconnectError,
|
||||
} from '@toeverything/y-indexeddb';
|
||||
|
||||
import { createBroadCastChannelProvider } from './broad-cast-channel';
|
||||
import { localProviderLogger } from './logger';
|
||||
@ -57,7 +60,10 @@ const createAffineWebSocketProvider = (
|
||||
const createIndexedDBProvider = (
|
||||
blockSuiteWorkspace: BlockSuiteWorkspace
|
||||
): LocalIndexedDBProvider => {
|
||||
let indexeddbProvider: IndexeddbPersistence | null = null;
|
||||
const indexeddbProvider = create(
|
||||
blockSuiteWorkspace.id,
|
||||
blockSuiteWorkspace.doc
|
||||
);
|
||||
const callbacks = new Set<() => void>();
|
||||
return {
|
||||
flavour: 'local-indexeddb',
|
||||
@ -65,23 +71,25 @@ const createIndexedDBProvider = (
|
||||
// fixme: remove background long polling
|
||||
background: true,
|
||||
cleanup: () => {
|
||||
assertExists(indexeddbProvider);
|
||||
indexeddbProvider.clearData();
|
||||
callbacks.clear();
|
||||
indexeddbProvider = null;
|
||||
// todo: cleanup data
|
||||
},
|
||||
connect: () => {
|
||||
localProviderLogger.info(
|
||||
'connect indexeddb provider',
|
||||
blockSuiteWorkspace.id
|
||||
);
|
||||
indexeddbProvider = new IndexeddbPersistence(
|
||||
blockSuiteWorkspace.id,
|
||||
blockSuiteWorkspace.doc
|
||||
);
|
||||
indexeddbProvider.whenSynced.then(() => {
|
||||
callbacks.forEach(cb => cb());
|
||||
});
|
||||
indexeddbProvider.connect();
|
||||
indexeddbProvider.whenSynced
|
||||
.then(() => {
|
||||
callbacks.forEach(cb => cb());
|
||||
})
|
||||
.catch(error => {
|
||||
if (error instanceof EarlyDisconnectError) {
|
||||
return;
|
||||
} else {
|
||||
throw error;
|
||||
}
|
||||
});
|
||||
},
|
||||
disconnect: () => {
|
||||
assertExists(indexeddbProvider);
|
||||
@ -89,8 +97,7 @@ const createIndexedDBProvider = (
|
||||
'disconnect indexeddb provider',
|
||||
blockSuiteWorkspace.id
|
||||
);
|
||||
indexeddbProvider.destroy();
|
||||
indexeddbProvider = null;
|
||||
indexeddbProvider.disconnect();
|
||||
},
|
||||
};
|
||||
};
|
||||
|
15
yarn.lock
15
yarn.lock
@ -207,7 +207,6 @@ __metadata:
|
||||
swr: ^2.1.2
|
||||
typescript: ^5.0.3
|
||||
webpack: ^5.77.0
|
||||
y-indexeddb: ^9.0.10
|
||||
y-protocols: ^1.0.5
|
||||
yjs: ^13.5.52
|
||||
zod: ^3.21.4
|
||||
@ -234,7 +233,6 @@ __metadata:
|
||||
react: ^18.2.0
|
||||
react-dom: ^18.2.0
|
||||
ws: ^8.13.0
|
||||
y-indexeddb: ^9.0.10
|
||||
y-protocols: ^1.0.5
|
||||
yjs: ^13.5.52
|
||||
zod: ^3.21.4
|
||||
@ -13611,7 +13609,7 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"lib0@npm:^0.2.35, lib0@npm:^0.2.42, lib0@npm:^0.2.68, lib0@npm:^0.2.72, lib0@npm:^0.2.73":
|
||||
"lib0@npm:^0.2.42, lib0@npm:^0.2.68, lib0@npm:^0.2.72, lib0@npm:^0.2.73":
|
||||
version: 0.2.73
|
||||
resolution: "lib0@npm:0.2.73"
|
||||
dependencies:
|
||||
@ -19280,17 +19278,6 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"y-indexeddb@npm:^9.0.10":
|
||||
version: 9.0.10
|
||||
resolution: "y-indexeddb@npm:9.0.10"
|
||||
dependencies:
|
||||
lib0: ^0.2.35
|
||||
peerDependencies:
|
||||
yjs: ^13.0.0
|
||||
checksum: 6a57825b599cdf77da7c9857b1acc0f782492fc41531618bd7392bdfbcf11c783ff1a30b82ae080b050a5ebafd54754a978de7a6ac42144ec59eb1fbdebd090b
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"y-protocols@npm:^1.0.5":
|
||||
version: 1.0.5
|
||||
resolution: "y-protocols@npm:1.0.5"
|
||||
|
Loading…
Reference in New Issue
Block a user