From 50fe17bce15b597dcc53351969eb10ae9af71c72 Mon Sep 17 00:00:00 2001 From: Sean Sube Date: Thu, 19 Jan 2023 17:17:43 -0600 Subject: [PATCH] fix(gui): set a reasonable timeout on the initial params fetch --- gui/src/components/error/ParamsVersion.tsx | 5 +++-- gui/src/components/error/ServerParams.tsx | 2 +- gui/src/main.tsx | 7 ++++--- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/gui/src/components/error/ParamsVersion.tsx b/gui/src/components/error/ParamsVersion.tsx index 31beb3d5..bb141af0 100644 --- a/gui/src/components/error/ParamsVersion.tsx +++ b/gui/src/components/error/ParamsVersion.tsx @@ -1,6 +1,7 @@ import { Alert, AlertTitle, Typography } from '@mui/material'; import * as React from 'react'; -import { PARAM_VERSION } from '../../config'; + +import { PARAM_VERSION } from '../../config.js'; export interface ParamsVersionErrorProps { root: string; @@ -10,7 +11,7 @@ export interface ParamsVersionErrorProps { export function ParamsVersionError(props: ParamsVersionErrorProps) { return - Parameter Version Error + Parameter version error The server returned parameters that are too old for the client to load. diff --git a/gui/src/components/error/ServerParams.tsx b/gui/src/components/error/ServerParams.tsx index 480b59b8..f82e4cad 100644 --- a/gui/src/components/error/ServerParams.tsx +++ b/gui/src/components/error/ServerParams.tsx @@ -19,7 +19,7 @@ function getErrorMessage(error: unknown): string { export function ServerParamsError(props: ServerParamsErrorProps) { return - Server Error + Error fetching server parameters Could not fetch parameters from the ONNX web API server at {props.root}. diff --git a/gui/src/main.tsx b/gui/src/main.tsx index 74709fd4..e6a80a0d 100644 --- a/gui/src/main.tsx +++ b/gui/src/main.tsx @@ -1,6 +1,5 @@ /* eslint-disable no-console */ -import { mustDefault, mustExist } from '@apextoaster/js-utils'; -import { merge } from 'lodash'; +import { mustDefault, mustExist, timeout } from '@apextoaster/js-utils'; import * as React from 'react'; import ReactDOM from 'react-dom/client'; import { QueryClient, QueryClientProvider } from 'react-query'; @@ -16,6 +15,8 @@ import { OnnxWeb } from './components/OnnxWeb.js'; import { getApiRoot, loadConfig, mergeConfig, PARAM_VERSION } from './config.js'; import { ClientContext, ConfigContext, createStateSlices, OnnxState, StateContext } from './state.js'; +export const INITIAL_LOAD_TIMEOUT = 5_000; + export async function main() { // load config from GUI server const config = await loadConfig(); @@ -30,7 +31,7 @@ export async function main() { try { // load full params from the API server and merge with the initial client config - const params = await client.params(); + const params = await timeout(INITIAL_LOAD_TIMEOUT, client.params()); const version = mustDefault(params.version, '0.0.0'); if (satisfies(version, PARAM_VERSION)) { const completeConfig = mergeConfig(config, params);