diff --git a/e2e/playwright/file-tree.spec.ts b/e2e/playwright/file-tree.spec.ts index 422754f26..d97174f42 100644 --- a/e2e/playwright/file-tree.spec.ts +++ b/e2e/playwright/file-tree.spec.ts @@ -72,7 +72,6 @@ test.describe('integrations tests', () => { }) await test.step('setup for next assertion', async () => { await toolbar.openFile('main.kcl') - await scene.settled(cmdBar) await clickObj() @@ -89,7 +88,7 @@ test.describe('integrations tests', () => { await toolbar.expectFileTreeState(['main.kcl', fileName]) }) await test.step('check sketch mode is exited when opening a different file', async () => { - await toolbar.openFile(fileName, { wait: false }) + await toolbar.openFile(fileName) // check we're out of sketch mode await expect(toolbar.exitSketchBtn).not.toBeVisible() diff --git a/e2e/playwright/fixtures/fixtureSetup.ts b/e2e/playwright/fixtures/fixtureSetup.ts index 88fe4f125..cbff1186a 100644 --- a/e2e/playwright/fixtures/fixtureSetup.ts +++ b/e2e/playwright/fixtures/fixtureSetup.ts @@ -39,7 +39,8 @@ export class AuthenticatedApp { } async initialise(code = '') { - await setup(this.context, this.page, this.testInfo) + const testDir = this.testInfo.outputPath('electron-test-projects-dir') + await setup(this.context, this.page, testDir, this.testInfo) const u = await getUtils(this.page) await this.page.addInitScript(async (code) => { diff --git a/e2e/playwright/fixtures/toolbarFixture.ts b/e2e/playwright/fixtures/toolbarFixture.ts index a07235c90..07b2d8445 100644 --- a/e2e/playwright/fixtures/toolbarFixture.ts +++ b/e2e/playwright/fixtures/toolbarFixture.ts @@ -159,16 +159,10 @@ export class ToolbarFixture { } } /** - * Opens file by it's name and waits for execution to finish + * Opens file by it's name */ - openFile = async ( - fileName: string, - { wait }: { wait?: boolean } = { wait: true } - ) => { + openFile = async (fileName: string) => { await this.filePane.getByText(fileName).click() - if (wait) { - await scene.settled(cmdBar) - } } selectCenterRectangle = async () => { await this.page diff --git a/e2e/playwright/testing-constraints.spec.ts b/e2e/playwright/testing-constraints.spec.ts index deb1b3114..12755f752 100644 --- a/e2e/playwright/testing-constraints.spec.ts +++ b/e2e/playwright/testing-constraints.spec.ts @@ -1029,7 +1029,7 @@ part002 = startSketchOn(XZ) await page.setBodyDimensions({ width: 1200, height: 500 }) await homePage.goToModelingScene() - await scene.settled() + await scene.settled(cmdBar) await page.getByText('line(end = [3.79, 2.68], tag = $seg01)').click() await expect(page.getByRole('button', { name: 'Edit Sketch' })).toBeEnabled( diff --git a/src/hooks/useNetworkStatus.tsx b/src/hooks/useNetworkStatus.tsx index 9695b69ab..25d5939cf 100644 --- a/src/hooks/useNetworkStatus.tsx +++ b/src/hooks/useNetworkStatus.tsx @@ -71,7 +71,7 @@ export function useNetworkStatus() { ? NetworkHealthState.Disconnected : hasIssues || hasIssues === undefined ? NetworkHealthState.Issue - : ping > 16.6 * 3 // we consider ping longer than 3 frames as weak + : (ping ?? 0) > 16.6 * 3 // we consider ping longer than 3 frames as weak ? NetworkHealthState.Weak : NetworkHealthState.Ok ) diff --git a/src/lang/std/engineConnection.ts b/src/lang/std/engineConnection.ts index 11dea923d..ba0877f5c 100644 --- a/src/lang/std/engineConnection.ts +++ b/src/lang/std/engineConnection.ts @@ -298,11 +298,9 @@ class EngineConnection extends EventTarget { public webrtcStatsCollector?: () => Promise private engineCommandManager: EngineCommandManager - private pingPongSpan: { ping?: Date; pong?: Date } - private pingIntervalId: ReturnType = setInterval( - () => {}, - 60_000 - ) + private pingPongSpan: { ping?: number; pong?: number } + private pingIntervalId: ReturnType = setInterval(() => {}, + 60_000) isUsingConnectionLite: boolean = false timeoutToForceConnectId: ReturnType = setTimeout(() => {}, @@ -346,7 +344,7 @@ class EngineConnection extends EventTarget { this.send({ type: 'ping' }) this.pingPongSpan = { - ping: new Date(), + ping: Date.now(), pong: undefined, } }, pingIntervalMs) @@ -909,7 +907,7 @@ class EngineConnection extends EventTarget { // Send an initial ping this.send({ type: 'ping' }) - this.pingPongSpan.ping = new Date() + this.pingPongSpan.ping = Date.now() } this.websocket.addEventListener('open', this.onWebSocketOpen) @@ -1004,12 +1002,14 @@ class EngineConnection extends EventTarget { switch (resp.type) { case 'pong': - this.pingPongSpan.pong = new Date() + this.pingPongSpan.pong = Date.now() this.dispatchEvent( new CustomEvent(EngineConnectionEvents.PingPongChanged, { detail: Math.min( 999, - Math.floor(this.pingPongSpan.pong - this.pingPongSpan.ping) + Math.floor( + this.pingPongSpan.pong - (this.pingPongSpan.ping ?? 0) + ) ), }) ) @@ -1176,7 +1176,7 @@ class EngineConnection extends EventTarget { // Do not change this back to an object or any, we should only be sending the // WebSocketRequest type! unreliableSend(message: Models['WebSocketRequest_type']) { - if (this.unreliableDataChannel.readyState !== 'open') return + if (this.unreliableDataChannel?.readyState !== 'open') return // TODO(paultag): Add in logic to determine the connection state and // take actions if needed? diff --git a/src/lib/settings/initialSettings.tsx b/src/lib/settings/initialSettings.tsx index 2fa317a4c..fd7a4f7a7 100644 --- a/src/lib/settings/initialSettings.tsx +++ b/src/lib/settings/initialSettings.tsx @@ -223,16 +223,35 @@ export function createSettings() { value: settingValueInStorage, updateValue: writeSettingValueToStorage, }) => { - const [timeoutId, setTimeoutId] = useState(undefined) + const [timeoutId, setTimeoutId] = useState< + ReturnType | undefined + >(undefined) const [preview, setPreview] = useState( settingValueInStorage === undefined ? settingValueInStorage : settingValueInStorage / MS_IN_MINUTE ) - const onChangeRange = (e: React.SyntheticEvent) => - setPreview(e.currentTarget.value) + const onChangeRange = (e: React.SyntheticEvent) => { + if ( + !( + e.isTrusted && + 'value' in e.currentTarget && + e.currentTarget.value + ) + ) + return + setPreview(Number(e.currentTarget.value)) + } const onSaveRange = (e: React.SyntheticEvent) => { if (preview === undefined) return + if ( + !( + e.isTrusted && + 'value' in e.currentTarget && + e.currentTarget.value + ) + ) + return writeSettingValueToStorage( Number(e.currentTarget.value) * MS_IN_MINUTE ) @@ -241,6 +260,7 @@ export function createSettings() { return (