-
Notifications
You must be signed in to change notification settings - Fork 47k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[rcr] Re-export useMemoCache in top level React namespace #31050
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Can you clarify this bit? I'm assuming it's so that we can do the feature detection, but why doesn't it work to check for |
for backwards compatibility we can't inject something like if we export this from the main API (could also rename?) then it makes the import always work and then it's trivial to do the check and fallback |
Ahh that makes sense. I’m too used to require(). In that case, how about naming more generically and put this behind an object so that we could add other compiler runtime apis there later? Eg React.__compilerRuntume.c for the memo cache. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's export an object so we have a single place to check for various runtime APIs we may add over time
Done! |
Stack from ghstack (oldest at bottom):
In order to support using the compiler on versions of React prior to 19,
we need the ability to statically import
c
(aka useMemoCache) orfallback to a polyfill supplied by
react-compiler-runtime
(note: thisis a separate npm package, not to be confused with
react/compiler-runtime
, which is currently a part of react).To do this we first need to re-export
useMemoCache
under the top levelReact namespace again, which is additive and thus non-breaking. Doing so
allows
react-compiler-runtime
to statically either re-exportReact.__COMPILER_RUNTIME.c
or supply a polyfill, without the need fora dynamic import which is finicky to support due to returning a promise.
In later PRs I will remove
react/compiler-runtime
and update thecompiler to emit imports to
react-compiler-runtime
instead.