There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.
TypeScript appcrdteditorelectronknowledge-basemarkdownmironotesnotionnotion-alternativerustrust-langrust-languagetabletableviewwhiteboardwikiworkspace
fix(y-provider): syncing status (#3903)
Alex Yangc7a4805e5cf1
diff --git a/.commitlintrc.json b/.commitlintrc.jsonindex bd052fb43a..1c33fe25bc 100644--- a/.commitlintrc.json+++ b/.commitlintrc.json@@ -21,6 +21,7 @@"native","templates","y-indexeddb",+ "y-provider","debug","storage","infra",diff --git a/packages/y-provider/src/lazy-provider.ts b/packages/y-provider/src/lazy-provider.tsindex 852cb6ff3e..670d2e0cf2 100644--- a/packages/y-provider/src/lazy-provider.ts+++ b/packages/y-provider/src/lazy-provider.ts@@ -52,7 +52,7 @@ export const createLazyProvider = (const changeStatus = (newStatus: Status) => {// simulate a stack, each syncing and synced should be pairedif (newStatus.type === 'idle') {- if (syncingStack !== 0) {+ if (connected && syncingStack !== 0) {console.error('syncingStatus !== 0, this should not happen');}syncingStack = 0;@@ -79,6 +79,9 @@ export const createLazyProvider = (async function syncDoc(doc: Doc) {const guid = doc.guid;+ if (!connected) {+ return;+ }changeStatus({type: 'syncing',@@ -87,6 +90,18 @@ export const createLazyProvider = (.queryDocState(guid, {stateVector: encodeStateVector(doc),})+ .then(remoteUpdate => {+ if (!connected) {+ changeStatus({+ type: 'idle',+ });+ return;+ }+ changeStatus({+ type: 'synced',+ });+ return remoteUpdate;+ }).catch(error => {changeStatus({type: 'error',@@ -94,9 +109,6 @@ export const createLazyProvider = (});throw error;});- changeStatus({- type: 'synced',- });pendingMap.set(guid, []);@@ -171,6 +183,9 @@ export const createLazyProvider = (*/function setupDatasourceListeners() {datasourceUnsub = datasource.onDocUpdate?.((guid, update) => {+ if (!connected) {+ return;+ }changeStatus({type: 'syncing',});@@ -244,16 +259,25 @@ export const createLazyProvider = (});// root doc should be already loaded,// but we want to populate the cache for later update events- connectDoc(rootDoc).catch(error => {- changeStatus({- type: 'error',- error,+ connectDoc(rootDoc)+ .then(() => {+ if (!connected) {+ changeStatus({+ type: 'idle',+ });+ return;+ }+ changeStatus({+ type: 'synced',+ });+ })+ .catch(error => {+ changeStatus({+ type: 'error',+ error,+ });+ console.error(error);});- console.error(error);- });- changeStatus({- type: 'synced',- });setupDatasourceListeners();}