Merge pull request #2139 from Dokploy/1541-register-login-screen-fails-on-chrome

1541 register login screen fails on chrome
This commit is contained in:
Mauricio Siu
2025-07-05 17:07:51 -06:00
committed by GitHub

View File

@@ -30,12 +30,41 @@ const getWsUrl = () => {
return `${protocol}${host}/drawer-logs`;
};
const wsClient =
typeof window !== "undefined"
? createWSClient({
url: getWsUrl() || "",
})
: null;
// Create WebSocket client with delayed connection
const createLazyWSClient = () => {
if (typeof window === "undefined") return null;
let actualClient: ReturnType<typeof createWSClient> | null = null;
return {
request: (op: any, callbacks: any) => {
if (!actualClient) {
const wsUrl = getWsUrl();
if (wsUrl) {
actualClient = createWSClient({ url: wsUrl });
}
}
return actualClient?.request(op, callbacks) || (() => {});
},
close: () => {
if (actualClient) {
actualClient.close();
actualClient = null;
}
},
getConnection: () => {
if (!actualClient) {
const wsUrl = getWsUrl();
if (wsUrl) {
actualClient = createWSClient({ url: wsUrl });
}
}
return actualClient!.getConnection();
},
};
};
const wsClient = createLazyWSClient();
/** A set of type-safe react-query hooks for your tRPC API. */
export const api = createTRPCNext<AppRouter>({