Skip to content

Conversation

@max-nextcloud
Copy link
Collaborator

Process initial document state as incoming message.
This way it will be tracked as received from the remote server by y-websocket
and the update send to the server will exclude it.

Also use the sync services opened event inside WebsocketPolyfill
rather than mixing async syncService.open().then and event handling.
This allows us to emit opened and then sync from syncService.open().

Process initial document state as incoming message.
This way it will be tracked as received from the remote server by y-websocket
and the update send to the server will exclude it.

Also use the sync services `opened` event inside WebsocketPolyfill
rather than mixing async `syncService.open().then` and event handling.
This allows us to emit `opened` and then `sync` from `syncService.open()`.

Signed-off-by: Max <max@nextcloud.com>
@max-nextcloud
Copy link
Collaborator Author

/backport to stable32

@max-nextcloud
Copy link
Collaborator Author

/backport to stable31

@codecov
Copy link

codecov bot commented Oct 15, 2025

Codecov Report

❌ Patch coverage is 36.00000% with 16 lines in your changes missing coverage. Please review.
✅ Project coverage is 60.17%. Comparing base (490ddb6) to head (205c7cb).
⚠️ Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
src/services/SyncService.ts 14.28% 12 Missing ⚠️
src/services/WebSocketPolyfill.ts 50.00% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7787      +/-   ##
==========================================
- Coverage   60.19%   60.17%   -0.02%     
==========================================
  Files         502      502              
  Lines       38561    38572      +11     
  Branches     1135     1134       -1     
==========================================
+ Hits        23210    23212       +2     
- Misses      15245    15254       +9     
  Partials      106      106              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@max-nextcloud
Copy link
Collaborator Author

Cypress failures are due to nextcloud/server#55726

return [
'steps' => $stepsToReturn,
'version' => $newVersion,
'version' => isset($documentState) ? $document->getLastSavedVersion() : 0,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you tell if this has any other side effects? We now no longer return the latest version (number of steps in the db) but just the last saved. We used this in the past to compare and see if the document had unsaved changes, but I think that part was changed already.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise $newVersion is no longer used as a variable

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch wrt $newVersion. We were not using the version in the response on the client side anymore.

The unsaved changes check is on the server when cleaning up docs, right? That should still work. this is not changing the data structures there.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right there we still have it, i just remembered that we also used it in the frontend in the early days

Copy link
Member

@juliusknorr juliusknorr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

General approach makes sense but only looked at the code, not tested

@max-nextcloud max-nextcloud force-pushed the fix/receive-doc-state-as-message branch 2 times, most recently from 6bc7587 to 8763eb9 Compare October 16, 2025 06:30
* Emit the documents last saved version in the push response
  if document state is send as well.
* Otherwise send the version as 0 so it cannot increase the sync service version.
* Use the versions returned by create and push requests alongside the document state
  to construct a consistent step with the last saved version that matches the document state.

This will result in the sync service version getting bumped
to the documents last saved version
once the coresponding document state has been processed.

Signed-off-by: Max <max@nextcloud.com>
Signed-off-by: Max <max@nextcloud.com>
@max-nextcloud max-nextcloud force-pushed the fix/receive-doc-state-as-message branch from 8763eb9 to 205c7cb Compare October 16, 2025 06:37
@max-nextcloud

This comment was marked as resolved.

Copy link
Member

@mejo- mejo- left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went through the code changes once again, stepped through processing steps in the frontend with debugger (to make sure the $version = 0 doesn't have an impact there) and tested with three clients in different browsers. Didn't catch anything.

@mejo- mejo- merged commit 69fa176 into main Oct 16, 2025
63 of 67 checks passed
@mejo- mejo- deleted the fix/receive-doc-state-as-message branch October 16, 2025 10:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants