Commit Graph

20803 Commits

Author SHA1 Message Date
lauren fbc650d2a7 Merge 6c103ff2e8 into sapling-pr-archive-poteto 2025-03-13 18:43:37 -04:00
Lauren Tan 6c103ff2e8 [ci] Update yarn and node_modules cache key
Now that the compiler lint rule is merged into eslint-plugin-react-hooks, we also need to update our caches so compiler dependencies are also cached. This should fix the CI walltime regression we are now seeing.
2025-03-13 18:43:32 -04:00
Lauren Tan 1af39a7dd5 merge commit for archive created by Sapling 2025-03-13 18:26:59 -04:00
Lauren Tan 848b950cdc [ci] Update yarn and node_modules cache key
Now that the compiler lint rule is merged into eslint-plugin-react-hooks, we also need to update our caches so compiler dependencies are also cached. This should fix the CI walltime regression we are now seeing.
2025-03-13 18:26:52 -04:00
lauren 762ae5d2c3 Merge 7d802d6cc2 into sapling-pr-archive-poteto 2025-03-13 18:04:52 -04:00
Lauren Tan 7d802d6cc2 [ci] Update yarn and node_modules cache key
Now that the compiler lint rule is merged into eslint-plugin-react-hooks, we also need to update our caches so compiler dependencies are also cached. This should fix the CI walltime regression we are now seeing.
2025-03-13 18:04:48 -04:00
lauren 11dee00217 Merge 4199802ecc into sapling-pr-archive-poteto 2025-03-13 17:58:45 -04:00
Lauren Tan 4199802ecc [ci] Update node_modules cache key
Now that the compiler lint rule is merged into eslint-plugin-react-hooks, we also need to update our caches so compiler dependencies are also cached. This should fix the CI walltime regression we are now seeing.
2025-03-13 17:58:37 -04:00
lauren 77987e5ee3 [ci] mkdir before mv (#32602)
Missed this earlier.
2025-03-13 17:46:46 -04:00
Lauren Tan b67ac3f2ea merge commit for archive created by Sapling 2025-03-13 17:39:11 -04:00
Lauren Tan 1a431dba62 [ci] mkdir before mv
Missed this earlier.
2025-03-13 17:39:06 -04:00
Lauren Tan a9c4573198 merge commit for archive created by Sapling 2025-03-13 17:27:03 -04:00
Lauren Tan 9f44adbb04 [ci] mkdir before mv
Missed this earlier.
2025-03-13 17:26:54 -04:00
lauren 0df46f01a9 [ci] Update eslint-plugin-react-hooks output location for Meta builds (#32601)
Updates where this file is output so we can sync it independently to
another directory.
2025-03-13 16:54:39 -04:00
Lauren Tan f562b63a66 merge commit for archive created by Sapling 2025-03-13 15:26:04 -04:00
Lauren Tan 2d79dc06dc [ci] Update eslint-plugin-react-hooks output location for Meta builds
Updates where this file is output so we can sync it independently to another directory.
2025-03-13 15:25:59 -04:00
Lauren Tan 41c9d8ae25 merge commit for archive created by Sapling 2025-03-13 15:24:28 -04:00
Lauren Tan 7c422d7c79 [ci] Update eslint-plugin-react-hooks output location for Meta builds
Updates where this file is output so we can sync it independently to another directory.
2025-03-13 15:24:19 -04:00
mofeiZ f457d0b4c6 [compiler][ez] Only fail gating hoisting check for referenced identifiers (#32596)
Reduce false positive bailouts by using the same
`isReferencedIdentifier` logic that the compiler also uses for
determining context variables and a function's own hoisted declarations.

Details:
Previously, we counted every babel identifier as a reference. This is
problematic because babel counts most string symbols as an identifier.

```js
print(x);  // x is an identifier as expected
obj.x      // x is.. also an identifier here
{x: 2}     // x is also an identifier here
```

This PR adds a check for `isReferencedIdentifier`. Note that only
non-lval
references pass this check. This should be fine as we don't need to
hoist function declarations before writes to the same lvalue (which
should error in strict mode anyways)
```js
print(x);  // isReferencedIdentifier(x) -> true
obj.x      // isReferencedIdentifier(x) -> false
{x: 2}     // isReferencedIdentifier(x) -> false
x = 2      // isReferencedIdentifier(x) -> false
```
---
[//]: # (BEGIN SAPLING FOOTER)
Stack created with [Sapling](https://sapling-scm.com). Best reviewed
with [ReviewStack](https://reviewstack.dev/facebook/react/pull/32596).
* __->__ #32596
* #32595
* #32594
* #32593
* #32522
* #32521
2025-03-13 12:10:22 -04:00
mofeiZ 1c79cb82ab [compiler][ez] Move compiler gating tests (#32595)
Move all gating tests to `gating/`
---
[//]: # (BEGIN SAPLING FOOTER)
Stack created with [Sapling](https://sapling-scm.com). Best reviewed
with [ReviewStack](https://reviewstack.dev/facebook/react/pull/32595).
* #32596
* __->__ #32595
* #32594
* #32593
* #32522
* #32521
2025-03-13 12:06:48 -04:00
mofeiZ 89a46a57df [compiler][optim] more shapes for mixedreadonly (#32594)
- Add `at`, `indexOf`, and `includes`
- Optimize MixedReadOnly which is currently only used by hook return
values. Hook return values are typed as Frozen, this change propagates
that to return values of aliasing function calls (such as `at`). One
potential issue is that developers may pass
`enableAssumeHooksFollowRulesOfReact:false` and set
`transitiveMixedData`, expecting their transitive mixed data to be
mutable. This is a bit of an edge case and already doesn't have clear
semantics.
---
[//]: # (BEGIN SAPLING FOOTER)
Stack created with [Sapling](https://sapling-scm.com). Best reviewed
with [ReviewStack](https://reviewstack.dev/facebook/react/pull/32594).
* #32596
* #32595
* __->__ #32594
* #32593
* #32522
* #32521
2025-03-13 11:59:50 -04:00
mofeiZ eb53139ee5 [compiler][optim] infer mixedReadOnly for numeric and computed properties (#32593)
Expand type inference to infer mixedReadOnly types for numeric and
computed property accesses.
```js
function Component({idx})
  const data = useFragment(...)
  // we want to type `posts` correctly as Array
  const posts = data.viewers[idx].posts.slice(0, 5);
  // ...
}
```
---
[//]: # (BEGIN SAPLING FOOTER)
Stack created with [Sapling](https://sapling-scm.com). Best reviewed
with [ReviewStack](https://reviewstack.dev/facebook/react/pull/32593).
* #32596
* #32595
* #32594
* __->__ #32593
* #32522
* #32521
2025-03-13 11:58:40 -04:00
mofeiZ 38a7600920 [compiler][optim] Add shape for Array.from (#32522)
(see title)
---
[//]: # (BEGIN SAPLING FOOTER)
Stack created with [Sapling](https://sapling-scm.com). Best reviewed
with [ReviewStack](https://reviewstack.dev/facebook/react/pull/32522).
* #32596
* #32595
* #32594
* #32593
* __->__ #32522
* #32521
2025-03-13 11:58:17 -04:00
mofeiZ ed1264f077 [compiler] Patch array and argument spread mutability (#32521)
Array and argument spreads may mutate stateful iterables. Spread sites
should have `ConditionallyMutate` effects (e.g. mutate if the ValueKind
is mutable, otherwise read).

See
- [ecma spec (13.2.4.1 Runtime Semantics: ArrayAccumulation.
SpreadElement : ...
AssignmentExpression)](https://tc39.es/ecma262/multipage/ecmascript-language-expressions.html#sec-runtime-semantics-arrayaccumulation).
- [ecma spec 13.3.8.1 Runtime Semantics:
ArgumentListEvaluation](https://tc39.es/ecma262/multipage/ecmascript-language-expressions.html#sec-runtime-semantics-argumentlistevaluation)

Note that
- Object and JSX Attribute spreads do not evaluate iterables (srcs
[mozilla](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax#description),
[ecma](https://tc39.es/ecma262/multipage/ecmascript-language-expressions.html#sec-runtime-semantics-propertydefinitionevaluation))
- An ideal mutability inference system could model known collections
(i.e. Arrays or Sets) as a "mutated collection of non-mutable objects"
(see `todo-granular-iterator-semantics`), but this is not what we do
today. As such, an array / argument spread will always extend the range
of built-in arrays, sets, etc
- Due to HIR limitations, call expressions with argument spreads may
cause unnecessary bailouts and/or scope merging when we know the call
itself has `freeze`, `capture`, or `read` semantics (e.g.
`useHook(...mutableValue)`)
We can deal with this by rewriting these call instructions to (1) create
an intermediate array to consume the iterator and (2) capture and spread
the array at the callsite
---
[//]: # (BEGIN SAPLING FOOTER)
Stack created with [Sapling](https://sapling-scm.com). Best reviewed
with [ReviewStack](https://reviewstack.dev/facebook/react/pull/32521).
* #32596
* #32595
* #32594
* #32593
* #32522
* __->__ #32521
2025-03-13 11:58:02 -04:00
Tyler Scott Williams ef06b54f8d fix: clarify which mobx libs are not compatible with compiler (#32570)
## Summary

Right now, `react-compiler-healthcheck` flags `mobx` as a "known
incompatible library". But it's not precisely *MobX* that's
incompatible. It's the observer HOC that comes from `mobx-react` and
`mobx-react-lite`.

I've been working on
[mst-use-observable](https://github.com/coolsoftwaretyler/mst-use-observable),
which makes MobX-State-Tree compatible with the compiler. However,
projects that use `mobx-state-tree` and `mst-use-observable` will still
depend on `mobx` as a dependency.

And there [have been efforts in the past to write a hook for
observability](https://github.com/mobxjs/mobx/discussions/2566). So it's
possible that MobX could become compatible, so long as authors access it
with a hook, rather than the HOC.

I would like to propose updating the health check to be a little more
precise and flag the HOC dependencies, rather than MobX itself.

Thanks in advance for your consideration!

## How did you test this change?

`npx react-compiler-healthcheck` shouldn't flag on `mobx` in
dependencies, but will for `mobx-react-lite` and `mobx-react`.

Test suites, formatting, linting, all passed.

---------

Co-authored-by: lauren <poteto@users.noreply.github.com>
2025-03-13 11:46:26 -04:00
Mohhamad Hussain 1b77c3d7b9 Update DEVELOPMENT_GUIDE.md (#32281)
fix: update CONTRIBUTING.md link path

Updated the relative path to CONTRIBUTING.md from `../CONTRIBUTING.md`
to `./../../CONTRIBUTING.md` to ensure the correct file is referenced.

<!--
  Thanks for submitting a pull request!
We appreciate you spending the time to work on these changes. Please
provide enough information so that others can review your pull request.
The three fields below are mandatory.

Before submitting a pull request, please make sure the following is
done:

1. Fork [the repository](https://github.com/facebook/react) and create
your branch from `main`.
  2. Run `yarn` in the repository root.
3. If you've fixed a bug or added code that should be tested, add tests!
4. Ensure the test suite passes (`yarn test`). Tip: `yarn test --watch
TestName` is helpful in development.
5. Run `yarn test --prod` to test in the production environment. It
supports the same options as `yarn test`.
6. If you need a debugger, run `yarn test --debug --watch TestName`,
open `chrome://inspect`, and press "Inspect".
7. Format your code with
[prettier](https://github.com/prettier/prettier) (`yarn prettier`).
8. Make sure your code lints (`yarn lint`). Tip: `yarn linc` to only
check changed files.
  9. Run the [Flow](https://flowtype.org/) type checks (`yarn flow`).
  10. If you haven't already, complete the CLA.

Learn more about contributing:
https://reactjs.org/docs/how-to-contribute.html
-->

## Summary

<!--
Explain the **motivation** for making this change. What existing problem
does the pull request solve?
-->

## How did you test this change?

<!--
Demonstrate the code is solid. Example: The exact commands you ran and
their output, screenshots / videos if the pull request changes the user
interface.
How exactly did you verify that your PR solves the issue you wanted to
solve?
  If you leave this empty, your PR will very likely be closed.
-->
2025-03-13 11:45:26 -04:00
michael faith 5ccfcd17ff feat(eslint-plugin-react-hooks): merge rule from eslint-plugin-react-compiler into react-hooks plugin (#32416)
This change merges the `react-compiler` rule from
`eslint-plugin-react-compiler` into the `eslint-plugin-react-hooks`
plugin. In order to do the move in a way that keeps commit history with
the moved files, but also no remove them from their origin until a
future cleanup change can be done, I did the `git mv` first, and then
recreated the files that were moved in their original places, as a
separate commit. Unfortunately GH shows the moved files as new instead
of the ones that are truly new. But in the IDE and `git blame`, commit
history is intact with the moved files.

Since this change adds new dependencies, and one of those dependencies
has a higher `engines` declaration for `node` than what the plugin
currently has, this is technically a breaking change and will have to go
out as part of a major release.

### Related Changes
- https://github.com/facebook/react/pull/32458

---------

Co-authored-by: Lauren Tan <poteto@users.noreply.github.com>
2025-03-12 21:43:06 -04:00
lauren a8ab2bcb62 [rollup] Add support for running prebuild commands (#32592)
Extracting portions of #32416 for easier review.

Adds a new `prebuild` option to allow for a prebuild command to be run
prior to building the bundle.

Co-authored-by: michael faith <michaelfaith@users.noreply.github.com>
---
[//]: # (BEGIN SAPLING FOOTER)
Stack created with [Sapling](https://sapling-scm.com). Best reviewed
with [ReviewStack](https://reviewstack.dev/facebook/react/pull/32592).
* __->__ #32592
* #32591
* #32590
* #32589
* #32588

---------

Co-authored-by: michael faith <michaelfaith@users.noreply.github.com>
2025-03-12 19:12:45 -04:00
lauren 8646349aeb [rollup] Fix codeFrame is not a function (#32591)
Extracting portions of #32416 for easier review.

Fixes a small issue where `codeFrame` is not a function when a rollup
error was encountered.

Co-authored-by: michael faith <michaelfaith@users.noreply.github.com>
---
[//]: # (BEGIN SAPLING FOOTER)
Stack created with [Sapling](https://sapling-scm.com). Best reviewed
with [ReviewStack](https://reviewstack.dev/facebook/react/pull/32591).
* #32592
* __->__ #32591
* #32590
* #32589
* #32588

---------

Co-authored-by: michael faith <michaelfaith@users.noreply.github.com>
2025-03-12 19:12:33 -04:00
lauren f31779a112 [ez] Run Prettier on eslint-plugin-react-compiler/src/types (#32590)
Extracting portions of #32416 for easier review.

This PR contains small formatting fixes.

Co-authored-by: michael faith <michaelfaith@users.noreply.github.com>
---
[//]: # (BEGIN SAPLING FOOTER)
Stack created with [Sapling](https://sapling-scm.com). Best reviewed
with [ReviewStack](https://reviewstack.dev/facebook/react/pull/32590).
* #32592
* #32591
* __->__ #32590
* #32589
* #32588

---------

Co-authored-by: michael faith <michaelfaith@users.noreply.github.com>
2025-03-12 19:12:22 -04:00
lauren 0e2402eb20 Update eslint fixtures (#32589)
Extracting portions of #32416 for easier review.

This PR lightly updates the build scripts for the eslint fixtures.

Co-authored-by: michael faith <michaelfaith@users.noreply.github.com>
---
[//]: # (BEGIN SAPLING FOOTER)
Stack created with [Sapling](https://sapling-scm.com). Best reviewed
with [ReviewStack](https://reviewstack.dev/facebook/react/pull/32589).
* #32592
* #32591
* #32590
* __->__ #32589
* #32588

---------

Co-authored-by: michael faith <michaelfaith@users.noreply.github.com>
2025-03-12 19:07:51 -04:00
lauren f695f95290 Update babel configs used in jest (#32588)
Extracting portions of #32416 for easier review.

This PR updates our babel configs (only used in jest) to support
classes.

Co-authored-by: michael faith <michaelfaith@users.noreply.github.com>
---
[//]: # (BEGIN SAPLING FOOTER)
Stack created with [Sapling](https://sapling-scm.com). Best reviewed
with [ReviewStack](https://reviewstack.dev/facebook/react/pull/32588).
* #32592
* #32591
* #32590
* #32589
* __->__ #32588

Co-authored-by: michael faith <michaelfaith@users.noreply.github.com>
2025-03-12 19:07:39 -04:00
lauren c0330b9f7f Merge ed8e6dcf7a into sapling-pr-archive-poteto 2025-03-12 18:53:10 -04:00
Lauren Tan ed8e6dcf7a [rollup] Add support for running prebuild commands
Extracting portions of #32416 for easier review.

Adds a new `prebuild` option to allow for a prebuild command to be run prior to building the bundle.

Co-authored-by: michael faith <michaelfaith@users.noreply.github.com>
2025-03-12 18:53:00 -04:00
Lauren Tan b8cd7042f9 [rollup] Fix codeFrame is not a function
Extracting portions of #32416 for easier review.

Fixes a small issue where `codeFrame` is not a function when a rollup error was encountered.

Co-authored-by: michael faith <michaelfaith@users.noreply.github.com>
2025-03-12 18:53:00 -04:00
Lauren Tan 165794019f [ez] Run Prettier on eslint-plugin-react-compiler/src/types
Extracting portions of #32416 for easier review.

This PR contains small formatting fixes.

Co-authored-by: michael faith <michaelfaith@users.noreply.github.com>
2025-03-12 18:53:00 -04:00
Lauren Tan 1ae344261c Update eslint fixtures
Extracting portions of #32416 for easier review.

This PR lightly updates the build scripts for the eslint fixtures.

Co-authored-by: michael faith <michaelfaith@users.noreply.github.com>
2025-03-12 18:53:00 -04:00
Lauren Tan 6fc26be245 Update babel configs used in jest
Extracting portions of #32416 for easier review.

This PR updates our babel configs (only used in jest) to support classes.

Co-authored-by: michael faith <michaelfaith@users.noreply.github.com>
2025-03-12 18:52:59 -04:00
lauren b2e4ff04ad Merge ebc95ed34a into sapling-pr-archive-poteto 2025-03-12 18:44:32 -04:00
Lauren Tan ebc95ed34a [rollup] Add support for running prebuild commands
Extracting portions of #32416 for easier review.

Adds a new `prebuild` option to allow for a prebuild command to be run prior to building the bundle.

Co-authored-by: michael faith <michaelfaith@users.noreply.github.com>
2025-03-12 18:44:06 -04:00
Lauren Tan 2ada449f85 [rollup] Fix codeFrame is not a function
Extracting portions of #32416 for easier review.

Fixes a small issue where `codeFrame` is not a function when a rollup error was encountered.

Co-authored-by: michael faith <michaelfaith@users.noreply.github.com>
2025-03-12 18:43:16 -04:00
Lauren Tan 2009bb34d7 [ez] Run Prettier on eslint-plugin-react-compiler/src/types
Extracting portions of #32416 for easier review.

This PR contains small formatting fixes.

Co-authored-by: michael faith <michaelfaith@users.noreply.github.com>
2025-03-12 18:38:26 -04:00
Lauren Tan 1326153ca1 Update eslint fixtures
Extracting portions of #32416 for easier review.

This PR lightly updates the build scripts for the eslint fixtures.

Co-authored-by: michael faith <michaelfaith@users.noreply.github.com>
2025-03-12 18:36:37 -04:00
Lauren Tan 76a0966c1b Update babel configs used in jest
Extracting portions of #32416 for easier review.

This PR updates our babel configs (only used in jest) to support classes.

Co-authored-by: michael faith <michaelfaith@users.noreply.github.com>
2025-03-12 18:35:43 -04:00
lauren 5de83dcc0f [playground] Use onMount to check if the editor is available (#32586)
Playground test flakiness seems to be fixed but adding this as an extra
precaution
2025-03-12 18:27:15 -04:00
lauren 98b05bc03d Merge a89eca052d into sapling-pr-archive-poteto 2025-03-12 18:22:53 -04:00
Lauren Tan a89eca052d [playground] Use onMount to check if the editor is available
Playground test flakiness seems to be fixed but adding this as an extra precaution
2025-03-12 18:22:49 -04:00
Lauren Tan 3ffd34da78 merge commit for archive created by Sapling 2025-03-12 18:15:33 -04:00
Lauren Tan 7ed96a2152 [playground] Use onMount to check if the editor is available
Playground test flakiness seems to be fixed but adding this as an extra precaution
2025-03-12 18:15:25 -04:00
Lauren Tan df84c903ee merge commit for archive created by Sapling 2025-03-12 18:06:52 -04:00