Skip to content

Commit 6685a16

Browse files
fix(web): pull request links settle when the local environment is disabled
Pull request links wait for every reachable environment to report its projects. That wait required a primary environment unless the app was hosted, so on a desktop with the local environment disabled it never settled and the link never opened.
1 parent 5df4320 commit 6685a16

2 files changed

Lines changed: 22 additions & 3 deletions

File tree

‎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)