forked from bluesky-social/social-app
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add React Compiler (bluesky-social#4161)
* Install babel-plugin-react-compiler * Install eslint-plugin-react-compiler * Add and configure react-compiler-runtime React Compiler uses a small cache function from React 19 at runtime. Until it's possible to use R19 on RN, this adds a userspace implementation to polyfill the cache function * Add eslint-plugin-react-compiler to config * @lingui/macro should run as the first plugin @lingui recommends running their `macro` plugin [first in the pipeline](https://lingui.dev/ref/macro). Normally with the React Compiler, the compiler plugin should run first as we want to see the original code as it was written. However, this sometimes causes conflicts with other babel plugins. In this case, it looks like the @lingui/macro plugin does some very light transformation that the compiler can still understand and compile correctly, so let's run it first. Before this commit, the compiler would cause the @lingui/macro plugin to crash because it seems like it would strip off the `extra.raw` property off of StringLiterals which was being used [here](https://github.com/lingui/js-lingui/blob/1293412c5dcc565636403443788a5b5d4ca206c1/packages/macro/src/macroJsx.ts#L395). I need to figure out why the compiler is doing that but for now this works and should be a safe change unless there were specific reasons the macro plugin was placed 2nd to last.
- Loading branch information
Showing
7 changed files
with
386 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,4 @@ | |
android | ||
ios | ||
src/locale/locales | ||
lib/react-compiler-runtime |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
const React = require('react') | ||
const $empty = Symbol.for('react.memo_cache_sentinel') | ||
/** | ||
* DANGER: this hook is NEVER meant to be called directly! | ||
* | ||
* Note that this is a temporary userspace implementation of this function | ||
* from React 19. It is not as efficient and may invalidate more frequently | ||
* than the official API. Please upgrade to React 19 as soon as you can. | ||
**/ | ||
export function c(size) { | ||
// eslint-disable-next-line react-hooks/rules-of-hooks | ||
return React.useState(() => { | ||
const $ = new Array(size) | ||
for (let ii = 0; ii < size; ii++) { | ||
$[ii] = $empty | ||
} | ||
// @ts-ignore | ||
$[$empty] = true | ||
return $ | ||
})[0] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"name": "react-compiler-runtime", | ||
"version": "0.0.1", | ||
"license": "MIT", | ||
"main": "index.js", | ||
"peerDependencies": { | ||
"react": "^18.2.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.