From fefbcd7e13ae8b38d9f96b7225588d9d490ba638 Mon Sep 17 00:00:00 2001 From: Alexander Onnikov Date: Mon, 13 Oct 2025 13:17:44 +0700 Subject: [PATCH 1/2] qfix: remove indexeddb provider Signed-off-by: Alexander Onnikov --- plugins/text-editor-resources/package.json | 2 - .../components/CollaborativeTextEditor.svelte | 39 +++++++------------ .../src/provider/indexeddb.ts | 37 ------------------ .../src/provider/utils.ts | 6 --- 4 files changed, 14 insertions(+), 70 deletions(-) delete mode 100644 plugins/text-editor-resources/src/provider/indexeddb.ts diff --git a/plugins/text-editor-resources/package.json b/plugins/text-editor-resources/package.json index c63ff60d58f..07e755bf742 100644 --- a/plugins/text-editor-resources/package.json +++ b/plugins/text-editor-resources/package.json @@ -85,14 +85,12 @@ "prosemirror-codemark": "^0.4.2", "y-protocols": "^1.0.6", "y-prosemirror": "^1.3.7", - "y-websocket": "^2.1.0", "yjs": "^13.6.27", "fast-equals": "^5.2.2", "rfc6902": "^5.0.1", "diff": "^5.1.0", "slugify": "^1.6.6", "lib0": "^0.2.109", - "y-indexeddb": "^9.0.12", "lowlight": "^3.3.0", "mermaid": "^11.12.0", "@hcengineering/theme": "^0.7.0", diff --git a/plugins/text-editor-resources/src/components/CollaborativeTextEditor.svelte b/plugins/text-editor-resources/src/components/CollaborativeTextEditor.svelte index 0f0b1d841a6..e181c3085f3 100644 --- a/plugins/text-editor-resources/src/components/CollaborativeTextEditor.svelte +++ b/plugins/text-editor-resources/src/components/CollaborativeTextEditor.svelte @@ -68,7 +68,7 @@ import { deleteAttachment } from '../command/deleteAttachment' import { textEditorCommandHandler } from '../commands' import { Provider } from '../provider/types' - import { createLocalProvider, createRemoteProvider } from '../provider/utils' + import { createRemoteProvider } from '../provider/utils' import { addTableHandler } from '../utils' import { noSelectionRender, renderCursor } from './editor/collaboration' @@ -124,23 +124,17 @@ const ydoc = getContext(CollaborationIds.Doc) ?? new YDoc({ guid: generateId(), gc: false }) const contextProvider = getContext(CollaborationIds.Provider) - const localProvider = createLocalProvider(ydoc, collaborativeDoc) - const remoteProvider = contextProvider ?? createRemoteProvider(ydoc, collaborativeDoc, content) + const provider = contextProvider ?? createRemoteProvider(ydoc, collaborativeDoc, content) let contentError = false - let localSynced = false - let remoteSynced = false + let synced = false let editorReady = false - $: loading = !localSynced - $: editable = !readonly && !contentError && remoteSynced && editorReady && hasAccountRole(account, AccountRole.User) + $: loading = !synced + $: editable = !readonly && !contentError && synced && editorReady && hasAccountRole(account, AccountRole.User) - void localProvider.loaded.then(() => (localSynced = true)) - void remoteProvider.loaded.then(() => (remoteSynced = true)) - - void Promise.all([localProvider.loaded, remoteProvider.loaded]).then(() => { - dispatch('loaded') - }) + void provider.loaded.then(() => (synced = true)) + void provider.loaded.then(() => dispatch('loaded')) let editor: Editor let element: HTMLElement @@ -313,14 +307,12 @@ const throttle = new ThrottledCaller(100) const updateLastUpdateTime = (): void => { - remoteProvider.awareness?.setLocalStateField('lastUpdate', Date.now()) + provider.awareness?.setLocalStateField('lastUpdate', Date.now()) } interface SavedBoardRaw { ydoc: YDoc - localProvider: Provider remoteProvider: Provider - localSynced: boolean remoteSynced: boolean } const savedBoards: Record = {} @@ -337,10 +329,8 @@ objectId: id as Ref, objectAttr: 'content' } - const localProvider = createLocalProvider(ydoc, collabId) const remoteProvider = createRemoteProvider(ydoc, collabId, id as Ref) - savedBoards[id] = { ydoc, localProvider, remoteProvider, localSynced: false, remoteSynced: false } - void localProvider.loaded.then(() => (savedBoards[id].localSynced = true)) + savedBoards[id] = { ydoc, remoteProvider, remoteSynced: false } void remoteProvider.loaded.then(() => (savedBoards[id].remoteSynced = true)) board = savedBoards[id] } @@ -348,14 +338,14 @@ document: board.ydoc, props: board.ydoc.getMap('props'), commands: board.ydoc.getArray('commands'), - loading: !board.localSynced || !board.remoteSynced + loading: !board.remoteSynced } } onMount(async () => { // it is recommended to wait for the local provider to be loaded // https://discuss.yjs.dev/t/initial-offline-value-of-a-shared-document/465/4 - await localProvider.loaded + await provider.loaded const canAttachFiles = attachFile != null @@ -410,7 +400,7 @@ collaboration: { collaboration: { document: ydoc, field }, collaborationCursor: { - provider: remoteProvider, + provider, user, render: renderCursor, selectionRender: noSelectionRender @@ -420,7 +410,7 @@ boundary, popupContainer: editorPopupContainer, requestSideSpace, - whenSync: remoteProvider.loaded + whenSync: provider.loaded } } }, @@ -480,9 +470,8 @@ } catch (err: any) {} } if (contextProvider === undefined) { - void remoteProvider.destroy() + void provider.destroy() } - void localProvider.destroy() }) diff --git a/plugins/text-editor-resources/src/provider/indexeddb.ts b/plugins/text-editor-resources/src/provider/indexeddb.ts deleted file mode 100644 index d2aab95863b..00000000000 --- a/plugins/text-editor-resources/src/provider/indexeddb.ts +++ /dev/null @@ -1,37 +0,0 @@ -// -// Copyright © 2024 Hardcore Engineering Inc. -// -// Licensed under the Eclipse Public License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. You may -// obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// -// See the License for the specific language governing permissions and -// limitations under the License. -// - -import { type Doc as YDoc } from 'yjs' -import { IndexeddbPersistence } from 'y-indexeddb' -import { type Awareness } from 'y-protocols/awareness' - -import { type Provider } from './types' - -export class IndexeddbProvider extends IndexeddbPersistence implements Provider { - readonly loaded: Promise - readonly awareness: Awareness | null = null - - constructor (documentId: string, doc: YDoc) { - super(documentId, doc) - - this.loaded = new Promise((resolve) => { - this.on('synced', resolve) - }) - } - - async destroy (): Promise { - await super.destroy() - } -} diff --git a/plugins/text-editor-resources/src/provider/utils.ts b/plugins/text-editor-resources/src/provider/utils.ts index 172ab93f14e..373f5de3d9f 100644 --- a/plugins/text-editor-resources/src/provider/utils.ts +++ b/plugins/text-editor-resources/src/provider/utils.ts @@ -22,7 +22,6 @@ import { Doc as Ydoc } from 'yjs' import plugin from '../plugin' import { HocuspocusCollabProvider } from './hocuspocus' -import { IndexeddbProvider } from './indexeddb' import { type Provider } from './types' function getDocumentId (doc: CollaborativeDoc): string { @@ -30,11 +29,6 @@ function getDocumentId (doc: CollaborativeDoc): string { return encodeDocumentId(workspace, doc) } -export function createLocalProvider (ydoc: Ydoc, doc: CollaborativeDoc): Provider { - const documentId = getDocumentId(doc) - return new IndexeddbProvider(documentId, ydoc) -} - export function createRemoteProvider (ydoc: Ydoc, doc: CollaborativeDoc, content: Ref | null): Provider { const token = getMetadata(presentation.metadata.Token) ?? '' const collaboratorUrl = getMetadata(presentation.metadata.CollaboratorUrl) ?? '' From 0a3bf82860a1dab1b3c5f8e67a7a0fe37d0c2eaf Mon Sep 17 00:00:00 2001 From: Alexander Onnikov Date: Mon, 13 Oct 2025 17:07:13 +0700 Subject: [PATCH 2/2] fix: remove cloud provider Signed-off-by: Alexander Onnikov --- .../src/provider/cloud.ts | 46 ------------------- 1 file changed, 46 deletions(-) delete mode 100644 plugins/text-editor-resources/src/provider/cloud.ts diff --git a/plugins/text-editor-resources/src/provider/cloud.ts b/plugins/text-editor-resources/src/provider/cloud.ts deleted file mode 100644 index 82b4a858bf5..00000000000 --- a/plugins/text-editor-resources/src/provider/cloud.ts +++ /dev/null @@ -1,46 +0,0 @@ -// -// Copyright © 2024 Hardcore Engineering Inc. -// -// Licensed under the Eclipse Public License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. You may -// obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// -// See the License for the specific language governing permissions and -// limitations under the License. -// -import { type Blob, type Ref } from '@hcengineering/core' -import { type Doc as YDoc } from 'yjs' -import { WebsocketProvider } from 'y-websocket' - -import { type Provider } from './types' - -export interface DatalakeCollabProviderParameters { - url: string - name: string - token: string - - document: YDoc - content: Ref | null -} - -export class CloudCollabProvider extends WebsocketProvider implements Provider { - readonly loaded: Promise - - constructor ({ document, url, name, content }: DatalakeCollabProviderParameters) { - const params = content != null ? { content } : undefined - - super(url, encodeURIComponent(name), document, { params }) - - this.loaded = new Promise((resolve) => { - this.on('sync', resolve) - }) - } - - destroy (): void { - this.disconnect() - } -}