Skip to content

Commit 28c39dd

Browse files
chore(web): lint rejects "use memo" directives
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent e6ced71 commit 28c39dd

4 files changed

Lines changed: 31 additions & 5 deletions

File tree

‎apps/web/src/components/CommandPalette.tsx‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -366,13 +366,15 @@ function notifyThemeSaveFailure(): void {
366366
);
367367
}
368368

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.
372373
function useThemeCards(
373374
customThemes: ReturnType<typeof useCustomThemes>,
374375
environmentThemes: ReturnType<typeof useEnvironmentThemeDefinitions>,
375376
) {
377+
// oxlint-disable-next-line t3code/no-manual-memo -- Kept until the palette's item building moves out of this component (see above).
376378
"use memo";
377379
const seen = new Set<string>();
378380
return [
@@ -388,6 +390,7 @@ function useThemeCards(
388390
}
389391

390392
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).
391394
"use memo";
392395
return new Map(
393396
matches.flatMap((match) =>
@@ -399,6 +402,7 @@ function useThreadContentMatchByKey(matches: ReturnType<typeof useThreadSearch>[
399402
}
400403

401404
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).
402406
"use memo";
403407
const environmentLabelById = new Map(
404408
environments.map((environment) => [environment.environmentId, environment.label] as const),
@@ -421,6 +425,7 @@ function useEnvironmentLookups(environments: ReturnType<typeof useEnvironments>[
421425
}
422426

423427
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).
424429
"use memo";
425430
const projectCwdById = new Map<ProjectId, string>(
426431
projects.map((project) => [project.id, project.workspaceRoot]),
@@ -449,6 +454,7 @@ function useSortedProjectGroups({
449454
readonly environmentLabelById: ReadonlyMap<EnvironmentId, string>;
450455
readonly threads: ReturnType<typeof useThreadShells>;
451456
}) {
457+
// oxlint-disable-next-line t3code/no-manual-memo -- Kept until the palette's item building moves out of this component (see above).
452458
"use memo";
453459
const projectGroupingSettings = selectProjectGroupingSettings(clientSettings);
454460
const orderedProjects = orderItemsByPreferredIds({

‎docs/internals/web-ui.md‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,10 @@ makes it skip the whole function without a build error. Lint reports each skip a
6363

6464
Every file under `apps/web/src` must compile. Lint makes those rules errors there, and
6565
`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
6770
`throw` inside `try`, so [`reactCompilerCoverage.test.ts`](../../apps/web/src/reactCompilerCoverage.test.ts)
6871
compiles every file and fails on any skip. Async handlers rarely need `try`: an
6972
atom command settles into a result, so cleanup can follow the `await`. `useStableCallback` still

‎oxlint-plugin-t3code/rules/no-manual-memo.test.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ describe("t3code/no-manual-memo", () => {
1313

1414
rule.valid("allows other React members", `const ref = React.useRef(null);`);
1515

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+
1623
rule.invalid("reports useMemo", `const total = useMemo(() => items.length, [items]);`);
1724

1825
rule.invalid("reports useCallback", `const onClick = useCallback(() => save(), []);`);

‎oxlint-plugin-t3code/rules/no-manual-memo.ts‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,21 @@ export default defineRule({
2424
type: "suggestion",
2525
docs: {
2626
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.',
2828
},
2929
},
3030
create(context) {
3131
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+
},
3242
CallExpression(node) {
3343
const name = manualMemoHookName(node.callee);
3444
if (name === null) return;

0 commit comments

Comments
 (0)