Skip to content

Conversation

@poteto
Copy link
Member

@poteto poteto commented Oct 29, 2024

When resolving import specifiers from the react namespace (import {imported as local} from 'react'), we were previously only checking if the imported identifier was a hook if we didn't already have its definition in the global registry. We also need to check if local is a hook in the case of aliasing since there may be hook-like APIs in react that don't start with use (eg they are experimental or unstable).


Stack created with Sapling. Best reviewed with ReviewStack.

@vercel
Copy link

vercel bot commented Oct 29, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
react-compiler-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 29, 2024 10:36pm

This was originally reported in reactwg/react-compiler#27.

Adding a failing repro to capture this case.
When resolving import specifiers from the react namespace (`import {imported as local} from 'react'`), we were previously only checking if the `imported` identifier was a hook if we didn't already have its definition in the global registry. We also need to check if `local` is a hook in the case of aliasing since there may be hook-like APIs in react that don't start with `use` (eg they are experimental or unstable).
Comment on lines +855 to +857
(isHookName(binding.imported) || isHookName(binding.name)
? this.#getCustomHookType()
: null)
Copy link
Member

Choose a reason for hiding this comment

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

We should probably also just define all the APIs, including unstable ones. But this is pretty reasonable. Thanks!

poteto added a commit that referenced this pull request Oct 30, 2024
#31383)

This was originally reported in
reactwg/react-compiler#27.

Adding a failing repro to capture this case.

---
[//]: # (BEGIN SAPLING FOOTER)
Stack created with [Sapling](https://sapling-scm.com). Best reviewed
with [ReviewStack](https://reviewstack.dev/facebook/react/pull/31383).
* #31385
* #31384
* __->__ #31383
@poteto poteto merged commit 4abe4b5 into main Oct 30, 2024
19 of 27 checks passed
@poteto poteto deleted the pr31384 branch October 30, 2024 01:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed React Core Team Opened by a member of the React Core Team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants