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

Try: React Compiler #66361

Draft
wants to merge 4 commits into
base: trunk
Choose a base branch
from
Draft

Try: React Compiler #66361

wants to merge 4 commits into from

Conversation

tyxla
Copy link
Member

@tyxla tyxla commented Oct 23, 2024

What?

This PR starts experimenting with the React Compiler.

This is simultaneous to the effort to adopt the React Compiler ESLint plugin in #61788.

Currently, this will trigger tons of errors, but having the PR here will help us with addressing them one by one.

Why?

Beta was just released 2 days ago, and adopting it earlier will help us prepare for React 19.

How?

We're using the babel-plugin-react-compiler plugin and the react-compiler-runtime to add React 18 support.

Testing Instructions

TBD - the sky falls right now, due to tons of violations.

Testing Instructions for Keyboard

Same

Screenshots or screencast

@tyxla tyxla added the [Type] Build Tooling Issues or PRs related to build tooling label Oct 23, 2024
@tyxla tyxla self-assigned this Oct 23, 2024
@tyxla
Copy link
Member Author

tyxla commented Oct 23, 2024

Will be working on some fixes here, starting with:

@swissspidy
Copy link
Member

Re-sharing this here as I consider this a blocker from an i18n perspective:

I noticed that with React Compiler all translators comments are removed, which is not great, as WordPress translators rely on these comments for additional context. We must preserve them. I filed facebook/react#31364 for this.

We'll need to come up with an alternative in the meantime.

@tyxla
Copy link
Member Author

tyxla commented Oct 27, 2024

Re-sharing this here as I consider this a blocker from an i18n perspective:

I noticed that with React Compiler all translators comments are removed, which is not great, as WordPress translators rely on these comments for additional context. We must preserve them. I filed facebook/react#31364 for this.

We'll need to come up with an alternative in the meantime.

Thanks for spotting this one @swissspidy, it's quite a major setback and blocker. We'll need to find a way around it, maybe through a config variable that allows skipping comments containing a particular string.

Still, blockers like that only highlight the fragility of how we've been indexing localized strings from compiled/built code. It will likely backfire in other instances in the future. That is a tricky issue to solve, though, especially with all the legacy accumulated over the years.

@tyxla tyxla force-pushed the try/react-compiler branch from fd7ff69 to ef18f0b Compare October 31, 2024 14:03
@Mamaduka
Copy link
Member

I know we've got a couple of blockers, but it would be nice to get this PR to a point where all CI checks are green.

Looking forward to seeing performance stats and playing with editors.

@tyxla
Copy link
Member Author

tyxla commented Nov 25, 2024

I know we've got a couple of blockers, but it would be nice to get this PR to a point where all CI checks are green.

Looking forward to seeing performance stats and playing with editors.

Likewise, after landing the ESLint plugin in #61788, this is the next step. I've been busy with other things, but hoping to restart working on this by the end of this week. Any contributions are welcome, of course!

@@ -1,3 +1,5 @@
'use no memo';

Copy link
Member

Choose a reason for hiding this comment

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

This directive disables memoization of the valueToHTMLString call in the RichText.Content component. The Content component is used in a renderToString call when serializing components to strings, and such components should never use hooks. Because renderToString has no dispatcher for hooks. But the compiler adds a useMemo.

Copy link
Member Author

Choose a reason for hiding this comment

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

Nice find, and thanks for elaborating!

@@ -1,3 +1,4 @@
'use no memo';
Copy link
Member

Choose a reason for hiding this comment

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

This disables memoization of the conditional call in useSelect:

return staticSelectMode : _useStaticSelect() : _useMappingSelect();

The React Compiler things that the _use functions are regular function calls that it can memoize. But it can't, because that leads to the inner hook being called only sometimes. Breaking the rules of hooks in a breaking way.

Copy link
Member Author

Choose a reason for hiding this comment

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

Makes sense to me! I think this is a good compromise to allow moving this work forward.

@tyxla tyxla mentioned this pull request Jan 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Build Tooling Issues or PRs related to build tooling
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants