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 Dec 18, 2023
commit d9faf1cdf7b9f4787de22dc79456a843c5e45be1
15 changes: 7 additions & 8 deletions src/services/WebSocketPolyfill.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,21 +83,20 @@ export default function initWebSocketPolyfill(syncService, fileId, initialSessio
// data.forEach(logStep)

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 @@ -126,18 +125,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