From f18917f0ac898f3dc7e3d46c5068ea0104d398b1 Mon Sep 17 00:00:00 2001 From: yflory Date: Thu, 8 Feb 2018 12:24:34 +0100 Subject: [PATCH] Fix race condition at registration --- customize.dist/login.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/customize.dist/login.js b/customize.dist/login.js index 02d8936a1..5511637e8 100644 --- a/customize.dist/login.js +++ b/customize.dist/login.js @@ -80,7 +80,7 @@ define([ var rt = opt.rt = Listmap.create(config); rt.proxy .on('ready', function () { - cb(void 0, rt); + setTimeout(function () { cb(void 0, rt); }); }) .on('disconnect', function (info) { cb('E_DISCONNECT', info); @@ -162,9 +162,16 @@ define([ sessionStorage.migrateAnonDrive = 1; } - Realtime.whenRealtimeSyncs(rt.realtime, function () { - LocalStore.login(res.userHash, res.userName, function () { - cb(void 0, res); + // We have to call whenRealtimeSyncs asynchronously here because in the current + // version of listmap, onLocal calls `chainpad.contentUpdate(newValue)` + // asynchronously. + // The following setTimeout is here to make sure whenRealtimeSyncs is called after + // `contentUpdate` so that we have an update userDoc in chainpad. + setTimeout(function () { + Realtime.whenRealtimeSyncs(rt.realtime, function () { + LocalStore.login(res.userHash, res.userName, function () { + setTimeout(function () { cb(void 0, res); }); + }); }); }); });