Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

thread-route-hydration.ts

43 lines1.5 KB

1import type { EnvironmentConnectionPhase } from "@t3tools/client-runtime/connection";
2import type { EnvironmentShellStatus } from "@t3tools/client-runtime/state/shell";
3import type { EnvironmentThreadStatus } from "@t3tools/client-runtime/state/threads";
4​
5export function threadRouteIsHydrating(input: {
6 readonly isLoadingConnections: boolean;
7 readonly environmentRegistered: boolean;
8 readonly localCacheRead: boolean;
9 readonly connectionState: EnvironmentConnectionPhase;
10 readonly shellStatus: EnvironmentShellStatus;
11 readonly shellHasError: boolean;
12 readonly detailStatus: EnvironmentThreadStatus;
13 readonly detailHasError: boolean;
14}): boolean {
15 if (input.detailStatus === "deleted" || input.shellHasError || input.detailHasError) {
16 return false;
17 }
18 if (input.isLoadingConnections) {
19 return true;
20 }
21 if (!input.environmentRegistered) {
22 return false;
23 }
24 if (!input.localCacheRead) {
25 return true;
26 }
27 // Only a first attempt is worth waiting out; a reconnecting environment has already failed.
28 if (
29 input.connectionState === "available" ||
30 input.connectionState === "offline" ||
31 input.connectionState === "reconnecting" ||
32 input.connectionState === "error"
33 ) {
34 return false;
35 }
36 return (
37 input.connectionState === "connecting" ||
38 input.shellStatus === "synchronizing" ||
39 (input.connectionState === "connected" && input.shellStatus === "empty") ||
40 input.detailStatus === "synchronizing" ||
41 (input.connectionState === "connected" && input.detailStatus === "empty")
42 );