From f2c864ec667fc5f85e5ecb2e6379262e0dff093b Mon Sep 17 00:00:00 2001 From: Ben Newman Date: Tue, 31 Jul 2018 22:38:18 -0400 Subject: [PATCH] Avoid TDZ error from calling observe callbacks synchronously. Should fix #10092. --- packages/autoupdate/autoupdate_client.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/autoupdate/autoupdate_client.js b/packages/autoupdate/autoupdate_client.js index db9075d39f..a3ce4d2449 100644 --- a/packages/autoupdate/autoupdate_client.js +++ b/packages/autoupdate/autoupdate_client.js @@ -96,9 +96,17 @@ Autoupdate._retrySubscription = () => { }, onReady() { + // Call checkNewVersionDocument with a slight delay, so that the + // const handle declaration is guaranteed to be initialized, even if + // the added or changed callbacks are called synchronously. + const resolved = Promise.resolve(); + function check(doc) { + resolved.then(() => checkNewVersionDocument(doc)); + } + const handle = ClientVersions.find().observe({ - added: checkNewVersionDocument, - changed: checkNewVersionDocument + added: check, + changed: check }); function checkNewVersionDocument(doc) {