Skip to content

Commit 79422f4

Browse files
committed
prevent page load race conditions and suggestion selection in editor
1 parent 6177765 commit 79422f4

File tree

5 files changed

+39
-9
lines changed

5 files changed

+39
-9
lines changed

packages/browser-tests/cypress/commands.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -363,15 +363,21 @@ Cypress.Commands.add(
363363
}
364364
);
365365

366+
Cypress.Commands.add("clearStorageAndVisit", (url) => {
367+
cy.visit(url, {
368+
onBeforeLoad: (win) => {
369+
win.localStorage.clear();
370+
win.indexedDB.deleteDatabase("web-console");
371+
},
372+
});
373+
});
374+
366375
Cypress.Commands.add("loadConsoleWithAuth", (clearWarnings = false) => {
367-
cy.clearLocalStorage();
368-
indexedDB.deleteDatabase("web-console");
369-
cy.visit(baseUrl);
376+
cy.clearStorageAndVisit(baseUrl);
370377
cy.loginWithUserAndPassword();
371378
if (clearWarnings) {
372379
cy.clearSimulatedWarnings();
373-
indexedDB.deleteDatabase("web-console");
374-
cy.visit(baseUrl);
380+
cy.clearStorageAndVisit(baseUrl);
375381
cy.getEditor().should("be.visible");
376382
}
377383
});

packages/browser-tests/cypress/integration/console/editor.spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ describe("run query", () => {
4646
cy.realPress("ArrowLeft");
4747
}
4848
cy.focused().type(`${ctrlOrCmd}{enter}`);
49-
cy.getColumnName(0).should("contain", "count");
49+
cy.getColumnName(0).should("contain", "count()");
5050
cy.getGridRow(0).should("contain", "100");
5151

5252
// go inside the first query
@@ -55,7 +55,7 @@ describe("run query", () => {
5555
cy.realPress("ArrowLeft");
5656
}
5757
cy.focused().type(`${ctrlOrCmd}{enter}`);
58-
cy.getColumnName(0).should("contain", "count");
58+
cy.getColumnName(0).should("contain", "count()");
5959
cy.getGridRow(0).should("contain", "100");
6060
});
6161

@@ -918,7 +918,7 @@ describe("handling comments", () => {
918918
});
919919

920920
it("should highlight and execute sql with line comments inside", () => {
921-
cy.typeQuery("select\n\nx\n-- y\n-- z\n from long_sequence(1);");
921+
cy.typeQueryDirectly("select\nx\n-- y\n-- z\n from long_sequence(1);");
922922
cy.getCursorQueryDecoration().should("have.length", 5);
923923
cy.getCursorQueryGlyph().should("have.length", 1);
924924
cy.runLine();
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import React, { useEffect, useRef } from 'react'
2+
3+
export const useEffectIgnoreFirst = (effect: () => void, deps?: React.DependencyList) => {
4+
const firstRender = useRef(true)
5+
6+
useEffect(() => {
7+
if (firstRender.current) {
8+
firstRender.current = false
9+
return
10+
}
11+
effect()
12+
}, deps ?? [])
13+
}

packages/web-console/src/scenes/Search/SearchPanel.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import { SearchResults } from './SearchResults'
88
import { eventBus } from '../../modules/EventBus'
99
import { EventType } from '../../modules/EventBus/types'
1010
import { useSearch } from '../../providers'
11+
import { db } from '../../store/db'
12+
import { useEffectIgnoreFirst } from '../../components/Hooks/useEffectIgnoreFirst'
1113

1214
const Wrapper = styled(PaneWrapper)<{
1315
$open?: boolean
@@ -154,8 +156,15 @@ export const SearchPanel = React.forwardRef<SearchPanelRef, SearchPanelProps>(({
154156
}
155157
}, [performSearch])
156158

157-
useEffect(() => {
159+
useEffectIgnoreFirst(() => {
158160
const timeoutId = setTimeout(() => {
161+
if (!db.ready) {
162+
setTimeout(() => {
163+
performSearch()
164+
}, 1000)
165+
return
166+
}
167+
159168
performSearch()
160169
}, 300)
161170

packages/web-console/src/store/db.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export class Storage extends Dexie {
3838
buffers!: Table<Buffer, number>
3939
editor_settings!: Table<EditorSettings, number>
4040
read_notifications!: Table<{ newsId: string }, number>
41+
ready: boolean = false
4142

4243
constructor() {
4344
super("web-console")
@@ -140,6 +141,7 @@ export class Storage extends Dexie {
140141

141142
// clear search params from the address bar
142143
window.history.replaceState({}, "", url)
144+
this.ready = true
143145
})
144146
}
145147
}

0 commit comments

Comments
 (0)