Skip to content

Commit 328289e

Browse files
committed
Ensure graph view loads when result is clicked
Without these changes, a race condition was sometimes hit when viewing a graph. There are two, related issues that are fixed. These problems did not appear in the past since rendering a normal results view is much faster and the message handler is always already set up by the time the interface first sends a message over to the web view. 1. `vscode.postMessage({ t: 'resultViewLoaded' });` was being called before the component is completely mounted. Ie- `componentDidMount` is not called. So, the interface is notified that the web view is ready to receive messages _before_ it is actually ready to receive messages. The change ensures the interface only sends messages when the web view is ready. 2. `this._panelLoaded` is never set to false if the panel is unloaded. This means that if a panel is re-opened, the interface assumes that the view is nearly _immediately_ ready to receive messages. The change ensures that the interface waits for the webview to really be loaded before sending messages. In both of these cases, if the interface sends the `setState` message too early, then the message is ignored since no handlers have been added to the web view.
1 parent 64b33b7 commit 328289e

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

extensions/ql-vscode/src/interface.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ export class InterfaceManager extends DisposableObject {
203203
() => {
204204
this._panel = undefined;
205205
this._displayedQuery = undefined;
206+
this._panelLoaded = false;
206207
},
207208
null,
208209
ctx.subscriptions

extensions/ql-vscode/src/view/results.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ class App extends React.Component<Record<string, never>, ResultsViewState> {
302302
componentDidMount(): void {
303303
this.vscodeMessageHandler = this.vscodeMessageHandler.bind(this);
304304
window.addEventListener('message', this.vscodeMessageHandler);
305+
vscode.postMessage({ t: 'resultViewLoaded' });
305306
}
306307

307308
componentWillUnmount(): void {
@@ -320,5 +321,3 @@ class App extends React.Component<Record<string, never>, ResultsViewState> {
320321
}
321322

322323
Rdom.render(<App />, document.getElementById('root'));
323-
324-
vscode.postMessage({ t: 'resultViewLoaded' });

0 commit comments

Comments
 (0)