fix(app): latch startup store readiness

This commit is contained in:
Mohamed Boudra
2026-05-03 20:15:19 +07:00
parent 6d13796b2d
commit ade05607d2
3 changed files with 38 additions and 1 deletions

View File

@@ -60,6 +60,7 @@ import { UpdateCalloutSource } from "@/desktop/updates/update-callout-source";
import { useActiveWorktreeNewAction } from "@/hooks/use-active-worktree-new-action";
import { useFaviconStatus } from "@/hooks/use-favicon-status";
import { useKeyboardShortcuts } from "@/hooks/use-keyboard-shortcuts";
import { useLatchedBoolean } from "@/hooks/use-latched-boolean";
import { useOpenProject } from "@/hooks/use-open-project";
import { useAppSettings } from "@/hooks/use-settings";
import { useStableEvent } from "@/hooks/use-stable-event";
@@ -349,8 +350,9 @@ function HostRuntimeBootstrapProvider({ children }: { children: ReactNode }) {
}, []);
const splashError = !anyOnlineHostServerId ? daemonStartError : null;
const storeReady =
const isCurrentlyStoreReady =
Boolean(anyOnlineHostServerId) || Boolean(splashError) || hasGivenUpWaitingForHost;
const storeReady = useLatchedBoolean(isCurrentlyStoreReady);
const state = useMemo<HostRuntimeBootstrapState>(
() => ({ splashError, retry, hasGivenUpWaitingForHost, storeReady }),

View File

@@ -0,0 +1,22 @@
/**
* @vitest-environment jsdom
*/
import { renderHook } from "@testing-library/react";
import { describe, expect, it } from "vitest";
import { useLatchedBoolean } from "./use-latched-boolean";
describe("useLatchedBoolean", () => {
it("stays true after the input first becomes true", () => {
const { result, rerender } = renderHook(({ value }) => useLatchedBoolean(value), {
initialProps: { value: false },
});
expect(result.current).toBe(false);
rerender({ value: true });
expect(result.current).toBe(true);
rerender({ value: false });
expect(result.current).toBe(true);
});
});

View File

@@ -0,0 +1,13 @@
import { useEffect, useState } from "react";
export function useLatchedBoolean(value: boolean): boolean {
const [hasLatched, setHasLatched] = useState(value);
useEffect(() => {
if (value) {
setHasLatched(true);
}
}, [value]);
return hasLatched || value;
}