From 69ebcf08fc2b366c8af53f58a2f268e24af64d5f Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Tue, 14 Feb 2017 17:28:56 +0000 Subject: [PATCH] Bugfix where, upon refresh, it was impossible to write to the db (clone errors) --- src/sync.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/sync.js b/src/sync.js index 9132d7018..0b4c5b578 100644 --- a/src/sync.js +++ b/src/sync.js @@ -513,11 +513,14 @@ SyncApi.prototype._sync = function(syncOptions) { let isCachedResponse = false; if (self.opts.syncAccumulator && !syncOptions.hasSyncedBefore) { - const data = self.opts.syncAccumulator.getJSON(); + let data = self.opts.syncAccumulator.getJSON(); // Don't do an HTTP hit to /sync. Instead, load up the persisted /sync data, // if there is data there. if (data.nextBatch) { debuglog("sync(): not doing HTTP hit, instead returning stored /sync data"); + // We must deep copy the stored data so that the /sync processing code doesn't + // corrupt the internal state of the sync accumulator (it adds non-clonable keys) + data = JSON.parse(JSON.stringify(data)); this._currentSyncRequest = q.resolve({ next_batch: data.nextBatch, rooms: data.roomsData,