[rcr] Re-export useMemoCache in top level React namespace#31050
[rcr] Re-export useMemoCache in top level React namespace#31050poteto wants to merge 10 commits intogh/poteto/9/basefrom
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. |
josephsavona
left a comment
There was a problem hiding this comment.
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
useMemoCacheunder the top levelReact namespace again, which is additive and thus non-breaking. Doing so
allows
react-compiler-runtimeto statically either re-exportReact.__COMPILER_RUNTIME.cor 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-runtimeand update thecompiler to emit imports to
react-compiler-runtimeinstead.