Skip to content

Commit fc25392

Browse files
committed
fix(web): hover cards read their own preview query so clicks keep main's behavior
1 parent 78a5aff commit fc25392

2 files changed

Lines changed: 21 additions & 12 deletions

File tree

‎apps/web/src/components/pullRequest/PullRequestLinkPreview.tsx‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313

1414
import { RelativeTime } from "~/components/RelativeTime";
1515
import { pullRequestEnvironment } from "~/state/pullRequests";
16-
import { useAtomCommand } from "~/state/use-atom-command";
16+
import { useAtomQueryRunner } from "~/state/use-atom-query-runner";
1717
import { useEnvironmentQuery } from "~/state/query";
1818

1919
import { PreviewCard, PreviewCardPopup, PreviewCardTrigger } from "../ui/preview-card";
@@ -51,13 +51,13 @@ export function PullRequestLinkPreview({
5151
const [resolvingClick, setResolvingClick] = useState(false);
5252
const previewQuery = useEnvironmentQuery(
5353
open
54-
? pullRequestEnvironment.preview({
54+
? pullRequestEnvironment.previewCard({
5555
environmentId: target.environmentId,
5656
input: target.input,
5757
})
5858
: null,
5959
);
60-
const readPreview = useAtomCommand(pullRequestEnvironment.resolvePreview, {
60+
const readPreview = useAtomQueryRunner(pullRequestEnvironment.preview, {
6161
reportFailure: false,
6262
reportDefect: false,
6363
});

‎packages/client-runtime/src/state/pullRequests.ts‎

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,18 @@ export function createPullRequestEnvironmentAtoms<R, E>(
205205
refreshTrigger: ({ environmentId }) => refreshes({ environmentId, input: {} }),
206206
}),
207207
);
208+
// Hover cards read their own atoms, so a pending or failed hover read never decides where a
209+
// click on the same link goes.
210+
const previewCard = writableQueryFamily(
211+
createEnvironmentRpcQueryAtomFamily(runtime, {
212+
label: "environment-data:pull-requests:preview-card",
213+
persistence: persistQuery(PullRequestPreview),
214+
tag: WS_METHODS.pullRequestsPreview,
215+
execute: (input) => routedRequest(WS_METHODS.pullRequestsPreview, input),
216+
staleTimeMs: 60_000,
217+
refreshTrigger: ({ environmentId }) => refreshes({ environmentId, input: {} }),
218+
}),
219+
);
208220
const labelCandidates = writableQueryFamily(
209221
createEnvironmentRpcQueryAtomFamily(runtime, {
210222
label: "environment-data:pull-requests:label-candidates",
@@ -319,14 +331,7 @@ export function createPullRequestEnvironmentAtoms<R, E>(
319331
}),
320332
detail,
321333
preview,
322-
// Its own request per click: a pending or failed hover read of `preview` must not decide where
323-
// a click goes.
324-
resolvePreview: createEnvironmentRpcCommand(runtime, {
325-
label: "environment-data:pull-requests:resolve-preview",
326-
tag: WS_METHODS.pullRequestsPreview,
327-
execute: (input) => routedRequest(WS_METHODS.pullRequestsPreview, input),
328-
scheduler: commandScheduler,
329-
}),
334+
previewCard,
330335
checks: createEnvironmentRpcQueryAtomFamily(runtime, {
331336
label: "environment-data:pull-requests:checks",
332337
persistence: persistQuery(Schema.NullOr(PullRequestChecks)),
@@ -411,7 +416,10 @@ export function createPullRequestEnvironmentAtoms<R, E>(
411416
// every preceding action, and preparing outside the lane could reorder the clicks.
412417
execute: runAction,
413418
onSuccess: ({ environmentId, input }, registry) =>
414-
Effect.sync(() => registry.refresh(preview({ environmentId, input }))),
419+
Effect.sync(() => {
420+
registry.refresh(preview({ environmentId, input }));
421+
registry.refresh(previewCard({ environmentId, input }));
422+
}),
415423
scheduler: commandScheduler,
416424
concurrency: serialPerEnvironment,
417425
}),
@@ -609,6 +617,7 @@ export function createPullRequestEnvironmentAtoms<R, E>(
609617
Effect.sync(() => {
610618
if (input.reference !== undefined) {
611619
registry.refresh(preview({ environmentId, input: input.reference }));
620+
registry.refresh(previewCard({ environmentId, input: input.reference }));
612621
}
613622
}),
614623
scheduler: commandScheduler,

0 commit comments

Comments
 (0)