Skip to content

Commit cbd43b6

Browse files
fix(web): PR links at launch open the PR view with the local environment disabled (pingdotgg#26099)
1 parent dcd9adc commit cbd43b6

4 files changed

Lines changed: 36 additions & 7 deletions

File tree

‎apps/web/src/components/desktop/DesktopWebLinkCoordinator.browser.test.tsx‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,9 +329,21 @@ it("pairs with Local environment disabled, where there is no primary environment
329329
);
330330
});
331331

332-
it("does not hold a PR link for project discovery that never settles with Local environment disabled", async () => {
332+
it("holds a launch PR link with Local environment disabled until discovery settles", async () => {
333333
setup();
334334
state.localEnvironmentDisabled = true;
335335
await using _coordinator = await mount(pullRequestUrl);
336-
await vi.waitFor(() => expect(state.openScratchProject).toHaveBeenCalledOnce());
336+
expect(state.navigate).not.toHaveBeenCalled();
337+
expect(state.openScratchProject).not.toHaveBeenCalled();
338+
339+
state.projects = [project];
340+
const navigated = new Promise<void>((resolve) => {
341+
state.navigate.mockImplementationOnce(async () => resolve());
342+
});
343+
await act(async () => {
344+
appAtomRegistry.set(discoverySettled, true);
345+
await navigated;
346+
});
347+
expect(state.navigate).toHaveBeenCalledExactlyOnceWith(pullRequestView);
348+
expect(state.openScratchProject).not.toHaveBeenCalled();
337349
});

‎apps/web/src/components/desktop/DesktopWebLinkCoordinator.tsx‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,10 +237,8 @@ export function DesktopWebLinkCoordinator() {
237237
// A connected server publishes its config before its project snapshot, so a source control
238238
// link delivered at launch would miss its project and fall through to the browser. Hold
239239
// those links until discovery settles; an ordinary link never waits for it.
240-
// Discovery never settles without the local environment, so those links do not wait.
241240
const hold =
242241
openPullRequestsInApp &&
243-
!localEnvironmentDisabled &&
244242
(sourceControlClients.parseChangeRequestUrl(url) !== null ||
245243
sourceControlClients.parseCommitUrl(url) !== null)
246244
? projectsSettled()

‎apps/web/src/state/shell.test.ts‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import { EMPTY_SHELL_STATE, type EnvironmentShellState } from "@t3tools/client-r
77
import { EnvironmentId } from "@t3tools/contracts";
88
import * as Option from "effect/Option";
99
import { Atom, AtomRegistry } from "effect/reactivity";
10-
import { describe, expect, it } from "vite-plus/test";
10+
import { describe, expect, it, vi } from "vite-plus/test";
1111

12-
import { createAllEnvironmentProjectSnapshotsReadyAtom } from "./shell";
12+
import { createAllEnvironmentProjectSnapshotsReadyAtom, expectsPrimaryEnvironment } from "./shell";
1313

1414
const LOCAL = EnvironmentId.make("local");
1515
const REMOTE = EnvironmentId.make("remote");
@@ -135,3 +135,16 @@ describe("project snapshot readiness", () => {
135135
registry.dispose();
136136
});
137137
});
138+
139+
it("expects a primary environment only on desktops with the local environment enabled", () => {
140+
const desktop = (enabled: boolean) => {
141+
vi.stubGlobal("window", { desktopBridge: { getLocalEnvironmentEnabled: () => enabled } });
142+
try {
143+
return expectsPrimaryEnvironment();
144+
} finally {
145+
vi.unstubAllGlobals();
146+
}
147+
};
148+
expect(desktop(true)).toBe(true);
149+
expect(desktop(false)).toBe(false);
150+
});

‎apps/web/src/state/shell.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { AsyncResult, Atom } from "effect/reactivity";
2121
import { environmentCatalog } from "../connection/catalog";
2222
import { connectionAtomRuntime } from "../connection/runtime";
2323
import { isHostedStaticApp } from "../hostedPairing";
24+
import { isLocalEnvironmentDisabled } from "../localEnvironment";
2425

2526
export const shellEnvironment = createShellEnvironmentAtoms(connectionAtomRuntime);
2627
export const environmentShell = createEnvironmentShellAtoms(connectionAtomRuntime);
@@ -126,9 +127,14 @@ export const allEnvironmentProjectSnapshotsReadyAtom =
126127
requiresPrimaryEnvironment: !isHostedStaticApp(),
127128
});
128129

130+
/** Hosted clients and desktops with the local environment disabled never discover a primary. */
131+
export function expectsPrimaryEnvironment(): boolean {
132+
return !isHostedStaticApp() && !isLocalEnvironmentDisabled();
133+
}
134+
129135
export const allReachableShellsLiveAtom = Atom.make((get) => {
130136
const catalog = get(environmentCatalog.catalogValueAtom);
131-
if (!catalogIsComplete(catalog, !isHostedStaticApp())) return false;
137+
if (!catalogIsComplete(catalog, expectsPrimaryEnvironment())) return false;
132138
for (const environmentId of enabledEnvironmentIds(catalog)) {
133139
const shell = get(environmentShell.stateValueAtom(environmentId));
134140
if (shell.status === "live" && Option.isSome(shell.snapshot)) continue;

0 commit comments

Comments
 (0)