Skip to content
Merged
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(sync): ensure queue stays the same array
Change the content of `queue` with `queue.splice`
rather than setting `queue` to another array.

Signed-off-by: Max <[email protected]>
  • Loading branch information
max-nextcloud committed Jan 9, 2024
commit 8954454e9ac8031dace2cc3ffacc12d0cf6fc142
15 changes: 7 additions & 8 deletions src/services/WebSocketPolyfill.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,21 +80,20 @@ export default function initWebSocketPolyfill(syncService, fileId, initialSessio

send(...data) {
queue.push(...data)
let outbox = []
let outbox
return syncService.sendSteps(() => {
outbox = [...queue]
const data = {
steps: this.#steps,
awareness: this.#awareness,
version: this.#version,
}
queue = []
outbox = queue.splice(0, queue.length)
logger.debug('sending steps ', data)
return data
})?.catch(err => {
logger.error(err)
// try to send the steps again
queue = [...outbox, ...queue]
// Prefix the queue with the steps in outbox to send them again
queue.splice(0, 0, ...outbox)
})
}

Expand Down Expand Up @@ -123,18 +122,18 @@ export default function initWebSocketPolyfill(syncService, fileId, initialSessio
if (queue.length) {
let outbox = []
return syncService.sendStepsNow(() => {
outbox = [...queue]
const data = {
steps: this.#steps,
awareness: this.#awareness,
version: this.#version,
}
queue = []
outbox = queue.splice(0, queue.length)
logger.debug('sending final steps ', data)
return data
})?.catch(err => {
logger.error(err)
queue = [...outbox, ...queue]
// Prefix the queue with the steps in outbox to send them again
queue.splice(0, 0, ...outbox)
})
}
}
Expand Down