diff --git a/compiler/packages/babel-plugin-react-compiler/src/HIR/Environment.ts b/compiler/packages/babel-plugin-react-compiler/src/HIR/Environment.ts index 98cf1ed57d9f..639b9cda2de7 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/HIR/Environment.ts +++ b/compiler/packages/babel-plugin-react-compiler/src/HIR/Environment.ts @@ -903,8 +903,14 @@ export class Environment { case 'ImportNamespace': { if (this.#isKnownReactModule(binding.module)) { // only resolve imports to modules we know about + // For default imports from 'react', always resolve to the React global type + // regardless of the local binding name (e.g., import ReactAlias from 'react') + const globalType = + binding.kind === 'ImportDefault' && binding.module.toLowerCase() === 'react' + ? this.#globals.get('React') + : this.#globals.get(binding.name); return ( - this.#globals.get(binding.name) ?? + globalType ?? (isHookName(binding.name) ? this.#getCustomHookType() : null) ); } else { diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/use-hook-aliased-import.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/use-hook-aliased-import.expect.md new file mode 100644 index 000000000000..32b351cfcdfa --- /dev/null +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/use-hook-aliased-import.expect.md @@ -0,0 +1,34 @@ + +## Input + +```javascript +import ReactAlias from 'react' + +function App3() { + const v = ReactAlias.use(); + return