Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,7 @@ function hasMemoCacheFunctionImport(
}

function isHookName(s: string): boolean {
return /^use[A-Z0-9]/.test(s);
return s === 'use' || /^use[A-Z0-9]/.test(s);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sibling isHookName in Environment.ts not updated

There is a second, independently-defined isHookName exported from compiler/packages/babel-plugin-react-compiler/src/HIR/Environment.ts (line 1037) that still uses only the old regex:

// Environment.ts – unchanged
export function isHookName(name: string): boolean {
  return /^use[A-Z0-9]/.test(name);
}

This exported function is the one actually used throughout the HIR pipeline – ValidateHooksUsage.ts, Globals.ts, and Imports.ts all import it. Because it was not updated, identifiers named exactly 'use' are not treated as hook names inside compilation:

  1. Globals.ts (line 1027) — When a user-supplied type provider configures a function called 'use' as a hook, isHookName('use') returns false but the type check returns true, triggering a spurious CompilerError.throwInvalidConfig.
  2. Environment.ts (line 858 / 897) — For non-React third-party imports whose name is 'use', the fallback isHookName check will not assign the custom hook type.
  3. ValidateHooksUsage.ts (lines 168, 197) — Hook-usage validation based on identifier names will miss identifiers named 'use'.

The comment on Environment.ts's isHookName explicitly says it mirrors the eslint-plugin-react-hooks implementation, and that source (eslint-plugin-react-hooks/src/rules/RulesOfHooks.ts line 30) has already been updated to s === 'use' || /^use[A-Z0-9]/.test(s). The same update should be applied here:

// Environment.ts
export function isHookName(name: string): boolean {
  return name === 'use' || /^use[A-Z0-9]/.test(name);
}
Prompt To Fix With AI
This is a comment left during a code review.
Path: compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Program.ts
Line: 898

Comment:
**Sibling `isHookName` in `Environment.ts` not updated**

There is a second, independently-defined `isHookName` exported from `compiler/packages/babel-plugin-react-compiler/src/HIR/Environment.ts` (line 1037) that still uses only the old regex:

```ts
// Environment.ts – unchanged
export function isHookName(name: string): boolean {
  return /^use[A-Z0-9]/.test(name);
}
```

This exported function is the one actually used throughout the HIR pipeline – `ValidateHooksUsage.ts`, `Globals.ts`, and `Imports.ts` all import it. Because it was not updated, identifiers named exactly `'use'` are not treated as hook names inside compilation:

1. **`Globals.ts` (line 1027)** — When a user-supplied type provider configures a function called `'use'` as a hook, `isHookName('use')` returns `false` but the type check returns `true`, triggering a spurious `CompilerError.throwInvalidConfig`.
2. **`Environment.ts` (line 858 / 897)** — For non-React third-party imports whose name is `'use'`, the fallback `isHookName` check will not assign the custom hook type.
3. **`ValidateHooksUsage.ts` (lines 168, 197)** — Hook-usage validation based on identifier names will miss identifiers named `'use'`.

The comment on `Environment.ts`'s `isHookName` explicitly says it mirrors the eslint-plugin-react-hooks implementation, and that source (`eslint-plugin-react-hooks/src/rules/RulesOfHooks.ts` line 30) has *already* been updated to `s === 'use' || /^use[A-Z0-9]/.test(s)`. The same update should be applied here:

```ts
// Environment.ts
export function isHookName(name: string): boolean {
  return name === 'use' || /^use[A-Z0-9]/.test(name);
}
```

How can I resolve this? If you propose a fix, please make it concise.

Fix in Claude Code Fix in Codex

}

/*
Expand Down
Loading