From 71c77d30a00f6a3b1db5232f88476b8d7dc1b59b Mon Sep 17 00:00:00 2001 From: "M. Palanikannan" <73993394+Palanikannan1437@users.noreply.github.com> Date: Fri, 14 Jun 2024 17:01:36 +0530 Subject: [PATCH] fix: extra indexed db update on mount (reload) causing repeated popups of unsaved changes (#4808) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * docs: update self-host guide link in README (#4704) found via: - https://github.com/makeplane/docs/issues/48 - https://github.com/makeplane/plane/pull/3109 * fix: extra indexed db update on mount causing repeated popups on unload * revert: old stuff --------- Co-authored-by: jon ⚝ --- README.md | 2 +- .../document-editor/src/hooks/use-document-editor.ts | 3 +++ .../src/providers/collaboration-provider.ts | 10 ++++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e465f3cb1..38ead5f99 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ Meet [Plane](https://dub.sh/plane-website-readme), an open-source project manage The easiest way to get started with Plane is by creating a [Plane Cloud](https://app.plane.so) account. -If you would like to self-host Plane, please see our [deployment guide](https://docs.plane.so/self-hosting/overview). +If you would like to self-host Plane, please see our [deployment guide](https://docs.plane.so/docker-compose). | Installation methods | Docs link | | -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ | diff --git a/packages/editor/document-editor/src/hooks/use-document-editor.ts b/packages/editor/document-editor/src/hooks/use-document-editor.ts index c2070a9f3..47bd397f9 100644 --- a/packages/editor/document-editor/src/hooks/use-document-editor.ts +++ b/packages/editor/document-editor/src/hooks/use-document-editor.ts @@ -59,6 +59,9 @@ export const useDocumentEditor = ({ // indexedDB provider useLayoutEffect(() => { const localProvider = new IndexeddbPersistence(id, provider.document); + localProvider.on("synced", () => { + provider.setHasIndexedDBSynced(true); + }); return () => { localProvider?.destroy(); }; diff --git a/packages/editor/document-editor/src/providers/collaboration-provider.ts b/packages/editor/document-editor/src/providers/collaboration-provider.ts index b61ceebd5..9a9e6f78d 100644 --- a/packages/editor/document-editor/src/providers/collaboration-provider.ts +++ b/packages/editor/document-editor/src/providers/collaboration-provider.ts @@ -13,6 +13,10 @@ export interface CompleteCollaboratorProviderConfiguration { * onChange callback */ onChange: (updates: Uint8Array) => void; + /** + * Whether connection to the database has been established and all available content has been loaded or not. + */ + hasIndexedDBSynced: boolean; } export type CollaborationProviderConfiguration = Required> & @@ -24,6 +28,7 @@ export class CollaborationProvider { // @ts-expect-error cannot be undefined document: undefined, onChange: () => {}, + hasIndexedDBSynced: false, }; constructor(configuration: CollaborationProviderConfiguration) { @@ -45,7 +50,12 @@ export class CollaborationProvider { return this.configuration.document; } + setHasIndexedDBSynced(hasIndexedDBSynced: boolean) { + this.configuration.hasIndexedDBSynced = hasIndexedDBSynced; + } + documentUpdateHandler(update: Uint8Array, origin: any) { + if (!this.configuration.hasIndexedDBSynced) return; // return if the update is from the provider itself if (origin === this) return;