Skip to content

Commit 2a4a912

Browse files
committed
Fix empty result view when switching between queries
When updating to React 18, we removed the loading step from the updating of the state of the result view since React would batch the updates anyway. However, this caused a bug where the result view would be empty when switching between queries. This is because the result view would retain the old selected result set name. This would not happen previously because React would re-render the view at least once, which would cause the result view to be unmounted and re-created. This fixes it by resetting the selected result set if we can't find the result set in the new result sets.
1 parent 3628f4b commit 2a4a912

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,31 @@ export class ResultTables extends React.Component<
139139
};
140140
}
141141

142+
componentDidUpdate(
143+
prevProps: Readonly<ResultTablesProps>,
144+
prevState: Readonly<ResultTablesState>,
145+
snapshot?: any,
146+
) {
147+
const resultSetExists =
148+
this.props.parsedResultSets.resultSetNames.some(
149+
(v) => this.state.selectedTable === v,
150+
) ||
151+
this.getResultSets().some(
152+
(v) => this.state.selectedTable === v.schema.name,
153+
);
154+
155+
// If the selected result set does not exist, select the default result set.
156+
if (!resultSetExists) {
157+
const selectedTable =
158+
this.props.parsedResultSets.selectedTable ||
159+
getDefaultResultSet(this.getResultSets());
160+
this.setState({
161+
selectedTable,
162+
selectedPage: `${this.props.parsedResultSets.pageNumber + 1}`,
163+
});
164+
}
165+
}
166+
142167
untoggleProblemsView() {
143168
this.setState({
144169
problemsViewSelected: false,

0 commit comments

Comments
 (0)