Skip to content

Commit da0b2f9

Browse files
fix race condition
Setting .html starts the loading of the UI, but setup() sets up the message listeners in the backend for messages from the UI. We had setup() come after, and it worked, but if I added a small sleep() before setup() was run it would result in a failure due to messages not being handled due to handlers not being setup in time. As a solution this just moves the handler setup before we set the new UI. Signed-off-by: nkomonen-amazon <[email protected]>
1 parent 965969c commit da0b2f9

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

packages/core/src/login/webview/commonAuthViewProvider.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,10 @@ export class CommonAuthViewProvider implements WebviewViewProvider {
135135
enableCommandUris: true,
136136
localResourceRoots: [dist, resources],
137137
}
138-
webviewView.webview.html = this._getHtmlForWebview(this.extensionContext.extensionUri, webviewView.webview)
139138
// register the webview server
140139
await this.webView?.setup(webviewView.webview)
140+
141+
webviewView.webview.html = this._getHtmlForWebview(this.extensionContext.extensionUri, webviewView.webview)
141142
}
142143

143144
private _getHtmlForWebview(extensionURI: Uri, webview: vscode.Webview) {

packages/core/src/login/webview/vue/root.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ export default defineComponent({
8585
// TODO: Move this in to a reusable class for other webviews, it feels a bit messy here
8686
let didSetReady = false
8787
88-
// Setup error handlers to report
88+
// Setup error handlers to report. This may not actually be able to catch certain errors that we'd expect,
89+
// so this may have to be revisited.
8990
window.onerror = function (message) {
9091
if (didSetReady) {
9192
return
@@ -119,7 +120,7 @@ const handleLoaded = () => {
119120
if (!foundElement) {
120121
setUiReady((window as any).uiState, `Could not find element: ${(window as any).uiReadyElementId}`)
121122
} else {
122-
// Successful load!
123+
// Successful load!
123124
setUiReady((window as any).uiState)
124125
}
125126
}

0 commit comments

Comments
 (0)