@devries-cameron20 / t3code Mirror · read-only / commits / 2fbd4318fc
Fork 0

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

chore(web): lint rejects "use memo" directives (#20843)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Julius Marminge committed Oct 17, 2026 at 01:03 UTC 2fbd4318fc5b610c3e7fcfcbd5bbd80b73521d8f
4 files changed +31 -5
apps/web/src/components/CommandPalette.tsx
+9 -3
@@ -366,13 +366,15 @@ function notifyThemeSaveFailure(): void {
366 );
367 }
368
369 -// Kept as "use memo" hooks: inlined, each result reaches the dialog's returned
370 -// <CommandPaletteContent> through the action and thread item arrays built after
371 -// the browse hooks, and the compiler leaves all of them uncached.
369 +// These helpers keep "use memo" until the palette's item building moves out of this
370 +// component: inlined, each result reaches the returned <CommandPaletteContent> through
371 +// the action and thread item arrays built after the browse hooks, and the compiler
372 +// leaves all of them uncached.
373 function useThemeCards(
374 customThemes: ReturnType<typeof useCustomThemes>,
375 environmentThemes: ReturnType<typeof useEnvironmentThemeDefinitions>,
376 ) {
377 + // oxlint-disable-next-line t3code/no-manual-memo -- Kept until the palette's item building moves out of this component (see above).
378 "use memo";
379 const seen = new Set<string>();
380 return [
@@ -388,6 +390,7 @@ function useThemeCards(
390 }
391
392 function useThreadContentMatchByKey(matches: ReturnType<typeof useThreadSearch>["matches"]) {
393 + // oxlint-disable-next-line t3code/no-manual-memo -- Kept until the palette's item building moves out of this component (see above).
394 "use memo";
395 return new Map(
396 matches.flatMap((match) =>
@@ -399,6 +402,7 @@ function useThreadContentMatchByKey(matches: ReturnType<typeof useThreadSearch>[
402 }
403
404 function useEnvironmentLookups(environments: ReturnType<typeof useEnvironments>["environments"]) {
405 + // oxlint-disable-next-line t3code/no-manual-memo -- Kept until the palette's item building moves out of this component (see above).
406 "use memo";
407 const environmentLabelById = new Map(
408 environments.map((environment) => [environment.environmentId, environment.label] as const),
@@ -421,6 +425,7 @@ function useEnvironmentLookups(environments: ReturnType<typeof useEnvironments>[
425 }
426
427 function useProjectLookups(projects: ReturnType<typeof useProjects>) {
428 + // oxlint-disable-next-line t3code/no-manual-memo -- Kept until the palette's item building moves out of this component (see above).
429 "use memo";
430 const projectCwdById = new Map<ProjectId, string>(
431 projects.map((project) => [project.id, project.workspaceRoot]),
@@ -449,6 +454,7 @@ function useSortedProjectGroups({
454 readonly environmentLabelById: ReadonlyMap<EnvironmentId, string>;
455 readonly threads: ReturnType<typeof useThreadShells>;
456 }) {
457 + // oxlint-disable-next-line t3code/no-manual-memo -- Kept until the palette's item building moves out of this component (see above).
458 "use memo";
459 const projectGroupingSettings = selectProjectGroupingSettings(clientSettings);
460 const orderedProjects = orderItemsByPreferredIds({
docs/internals/web-ui.md
+4 -1
@@ -63,7 +63,10 @@ makes it skip the whole function without a build error. Lint reports each skip a
63
64 Every file under `apps/web/src` must compile. Lint makes those rules errors there, and
65 `t3code/no-manual-memo` rejects `useMemo` and `useCallback`, which the compiler makes redundant;
66 -no upstream rule bans them outright. Lint misses some bailouts, notably `try` with `finally` and
66 +no upstream rule bans them outright. It also rejects `"use memo"`. The compiler withholds a cache
67 +scope when a value reaches plain function calls on both sides of a hook call. A `"use memo"`
68 +helper forces one, but hides the ordering problem. Fix the order instead: plain uses of a value go
69 +before the hook, or the helper is inlined. Lint misses some bailouts, notably `try` with `finally` and
70 `throw` inside `try`, so [`reactCompilerCoverage.test.ts`](../../apps/web/src/reactCompilerCoverage.test.ts)
71 compiles every file and fails on any skip. Async handlers rarely need `try`: an
72 atom command settles into a result, so cleanup can follow the `await`. `useStableCallback` still
oxlint-plugin-t3code/rules/no-manual-memo.test.ts
+7
@@ -13,6 +13,13 @@ describe("t3code/no-manual-memo", () => {
13
14 rule.valid("allows other React members", `const ref = React.useRef(null);`);
15
16 + rule.valid("allows other directives", `function Panel() { "use client"; return null; }`);
17 +
18 + rule.invalid(
19 + 'reports a "use memo" directive',
20 + `function useTotal(items) { "use memo"; return items.length; }`,
21 + );
22 +
23 rule.invalid("reports useMemo", `const total = useMemo(() => items.length, [items]);`);
24
25 rule.invalid("reports useCallback", `const onClick = useCallback(() => save(), []);`);
oxlint-plugin-t3code/rules/no-manual-memo.ts
+11 -1
@@ -24,11 +24,21 @@ export default defineRule({
24 type: "suggestion",
25 docs: {
26 description:
27 - "Disallow useCallback and useMemo in files the React Compiler must compile; it memoizes them.",
27 + 'Disallow useCallback, useMemo and "use memo" directives in files the React Compiler must compile; it memoizes them.',
28 },
29 },
30 create(context) {
31 return {
32 + // A "use memo" helper only exists to force a cache scope the compiler withheld,
33 + // which hides the ordering or structure problem that withheld it.
34 + ExpressionStatement(node) {
35 + if (node.directive !== "use memo") return;
36 + context.report({
37 + node,
38 + message:
39 + 'Drop "use memo": restructure so the compiler caches this on its own, e.g. move plain uses of a value before the hook call that splits its scope, or inline the helper.',
40 + });
41 + },
42 CallExpression(node) {
43 const name = manualMemoHookName(node.callee);
44 if (name === null) return;