Commit Graph

15536 Commits

Author SHA1 Message Date
acdlite 55dcf28607 Fix: Selective hydration causing incorrect thenable type passed to DevTools (#26275)
Selective hydration is implemented by suspending the current render
using a special internal opaque object. This is conceptually similar to
suspending with a thenable in userspace, but the opaque object should
not leak outside of the reconciler.

We were accidentally passing this object to DevTool's
markComponentSuspended function, which expects an actual thenable. This
happens in the error handling path (handleThrow).

The fix is to check for the exception reason before calling
markComponentSuspended. There was already a naive check in place, but it
didn't account for all possible enum values of the exception reason.

DiffTrain build for [41110021f2](https://github.com/facebook/react/commit/41110021f28100b16c11d6d9a248582c5bb6bc3c)
2023-03-01 16:44:34 +00:00
sebmarkbage f091225e5c [Flight Fixture] Show SSR Support with CSS (#26263)
Builds on #26257.

To do this we need access to a manifest for which scripts and CSS are
used for each "page" (entrypoint).

The initial script to bootstrap the app is inserted with
`bootstrapScripts`. Subsequent content are loaded using the chunks
mechanism built-in.

The stylesheets for each pages are prepended to each RSC payload and
rendered using Float. This doesn't yet support styles imported in
components that are also SSR:ed nor imported through Server Components.
That's more complex and not implemented in the node loader.

HMR doesn't work after reloads right now because the SSR renderer isn't
hot reloaded because there's no idiomatic way to hot reload ESM modules
in Node.js yet. Without killing the HMR server. This leads to hydration
mismatches when reloading the page after a hot reload.

Notably this doesn't show serializing the stream through the HTML like
real implementations do. This will lead to possible hydration mismatches
based on the data. However, manually serializing the stream as a string
isn't exactly correct due to binary data. It's not the idiomatic way
this is supposed to work. This will all be built-in which will make this
automatic in the future.

DiffTrain build for [67a61d5bd7](https://github.com/facebook/react/commit/67a61d5bd7f731f5eb37d148dfc4ae0515a8c934)
2023-03-01 00:49:41 +00:00
sebmarkbage d23a4f28d1 [Flight Fixture] Proxy requests through the global server instead of directly (#26257)
This proxies requests through the global server instead of requesting
RSC responses from the regional server. This is a bit closer to
idiomatic, and closer to SSR.

This also wires up HMR using the Middleware technique instead of server.
This will be an important part of RSC compatibility because there will
be a `react-refresh` aspect to the integration.

This convention uses `Accept` header to branch a URL between HTML/RSC
but it could be anything really. Special headers, URLs etc. We might be
more opinionated about this in the future but now it's up to the router.

Some fixes for Node 16/17 support in the loader and fetch polyfill.

DiffTrain build for [40755c01a6](https://github.com/facebook/react/commit/40755c01a68de4b44bc24cca7f03a46140f31d5e)
2023-03-01 00:29:11 +00:00
sebmarkbage 58f6077667 Add preconnect and prefetchDNS to rendering-stub (#26265)
<!--
  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

Adding `preconnect` and `prefetchDNS` to rendering-stub build

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

DiffTrain build for [38509cce9b](https://github.com/facebook/react/commit/38509cce9b2f8b2046d2952645879e2f474ca745)
2023-02-28 22:32:48 +00:00
kassens 294d43d8f5 Cleanup enableSyncDefaultUpdate flag (#26236)
This feature flag is enabled everywhere.

DiffTrain build for [b2ae9ddb3b](https://github.com/facebook/react/commit/b2ae9ddb3b497d16a7c27c051da1827d08871138)
2023-02-27 19:10:00 +00:00
gnoff 0657099dd3 [Float][Fizz][Fiber] support type for ReactDOM.preload() options (#26239)
preloads often need to come with a type attribute which allows browsers
to decide if they support the preloading resource's type. If the type is
unsupported the preload will not be fetched by the Browser. This change
adds support for `type` in `ReactDOM.preload()` as a string option.

DiffTrain build for [6ff1733e63](https://github.com/facebook/react/commit/6ff1733e63fdb948ae973a713741b4526102c73c)
2023-02-25 19:11:08 +00:00
gnoff 81e2051235 [Float][Fizz][Fiber] implement preconnect and prefetchDNS float methods (#26237)
Adds two new ReactDOM methods

### `ReactDOM.prefetchDNS(href: string)`
In SSR this method will cause a `<link rel="dns-prefetch" href="..." />`
to flush before most other content both on intial flush (Shell) and late
flushes. It will only emit one link per href.

On the client, this method will case the same kind of link to be
inserted into the document immediately (when called during render, not
during commit) if there is not already a matching element in the
document.

### `ReactDOM.preconnect(href: string, options?: { crossOrigin?: string
})`
In SSR this method will cause a `<link rel="dns-prefetch" href="..."
[corssorigin="..."] />` to flush before most other content both on
intial flush (Shell) and late flushes. It will only emit one link per
href + crossorigin combo.

On the client, this method will case the same kind of link to be
inserted into the document immediately (when called during render, not
during commit) if there is not already a matching element in the
document.

DiffTrain build for [1173a17e6e](https://github.com/facebook/react/commit/1173a17e6eea08599005e9f8e7d7a4245783edba)
2023-02-25 19:09:37 +00:00
sebmarkbage 3b9bf7625d Move Flight Fixture to use Middleware instead of WebDevServer (#26246)
This lets us put it in the same server that would be serving this
content in a more real world scenario.

I also de-CRA:ified this a bit by simplifying pieces we don't need.

I have more refactors coming for the SSR pieces but since many are
eyeing these fixtures right now I figured I'd push earlier.

The design here is that there are two servers:

- Global - representing a "CDN" which will also include the SSR server.
- Regional - representing something close to the data with low waterfall
costs which include the RSC server.

This is just an example.

These are using the "unbundled" strategy for the RSC server just to show
a simple case, but an implementation can use a bundled SSR server.

A smart SSR bundler could also put RSC and SSR in the same server and
even the same JS environment. It just need to ensure that the module
graphs are kept separately - so that the `react-server` condition is
respected. This include `react` itself. React will start breaking if
this isn't respected because the runtime will get the wrong copy of
`react`. Technically, you don't need the *entire* module graph to be
separated. It just needs to be any part of the graph that depends on a
fork. Like if "Client A" -> "foo" and "Server B" -> "foo", then it's ok
for the module "foo" to be shared. However if "foo" -> "bar", and "bar"
is forked by the "react-server" condition, then "foo" also needs to be
duplicated in the module graph so that it can get two copies of "bar".

DiffTrain build for [e7d7d4cb4b](https://github.com/facebook/react/commit/e7d7d4cb4b61624c5762521370a58d941c1c46e3)
2023-02-25 17:15:36 +00:00
mondaychen fb32e1b170 [DevTools] remove script tag immediately (#26233)
Fixes https://github.com/facebook/react/issues/25924 for React DevTools
specifically.

## Summary

If we remove the script after it's loaded, it creates a race condition
with other code. If some other code is searching for the first script
tag or first element of the document, this might broke it.

## How did you test this change?

I've tested in my local build that even if we remove the script tag
immediately, the code is still correctly executed.

DiffTrain build for [564166099b](https://github.com/facebook/react/commit/564166099b5f46dd33f3356b01a72c0314103a18)
2023-02-24 20:21:01 +00:00
sophiebits 5ae58c5e52 Switch to mount dispatcher after use() when needed (#26232)
When resuming a suspended render, there may be more Hooks to be called
that weren't seen the previous time through. Make sure to switch to the
mount dispatcher when calling use() if the next Hook call should be
treated as a mount.

Fixes #25964.

DiffTrain build for [a8f971b7a6](https://github.com/facebook/react/commit/a8f971b7a669a9a6321b9f3cea820f68b2e4ac6e)
2023-02-24 20:11:41 +00:00
sophiebits a1ece33413 [Fizz Node] Fix null bytes written at text chunk boundaries (#26228)
We encode strings 2048 UTF-8 bytes at a time. If the string we are
encoding crosses to the next chunk but the current chunk doesn't fit an
integral number of characters, we need to make sure not to send the
whole buffer, only the bytes that are actually meaningful.

Fixes #24985. I was able to verify that this fixes the repro shared in
the issue (be careful when testing because the null bytes do not show
when printed to my terminal, at least). However, I don't see a clear way
to add a test for this that will be resilient to small changes in how we
encode the markup (since it depends on where specific multibyte
characters fall against the 2048-byte boundaries).

DiffTrain build for [96cdeaf89b](https://github.com/facebook/react/commit/96cdeaf89bfde7551b4ffe4d685da169b780f2f7)
2023-02-24 19:38:44 +00:00
mondaychen f007bf82e7 [DevTools] permanently polyfill for rAF in devtools_page (#26193)
## Summary

We had this as a temporary fix for #24626. Now that Chrome team decides
to turn the flag on again (with good reasons explained in
https://bugs.chromium.org/p/chromium/issues/detail?id=1241986#c31), we
will turn it into a long term solution.
In the future, we want to explore whether we can render React elements
on panel.html instead, as `requestAnimationFrame` produces higher
quality animation.

## How did you test this change?

Tested on local build with "Throttle non-visible cross-origin iframes"
flag enabled.

DiffTrain build for [ca2cf319fd](https://github.com/facebook/react/commit/ca2cf319fdfcf6e5f048e082f5169bc1b849c129)
2023-02-23 21:59:14 +00:00
poteto 56ece5204c [difftrain] Make github sha clickable for easier debugging (#26225)
DiffTrain build for [bfb9cbd8ca](https://github.com/facebook/react/commit/bfb9cbd8ca2d042677056110887cc62d438f665f)
2023-02-23 16:05:29 +00:00
acdlite e246c05ebf Remove eventTime field from class Update type (#26219)
`eventTime` is a vestigial field that can be cleaned up. It was
originally used as part of the starvation mechanism but it's since been
replaced by a per-lane field on the root.

This is a part of a series of smaller refactors I'm doing to
simplify/speed up the `setState` path, related to the Sync Unification
project that @tyao1 has been working on.

DiffTrain build for commit c04b180701.
2023-02-22 20:37:03 +00:00
eps1lon b6024b9b77 Bug: yarn flow dom does not exist, so console should suggest yarn flow dom-node (#26213)
<!--
  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
The `yarn flow` command, as suggested for every PR Submission (Task No.
9), tells us `The yarn flow command now requires you to pick a primary
renderer` and provides a list for the same. However, in at the bottom of
the prompt, it suggests `If you are not sure, run yarn flow dom`. This
command `yarn flow dom` does not exist in the list and thus the command
does nothing and exits with `status code 1` without any flow test.

<!--
Explain the **motivation** for making this change. What existing problem
does the pull request solve?
-->
While trying to submit a different PR for code cleaning, just during
submission I read the PR Guidelines, and while doing `yarn test`, `yarn
lint`, and `yarn flow`, I came across this issue and thought of
submitting a PR for the same.

## How did you test this change?
Since this code change does not change any logic, just the text
information, I only ran `yarn linc` and `yarn test` for the same.

<!--
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.
-->
Here is how the issue currently looks like:

![facebook yarn flow
dom](https://user-images.githubusercontent.com/20269286/220337686-b8a9b786-92e0-4c66-88a9-e94bfbed6edf.JPG)

Signed-off-by: abhiram11 <abhiramsatpute@gmail.com>
Co-authored-by: abhiram11 <abhiramsatpute@gmail.com>

DiffTrain build for commit 212b89fa25.
2023-02-21 20:36:48 +00:00
sebmarkbage 7df133e42a Copy from build to node_modules instead of linking to builds (#26210)
Using the `link:` protocol to create a dependency doesn't work when we
edit the `package.json` to lock the version to a specific version. It
didn't really work before neither, it was just that `yarn` installed an
existing `scheduler` dependency from npm instead of using the built one.

So I'm updating all the fixture to use the technique where we copy files
instead.

DiffTrain build for commit 0a76fb9ec4.
2023-02-21 19:53:28 +00:00
sebmarkbage 466df59134 Rename yarn start to yarn dev and yarn start:prod to yarn start (#26209)
The `start` convention is a CRA convention but nobody else of the modern
frameworks / tools use this convention for a file watcher and dev mode.
Instead the common convention is `dev`. Instead `start` is for running a
production build that's already been built.

---------

Co-authored-by: Sebastian Silbermann <silbermann.sebastian@gmail.com>

DiffTrain build for commit c8d4eeda5f.
2023-02-21 19:23:25 +00:00
sebmarkbage 186e383fbc Split out Edge and Node implementations of the Flight Client (#26187)
This splits out the Edge and Node implementations of Flight Client into
their own implementations. The Node implementation now takes a Node
Stream as input.

I removed the bundler config from the Browser variant because you're
never supposed to use that in the browser since it's only for SSR.
Similarly, it's required on the server. This also enables generating a
SSR manifest from the Webpack plugin. This is necessary for SSR so that
you can reverse look up what a client module is called on the server.

I also removed the option to pass a callServer from the server. We might
want to add it back in the future but basically, we don't recommend
calling Server Functions from render for initial render because if that
happened client-side it would be a client-side waterfall. If it's never
called in initial render, then it also shouldn't ever happen during SSR.
This might be considered too restrictive.

~This also compiles the unbundled packages as ESM. This isn't strictly
necessary because we only need access to dynamic import to load the
modules but we don't have any other build options that leave
`import(...)` intact, and seems appropriate that this would also be an
ESM module.~ Went with `import(...)` in CJS instead.

DiffTrain build for commit 60144a04da.
2023-02-21 18:23:17 +00:00
mofeiZ 1041fb1a19 [fizz][external-runtime] Fix: process mutation records before disconnecting (#26169)
> All notifications of mutations that have already been detected, but
not yet reported to the observer, are discarded. To hold on to and
handle the detected but unreported mutations, use the takeRecords()
method.
>    -- ([Mozilla docs for disconnect](

https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver/disconnect))

Fizz external runtime needs to process mutation records (representing
potential Fizz instructions) before calling `disconnect()`. We currently
do not do this (and might drop some instructions).

DiffTrain build for commit 70b0bbda76.
2023-02-21 17:16:12 +00:00
eps1lon d8eed112dc Distribute bundles more evenly into CI shards (#26208)
## Summary

Previously, we distributed bundles into shards and then checked if we
need to actually build that bundle. This can under-utilize shards
heavily (e.g.
https://app.circleci.com/pipelines/github/facebook/react/38611/workflows/df9e56e7-d476-49ee-9392-d8b37c81aa66/jobs/630545/parallel-runs/28?filterBy=ALL
only building a single bundle).

This won't result in an optimal distribution but, if we're lucky, we
might end up with shard #26 not taking 7mins anymore. The slowest shard
ultimately decicdes when we can start with testing builds.

## How did you test this change?

- [x] `CIRCLE_NODE_INDEX=28 CIRCLE_NODE_TOTAL=40 yarn build` building
more than 1 bundle
- [x] Check timings of `yarn_build` so that we don't up with an
over-stuffed shard (e.g. a shard having to build all the expensive
bundles). Casually dropping 60min idle time 🎉:
- Before:
https://app.circleci.com/pipelines/github/facebook/react/38683/workflows/a41533d7-811c-439d-9751-214ba06035c5/jobs/632230/timing
- After:
https://app.circleci.com/pipelines/github/facebook/react/38686/workflows/8a770df6-5b3e-41ea-b3b5-10abeae703e7/jobs/632247/timing

DiffTrain build for commit c7967b194b.
2023-02-20 21:22:13 +00:00
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