mirror of
https://github.com/getpaseo/paseo.git
synced 2026-07-29 12:01:31 +00:00
fix(app): latch startup store readiness
This commit is contained in:
@@ -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 }),
|
||||
|
||||
22
packages/app/src/hooks/use-latched-boolean.test.tsx
Normal file
22
packages/app/src/hooks/use-latched-boolean.test.tsx
Normal 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);
|
||||
});
|
||||
});
|
||||
13
packages/app/src/hooks/use-latched-boolean.ts
Normal file
13
packages/app/src/hooks/use-latched-boolean.ts
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user