react/compiler
Joe Savona 82137ec184 Rename react-compiler-runtime
ghstack-source-id: c6c825f5efdb4f9c413050b22b7713966871338c
Pull Request resolved: https://github.com/facebook/react-forget/pull/2931
2024-05-02 17:14:26 -07:00
..
.github/workflows Update references to Forget to React Compiler 2024-05-02 14:28:06 -07:00
.vscode
apps/playground Rename react-compiler-runtime 2024-05-02 17:14:26 -07:00
crates Update copyrights to reference Meta instead of Facebook 2024-04-03 08:43:36 -07:00
docs Rename docs/architecture.md to design_goals per contents 2024-04-02 16:05:11 -07:00
packages Rename react-compiler-runtime 2024-05-02 17:14:26 -07:00
scripts Rename babel plugin 2024-05-02 14:12:33 -07:00
.git-blame-ignore-revs
.gitignore [.gitignore] Add bundle script 2024-04-16 14:41:13 +01:00
.gitmodules
.prettierignore
.prettierrc.json
.watchmanconfig
Cargo.lock Remove reactive_ir crate 2024-04-02 21:03:25 -07:00
Cargo.toml Update references to Forget to React Compiler 2024-05-02 14:28:06 -07:00
CODE_OF_CONDUCT.md
CONTRIBUTING.md
LICENSE Update copyrights to reference Meta instead of Facebook 2024-04-03 08:43:36 -07:00
package.json Rename react-compiler-runtime 2024-05-02 17:14:26 -07:00
README.md Update references to Forget to React Compiler 2024-05-02 14:28:06 -07:00
rust-toolchain.toml
rustfmt.toml
yarn.lock [healthcheck] Add status message 2024-05-01 13:35:03 +01:00

React Compiler

React Compiler is an experimental Babel plugin to automatically memoize React Hooks and Components.

Development

# tsc --watch
$ yarn dev

# in another terminal window
$ yarn test --watch

Notes

An overview of the implementation can be found in the Architecture Overview.

This transform

Scaffolding

Reference

Rust Development

First-Time Setup

  1. Install Rust using rustup. See the guide at https://www.rust-lang.org/tools/install.
  2. Install Visual Studio Code from https://code.visualstudio.com/. Note to Meta employees: install the stock version from that website, not the pre-installed version.
  3. Install the Rust Analyzer VSCode extension through the VSCode marketplace. See instructions at https://rust-analyzer.github.io/manual.html#vs-code.
  4. Install cargo edit which extends cargo with commands to manage dependencies. See https://github.com/killercup/cargo-edit#installation
  5. Install cargo insta which extens cargo with a command to manage snapshots. See https://insta.rs/docs/cli/

Workspace Hygiene

Adding Dependencies

To add a dependency, add it to the top-level Cargo.toml

// Cargo.toml
[workspace.dependencies]
...
new_dep = { version = "x.y.z" }
...

Then reference it from your crate as follows:

// crates/react_foo/Cargo.toml
[dependencies]
...
new_dep = { workspace = true }
...

Adding new crates

Rust's compilation strategy is largely based on parallelizing at the granularity of crates, so builds can be faster when projects have more but smaller crates. Where possible it helps to structure crates to minimize dependencies. For example, our various compiler passes depend on each other in the sense that they often must run in a certain order. However, they often don't need to call each other, so they can generally be split into crates of similar types of passes, so that those crates can compile in parallel.

As a rule of thumb, add crates at roughly the granularity of our existing top-level folds. If you have some one-off utility code that doesn't fit neatly in a crate, add it to react_utils rather than add a one-off crate for it.

Running Tests

Run all tests with the following from the root directory:

cargo test

The majority of our tests will (should) live in the react_fixtures crate, which is a test-only crate that runs compilation end-to-end with snapshot tests. To run just these tests use:

# quiet version
cargo test -p react_fixtures

# without suppressing stdout/stderr output
cargo test -p react_fixtures -- --nocapture

Another hint is that VSCode will show a "Run test" option if you hover over a test in the source code, this lets you run a single test easily. The command line will also give you the CLI command to run just that one test.

Updating Snapshots

The above tests make frequent use of snapshot tests. If snapshots do not match the tests will fail with a diff, if the new output is correct you can accept the changes with:

cargo insta accept

If this command fails, see the note in "first-time setup" about installing cargo insta.

CI Configuration

GitHub CI is configured in .github/workflows/rust.yml.