Skip to content
TypeScript

perf(web): the pull request stack hook compiles without manual memoization (#20620)

Julius Marmingea9c0bb672904
diff --git a/apps/web/src/state/usePullRequestStack.ts b/apps/web/src/state/usePullRequestStack.ts
index a9ee0f10fa7..a34610d4d2f 100644
--- a/apps/web/src/state/usePullRequestStack.ts
+++ b/apps/web/src/state/usePullRequestStack.ts
@@ -1,5 +1,4 @@
import type { EnvironmentId, PullRequestRef } from "@t3tools/contracts";
-import { useMemo } from "react";
import {
savedPullRequestStack,
pullRequestStackView,
@@ -8,23 +7,24 @@ import { useThreadShells } from "./entities";
import { pullRequestStackAtom } from "./pullRequests";
import { useEnvironmentQuery } from "./query";
+function useSavedPullRequestStack(environmentId: EnvironmentId, reference: PullRequestRef | null) {
+ "use memo";
+ const threads = useThreadShells();
+ return reference === null
+ ? null
+ : savedPullRequestStack(
+ threads
+ .filter((thread) => thread.environmentId === environmentId)
+ .flatMap((thread) => thread.pullRequests ?? []),
+ reference,
+ );
+}
+
export function usePullRequestStack(
environmentId: EnvironmentId,
reference: PullRequestRef | null,
) {
- const threads = useThreadShells();
- const saved = useMemo(
- () =>
- reference === null
- ? null
- : savedPullRequestStack(
- threads
- .filter((thread) => thread.environmentId === environmentId)
- .flatMap((thread) => thread.pullRequests ?? []),
- reference,
- ),
- [environmentId, reference, threads],
- );
+ const saved = useSavedPullRequestStack(environmentId, reference);
const query = useEnvironmentQuery(
reference === null ? null : pullRequestStackAtom({ environmentId, input: reference }),
);