Skip to content

Sync fails if initial state is present in the yjs documentΒ #4480

@max-nextcloud

Description

@max-nextcloud

Describe the bug
If there is some initial state in the yjs document our sync mechanism fails and changes from the user in question are not transferred.

If a yjs session starts with initial data in the document the client will not send updates for that initial data. Normally this is not a problem because the initial Sync message 1 by the other party will cause the client to send it's 'backlog'.

Our sync mechanism blocks yjs queries (Sync Message 1).

It's not clear if this can happen in a real life scenario. Tiptap may take longer to load than yjs takes to initialize and send the initial push message.

To Reproduce

Add this test to cypress/e2e/api/SyncServiceProvider.spec.js:

it('syncs even when initial state was present', function() {
		const sourceMap = this.source.getMap()
		const targetMap = this.target.getMap()
		sourceMap.set('unrelated', 'value')
		cy.intercept({ method: 'POST', url: '**/apps/text/session/push' })
			.as('push')
		cy.intercept({ method: 'POST', url: '**/apps/text/session/sync' })
			.as('sync')
		cy.wait('@push')
		cy.then(() => {
			sourceMap.set('keyA', 'valueA')
			expect(targetMap.get('keyB')).to.be.eq(undefined)
		})
		cy.wait('@sync')
		cy.wait('@sync')
		// eslint-disable-next-line cypress/no-unnecessary-waiting
		cy.wait(1000)
		cy.then(() => {
			expect(targetMap.get('keyA')).to.be.eq('valueA')
		})
	})

See it fail.

Metadata

Metadata

Assignees

Type

No type

Projects

Status

β˜‘οΈ Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions