Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions src/components/Editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,7 @@ export default {
filePath: this.relativePath,
clientId: this.ydoc.clientID,
pendingStructs: this.ydoc.store.pendingStructs,
pendingStructsRemote: this.syncProvider?.remote.store.pendingStructs,
clientVectors: [],
documentState: this.syncService?.getDocumentState(),
}
Expand Down
20 changes: 18 additions & 2 deletions src/services/y-websocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,24 @@
) => {
encoding.writeVarUint(encoder, messageSync)
const decoderForRemote = decoding.clone(decoder)
const pendingStructsBefore = provider.doc.store.pendingStructs

Check warning on line 47 in src/services/y-websocket.js

View check run for this annotation

Codecov / codecov/patch

src/services/y-websocket.js#L47

Added line #L47 was not covered by tests
const syncMessageType = syncProtocol.readSyncMessage(
decoder,
encoder,
provider.doc,
provider,
)
if (
!pendingStructsBefore
&& provider.doc.store.pendingStructs
&& !encoder.hasContent
) {
// The message received left pending structs behind.
// Send SyncStep1 to resync.
console.error('Failed to integrate yjs message. Trying to resync.')
encoding.writeVarUint(encoder, messageSync)
syncProtocol.writeSyncStep1(encoder, provider.doc)
}

Check warning on line 64 in src/services/y-websocket.js

View check run for this annotation

Codecov / codecov/patch

src/services/y-websocket.js#L54-L64

Added lines #L54 - L64 were not covered by tests
// Message came from the broadcast channel
// Do not track in this.remote and do not emit sync.
if (!emitSynced) {
Expand Down Expand Up @@ -289,7 +301,7 @@
params = {},
protocols = [],
WebSocketPolyfill = WebSocket,
resyncInterval = -1,
resyncInterval = 30_000,

Check warning on line 304 in src/services/y-websocket.js

View check run for this annotation

Codecov / codecov/patch

src/services/y-websocket.js#L304

Added line #L304 was not covered by tests
maxBackoffTime = 2500,
disableBc = false,
} = {},
Expand Down Expand Up @@ -345,7 +357,11 @@
if (resyncInterval > 0) {
this._resyncInterval = /** @type {any} */ (
setInterval(() => {
if (this.ws && this.ws.readyState === WebSocket.OPEN) {
if (
this.ws
&& this.ws.readyState === WebSocket.OPEN
&& doc.store.pendingStructs
) {

Check warning on line 364 in src/services/y-websocket.js

View check run for this annotation

Codecov / codecov/patch

src/services/y-websocket.js#L360-L364

Added lines #L360 - L364 were not covered by tests
// resend sync step 1
const encoder = encoding.createEncoder()
encoding.writeVarUint(encoder, messageSync)
Expand Down
Loading