diff --git a/services/web/frontend/js/features/ide-react/components/loading.tsx b/services/web/frontend/js/features/ide-react/components/loading.tsx index 2d886e2cac..11b51ac26e 100644 --- a/services/web/frontend/js/features/ide-react/components/loading.tsx +++ b/services/web/frontend/js/features/ide-react/components/loading.tsx @@ -54,16 +54,38 @@ export const Loading: FC<{ } }, [projectJoined]) - const error = - connectionState.error || - (i18n.error ? getMeta('ol-translationLoadErrorMessage') : '') + const LoadingScreenError = () => { + if (connectionState.error) { + // NOTE: translations not ready yet + return connectionState.error === 'io-not-loaded' + ? 'Could not connect to websocket server :(' + : connectionState.error + } + + if (i18n.error) { + return getMeta('ol-translationLoadErrorMessage') + } + + return '' + } // Use loading text from the server, because i18n will not be ready initially const label = getMeta('ol-loadingText') + const hasError = Boolean(connectionState.error || i18n.error) + return (
- + + {hasError && ( +

+ +

+ )}
) } diff --git a/services/web/frontend/js/features/ide-react/connection/connection-manager.ts b/services/web/frontend/js/features/ide-react/connection/connection-manager.ts index 798136e2c7..080231744d 100644 --- a/services/web/frontend/js/features/ide-react/connection/connection-manager.ts +++ b/services/web/frontend/js/features/ide-react/connection/connection-manager.ts @@ -67,6 +67,18 @@ export class ConnectionManager extends Emitter { }) as unknown as Socket this.socket = socket + // bail out if socket.io failed to load (e.g. the real-time server is down) + if (typeof window.io !== 'object') { + debugConsole.error( + 'Socket.io javascript not loaded. Please check that the real-time service is running and accessible.' + ) + this.changeState({ + ...this.state, + error: 'io-not-loaded', + }) + return + } + socket.on('disconnect', () => this.onDisconnect()) socket.on('error', () => this.onConnectError()) socket.on('connect_failed', () => this.onConnectError()) diff --git a/services/web/frontend/js/features/ide-react/connection/types/connection-state.ts b/services/web/frontend/js/features/ide-react/connection/types/connection-state.ts index fc0501a3a1..6b0f4f45d0 100644 --- a/services/web/frontend/js/features/ide-react/connection/types/connection-state.ts +++ b/services/web/frontend/js/features/ide-react/connection/types/connection-state.ts @@ -7,6 +7,7 @@ export type ConnectionError = | 'rate-limited' | 'unable-to-connect' | 'unable-to-join' + | 'io-not-loaded' export type ConnectionState = { readyState: WebSocket['CONNECTING'] | WebSocket['OPEN'] | WebSocket['CLOSED'] diff --git a/services/web/frontend/js/features/project-list/components/project-list-root.tsx b/services/web/frontend/js/features/project-list/components/project-list-root.tsx index 0f70ed4b22..235863cad2 100644 --- a/services/web/frontend/js/features/project-list/components/project-list-root.tsx +++ b/services/web/frontend/js/features/project-list/components/project-list-root.tsx @@ -71,9 +71,11 @@ function ProjectListPageContent() { eventTracking.sendMB('loads_v2_dash', {}) }, []) + const { t } = useTranslation() + return isLoading ? (
- +
) : ( <> diff --git a/services/web/frontend/js/shared/components/loading-branded.tsx b/services/web/frontend/js/shared/components/loading-branded.tsx index bbd52c1914..21079b73a3 100644 --- a/services/web/frontend/js/shared/components/loading-branded.tsx +++ b/services/web/frontend/js/shared/components/loading-branded.tsx @@ -1,28 +1,26 @@ -import { useTranslation } from 'react-i18next' - type LoadingBrandedTypes = { loadProgress: number // Percentage label?: string - error?: string | null + hasError?: boolean } export default function LoadingBranded({ loadProgress, label, - error, + hasError = false, }: LoadingBrandedTypes) { - const { t } = useTranslation() return ( -
-
- {error ? ( -

{error}

- ) : ( + <> +
+
+
+ + {!hasError && (
- {label || t('loading')} + {label} @@ -34,6 +32,6 @@ export default function LoadingBranded({
)} -
+ ) } diff --git a/services/web/types/window.ts b/services/web/types/window.ts index c4bfe6bb7a..033e15580c 100644 --- a/services/web/types/window.ts +++ b/services/web/types/window.ts @@ -43,5 +43,6 @@ declare global { } expectingLinkedFileRefreshedSocketFor?: string | null writefull?: any + io?: any } }