The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 23, 05:30 UTC
refactor(web): linked pull request status keeps its caching without "use memo" hooks (#20781)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Oct 16, 2026 at 23:30 UTC
bcd3c12f4683effe78a580ac9c271d104a85c975
2 files changed
+15
-31
apps/web/src/components/ThreadStatusIndicators.tsx
+7
-21
@@ -95,11 +95,14 @@ export function useLinkedThreadPullRequest(
95
branchPullRequest?: ThreadLinkedPullRequest | null,
96
): LinkedThreadPullRequestStatus | null {
97
const supportsLinks = useSupportsMultiplePullRequests(environmentId);
98
- const { current, currentStatus } = useCurrentPullRequestLink(supportsLinks, pullRequests);
98
+ const current = supportsLinks ? resolveThreadCurrentPullRequestLink(pullRequests ?? []) : null;
99
+ // Callers key on the returned status, so it stays cached across the query hooks.
100
+ const currentStatus = current === null ? null : linkedPullRequestSnapshotStatus(current);
101
const fallback =
102
current === null ? ((!supportsLinks ? linkedPullRequest : null) ?? branchPullRequest) : null;
101
- // A sidebar row must not touch the summary cache on every render.
102
- const reference = useLinkedPullRequestReference(fallback);
103
+ // The query atom and shared summary effect key on this object, and a sidebar row
104
+ // must not touch the summary cache on every render.
105
+ const reference = fallback == null ? null : linkedPullRequestReference(fallback);
106
const queried = useEnvironmentQuery(
107
!enabled || environmentId === null || reference === null
108
? null
@@ -121,24 +124,7 @@ export function useLinkedThreadPullRequest(
124
};
125
}
126
124
-// Callers key on the returned status, so it stays stable across the query hooks.
125
-function useCurrentPullRequestLink(
126
- supportsLinks: boolean,
127
- pullRequests: ReadonlyArray<ThreadPullRequestLink> | undefined,
128
-) {
129
- "use memo";
130
- const current = supportsLinks ? resolveThreadCurrentPullRequestLink(pullRequests ?? []) : null;
131
- return {
132
- current,
133
- currentStatus: current === null ? null : linkedPullRequestSnapshotStatus(current),
134
- };
135
-}
136
-
137
-// The query atom and shared summary effect key on this object, so it stays
138
-// stable per link across the hooks that read it.
139
-function useLinkedPullRequestReference(fallback: ThreadLinkedPullRequest | null | undefined) {
140
- "use memo";
141
- if (fallback == null) return null;
127
+function linkedPullRequestReference(fallback: ThreadLinkedPullRequest) {
128
const host = parseChangeRequestUrl(fallback.url)?.host;
129
return { ...fallback, ...(host === undefined ? {} : { host }) };
130
}
apps/web/src/state/pullRequests.ts
+8
-10
@@ -137,12 +137,11 @@ export function newestPullRequestObservation(
137
}
138
139
function observePullRequestSummary(
140
- environmentId: EnvironmentId,
141
- reference: PullRequestRef,
140
+ key: string,
141
summary: PullRequestSummary,
142
observedAt: number,
143
): void {
145
- const atom = observedPullRequestSummaryAtom(pullRequestSummaryKey(environmentId, reference));
144
+ const atom = observedPullRequestSummaryAtom(key);
145
appAtomRegistry.modify(atom, (previous) => {
146
const next = newestPullRequestObservation(previous, { summary, observedAt });
147
return next === previous ? [false, previous] : [true, next];
@@ -216,11 +215,11 @@ export function useSharedPullRequestSummary(
215
: savedPullRequestKey(environmentId, reference),
216
),
217
);
218
+ // Keyed structurally so a fresh reference object for the same pull request is a no-op.
219
useLayoutEffect(() => {
220
- if (environmentId === null || reference === null || current === null || observedAt === null)
221
- return;
222
- observePullRequestSummary(environmentId, reference, current, observedAt);
223
- }, [current, environmentId, reference, observedAt]);
220
+ if (key === "none" || current === null || observedAt === null) return;
221
+ observePullRequestSummary(key, current, observedAt);
222
+ }, [current, key, observedAt]);
223
const summary =
224
newestPullRequestObservation(
225
observed,
@@ -343,13 +342,12 @@ export function usePullRequestList(
342
for (const [environmentId, answer, observedAt] of query.observations) {
343
for (const entry of answer.entries) {
344
observePullRequestSummary(
346
- environmentId,
347
- {
345
+ pullRequestSummaryKey(environmentId, {
346
projectId: entry.projectId,
347
host: entry.host,
348
repository: entry.repository,
349
number: entry.number,
352
- },
350
+ }),
351
pullRequestListEntryToSummary(entry),
352
observedAt,
353
);