Commit Graph
15516 Commits
Author SHA1 Message Date
eps1lon 8a67cf0679 Fail yarn build if any bundle fails to build (#26207)
## Summary

`yarn build` would previously still exit with zero exit code hiding
build errors such as
https://app.circleci.com/pipelines/github/facebook/react/38609/workflows/62a73635-3bf3-4264-8c48-a61844a27764/jobs/630503/parallel-runs/11?filterBy=ALL&invite=true#step-105-17.
These issues are still surfaced due to missing size bot artifacts but
the overall PR status would still be green which we don't want.

Now we just exit with the same exit has a the process of a single build
if it's non-zero.

## How did you test this change?

- [x] fails based on the parent of
62e6c4612e:
https://app.circleci.com/pipelines/github/facebook/react/38681/workflows/654c68ed-cebc-48d4-a156-bac719772f6f/jobs/632166
- [x] passes based on `main`

DiffTrain build for commit bb1e3d0e19.
2023-02-20 21:05:24 +00:00
sebmarkbage 3484cc280c Move Mutation/Persistence fork inline into the functions (#26206)
We should never use any logic beyond declarations in the module scope,
including conditions, because in a cycle that can lead to problems.

More importantly, the compiler can't safely reorder statements between
these points which limits the optimizations we can do.

DiffTrain build for commit 62e6c4612e.
2023-02-20 20:10:11 +00:00
sebmarkbage ac6f055db6 Update Closure Compiler (#26205)
I need it for https://github.com/facebook/react/pull/26187.

We need to specify specifically the output mode `ECMASCRIPT5_STRICT` to
remove `const` from the Fizz runtime.

DiffTrain build for commit 80cf4a099e.
2023-02-20 18:34:09 +00:00
sammy-SC ef43b879a4 Change commit message for DiffTrain commigs (#26203)
Previously, the commit message looked something like this in Github:
<img width="921" alt="Screenshot 2023-02-20 at 13 52 35"
src="https://user-images.githubusercontent.com/1733610/220126265-d77931e0-18ac-46a0-bf23-d868f8af17a9.png">

With this change, it will look like:

DiffTrain build for commit db5e6250d4.

DiffTrain build for commit 2cc54b57ed.
2023-02-20 15:23:35 +00:00
eps1lon 0b4b574844 add test case for semver major comparisons
DiffTrain build for [8a82207286](https://github.com/facebook/react/commit/8a82207286efc2211d3c3ad5360441a4e92bbcac)
[View git log for this commit](https://github.com/facebook/react/commits/8a82207286efc2211d3c3ad5360441a4e92bbcac)
2023-02-20 14:44:33 +00:00
sebmarkbage 7b76862985 Update Rollup and related plugins to their most recent versions (#24916)
Update Rollup and related plugins to their most recent versions +
resolve any breaking changes/deprecations/etc along the way. I made each
change piece by piece, so the commit history tells a pretty good story
of what was changed where/how/why.

fixes https://github.com/facebook/react/issues/24894

For the full deepdive/context, see:

- https://github.com/facebook/react/issues/24894

The inspiration for this came from @jasonwilliams 's PR for attempting
to add sourcemap output support to React's builds:

- https://github.com/facebook/react/issues/20186
  - https://github.com/facebook/react/pull/21946

But I figured that it would be useful to minimise the scope of changes
in that PR, and to modernise the build tooling along the way.

If any of these updates rely on a node version later than `10.x`, then
the following PR may have to land first, otherwise things might break on
AppVeyor:

- https://github.com/facebook/react/issues/24891
  - https://github.com/facebook/react/pull/24892

Co-authored-by: Sebastian Markbage <sebastian@calyptus.eu>

DiffTrain build for [6b6d0617ef](https://github.com/facebook/react/commit/6b6d0617eff48860c5b4e3e79c74cbd3312cf45a)
[View git log for this commit](https://github.com/facebook/react/commits/6b6d0617eff48860c5b4e3e79c74cbd3312cf45a)
2023-02-20 06:42:51 +00:00
sebmarkbage fe55d7cdbd Update rollup config to use moduleSideEffects (#26199)
## Summary

In rollup v1.19.4, The "treeshake.pureExternalModules" option is
deprecated. The "treeshake.moduleSideEffects" option should be used
instead, see
https://github.com/rollup/rollup/blob/v1.19.4/src/Graph.ts#L130.

## How did you test this change?

ci green

DiffTrain build for [bc38a3dfa7](https://github.com/facebook/react/commit/bc38a3dfa74f63e66a8307d34ad6d52e838ab3b0)
[View git log for this commit](https://github.com/facebook/react/commits/bc38a3dfa74f63e66a8307d34ad6d52e838ab3b0)
2023-02-20 05:11:14 +00:00
sebmarkbage cf51f6ec6a Rename yarn build-combined to just yarn build (#26192)
It's confusing to new contributors, and me, that you're supposed to use
`yarn build-combined` for almost everything but not fixtures.

We should use only one build command for everything.

Updated fixtures to use the folder convention of build-combined.

DiffTrain build for [db5e6250d4](https://github.com/facebook/react/commit/db5e6250d4bbb70c5085c58694a2e9c78c3f6371)
[View git log for this commit](https://github.com/facebook/react/commits/db5e6250d4bbb70c5085c58694a2e9c78c3f6371)
2023-02-17 21:06:10 +00:00
acdlite f4c9430c80 Make enableCustomElementPropertySupport a dynamic flag in www build (#26194)
Turns enableCustomElementPropertySupport into a dynamic flag in the www
build so we can turn it on behind a GK.

DiffTrain build for [c9d9f524d7](https://github.com/facebook/react/commit/c9d9f524d7deaf3ec94e3d13dc84240bd63cded2)
[View git log for this commit](https://github.com/facebook/react/commits/c9d9f524d7deaf3ec94e3d13dc84240bd63cded2)
2023-02-17 20:54:57 +00:00
mondaychen 334b03a8c0 remove flow check in electron app.js (#26184)
When we were upgrading flow in
https://github.com/facebook/react/commit/6ddcbd4f96cb103de3978617a53c200baf5b546c
we added `$FlowFixMe` for some parameters in this file. However, this
file is not compiled at all, and the `:` syntax breaks the code.

This PR removes the flow check in this file

DiffTrain build for [1a49e2d833](https://github.com/facebook/react/commit/1a49e2d833ed24b4d541fc70659a19821585e570)
[View git log for this commit](https://github.com/facebook/react/commits/1a49e2d833ed24b4d541fc70659a19821585e570)
2023-02-17 17:01:26 +00:00
eps1lon 4810084325 Test :Add a small test for ReactTestUtils to find rendered component with type in document (#24368)
I tried to write test for the ReactTestUtils to find rendered component
with type in document

Tests before this PR

![Windows PowerShell 4_13_2022 11_35_24
PM](https://user-images.githubusercontent.com/72331432/163243620-40eb753c-4136-4793-a628-efcf9e004562.png)

Tests after this PR

![Windows PowerShell 4_13_2022 11_35_30
PM](https://user-images.githubusercontent.com/72331432/163244704-cd17f0e3-7289-4794-895a-be03753e46de.png)

DiffTrain build for [4fcc9184ac](https://github.com/facebook/react/commit/4fcc9184ac2662186cbf1470005bf2b7c67dd40b)
[View git log for this commit](https://github.com/facebook/react/commits/4fcc9184ac2662186cbf1470005bf2b7c67dd40b)
2023-02-17 11:30:45 +00:00
mondaychen 53facbab37 React DevTools 4.27.1 -> 4.27.2 (#26185)
DiffTrain build for [42106558ed](https://github.com/facebook/react/commit/42106558ed31a186ea76ea548db3d7e1427c8043)
[View git log for this commit](https://github.com/facebook/react/commits/42106558ed31a186ea76ea548db3d7e1427c8043)
2023-02-16 21:53:18 +00:00
poteto e6a93dac30 [difftrain] Remove dependency on node-fetch (#26182)
`fetch` is now provided by github-scripts implicitly in
https://github.com/actions/github-script/releases/tag/v6.4.0, so this
was causing a duplicate declaration error.

DiffTrain build for [21b49103d6](https://github.com/facebook/react/commit/21b49103d6e79706401b3d66e15f6a9a15edf8ce)
[View git log for this commit](https://github.com/facebook/react/commits/21b49103d6e79706401b3d66e15f6a9a15edf8ce)
2023-02-16 20:54:07 +00:00
eps1lon fb9dd9ac14 Remove redundant test steps (#26161)
<!--
  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 debug-test --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

This TODO mentions an issue with JSDOM that [seems to have been
resolved](https://github.com/jsdom/jsdom/pull/2996).

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

## How did you test this change?

- Ensured that the `document.activeElement` is no longer `node` after
`node.blur` is called.
- Verified that the tests still pass.
- Looked for [a merged PR that fixes the
issue](https://github.com/jsdom/jsdom/pull/2996).

<!--
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.
-->

DiffTrain build for [fccf3a9fba](https://github.com/facebook/react/commit/fccf3a9fba5fd778c678657c556344b333111cfb)
[View git log for this commit](https://github.com/facebook/react/commits/fccf3a9fba5fd778c678657c556344b333111cfb)
2023-02-13 20:57:01 +00:00
eps1lon 7a9cb87dae test: Don't retry flushActWork if flushUntilNextPaint threw (#26121)
## Summary

Fixes "ReferenceError: You are trying to access a property or method of
the Jest environment after it has been torn down." in
`ReactIncrementalErrorHandling-test.internal.js`

Alternatives:

1. Additional `await act(cb)` call where `cb` makes sure we can flush
until next paint without throwing
    ```js
    // Ensure test isn't exited with pending work
    await act(async () => {
      root.render(<App shouldThrow={false} />);
    });
    ```
1. Use `toFlushAndThrow`
    ```diff
    -    let error;
    -    try {
    -      await act(async () => {
    -        root.render(<App shouldThrow={true} />);
    -      });
    -    } catch (e) {
    -      error = e;
    -    }
    +    root.render(<App shouldThrow={true} />);

    -    expect(error.message).toBe('Oops!');
    +    expect(Scheduler).toFlushAndThrow('Oops!');
         expect(numberOfThrows < 100).toBe(true);
    ```

But then it still wouldn't make sense to pass `resolve` and `reject` to
the next `flushActWork`. Even if the next `flushActWork` would flush
until next paint without throwing, we couldn't resolve or reject because
we already did reject.

## How did you test this change?

- `yarn test --watch
packages/react-reconciler/src/__tests__/ReactIncrementalErrorHandling-test.internal.js`
produces no more errors after the test finishes.

DiffTrain build for [86c8c8db79](https://github.com/facebook/react/commit/86c8c8db7938319027132eeea81c9b7e28938f9d)
[View git log for this commit](https://github.com/facebook/react/commits/86c8c8db7938319027132eeea81c9b7e28938f9d)
2023-02-13 20:54:01 +00:00
kassens bcc7b385c7 Remove unnecessary flowconfig ignore paths (#26159)
## Summary

By removing them, the flowconfig file will be cleaner and easier to
maintain.

## How did you test this change?

ci green

DiffTrain build for [4a4ef2706c](https://github.com/facebook/react/commit/4a4ef2706cfb51db96d48fe20dadcb4fb8e3cb17)
[View git log for this commit](https://github.com/facebook/react/commits/4a4ef2706cfb51db96d48fe20dadcb4fb8e3cb17)
2023-02-12 21:10:21 +00:00
gnoff 427f9d9332 remove unguarded getRootNode call (#26152)
I forgot to guard the `getRootNode` call in #26106 and it fails in IE8
and old jsdom. I consolidated the implementation a bit and removed the
unguarded call

DiffTrain build for [64acd3918a](https://github.com/facebook/react/commit/64acd3918a26d92773d3dd451a735603ef50d3a7)
[View git log for this commit](https://github.com/facebook/react/commits/64acd3918a26d92773d3dd451a735603ef50d3a7)
2023-02-10 21:41:40 +00:00
kassens c7ad6cb7da Minor Jest upgrade (#26150)
Minor version bump to get the fix for `numPassingAsserts`:
https://github.com/facebook/jest/pull/13795

Test Plan:
CI

DiffTrain build for [2de85d7c71](https://github.com/facebook/react/commit/2de85d7c712ff0f052d9c92f8129ed476f8ce4d8)
[View git log for this commit](https://github.com/facebook/react/commits/2de85d7c712ff0f052d9c92f8129ed476f8ce4d8)
2023-02-10 19:13:08 +00:00
kassens cd7e08855b Migrate testRunner from jasmine2 to jest-circus (#26144)
## Summary

In jest v27, jest-circus as default test runner
(https://github.com/facebook/jest/pull/10686)

## How did you test this change?

ci green

DiffTrain build for [71cace4d32](https://github.com/facebook/react/commit/71cace4d3267e4527964db51ccaf5eab7234f37f)
[View git log for this commit](https://github.com/facebook/react/commits/71cace4d3267e4527964db51ccaf5eab7234f37f)
2023-02-10 18:46:25 +00:00
eps1lon ec5f59a3b9 Fix and update attribute-behavior fixture (#26114)
## Summary

Due to https://github.com/facebook/react/issues/25928 the attribute
fixture could no longer finish since it expects at least something to
render. But since Fizz currently breaks down completely on malformed
`<meta>` tags, the fixture could no longer handle this.

The fixture now renders valid types for `meta` tags.

Note that the snapshot change to `viewTarget`` is already on `main`.
Review by commit helps to understand this.

Added `html[lang]` so that we test at least one standard attribute on
`<html>`. `version` is obsolete so results are not that trustworthy.

## How did you test this change?

With Chrome Version 109.0.5414.119 (Official Build) (64-bit)

- `yarn build --type=UMD_DEV react/index,react-dom && cd
fixtures/attribute-behavior && yarn install && yarn start`

DiffTrain build for [b8ae89f382](https://github.com/facebook/react/commit/b8ae89f38288bfae37dff54fa1ec4bf3b4555ed5)
[View git log for this commit](https://github.com/facebook/react/commits/b8ae89f38288bfae37dff54fa1ec4bf3b4555ed5)
2023-02-10 18:26:30 +00:00
mondaychen 5d94a68c3c Bypass packages that are already published when confirmed by users (#26141)
## Summary

I ran into some two factor certification issue and had to resume the
publish script. However, this time if I confirmed the published package,
it will still try to publish the same version and fail. This is not
expected, and it blocks me from publishing the rest of the packages.

## How did you test this change?

I re-run the publish script after the change and successfully publish
the rest of the packages.

```
? Have you run the build-and-test script? Yes

✓ Checking NPM permissions for ryancat. 881 ms

? Please provide an NPM two-factor auth token: 278924

react-devtools version 4.27.2 has already been published.

? Is this expected (will skip react-devtools@4.27.2)? Yes

react-devtools-core version 4.27.2 has already been published.

? Is this expected (will skip react-devtools-core@4.27.2)? Yes

✓ Publishing package react-devtools-inline 23.1 secs

You are now ready to publish the extension to Chrome, Edge, and Firefox:
  https://fburl.com/publish-react-devtools-extensions

When publishing to Firefox, remember the following:
  Build id: 625690
  Git archive: ******
```

DiffTrain build for [d9e0485c84](https://github.com/facebook/react/commit/d9e0485c84b45055ba86629dc20870faca9b5973)
[View git log for this commit](https://github.com/facebook/react/commits/d9e0485c84b45055ba86629dc20870faca9b5973)
2023-02-10 16:35:42 +00:00
sebmarkbage 38cdbc28fc Treat displayName as undefined (#26148)
When we have a key we read displayName eagerly for future warnings.

In general, React should be inspecting if something is a client
reference before dotting into it. However, we use displayName a lot and
it kind of has defined meaning for debugging everywhere it's used so
seems fine to treat this as undefined.

DiffTrain build for [c8510227c1](https://github.com/facebook/react/commit/c8510227c1b9c4049979b81e998ec40545e2ce9b)
[View git log for this commit](https://github.com/facebook/react/commits/c8510227c1b9c4049979b81e998ec40545e2ce9b)
2023-02-10 16:31:32 +00:00
eps1lon 33d2304b83 Update jest printBasicPrototype config (#26142)
DiffTrain build for [55542bc73d](https://github.com/facebook/react/commit/55542bc73decab8337df3f7e519451b28593b04e)
[View git log for this commit](https://github.com/facebook/react/commits/55542bc73decab8337df3f7e519451b28593b04e)
2023-02-10 09:05:03 +00:00
gnoff a1c26b10eb Model Float on Hoistables semantics (#26106)
## Hoistables

In the original implementation of Float, all hoisted elements were
treated like Resources. They had deduplication semantics and hydrated
based on a key. This made certain kinds of hoists very challenging such
as sequences of meta tags for `og:image:...` metadata. The reason is
each tag along is not dedupable based on only it's intrinsic properties.
two identical tags may need to be included and hoisted together with
preceding meta tags that describe a semantic object with a linear set of
html nodes.

It was clear that the concept of Browser Resources (stylesheets /
scripts / preloads) did not extend universally to all hositable tags
(title, meta, other links, etc...)

Additionally while Resources benefit from deduping they suffer an
inability to update because while we may have multiple rendered elements
that refer to a single Resource it isn't unambiguous which element owns
the props on the underlying resource. We could try merging props, but
that is still really hard to reason about for authors. Instead we
restrict Resource semantics to freezing the props at the time the
Resource is first constructed and warn if you attempt to render the same
Resource with different props via another rendered element or by
updating an existing element for that Resource.

This lack of updating restriction is however way more extreme than
necessary for instances that get hoisted but otherwise do not dedupe;
where there is a well defined DOM instance for each rendered element. We
should be able to update props on these instances.

Hoistable is a generalization of what Float tries to model for hoisting.
Instead of assuming every hoistable element is a Resource we now have
two distinct categories, hoistable elements and hoistable resources. As
one might guess the former has semantics that match regular Host
Components except the placement of the node is usually in the <head>.
The latter continues to behave how the original implementation of
HostResource behaved with the first iteration of Float

### Hoistable Element
On the server hoistable elements render just like regular tags except
the output is stored in special queues that can be emitted in the stream
earlier than they otherwise would be if rendered in place. This also
allow for instance the ability to render a hoistable before even
rendering the <html> tag because the queues for hoistable elements won't
flush until after we have flushed the preamble (`<DOCTYPE
html><html><head>`).

On the client, hoistable elements largely operate like HostComponents.
The most notable difference is in the hydration strategy. If we are
hydrating and encounter a hoistable element we will look for all tags in
the document that could potentially be a match and we check whether the
attributes match the props for this particular instance. We also do this
in the commit phase rather than the render phase. The reason hydration
can be done for HostComponents in render is the instance will be removed
from the document if hydration fails so mutating it in render is safe.
For hoistables the nodes are not in a hydration boundary (Root or
SuspenseBoundary at time of writing) and thus if hydration fails and we
may have an instance marked as bound to some Fiber when that Fiber never
commits. Moving the hydration matching to commit ensures we will always
succeed in pairing the hoisted DOM instance with a Fiber that has
committed.

### Hoistable Resource
On the server and client the semantics of Resources are largely the same
they just don't apply to title, meta, and most link tags anymore.
Resources hoist and dedupe via an `href` key and are ref counted. In a
future update we will add a garbage collector so we can clean up
Resources that no longer have any references

## `<style>` support
In earlier implementations there was no support for <style> tags. This
PR adds support for treating `<style href="..."
precedence="...">...</style>` as a Resource analagous to `<link
rel="stylesheet" href="..." precedence="..." />`

It may seem odd at first to require an href to get Resource semantics
for a style tag. The rationale is that these are for inlining of actual
external stylesheets as an optimization and for URI like scoping of
inline styles for css-in-js libraries. The href indicates that the key
space for `<style>` and `<link rel="stylesheet" />` Resources is shared.
and the precedence is there to allow for interleaving of both kinds of
Style resources. This is an advanced feature that we do not expect most
app developers to use directly but will be quite handy for various
styling libraries and for folks who want to inline as much as possible
once Fizz supports this feature.

## refactor notes
* HostResource Fiber type is renamed HostHoistable to reflect the
generalization of the concept
* The Resource object representation is modified to reduce hidden class
checks and to use less memory overall
* The thing that distinguishes a resource from an element is whether the
Fiber has a memoizedState. If it does, it will use resource semantics,
otherwise element semantics
* The time complexity of matching hositable elements for hydration
should be improved

DiffTrain build for [6396b66411](https://github.com/facebook/react/commit/6396b664118442f3c2eae7bf13732fcb27bda98f)
[View git log for this commit](https://github.com/facebook/react/commits/6396b664118442f3c2eae7bf13732fcb27bda98f)
2023-02-10 07:07:19 +00:00
sebmarkbage 6c6f5d04e8 Enable passing Server References from Server to Client (#26124)
This is the first of a series of PRs, that let you pass functions, by
reference, to the client and back. E.g. through Server Context. It's
like client references but they're opaque on the client and resolved on
the server.

To do this, for security, you must opt-in to exposing these functions to
the client using the `"use server"` directive. The `"use client"`
directive lets you enter the client from the server. The `"use server"`
directive lets you enter the server from the client.

This works by tagging those functions as Server References. We could
potentially expand this to other non-serializable or stateful objects
too like classes.

This only implements server->server CJS imports and server->server ESM
imports. We really should add a loader to the webpack plug-in for
client->server imports too. I'll leave closures as an exercise for
integrators.

You can't "call" a client reference on the server, however, you can
"call" a server reference on the client. This invokes a callback on the
Flight client options called `callServer`. This lets a router implement
calling back to the server. Effectively creating an RPC. This is using
JSON for serializing those arguments but more utils coming from
client->server serialization.

DiffTrain build for [ef9f6e77b8](https://github.com/facebook/react/commit/ef9f6e77b8ef968eee659ae797da4bdc07bbbde3)
[View git log for this commit](https://github.com/facebook/react/commits/ef9f6e77b8ef968eee659ae797da4bdc07bbbde3)
2023-02-10 00:51:12 +00:00
sebmarkbage 52aee4e854 Delete blocks fixture (#26143)
It's not really up-to-date and it's not really show casing anything we
don't have elsewhere.

DiffTrain build for [6c75d4e009](https://github.com/facebook/react/commit/6c75d4e00961f7d5679ad3bf85ead8d96b824d08)
[View git log for this commit](https://github.com/facebook/react/commits/6c75d4e00961f7d5679ad3bf85ead8d96b824d08)
2023-02-09 23:52:00 +00:00
eps1lon 7507586c09 Update jest escapeString config (#26140)
## Summary

In jest v29, snapshotFormat default to escapeString:
false(https://github.com/facebook/jest/pull/13036)

## How did you test this change?

ci green

DiffTrain build for [35698311de](https://github.com/facebook/react/commit/35698311de3c068be9a542e1a2c545d718ec4782)
[View git log for this commit](https://github.com/facebook/react/commits/35698311de3c068be9a542e1a2c545d718ec4782)
2023-02-09 23:31:10 +00:00
kassens c83d3c710f [flow] enable LTI inference mode (#26104)
This is the next generation inference mode for Flow.

DiffTrain build for [6ddcbd4f96](https://github.com/facebook/react/commit/6ddcbd4f96cb103de3978617a53c200baf5b546c)
[View git log for this commit](https://github.com/facebook/react/commits/6ddcbd4f96cb103de3978617a53c200baf5b546c)
2023-02-09 22:14:41 +00:00
sammy-SC 0e23e21b64 Implement unstable_getBoundingClientRect in RN Fabric refs (#26137)
We're fixing the timing of layout and passive effects in React Native,
and adding support for some Web APIs so common use cases for those
effects can be implemented with the same code on React and React Native.

Let's take this example:

```javascript
function MyComponent(props) {
  const viewRef = useRef();

  useLayoutEffect(() => {
    const rect = viewRef.current?.getBoundingClientRect();
    console.log('My view is located at', rect?.toJSON());
  }, []);

  return <View ref={viewRef}>{props.children}</View>;
}
```

This could would work as expected on Web (ignoring the use of `View` and
assuming something like `div`) but not on React Native because:
1. Layout is done asynchronously in a background thread in parallel with
the execution of layout and passive effects. This is incorrect and it's
being fixed in React Native (see
https://github.com/facebook/react-native/commit/afec07aca273503b0647dbf1f73c518c6e52e8ba).
2. We don't have an API to access layout information synchronously. The
existing `ref.current.measureInWindow` uses callbacks to pass the
result. That is asynchronous at the moment in Paper (the legacy renderer
in React Native), but it's actually synchronous in Fabric (the new React
Native renderer).

This fixes point 2) by adding a Web-compatible method to access layout
information (on Fabric only).

This has 2 dependencies in React Native:
1. Access to `getBoundingClientRect` in Fabric, which was added in
https://github.com/facebook/react-native/blob/main/ReactCommon/react/renderer/uimanager/UIManagerBinding.cpp#L644-
L676
2. Access to `DOMRect`, which was added in
https://github.com/facebook/react-native/commit/673c7617bcf90a892a0afc2c0d9cf9c0493fdf27
.

As next step, I'll modify the implementation of this and other methods
in Fabric to warn when they're accessed during render. We can't do this
on Web because we can't (shouldn't) modify built-in DOM APIs, but we can
do it in React Native because the refs objects are built by the
framework.

DiffTrain build for [53b1f69ba6](https://github.com/facebook/react/commit/53b1f69ba6c08083e4934373d3f6f2e31b232874)
[View git log for this commit](https://github.com/facebook/react/commits/53b1f69ba6c08083e4934373d3f6f2e31b232874)
2023-02-09 18:57:55 +00:00
eps1lon 990e05e28a Only restore Yarn caches on exact key hits (#26133)
## Summary

[Current Yarn cache size:
555MB](https://app.circleci.com/pipelines/github/facebook/react/38163/workflows/70d0149e-b0bc-44e8-b8c9-e5c744cab89b/jobs/625334?invite=true#step-102-2)
[Used Yarn cache size:
344MB](https://app.circleci.com/pipelines/github/facebook/react/38166/workflows/4825d444-1426-4321-b95b-c540e6cdc6d7/jobs/625354?invite=true#step-104-5)

When we restore a global Yarn cache that's not specific to a lockfile
entry (i.e. a fallback cache), we might restore packages that are no
longer used. When we then run yarn install, we potentially add new
packages to the cache.
For example:
1. we bump a package version
2. lockfile changes
3. cache restore misses for exact key
4. cache restore hits a prefix (fallback) containing the older version,
5. yarn install adds the new version to the cache

Yarn is not clearing the unused packages from the global cache. So when
we then save the cache we now retain the old and new version of a
package in the global cache even though the old version is no longer
used.
This means that the global cache grows indefinitely. Restoring the cache
isn't free so CI install times will degrade over time.

Either we
1. periodically prune the cache
2. just not restore anything unless we have an exact hit.

The chosen tradeoff depends on the
relation of commits changing deps to commits not changing deps.
From my experience, we change deps rarely so I opted to only restore the
cache on exact hits.

## How did you test this change?

- run on `main` has 555MB of Yarn cache:
https://app.circleci.com/pipelines/github/facebook/react/38163/workflows/70d0149e-b0bc-44e8-b8c9-e5c744cab89b/jobs/625334?invite=true#step-102-2
- run on this branch only has 334MB of Yarn cache:
https://app.circleci.com/pipelines/github/facebook/react/38166/workflows/4825d444-1426-4321-b95b-c540e6cdc6d7/jobs/625354?invite=true#step-104-5

DiffTrain build for [c0b0b3a9f8](https://github.com/facebook/react/commit/c0b0b3a9f80fd57e882859afd95c2f08599442ba)
[View git log for this commit](https://github.com/facebook/react/commits/c0b0b3a9f80fd57e882859afd95c2f08599442ba)
2023-02-09 17:58:48 +00:00
eps1lon a1ba91ff2f Add support for SVG transformOrigin prop (#26130)
Co-authored-by: eps1lon <silbermann.sebastian@gmail.com>

DiffTrain build for [28fcae062b](https://github.com/facebook/react/commit/28fcae062bff2b611cd935911f8666b0627b9551)
[View git log for this commit](https://github.com/facebook/react/commits/28fcae062bff2b611cd935911f8666b0627b9551)
2023-02-09 12:54:12 +00:00
sammy-SC a206fbd2fd Prefer JSX in ReactNoop assertions (to combat out-of-memory test runs) (#26127)
## Summary

Prefer `getChildrenAsJSX` or `toMatchRenderedOutput` over `getChildren`.
Use `dangerouslyGetChildren` if you really need to (e.g. for `toBe`
assertions).

Prefer `getPendingChildrenAsJSX` over `getPendingChildren`. Use
`dangerouslyGetPendingChildren` if you really need to (e.g. for `toBe`
assertions).

`ReactNoop.getChildren` contains the fibers as non-enumerable
properties. If you pass the children to `toEqual` and have a mismatch,
Jest performance is very poor (to the point of causing out-of-memory
crashes e.g.
https://app.circleci.com/pipelines/github/facebook/react/38084/workflows/02ca0cbb-bab4-4c19-8d7d-ada814eeebb9/jobs/624297/parallel-runs/5?filterBy=ALL&invite=true#step-106-27).
Mismatches can sometimes be intended e.g. on gated tests.

Instead, I converted almost all of the `toEqual` assertions to
`toMatchRenderedOutput` assertions or compare the JSX instead. For
ReactNoopPersistent we still use `getChildren` since we have assertions
on referential equality. `toMatchRenderedOutput` is more accurate in
some instances anyway. I highlighted some of those more accurate
assertions in review-comments.

## How did you test this change?

- [x] `CIRCLE_NODE_TOTAL=20 CIRCLE_NODE_INDEX=5 yarn test
-r=experimental --env=development --ci`: Can take up to 350s (and use up
to 7GB of memory) on `main` but 11s on this branch
- [x] No more slow `yarn test` parallel runs of `yarn_test` jobs (the
steps in these runs should take <1min but sometimes they take 3min and
end with OOM like
https://app.circleci.com/pipelines/github/facebook/react/38084/workflows/02ca0cbb-bab4-4c19-8d7d-ada814eeebb9/jobs/624258/parallel-runs/5?filterBy=ALL:
Looks good with a sample size of 1
https://app.circleci.com/pipelines/github/facebook/react/38110/workflows/745109a2-b86b-429f-8c01-9b23a245417a/jobs/624651

DiffTrain build for [3ff1540e9b](https://github.com/facebook/react/commit/3ff1540e9bbe30aae52e2c9ab61c843bd0c94237)
[View git log for this commit](https://github.com/facebook/react/commits/3ff1540e9bbe30aae52e2c9ab61c843bd0c94237)
2023-02-09 11:01:30 +00:00
mondaychen cbbf551897 Replace DevTools semver usages with compare-versions for smaller bundle size (#26122)
<!--
  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 debug-test --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

This PR:

- Replaces the existing usages of methods from the `semver` library in
the React DevTools source with an inlined version based on
https://www.npmjs.com/package/semver-compare.

This appears to drop the unminified bundle sizes of 3 separate
`react-devtools-extensions` build artifacts by about 50K:

![image](https://user-images.githubusercontent.com/1128784/217326947-4c26d1be-d834-4f77-9e6e-be2d5ed0954d.png)

## How did you test this change?

I was originally working on [a fork of React
DevTools](https://github.com/replayio/react/pull/2) for use with
https://replay.io , specifically our integration of the React DevTools
UI to show the React component tree while users are debugging a recorded
application.

As part of the dev work on that fork, I wanted to shrink the bundle size
of the extension's generated JS build artifacts. I noted that the
official NPM `semver` library was taking up a noticeable chunk of space
in the bundles, and saw that it's only being used in a handful of places
to do some very simple version string comparisons.

I was able to replace the `semver` imports and usages with a simple
alternate comparison function, and confirmed via hands-on checks and
console logging that the checks behaved the same way.

Given that, I wanted to upstream this particular change to help shrink
the real extension's bundle sizes.

I know that it's an extension, so bundle size isn't _as_ critical a
concern as it would be for a pure library. But, smaller download sizes
do benefit all users, and that also includes sites like CodeSandbox and
Replay that are using the React DevTools as a library as well.

I'm happy to tweak this PR if necessary.  Thanks!

DiffTrain build for [78d2e9e2a8](https://github.com/facebook/react/commit/78d2e9e2a894a7ea9aa3f9faadfc4c6038e86a75)
[View git log for this commit](https://github.com/facebook/react/commits/78d2e9e2a894a7ea9aa3f9faadfc4c6038e86a75)
2023-02-09 01:07:22 +00:00
gnoff 3945ca9ce7 support ReactDOM.render(..., document) without crashing (#26129)
as reported in #26128 `ReactDOM.render(..., document)` crashed when
`enableHostSingletons` was on. This is because it had a different way of
clearing the container than `createRoot(document)`. I updated the legacy
implementation to share the clearing behavior of `creatRoot` which will
preserve the singleton instances.

I also removed the warning saying not to use `document.body` as a
container

DiffTrain build for [a3152eda5f](https://github.com/facebook/react/commit/a3152eda5f89e20f056521855f7fa101ce50e4c3)
[View git log for this commit](https://github.com/facebook/react/commits/a3152eda5f89e20f056521855f7fa101ce50e4c3)
2023-02-08 19:40:52 +00:00
ryancat 9d88d1ff8b Support highlights for React Native apps in dev tools (#26060)
<!--
  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 debug-test --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?
-->

This pull request emit the trace update events `drawTraceUpdates` with
the trace frame information when the trace update drawer runs outside of
web environment. This allows React Devtool running in mobile or other
platforms have a chance to render such highlights and provide similar
feature on web to provide re-render highlights. This is a feature needed
for identifying unnecessary re-renders.

## 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.
-->

I tested this change with Flipper desktop app running against mobile
app, and verified that the event with correct array of frames are
passing through properly.

DiffTrain build for [758fc7fde1](https://github.com/facebook/react/commit/758fc7fde10f49912b18496299506cba30d6029b)
[View git log for this commit](https://github.com/facebook/react/commits/758fc7fde10f49912b18496299506cba30d6029b)
2023-02-07 22:53:06 +00:00
sebmarkbage 79ef501908 Add Edge Server Builds for workerd / edge-light (#26116)
We currently abuse the browser builds for Web streams derived
environments. We already have a special build for Bun but we should also
have one for [other "edge"
runtimes](https://runtime-keys.proposal.wintercg.org/) so that we can
maximally take advantage of the APIs that exist on each platform.

In practice, we currently check for a global property called
`AsyncLocalStorage` in the server browser builds which we shouldn't
really do since browsers likely won't ever have it. Additionally, this
should probably move to an import which we can't add to actual browser
builds where that will be an invalid import. So it has to be a separate
build. That's not done yet in this PR but Vercel will follow
Cloudflare's lead here.

The `deno` key still points to the browser build since there's no
AsyncLocalStorage there but it could use this same or a custom build if
support is added.

DiffTrain build for [01a0c4e12c](https://github.com/facebook/react/commit/01a0c4e12c6aa9732d290e13b1452f72d276934d)
[View git log for this commit](https://github.com/facebook/react/commits/01a0c4e12c6aa9732d290e13b1452f72d276934d)
2023-02-07 20:16:53 +00:00
eps1lon 2a5aa3d064 Fix main (#26120)
## Summary

Prettier was bumped recently. So any branch not including that bump,
might bring in outdated formatting (e.g.
https://github.com/facebook/react/pull/26068)

## How did you test this change?

- [x] `yarn prettier-all`

DiffTrain build for [13f4ccfdba](https://github.com/facebook/react/commit/13f4ccfdba06b599a5db7c5a192024cbfa365edc)
[View git log for this commit](https://github.com/facebook/react/commits/13f4ccfdba06b599a5db7c5a192024cbfa365edc)
2023-02-07 17:05:06 +00:00
mondaychen c2b52ad54b [DevTools] improve error handling in extension (#26068)
## Summary

This is to fix some edge cases I recently observed when developing and
using the extension:
- When you reload the page, there's a chance that a port (most likely
the devtools one) is not properly unloaded. In this case, the React
DevTools will stop working unless you create a new tab.
- For unknown reasons, Chrome sometimes spins up two service worker
processes. In this case, an error will be thrown "duplicate ID when
registering content script" and sometimes interrupt the execution of the
rest of service worker.

This is an attempt to make the logic more robust
- Automatically shutting down the double pipe if the message fails, and
allowing the runtime to rebuild the double pipe.
- Log the error message so Chrome believes we've handled it and will not
interrupt the execution.

This also seems to be helpful in fixing #25806.

DiffTrain build for [c12194f748](https://github.com/facebook/react/commit/c12194f7485f298fadc1e51cfffb93e63d61ad96)
[View git log for this commit](https://github.com/facebook/react/commits/c12194f7485f298fadc1e51cfffb93e63d61ad96)
2023-02-07 13:06:42 +00:00
sebmarkbage e52c53880b Rename "dom" fork to "dom-node" and "bun" fork to "dom-bun" (#26117)
The "dom" configuration is actually the node specific configuration. It
just happened to be that this was the mainline variant before so it was
implied but with so many variants, this is less obvious now.

The "bun" configuration is specifically for "bun". There's no "native"
renderer for "bun" yet.

DiffTrain build for [03a216070d](https://github.com/facebook/react/commit/03a216070dfe14ff8fecaee2fa95ca6d6e94846d)
[View git log for this commit](https://github.com/facebook/react/commits/03a216070dfe14ff8fecaee2fa95ca6d6e94846d)
2023-02-06 21:01:20 +00:00
kassens f53686ad13 Revert "Move the Webpack manifest config to one level deeper (#26083)" (#26111)
Just kidding. We're not going to need any other fields afaik after all.

DiffTrain build for [4bf2113a15](https://github.com/facebook/react/commit/4bf2113a153522904e34e7a2cef3c1de1c10cbec)
[View git log for this commit](https://github.com/facebook/react/commits/4bf2113a153522904e34e7a2cef3c1de1c10cbec)
2023-02-06 19:43:58 +00:00
acdlite 98b02339b1 publish-prereleases: Exit if CircleCI request fails (#26100)
If the publish-prereleases command fails to access CircleCI, it will now
exit with a message instead of hanging indefinitely.

DiffTrain build for [855b77c9bb](https://github.com/facebook/react/commit/855b77c9bbee347735efcd626dda362db2ffae1d)
[View git log for this commit](https://github.com/facebook/react/commits/855b77c9bbee347735efcd626dda362db2ffae1d)
2023-02-03 00:27:37 +00:00
kassens cb5104f6f8 [flow] upgrade to 0.199.0 (#26096)
`flow-remove-types` was also upgraded to the latest version.

DiffTrain build for [2ef24145e4](https://github.com/facebook/react/commit/2ef24145e4628fda9d8883cd573553b82a2e0a81)
[View git log for this commit](https://github.com/facebook/react/commits/2ef24145e4628fda9d8883cd573553b82a2e0a81)
2023-02-02 21:28:52 +00:00
sebmarkbage 3209889fe2 Revert the outer module object to an object (#26093)
This is because Webpack has a `typeof ... === 'object'` before its esm
compat test.

This is unfortunate because it means we can't have a nice error in CJS
when someone does this:

```
const fn = require('client-fn');
fn();
```

I also fixed some checks in the validator that read off the client ref.
It shouldn't do those checks against a client ref, since those now
throw.

DiffTrain build for [922dd7ba50](https://github.com/facebook/react/commit/922dd7ba50f69f1f969c5809eb57104768716c89)
[View git log for this commit](https://github.com/facebook/react/commits/922dd7ba50f69f1f969c5809eb57104768716c89)
2023-02-02 20:39:03 +00:00
sebmarkbage 8aff9a7a73 Serialize Promises through Flight (#26086)
This lets you pass Promises from server components to client components
and `use()` them there.

We still don't support Promises as children on the client, so we need to
support both. This will be a lot simpler when we remove the need to
encode children as lazy since we don't need the lazy encoding anymore
then.

I noticed that this test failed because we don't synchronously resolve
instrumented Promises if they're lazy. The second fix calls `.then()`
early to ensure that this lazy initialization can happen eagerly. ~It
felt silly to do this with an empty function or something, so I just did
the attachment of ping listeners early here. It's also a little silly
since they will ping the currently running render for no reason if it's
synchronously available.~ EDIT: That didn't work because a ping might
interrupt the current render. Probably need a bigger refactor.

We could add another extension but we've already taken a lot of
liberties with the Promise protocol. At least this is one that doesn't
need extension of the protocol as much. Any sub-class of promises could
do this.

DiffTrain build for [9d111ffdfb](https://github.com/facebook/react/commit/9d111ffdfbcfee4b348a3d49c16f02cb718c896f)
[View git log for this commit](https://github.com/facebook/react/commits/9d111ffdfbcfee4b348a3d49c16f02cb718c896f)
2023-02-01 18:05:07 +00:00
eps1lon 7999f28011 Fix async test in React reconciler (#26087)
DiffTrain build for [0ba4698c7b](https://github.com/facebook/react/commit/0ba4698c7b178161ca8d9dded49d69a53ba3497a)
[View git log for this commit](https://github.com/facebook/react/commits/0ba4698c7b178161ca8d9dded49d69a53ba3497a)
2023-02-01 09:07:43 +00:00
sebmarkbage 10e3d0b7ff Move the Webpack manifest config to one level deeper (#26083)
This frees up the Webpack manifest to contain a `serverManifest` part
too.

@shuding

DiffTrain build for [8c234c0de9](https://github.com/facebook/react/commit/8c234c0de9be40dcb95f33fcefb57aed845d324b)
[View git log for this commit](https://github.com/facebook/react/commits/8c234c0de9be40dcb95f33fcefb57aed845d324b)
2023-02-01 04:41:25 +00:00
kassens c1de37709d Remove unused dependency 'abort-controller' (#26074)
## Summary
This PR removes the unused dependency 'abort-controller' from the
project. it helps to keep the project clean and maintainable.

## How did you test this change?
ci green

DiffTrain build for [8b9ac8175f](https://github.com/facebook/react/commit/8b9ac8175fb3052ba5c82f99003bb8ff667e1e68)
[View git log for this commit](https://github.com/facebook/react/commits/8b9ac8175fb3052ba5c82f99003bb8ff667e1e68)
2023-01-31 15:55:27 +00:00
kassens 7a99e9d094 [cleanup] Remove unused package jest-mock-scheduler (#26084)
## Summary

Removing package jest-mock-scheduler introduced in PR
https://github.com/facebook/react/pull/14358, as it is no longer
referenced in the main branch code. The following files previously
referenced it:

- packages/scheduler/src/__tests__/Scheduler-test.js
- packages/scheduler/src/__tests__/SchedulerDOM-test.js
- packages/shared/__tests__/ReactDOMFrameScheduling-test.js
- scripts/jest/setupTests.js
- scripts/rollup/bundles.js

## How did you test this change?

ci green

DiffTrain build for [d7bb524ade](https://github.com/facebook/react/commit/d7bb524ade26513ad310fedab5cad659012efd45)
[View git log for this commit](https://github.com/facebook/react/commits/d7bb524ade26513ad310fedab5cad659012efd45)
2023-01-31 15:30:51 +00:00
kassens 5bd4fb4b24 Upgrade prettier (#26081)
The old version of prettier we were using didn't support the Flow syntax
to access properties in a type using `SomeType['prop']`. This updates
`prettier` and `rollup-plugin-prettier` to the latest versions.

I added the prettier config `arrowParens: "avoid"` to reduce the diff
size as the default has changed in Prettier 2.0. The largest amount of
changes comes from function expressions now having a space. This doesn't
have an option to preserve the old behavior, so we have to update this.

DiffTrain build for [6b30832666](https://github.com/facebook/react/commit/6b3083266686f62b29462d32de75c6e71f7ba3e3)
[View git log for this commit](https://github.com/facebook/react/commits/6b3083266686f62b29462d32de75c6e71f7ba3e3)
2023-01-31 13:33:56 +00:00
kassens 1f2f55a72f [cleanup] fully roll out warnAboutSpreadingKeyToJSX (#26080)
I fully enabled this flag internally now and unless I see complications,
we should be able to clean this up in the code.

DiffTrain build for [1f5ce59dd7](https://github.com/facebook/react/commit/1f5ce59dd7b6869b1a17ede65aa301002ef31d4b)
[View git log for this commit](https://github.com/facebook/react/commits/1f5ce59dd7b6869b1a17ede65aa301002ef31d4b)
2023-01-30 20:33:31 +00:00