Fix startup workspace restore (#1111)
This commit is contained in:
@@ -8,7 +8,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|||||||
import type { HostRuntimeBootstrapState } from "./_layout";
|
import type { HostRuntimeBootstrapState } from "./_layout";
|
||||||
import type { ActiveWorkspaceSelection } from "@/stores/navigation-active-workspace-store";
|
import type { ActiveWorkspaceSelection } from "@/stores/navigation-active-workspace-store";
|
||||||
|
|
||||||
const { navigateToWorkspaceMock, redirectMock, state } = vi.hoisted(() => {
|
const { redirectMock, state } = vi.hoisted(() => {
|
||||||
const hoistedState = {
|
const hoistedState = {
|
||||||
pathname: "/",
|
pathname: "/",
|
||||||
bootstrapState: {
|
bootstrapState: {
|
||||||
@@ -23,7 +23,6 @@ const { navigateToWorkspaceMock, redirectMock, state } = vi.hoisted(() => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
navigateToWorkspaceMock: vi.fn(),
|
|
||||||
redirectMock: vi.fn(),
|
redirectMock: vi.fn(),
|
||||||
state: hoistedState,
|
state: hoistedState,
|
||||||
};
|
};
|
||||||
@@ -51,7 +50,6 @@ vi.mock("@/screens/startup-splash-screen", () => ({
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
vi.mock("@/stores/navigation-active-workspace-store", () => ({
|
vi.mock("@/stores/navigation-active-workspace-store", () => ({
|
||||||
navigateToWorkspace: navigateToWorkspaceMock,
|
|
||||||
useIsLastWorkspaceSelectionHydrated: () => state.isWorkspaceSelectionLoaded,
|
useIsLastWorkspaceSelectionHydrated: () => state.isWorkspaceSelectionLoaded,
|
||||||
useLastWorkspaceSelection: () => state.workspaceSelection,
|
useLastWorkspaceSelection: () => state.workspaceSelection,
|
||||||
}));
|
}));
|
||||||
@@ -72,7 +70,6 @@ describe("Index route startup navigation", () => {
|
|||||||
state.anyOnlineHostServerId = null;
|
state.anyOnlineHostServerId = null;
|
||||||
state.isWorkspaceSelectionLoaded = true;
|
state.isWorkspaceSelectionLoaded = true;
|
||||||
state.workspaceSelection = null;
|
state.workspaceSelection = null;
|
||||||
navigateToWorkspaceMock.mockReset();
|
|
||||||
redirectMock.mockReset();
|
redirectMock.mockReset();
|
||||||
|
|
||||||
container = document.createElement("div");
|
container = document.createElement("div");
|
||||||
@@ -108,7 +105,6 @@ describe("Index route startup navigation", () => {
|
|||||||
await renderIndex();
|
await renderIndex();
|
||||||
|
|
||||||
expect(container.querySelector("[data-testid='startup-splash']")).not.toBeNull();
|
expect(container.querySelector("[data-testid='startup-splash']")).not.toBeNull();
|
||||||
expect(navigateToWorkspaceMock).not.toHaveBeenCalled();
|
|
||||||
expect(redirectMock).not.toHaveBeenCalled();
|
expect(redirectMock).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -118,11 +114,8 @@ describe("Index route startup navigation", () => {
|
|||||||
|
|
||||||
await renderIndex();
|
await renderIndex();
|
||||||
|
|
||||||
expect(navigateToWorkspaceMock).toHaveBeenCalledWith("server-1", "workspace-a", {
|
expect(redirectMock).toHaveBeenCalledWith("/h/server-1/workspace/workspace-a");
|
||||||
currentPathname: "/",
|
expect(container.querySelector("[data-testid='redirect']")).not.toBeNull();
|
||||||
});
|
|
||||||
expect(redirectMock).not.toHaveBeenCalled();
|
|
||||||
expect(container.querySelector("[data-testid='startup-splash']")).not.toBeNull();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("restores the persisted workspace even when the first online host is different", async () => {
|
it("restores the persisted workspace even when the first online host is different", async () => {
|
||||||
@@ -131,10 +124,7 @@ describe("Index route startup navigation", () => {
|
|||||||
|
|
||||||
await renderIndex();
|
await renderIndex();
|
||||||
|
|
||||||
expect(navigateToWorkspaceMock).toHaveBeenCalledWith("server-1", "workspace-a", {
|
expect(redirectMock).toHaveBeenCalledWith("/h/server-1/workspace/workspace-a");
|
||||||
currentPathname: "/",
|
|
||||||
});
|
|
||||||
expect(redirectMock).not.toHaveBeenCalled();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("navigates to the host root when no persisted workspace exists", async () => {
|
it("navigates to the host root when no persisted workspace exists", async () => {
|
||||||
|
|||||||
@@ -7,11 +7,11 @@ import {
|
|||||||
resolveStartupWorkspaceSelection,
|
resolveStartupWorkspaceSelection,
|
||||||
} from "@/app/host-runtime-bootstrap";
|
} from "@/app/host-runtime-bootstrap";
|
||||||
import {
|
import {
|
||||||
navigateToWorkspace,
|
|
||||||
useIsLastWorkspaceSelectionHydrated,
|
useIsLastWorkspaceSelectionHydrated,
|
||||||
useLastWorkspaceSelection,
|
useLastWorkspaceSelection,
|
||||||
} from "@/stores/navigation-active-workspace-store";
|
} from "@/stores/navigation-active-workspace-store";
|
||||||
import { shouldUseDesktopDaemon } from "@/desktop/daemon/desktop-daemon";
|
import { shouldUseDesktopDaemon } from "@/desktop/daemon/desktop-daemon";
|
||||||
|
import { buildHostWorkspaceRoute } from "@/utils/host-routes";
|
||||||
|
|
||||||
const isDesktop = shouldUseDesktopDaemon();
|
const isDesktop = shouldUseDesktopDaemon();
|
||||||
|
|
||||||
@@ -37,17 +37,15 @@ export default function Index() {
|
|||||||
hasGivenUpWaitingForHost: bootstrapState.hasGivenUpWaitingForHost,
|
hasGivenUpWaitingForHost: bootstrapState.hasGivenUpWaitingForHost,
|
||||||
});
|
});
|
||||||
|
|
||||||
React.useEffect(() => {
|
|
||||||
if (!startupWorkspaceSelection) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
navigateToWorkspace(startupWorkspaceSelection.serverId, startupWorkspaceSelection.workspaceId, {
|
|
||||||
currentPathname: pathname,
|
|
||||||
});
|
|
||||||
}, [pathname, startupWorkspaceSelection]);
|
|
||||||
|
|
||||||
if (startupWorkspaceSelection) {
|
if (startupWorkspaceSelection) {
|
||||||
return <StartupSplashScreen bootstrapState={isDesktop ? bootstrapState : undefined} />;
|
return (
|
||||||
|
<Redirect
|
||||||
|
href={buildHostWorkspaceRoute(
|
||||||
|
startupWorkspaceSelection.serverId,
|
||||||
|
startupWorkspaceSelection.workspaceId,
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (redirectRoute) {
|
if (redirectRoute) {
|
||||||
|
|||||||
Reference in New Issue
Block a user