Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
993571a491 | ||
|
|
4b87dbf7d7 |
No files matched your search
@@ -1,4 +1,4 @@
|
||||
import { type ReactNode, type RefObject, useEffect, useEffectEvent, useRef } from "react";
|
||||
import { type ReactNode, useEffect, useEffectEvent, useRef, useState } from "react";
|
||||
|
||||
import { type SlowRpcAckRequest, useSlowRpcAckRequests } from "../rpc/requestLatencyState";
|
||||
import {
|
||||
@@ -53,8 +53,6 @@ function describeExhaustedToast(): string {
|
||||
return "Retries exhausted trying to reconnect";
|
||||
}
|
||||
|
||||
type ThreadToastId = ReturnType<typeof toastManager.add>;
|
||||
|
||||
function getConnectionDisplayName(status: WsConnectionStatus): string {
|
||||
return status.connectionLabel?.trim() || "T3 Server";
|
||||
}
|
||||
@@ -92,70 +90,6 @@ function describeSlowRpcAckToast(requests: ReadonlyArray<SlowRpcAckRequest>): st
|
||||
return `${count} request${count === 1 ? "" : "s"} waiting longer than ${thresholdSeconds}s.`;
|
||||
}
|
||||
|
||||
function buildReconnectToast(
|
||||
status: WsConnectionStatus,
|
||||
nowMs: number,
|
||||
triggerManualReconnect: () => void,
|
||||
) {
|
||||
return stackedThreadToast({
|
||||
actionProps: {
|
||||
children: "Retry now",
|
||||
onClick: triggerManualReconnect,
|
||||
},
|
||||
data: {
|
||||
hideCopyButton: true,
|
||||
},
|
||||
description:
|
||||
status.nextRetryAt === null
|
||||
? `Reconnecting... ${formatReconnectAttemptLabel(status)}`
|
||||
: `Reconnecting in ${formatRetryCountdown(status.nextRetryAt, nowMs)}... ${formatReconnectAttemptLabel(status)}`,
|
||||
timeout: 0,
|
||||
title: buildReconnectTitle(status),
|
||||
type: "loading",
|
||||
});
|
||||
}
|
||||
|
||||
function useReconnectToastCountdown(
|
||||
status: WsConnectionStatus,
|
||||
toastIdRef: RefObject<ThreadToastId | null>,
|
||||
triggerManualReconnect: () => void,
|
||||
) {
|
||||
const nowMsRef = useRef(Date.now());
|
||||
|
||||
useEffect(() => {
|
||||
if (status.reconnectPhase !== "waiting" || status.nextRetryAt === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
const refreshReconnectToast = () => {
|
||||
nowMsRef.current = Date.now();
|
||||
const toastId = toastIdRef.current;
|
||||
if (!toastId) {
|
||||
return;
|
||||
}
|
||||
|
||||
const currentStatus = getWsConnectionStatus();
|
||||
if (getWsConnectionUiState(currentStatus) !== "reconnecting") {
|
||||
return;
|
||||
}
|
||||
|
||||
toastManager.update(
|
||||
toastId,
|
||||
buildReconnectToast(currentStatus, nowMsRef.current, triggerManualReconnect),
|
||||
);
|
||||
};
|
||||
|
||||
refreshReconnectToast();
|
||||
const intervalId = window.setInterval(refreshReconnectToast, 1_000);
|
||||
|
||||
return () => {
|
||||
window.clearInterval(intervalId);
|
||||
};
|
||||
}, [status.nextRetryAt, status.reconnectPhase, toastIdRef, triggerManualReconnect]);
|
||||
|
||||
return nowMsRef;
|
||||
}
|
||||
|
||||
function SlowRpcAckRequestDetails({ requests }: { requests: ReadonlyArray<SlowRpcAckRequest> }) {
|
||||
return (
|
||||
<ul className="space-y-2.5 text-xs text-muted-foreground">
|
||||
@@ -213,8 +147,9 @@ export function shouldRestartStalledReconnect(
|
||||
|
||||
export function WebSocketConnectionCoordinator() {
|
||||
const status = useWsConnectionStatus();
|
||||
const [nowMs, setNowMs] = useState(() => Date.now());
|
||||
const lastForcedReconnectAtRef = useRef(0);
|
||||
const toastIdRef = useRef<ThreadToastId | null>(null);
|
||||
const toastIdRef = useRef<ReturnType<typeof toastManager.add> | null>(null);
|
||||
const toastResetTimerRef = useRef<number | null>(null);
|
||||
const previousUiStateRef = useRef<WsConnectionUiState>(getWsConnectionUiState(status));
|
||||
const previousDisconnectedAtRef = useRef<string | null>(status.disconnectedAt);
|
||||
@@ -265,11 +200,6 @@ export function WebSocketConnectionCoordinator() {
|
||||
|
||||
runReconnect(false);
|
||||
});
|
||||
const reconnectToastNowMsRef = useReconnectToastCountdown(
|
||||
status,
|
||||
toastIdRef,
|
||||
triggerManualReconnect,
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
const handleOnline = () => {
|
||||
@@ -290,6 +220,21 @@ export function WebSocketConnectionCoordinator() {
|
||||
};
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (status.reconnectPhase !== "waiting" || status.nextRetryAt === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
setNowMs(Date.now());
|
||||
const intervalId = window.setInterval(() => {
|
||||
setNowMs(Date.now());
|
||||
}, 1_000);
|
||||
|
||||
return () => {
|
||||
window.clearInterval(intervalId);
|
||||
};
|
||||
}, [status.nextRetryAt, status.reconnectPhase]);
|
||||
|
||||
useEffect(() => {
|
||||
if (
|
||||
status.reconnectPhase !== "waiting" ||
|
||||
@@ -363,7 +308,22 @@ export function WebSocketConnectionCoordinator() {
|
||||
title: buildReconnectTitle(status),
|
||||
type: "error",
|
||||
})
|
||||
: buildReconnectToast(status, reconnectToastNowMsRef.current, triggerManualReconnect);
|
||||
: stackedThreadToast({
|
||||
actionProps: {
|
||||
children: "Retry now",
|
||||
onClick: triggerManualReconnect,
|
||||
},
|
||||
data: {
|
||||
hideCopyButton: true,
|
||||
},
|
||||
description:
|
||||
status.nextRetryAt === null
|
||||
? `Reconnecting... ${formatReconnectAttemptLabel(status)}`
|
||||
: `Reconnecting in ${formatRetryCountdown(status.nextRetryAt, nowMs)}... ${formatReconnectAttemptLabel(status)}`,
|
||||
timeout: 0,
|
||||
title: buildReconnectTitle(status),
|
||||
type: "loading",
|
||||
});
|
||||
|
||||
if (toastIdRef.current) {
|
||||
toastManager.update(toastIdRef.current, toastPayload);
|
||||
@@ -405,7 +365,7 @@ export function WebSocketConnectionCoordinator() {
|
||||
|
||||
previousUiStateRef.current = uiState;
|
||||
previousDisconnectedAtRef.current = status.disconnectedAt;
|
||||
}, [reconnectToastNowMsRef, status]);
|
||||
}, [nowMs, status]);
|
||||
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
|
||||
@@ -99,19 +99,20 @@ export const Route = createRootRouteWithContext<{
|
||||
}),
|
||||
});
|
||||
|
||||
const APP_SHELL = (
|
||||
<CommandPalette>
|
||||
<AppSidebarLayout>
|
||||
<Outlet />
|
||||
</AppSidebarLayout>
|
||||
</CommandPalette>
|
||||
);
|
||||
|
||||
function RootRouteView() {
|
||||
const pathname = useLocation({ select: (location) => location.pathname });
|
||||
const { authGateState } = Route.useRouteContext();
|
||||
const primaryEnvironmentAuthenticated = authGateState.status === "authenticated";
|
||||
|
||||
useEffect(() => {
|
||||
const frame = window.requestAnimationFrame(() => {
|
||||
syncBrowserChromeTheme();
|
||||
});
|
||||
return () => {
|
||||
window.cancelAnimationFrame(frame);
|
||||
};
|
||||
}, [pathname]);
|
||||
useBrowserChromeThemeSync(pathname);
|
||||
|
||||
if (pathname === "/pair") {
|
||||
return <Outlet />;
|
||||
@@ -121,14 +122,6 @@ function RootRouteView() {
|
||||
return <Outlet />;
|
||||
}
|
||||
|
||||
const appShell = (
|
||||
<CommandPalette>
|
||||
<AppSidebarLayout>
|
||||
<Outlet />
|
||||
</AppSidebarLayout>
|
||||
</CommandPalette>
|
||||
);
|
||||
|
||||
return (
|
||||
<ToastProvider>
|
||||
<AnchoredToastProvider>
|
||||
@@ -142,15 +135,26 @@ function RootRouteView() {
|
||||
{primaryEnvironmentAuthenticated ? <WebSocketConnectionCoordinator /> : null}
|
||||
{primaryEnvironmentAuthenticated ? <SlowRpcAckToastCoordinator /> : null}
|
||||
{primaryEnvironmentAuthenticated ? (
|
||||
<WebSocketConnectionSurface>{appShell}</WebSocketConnectionSurface>
|
||||
<WebSocketConnectionSurface>{APP_SHELL}</WebSocketConnectionSurface>
|
||||
) : (
|
||||
appShell
|
||||
APP_SHELL
|
||||
)}
|
||||
</AnchoredToastProvider>
|
||||
</ToastProvider>
|
||||
);
|
||||
}
|
||||
|
||||
function useBrowserChromeThemeSync(pathname: string) {
|
||||
useEffect(() => {
|
||||
const frame = window.requestAnimationFrame(() => {
|
||||
syncBrowserChromeTheme();
|
||||
});
|
||||
return () => {
|
||||
window.cancelAnimationFrame(frame);
|
||||
};
|
||||
}, [pathname]);
|
||||
}
|
||||
|
||||
function HostedStaticEnvironmentBootstrap() {
|
||||
const savedEnvironmentCount = useSavedEnvironmentRegistryStore(
|
||||
(state) => Object.keys(state.byId).length,
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in new issue
Block a user