Commit Graph

8 Commits

Author SHA1 Message Date
Ahmed Abdelbaset
f7ee804c22
[compiler] Add git info to package.json files in compiler packages (#30475)
This PR adds the repository field to `compiler/packages/*/package.json`

| eslint-plugin-react-compiler | eslint-plugin-react-hooks |
| --- | --- |
|
![image](https://github.com/user-attachments/assets/3392a496-1ff1-4f36-ab96-cfbe1ed88693)
|
![image](https://github.com/user-attachments/assets/b0605dba-eef7-44fe-9484-979b4814d9fb)
|
2024-07-26 12:56:39 -04:00
Jan Kassens
fd2b3e13d3
Compiler: unfork prettier config (#30205)
Updates the prettier config to format all `.ts` and `.tsx` files in the
repo using the existing defaults and removing overrides.

The first commit in this PR contains the config changes, the second is
just the result of running `yarn prettier-all`.
2024-07-18 17:00:24 -04:00
Mike Vitousek
ec6fe57a50 [compiler] rfc: Include location information in identifiers and reactive scopes for debugging
Summary: Using the change detection code to debug codebases that violate the rules of react is a lot easier when we have a source location corresponding to the value that has changed inappropriately. I didn't see an easy way to track that information in the existing data structures at the point of codegen, so this PR adds locations to identifiers and reactive scopes (the location of a reactive scope is the range of the locations of its included identifiers).

I'm interested if there's a better way to do this that I missed!

ghstack-source-id: aed5f7edda
Pull Request resolved: https://github.com/facebook/react/pull/29658
2024-05-31 14:06:04 -07:00
Mike Vitousek
522d22f299 [compiler] Recompute values every time
Summary: This PR expands the analysis from the previous in the stack in order to also capture when a value can incorrectly change within a single render, rather than just changing between two renders. In the case where dependencies have changed and so a new value is being computed, we now compute the value twice and compare the results. This would, for example, catch when we call Math.random() in render.

The generated code is a little convoluted, because we don't want to have to traverse the generated code and substitute variable names with new ones. Instead, we save the initial value to the cache as normal, then run the computation block again and compare the resulting values to the cached ones. Then, to make sure that the cached values are identical to the computed ones, we reassign the cached values into the output variables.

ghstack-source-id: d0f11a4cb2
Pull Request resolved: https://github.com/facebook/react/pull/29657
2024-05-31 14:06:02 -07:00
Mike Vitousek
5c420e3824 [compiler] Debug tool to emit change detection code rather than memoization
Summary: The essential assumption of the compiler is that if the inputs to a computation have not changed, then the output should not change either--computation that the compiler optimizes is idempotent.

This is, of course, known to be false in practice, because this property rests on requirements (the Rules of React) that are loosely enforced at best. When rolling out the compiler to a codebase that might have rules of react violations, how should developers debug any issues that arise?

This diff attempts one approach to that: when the option is set, rather than simply skipping computation when dependencies haven't changed, we will *still perform the computation*, but will then use a runtime function to compare the original value and the resultant value. The runtime function can be customized, but the idea is that it will perform a structural equality check on the values, and if the values aren't structurally equal, we can report an error, including information about what file and what variable was to blame.

This assists in debugging by narrowing down what specific computation is responsible for a difference in behavior between the uncompiled code and the program after compilation.

ghstack-source-id: 50dad3dacf
Pull Request resolved: https://github.com/facebook/react/pull/29656
2024-05-31 14:05:58 -07:00
Lauren Tan
67ea821e5f [publish] Fix files field for packages, invalid version range
The [`files` field](https://docs.npmjs.com/cli/v10/commands/npm-publish#files-included-in-package)
controls what files get included in the published package.

This PR specifies the `files` field on our publishable packages to only
include the `dist` directory, since we don't need to ship any types or
sourcemaps with 3 of them.

react-compiler-runtime is a runtime package which has sourcemaps, so we
also include the `src` directory in the published package.

Also fixes an invalid version range for the react peer dependency in
react-compiler-runtime, tested that it works via https://semver.npmjs.com/

ghstack-source-id: 12b36c203fc9fd8d72a1995fb3fba2312de4aa51
Pull Request resolved: https://github.com/facebook/react-forget/pull/2965
2024-05-14 11:02:29 -04:00
Jan Kassens
e63d3d1491 Upgrade to React 19 beta (#2938)
- Updated all directly defined dependencies to the latest React 19 Beta
- `package.json`: used `resolutions` to force React 19 for `react-is` transitive dependency
- `package.json`: postinstall script to patch fbt for the React 19 element Symbol
- Match on the message in Snap to exclude a React 19 warning that `act` should be imported from `react` instead (from inside `@testing-library/react`)
- Some updated snapshots, I think due to now recovering behavior of `useMemoCache`, please review.

In a next step, we can do the following. I excluded it since it from here as it made the PR unreviewable on GitHub.

- Snapshots now use `react/compiler-runtime` as in prod, so the different default in Snap is no longer needed.
2024-05-06 19:48:39 -04:00
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