Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
fa5443f
wip: try y-indexeddb
max-nextcloud Jun 13, 2025
dad1fc4
chore(split) useIndexedDbProvider from Editor.vue
max-nextcloud Sep 4, 2025
740e864
fix(cron): do not reset document
max-nextcloud Sep 4, 2025
761da7c
enh(yjs): store baseVersionEtag alongside doc
max-nextcloud Sep 4, 2025
e822638
fix(offline): persist dirty state in indexed db
max-nextcloud Oct 14, 2025
fab8003
chore(test): explore empty changesets
max-nextcloud Oct 22, 2025
7b44473
chore(rename): use privateMethods for emitError and emitDocumentState…
max-nextcloud Oct 26, 2025
f824247
chore(cleanup): _getContent alias for serialize
max-nextcloud Oct 26, 2025
b7f3c01
chore(refactor): handle open data in websocket polyfill
max-nextcloud Oct 26, 2025
eb957bf
fix(sync): only accept sync protocol and return sync step 2
max-nextcloud Oct 26, 2025
01c3c9e
enh(sync): recover automatically from outdated / renamed doc
max-nextcloud Oct 27, 2025
f771fba
fix(sync): ensure dirty is updated when saving in onDestroy
max-nextcloud Nov 4, 2025
5c6937f
chore(logging): some optional debug logging
max-nextcloud Nov 5, 2025
6142c04
fix(sync): actually disable browser broadcast
max-nextcloud Nov 5, 2025
caca244
chore(test): conflict and sync with autoreload
max-nextcloud Nov 5, 2025
1924efb
chore(type) a few more files
max-nextcloud Nov 6, 2025
d9545ef
chore(test): add initial test for indexed db
max-nextcloud Nov 7, 2025
0fb8609
fix(sync): Cleanup sessions even with unsaved changes
max-nextcloud Nov 7, 2025
e7a6ec4
chore(type): EditorFactory and setInitialYjsState
max-nextcloud Nov 10, 2025
5c0e437
enh(sync): updateFromContent()
max-nextcloud Nov 10, 2025
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
51 changes: 21 additions & 30 deletions cypress/e2e/api/SessionApi.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,34 +73,33 @@ describe('The session Api', function () {
cy.closeConnection(connection)
})

// Echoes all message types but queries
Object.entries(messages)
.filter(([key, _value]) => key !== 'query')
.forEach(([type, sample]) => {
it(`echos ${type} messages`, function () {
const steps = [sample]
const version = 0
cy.pushSteps({ connection, steps, version })
.its('version')
.should('eql', 0)
cy.syncSteps(connection)
.its('steps[0].data')
.should('eql', steps)
})
// Echoes updates and responses
;['update', 'response'].forEach((type) => {
it(`echos ${type} messages`, function () {
const steps = [messages[type]]
const version = 0
cy.pushSteps({ connection, steps, version })
.its('version')
.should('eql', 0)
cy.syncSteps(connection).its('steps[0].data').should('eql', steps)
})
})

it('responds to queries', function () {
it('responds to queries with updates and responses', function () {
const version = 0
Object.entries(messages).forEach(([type, sample]) => {
cy.pushSteps({ connection, steps: [sample], version })
})
cy.pushSteps({ connection, steps: [messages.query], version }).then(
(response) => {
cy.wrap(response).its('version').should('eql', 0)
cy.wrap(response).its('steps.length').should('eql', 1)
cy.wrap(response).its('steps.length').should('eql', 2)
cy.wrap(response)
.its('steps[0].data')
.should('eql', [messages.update])
cy.wrap(response)
.its('steps[1].data')
.should('eql', [messages.response])
},
)
})
Expand All @@ -111,7 +110,6 @@ describe('The session Api', function () {
let connection
let fileId
let filePath
let joining

beforeEach(function () {
cy.testName().then((name) => {
Expand Down Expand Up @@ -156,13 +154,10 @@ describe('The session Api', function () {
manualSave: true,
})
cy.openConnection({ fileId, filePath })
.then(({ connection: con, data }) => {
joining = con
return data
})
.its('documentState')
.as('joining')
.its('data.documentState')
.should('eql', documentState)
cy.closeConnection(joining)
cy.get('@joining').its('connection').then(cy.closeConnection)
})

afterEach(function () {
Expand All @@ -175,7 +170,6 @@ describe('The session Api', function () {
let connection
let filePath
let shareToken
let joining

beforeEach(function () {
cy.testName().then((name) => {
Expand Down Expand Up @@ -232,13 +226,10 @@ describe('The session Api', function () {
manualSave: true,
})
cy.openConnection({ filePath: '', token: shareToken })
.then(({ connection: con, data }) => {
joining = con
return data
})
.its('documentState')
.as('joining')
.its('data.documentState')
.should('eql', documentState)
cy.closeConnection(joining)
cy.get('@joining').its('connection').then(cy.closeConnection)
})
})

Expand Down
21 changes: 13 additions & 8 deletions cypress/e2e/api/SyncServiceProvider.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,20 @@ describe('Sync service provider', function () {
*/
function createProvider(ydoc) {
const relativePath = '.'
const { connection, openConnection, baseVersionEtag } = provideConnection({
fileId,
relativePath,
})
const { syncService } = provideSyncService(
connection,
openConnection,
baseVersionEtag,
let baseVersionEtag
const setBaseVersionEtag = (val) => {
baseVersionEtag = val
}
const getBaseVersionEtag = () => baseVersionEtag
const { connection, openConnection } = provideConnection(
{
fileId,
relativePath,
},
getBaseVersionEtag,
setBaseVersionEtag,
)
const { syncService } = provideSyncService(connection, openConnection)
const queue = []
syncService.bus.on('opened', () => syncService.startSync())
return createSyncServiceProvider({
Expand Down
11 changes: 3 additions & 8 deletions cypress/e2e/conflict.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,9 @@ variants.forEach(function ({ fixture, mime }) {
cy.getContent().should('contain', 'Heading')

cy.uploadFile(fileName, mime, testName + '/' + fileName)
cy.get('#editor-container .document-status', {
timeout: 40000,
}).should('contain', 'session has expired')

// Reload button works
cy.get('#editor-container .document-status a.button')
.contains('Reload')
.click()
cy.intercept({ method: 'POST', url: '**/session/*/push' }).as('push')
cy.wait('@push', { timeout: 20_000 })
// Autoreload works
getWrapper().should('not.exist')
cy.getContent().should('contain', 'Hello world')
cy.getContent().should('not.contain', 'Heading')
Expand Down
22 changes: 8 additions & 14 deletions cypress/e2e/sync.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,10 @@ describe('Sync', () => {
'contain',
'The document could not be loaded.',
)
cy.intercept('**/apps/text/session/*/create').as('create')
cy.get('#editor-container .document-status').find('.button.primary').click()
// let first attempt fail
cy.wait('@create', { timeout: 10000 })
cy.get('#editor-container .document-status', { timeout: 30000 }).should(
'contain',
'The document could not be loaded.',
Expand All @@ -117,13 +120,13 @@ describe('Sync', () => {
cy.intercept('**/apps/text/session/*/*', (req) => {
req.continue()
}).as('alive')
cy.intercept('**/apps/text/session/*/create').as('create')
cy.get('#editor-container .document-status').find('.button.primary').click()
// this is the create request... - now with the alive alias
cy.wait('@alive', { timeout: 30000 })
cy.wait('@create', { timeout: 10000 })
.its('request.body')
.should('have.property', 'baseVersionEtag')
.should('not.be.empty')
cy.getContent().should('contain', 'Hello world')
})

it('recovers from a lost and closed connection', () => {
Expand Down Expand Up @@ -176,18 +179,9 @@ describe('Sync', () => {
cy.wait('@save')
cy.uploadTestFile('test.md')

cy.get('#editor-container .document-status', { timeout: 30000 }).should(
'contain',
'Editing session has expired.',
)

// Reload button works
cy.get('#editor-container .document-status a.button')
.contains('Reload')
.click()

cy.getContent()
cy.get('#editor-container .document-status .notecard').should('not.exist')
cy.getContent().should('not.exist')
cy.getContent().find('h2').should('contain', 'Hello world')
cy.getContent().find('li').should('not.exist') // was overwritten after the save
})

it('passes the doc content from one session to the next', () => {
Expand Down
6 changes: 0 additions & 6 deletions lib/Cron/Cleanup.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

namespace OCA\Text\Cron;

use OCA\Text\Exception\DocumentHasUnsavedChangesException;
use OCA\Text\Service\AttachmentService;
use OCA\Text\Service\DocumentService;
use OCA\Text\Service\SessionService;
Expand Down Expand Up @@ -42,11 +41,6 @@ protected function run($argument): void {
// Inactive sessions will get removed further down and will trigger a reset next time
continue;
}

try {
$this->documentService->resetDocument($document->getId());
} catch (DocumentHasUnsavedChangesException) {
}
$this->attachmentService->cleanupAttachments($document->getId());
}

Expand Down
4 changes: 2 additions & 2 deletions lib/Listeners/BeforeNodeWrittenListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ public function handle(Event $event): void {
}
// Reset document session to avoid manual conflict resolution if there's no unsaved steps
try {
$this->documentService->resetDocument($node->getId());
$this->documentService->resetDocument($node->getId(), true);
} catch (DocumentHasUnsavedChangesException|NotFoundException $e) {
// Do not throw during event handling in this is expected to happen
// DocumentHasUnsavedChangesException: A document editing session is likely ongoing, someone can resolve the conflict
// NotFoundException: The event was called oin a file that was just created so a NonExistingFile object is used that has no id yet
$this->logger->debug('Reset document skipped in BeforeNodeWrittenEvent', ['exception' => $e]);
$this->logger->warning('Reset document skipped in BeforeNodeWrittenEvent', ['exception' => $e]);
}
}
}
8 changes: 6 additions & 2 deletions lib/Service/DocumentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,12 @@ public function addStep(Document $document, Session $session, array $steps, int
if ($readOnly && $message->isUpdate()) {
continue;
}
// Only accept sync protocol
if ($message->getYjsMessageType() !== YjsMessage::YJS_MESSAGE_SYNC) {
continue;
}
// Filter out query steps as they would just trigger clients to send their steps again
if ($message->getYjsMessageType() === YjsMessage::YJS_MESSAGE_SYNC && $message->getYjsSyncType() === YjsMessage::YJS_MESSAGE_SYNC_STEP1) {
if ($message->getYjsSyncType() === YjsMessage::YJS_MESSAGE_SYNC_STEP1) {
$stepsIncludeQuery = true;
} else {
$stepsToInsert[] = $step;
Expand Down Expand Up @@ -249,7 +253,7 @@ public function addStep(Document $document, Session $session, array $steps, int
$stepsToReturn = [];
foreach ($allSteps as $step) {
$message = YjsMessage::fromBase64($step->getData());
if ($message->getYjsMessageType() === YjsMessage::YJS_MESSAGE_SYNC && $message->getYjsSyncType() === YjsMessage::YJS_MESSAGE_SYNC_UPDATE) {
if ($message->isUpdate()) {
$stepsToReturn[] = $step;
}
}
Expand Down
21 changes: 21 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
"vue-click-outside": "^1.1.0",
"vue-material-design-icons": "^5.3.1",
"webdav": "^5.8.0",
"y-indexeddb": "^9.0.12",
"y-prosemirror": "^1.3.7",
"y-protocols": "^1.0.7",
"yjs": "^13.6.28"
Expand Down
58 changes: 58 additions & 0 deletions playwright/e2e/indexed-db.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/**
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import { expect, mergeTests } from '@playwright/test'
import { test as editorTest } from '../support/fixtures/editor'
import { test as offlineTest } from '../support/fixtures/offline'
import { test as randomUserTest } from '../support/fixtures/random-user'
import { test as uploadFileTest } from '../support/fixtures/upload-file'

const test = mergeTests(editorTest, offlineTest, randomUserTest, uploadFileTest)

// As we switch on and off the network
// we cannot run tests in parallel.
test.describe.configure({ mode: 'serial' })

test.beforeEach(async ({ open }) => {
await open()
})

test('recovering from indexed db', async ({
close,
editor,
file,
setOffline,
setOnline,
}) => {
await expect(editor.el).toBeVisible()
await setOffline()
await editor.typeHeading('Hello world')
await close()
await setOnline()
await file.open()
await expect(editor.getHeading({ name: 'Hello world' })).toBeVisible()
await expect(editor.offlineState).not.toBeVisible()
await expect(editor.saveIndicator).toHaveAttribute('title', /Unsaved changes/)
})

test('conflict when recovering from indexed db', async ({
close,
editor,
file,
setOffline,
setOnline,
user,
}) => {
await expect(editor.el).toBeVisible()
await setOffline()
await editor.typeHeading('Hello world')
await close()
await setOnline()
await user.uploadFile({ name: file.name, content: 'Good bye' })
await file.open()
await expect(editor.getHeading({name: 'Hello world'})).toBeVisible()

Check failure on line 55 in playwright/e2e/indexed-db.spec.ts

View workflow job for this annotation

GitHub Actions / test

[chromium] › playwright/e2e/indexed-db.spec.ts:42:1 › conflict when recovering from indexed db

1) [chromium] › playwright/e2e/indexed-db.spec.ts:42:1 › conflict when recovering from indexed db Retry #2 ─────────────────────────────────────────────────────────────────────────────────────── Error: expect(locator).toBeVisible() failed Locator: locator('.editor').first().getByRole('textbox').getByRole('heading', { name: 'Hello world' }) Expected: visible Timeout: 5000ms Error: element(s) not found Call log: - Expect "toBeVisible" with timeout 5000ms - waiting for locator('.editor').first().getByRole('textbox').getByRole('heading', { name: 'Hello world' }) 53 | await user.uploadFile({ name: file.name, content: 'Good bye' }) 54 | await file.open() > 55 | await expect(editor.getHeading({name: 'Hello world'})).toBeVisible() | ^ 56 | await expect(editor.offlineState).not.toBeVisible() 57 | await expect(editor.saveIndicator).toHaveAttribute('title', /Unsaved changes/) 58 | }) at /home/runner/work/text/text/playwright/e2e/indexed-db.spec.ts:55:57

Check failure on line 55 in playwright/e2e/indexed-db.spec.ts

View workflow job for this annotation

GitHub Actions / test

[chromium] › playwright/e2e/indexed-db.spec.ts:42:1 › conflict when recovering from indexed db

1) [chromium] › playwright/e2e/indexed-db.spec.ts:42:1 › conflict when recovering from indexed db Retry #1 ─────────────────────────────────────────────────────────────────────────────────────── Error: expect(locator).toBeVisible() failed Locator: locator('.editor').first().getByRole('textbox').getByRole('heading', { name: 'Hello world' }) Expected: visible Timeout: 5000ms Error: element(s) not found Call log: - Expect "toBeVisible" with timeout 5000ms - waiting for locator('.editor').first().getByRole('textbox').getByRole('heading', { name: 'Hello world' }) 53 | await user.uploadFile({ name: file.name, content: 'Good bye' }) 54 | await file.open() > 55 | await expect(editor.getHeading({name: 'Hello world'})).toBeVisible() | ^ 56 | await expect(editor.offlineState).not.toBeVisible() 57 | await expect(editor.saveIndicator).toHaveAttribute('title', /Unsaved changes/) 58 | }) at /home/runner/work/text/text/playwright/e2e/indexed-db.spec.ts:55:57

Check failure on line 55 in playwright/e2e/indexed-db.spec.ts

View workflow job for this annotation

GitHub Actions / test

[chromium] › playwright/e2e/indexed-db.spec.ts:42:1 › conflict when recovering from indexed db

1) [chromium] › playwright/e2e/indexed-db.spec.ts:42:1 › conflict when recovering from indexed db Error: expect(locator).toBeVisible() failed Locator: locator('.editor').first().getByRole('textbox').getByRole('heading', { name: 'Hello world' }) Expected: visible Timeout: 5000ms Error: element(s) not found Call log: - Expect "toBeVisible" with timeout 5000ms - waiting for locator('.editor').first().getByRole('textbox').getByRole('heading', { name: 'Hello world' }) 53 | await user.uploadFile({ name: file.name, content: 'Good bye' }) 54 | await file.open() > 55 | await expect(editor.getHeading({name: 'Hello world'})).toBeVisible() | ^ 56 | await expect(editor.offlineState).not.toBeVisible() 57 | await expect(editor.saveIndicator).toHaveAttribute('title', /Unsaved changes/) 58 | }) at /home/runner/work/text/text/playwright/e2e/indexed-db.spec.ts:55:57
await expect(editor.offlineState).not.toBeVisible()
await expect(editor.saveIndicator).toHaveAttribute('title', /Unsaved changes/)
})
1 change: 0 additions & 1 deletion playwright/support/fixtures/editor-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ export const test = base.extend<EditorApiFixture>({
document.body.appendChild(container)

const method = type === 'editor' ? 'createEditor' : 'createTable'
// @ts-expect-error - OCA.Text is a global
await window.OCA.Text[method]({
el: container,
...(fileId != null ? { fileId } : { content }),
Expand Down
1 change: 1 addition & 0 deletions playwright/support/fixtures/upload-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,6 @@ export const test = base.extend<UploadFileFixture>({

open: ({ file }, use) => use(() => file.open()),
viewer: ({ fileName, page }, use) => use(new ViewerSection(fileName, page)),
close: ({ viewer }, use) => use(() => viewer.close()),

})
Loading
Loading