From b99e5bccaa7f86342deb8a227b5690752391ea77 Mon Sep 17 00:00:00 2001 From: Hans Larsen Date: Tue, 10 Mar 2020 10:22:25 -0700 Subject: [PATCH 1/2] feat: remove progress bar after loading the Javascript Before we did not remove it, so if the app Javascript has a bug or uses synchronous code, the progress bar would still show up. Now at least we remove the progress bar, and leave the page blank. --- src/userlib/js/bootstrap/index.html | 2 +- src/userlib/js/bootstrap/index.ts | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/userlib/js/bootstrap/index.html b/src/userlib/js/bootstrap/index.html index fceeef1dc9..db84554f06 100644 --- a/src/userlib/js/bootstrap/index.html +++ b/src/userlib/js/bootstrap/index.html @@ -7,6 +7,6 @@ - Loading... + Loading... diff --git a/src/userlib/js/bootstrap/index.ts b/src/userlib/js/bootstrap/index.ts index 00aa0a2be3..96601b6902 100644 --- a/src/userlib/js/bootstrap/index.ts +++ b/src/userlib/js/bootstrap/index.ts @@ -36,10 +36,14 @@ function _getVariable( } // Retrieve and execute a JavaScript file from the server. -async function _loadJs(canisterId: string, filename: string): Promise { +async function _loadJs(canisterId: string, filename: string, onload = async () => {}): Promise { const content = await window.icHttpAgent.retrieveAsset(canisterId, filename); const js = new TextDecoder().decode(content); const dataUri = 'data:text/javascript;charset=utf-8,' + encodeURIComponent(js); + + // Run an event function so the callee can execute some code before loading the + // Javascript. + await onload(); // TODO(hansl): either get rid of eval, or rid of webpack, or make this // work without this horrible hack. return eval('import("' + dataUri + '")'); // tslint:disable-line @@ -105,7 +109,9 @@ async function _main() { render.render(canisterId, actor, canister); } else { // Load index.js from the canister and execute it. - await _loadJs(canisterId, 'index.js'); + await _loadJs(canisterId, 'index.js', async () => { + document.getElementById('ic-progress')!.remove(); + }); } } } From 99d15253a7ca3e35d2cbcc925e816dc86201b690 Mon Sep 17 00:00:00 2001 From: Hans Larsen Date: Tue, 10 Mar 2020 10:33:54 -0700 Subject: [PATCH 2/2] fixup! feat: remove progress bar after loading the Javascript --- src/userlib/js/bootstrap/index.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/userlib/js/bootstrap/index.ts b/src/userlib/js/bootstrap/index.ts index 96601b6902..7b24391565 100644 --- a/src/userlib/js/bootstrap/index.ts +++ b/src/userlib/js/bootstrap/index.ts @@ -36,7 +36,11 @@ function _getVariable( } // Retrieve and execute a JavaScript file from the server. -async function _loadJs(canisterId: string, filename: string, onload = async () => {}): Promise { +async function _loadJs( + canisterId: string, + filename: string, + onload = async () => {}, +): Promise { const content = await window.icHttpAgent.retrieveAsset(canisterId, filename); const js = new TextDecoder().decode(content); const dataUri = 'data:text/javascript;charset=utf-8,' + encodeURIComponent(js);