Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix(awareness): handle awareness independently from provider
Keep the same awareness state - even when a new provider instance is created
 - for example on reconnect.

Signed-off-by: Max <[email protected]>
  • Loading branch information
max-nextcloud committed Jun 30, 2025
commit 0dd33bdf94bce04ded9b9d3bc844fe3f7bc55811
8 changes: 7 additions & 1 deletion src/components/Editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ import { useDelayedFlag } from './Editor/useDelayedFlag.ts'
import { useEditorMethods } from '../composables/useEditorMethods.ts'
import { useSyntaxHighlighting } from '../composables/useSyntaxHighlighting.ts'
import { provideConnection } from '../composables/useConnection.ts'
import { Awareness } from 'y-protocols/awareness.js'

export default {
name: 'Editor',
Expand Down Expand Up @@ -237,6 +238,7 @@ export default {
el.value.style.setProperty('--widget-full-width', `${maxWidth}px`)
})
const ydoc = new Doc()
const awareness = new Awareness(ydoc)
// Wrap the connection in an object so we can hand it to the Mention extension as a ref.
const wrappedConnection = provideConnection()
const hasConnectionIssue = ref(false)
Expand Down Expand Up @@ -273,6 +275,7 @@ export default {
const syncProvider = shallowRef(null)

return {
awareness,
baseVersionEtag,
connectSyncService,
editor,
Expand Down Expand Up @@ -422,7 +425,9 @@ export default {
const extensions = [
Autofocus.configure({ fileId: this.fileId }),
Collaboration.configure({ document: this.ydoc }),
CollaborationCursor.configure({ provider: this.syncProvider }),
CollaborationCursor.configure({
provider: { awareness: this.awareness },
}),
]
this.editor = this.isRichEditor
? createRichEditor({
Expand Down Expand Up @@ -461,6 +466,7 @@ export default {
fileId: this.fileId,
initialSession: this.initialSession,
disableBC: true,
awareness: this.awareness,
})
},

Expand Down
4 changes: 3 additions & 1 deletion src/services/SyncServiceProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ import { logger } from '../helpers/logger.js'
* @param {number} options.queue - queue for outgoing steps
* @param {object} options.initialSession - initialSession to start from
* @param {boolean} options.disableBc - disable broadcast channel synchronization (default: disabled in debug mode, enabled otherwise)
* @param {object} options.awareness - awareness instance for the provider
*/
export default function createSyncServiceProvider({
ydoc,
syncService,
fileId,
initialSession,
queue,
awareness,
disableBc,
}) {
if (!fileId) {
Expand All @@ -40,7 +42,7 @@ export default function createSyncServiceProvider({
'ws://localhost:1234',
'file:' + fileId,
ydoc,
{ WebSocketPolyfill, disableBc },
{ WebSocketPolyfill, awareness, disableBc },
)
websocketProvider.on('status', (event) => logger.debug('status', event))
return websocketProvider
Expand Down