Skip to content
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

[React 19] Support React Compiler with older React versions for libraries #29111

Open
devongovett opened this issue May 16, 2024 · 1 comment

Comments

@devongovett
Copy link
Contributor

@poteto asked me to create this issue for discussion.

It would be useful for library authors if the React Compiler could work with older versions of React. Libraries often need to support many different versions of React to avoid breaking older applications that haven't had a chance to update yet. That's the case for us with React Aria, which supports 16.8+. We can't really release a major version that bumps the requirement to React 19 because we have to support many older applications still using 16-18 that haven't prioritized updating yet. We can't realistically leave those applications behind, or maintain multiple major versions of React Aria ourselves, which means we can't use the compiler.

It would be amazing if the compiler could optionally generate regular useMemo, or there was a shim available for older versions of React (similar to the useSyncExternalStore shim that was previously released). This could be available specifically for library authors who need to support multiple versions of React, rather than applications (which should just update to React 19).

@josephsavona
Copy link
Contributor

Thanks for filing this. We absolutely want to make the compiler work with older versions of React as well. It is possible to polyfill the memo cache function today on older versions of React: there are preliminary docs for this in the working group.

Note that there are a bunch of things for us to figure out here. Over time we will likely add additional new internal runtime APIs for the compiler to call, and we are working on the strategy for making that work while still allowing the compiler to work across versions.

But to experiment with the compiler, feel free to use the polyfill option. However, note that we strongly recommend using strict mode to help identify potential problems in your code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants