From d6bae1e5b8329786b12324c30f37fe0e64961c1f Mon Sep 17 00:00:00 2001 From: Ivan Date: Fri, 10 May 2019 16:04:11 +0000 Subject: [PATCH] Ensure that WebView is fully loaded before sending message --- src/webview/src/App.vue | 4 ++++ src/webview_controller.js | 17 +++++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/webview/src/App.vue b/src/webview/src/App.vue index f1a1d33..b1c3f70 100644 --- a/src/webview/src/App.vue +++ b/src/webview/src/App.vue @@ -50,6 +50,10 @@ export default { note.markdownRenderedOnServer = true; } }); + + window.vsCodeApi.postMessage({ + command: 'appReady', + }); }, } diff --git a/src/webview_controller.js b/src/webview_controller.js index b10547a..09fc33c 100644 --- a/src/webview_controller.js +++ b/src/webview_controller.js @@ -64,10 +64,20 @@ const createPanel = issuable => { }); }; -async function handleCreate(panel, issuable) { - const discussions = await gitLabService.fetchDiscussions(issuable); +function sendIssuableAndDiscussions(panel, issuable, discussions, appIsReady) { + if (!discussions || !appIsReady) return; panel.webview.postMessage({ type: 'issuableFetch', issuable, discussions }); +} + +async function handleCreate(panel, issuable) { + let discussions = false; + let appIsReady = false; panel.webview.onDidReceiveMessage(async message => { + if (message.command === 'appReady') { + appIsReady = true; + sendIssuableAndDiscussions(panel, issuable, discussions, appIsReady); + } + if (message.command === 'renderMarkdown') { let rendered = await gitLabService.renderMarkdown(message.markdown); rendered = (rendered || '') @@ -97,6 +107,9 @@ async function handleCreate(panel, issuable) { } } }); + + discussions = await gitLabService.fetchDiscussions(issuable); + sendIssuableAndDiscussions(panel, issuable, discussions, appIsReady); } async function create(issuable) { -- GitLab