TypeScript
fix(web): PR links at launch open the PR view with the local environment disabled (#26099)
NotAnNvidiaFancbd43b63d209
diff --git a/apps/web/src/components/desktop/DesktopWebLinkCoordinator.browser.test.tsx b/apps/web/src/components/desktop/DesktopWebLinkCoordinator.browser.test.tsxindex 31ad2028c5f..1f901a5eae1 100644--- a/apps/web/src/components/desktop/DesktopWebLinkCoordinator.browser.test.tsx+++ b/apps/web/src/components/desktop/DesktopWebLinkCoordinator.browser.test.tsx@@ -329,9 +329,21 @@ it("pairs with Local environment disabled, where there is no primary environment);});-it("does not hold a PR link for project discovery that never settles with Local environment disabled", async () => {+it("holds a launch PR link with Local environment disabled until discovery settles", async () => {setup();state.localEnvironmentDisabled = true;await using _coordinator = await mount(pullRequestUrl);- await vi.waitFor(() => expect(state.openScratchProject).toHaveBeenCalledOnce());+ expect(state.navigate).not.toHaveBeenCalled();+ expect(state.openScratchProject).not.toHaveBeenCalled();++ state.projects = [project];+ const navigated = new Promise<void>((resolve) => {+ state.navigate.mockImplementationOnce(async () => resolve());+ });+ await act(async () => {+ appAtomRegistry.set(discoverySettled, true);+ await navigated;+ });+ expect(state.navigate).toHaveBeenCalledExactlyOnceWith(pullRequestView);+ expect(state.openScratchProject).not.toHaveBeenCalled();});diff --git a/apps/web/src/components/desktop/DesktopWebLinkCoordinator.tsx b/apps/web/src/components/desktop/DesktopWebLinkCoordinator.tsxindex ddd892d02bd..b138a8232bd 100644--- a/apps/web/src/components/desktop/DesktopWebLinkCoordinator.tsx+++ b/apps/web/src/components/desktop/DesktopWebLinkCoordinator.tsx@@ -237,10 +237,8 @@ export function DesktopWebLinkCoordinator() {// A connected server publishes its config before its project snapshot, so a source control// link delivered at launch would miss its project and fall through to the browser. Hold// those links until discovery settles; an ordinary link never waits for it.- // Discovery never settles without the local environment, so those links do not wait.const hold =openPullRequestsInApp &&- !localEnvironmentDisabled &&(sourceControlClients.parseChangeRequestUrl(url) !== null ||sourceControlClients.parseCommitUrl(url) !== null)? projectsSettled()diff --git a/apps/web/src/state/shell.test.ts b/apps/web/src/state/shell.test.tsindex 4d5920a94ad..19a88cfbb19 100644--- a/apps/web/src/state/shell.test.ts+++ b/apps/web/src/state/shell.test.ts@@ -7,9 +7,9 @@ import { EMPTY_SHELL_STATE, type EnvironmentShellState } from "@t3tools/client-rimport { EnvironmentId } from "@t3tools/contracts";import * as Option from "effect/Option";import { Atom, AtomRegistry } from "effect/reactivity";-import { describe, expect, it } from "vite-plus/test";+import { describe, expect, it, vi } from "vite-plus/test";-import { createAllEnvironmentProjectSnapshotsReadyAtom } from "./shell";+import { createAllEnvironmentProjectSnapshotsReadyAtom, expectsPrimaryEnvironment } from "./shell";const LOCAL = EnvironmentId.make("local");const REMOTE = EnvironmentId.make("remote");@@ -135,3 +135,16 @@ describe("project snapshot readiness", () => {registry.dispose();});});++it("expects a primary environment only on desktops with the local environment enabled", () => {+ const desktop = (enabled: boolean) => {+ vi.stubGlobal("window", { desktopBridge: { getLocalEnvironmentEnabled: () => enabled } });+ try {+ return expectsPrimaryEnvironment();+ } finally {+ vi.unstubAllGlobals();+ }+ };+ expect(desktop(true)).toBe(true);+ expect(desktop(false)).toBe(false);+});diff --git a/apps/web/src/state/shell.ts b/apps/web/src/state/shell.tsindex c4675d3d013..f88368b3702 100644--- a/apps/web/src/state/shell.ts+++ b/apps/web/src/state/shell.ts@@ -21,6 +21,7 @@ import { AsyncResult, Atom } from "effect/reactivity";import { environmentCatalog } from "../connection/catalog";import { connectionAtomRuntime } from "../connection/runtime";import { isHostedStaticApp } from "../hostedPairing";+import { isLocalEnvironmentDisabled } from "../localEnvironment";export const shellEnvironment = createShellEnvironmentAtoms(connectionAtomRuntime);export const environmentShell = createEnvironmentShellAtoms(connectionAtomRuntime);@@ -126,9 +127,14 @@ export const allEnvironmentProjectSnapshotsReadyAtom =requiresPrimaryEnvironment: !isHostedStaticApp(),});+/** Hosted clients and desktops with the local environment disabled never discover a primary. */+export function expectsPrimaryEnvironment(): boolean {+ return !isHostedStaticApp() && !isLocalEnvironmentDisabled();+}+export const allReachableShellsLiveAtom = Atom.make((get) => {const catalog = get(environmentCatalog.catalogValueAtom);- if (!catalogIsComplete(catalog, !isHostedStaticApp())) return false;+ if (!catalogIsComplete(catalog, expectsPrimaryEnvironment())) return false;for (const environmentId of enabledEnvironmentIds(catalog)) {const shell = get(environmentShell.stateValueAtom(environmentId));if (shell.status === "live" && Option.isSome(shell.snapshot)) continue;