Skip to content

Commit 1c3d5f7

Browse files
fix(web): a link to a thread on a linked machine no longer opens a blank pane (pingdotgg#34657)
1 parent cd8fc91 commit 1c3d5f7

2 files changed

Lines changed: 31 additions & 2 deletions

File tree

‎apps/web/src/components/chat/MarkdownThreadLink.browser.test.tsx‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ vi.mock(import("../../state/entities"), () => ({
2121
useProject: (ref: { projectId: string } | null) =>
2222
ref?.projectId === "essay-project" ? ({ title: "Essays" } as never) : null,
2323
}));
24+
vi.mock(import("../../state/environments"), () => ({
25+
useEnvironmentIdentities: () => [
26+
{ environmentId: EnvironmentId.make("environment"), label: "Here" },
27+
{ environmentId: EnvironmentId.make("remote"), label: "Remote" },
28+
],
29+
}));
2430
vi.mock(import("../ProjectFavicon"), () => ({
2531
ProjectFavicon: () => (
2632
<span role="img" aria-label="Essays project icon">
@@ -132,3 +138,21 @@ it.each([
132138
}
133139
},
134140
);
141+
142+
it("names a thread on a machine this client has no connection to, without waiting on it", async () => {
143+
const { registry } = setup();
144+
using _registry = { [Symbol.dispose]: () => registry.dispose() };
145+
await using screen = await render(
146+
<RegistryContext value={registry}>
147+
<MarkdownThreadLink
148+
environmentId={EnvironmentId.make("environment")}
149+
link={{ environmentId: EnvironmentId.make("peer"), threadId: ThreadId.make("peer-thread") }}
150+
label={null}
151+
/>
152+
</RegistryContext>,
153+
);
154+
await expect
155+
.element(screen.getByText("Thread on another machine", { exact: true }))
156+
.toBeVisible();
157+
await expect.element(screen.getByRole("link")).not.toBeInTheDocument();
158+
});

‎apps/web/src/components/chat/MarkdownThreadLink.tsx‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99

1010
import { configuredHostedAppUrl } from "../../hostedPairing";
1111
import { useThreadRefs, useThreadShell } from "../../state/entities";
12+
import { useEnvironmentIdentities } from "../../state/environments";
1213
import { orchestrationEnvironment } from "../../state/orchestration";
1314
import { useEnvironmentQuery } from "../../state/query";
1415
import { UnresolvedChip } from "../contextChipParts";
@@ -23,8 +24,12 @@ export function MarkdownThreadLink(props: {
2324
const candidates = threadLinkCandidates(props.link, props.environmentId);
2425
const writtenRef = candidates[0]!;
2526
const written = useThreadShell(writtenRef);
27+
// A linked machine's threads are reachable only through its server, not from this client.
28+
const reachable = useEnvironmentIdentities().some(
29+
(environment) => environment.environmentId === writtenRef.environmentId,
30+
);
2631
const lookup = useEnvironmentQuery(
27-
written === null
32+
written === null && reachable
2833
? orchestrationEnvironment.threadLinkMetadata({
2934
environmentId: writtenRef.environmentId,
3035
input: { threadIds: candidates.map((ref) => ref.threadId) },
@@ -39,7 +44,7 @@ export function MarkdownThreadLink(props: {
3944
const metadata = lookup.data?.[ref.threadId];
4045
return metadata ? [{ ref, metadata }] : [];
4146
})[0] ?? null);
42-
const missing = target === null && settled;
47+
const missing = target === null && (settled || !reachable);
4348
const guess = missing && props.link.environmentId === null;
4449
const refs = useThreadRefs(guess);
4550
const remoteRef = guess

0 commit comments

Comments
 (0)