Compare commits

...

6241 Commits

Author SHA1 Message Date
Mike Vitousek
25835c3bca [compiler] useMemo calls directly induce memoization blocks
[ghstack-poisoned]
2024-06-30 23:51:22 -07:00
Mike Vitousek
d6b1c488d4 [compiler] Clone computation block in change detection mode
Summary: In change-detection mode, we previously were spreading the contents of the computation block into the result twice. Other babel passes that cause in-place mutations of the AST would then be causing action at a distance and breaking the overall transform result. This pr creates clones of the nodes instead, so that mutations aren't reflected in both places where the block is used.

ghstack-source-id: b78def8d8d1b8f9978df0a231f64fdeda786a3a3
Pull Request resolved: https://github.com/facebook/react/pull/30148
2024-06-30 22:43:32 -07:00
Mike Vitousek
05cebffe16 [prettier][eslint] Support sapling in prettier changed files command
Summary: The listChangesFiles module didn't work under sapling; this fixes

ghstack-source-id: 9f685de5e7
Pull Request resolved: https://github.com/facebook/react/pull/30149
2024-06-30 14:22:22 -07:00
Sebastian Markbåge
2e72ea8401 [Flight] Make byteLengthOfChunk Optional (#30130)
We use this to encode the binary length of a large string without
escaping it. This is really kind of optional though. This lets a Server
that can't encode strings but just pass them along able to emit RSC -
albeit a less optimal format.

The only build we have that does that today is react-html but the FB
version of Flight had a similar constraint.

It's still possible to support binary data as long as
byteLengthOfBinaryChunk is implemented which doesn't require a text
encoder. Many streams (including Node streams) support binary OR string
chunks.
2024-06-28 13:42:17 -04:00
Sebastian Markbåge
58af67a8f8 Only build react-html in experimental channel (#30129)
Even though the whole package is private right now. Once we publish it,
it'll likely be just the experimental channel first before upgrading to
stable.

This means it gets excluded from the built packages.
2024-06-28 10:19:20 -04:00
Sebastian Markbåge
0d1fdb5c2e Add doctype to renderToMarkup when html tags are rendered (#30122)
Stacked on top of #30121.

This is the same thing we do for `renderToReadableStream` so that you
don't have to manually inject it into the stream.

The only reason we didn't for `renderToString` / `renderToStaticMarkup`
was to preserve legacy behavior but since this is a new API we can
change that.

If you're rendering a partial it doesn't matter. This is likely what
you'd do for RSS feeds. The question is if you can reliably rely on the
doctype being used while rendering e-mails since many clients are so
quirky. However, if you're careful it also doesn't hurt so it seems best
to include it.
2024-06-28 09:35:12 -04:00
Sebastian Markbåge
1e241f9d6c Add renderToMarkup for Client Components (#30121)
Follow up to #30105.

This supports `renderToMarkup` in a non-RSC environment (not the
`react-server` condition).

This is just a Fizz renderer but it errors at runtime when you use
state, effects or event handlers that would require hydration - like the
RSC version would. (Except RSC can give early errors too.)

To do this I have to move the `react-html` builds to a new `markup`
dimension out of the `dom-legacy` dimension so that we can configure
this differently from `renderToString`/`renderToStaticMarkup`.
Eventually that dimension can go away though if deprecated. That also
helps us avoid dynamic configuration and we can just compile in the
right configuration so the split helps anyway.

One consideration is that if a compiler strips out useEffects or inlines
initial state from useState, then it would not get called an the error
wouldn't happen. Therefore to preserve semantics, a compiler would need
to inject some call that can check the current renderer and whether it
should throw.

There is an argument that it could be useful to not error for these
because it's possible to write components that works with SSR but are
just optionally hydrated. However, there's also an argument that doing
that silently is too easy to lead to mistakes and it's better to error -
especially for the e-mail use case where you can't take it back but you
can replay a queue that had failures. There are other ways to
conditionally branch components intentionally. Besides if you want it to
be silent you can still use renderToString (or better yet
renderToReadableStream).

The primary mechanism is the RSC environment and the client-environment
is really the secondary one that's only there to support legacy
environments. So this also ensures parity with the primary environment.
2024-06-28 09:25:10 -04:00
Sharath
b3aface19a [fix] replace polyfill.io with cloudflare equivalent (#30123) 2024-06-28 10:26:28 +02:00
Sebastian Markbåge
e02baf6c92 Warn for invalid type in renderer with the correct RSC stack (#30102)
This is all behind the `enableOwnerStacks` flag.

This is a follow up to #29088. In that I moved type validation into the
renderer since that's the one that knows what types are allowed.
However, I only removed it from `React.createElement` and not the JSX
which was an oversight.

However, I also noticed that for invalid types we don't have the right
stack trace for throws because we're not yet inside the JSX element that
itself is invalid. We should use its stack for the stack trace. That's
the reason it's enough to just use the throw now because we can get a
good stack trace from the owner stack. This is fixed by creating a fake
Throw Fiber that gets assigned the right stack.

Additionally, I noticed that for certain invalid types like the most
common one `undefined` we error in Flight so a missing import in RSC
leads to a generic error. Instead of erroring on the Flight side we
should just let anything that's not a Server Component through to the
client and then let the Client renderer determine whether it's a valid
type or not. Since we now have owner stacks through the server too, this
will still be able to provide a good stack trace on the client that
points to the server in that case.

<img width="571" alt="Screenshot 2024-06-25 at 6 46 35 PM"
src="https://github.com/facebook/react/assets/63648/6812c24f-e274-4e09-b4de-21deda9ea1d4">

To get the best stack you have to expand the little icon and the regular
stack is noisy [due to this Chrome
bug](https://issues.chromium.org/issues/345248263) which makes it a
little harder to find but once that's fixed it might be easier.
2024-06-27 12:10:09 -04:00
Sebastian Markbåge
ffec9ec5b5 Add new package with renderToMarkup export (#30105)
Name of the package is tbd (straw: `react-html`). It's a new package
separate from `react-dom` though and can be used as a standalone package
- e.g. also from a React Native app.

```js
import {renderToMarkup} from '...';
const html = await renderToMarkup(<Component />);
```

The idea is that this is a helper for rendering HTML that is not
intended to be hydrated. It's primarily intended to support a subset of
HTML that can be used as embedding and not served as HTML documents from
HTTP. For example as e-mails or in RSS/Atom feeds or other
distributions. It's a successor to `renderToStaticMarkup`.

A few differences:

- This doesn't support "Client Components". It can only use the Server
Components subset. No useEffect, no useState etc. since it will never be
hydrated. Use of those are errors.
- You also can't pass Client References so you can't use components
marked with `"use client"`.
- Unlike `renderToStaticMarkup` this does support async so you can
suspend and use data from these components.
- Unlike `renderToReadableStream` this does not support streaming or
Suspense boundaries and any error rejects the promise. Since there's no
feasible way to "client render" or patch up the document.
- Form Actions are not supported since in an embedded environment
there's no place to post back to across versions. You can render plain
forms with fixed URLs though.
- You can't use any resource preloading like `preload()` from
`react-dom`.

## Implementation

This first version in this PR only supports Server Components since
that's the thing that doesn't have an existing API. Might add a Client
Components version later that errors.

We don't want to maintain a completely separate implementation for this
use case so this uses the `dom-legacy` build dimension to wire up a
build that encapsulates a Flight Server -> Flight Client -> Fizz stream
to render Server Components that then get SSR:ed.

There's no problem to use a Flight Client in a Server Component
environment since it's already supported for Server-to-Server. Both of
these use a bundler config that just errors for Client References though
since we don't need any bundling integration and this is just a
standalone package.

Running Fizz in a Server Component environment is a problem though
because it depends on "react" and it needs the client version.
Therefore, for this build we embed the client version of "react" shared
internals into the build. It doesn't need anything to be able to use
those APIs since you can't call the client APIs anyway.

One unfortunate thing though is that since Flight currently needs to go
to binary and back, we need TextEncoder/TextDecoder to be available but
this shouldn't really be necessary. Also since we use the legacy stream
config, large strings that use byteLengthOfChunk errors atm. This needs
to be fixed before shipping. I'm not sure what would be the best
layering though that isn't unnecessarily burdensome to maintain. Maybe
some kind of pass-through protocol that would also be useful in general
- e.g. when Fizz and Flight are in the same process.

---------

Co-authored-by: Sebastian Silbermann <silbermann.sebastian@gmail.com>
2024-06-27 12:09:40 -04:00
Sebastian Markbåge
3bee073c01 Remove isPrimaryRenderer from Flight Server Config (#30115)
This was used for Context but since ReactFlightNewContext is gone now
this is no longer used.
2024-06-27 12:08:56 -04:00
dependabot[bot]
f5a22fa27d Bump ws from 7.2.1 to 7.5.10 (#29919)
Bumps [ws](https://github.com/websockets/ws) from 7.2.1 to 7.5.10.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a
href="https://github.com/websockets/ws/releases">ws's
releases</a>.</em></p>
<blockquote>
<h2>7.5.10</h2>
<h1>Bug fixes</h1>
<ul>
<li>Backported e55e5106 to the 7.x release line (22c28763).</li>
</ul>
<h2>7.5.9</h2>
<h1>Bug fixes</h1>
<ul>
<li>Backported bc8bd34e to the 7.x release line (0435e6e1).</li>
</ul>
<h2>7.5.8</h2>
<h1>Bug fixes</h1>
<ul>
<li>Backported 0fdcc0af to the 7.x release line (2758ed35).</li>
<li>Backported d68ba9e1 to the 7.x release line (dc1781bc).</li>
</ul>
<h2>7.5.7</h2>
<h1>Bug fixes</h1>
<ul>
<li>Backported 6946f5fe to the 7.x release line (1f72e2e1).</li>
</ul>
<h2>7.5.6</h2>
<h1>Bug fixes</h1>
<ul>
<li>Backported b8186dd1 to the 7.x release line (73dec34b).</li>
<li>Backported ed2b8039 to the 7.x release line (22a26afb).</li>
</ul>
<h2>7.5.5</h2>
<h1>Bug fixes</h1>
<ul>
<li>Backported ec9377ca to the 7.x release line (0e274acd).</li>
</ul>
<h2>7.5.4</h2>
<h1>Bug fixes</h1>
<ul>
<li>Backported 6a72da3e to the 7.x release line (76087fbf).</li>
<li>Backported 869c9892 to the 7.x release line (27997933).</li>
</ul>
<h2>7.5.3</h2>
<h1>Bug fixes</h1>
<ul>
<li>The <code>WebSocketServer</code> constructor now throws an error if
more than one of the
<code>noServer</code>, <code>server</code>, and <code>port</code>
options are specefied (66e58d27).</li>
<li>Fixed a bug where a <code>'close'</code> event was emitted by a
<code>WebSocketServer</code> before
the internal HTTP/S server was actually closed (5a587304).</li>
<li>Fixed a bug that allowed WebSocket connections to be established
after
<code>WebSocketServer.prototype.close()</code> was called
(772236a1).</li>
</ul>
<h2>7.5.2</h2>
<h1>Bug fixes</h1>
<!-- raw HTML omitted -->
</blockquote>
<p>... (truncated)</p>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="d962d70649"><code>d962d70</code></a>
[dist] 7.5.10</li>
<li><a
href="22c2876323"><code>22c2876</code></a>
[security] Fix crash when the Upgrade header cannot be read (<a
href="https://redirect.github.com/websockets/ws/issues/2231">#2231</a>)</li>
<li><a
href="8a78f87706"><code>8a78f87</code></a>
[dist] 7.5.9</li>
<li><a
href="0435e6e12b"><code>0435e6e</code></a>
[security] Fix same host check for ws+unix: redirects</li>
<li><a
href="4271f07cfc"><code>4271f07</code></a>
[dist] 7.5.8</li>
<li><a
href="dc1781bc31"><code>dc1781b</code></a>
[security] Drop sensitive headers when following insecure redirects</li>
<li><a
href="2758ed3550"><code>2758ed3</code></a>
[fix] Abort the handshake if the Upgrade header is invalid</li>
<li><a
href="a370613fab"><code>a370613</code></a>
[dist] 7.5.7</li>
<li><a
href="1f72e2e14f"><code>1f72e2e</code></a>
[security] Drop sensitive headers when following redirects (<a
href="https://redirect.github.com/websockets/ws/issues/2013">#2013</a>)</li>
<li><a
href="8ecd890800"><code>8ecd890</code></a>
[dist] 7.5.6</li>
<li>Additional commits viewable in <a
href="https://github.com/websockets/ws/compare/7.2.1...7.5.10">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=ws&package-manager=npm_and_yarn&previous-version=7.2.1&new-version=7.5.10)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)
You can disable automated security fix PRs for this repo from the
[Security Alerts
page](https://github.com/facebook/react/network/alerts).

</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-06-27 10:07:09 -04:00
Mike Vitousek
fcfbfc1d1e [compiler] Always error on async reassignments
Summary: Addresses the issue in #30109: any mutation of a local in an async function may occur after rendering has finished.

ghstack-source-id: 9f15cf0f14
Pull Request resolved: https://github.com/facebook/react/pull/30111
2024-06-26 17:07:40 -07:00
Mike Vitousek
1f59d07042 [compiler] Repro for nested function local reassignment issue
Summary: Additional repro demonstrating a case that still exists after #30106

ghstack-source-id: f03176fd88
Pull Request resolved: https://github.com/facebook/react/pull/30110
2024-06-26 17:07:38 -07:00
Joe Savona
00775d94dc [compiler] Add todo fixtures for local reassignment in an async callback
ghstack-source-id: eca878f62a2149af76a72b59acd1820d0df86f30
Pull Request resolved: https://github.com/facebook/react/pull/30109
2024-06-26 16:51:15 -07:00
Joe Savona
4c9a2d2ddf [compiler] Validate against locals being reassigned after render
Adds a pass which validates that local variables are not reassigned by functions which may be called after render. This is a straightforward forward data-flow analysis, where we:
1. Build up a mapping of context variables in the outer component/hook
2. Find ObjectMethod/FunctionExpressions which may reassign those context variables
3. Propagate aliases of those functions via StoreLocal/LoadLocal
4. Disallow passing those functions with a Freeze effect. This includes JSX arguments, hook arguments, hook return types, etc.

Conceptually, a function that reassigns a local is inherently mutable. Frozen functions must be side-effect free, so these two categories are incompatible and we can use the freeze effect to find all instances of where such functions are disallowed rather than special-casing eg hook calls and JSX.

ghstack-source-id: c2b22e3d62a1ab490a6a2150e28b934b9dc8676b
Pull Request resolved: https://github.com/facebook/react/pull/30107
2024-06-26 16:51:15 -07:00
Joe Savona
b1d10c8a45 [compiler] Examples of invalid code reassigning locals outside of render
ghstack-source-id: c48d0d0b86e47e2449982263c88cc2cfd44e326b
Pull Request resolved: https://github.com/facebook/react/pull/30106
2024-06-26 16:51:15 -07:00
Jan Kassens
8416ebee38 Update ReactFabric-test.internal to concurrent root (#30103) 2024-06-26 16:04:38 -04:00
Jiachi Liu
609d0cc3c8 Add new error message for awaiting the client export (#29853)
<!--
  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

`Cannot access .then on server` is not an ideal message when you try to
await or do promise chain to the properties of client reference. The
below example will let `.then` get accessed by native code while
handling the promise chain but the access is not clearly visible in user
code.

```
import('./client-module').then((mod) => mod.Component)
```

This PR chnage the error message of module reference proxy '.then'
property to show more kinds of usage, then it can be pretty clearly for
helping users to avoid the bad usage

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

## How did you test this change?

Unit test

<!--
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.
-->
2024-06-26 13:47:39 -04:00
Sebastian Markbåge
349a99a7a3 Badge Environment Name on Thrown Errors from the Server (#29846)
When we replay logs we badge them with e.g. `[Server]`. That way it's
easy to identify that the source of the log actually happened on the
Server (RSC). However, when we threw an error we didn't have any such
thing. The error was rethrown on the client and then handled just like
any other client error.

This transfers the `environmentName` in DEV to our restored Error
"sub-class" (conceptually) along with `digest`. That way you can read
`error.environmentName` to print this in your own UI.

I also updated our default for `onCaughtError` (and `onError` in Fizz)
to use the `printToConsole` helper that the Flight Client uses to log it
with the badge format. So by default you get the same experience as
console.error for caught errors:

<img width="810" alt="Screenshot 2024-06-10 at 9 25 12 PM"
src="https://github.com/facebook/react/assets/63648/8490fedc-09f6-4286-9332-fbe6b0faa2d3">

<img width="815" alt="Screenshot 2024-06-10 at 9 39 30 PM"
src="https://github.com/facebook/react/assets/63648/bdcfc554-504a-4b1d-82bf-b717e74975ac">

Unfortunately I can't do the same thing for `onUncaughtError` nor
`onRecoverableError` because they use `reportError` which doesn't have
custom formatting (unless we also prevented default on window.onerror).
However maybe that's ok because 1) you should always have an error
boundary 2) it's not likely that an RSC error can actually recover
because it's not going to be rendered again so shouldn't really happen
outside some parent conditionally rendering maybe.

The other problem with this approach is that the default is no longer
trivial - so reimplementing the default in user space is trickier and
ideally we shouldn't expose our default to be called.
2024-06-26 13:27:26 -04:00
Jan Kassens
7045700a6d Run ReactFabric-test.internal.js in xplat variant (#30101)
The explicit mock override in this test was causing it to always run as
native-oss instead of also as xplat. This moves the test to use `//
@gate persistent` instead to run it in all persistent configs.
2024-06-26 12:51:46 -04:00
Timothy Yung
ef0f44ecff Enable enableDeferRootSchedulingToMicrotask and enableInfiniteRenderLoopDetection for React Native (Meta) (#30090) 2024-06-26 08:50:06 -07:00
Sol Lee
7baae65e76 compiler: fix the hookKind for useInsertionEffect (#30069)
Currently, the `hookKind` for `useInsertionEffect` is set to
`useLayoutEffect`. This pull request fixes it by adding a new `hookKind`
for `useInsertionEffect`.
2024-06-26 14:59:03 +01:00
dependabot[bot]
bbc8851c84 Bump ws from 8.13.0 to 8.17.1 in /compiler (#30043)
Bumps [ws](https://github.com/websockets/ws) from 8.13.0 to 8.17.1.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a
href="https://github.com/websockets/ws/releases">ws's
releases</a>.</em></p>
<blockquote>
<h2>8.17.1</h2>
<h1>Bug fixes</h1>
<ul>
<li>Fixed a DoS vulnerability (<a
href="https://redirect.github.com/websockets/ws/issues/2231">#2231</a>).</li>
</ul>
<p>A request with a number of headers exceeding
the[<code>server.maxHeadersCount</code>][]
threshold could be used to crash a ws server.</p>
<pre lang="js"><code>const http = require('http');
const WebSocket = require('ws');
<p>const wss = new WebSocket.Server({ port: 0 }, function () {
const chars =
&quot;!#$%&amp;'*+-.0123456789abcdefghijklmnopqrstuvwxyz^_`|~&quot;.split('');
const headers = {};
let count = 0;</p>
<p>for (let i = 0; i &lt; chars.length; i++) {
if (count === 2000) break;</p>
<pre><code>for (let j = 0; j &amp;lt; chars.length; j++) {
  const key = chars[i] + chars[j];
  headers[key] = 'x';

  if (++count === 2000) break;
}
</code></pre>
<p>}</p>
<p>headers.Connection = 'Upgrade';
headers.Upgrade = 'websocket';
headers['Sec-WebSocket-Key'] = 'dGhlIHNhbXBsZSBub25jZQ==';
headers['Sec-WebSocket-Version'] = '13';</p>
<p>const request = http.request({
headers: headers,
host: '127.0.0.1',
port: wss.address().port
});</p>
<p>request.end();
});
</code></pre></p>
<p>The vulnerability was reported by <a
href="https://github.com/rrlapointe">Ryan LaPointe</a> in <a
href="https://redirect.github.com/websockets/ws/issues/2230">websockets/ws#2230</a>.</p>
<p>In vulnerable versions of ws, the issue can be mitigated in the
following ways:</p>
<ol>
<li>Reduce the maximum allowed length of the request headers using the
[<code>--max-http-header-size=size</code>][] and/or the
[<code>maxHeaderSize</code>][] options so
that no more headers than the <code>server.maxHeadersCount</code> limit
can be sent.</li>
</ol>
<!-- raw HTML omitted -->
</blockquote>
<p>... (truncated)</p>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="3c56601092"><code>3c56601</code></a>
[dist] 8.17.1</li>
<li><a
href="e55e5106f1"><code>e55e510</code></a>
[security] Fix crash when the Upgrade header cannot be read (<a
href="https://redirect.github.com/websockets/ws/issues/2231">#2231</a>)</li>
<li><a
href="6a00029edd"><code>6a00029</code></a>
[test] Increase code coverage</li>
<li><a
href="ddfe4a804d"><code>ddfe4a8</code></a>
[perf] Reduce the amount of <code>crypto.randomFillSync()</code>
calls</li>
<li><a
href="b73b11828d"><code>b73b118</code></a>
[dist] 8.17.0</li>
<li><a
href="29694a5905"><code>29694a5</code></a>
[test] Use the <code>highWaterMark</code> variable</li>
<li><a
href="934c9d6b93"><code>934c9d6</code></a>
[ci] Test on node 22</li>
<li><a
href="1817bac06e"><code>1817bac</code></a>
[ci] Do not test on node 21</li>
<li><a
href="96c9b3dedd"><code>96c9b3d</code></a>
[major] Flip the default value of <code>allowSynchronousEvents</code>
(<a
href="https://redirect.github.com/websockets/ws/issues/2221">#2221</a>)</li>
<li><a
href="e5f32c7e1e"><code>e5f32c7</code></a>
[fix] Emit at most one event per event loop iteration (<a
href="https://redirect.github.com/websockets/ws/issues/2218">#2218</a>)</li>
<li>Additional commits viewable in <a
href="https://github.com/websockets/ws/compare/8.13.0...8.17.1">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=ws&package-manager=npm_and_yarn&previous-version=8.13.0&new-version=8.17.1)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)
You can disable automated security fix PRs for this repo from the
[Security Alerts
page](https://github.com/facebook/react/network/alerts).

</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-06-26 09:56:13 -04:00
Ruslan Lesiutin
a8b465c6e0 fix[react-devtools]: restore original args when recording errors (#30091)
## Summary

When DevTools frontend and backend are connected, we patch console in 2
places:
- `patch()`, when renderer is attached to:
  - listen to any errors / warnings emitted
  - append component stack if requested by the user
- `patchForStrictMode()`, when React notifies about that the next
invocation is about to happed during StrictMode

`patchForStrictMode()` will always be at the top of the patch stack,
because it is called at runtime when React notifies React DevTools,
because of this, `patch()` may receive already modified arguments (with
stylings for dimming), we should attempt to restore the original
arguments

## How did you test this change?

Look at yellow warnings on the element view:
| Before | After |
| --- | --- |
| ![Screenshot 2024-06-25 at 14 38
26](https://github.com/facebook/react/assets/28902667/6b0ec512-f0c9-4557-a524-d7f31b03464d)
| ![Screenshot 2024-06-25 at 17 26
23](https://github.com/facebook/react/assets/28902667/60ff5d80-06ea-4447-bbe8-b57bc0c63f6d)
|
2024-06-26 14:17:09 +01:00
Mofei Zhang
d878489431 [compiler][ez] PrintHIR prints optional flag for debugging
Adding the equivalent of [PrintReactiveFunction:OptionalExpression](f5d2feb4f0/compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/PrintReactiveFunction.ts (L218)) to `PrintHIR`.

ghstack-source-id: 5b175f6f62
Pull Request resolved: https://github.com/facebook/react/pull/30078
2024-06-25 17:00:14 -04:00
Mofei Zhang
4bfab07832 [compiler][patch] Patch O(n^2) traversal in validatePreserveMemo
Double checked by syncing internally and verifying the # of `visitInstruction` calls with unique `InstructionId`s.

This is a bit of an awkward pattern though. A cleaner alternative might be to override `visitValue` and store its results in a sidemap (instead of returning)

ghstack-source-id: f6797d7652
Pull Request resolved: https://github.com/facebook/react/pull/30077
2024-06-25 17:00:14 -04:00
Mofei Zhang
7d9861e706 [compiler][hir] Correctly remove non-existent terminal preds when pruning labels
Missed this initially in `pruneUnusedLabelsHIR`. It wasn't an active bug as `preds` wasn't referenced by later passes, until #30079

ghstack-source-id: 3e151b74c3
Pull Request resolved: https://github.com/facebook/react/pull/30076
2024-06-25 17:00:13 -04:00
Mofei Zhang
9262761f1c [compiler][ez] Add more Array.prototype methods
Adds Array.prototype methods that return primitives or other arrays -- naive type inference can be really helpful in reducing mutable ranges -> achieving higher quality memoization.
Also copies Array.prototype methods to our mixed read-only JSON-like object shape.

(Inspired after going through some suboptimal internal compilation outputs.)

ghstack-source-id: 0bfad11180
Pull Request resolved: https://github.com/facebook/react/pull/30075
2024-06-25 17:00:13 -04:00
Mofei Zhang
9c2c7c670c [compiler][ez] Patch Array.concat object shape to capture callee
ghstack-source-id: 503fbf8f76
Pull Request resolved: https://github.com/facebook/react/pull/30074
2024-06-25 17:00:13 -04:00
Mofei Zhang
86d1a6f54a [compiler][rewrite] Patch logic for aligning scopes to non-value blocks
Our previous logic for aligning scopes to block scopes constructs a tree of block and scope nodes. We ensured that blocks always mapped to the same node as their fallthroughs. e.g.
```js
// source
a();
if (...) {
  b();
}
c();

// HIR
bb0:
a()
if test=... consequent=bb1 fallthrough=bb2

bb1:
b()
goto bb2

bb2:
c()

// AlignReactiveScopesToBlockScopesHIR nodes
Root node (maps to both bb0 and bb2)
  |- bb1
  |- ...
```

There are two issues with the existing implementation:
1. Only scopes that overlap with the beginning of a block are aligned correctly. This is because the traversal does not store information about the block-fallthrough pair for scopes that begin *within* the block-fallthrough range.
```
\# This case gets handled correctly
         ┌──────────────┐
         │              │
         block start    block end

scope start     scope end
│               │
└───────────────┘

\# But not this one!
┌──────────────┐
│              │
block start    block end

          scope start     scope end
          │               │
          └───────────────┘
```
2. Only scopes that are directly used by a block is considered. See the `align-scopes-nested-block-structure` fixture for details.

ghstack-source-id: 327dec5019
Pull Request resolved: https://github.com/facebook/react/pull/29891
2024-06-25 17:00:13 -04:00
Mofei Zhang
4d11e1e88d [compiler][fixtures] test repros: codegen, alignScope, phis
ghstack-source-id: 04b1526c85
Pull Request resolved: https://github.com/facebook/react/pull/29878

The AlignReactiveScope bug should be simplest to fix, but it's also caught by an invariant assertion. I think a fix could be either keeping track of "active" block-fallthrough pairs (`retainWhere(pair => pair.range.end > current.instr[0].id)`) or following the approach in `assertValidBlockNesting`.
I'm tempted to pull the value-block aligning logic out into its own pass (using the current `node` tree traversal), then align to non-value blocks with the `assertValidBlockNesting` approach. Happy to hear feedback on this though!

The other two are likely bigger issues, as they're not caught by static invariants.

Update:
- removed bug-phi-reference-effect as it's been patched by @josephsavona
- added bug-array-concat-should-capture
2024-06-25 17:00:13 -04:00
LoganDark
133ada7254 Read constructor name more carefully (#29954)
## Summary

Sometimes `constructor` happens to be the name of an unrelated property,
or we may be dealing with a `Proxy` that intercepts every read. Verify
the constructor is a function before using its name, and reset the name
anyway if it turns out not to be serializable.

Fixes some cases of the devtools crashing and becoming inoperable upon
attempting to inspect components whose props are Hookstate `State`s.

## How did you test this change?

Installed a patched version of the extension and confirmed that it
solves the problem.

---------

Co-authored-by: Ruslan Lesiutin <rdlesyutin@gmail.com>
2024-06-25 19:30:28 +01:00
Lauren Tan
708d8f8c49 [ez] Remove outdated files
These are no longer in use

ghstack-source-id: 075e4fd0ab
Pull Request resolved: https://github.com/facebook/react/pull/30092
2024-06-25 14:09:04 -04:00
Lauren Tan
f6b546737e Bump version to 0.0.0-experimental-b130d5f-20240625 2024-06-25 12:42:06 -04:00
Lauren Tan
bdb355f349 Bump version to 0.0.0-experimental-0998c1e-20240625 2024-06-25 12:42:06 -04:00
Lauren Tan
d17f024681 Bump version to 0.0.0-experimental-696af53-20240625 2024-06-25 12:42:06 -04:00
Sathya Gunasekaran
8971381549 [compiler] Enable sourceMaps in tsconfig (#30064)
With this, we can set a `debugger` breakpoint and we'll break into the
source code when running tests with snap. Without this, we'd break into
the transpiled js code.
2024-06-25 17:01:43 +01:00
Joe Savona
f5d2feb4f0 [compiler] Fix assignment within for update expression
When converting value blocks from HIR to ReactiveFunction, we have to drop StoreLocal assignments that represent the assignment of the phi, since ReactiveFunction supports compound expressions. These StoreLocals are only present to represent the conditional assignment of the value itself - but it's also possible for the expression to have contained an assignment expression. Before, in trying to strip the first category of StoreLocal we also accidentally stripped the second category. Now we check that the assignment is for a temporary, and don't strip otherwise.

ghstack-source-id: e7759c963bbc1bbff2d3230534b049199e3262ad
Pull Request resolved: https://github.com/facebook/react/pull/30067
2024-06-24 10:49:36 -07:00
Jack Pope
89580f209c Set renameElementSymbol to dynamic value (#30066)
Prepare to roll this out with dynamic flag

`yarn flags --diff www canary`

<img width="514" alt="Screenshot 2024-06-24 at 11 33 55 AM"
src="https://github.com/facebook/react/assets/8965173/31508fdc-4cb1-4ce0-8e22-c02a034377b0">
2024-06-24 12:28:39 -04:00
Jack Pope
c21bcd627b Clean up enableUnifiedSyncLane flag (#30062)
`enableUnifiedSyncLane` now passes everywhere. Let's clean it up

Implemented with https://github.com/facebook/react/pull/27646

Flag enabled with https://github.com/facebook/react/pull/27646,
https://github.com/facebook/react/pull/28269,
https://github.com/facebook/react/pull/29052
2024-06-24 11:18:22 -04:00
Ruslan Lesiutin
7608516479 refactor[react-devtools/extensions]: dont debounce cleanup logic on navigation (#30027)
## Summary
There is a race condition in the way we poll if React is on the page and
when we actually clear this polling instance. When user navigates to a
different page, we will debounce a callback for 500ms, which will:
1. Cleanup previous React polling instance
2. Start a new React polling instance

Since the cleanup logic is debounced, there is a small chance that by
the time we are going to clean up this polling instance, it will be
`eval`-ed on the page, that is using React. For example, when user is
navigating from the page which doesn't have React running, to a page
that has React running.

Next, we incorrectly will try to mount React DevTools panels twice,
which will result into conflicts in the Store, and the error will be
shown to the user

## How did you test this change?
Since this is a race condition, it is hard to reproduce consistently,
but you can try this flow:
1. Open a page that is using React, open browser DevTools and React
DevTools components panel
2. Open a page that is NOT using React, like google.com, wait ~5 seconds
until you see `"Looks like this page doesn't have React, or it hasn't
been loaded yet"` message in RDT panel
3. Open a page that is using React, observe the error `"Uncaught Error:
Cannot add node "1" because a node with that id is already in the
Store."`

Couldn't been able to reproduce this with these changes.
2024-06-24 13:28:17 +01:00
Lauren Tan
27e9476f0a [ci] Cleanup
- Made each workflow's name consistent
- Rename each workflow file with consistent naming scheme
- Promote flow-ci-ghaction to flow-ci

ghstack-source-id: 490b643dcd
Pull Request resolved: https://github.com/facebook/react/pull/30037
2024-06-22 12:37:42 -04:00
Lauren Tan
0bff0e4377 [ci] Remove circleci check_generated_fizz_runtime job
This was migrated to GitHub actions

ghstack-source-id: 3b307a3110
Pull Request resolved: https://github.com/facebook/react/pull/30036
2024-06-22 12:37:42 -04:00
Lauren Tan
a7c5c07ed4 [ci] Add new fizz GitHub action
Copies the existing circleci workflow for checking the inlined Fizz
runtime into GitHub actions. I didn't remove the circleci job for now
just to check for parity.

ghstack-source-id: 09480b1a20
Pull Request resolved: https://github.com/facebook/react/pull/30035
2024-06-22 12:37:42 -04:00
Lauren Tan
917585d037 [ci] Remove circleci yarn_test job
This was migrated to GitHub actions

ghstack-source-id: adf9b2bdc7
Pull Request resolved: https://github.com/facebook/react/pull/30034
2024-06-22 12:37:42 -04:00
Lauren Tan
85215413cb [ci] Improve parallelism of yarn test
This PR adds parallelism similar to our existing circleci setup for
running yarn tests with the various test params. It does this by
sharding tests into `$SHARD_COUNT` number of groups, then spawning a job
for each of them and using jest's built in `--shard` option.

Effectively this means that the job will spawn an additional (where `n`
is the number of test params)

`n * $SHARD_COUNT` number of jobs to run tests in parallel

for a total of `n + (n * $SHARD_COUNT)` jobs. This does mean the
GitHub UI at the bottom of each PR gets longer and unfortunately it's
not sorted in any way as far as I can tell. But if something goes wrong
it should still be easy to find out what the problem is.

The PR also changes the `ci` argument for jest-cli to be an enum instead
so the tests use all available workers in GitHub actions. This will have
to live around for a bit until we can fully migrate off of circleci.

ghstack-source-id: 08f2d16353
Pull Request resolved: https://github.com/facebook/react/pull/30033
2024-06-22 12:37:42 -04:00
Lauren Tan
28c1336c91 [ci] Add new yarn test GitHub action
Copies the existing circleci workflow for yarn test into GitHub
actions. I didn't remove the circleci job for now just to check for
parity.

Opted to keep the same hardcoded list of params rather than use GitHub's
matrix permutations since this was intentional in the circleci config.

ghstack-source-id: b77a091254
Pull Request resolved: https://github.com/facebook/react/pull/30032
2024-06-22 12:37:41 -04:00
Joe Savona
454fb35065 [compiler] add fixture for optimization across scopes
Adds a fixture based on internal case where our current output is quite a bit more verbose than the original memoization. See the comment in the fixture for more about the heuristic we can apply.

ghstack-source-id: e637a38140
Pull Request resolved: https://github.com/facebook/react/pull/29998
2024-06-21 16:48:14 -07:00
Joe Savona
2caaa05c08 [compiler] Optimize instruction reordering
Note: due to a bad rebase i included #29883 here. Both were stamped so i'm not gonna bother splitting it back up aain.

This PR includes two changes:
* First, allow `LoadLocal` to be reordered if a) the load occurs after the last write to a variable and b) the LoadLocal lvalue is used exactly once
* Uses a more optimal reordering for statement blocks, while keeping the existing approach for expression blocks.

In #29863 I tried to find a clean way to share code for emitting instructions between value blocks and regular blocks. The catch is that value blocks have special meaning for their final instruction — that's the value of the block — so reordering can't change the last instruction. However, in finding a clean way to share code for these two categories of code, i also inadvertently reduced the effectiveness of the optimization.

This PR updates to use different strategies for these two kinds of blocks: value blocks use the code from #29863 where we first emit all non-reorderable instructions in their original order, then try to emit reorderable values. The reason this is suboptimal, though, is that we want to move instructions closer to their dependencies so that they can invalidate (merge) together. Emitting the reorderable values last prevents this.

So for normal blocks, we now emit terminal operands first. This will invariably cause some of the non-reorderable instructions to be emitted, but it will intersperse reoderable instructions in between, right after their dependencies. This maximizes our ability to merge scopes.

I think the complexity cost of two strategies is worth the benefit, as evidenced by the reduced memo slots in the fixtures.

ghstack-source-id: ad3e516fa4
Pull Request resolved: https://github.com/facebook/react/pull/29882
2024-06-21 16:48:14 -07:00
Lauren Tan
6aea169480 [ci] Remove circleci yarn_flags job
This was migrated to GitHub actions

ghstack-source-id: 744671f311
Pull Request resolved: https://github.com/facebook/react/pull/30030
2024-06-21 15:02:18 -04:00
Lauren Tan
2f34bf427f [ci] Add new flags GitHub action
Copies the existing circleci workflow for yarn flags into GitHub
actions. I didn't remove the circleci job for now just to check for
parity.

ghstack-source-id: 003f2a4796
Pull Request resolved: https://github.com/facebook/react/pull/30029
2024-06-21 15:02:18 -04:00
Lauren Tan
5727928771 [ci] Remove circleci yarn_flow job
This was migrated to GitHub actions

ghstack-source-id: e1cd659e343abe21d8d4f43f19aa518b3b992400
Pull Request resolved: https://github.com/facebook/react/pull/30028
2024-06-21 12:32:47 -04:00
Lauren Tan
419ace93ec [ci] Parallelize flow github action
The existing flow-ci script makes some assumptions about running inside
of circleci for parallelization. This PR forks the script with very smal
ll tweaks to allow for a short name to be passed in as an argument.
These short names are discovered in a new GH job and then each one is
passed as an argument for parallelization

ghstack-source-id: dc85486388f74088c22b386b77b45996ef753f1a
Pull Request resolved: https://github.com/facebook/react/pull/30026
2024-06-21 12:32:47 -04:00
Lauren Tan
0477799cfb [ci] Add new flow GitHub action
Copies the existing circleci workflow for flow into GitHub actions. I
didn't remove the circleci job for now just to check for parity.

ghstack-source-id: 59104902e48a2b520ea2971d99c061c74b03a1a0
Pull Request resolved: https://github.com/facebook/react/pull/30025
2024-06-21 12:32:47 -04:00
Jan Kassens
b565373afd lint: enable reportUnusedDisableDirectives and remove unused suppressions (#28721)
This enables linting against unused suppressions and removes the ones
that were unused.
2024-06-21 12:24:32 -04:00
Lauren Tan
3563387fe3 [ci] Remove circleci yarn_lint job
This was migrated to GitHub actions

ghstack-source-id: bf284ae211
Pull Request resolved: https://github.com/facebook/react/pull/30024
2024-06-21 12:05:29 -04:00
Lauren Tan
f598eb4dc9 [ci] Add new lint GitHub action
Copies the existing circleci workflow for linting into GitHub actions. I
didn't remove the circleci for now just to check for parity.

ghstack-source-id: a3754dcc3b
Pull Request resolved: https://github.com/facebook/react/pull/30023
2024-06-21 12:05:29 -04:00
Lauren Tan
3776e98f90 [prettier] Run prettier
ghstack-source-id: 80f1247d5d
Pull Request resolved: https://github.com/facebook/react/pull/30022
2024-06-21 12:05:29 -04:00
Lauren Tan
49c37048de [prettier] Combine compiler and runtime configs
Merges the existing config to the root one so we can have a single
configuration file. I've tried to keep the compiler config as much as
possible in this PR so that no formatting changes occur.

ghstack-source-id: 8bbfc9f269
Pull Request resolved: https://github.com/facebook/react/pull/30021
2024-06-21 12:05:29 -04:00
Lauren Tan
49a4887586 [compiler:codegen] Wrap non-ascii characters in JsxExpressionContainer
This PR extends the previous logic added in #29141 to also account for
other kinds of non-ascii characters such as `\n`. Because these control
characters are individual special characters (and not 2 characters `\`
and `n`) we match based on unicode which was already being checked for
non-Latin characters.

This allows control characters to continue to be compiled equivalently
to its original source if it was provided in a JsxExpressionContainer.
However note that this PR does not convert JSX attributes that are
StringLiterals to JsxExpressionContainer, to preserve the original
source code as it was written.

Alternatively we could always emit a JsxExpressionContainer if it was
used in the source and not try to down level it to some other node
kind. But since we already do this I opted to keep this behavior.

Partially addresses #29648.

ghstack-source-id: ecc61c9f0bece90d18623b3c570fea05fbcd811a
Pull Request resolved: https://github.com/facebook/react/pull/29997
2024-06-21 10:08:15 -04:00
Jan Kassens
0b724e9e9c www: remove dynamic scheduler feature flag: enableProfiling (#29996)
I removed the wrong feature flag in #29995, this is the correct one to
match D58682445.
2024-06-21 09:51:46 -04:00
Sebastian Markbåge
6fb39ec9e9 Plumbing of isomorphic code (#29967)
Need to tighten up this a bit.

react-dom isomorphic currently depends on react-reconciler which is
mostly DCE but it's pulled in which makes it hard to make other bundling
changes.

ReactFlightServer can have a hard dependency on the module that imports
its internals since even if other internals are aliased it still always
needs the server one.
2024-06-21 06:39:10 -04:00
Lauren Tan
0f568418d2 Re-enable prettier for compiler/
Now that the compiler directory has its own prettier config, we can
remove the prettierignore entry for compiler/ so it still runs in your
editor if you open the root directory

ghstack-source-id: 5e3bd597cf2f11a9931f084eb909ffd81ebdca81
Pull Request resolved: https://github.com/facebook/react/pull/29993
2024-06-20 19:09:31 -04:00
Jan Kassens
6ab67c35f1 Revert "www: remove dynamic feature flag enableSchedulingProfiler" (#29995)
Reverts facebook/react#29994
2024-06-20 17:17:25 -04:00
Jan Kassens
babe5a2f1b www: remove dynamic feature flag enableSchedulingProfiler (#29994) 2024-06-20 16:47:28 -04:00
nakjun
395e2fc6a0 [chore] Fix TypeError in shouldSkipBundle During yarn build-for-devtools-dev and yarn build-for-devtools-prod Commands (#29906)
## Summary

Fix bundle type filtering logic to correctly handle array input in
argv.type and use some with includes for accurate filtering. This
addresses a TypeError encountered during yarn build-for-devtools-prod
and yarn build-for-devtools-dev commands.

## Motivation

The current implementation of the `shouldSkipBundle` function in
`scripts/rollup/build.js` has two issues:

1. **Incorrect array handling in
`parseRequestedNames`([#29613](https://github.com/facebook/react/issues/29613)):**
    
The function incorrectly wraps the `argv.type` value in an additional
array when it's already an array. This leads to a `TypeError:
names[i].split is not a function` when `parseRequestedNames` attempts to
split the nested array, as seen in this error message:
    
    ```
C:\Users\Administrator\Documents\새 폴더\react\scripts\rollup\build.js:76
        let splitNames = names[i].split(',');
                            ^
    TypeError: names[i].split is not a function
    ```
This PR fixes this by correctly handling both string and array inputs in
`argv.type`:
    
    ```diff
    - const requestedBundleTypes = argv.type
    -   ? parseRequestedNames([argv.type], 'uppercase')
+ const argvType = Array.isArray(argv.type) ? argv.type : [argv.type];
    + const requestedBundleTypes = argv.type
    +   ? parseRequestedNames(argvType, 'uppercase')
    ```
    
2. **Inaccurate filtering logic in
`shouldSkipBundle`([#29614](https://github.com/facebook/react/issues/29614)):**
    
The function uses `Array.prototype.every` with `indexOf` to check if
**all** requested bundle types are missing in the current bundle type.
However, when multiple bundle types are requested (e.g., `['NODE',
'NODE_DEV']`), the function should skip a bundle only if **none** of the
requested types are present. The current implementation incorrectly
allows bundles that match any of the requested types.
    
    To illustrate, consider the following example output:
    
    ```
    requestedBundleTypes [ 'NODE', 'NODE_DEV' ]
    bundleType NODE_DEV
    isAskingForDifferentType false

    requestedBundleTypes [ 'NODE', 'NODE_DEV' ]
    bundleType NODE_PROD
    isAskingForDifferentType false  // Incorrect behavior
    ```
    
In this case, even though the bundle type is `NODE_PROD` and doesn't
include `NODE_DEV`, the bundle is not skipped due to the incorrect
logic.
    
This PR fixes this by replacing `every` with `some` and using `includes`
for a more accurate check:
    
    ```diff
    - const isAskingForDifferentType = requestedBundleTypes.every(
    -   requestedType => bundleType.indexOf(requestedType) === -1
    - );
    + const isAskingForDifferentType = requestedBundleTypes.some(
    +   requestedType => !bundleType.includes(requestedType)
    + );
    ```
    
This ensures that the bundle is skipped only if **none** of the
requested types are found in the `bundleType`.

This PR addresses both of these issues to ensure correct bundle type
filtering in various build scenarios.


## How did you test this change?

1. **Verification of `requestedBundleTypes` usage in
`shouldSkipBundle`:**

   * I manually tested the following scenarios:
* `yarn build`: Verified that `requestedBundleTypes` remains an empty
array, as expected.
* `yarn build-for-devtools`: Confirmed that `requestedBundleTypes` is
correctly set to `['NODE']`, as in the original implementation.
* `yarn build-for-devtools-dev`: This previously failed due to the
error. After the fix, I confirmed that `requestedBundleTypes` is now
correctly passed as `['NODE', 'NODE_DEV']`.

2. **Debugging of filtering logic in `shouldSkipBundle`:**

* I added the following logging statements to the `shouldSkipBundle`
function to observe its behavior during the build process:

     ```javascript
     console.log('requestedBundleTypes', requestedBundleTypes);
     console.log('bundleType', bundleType);
     console.log('isAskingForDifferentType', isAskingForDifferentType);
     ```

* By analyzing the log output, I confirmed that the filtering logic now
correctly identifies when a bundle should be skipped based on the
requested types. This allowed me to verify that the fix enables building
specific target bundles as intended.
2024-06-20 21:12:41 +01:00
NISHIZAWA Shuntaro
a5554190c1 fix[compiler playground]: Set source as the pre-change state in HIR diff (#29957)
<!--
  Thanks for submitting a pull request!
We appreciate you spending the time to work on these changes. Please
provide enough information so that others can review your pull request.
The three fields below are mandatory.

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

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

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

## Summary

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

I have fixed an issue where the display of the HIR diff in the React
Compiler Playground was incorrect. The HIR diff is supposed to show the
pre-change state as the source, but currently, it is showing
EnvironmentConfig as the pre-change state. This PR corrects this by
setting the pre-change state to source instead of EnvironmentConfig.

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

before:


![image](https://github.com/facebook/react/assets/37236438/c98aee7a-b569-430e-8698-0f7eff6c21e2)

after:


![image](https://github.com/facebook/react/assets/37236438/6113297c-80f9-4e71-a0d1-df8cc87507db)
2024-06-20 12:01:35 -04:00
Ruslan Lesiutin
b15c8492ca fix[react-devtools/extensions]: propagate globals from env (#29963)
Somehow missed this while working on
https://github.com/facebook/react/pull/29869.

With these changes, manual inspection of the
`react_devtools_backend_compact.js` doesn't have any occurences of
`__IS_FIREFOX__` flag.
2024-06-20 09:29:05 +01:00
Sebastian Markbåge
6b4646cbd0 Export captureOwnerStacks() only in DEV "react" builds (#29923)
Only with the enableOwnerStacks flag (which is not on in www).

This is a new DEV-only API to be able to implement what we do for
console.error in user space.

This API does not actually include the current stack that you'd get from
`new Error().stack`. That you'd have to add yourself.

This adds the ability to have conditional development exports because we
plan on eventually having separate ESM builds that use the "development"
or "production" export conditions.

NOTE: This removes the export of `act` from `react` in prod (as opposed
to a function that throws) - inline with what we do with other
conditional exports.
2024-06-19 14:19:48 -04:00
Ruslan Lesiutin
e684ca66ab refactor[react-devtools/tests]: use registered marks instead of cleared in tests (#29929)
## Summary
This is the pre-requisite for
https://github.com/facebook/react/pull/29231.

Current implementation of profiling hooks is only using
`performance.mark` and then makes `performance.clearMarks` call right
after it to free the memory. We've been relying on this assumption in
the tests that every mark is cleared by the time we check something.

https://github.com/facebook/react/pull/29231 adds `performance.measure`
calls and the `start` mark is not cleared until the corresponding `stop`
one is registered, and then they are cleared together.

## How did you test this change?
To test against React from source:
```
yarn test --build --project=devtools -r=experimental --ci
```

To test against React 18:
```
./scripts/circleci/download_devtools_regression_build.js 18.0 --replaceBuild
node ./scripts/jest/jest-cli.js --build --project devtools --release-channel=experimental --reactVersion 18.0 --ci
```
2024-06-19 15:45:01 +01:00
Sathya Gunasekaran
83d538e0d0 [compiler] Treat ref-like named objects as refs (#29916)
If a component uses the `useRef` hook directly then we type it's return
value as a ref. But if it's wrapped in a custom hook then we lose out on
this type information as the compiler doesn't look at the hook
definition. This has resulted in some false positives in our analysis
like the ones reported in #29160 and #29196.

This PR will treat objects named as `ref` or if their names end with the
substring `Ref`, and contain a property named `current`, as React refs.

```
const ref = useMyRef();
const myRef = useMyRef2();
useEffect(() => {
  ref.current = ...;
  myRef.current = ...;
})
```
In the above example, `ref` and `myRef` will be treated as React refs.
2024-06-18 18:02:19 +01:00
Ruslan Lesiutin
1434af3d22 React DevTools 5.2.0 -> 5.3.0 (#29918)
Full list of changes:

* chore[react-devtools]: improve console arguments formatting before
passing it to original console ([hoxyq](https://github.com/hoxyq) in
[#29873](https://github.com/facebook/react/pull/29873))
* chore[react-devtools]: unify console patching and default to ansi
escape symbols ([hoxyq](https://github.com/hoxyq) in
[#29869](https://github.com/facebook/react/pull/29869))
* chore[react-devtools/backend]: remove
consoleManagedByDevToolsDuringStrictMode
([hoxyq](https://github.com/hoxyq) in
[#29856](https://github.com/facebook/react/pull/29856))
* chore[react-devtools/extensions]: make source maps url relative
([hoxyq](https://github.com/hoxyq) in
[#29886](https://github.com/facebook/react/pull/29886))
* fix[react-devtools] divided inspecting elements between inspecting do…
([vzaidman](https://github.com/vzaidman) in
[#29885](https://github.com/facebook/react/pull/29885))
* [Fiber] Create virtual Fiber when an error occurs during reconcilation
([sebmarkbage](https://github.com/sebmarkbage) in
[#29804](https://github.com/facebook/react/pull/29804))
* fix[react-devtools] component badge in light mode is now not invisible
([vzaidman](https://github.com/vzaidman) in
[#29852](https://github.com/facebook/react/pull/29852))
* Remove Warning: prefix and toString on console Arguments
([sebmarkbage](https://github.com/sebmarkbage) in
[#29839](https://github.com/facebook/react/pull/29839))
* Add jest lint rules ([rickhanlonii](https://github.com/rickhanlonii)
in [#29760](https://github.com/facebook/react/pull/29760))
* [Fiber] Track the Real Fiber for Key Warnings
([sebmarkbage](https://github.com/sebmarkbage) in
[#29791](https://github.com/facebook/react/pull/29791))
* fix[react-devtools/store-test]: fork the test to represent current be…
([hoxyq](https://github.com/hoxyq) in
[#29777](https://github.com/facebook/react/pull/29777))
* Default native inspections config false
([vzaidman](https://github.com/vzaidman) in
[#29784](https://github.com/facebook/react/pull/29784))
* fix[react-devtools] remove native inspection button when it can't be
used ([vzaidman](https://github.com/vzaidman) in
[#29779](https://github.com/facebook/react/pull/29779))
* chore[react-devtools]: ip => internal-ip
([hoxyq](https://github.com/hoxyq) in
[#29772](https://github.com/facebook/react/pull/29772))
* Fix #29724: `ip` dependency update for CVE-2024-29415
([Rekl0w](https://github.com/Rekl0w) in
[#29725](https://github.com/facebook/react/pull/29725))
* cleanup[react-devtools]: remove unused supportsProfiling flag from
store config ([hoxyq](https://github.com/hoxyq) in
[#29193](https://github.com/facebook/react/pull/29193))
* [Fiber] Enable Native console.createTask Stacks When Available
([sebmarkbage](https://github.com/sebmarkbage) in
[#29223](https://github.com/facebook/react/pull/29223))
* Move createElement/JSX Warnings into the Renderer
([sebmarkbage](https://github.com/sebmarkbage) in
[#29088](https://github.com/facebook/react/pull/29088))
* Set the current fiber to the source of the error during error
reporting ([sebmarkbage](https://github.com/sebmarkbage) in
[#29044](https://github.com/facebook/react/pull/29044))
* Unify ReactFiberCurrentOwner and ReactCurrentFiber
([sebmarkbage](https://github.com/sebmarkbage) in
[#29038](https://github.com/facebook/react/pull/29038))
* Dim `console` calls on additional Effect invocations due to
`StrictMode` ([eps1lon](https://github.com/eps1lon) in
[#29007](https://github.com/facebook/react/pull/29007))
* refactor[react-devtools]: rewrite context menus
([hoxyq](https://github.com/hoxyq) in
[#29049](https://github.com/facebook/react/pull/29049))
2024-06-18 12:12:27 +01:00
Joseph Savona
ddcecbbebf Consider dispatch function from useActionState non-reactive (#29917)
Updated version of #29758 removing `useFormState` since that was the
previous name for `useActionState`.

---------

Co-authored-by: Hieu Do <hieudn.uh@gmail.com>
2024-06-17 12:26:55 -07:00
Ruslan Lesiutin
107a2f8c3e chore[react-devtools]: improve console arguments formatting before passing it to original console (#29873)
Stacked on https://github.com/facebook/react/pull/29869.

## Summary

When using ANSI escape sequences, we construct a message in the
following way: `console.<method>('\x1b...%s\x1b[0m',
userspaceArgument1?, userspaceArgument2?, userspaceArgument3?, ...)`.

This won't dim all arguments, if user had something like `console.log(1,
2, 3)`, we would only apply it to `1`, since this is the first
arguments, so we need to:
- inline everything whats possible into a single string, while
preserving console substitutions defined by the user
- omit css and object substitutions, since we can't really inline them
and will delegate in to the environment

## How did you test this change?

Added some tests, manually inspected that it works well for web and
native cases.
2024-06-17 16:38:03 +01:00
Ruslan Lesiutin
ff6e05a705 chore[react-devtools]: unify console patching and default to ansi escape symbols (#29869)
Stacked on https://github.com/facebook/react/pull/29856.

## Summary

By default, React DevTools will apply dimming with ANSI escape symbols,
so it works for both terminals and browser consoles.

For Firefox, which doesn't support ANSI escape symbols console stylings,
we fallback to css properties, like we used to do before.

## How did you test this change?

| Environment | Dark mode | Light mode |
|--------|--------|--------|
| Terminal | ![Screenshot 2024-06-12 at 19 39
46](https://github.com/facebook/react/assets/28902667/2d470eee-ec5f-4362-be7d-8d80c6c72d09)
| ![Screenshot 2024-06-12 at 19 39
09](https://github.com/facebook/react/assets/28902667/616f2c58-a251-406b-aee6-841e07d652ba)
|
| Fusebox&nbsp;console | ![Screenshot 2024-06-12 at 21 03
14](https://github.com/facebook/react/assets/28902667/6050f730-8e82-4aa1-acbc-7179aac3a8aa)
| ![Screenshot 2024-06-12 at 21 02
48](https://github.com/facebook/react/assets/28902667/6708b938-8a90-476f-a057-427963d58caa)
|
| Firefox&nbsp;console | ![Screenshot 2024-06-12 at 21 40
29](https://github.com/facebook/react/assets/28902667/4721084f-bbfa-438c-b61b-395da8ded590)
| ![Screenshot 2024-06-12 at 21 40
42](https://github.com/facebook/react/assets/28902667/72bbf001-2d3d-49e7-91c9-20a4f0914d4d)
|
| Chrome&nbsp;console | ![Screenshot 2024-06-12 at 21 43
09](https://github.com/facebook/react/assets/28902667/93c47881-a0dd-44f8-8dc2-8710149774e5)
| ![Screenshot 2024-06-12 at 21 43
00](https://github.com/facebook/react/assets/28902667/07ea4ff5-4322-4db9-9c12-4321d9577c9d)
|
2024-06-17 16:31:36 +01:00
Joe Savona
dbc5f36fe9 [compiler] Support method-call version of macro functions
Adds fixtures for `macro.namespace(...)` style invocations which we use internally in some cases instead of just `macro(...)`. I tried every example i could think of that could possibly break it (including basing one off of another fixture where we hit an invariant related due to a temporary being emitted for a method call), and they all worked. I just had to fix an existing bug where we early return in some cases instead of continuing, which is a holdover from when this pass was originally written as a ReactiveFunction visitor.

ghstack-source-id: c01f45b3ef6f42b6d1f1ff0508aea258000e0fce
Pull Request resolved: https://github.com/facebook/react/pull/29899
2024-06-17 08:17:24 -07:00
Ruslan Lesiutin
92219ff9b8 chore[react-devtools/backend]: remove consoleManagedByDevToolsDuringStrictMode (#29856)
## Summary

Removes the usage of `consoleManagedByDevToolsDuringStrictMode` flag
from React DevTools backend, this is the only place in RDT where this
flag was used. The only remaining part is
[`ReactFiberDevToolsHook`](6708115937/packages/react-reconciler/src/ReactFiberDevToolsHook.js (L203)),
so React renderers can start notifying DevTools when `render` runs in a
Strict Mode.

> TL;DR: it is broken, and we already incorrectly apply dimming, when
RDT frontend is not opened. Fixing in the next few changes, see next
steps.

Before explaining why I am removing this, some context is required. The
way RDT works is slightly different, based on the fact if RDT frontend
and RDT backend are actually connected:
1. For browser extension case, the Backend is a script, which is
injected by the extension when page is loaded and before React is
loaded. RDT Frontend is loaded together with the RDT panel in browser
DevTools, so ONLY when user actually opens the RDT panel.
2. For native case, RDT backend is shipped together with `react-native`
for DEV bundles. It is always injected before React is loaded. RDT
frontend is loaded only when user starts a standalone RDT app via `npx
react-devtools` or by opening React Native DevTools and then selecting
React DevTools panel.

When Frontend is not connected to the Backend, the only thing we have is
the `__REACT_DEVTOOLS_GLOBAL_HOOK__` — this thing inlines some APIs in
itself, so that it can work similarly when RDT Frontend is not even
opened. This is especially important for console logs, since they are
cached and stored, then later displayed to the user once the Console
panel is opened, but from RDT side, you want to modify these console
logs when they are emitted.

In order to do so, we [inline the console patching logic into the
hook](3ac551e855/packages/react-devtools-shared/src/hook.js (L222-L319)).
This implementation doesn't use the
`consoleManagedByDevToolsDuringStrictMode`. This means that if we enable
`consoleManagedByDevToolsDuringStrictMode` for Native right now, users
would see broken dimming in LogBox / Metro logs when RDT Frontend is not
opened.

Next steps:
1. Align this console patching implementation with the one in `hook.js`.
2. Make LogBox compatible with console stylings: both css and ASCII
escape symbols.
3. Ship new version of RDT with these changes.
4. Remove `consoleManagedByDevToolsDuringStrictMode` from
`ReactFiberDevToolsHook`, so this is rolled out for all renderers.
2024-06-17 16:13:04 +01:00
Ruslan Lesiutin
d7bb6039de chore[react-devtools/extensions]: make source maps url relative (#29886)
This adds few changes:
1. We are going to ship source maps only for 2 artifacts:
`installHook.js` and `react_devtools_backend_compact.js`, because it is
only these modules that can patch console and be visible to the user via
stack traces in console. We need to ship source maps to be able to use
`ignoreList` feature in source maps, so we can actually hide these from
stack traces.

| Before | After |
|--------|--------|
| ![Screenshot 2024-06-13 at 17 44
25](https://github.com/facebook/react/assets/28902667/464e097b-a95e-47eb-967c-0579daad316b)
| ![Screenshot 2024-06-13 at 17 39
53](https://github.com/facebook/react/assets/28902667/e4afe642-d65b-4296-a2cf-26c0b925ebf2)
|
 
2. The `"sources"` field in source map will have relative urls listed,
instead of absolute with `webpack://` protocol. This will move the
sources to the `React Developer Tools` frame in `Sources` panel, instead
of `webpack://`.
 
 | Before | After |
|--------|--------|
| ![Screenshot 2024-06-13 at 17 48
24](https://github.com/facebook/react/assets/28902667/a18edad2-5b4e-4ad7-8a7a-8b389c2edf92)
| ![Screenshot 2024-06-13 at 17 49
41](https://github.com/facebook/react/assets/28902667/5db491f7-5d1d-4155-9910-16ac4384d34e)
|

> [!NOTE]  
> I still have 1 unresolved issue with shipping source maps in extension
build, and it is related to Firefox, which can't find them in the
extension bundle and returns 404, even though urls are relative and I
can actually open them via unique address like
`moz-extension://<extension-id>/build/intallHook.js.map` ¯\\\_(ツ)\_/¯
2024-06-17 11:58:19 +01:00
Timothy Yung
f14d7f0d25 Prepare Feature Flags for React Native 0.75 (#29903)
## Summary

Configures the React Native open source feature flags in preparation for
React Native 0.75, which will be upgraded to React 19.

## How did you test this change?

```
$ yarn test
$ yarn flow fabric
```
2024-06-14 17:09:50 -07:00
Lauren Tan
05a3a7fa8d Bump version to 0.0.0-experimental-c20572a-20240614 2024-06-14 17:21:59 -04:00
Lauren Tan
d46985282d Bump version to 0.0.0-experimental-8ae29d2-20240614 2024-06-14 17:21:59 -04:00
Lauren Tan
7f9fbeafd5 Bump version to 0.0.0-experimental-179941d-20240614 2024-06-14 17:21:59 -04:00
Joe Savona
59e73d9016 [compiler] Instruction reordering
Adds a pass just after DCE to reorder safely reorderable instructions (jsx, primitives, globals) closer to where they are used, to allow other optimization passes to be more effective. Notably, the reordering allows scope merging to be more effective, since that pass relies on two scopes not having intervening instructions — in many cases we can now reorder such instructions out of the way and unlock merging, as demonstrated in the changed fixtures.

The algorithm itself is described in the docblock.

note: This is a cleaned up version of #29579 that is ready for review.

ghstack-source-id: c54a806cad
Pull Request resolved: https://github.com/facebook/react/pull/29863
2024-06-14 14:14:42 -07:00
Joe Savona
ed8dd2036b [compiler] Allow more instruction kinds btw merged scopes
Updates our scope merging pass to allow more types of instructions to intervene btw scopes. This includes all the non-allocating kinds of nodes that are considered reorderable in #29863. It's already safe to merge scopes with these instructions — we only merge if the lvalue is not used past the next scope. Additionally, without changing this pass reordering isn't very effective, since we would reorder to add these types of intervening instructions and then not be able to merge scopes.

Sequencing this first helps to see the win just from reordering alone.

ghstack-source-id: 79263576d8
Pull Request resolved: https://github.com/facebook/react/pull/29881
2024-06-14 14:14:42 -07:00
Jan Kassens
88959fd54a Revert "Set disableLegacyMode to true for www" (#29901)
Reverts facebook/react#29871

Just temporarily while we're investigating something.
2024-06-14 15:27:32 -04:00
Eric Rozell
3154ec8a38 Use a constant HostContext in prod builds for Fabric renderer (#29888)
<!--
  Thanks for submitting a pull request!
We appreciate you spending the time to work on these changes. Please
provide enough information so that others can review your pull request.
The three fields below are mandatory.

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

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

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

## Summary

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

In the Fabric renderer in React Native, we only use the HostContext to
issue soft errors in __DEV__ bundles when attempting to add a raw text
child to a node that may not support them. Moving the logic to set this
context to __DEV__ bundles only unblocks more expensive methods for
resolving whether a parent context supports raw text children, like
resolving this information from `getViewConfigForType`.

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

yarn test (--prod)
2024-06-14 13:37:19 -04:00
Jan Kassens
f0e8164410 sanitize javascript: urls for <object> tags (#29808)
sanitize javascript: urls for <object> tags

React 19 added sanitization for `javascript:` URLs for `href` properties
on various tags. This PR also adds that sanitization for `<object>` tags
as well that Firefox otherwise executes.
2024-06-14 13:17:43 -04:00
Jan Kassens
fb9a90fa48 Set disableLegacyMode to true for www (#29871)
Set disableLegacyMode to true for www
2024-06-14 09:52:49 -04:00
Joe Savona
a07f5a3db5 [compiler] Provide support for custom fbt-like macro functions
ghstack-source-id: e3c6455ac2
Pull Request resolved: https://github.com/facebook/react/pull/29893
2024-06-13 17:36:37 -07:00
Mike Vitousek
2ba462b665 [compiler][playground] Make change detection work in playground
Summary: The change detection mode was unavailable in the playground because the pragma was not a boolean. This fixes that by special casing it in pragma parsing, similar to validateNoCapitalizedCalls

ghstack-source-id: 4a8c17d21ab8b7936ca61c9dd1f7fdf8322614c9
Pull Request resolved: https://github.com/facebook/react/pull/29889
2024-06-13 11:02:47 -07:00
Vitali Zaidman
dfd30974ab created a vscode workspace file for the repo (#29830)
### Summary

Similarly to what has been done on the `react-native` repo in
https://github.com/facebook/react-native/pull/43851, this PR adds a
`react.code-workspace` workspace file when using VSCode.

This disables the built-in TypeScript Language Service for `.js`, `.ts`,
and `.json` files, recommends extensions, enables `formatOnSave`,
excludes certain files in search, and configures Flow language support.

### Motivation

This is a DevX benefit for **React contributors** using open source VS
Code. Without this, it takes quite a long time to set up the environment
in vscode to work well.

For me the following two points took around an hour each to figure out,
but for others it may take even more (screenshots can be found below):
* Search with "files to include" was searching in ignored files
(compiled/generated)
* Configure language validation and prettier both in "packages" that use
flow and in the "compiler" folder that uses typescript.

### Recommended extensions

NOTE: The recommended extensions list is currently minimal — happy to
extend this now or in future, but let's aim to keep these conservative
at the moment.

* Flow — language support
* EditorConfig — formatting based on `.editorconfig`, all file types
* Prettier — formatting for JS* files
* ESLint — linter for JS* files

### Why `react.code-workspace`?

`.code-workspace` files have slight extra behaviours over a `.vscode/`
directory:

* Allows user to opt-in or skip.
* Allows double-click launching from file managers.
* Allows base folder (and any subfolders in future) to be opened with
local file tree scope (useful in fbsource!)
* (Minor point) Single config file over multiple files.
https://code.visualstudio.com/docs/editor/workspaces

### Test plan
Against a new un-configured copy of Visual Studio Code Insiders.

**Without workspace config**

 .js files raise errors by default (built-in TypeScript language
service)
 When using the Flow VS Code extension, the wrong version (global) of
Flow is used.
<img width="978" alt="Screenshot 2024-06-10 at 16 03 59"
src="https://github.com/facebook/react/assets/5188459/17e19ba4-bac2-48ea-9b35-6b4b6242bcc1">

 Searching in excluded files when the "include" field is specified
<img width="502" alt="Screenshot 2024-06-10 at 15 41 24"
src="https://github.com/facebook/react/assets/5188459/00248755-7905-41bc-b303-498ddba82108">

**With workspace config**

 Built-in TypeScript Language Service is disabled for .js files, but
still enabled for .ts[x] files
![Screen Recording 2024-06-13 at 12 21
24](https://github.com/facebook/react/assets/5188459/6048218c-f316-44cd-8771-d2d0e848991d)

 Flow language support is configured correctly against flow version in
package.json
<img width="993" alt="Screenshot 2024-06-10 at 16 03 44"
src="https://github.com/facebook/react/assets/5188459/b54e143c-a013-4e73-8995-3af7b5a03e36">

 Does not search in excluded files when the "include" field is
specified
<img width="555" alt="Screenshot 2024-06-10 at 15 39 18"
src="https://github.com/facebook/react/assets/5188459/dd3e5344-84fb-4b5d-8689-4c8bd28168e0">

 Workspace config is suggested when folder is opened in VS Code

![image](https://github.com/facebook/react/assets/5188459/7434261f-1057-4954-9885-b057a10684ad)

 Dialog is shown on workspace launch with recommended VS Code
extensions
<img width="580" alt="Screenshot 2024-06-10 at 15 40 52"
src="https://github.com/facebook/react/assets/5188459/c6406fb6-92a0-47f1-8497-4ffe899bb6a9">
2024-06-13 16:23:42 +01:00
Joe Savona
ca9b6a7ebc [compiler] Fix visitors to emit the correct kind
Our passes aren't sequenced such that we could observe this bug, but this retains the proper terminal kind for pruned-scopes in mapTerminalSuccessors.

ghstack-source-id: 1a03b40e45649bbef7d6db968fb2dbd6261a246a
Pull Request resolved: https://github.com/facebook/react/pull/29884
2024-06-13 08:02:08 -07:00
Vitali Zaidman
d9a5b6393a fix[react-devtools] divided inspecting elements between inspecting do… (#29885)
# **before**
* nav to dom element from devtools
* nav to devtools element from page
are enabled on extension and disabled on the rest of the flavors.

## extension:
* nav to dom element from devtools **enabled** and working
* nav to devtools element from page **enabled** and working
![Screenshot 2024-06-13 at 11 15
11](https://github.com/facebook/react/assets/5188459/fef78b70-d22c-4405-8871-8b0449b51937)

## inline:
* nav to dom element from devtools **disabled**
* nav to devtools element from page **disabled**

![before-inline](https://github.com/facebook/react/assets/5188459/24020dc2-baec-4d0a-84d4-45c96d653843)

## standalone:
* nav to dom element from devtools **disabled**
* nav to devtools element from page **disabled**

![before-standalone](https://github.com/facebook/react/assets/5188459/19b4cb34-9d1f-412e-baea-59ea85f99d04)

## fusebox:
* nav to dom element from devtools **disabled**
* nav to devtools element from page **disabled**

![before-fusebox](https://github.com/facebook/react/assets/5188459/1a18fda4-04b8-40f4-ae8b-e059889fca93)

# **after**
same:
* nav to dom element from devtools
* nav to devtools element from page
are enabled on extension and disabled on inline.

change:
standalone and fusebox can nav to devtools element from page

## extension:
* nav to dom element from devtools **enabled** and working
* nav to devtools element from page **enabled** and working
![Screenshot 2024-06-13 at 10 50
25](https://github.com/facebook/react/assets/5188459/f4679c72-b211-43d6-b3ea-6380e0d1edf0)

## inline:
* nav to dom element from devtools **disabled**
* nav to devtools element from page **disabled**

![after-inline](https://github.com/facebook/react/assets/5188459/fdfdd87b-9bc3-47f3-b1e0-730239f6485d)

## standalone:
* nav to dom element from devtools **disabled**
* nav to devtools element from page **enabled** and working

![after-standalone](https://github.com/facebook/react/assets/5188459/b25e3c63-a697-4b0c-8ad2-0e12ec5c3e9c)

## fusebox:
* nav to dom element from devtools **disabled**
* nav to devtools element from page **enabled** and working

![after-fusebox](https://github.com/facebook/react/assets/5188459/f14147d8-9831-4909-a164-52f892c875e5)
2024-06-13 15:37:51 +01:00
Mike Vitousek
814a418645 [compiler] Make unary and binary operator types more precise
Summary: Minor change inspired by #29863: the BuildHIR pass ensures that Binary and UnaryOperator nodes only use a limited set of the operators that babel's operator types represent, which that pr relies on for safe reorderability, but the type of those HIR nodes admits the other operators. For example, even though you can't build an HIR UnaryOperator with `delete` as the operator, it is a valid HIR node--and if we made a mistaken change that let you build such a node, it would be unsafe to reorder.

This pr makes the typing of operators stricter to prevent that.

ghstack-source-id: 9bf3b1a37eae3f14c0e9fb42bb3ece522b317d98
Pull Request resolved: https://github.com/facebook/react/pull/29880
2024-06-12 15:31:59 -07:00
Josh Story
7f3911fac0 Standardize condition order so that edge-lite preferred over browser (#29877)
The export maps for react packages have to choose an order of
preference. Many runtimes use multiple conditions, for instance when
building for edge webpack also uses the browser condition which makes
sense given most edge runtimes have a web-standards based set of APIs.
However React is building the browser builds primarily for actual
browsers and sometimes have builds intended for servers that might be
browser compat. This change updates the order of conditions to
preference specific named runtimes > node > generic edge runtimes >
browser > default
2024-06-12 15:31:23 -07:00
Joe Savona
55fdcf87bd [compiler] Fix merging of queued states in InferReferenceEffects
Fixes a bug found by mofeiZ in #29878. When we merge queued states, if the new state does not introduce changes relative to the queued state we should use the queued state, not the new state.

ghstack-source-id: c59f69de15
Pull Request resolved: https://github.com/facebook/react/pull/29879
2024-06-12 14:49:23 -07:00
Sebastian Markbåge
195d5bb99e Execute event handlers in the context of the instance that it's associated with (#29876)
That way we get owner stacks (native or otherwise) for `console.error`
or `console.warn` inside of them.

Since the `reportError` is also called within this context, we also get
them for errors thrown within event listeners. You'll also be able to
observe this in in the `error` event. Similar to how `onUncaughtError`
is in the scope of the instance that errored - even though
`onUncaughtError` doesn't kick in for event listeners.

Chrome (from console.createTask):

<img width="306" alt="Screenshot 2024-06-12 at 2 08 19 PM"
src="https://github.com/facebook/react/assets/63648/34cd9d57-0df4-44df-a470-e89a5dd1b07d">

<img width="302" alt="Screenshot 2024-06-12 at 2 03 32 PM"
src="https://github.com/facebook/react/assets/63648/678117b1-e03a-47d4-9989-8350212c8135">

Firefox (from React DevTools):

<img width="493" alt="Screenshot 2024-06-12 at 2 05 01 PM"
src="https://github.com/facebook/react/assets/63648/94ca224d-354a-4ec8-a886-5740bcb418e5">

(This is the parent stack since React DevTools doesn't just yet print
owner stack.)

(Firefox doesn't print the component stack for uncaught since we don't
add component stacks for "error" events from React DevTools - just
console.error. Perhaps an oversight.)

If we didn't have the synthetic event system this would kind of just
work natively in Chrome because we have this task active when we attach
the event listeners to the DOM node and async stacks just follow along
that way. In fact, if you attach a manual listener in useEffect you get
this same effect. It's just because we use event delegation that this
doesn't work.

However, if we did get rid of the synthetic event system we'd likely
still want to add a wrapper on the DOM node to set our internal current
owner so that the non-native part of the system still can observe the
active instance. That wouldn't work with manually attached listeners
though.
2024-06-12 16:15:22 -04:00
Lenz Weber-Tronic
50e89ec9f2 Avoid acccessing React internals from use-sync-external-store/shim (#29868)
Co-authored-by: eps1lon <sebastian.silbermann@vercel.com>
2024-06-12 20:13:17 +02:00
dependabot[bot]
f3e09d6328 Bump braces from 3.0.2 to 3.0.3 in /fixtures/flight-esm (#29857)
Bumps [braces](https://github.com/micromatch/braces) from 3.0.2 to
3.0.3.
<details>
<summary>Commits</summary>
<ul>
<li><a
href="74b2db2938"><code>74b2db2</code></a>
3.0.3</li>
<li><a
href="88f1429a0f"><code>88f1429</code></a>
update eslint. lint, fix unit tests.</li>
<li><a
href="415d660c30"><code>415d660</code></a>
Snyk js braces 6838727 (<a
href="https://redirect.github.com/micromatch/braces/issues/40">#40</a>)</li>
<li><a
href="190510f79d"><code>190510f</code></a>
fix tests, skip 1 test in test/braces.expand</li>
<li><a
href="716eb9f12d"><code>716eb9f</code></a>
readme bump</li>
<li><a
href="a5851e57f4"><code>a5851e5</code></a>
Merge pull request <a
href="https://redirect.github.com/micromatch/braces/issues/37">#37</a>
from coderaiser/fix/vulnerability</li>
<li><a
href="2092bd1fb1"><code>2092bd1</code></a>
feature: braces: add maxSymbols (<a
href="https://github.com/micromatch/braces/issues/">https://github.com/micromatch/braces/issues/</a>...</li>
<li><a
href="9f5b4cf473"><code>9f5b4cf</code></a>
fix: vulnerability (<a
href="https://security.snyk.io/vuln/SNYK-JS-BRACES-6838727">https://security.snyk.io/vuln/SNYK-JS-BRACES-6838727</a>)</li>
<li><a
href="98414f9f1f"><code>98414f9</code></a>
remove funding file</li>
<li><a
href="665ab5d561"><code>665ab5d</code></a>
update keepEscaping doc (<a
href="https://redirect.github.com/micromatch/braces/issues/27">#27</a>)</li>
<li>Additional commits viewable in <a
href="https://github.com/micromatch/braces/compare/3.0.2...3.0.3">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=braces&package-manager=npm_and_yarn&previous-version=3.0.2&new-version=3.0.3)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)
You can disable automated security fix PRs for this repo from the
[Security Alerts
page](https://github.com/facebook/react/network/alerts).

</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-06-12 11:17:06 -04:00
Jan Kassens
93826c8483 remove unstable_renderSubtreeIntoContainer (#29771)
remove unstable_renderSubtreeIntoContainer

This is finally no longer used and can be deleted.
2024-06-12 11:14:51 -04:00
Jan Kassens
62af6b2280 delete ReactServerStreamConfig.dom-fb-experimental.js (#29836)
delete ReactServerStreamConfig.dom-fb-experimental.js

This config is no longer used since
1cd77a4ff7
2024-06-12 11:12:22 -04:00
Sebastian Markbåge
55c9d45f3b [Flight] Let environmentName vary over time by making it a function of string (#29867)
This lets the environment name vary within a request by the context a
component, log or error being executed in.

A potentially different API would be something like
`setEnvironmentName()` but we'd have to extend the `ReadableStream` or
something to do that like we do for `.allReady`. As a function though it
has some expansion possibilities, e.g. we could potentially also pass
some information to it for context about what is being asked for.

If it changes before completing a task, we also emit the change so that
we have the debug info for what the environment was before entering a
component and what it was after completing it.
2024-06-12 10:55:42 -04:00
Sebastian Markbåge
fb57fc5a8a [Flight] Let Errored/Blocked Direct References Turn Nearest Element Lazy (#29823)
Stacked on #29807.

This lets the nearest Suspense/Error Boundary handle it even if that
boundary is defined by the model itself.

It also ensures that when we have an error during serialization of
properties, those can be associated with the nearest JSX element and
since we have a stack/owner for that element we can use it to point to
the source code of that line. We can't track the source of any nested
arbitrary objects deeper inside since objects don’t track their stacks
but close enough. Ideally we have the property path but we don’t have
that right now. We have a partial in the message itself.

<img width="813" alt="Screenshot 2024-06-09 at 10 08 27 PM"
src="https://github.com/facebook/react/assets/63648/917fbe0c-053c-4204-93db-d68a66e3e874">

Note: The component name (Counter) is lost in the first message because
we don't print it in the Task. We use `"use client"` instead because we
expect the next stack frame to have the name. We also don't include it
in the actual error message because the Server doesn't know the
component name yet. Ideally Client References should be able to have a
name. If the nearest is a Host Component then we do use the name though.
However, it's not actually inside that Component that the error happens
it's in App and that points to the right line number.

An interesting case is that if something that's actually going to be
consumed by the props to a Suspense/Error Boundary or the Client
Component that wraps them fails, then it can't be handled by the
boundary. However, a counter intuitive case might be when that's on the
`children` props. E.g.
`<ErrorBoundary>{clientReferenceOrInvalidSerialization}</ErrorBoundary>`.
This value can be inspected by the boundary so it's not safe to pass it
so if it's errored it is not caught.

## Implementation

The first insight is that this is best solved on the Client rather than
in the Server because that way it also covers Client References that end
up erroring.

The key insight is that while we don't have a true stack when using
`JSON.parse` and therefore no begin/complete we can still infer these
phases for Elements because the first child of an Element is always
`'$'` which is also a leaf. In depth first that's our begin phase. When
the Element itself completes, we have the complete phase. Anything in
between is within the Element.

Using this idea I was able to refactor the blocking tracking mechanism
to stash the blocked information on `initializingHandler` and then on
the way up do we let whatever is nearest handle it - whether that's an
Element or the root Chunk. It's kind of like an Algebraic Effect.

cc @unstubbable This is something you might want to deep dive into to
find more edge cases. I'm sure I've missed something.

---------

Co-authored-by: eps1lon <sebastian.silbermann@vercel.com>
2024-06-11 19:12:39 -04:00
Sebastian Markbåge
383b2a1845 Use the Nearest Parent of an Errored Promise as its Owner (#29814)
Stacked on #29807.

Conceptually the error's owner/task should ideally be captured when the
Error constructor is called but neither `console.createTask` does this,
nor do we override `Error` to capture our `owner`. So instead, we use
the nearest parent as the owner/task of the error. This is usually the
same thing when it's thrown from the same async component but not if you
await a promise started from a different component/task.

Before this stack the "owner" and "task" of a Lazy that errors was the
nearest Fiber but if the thing erroring is a Server Component, we need
to get that as the owner from the inner most part of debugInfo.

To get the Task for that Server Component, we need to expose it on the
ReactComponentInfo object. Unfortunately that makes the object not
serializable so we need to special case this to exclude it from
serialization. It gets restored again on the client.

Before (Shell):
<img width="813" alt="Screenshot 2024-06-06 at 5 16 20 PM"
src="https://github.com/facebook/react/assets/63648/7da2d4c9-539b-494e-ba63-1abdc58ff13c">

After (App):
<img width="811" alt="Screenshot 2024-06-08 at 12 29 23 AM"
src="https://github.com/facebook/react/assets/63648/dbf40bd7-c24d-4200-81a6-5018bef55f6d">
2024-06-11 18:10:24 -04:00
Mike Vitousek
a26e3f403e [compiler] Expect component props annotations to be potential objects
Summary: We now expect that candidate components that have Flow or TS type annotations on their first parameters have annotations that are potentially objects--this lets us reject compiling functions that explicitly take e.g. `number` as a parameter.

ghstack-source-id: e2c23348265b7ef651232b962ed7be7f6fed1930
Pull Request resolved: https://github.com/facebook/react/pull/29866
2024-06-11 14:08:21 -07:00
Mike Vitousek
057de295d5 [compiler] Expect components to have hook calls or jsx directly in body
Summary: We can tighten our criteria for what is a component by requiring that a component or hook contain JSX or hook calls directly within its body, excluding nested functions . Currently, if we see them within the body anywhere -- including nested functions -- we treat it as a component if the other requirements are met. This change makes this stricter.

We also now expect components (but not necessarily hooks) to have return statements, and those returns must be potential React nodes (we can reject functions that return function or object literals, for example).

ghstack-source-id: 4507cc3955216c564bf257c0b81bfb551ae6ae55
Pull Request resolved: https://github.com/facebook/react/pull/29865
2024-06-11 14:08:21 -07:00
Mike Vitousek
3cd3735515 [compiler] Option to only compile component syntax
Summary: Projects which have heavily adopted Flow component syntax may wish to enable the compiler only for components and hooks that use the syntax, rather than trying to guess which functions are components and hooks. This provides that option.

ghstack-source-id: 579ac9f0fa01d8cdb6a0b8f9923906a0b37662f3
Pull Request resolved: https://github.com/facebook/react/pull/29864
2024-06-11 14:08:21 -07:00
Sebastian Markbåge
2c959f1d77 [Fiber] Track debugInfo on module state instead of stack (#29807)
Stacked on #29804.

Transferring of debugInfo was added in #28286. It represents the parent
stack between the current Fiber and into the next Fiber we're about to
create. I.e. Server Components in between. ~I don't love passing
DEV-only fields as arguments anyway since I don't trust closure to
remove unused arguments that way.~ EDIT: Actually it seems like closure
handled that just fine before which is why this is no change in prod.

Instead, I track it on the module scope. Notably with DON'T use
try/finally because if something throws we want to observe what it was
at the time we threw. Like the pattern we use many other places.

Now we can use this when we create the Throw Fiber to associate the
Server Components that were part of the parent stack before this error
threw. There by giving us the correct parent stacks at the location that
threw.
2024-06-11 17:04:13 -04:00
Sebastian Markbåge
270229f0c3 [Fiber] Create virtual Fiber when an error occurs during reconcilation (#29804)
This lets us rethrow it in the conceptual place of the child.

There's currently a problem when we suspend or throw in the child fiber
reconciliation phase. This work is done by the parent component, so if
it suspends or errors it is as if that component errored or suspended.
However, conceptually it's like a child suspended or errored.

In theory any thing can throw but it is really mainly due to either
`React.lazy` (both in the element.type position and node position),
`Thenable`s or the `Thenable`s that make up `AsyncIterable`s.

Mainly this happens because a Server Component that errors turns into a
`React.lazy`. In practice this means that if you have a Server Component
as the direct child of an Error Boundary. Errors inside of it won't be
caught.

We used to have the same problem with Thenables and Suspense but because
it's now always nested inside an inner Offscreen boundary that shields
it by being one level nested. However, when we have raw Offscreen
(Activity) boundaries they should also be able to catch the suspense if
it's in a hidden state so the problem returns. This fixes it for thrown
promises but it doesn't fix it for SuspenseException. I'm not sure this
is even the right strategy for Suspense though. It kind of relies on the
node never actually mounting/committing.

It's conceptually a little tricky because the current component can
inspect the children and make decisions based on them. Such as
SuspenseList.

The other thing that this PR tries to address is that it sets the
foundation for dealing with error reporting for Server Components that
errored. If something client side errors it'll be a stack like Server
(DebugInfo) -> Fiber -> Fiber -> Server -> (DebugInfo) -> Fiber.
However, all error reporting relies on it eventually terminating into a
Fiber that is responsible for the error. To avoid having to fork too
much it would be nice if I could create a Fiber to associate with the
error so that even a Server component error in this case ultimately
terminates in a Fiber.
2024-06-11 15:57:41 -04:00
Sebastian Markbåge
01a40570c3 [Flight/Fizz] Use Constructors for Large Request/Response Objects in Flight/Fizz (#29858)
We know from Fiber that inline objects with more than 16 properties in
V8 turn into dictionaries instead of optimized objects. The trick is to
use a constructor instead of an inline object literal. I don't actually
know if that's still the case or not. I haven't benchmarked/tested the
output. Better safe than sorry.

It's unfortunate that this can have a negative effect for Hermes and JSC
but it's not as bad as it is for V8 because they don't deopt into
dictionaries. The time to construct these objects isn't a concern - the
time to access them frequently is.

We have to beware the Task objects in Fizz. Those are currently on 16
fields exactly so we shouldn't add anymore ideally.

We should ideally have a lint rule against object literals with more
than 16 fields on them. It might not help since sometimes the fields are
conditional.
2024-06-11 15:55:29 -04:00
Lauren Tan
82dea10511 [compiler] Remove .vscode
To keep consistent with the rest of the React repo, let's remove this
because editor settings are personal. Additionally this wasn't in the
root directory so it wasn't being applied anyway.

ghstack-source-id: 3a2e2993d6
Pull Request resolved: https://github.com/facebook/react/pull/29861
2024-06-11 15:25:05 -04:00
dependabot[bot]
0c65538be8 Bump braces from 3.0.2 to 3.0.3 in /fixtures/legacy-jsx-runtimes (#29844)
Bumps [braces](https://github.com/micromatch/braces) from 3.0.2 to
3.0.3.
<details>
<summary>Commits</summary>
<ul>
<li><a
href="74b2db2938"><code>74b2db2</code></a>
3.0.3</li>
<li><a
href="88f1429a0f"><code>88f1429</code></a>
update eslint. lint, fix unit tests.</li>
<li><a
href="415d660c30"><code>415d660</code></a>
Snyk js braces 6838727 (<a
href="https://redirect.github.com/micromatch/braces/issues/40">#40</a>)</li>
<li><a
href="190510f79d"><code>190510f</code></a>
fix tests, skip 1 test in test/braces.expand</li>
<li><a
href="716eb9f12d"><code>716eb9f</code></a>
readme bump</li>
<li><a
href="a5851e57f4"><code>a5851e5</code></a>
Merge pull request <a
href="https://redirect.github.com/micromatch/braces/issues/37">#37</a>
from coderaiser/fix/vulnerability</li>
<li><a
href="2092bd1fb1"><code>2092bd1</code></a>
feature: braces: add maxSymbols (<a
href="https://github.com/micromatch/braces/issues/">https://github.com/micromatch/braces/issues/</a>...</li>
<li><a
href="9f5b4cf473"><code>9f5b4cf</code></a>
fix: vulnerability (<a
href="https://security.snyk.io/vuln/SNYK-JS-BRACES-6838727">https://security.snyk.io/vuln/SNYK-JS-BRACES-6838727</a>)</li>
<li><a
href="98414f9f1f"><code>98414f9</code></a>
remove funding file</li>
<li><a
href="665ab5d561"><code>665ab5d</code></a>
update keepEscaping doc (<a
href="https://redirect.github.com/micromatch/braces/issues/27">#27</a>)</li>
<li>Additional commits viewable in <a
href="https://github.com/micromatch/braces/compare/3.0.2...3.0.3">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=braces&package-manager=npm_and_yarn&previous-version=3.0.2&new-version=3.0.3)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)
You can disable automated security fix PRs for this repo from the
[Security Alerts
page](https://github.com/facebook/react/network/alerts).

</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-06-11 11:36:36 -04:00
dependabot[bot]
2f47e667da Bump braces from 3.0.2 to 3.0.3 in /fixtures/flight (#29845)
Bumps [braces](https://github.com/micromatch/braces) from 3.0.2 to
3.0.3.
<details>
<summary>Commits</summary>
<ul>
<li><a
href="74b2db2938"><code>74b2db2</code></a>
3.0.3</li>
<li><a
href="88f1429a0f"><code>88f1429</code></a>
update eslint. lint, fix unit tests.</li>
<li><a
href="415d660c30"><code>415d660</code></a>
Snyk js braces 6838727 (<a
href="https://redirect.github.com/micromatch/braces/issues/40">#40</a>)</li>
<li><a
href="190510f79d"><code>190510f</code></a>
fix tests, skip 1 test in test/braces.expand</li>
<li><a
href="716eb9f12d"><code>716eb9f</code></a>
readme bump</li>
<li><a
href="a5851e57f4"><code>a5851e5</code></a>
Merge pull request <a
href="https://redirect.github.com/micromatch/braces/issues/37">#37</a>
from coderaiser/fix/vulnerability</li>
<li><a
href="2092bd1fb1"><code>2092bd1</code></a>
feature: braces: add maxSymbols (<a
href="https://github.com/micromatch/braces/issues/">https://github.com/micromatch/braces/issues/</a>...</li>
<li><a
href="9f5b4cf473"><code>9f5b4cf</code></a>
fix: vulnerability (<a
href="https://security.snyk.io/vuln/SNYK-JS-BRACES-6838727">https://security.snyk.io/vuln/SNYK-JS-BRACES-6838727</a>)</li>
<li><a
href="98414f9f1f"><code>98414f9</code></a>
remove funding file</li>
<li><a
href="665ab5d561"><code>665ab5d</code></a>
update keepEscaping doc (<a
href="https://redirect.github.com/micromatch/braces/issues/27">#27</a>)</li>
<li>Additional commits viewable in <a
href="https://github.com/micromatch/braces/compare/3.0.2...3.0.3">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=braces&package-manager=npm_and_yarn&previous-version=3.0.2&new-version=3.0.3)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)
You can disable automated security fix PRs for this repo from the
[Security Alerts
page](https://github.com/facebook/react/network/alerts).

</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-06-11 11:35:53 -04:00
dependabot[bot]
54185a35d9 Bump braces from 3.0.2 to 3.0.3 in /fixtures/stacks (#29843)
Bumps [braces](https://github.com/micromatch/braces) from 3.0.2 to
3.0.3.
<details>
<summary>Commits</summary>
<ul>
<li><a
href="74b2db2938"><code>74b2db2</code></a>
3.0.3</li>
<li><a
href="88f1429a0f"><code>88f1429</code></a>
update eslint. lint, fix unit tests.</li>
<li><a
href="415d660c30"><code>415d660</code></a>
Snyk js braces 6838727 (<a
href="https://redirect.github.com/micromatch/braces/issues/40">#40</a>)</li>
<li><a
href="190510f79d"><code>190510f</code></a>
fix tests, skip 1 test in test/braces.expand</li>
<li><a
href="716eb9f12d"><code>716eb9f</code></a>
readme bump</li>
<li><a
href="a5851e57f4"><code>a5851e5</code></a>
Merge pull request <a
href="https://redirect.github.com/micromatch/braces/issues/37">#37</a>
from coderaiser/fix/vulnerability</li>
<li><a
href="2092bd1fb1"><code>2092bd1</code></a>
feature: braces: add maxSymbols (<a
href="https://github.com/micromatch/braces/issues/">https://github.com/micromatch/braces/issues/</a>...</li>
<li><a
href="9f5b4cf473"><code>9f5b4cf</code></a>
fix: vulnerability (<a
href="https://security.snyk.io/vuln/SNYK-JS-BRACES-6838727">https://security.snyk.io/vuln/SNYK-JS-BRACES-6838727</a>)</li>
<li><a
href="98414f9f1f"><code>98414f9</code></a>
remove funding file</li>
<li><a
href="665ab5d561"><code>665ab5d</code></a>
update keepEscaping doc (<a
href="https://redirect.github.com/micromatch/braces/issues/27">#27</a>)</li>
<li>Additional commits viewable in <a
href="https://github.com/micromatch/braces/compare/3.0.2...3.0.3">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=braces&package-manager=npm_and_yarn&previous-version=3.0.2&new-version=3.0.3)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)
You can disable automated security fix PRs for this repo from the
[Security Alerts
page](https://github.com/facebook/react/network/alerts).

</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-06-11 11:35:40 -04:00
Joe Savona
b5b9daa44d [compiler] HIR-based FlattenScopesWithHooksOrUse
Per title, implements an HIR-based version of FlattenScopesWithHooksOrUse as part of our push to use HIR everywhere. This is the last pass to migrate before PropagateScopeDeps, which is blocking the fix for `bug.invalid-hoisting-functionexpr`, ie where we can infer incorrect dependencies for function expressions if the dependencies are accessed conditionally.

ghstack-source-id: 05c6e26b3b7a3b1c3e106a37053f88ac3c72caf5
Pull Request resolved: https://github.com/facebook/react/pull/29840
2024-06-11 08:34:59 -07:00
Joe Savona
43c17d13ef [compiler] HIR-based FlattenReactiveLoops
Pre the title, this implements an HIR-based version of FlattenReactiveLoops. Another step on the way to HIR-everywhere.

ghstack-source-id: e1d166352df6b0725e4c4915a19445437916251f
Pull Request resolved: https://github.com/facebook/react/pull/29838
2024-06-11 08:34:59 -07:00
Joe Savona
f7b871a8d5 [compiler] Add pruned-scope terminal in HIR
Adds the HIR equivalent of a pruned-scope, allowing us to start porting the scope-pruning passes to operate on HIR.

ghstack-source-id: dbbdc43219123467acc1a531d8276e8b9cc91e14
Pull Request resolved: https://github.com/facebook/react/pull/29837
2024-06-11 08:34:59 -07:00
Vitali Zaidman
fb3b9ead47 fix[react-devtools] component badge in light mode is now not invisible (#29852)
In light mode, component badges in profiler were invisible due to using
the alpha channel to produce the grayish color. Instead I'm using the
equivalent RGB without that alpha.

**before**
In light mode, component badges in profiler were invisible (forwardRef
badge in this case):
![Screenshot 2024-06-11 at 13 15
16](https://github.com/facebook/react/assets/5188459/385b80a5-d385-4eac-bac6-7fec6938d78f)

**after**
Profiler tooltip fix. also notice there's no regression on the right
menu:
![Screenshot 2024-06-11 at 13 04
41](https://github.com/facebook/react/assets/5188459/64aa27f7-35b8-4e3b-91d4-c12d5a97330e)

also works in dark mode:
![Screenshot 2024-06-11 at 13 12
17](https://github.com/facebook/react/assets/5188459/99aa55fd-23ee-4881-9676-63eca86bf761)

Still visible in components in light mode, whether selected or not:
![Screenshot 2024-06-11 at 13 04
49](https://github.com/facebook/react/assets/5188459/59c0bf63-d9b0-4d46-a145-f615249d1da0)

components dark mode:
![Screenshot 2024-06-11 at 13 10
25](https://github.com/facebook/react/assets/5188459/16e61acc-c431-4bfa-8a65-ca6701f4379b)
2024-06-11 14:32:39 +01:00
Lauren Tan
c015abd9dc [compiler] Remove unused scripts
ghstack-source-id: ae0c1bf365
Pull Request resolved: https://github.com/facebook/react/pull/29842
2024-06-10 20:35:40 -04:00
Lauren Tan
ae0525f8f2 [compiler] Remove playground postinstall script
The ci step for the playground already installs playwright browsers so
this step was unnecessary. It also doesn't work internally for our sync
scripts

ghstack-source-id: d6e7615637
Pull Request resolved: https://github.com/facebook/react/pull/29841
2024-06-10 20:35:39 -04:00
Yuto Yoshino
a714685c15 fix[compiler] remove duplicate parsePluginOptions from the compilePro… (#29831)
<!--
  Thanks for submitting a pull request!
We appreciate you spending the time to work on these changes. Please
provide enough information so that others can review your pull request.
The three fields below are mandatory.

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

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

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

## Summary

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

The parsePluginOptions seemed to be duplicated within
[BabelPlugin.ts](f5af92d2c4/compiler/packages/babel-plugin-react-compiler/src/Babel/BabelPlugin.ts (L32))
and
[Program.ts](f5af92d2c4/compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Program.ts (L220)).
Since the options already parsed in BabelPlugin.ts should have been
passed to compileProgram, in this PR we deleted parsePluginOptions in
compileProgram and used the options passed as arguments as they are.
I've done that.

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

<img width="516" alt="image"
src="https://github.com/facebook/react/assets/87469023/2a70c6ea-0330-42a2-adff-48ae3e905790">
2024-06-10 16:18:01 -07:00
Sebastian Markbåge
2774208039 Remove Warning: prefix and toString on console Arguments (#29839)
Basically make `console.error` and `console.warn` behave like normal -
when a component stack isn't appended. I need this because I need to be
able to print rich logs with the component stack option and to be able
to disable instrumentation completely in `console.createTask`
environments that don't need it.

Currently we can't print logs with richer objects because they're
toString:ed first. In practice, pretty much all arguments we log are
already toString:ed so it's not necessary anyway. Some might be like a
number. So it would only be a problem if some environment can't handle
proper consoles but then it's up to that environment to toString it
before logging.

The `Warning: ` prefix is historic and is both noisy and confusing. It's
mostly unnecessary since the UI surrounding `console.error` and
`console.warn` tend to have visual treatment around it anyway. However,
it's actively misleading when `console.error` gets prefixed with a
Warning that we consider an error level. There's an argument to be made
that some of our `console.error` don't make the bar for an error but
then the argument is to downgrade each of those to `console.warn` - not
to brand all our actual error logging with `Warning: `.

Apparently something needs to change in React Native before landing this
because it depends on the prefix somehow which probably doesn't make
sense already.
2024-06-10 18:41:56 -04:00
Ricky
d172bdaf95 Add jest lint rules (#29760)
## Overview

Updates `eslint-plugin-jest` and enables the recommended rules with some
turned off that are unhelpful.

The main motivations is:
a) we have a few duplicated tests, which this found an I deleted 
b) making sure we don't accidentally commit skipped tests
2024-06-10 14:31:37 -04:00
Joe Savona
c50d593e63 [compiler] Type ref prop as a ref
Adds a shape type for component props, which has one defined property: "ref". This means that if the ref property exists, we can type usage of `props.ref` (or via destructuring) the same as the result of `useRef()` and infer downstream usage similarly.

ghstack-source-id: 76cd07c5dfeea2a4aafe141912663b097308fd73
Pull Request resolved: https://github.com/facebook/react/pull/29834
2024-06-10 11:29:55 -07:00
Rick Hanlon
bf1bb2e5e5 Fix xplat sync syntax error 2024-06-10 13:30:30 -04:00
Ricky
f81d5ee219 Fix xplat sync (#29833)
## Overview

The clever trick in https://github.com/facebook/react/pull/29799 turns
out to not work because signedsource includes the generated hash in the
header. Reverts back to checking git diff, filtering out the REVISION
file and `@generated` headers.
2024-06-10 13:24:45 -04:00
Joe Savona
a532d91d01 compiler: Known hooks/nonescaping scopes dont count as pruned
There are two cases where it's legit/intended to remove scopes, and we can inline the scope rather than reify a "pruned" scope:
* Scopes that contain a single instruction with a hook call. The fact that we create a scope in this case at all is just an artifact of it being simpler to do this and remove the scope later rather than try to avoid creating it in the first place. So for these scopes, we can just inline them.
* Scopes that are provably non-escaping. Removing the scope is an optimization, not a case of us having to prune away something that should be there. So again, its fine to inline in this case.

I found this from syncing the stack internally and looking at differences in compiled output. The latter case was most common but the first case is just an obvious improvement.

ghstack-source-id: 80610ddafad65eb837d0037e2692dd74bc548088
Pull Request resolved: https://github.com/facebook/react/pull/29820
2024-06-10 08:42:06 -07:00
Joe Savona
cdbafc8e67 compiler: Log metrics on pruned memo blocks/values
Adds additional information to the CompileSuccess LoggerEvent:
* `prunedMemoBlocks` is the number of reactive scopes that were pruned for some reason.
* `prunedMemoValues` is the number of unique _values_ produced by those scopes.

Both numbers exclude blocks that are just a hook call - ie although we create and prune a scope for eg `useState()`, that's just an artifact of the sequencing of our pipeline. So what this metric is counting is cases of _other_ values that go unmemoized. See the new fixture, which takes advantage of improvements in the snap runner to optionally emit the logger events in the .expect.md file if you include the "logger" pragma in a fixture.

ghstack-source-id: c2015bb5565746d07427587526b71e23685279c2
Pull Request resolved: https://github.com/facebook/react/pull/29810
2024-06-10 08:42:06 -07:00
Joe Savona
7d445acb02 compiler: treat pruned scope outputs as reactive
Mostly addresses the issue with non-reactive pruned scopes. Before, values from pruned scopes would not be memoized, but could still be depended upon by downstream scopes. However, those downstream scopes would assume the value could never change. This could allow the developer to observe two different versions of a value - the freshly created one (if observed outside a scope) or a cached one (if observed inside, or through) a scope which used the value but didn't depend on it.

The fix here is to consider the outputs of pruned reactive scopes as reactive. Note that this is a partial fix because of things like control variables — the full solution would be to mark these values as reactive, and then re-run InferReactivePlaces. We can do this once we've fully converted our pipeline to use HIR everywhere. For now, this should fix most issues in practice because PruneNonReactiveDependencies already does basic alias tracking (see new fixture).

ghstack-source-id: 364430bbeca4cfca2fbf9df4d92b2e61b3352311
Pull Request resolved: https://github.com/facebook/react/pull/29790
2024-06-10 08:42:06 -07:00
Joe Savona
d193455fc3 compiler: Promote pruned scope declarations to temporaries if used in a later scope
There's a category of bug currently where pruned reactive scopes whose outputs are non-reactive can have their code end up inlining into another scope, moving the location of the instruction. Any value that had a scope assigned has to have its order of evaluation preserved, despite the fact that it got pruned, so naively we could just force every pruned scope to have its declarations promoted to named variables.

However, that ends up assigning names to _tons_ of scope declarations that don't really need to be promoted. For example, a scope with just a hook call ends up with:

```
const x = useFoo();

=>

scope {
 $t0 = Call read useFoo$ (...);
}
$t1 = StoreLocal 'x' = read $t0;
```

Where t0 doesn't need to be promoted since it's used immediately to assign to another value which is a non-temporary.

So the idea of this PR is that we can track outputs of pruned scopes which are directly referenced from inside a later scope. This fixes one of the two cases of the above pattern. We'll also likely have to consider values from pruned scopes as always reactive, i'll do that in the next PR.

ghstack-source-id: b37fb9a7cb1430b7c35ec5946269ce5a886a486a
Pull Request resolved: https://github.com/facebook/react/pull/29789
2024-06-10 08:42:06 -07:00
Joe Savona
aa0930452b compiler: Represent pruned scopes instead of inlining
There are a few places where we want to check whether a value actually got memoized, and we currently have to infer this based on values that "should" have a scope and whether a corresponding scope actually exists. This PR adds a new ReactiveStatement variant to model a reactive scope block that was pruned for some reason, and updates all the passes that prune scopes to instead produce this new variant.

ghstack-source-id: aea6dab469acb1f20058b85cb6f9aafab5d167cd
Pull Request resolved: https://github.com/facebook/react/pull/29781
2024-06-10 08:42:06 -07:00
Rick Hanlon
a0e99f7a6d Revert bad push 2024-06-10 10:51:07 -04:00
Rick Hanlon
13cd4018a8 don't commit 2024-06-10 10:47:18 -04:00
Rick Hanlon
b6b2ab1e0c try this 2024-06-10 10:46:11 -04:00
Ricky
6b35ff766a Move @generated from build to sync (#29799)
## Overview

Reverts https://github.com/facebook/react/pull/26616 and implements the
suggested way instead.

This change in #26616 broken the internal sync command, which now
results in duplicated `@generated` headers. It also makes it harder to
detect changes during the diff train sync. Instead, we will check for
changes, and if there are changes sign the files and commit them to the
sync branch.

## Strategy

The new sync strategy accounts for the generated headers during the
sync:
- **Revert Version**: Revert the version strings
- **Revert @generated**: Re-sign the files (will be the same hash as
before if unchanged)
- **Check**: Check if there are changes **if not, skip**
- **Re-apply Version**: Now add back the new version string
- **Re-sign @generated**: And re-generate the headers

Then commit to branch. This ensures that if there are no changes, we'll
skip.

---------

Co-authored-by: Timothy Yung <yungsters@gmail.com>
2024-06-10 10:16:40 -04:00
Niklas Mollenhauer
f5af92d2c4 feat(compiler): Support MetaProperty (#29752)
## Summary
See #29737

## How did you test this change?
As the feature requires module support and the test runner does
currently not support running tests as modules, I could only test it via
playground.
2024-06-08 16:18:35 -07:00
Sebastian Markbåge
c2ae9e28bc Minify DEV bundles with closure (#29809)
The goal is to improve speed of the development by inlining and DCE
unused branches.

We have the ability to preserve some variable names and pretty print in
the production version so might as well do the same with DEV.
2024-06-08 11:15:57 -04:00
Josh Story
20b6f4c0e8 [Float][Fiber] Assume stylesheets in document are already loaded (#29811)
When we made stylesheets suspend even during high priority updates we
exposed a bug in the loading tracking of stylesheets that are loaded as
part of the preamble. This allowed these stylesheets to put suspense
boundaries into fallback mode more often than expected because cases
where a stylesheet was server rendered could now cause a fallback to
trigger which was never intended to happen.

This fix updates resource construction to evaluate whether the instance
exists in the DOM prior to construction and if so marks the resource as
loaded and inserted.

One ambiguity that needed to be solved still is how to tell whether a
stylesheet rendered as part of a late Suspense boundary reveal is
already loaded. I updated the instruction to clear out the loading
promise after successfully loading. This is useful because later if we
encounter this same resource again we can avoid the microtask if it is
already loaded. It also means that we can concretely understand that if
a stylesheet is in the DOM without this marker then it must have loaded
(or errored) already.
2024-06-07 16:53:24 -07:00
Lauren Tan
20841f9a62 [compiler] Always emit variable decl in gating mode
This PR makes it so we always emit a const VariableDeclaration for
compiled functions in gating mode. If the original declaration's parent
was an ExportDefaultDeclaration we'll also append a new
ExportDefaultDeclaration pointing to the new identifier. This allows
code that adds optional properties to the function declaration to still
work in gating mode

ghstack-source-id: 5705479135baa268eeb3c85bfbf1883964e84916
Pull Request resolved: https://github.com/facebook/react/pull/29806
2024-06-07 15:50:31 -04:00
Lauren Tan
a65de775e2 [compiler] Add repro for func properties bug with gating
When gating is enabled, any function declaration properties that were
previously set (typically `Function.displayName`) would cause a crash
after compilation as the original identifier is no longer present.

ghstack-source-id: beb7e258561ea598d306fa67706d34a8788d9322
Pull Request resolved: https://github.com/facebook/react/pull/29802
2024-06-07 15:50:30 -04:00
Sebastian Markbåge
a0a435d68f [Fiber] Track the Real Fiber for Key Warnings (#29791)
This refactors key warning to happen inline after we've matched a Fiber.
I didn't want to do that originally because it was riskier. But it turns
out to be straightforward enough.

This lets us use that Fiber as the source of the warning which matters
to DevTools because then DevTools can associate it with the right
component after it mounts.

We can also associate the duplicate key warning with this Fiber. That
way we'll get the callsite with the duplicate key on the stack and can
associate this warning with the child that had the duplicate.

I kept the forked DevTools tests because the warning now is counted on
the Child instead of the Parent (18 behavior).

However, this won't be released in 19.0.0 so I only test this in
whatever the next version is.

Doesn't seem worth it to have a test for just the 19.0.0 behavior.
2024-06-07 13:38:44 -04:00
Lauren Tan
0a5e0b0c2e [compiler] Fix outdated comment in scripts/release
ghstack-source-id: a37c6faa8b6d0fa443b5a3cb2f0d8398f8e7588c
Pull Request resolved: https://github.com/facebook/react/pull/29800
2024-06-07 12:29:50 -04:00
Sebastian Markbåge
cc1ec60d0d [Flight] Run recreated Errors within a fake native stack (#29717)
Stacked on #29740.

Before:

<img width="719" alt="Screenshot 2024-06-02 at 11 51 20 AM"
src="https://github.com/facebook/react/assets/63648/8f79fa82-2474-4583-894e-a2329e9a6304">

After (updated with my patches to Chrome):

<img width="813" alt="Screenshot 2024-06-06 at 5 16 20 PM"
src="https://github.com/facebook/react/assets/63648/bcc4f52f-e0ac-4708-ac2b-9629acdff705">

Sources panel after:

<img width="1188" alt="Screenshot 2024-06-06 at 5 14 21 PM"
src="https://github.com/facebook/react/assets/63648/2c673fac-d32d-42e4-8fac-bb63704e4b7f">

The fake eval file is now under "React" and the real file is now under
`file://`
2024-06-07 11:54:14 -04:00
Jan Kassens
142b2a8230 www: make disableLegacyMode dynamic flag (#29774)
This makes the flag dynamic for Meta and turns it on for the www test
renderer.
2024-06-07 07:36:10 -04:00
Joe Savona
827cbea417 compiler: Add support for ref effects
Fixes false positives where we currently disallow mutations of refs from callbacks passed to JSX, if the ref is also passed to jsx. We consider these to be mutations of "frozen" values, but refs are explicitly allowed to have interior mutability. The fix is to always allow (at leat within InferReferenceEffects) for refs to be mutated. This means we completely rely on ValidateNoRefAccessInRender to validate ref access and stop reporting false positives.

ghstack-source-id: 1a30609f5f
Pull Request resolved: https://github.com/facebook/react/pull/29733
2024-06-06 17:19:42 -07:00
Josh Story
c4b433f8cb [Flight] Allow aborting during render (#29764)
Stacked on #29491

Previously if you aborted during a render the currently rendering task
would itself be aborted which will cause the entire model to be replaced
by the aborted error rather than just the slot currently being rendered.

This change updates the abort logic to mark currently rendering tasks as
aborted but allowing the current render to emit a partially serialized
model with an error reference in place of the current model.

The intent is to support aborting from rendering synchronously, in
microtasks (after an await or in a .then) and in lazy initializers. We
don't specifically support aborting from things like proxies that might
be triggered during serialization of props
2024-06-06 14:41:27 -07:00
Ruslan Lesiutin
fe5ce4e3e9 fix[react-devtools/store-test]: fork the test to represent current be… (#29777)
## Summary

The test started to fail after
https://github.com/facebook/react/pull/29088.

Fork the test and the expected store state for:
- React 18.x, to represent the previous behavior
- React >= 19, to represent the current RDT behavior, where error can't
be connected to the fiber, because it was not yet mounted and shared
with DevTools.

Ideally, DevTools should start keeping track of such fibers, but also
distinguish them from some that haven't mounted due to Suspense or error
boundaries.
2024-06-06 20:01:15 +01:00
Ricky
90499a730e Fix RN version string in builds (#29787)
The version was set for React but not the renderers
2024-06-06 14:07:16 -04:00
Lauren Tan
29b1278790 [compiler] Check for __DEV__ for FastRefresh
We don't always have the NODE_ENV set, so additionally check for the
__DEV__ global if it has one set.

ghstack-source-id: 3719a4710a5fb1b4abf511f469c815917b7dfdf4
Pull Request resolved: https://github.com/facebook/react/pull/29785
2024-06-06 13:54:55 -04:00
XiaoPi
70194be403 fix<compiler>: reread the testfilter file if filter enabled during the watch process (#29775)
Resolve #29720
In the above PR, I overlooked that we can change the filter mode during the watch process. Now it's fixed.
2024-06-06 10:48:24 -07:00
Josh Story
1e1e5cd252 [Flight] Schedule work in a microtask (#29491)
Stacked on #29551

Flight pings much more often than Fizz because async function components
will always take at least a microtask to resolve . Rather than
scheduling this work as a new macrotask Flight now schedules pings in a
microtask. This allows more microtasks to ping before actually doing a
work flush but doesn't force the vm to spin up a new task which is quite
common give n the nature of Server Components
2024-06-06 10:19:57 -07:00
Josh Story
b526a0a419 [Flight][Fizz] schedule work async (#29551)
While most builds of Flight and Fizz schedule work in new tasks some do
execute work synchronously. While this is necessary for legacy APIs like
renderToString for modern APIs there really isn't a great reason to do
this synchronously.

We could schedule works as microtasks but we actually want to yield so
the runtime can run events and other things that will unblock additional
work before starting the next work loop.

This change updates all non-legacy uses to be async using the best
availalble macrotask scheduler.

Browser now uses postMessage
Bun uses setTimeout because while it also supports setImmediate the
scheduling is not as eager as the same API in node
the FB build also uses setTimeout

This change required a number of changes to tests which were utilizing
the sync nature of work in the Browser builds to avoid having to manage
timers and tasks. I added a patch to install MessageChannel which is
required by the browser builds and made this patched version integrate
with the Scheduler mock. This way we can effectively use `act` to flush
flight and fizz work similar to how we do this on the client.
2024-06-06 10:07:24 -07:00
Vitali Zaidman
fd6e130b00 Default native inspections config false (#29784)
## Summary

To make the config `supportsNativeInspection` explicit, set it to
default to `false` and only allow it in the extension.

## How did you test this change?
When disabled on **React DevTools extension**
<img width="419" alt="Screenshot 2024-06-06 at 17 34 02"
src="https://github.com/facebook/react/assets/5188459/0052b645-2214-475c-8b41-4f9207ca3343">

When enabled on **React DevTools extension** (the chosen config)
<img width="425" alt="Screenshot 2024-06-06 at 17 34 53"
src="https://github.com/facebook/react/assets/5188459/df34ec8e-2039-4984-86c8-74feaf89bbdd">

When enabled on **React DevTools in Fusebox**
<img width="1170" alt="Screenshot 2024-06-06 at 17 29 24"
src="https://github.com/facebook/react/assets/5188459/ae52274b-583d-463c-8482-2323d502f4c0">

When disabled on **React DevTools in Fusebox** (the chosen config)
<img width="1453" alt="Screenshot 2024-06-06 at 17 30 31"
src="https://github.com/facebook/react/assets/5188459/cba5b51b-c973-412d-8ad0-382a4f9bf115">

When enabled on **React DevTools Inline**
<img width="915" alt="Screenshot 2024-06-06 at 17 24 20"
src="https://github.com/facebook/react/assets/5188459/f0d61d99-2b75-4a87-a19e-db431be697e3">

When disabled on **React DevTools Inline** (the chosen config)
<img width="844" alt="Screenshot 2024-06-06 at 17 19 39"
src="https://github.com/facebook/react/assets/5188459/d3bcc8a7-535d-4656-844d-f9f89bb2b248">

When enabled on **React DevTools standalone**
<img width="1227" alt="Screenshot 2024-06-06 at 17 23 16"
src="https://github.com/facebook/react/assets/5188459/174fbae6-1412-4539-bbe6-e1d0e8baa7d5">

When disabled on **React DevTools standalone** (the chosen config)
<img width="844" alt="Screenshot 2024-06-06 at 17 19 39"
src="https://github.com/facebook/react/assets/5188459/00c46907-e3a6-4766-a1b4-dd088cac2157">
2024-06-06 17:48:44 +01:00
Vitali Zaidman
99da76f23a fix[react-devtools] remove native inspection button when it can't be used (#29779)
## Summary

There's no native inspection available in any of the React-Native
devtools:
* **React DevTools in Fusebox**
* **React DevTools standalone**

Besides, **React DevTools Inline** can't really open the devtools and
point to the native inspector because of lack of an API to do that.

Only **React DevTools extension** can actually do that.

That's why I've disabled it for the first 3 flavours of React DevTools
mentioned above.


## How did you test this change?
Still enabled on **React DevTools extension**
<img width="1355" alt="Screenshot 2024-06-06 at 16 09 21"
src="https://github.com/facebook/react/assets/5188459/a9b658a6-eafe-443c-9298-280bb9f4ed72">

Disabled on **React DevTools in Fusebox**
<img width="1670" alt="Screenshot 2024-06-06 at 16 04 28"
src="https://github.com/facebook/react/assets/5188459/a2ded76f-2aaf-47ce-b581-611494ca33bd">

Disabled on **React DevTools standalone**
<img width="1268" alt="Screenshot 2024-06-06 at 16 15 08"
src="https://github.com/facebook/react/assets/5188459/eb2f308d-32cb-43ea-921b-3503aa874d64">

Disabled on **React DevTools Inline**
<img width="1206" alt="Screenshot 2024-06-06 at 16 09 26"
src="https://github.com/facebook/react/assets/5188459/03da741a-66bf-4414-91f7-2f344c78a880">
2024-06-06 17:10:40 +01:00
XiaoPi
704aeed022 feat<Compiler>: consider that the dispatch function from useReducer is non-reactive (#29705)
Summary
The dispatch function from useReducer is stable, so it is also non-reactive.

the related PR: #29665
the related comment: #29674 (comment)

I am not sure if the location of the new test file is appropriate😅.

How did you test this change?
Added the specific test compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/useReducer-returned-dispatcher-is-non-reactive.expect.md.
2024-06-05 16:51:09 -07:00
Ruslan Lesiutin
3730b40e9b chore[react-devtools]: ip => internal-ip (#29772)
## Summary

There was an attempt to upgrade `ip` to 2.0.1 to mitigate CVE in
https://github.com/facebook/react/pull/29725#issuecomment-2150389616,
but there actually another one CVE in version `2.0.1`. Instead, migrate
to `internal-ip`, which similarly small package that we can use

Note: not upgrading to version 7+, because they are pure ESM.

## How did you test this change?

Validated that standalone version of RDT works and connects to the app.
2024-06-05 19:58:12 +01:00
Dmytro Rykun
eb259b5d3b Add enableShallowPropDiffing feature flag (#29664)
## Summary

We currently do deep diffing for object props, and also use custom
differs, if they are defined, for props with custom attribute config.

The idea is to simply do a `===` comparison instead of all that work. We
will do less computation on the JS side, but send more data to native.

The hypothesis is that this change should be neutral in terms of
performance. If that's the case, we'll be able to get rid of custom
differs, and be one step closer to deleting view configs.

This PR adds the `enableShallowPropDiffing` feature flag to support this
experiment.

## How did you test this change?

With `enableShallowPropDiffing` hardcoded to `true`:
```
yarn test packages/react-native-renderer
```
This fails on the following test cases:
- should use the diff attribute
- should do deep diffs of Objects by default
- should skip deeply-nested changed functions

Which makes sense with this change. These test cases should be deleted
if the experiment is shipped.
2024-06-05 15:07:58 +01:00
Batuhan Tomo
8d87e374ac Fix #29724: ip dependency update for CVE-2024-29415 (#29725)
## Summary

This version update of `ip` dependency solves the CVE-2024-29415
vulnerability.
2024-06-05 11:17:35 +01:00
Sebastian Markbåge
1df34bdf62 [Flight] Override prepareStackTrace when reading stacks (#29740)
This lets us ensure that we use the original V8 format and it lets us
skip source mapping. Source mapping every call can be expensive since we
do it eagerly for server components even if an error doesn't happen.

In the case of an error being thrown we don't actually always do this in
practice because if a try/catch before us touches it or if something in
onError touches it (which the default console.error does), it has
already been initialized. So we have to be resilient to thrown errors
having other formats.

These are not as perf sensitive since something actually threw but if
you want better perf in these cases, you can simply do something like
`onError(error) { console.error(error.message) }` instead.

The server has to be aware whether it's looking up original or compiled
output. I currently use the file:// check to determine if it's referring
to a source mapped file or compiled file in the fixture. A bundled app
can more easily check if it's a bundle or not.
2024-06-05 09:41:37 +02:00
Sebastian Markbåge
d2767c96e8 [Flight] Encode fragments properly in DEV (#29762)
Normally we take the renderClientElement path but this is an internal
fast path.

No tests because we don't run tests with console.createTask (which is
not easy since we test component stacks).

Ideally this would be covered by types but since the types don't
consider flags and DEV it doesn't really help.
2024-06-04 18:10:06 -04:00
Ricky
eabb681535 Add xplat test variants (#29734)
## Overview

We didn't have any tests that ran in persistent mode with the xplat
feature flags (for either variant).

As a result, invalid test gating like in
https://github.com/facebook/react/pull/29664 were not caught.

This PR adds test flavors for `ReactFeatureFlag-native-fb.js` in both
variants.
2024-06-04 13:07:29 -04:00
Jiachi Liu
9185b9b1e4 Remove startTransition and useActionState from react-server condition of react (#29753)
<!--
  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

Remove `startTransition` and `useActionState` from `react-server`
condition of react, as they should only stay in client bundle.
This will reduce the server bundle of react itself. 

Found this while tracing where the `process.emit` was called.

<!--
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.
-->
2024-06-04 12:23:36 -04:00
Jan Kassens
a26e90c29c www: set enableRefAsProp to true (#29756)
www: set enableRefAsProp to true
2024-06-04 11:17:19 -04:00
XiaoPi
408258268e fix<compiler>: only call readTestFilter if the filter option is enabled (#29720)
Following the instructions in the compiler/docs/DEVELOPMENT_GUIDE.md, we are stuck on the command `yarn snap --watch` because it calls readTestFilter even though the filter option is not enabled.
2024-06-03 16:09:58 -07:00
Joe Savona
8b677b1e6e compiler: Allow opting out of installed library check
ghstack-source-id: eedd024d36
Pull Request resolved: https://github.com/facebook/react/pull/29742
2024-06-03 15:30:55 -07:00
Ricky
8c3697a849 Fix xplat sync to ignore @generated header (#29738)
Use some clever git diffing to ignore lines that only change the
`@generated` header. We can't do this for the version string because the
version string can be embedded in lines with other changes, but this
header is always on one line.
2024-06-03 16:39:38 -04:00
Sebastian Markbåge
4dcdf21325 [Fiber] Prefix owner stacks with the current stack at the console call (#29697)
This information is available in the regular stack but since that's
hidden behind an expando and our appended stack to logs is not hidden,
it hides the most important frames like the name of the current
component.

This is closer to what happens to the native stack.

We only include stacks if they're within a ReactFiberCallUserSpace call
frame. This should be most that have a current fiber but this is
critical to filtering out most React frames if the regular node_modules
filter doesn't work.

Most React warnings fire during the rendering phase and not inside a
user space function but some do like hooks warnings and setState in
render. This feature is more important if we port this to React DevTools
appending stacks to all logs where it's likely to originate from inside
a component and you want the line within that component to immediately
part of the visible stack.

One thing that kind sucks is that we don't have a reliable way to
exclude React internal stack frames. We filter node_modules but it might
not match. For other cases I try hard to only track the stack frame at
the root of React (e.g. immediately inside createElement) until the
ReactFiberCallUserSpace so we don't need the filtering to work. In this
case it's hard to achieve the same thing though. This is easier in RDT
because we have the start/end line and parsing of stack traces so we can
use that to exclude internals but that's a lot of code/complexity for
shipping within the library.

For example in Safari:

<img width="590" alt="Screenshot 2024-05-31 at 6 15 27 PM"
src="https://github.com/facebook/react/assets/63648/2820c8c0-8a03-42e9-8678-8348f66b051a">

Ideally warnOnUseFormStateInDev and useFormState wouldn't be included
since they're React internals. Before this change, the Counter.js line
also wasn't included though which points to exactly where the error is
within the user code.

(Note Server Components have V8 formatted lines and Client Components
have JSC formatted lines.)
2024-06-03 12:26:38 -04:00
Andrew Clark
bf3a29d097 Update build script to automatically generate RCs (#29736)
RC releases are a special kind of prerelease build because unlike
canaries we shouldn't publish new RCs from any commit on `main`, only
when we intentionally bump the RC number. But they are still prerelases
— like canary and experimental releases, they should use exact version
numbers in their dependencies (no ^).

We only need to generate these builds during the RC phase, i.e. when the
canary channel label is set to "rc".

Example of resulting package.json output:

```json
{
  "name": "react-dom",
  "version": "19.0.0-rc.0",
  "dependencies": {
    "scheduler": "0.25.0-rc.0"
  },
  "peerDependencies": {
    "react": "19.0.0-rc.0"
  }
}
```


https://react-builds.vercel.app/prs/29736/files/oss-stable-rc/react-dom/package.json
2024-06-03 12:21:21 -04:00
Andrew Clark
9598c41a20 useActionState: On error, cancel remaining actions (#29695)
Based on

- #29694 

---

If an action in the useActionState queue errors, we shouldn't run any
subsequent actions. The contract of useActionState is that the actions
run in sequence, and that one action can assume that all previous
actions have completed successfully.

For example, in a shopping cart UI, you might dispatch an "Add to cart"
action followed by a "Checkout" action. If the "Add to cart" action
errors, the "Checkout" action should not run.

An implication of this change is that once useActionState falls into an
error state, the only way to recover is to reset the component tree,
i.e. by unmounting and remounting. The way to customize the error
handling behavior is to wrap the action body in a try/catch.
2024-06-03 11:25:43 -04:00
Andrew Clark
67b05be0d2 useActionState: Transfer transition context (#29694)
Mini-refactor of useActionState to only wrap the action in a transition
context if the dispatch is called during a transition. Conceptually, the
action starts as soon as the dispatch is called, even if the action is
queued until earlier ones finish.

We will also warn if an async action is dispatched outside of a
transition, since that is almost certainly a mistake. Ideally we would
automatically upgrade these to a transition, but we don't have a great
way to tell if the action is async until after it's already run.
2024-06-03 11:20:27 -04:00
Josh Story
def67b9b32 Fix stylesheet typo in 29693 (#29732)
stylehsheet -> stylesheet
2024-06-03 07:51:21 -07:00
Josh Story
47d0c30246 [Fiber][Float] Error when a host fiber changes "flavor" (#29693)
Host Components can exist as four semantic types

1. regular Components (Vanilla obv)
2. singleton Components
2. hoistable components
3. resources

Each of these component types have their own rules related to mounting
and reconciliation however they are not direclty modeled as their own
unique fiber type. This is partly for code size but also because
reconciling the inner type of these components would be in a very hot
path in fiber creation and reconciliation and it's just not practical to
do this logic check here.

Right now we have three Fiber types used to implement these 4 concepts
but we probably need to reconsider the model and think of Host
Components as a single fiber type with an inner implementation. Once we
do this we can regularize things like transitioning between a resource
and a regular component or a singleton and a hoistable instance. The
cases where these transitions happen today aren't particularly common
but they can be observed and currently the handling of these transitions
is incomplete at best and buggy at worst. The most egregious case is the
link type. This can be a regular component (stylesheet without
precedence) a hoistable component (non stylesheet link tags) or a
resource (stylesheet with a precedence) and if you have a single jsx
slot that tries to reconcile transitions between these types it just
doesn't work well.

This commit adds an error for when a Hoistable goes from Instance to
Resource. Currently this is only possible for `<link>` elements going to
and from stylesheets with precedence. Hopefully we'll be able to remove
this error and implement as an inner type before we encounter new
categories for the Hoistable types

detecting type shifting to and from regular components is harder to do
efficiently because we don't want to reevaluate the type on every update
for host components which is currently not required and would add
overhead to a very hot path

singletons can't really type shift in their one practical implementation
(DOM) so they are only a problem in theroy not practice
2024-06-03 07:47:45 -07:00
Rick Hanlon
b421783110 Don't skip www commit 2024-06-03 10:21:28 -04:00
Ricky
5ad2c37273 Skip empty sync commits (both repos) (#29707)
Requires https://github.com/facebook/react/pull/29706

The strategy here is to:
- Checkout the builds/facebook-www branch
- Read the current sync'd VERSION
- Checkout out main and sync new build
- sed/{new version string}/{old version string}
- Run git status, skip sync if clean
- Otherwise, sed/{old version string}/{new version string} and push
commit

This means that:
- We're using the real version strings from the builds
- We are checking the last commit on the branch for the real last
version
- We're skipping any commits that won't result in changes
- ???
- Profit!
2024-06-03 10:09:23 -04:00
Sebastian Markbåge
ba099e442b [Flight] Add findSourceMapURL option to get a URL to load Server source maps from (#29708)
This lets you click a stack frame on the client and see the Server
source code inline.

<img width="871" alt="Screenshot 2024-06-01 at 11 44 24 PM"
src="https://github.com/facebook/react/assets/63648/581281ce-0dce-40c0-a084-4a6d53ba1682">

<img width="840" alt="Screenshot 2024-06-01 at 11 43 37 PM"
src="https://github.com/facebook/react/assets/63648/00dc77af-07c1-4389-9ae0-cf1f45199efb">

We could do some logic on the server that sends a source map url for
every stack frame in the RSC payload. That would make the client
potentially config free. However regardless we need the config to
describe what url scheme to use since that’s not built in to the bundler
config. In practice you likely have a common pattern for your source
maps so no need to send data over and over when we can just have a
simple function configured on the client.

The server must return a source map, even if the file is not actually
compiled since the fake file is still compiled.

The source mapping strategy can be one of two models depending on if the
server’s stack traces (`new Error().stack`) are source mapped back to
the original (`—enable-source-maps`) or represents the location in
compiled code (like in the browser).

If it represents the location in compiled code it’s actually easier. You
just serve the source map generated for that file by the tooling.

If it is already source mapped it has to generate a source map where
everything points to the same location (as if not compiled) ideally with
a segment per logical ast node.
2024-06-02 22:58:24 -04:00
Lauren Tan
d77dd31a32 Bump version to 0.0.0-experimental-7054a14-20240601 2024-06-01 08:15:27 +09:00
Lauren Tan
c6b651bee0 Bump version to 0.0.0-experimental-51a85ea-20240601 2024-06-01 08:15:27 +09:00
Lauren Tan
b17016c869 Bump version to 0.0.0-experimental-938cd9a-20240601 2024-06-01 08:15:27 +09:00
Lauren Tan
113c8e7f72 [compiler:eslint] Don't crash if hermes parser fails to parse
Eslint rules should never throw, so if we fail to parse with Babel or
Hermes, we should just ignore the error. This should fix issues such as
trying to run the eslint rule on non tsx|ts|jsx|js files, Hermes parser
not supporting certain JS syntax, etc.

I didn't add a test for this as our eslint-rule-tester config uses
hermes-eslint parser, so it wasn't possible to add a top level await as
it would crash hermes-eslint before our rule was triggered. Similarly I
couldn't add a test for non-JS files as it would not be parseable by
hermes-eslint.

Fixes #29107

ghstack-source-id: 60afcdb89ab4a8d2e4697cc50c5490803e7cbeac
Pull Request resolved: https://github.com/facebook/react/pull/29631
2024-06-01 08:04:41 +09:00
Andrew Clark
adbec0c25a Fix: useTransition after use gets stuck in pending state (#29670)
When a component suspends with `use`, we switch to the "re-render"
dispatcher during the subsequent render attempt, so that we can reuse
the work from the initial attempt. However, once we run out of hooks
from the previous attempt, we should switch back to the regular "update"
dispatcher.

This is conceptually the same fix as the one introduced in
https://github.com/facebook/react/pull/26232. That fix only accounted
for initial mount, but the useTransition regression test added in
f82973302b3f490ec120c3b102e8c3792452dfc9 illustrates that we need to
handle updates, too.

The issue affects more than just useTransition but because most of the
behavior between the "re-render" and "update" dispatchers is the same
it's hard to contrive other scenarios in a test, which is probably why
it took so long for someone to notice.

Closes #28923 and #29209

---------

Co-authored-by: eps1lon <sebastian.silbermann@vercel.com>
2024-05-31 17:52:47 -04:00
Mike Vitousek
ec6fe57a50 [compiler] rfc: Include location information in identifiers and reactive scopes for debugging
Summary: Using the change detection code to debug codebases that violate the rules of react is a lot easier when we have a source location corresponding to the value that has changed inappropriately. I didn't see an easy way to track that information in the existing data structures at the point of codegen, so this PR adds locations to identifiers and reactive scopes (the location of a reactive scope is the range of the locations of its included identifiers).

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

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

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

ghstack-source-id: d0f11a4cb2
Pull Request resolved: https://github.com/facebook/react/pull/29657
2024-05-31 14:06:02 -07:00
Mike Vitousek
c69211a9df [compiler] Prune dependencies that are only used by useRef or useState
Summary: jmbrown215 recently had an observation that the arguments to useState/useRef are only used when a component renders for the first time, and never afterwards. We can skip more computation that we previously could, with reactive blocks that previously recomputed values when inputs changed now only ever computing them on the first render.

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

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

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

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

ghstack-source-id: 50dad3dacf
Pull Request resolved: https://github.com/facebook/react/pull/29656
2024-05-31 14:05:58 -07:00
Mike Vitousek
8b01a2e0bf [compiler] Option to always take the non-memo branch
Summary: This adds a debugging mode to the compiler that simply adds a `|| true` to the guard on all memoization blocks, which results in the generated code never using memoized values and always recomputing them. This is designed as a validation tool for the compiler's correctness--every program *should* behave exactly the same with this option enabled as it would with it disabled, and so any difference in behavior should be investigated as either a compiler bug or a pipeline issue.

(We add `|| true` rather than dropping the conditional block entirely because we still want to exercise the guard tests, in case the guards themselves are the source of an error, like reading a property from undefined in a guard.)

ghstack-source-id: 955a47ec16
Pull Request resolved: https://github.com/facebook/react/pull/29655
2024-05-31 14:04:54 -07:00
Mike Vitousek
28fe581bac [compiler] Option for preserving calls to useMemo/useCallback
Summary: This adds a compiler option to not drop existing manual memoization and leaving useMemo/useCallback in the generated source. Why do we need this, given that we also have options to validate or ensure that existing memoization is preserved? It's because later diffs on this stack are designed to alter the behavior of the memoization that the compiler emits, in order to detect rules of react violations and debug issues. We don't want to change the behavior of user-level memoization, however, since doing so would be altering the semantics of the user's program in an unacceptable way.

ghstack-source-id: 89dccdec9ccb4306b16e849e9fa2170bb5dd021f
Pull Request resolved: https://github.com/facebook/react/pull/29654
2024-05-31 14:02:13 -07:00
Sebastian Markbåge
8bc81ca90f Create a root task for every Flight response (#29673)
This lets any element created from the server, to bottom out with a
client "owner" which is the creator of the Flight request. This could be
a Server Action being invoked or a router.

This is similar to how a client element bottoms out in the creator of
the root element without an owner. E.g. where the root app element was
created.

Without this, we inherit the task of whatever is currently executing
when we're parsing which can be misleading.

Before:
<img width="507" alt="Screenshot 2024-05-30 at 12 06 57 PM"
src="https://github.com/facebook/react/assets/63648/e234db7e-67f7-404c-958a-5c5500ffdf1f">

After:
<img width="555" alt="Screenshot 2024-05-30 at 4 59 04 PM"
src="https://github.com/facebook/react/assets/63648/8ba6acb4-2ffd-49d4-bd44-08228ad4200e">

The before/after doesn't show much of a difference here but that's just
because our Flight parsing loop is an async, which maybe it shouldn't be
because it can be unnecessarily deep, and it creates a hidden line for
every loop. That's what the `Promise.then` is. If the element is lazily
initialized it's worse because we can end up in an unrelated render task
as the owner - although that's its own problem.
2024-05-31 13:54:10 -04:00
Ricky
6d3110b4d9 Don't allow blank issues (#29691)
We're getting a ton of issues filed using the blank template, for
example these airline support tickets:
https://github.com/facebook/react/issues/29678


I think someone somewhere is linking to our issues with pre-filled
content. This fixes it by forcing a template to be used.
2024-05-31 12:05:32 -04:00
Sebastian Markbåge
63d673c676 Use both displayName and name in forwardRef/memo (#29625)
When defining a displayName on forwardRef/memo we forward that name to
the inner function.

We used to use displayName for this but in #29206 I switched this to use
`"name"`. That's because V8 doesn't use displayName, it only uses the
overridden name in stack traces. This is the only thing covered by our
tests for component stacks.

However, I realized that Safari only uses displayName and not the name.
So this sets both.
2024-05-31 00:22:22 -04:00
Timothy Yung
8fd963a1e5 Fix Missing key Validation in React.Children (#29675)
## Summary

In https://github.com/facebook/react/pull/29088, the validation logic
for `React.Children` inspected whether `mappedChild` — the return value
of the map callback — has a valid `key`. However, this deviates from
existing behavior which only warns if the original `child` is missing a
required `key`.

This fixes false positive `key` validation warnings when using
`React.Children`, by validating the original `child` instead of
`mappedChild`.

This is a more general fix that expands upon my previous fix in
https://github.com/facebook/react/pull/29662.

## How did you test this change?

```
$ yarn test ReactChildren-test.js
```
2024-05-30 18:02:47 -07:00
Josh Wilson
aa3d6c0840 Add react-easy-state to list of known incompatible libraries. (#29661)
Like mobx, this library depends on mutating a Proxied store and breaks reference equality checks.
2024-05-30 16:37:09 -07:00
Sebastian Markbåge
9710853baf [Flight] Try/Catch Eval (#29671)
Follow up to https://github.com/facebook/react/pull/29632.

It's possible for `eval` to throw such as if we're in a CSP environment.
This is non-essential debug information. We can still proceed to create
a fake stack entry. It'll still have the right name. It just won't have
the right line/col number nor source url/source map. It might also be
ignored listed since it's inside Flight.
2024-05-30 15:00:55 -04:00
Sebastian Markbåge
9d4fba0788 [Flight] Eval Fake Server Component Functions to Recreate Native Stacks (#29632)
We have three kinds of stacks that we send in the RSC protocol:

- The stack trace where a replayed `console.log` was called on the
server.
- The JSX callsite that created a Server Component which then later
called another component.
- The JSX callsite that created a Host or Client Component.

These stack frames disappear in native stacks on the client since
they're executed on the server. This evals a fake file which only has
one call in it on the same line/column as the server. Then we call
through these fake modules to "replay" the callstack. We then replay the
`console.log` within this stack, or call `console.createTask` in this
stack to recreate the stack.

The main concern with this approach is the performance. It adds
significant cost to create all these eval:ed functions but it should
eventually balance out.

This doesn't yet apply source maps to these. With source maps it'll be
able to show the server source code when clicking the links.

I don't love how these appear.

- Because we haven't yet initialized the client module we don't have the
name of the client component we're about to render yet which leads to
the `<...>` task name.
- The `(async)` suffix Chrome adds is still a problem.
- The VMxxxx prefix is used to disambiguate which is noisy. Might be
helped by source maps.
- The continuation of the async stacks end up rooted somewhere in the
bootstrapping of the app. This might be ok when the bootstrapping ends
up ignore listed but it's kind of a problem that you can't clear the
async stack.

<img width="927" alt="Screenshot 2024-05-28 at 11 58 56 PM"
src="https://github.com/facebook/react/assets/63648/1c9d32ce-e671-47c8-9d18-9fab3bffabd0">

<img width="431" alt="Screenshot 2024-05-28 at 11 58 07 PM"
src="https://github.com/facebook/react/assets/63648/52f57518-bbed-400e-952d-6650835ac6b6">
<img width="327" alt="Screenshot 2024-05-28 at 11 58 31 PM"
src="https://github.com/facebook/react/assets/63648/d311a639-79a1-457f-9a46-4f3298d07e65">

<img width="817" alt="Screenshot 2024-05-28 at 11 59 12 PM"
src="https://github.com/facebook/react/assets/63648/3aefd356-acf4-4daa-bdbf-b8c8345f6d4b">
2024-05-30 12:00:46 -04:00
Ruslan Lesiutin
fb61a1b515 fix[ReactDebugHooks/find-primitive-index]: remove some assumptions (#29652)
Partially reverts https://github.com/facebook/react/pull/28593.

While rolling out RDT 5.2.0, I've observed some issues on React Native
side: hooks inspection for some complex hook trees, like in
AnimatedView, were broken. After some debugging, I've noticed a
difference between what is in frame's source.

The difference is in the top-most frame, where with V8 it will correctly
pick up the `Type` as `Proxy` in `hookStack`, but for Hermes it will be
`Object`. This means that for React Native this top most frame is
skipped, since sources are identical.

Here I am reverting back to the previous logic, where we check each
frame if its a part of the wrapper, but also updated `isReactWrapper`
function to have an explicit case for `useFormStatus` support.
2024-05-30 16:11:56 +01:00
Timothy Yung
5bd4031226 Revert Build Versions from Content Hash to Commit Hash (#29663)
https://github.com/facebook/react/pull/29236 caused issues for internal
syncs at Meta, because we were computing version numbers using file
hashes (to eliminate "no-op" internal sync commits). The problem is that
since version numbers may not be consistent across synced files (e.g. if
some files have not changed in recent commits), the newly introduced
version mismatch check fails.

There's some more work that needs to be done here to restore the
benefits of file-specific hashing, but for now this simply reverts the
content hash changes from the following PRs:

- https://github.com/facebook/react/pull/28633
(95319ab5af)
- https://github.com/facebook/react/pull/28590
(37676aba76)
- https://github.com/facebook/react/pull/28582
(cb076b593c)
- https://github.com/facebook/react/pull/26734
(5dd90c5623)
- https://github.com/facebook/react/pull/26331
(3cad3a54ed)
2024-05-30 07:26:12 -07:00
Timothy Yung
72644ef2f2 Fix key Warning for Flattened Positional Children (#29662)
## Summary

https://github.com/facebook/react/pull/29088 introduced a regression
triggering this warning when rendering flattened positional children:

> Each child in a list should have a unique "key" prop.

The specific scenario that triggers this is when rendering multiple
positional children (which do not require unique `key` props) after
flattening them with one of the `React.Children` utilities (e.g.
`React.Children.toArray`).

The refactored logic in `React.Children` incorrectly drops the
`element._store.validated` property in `__DEV__`. This diff fixes the
bug and introduces a unit test to prevent future regressions.

## How did you test this change?

```
$ yarn test ReactChildren-test.js
```
2024-05-30 07:25:48 -07:00
Dmytro Rykun
51dd09631a Add tests for ReactNativeAttributePayloadFabric.js (#29608)
## Summary

This PR add tests for `ReactNativeAttributePayloadFabric.js`.

It introduces `ReactNativeAttributePayloadFabric-test.internal.js`,
which is a copy-paste of `ReactNativeAttributePayload-test.internal.js`.

On top of that, there is a bunch of new test cases for the
`ReactNativeAttributePayloadFabric.create` function.

## How did you test this change?

```
yarn test packages/react-native-renderer
```
2024-05-30 10:24:00 +01:00
Niklas Mollenhauer
c2b45ef0dd feat(compiler): Implement constant folding for more binary expressions (#29650)
## Summary

There are already most arithmetic operators in constant propagation:
`+`, `-`, `*`, `/`.
We could add more, namely: `|`, `&`, `^`, `<<`, `>>`, `>>>` and `%`:

Input:
```js
function f() {
  return [
    123.45 | 0,
    123.45 & 0,
    123.45 ^ 0,
    123 << 0,
    123 >> 0,
    123 >>> 0,
    123.45 | 1,
    123.45 & 1,
    123.45 ^ 1,
    123 << 1,
    123 >> 1,
    123 >>> 1,
    3 ** 2,
    3 ** 2.5,
    3.5 ** 2,
    2 ** 3 ** 0.5,
    4 % 2,
    4 % 2.5,
    4 % 3,
    4.5 % 2,
  ];
}
```
Output:
```js
function f() {
  return [
    123, 0, 123, 123, 123, 123, 123, 1, 122, 246, 61, 61, 9,
    15.588457268119896, 12.25, 3.3219970854839125, 0, 1.5, 1, 0.5,
  ];
}
```

Resolves #29649

## How did you test this change?
See tests.

Note:
This PR was done without waiting for approval in #29649, so feel free to
just close it without any comment.
2024-05-29 10:35:19 -07:00
Joe Savona
867edc6576 compiler: ValidateNoRefInRender detects writes of refs
Improves ValidateNoRefAccessInRender, detecting modifications of refs during render.

Fixes #29161

ghstack-source-id: 99078b3cea5b2d9019dbf77ede9c2e4cd9fbfd27
Pull Request resolved: https://github.com/facebook/react/pull/29170
2024-05-29 09:27:44 -07:00
Niklas Mollenhauer
320da67570 feat(compiler): Compiler Logical Negation Constant Propagation (#29623)
## Summary

Resolves #29622

## How did you test this change?
I verified the implementation using the test.

Note:
This PR was done without waiting for approval in #29622, so feel free to
just close it.
2024-05-29 09:17:43 -07:00
Sophie Alpert
38e3b23483 Tweak error message for "Should have a queue" (#29626) 2024-05-29 08:41:10 -07:00
Joe Savona
afb2c39ec3 compiler: fixtures for fast-refresh mode (w todos)
ghstack-source-id: 65dd14fe9b37328bd60fe791b23dde54da10b285
Pull Request resolved: https://github.com/facebook/react/pull/29175
2024-05-29 07:47:05 -07:00
Joe Savona
c272789ce5 compiler: Add todo for getter/setter syntax
We were missing a check that ObjectMethods are not getters or setters. In our experience this is pretty rare within React components and hooks themselves, so let's start with a todo.

Closes #29586

ghstack-source-id: 03c6cce9a9
Pull Request resolved: https://github.com/facebook/react/pull/29592
2024-05-29 07:45:53 -07:00
Joe Savona
49ed6f0740 compiler: Allow global mutation in jsx props
Fixes https://x.com/raibima/status/1794395807216738792

The issue is that if you pass a global-modifying function as prop to JSX, we currently report that it's invalid to modify a global during rendering. The problem is that we don't really know when/if the child component will actually call that function prop. It would be against the rules to call the function during render, but it's totally fine to call it during an event handler or from a useEffect.

Since we don't know at the call-site how the child will use the function, we should allow such calls. In the future we could improve this in a few ways:
* For all functions that modify globals, codegen an assertion or warning into the function that fires if it's called "during render". We'd have to precisely define what "during render" is, but this would at least help developers catch this dynamically.
* Use the type system to distinguish "event/effect" and "render" functions to help developers avoid accidentally mutating globals during render.

ghstack-source-id: 4aba4e6d21
Pull Request resolved: https://github.com/facebook/react/pull/29591
2024-05-29 07:45:53 -07:00
Lauren Tan
e2e12f3351 Update .git-blame-ignore-revs
- Moves the file as it needs to be in root git directory
- Removes now unreachable commits due to repo merge
- Add run prettier commit c998bb1ed4 to ignored revs

ghstack-source-id: d9dfa7099fbc7782fbce600af4caafd405c196cb
Pull Request resolved: https://github.com/facebook/react/pull/29630
2024-05-29 18:12:16 +09:00
Timothy Yung
3b29ed1638 Fix "findNodeHandle inside its render()" False Positive Warning (#29627)
This was missed in https://github.com/facebook/react/pull/29038 when
unifying the "owner" abstractions, causing `findNodeHandle` to warn even
outside of `render()` invocations.
2024-05-28 20:36:41 -07:00
Lauren Tan
b44263addb Bump version to 0.0.0-experimental-31393f7-20240529 2024-05-29 12:01:36 +09:00
Lauren Tan
bd30dc3ae2 Bump version to 0.0.0-experimental-a97cca1-20240529 2024-05-29 12:01:35 +09:00
Lauren Tan
84c47b3d52 Bump version to 0.0.0-experimental-487cb0e-20240529 2024-05-29 12:01:35 +09:00
Lauren Tan
81c3775816 [compiler] Ignore run prettier commit in git blame 2024-05-29 11:47:42 +09:00
Lauren Tan
9d530e94c4 [compiler:babel] Don't read config files when not running as part of
user's pipeline

When the user app has a babel.config file that is missing the compiler,
strange things happen as babel does some strange merging of options from
the user's config and in various callsites like in our eslint rule and
healthcheck script. To minimize odd behavior, we default to not reading
the user's babel.config

Fixes #29135

ghstack-source-id: d6fdc43c5c
Pull Request resolved: https://github.com/facebook/react/pull/29211
2024-05-29 11:46:27 +09:00
Lauren Tan
c998bb1ed4 [compiler] Run prettier, fix snap
After this is merged, I'll add it to .git-blame-ignore-revs. I can't do
it now as the hash will change after ghstack lands this stack.

ghstack-source-id: 054ca869b7
Pull Request resolved: https://github.com/facebook/react/pull/29214
2024-05-29 11:46:27 +09:00
Lauren Tan
61aa159086 [compiler] Fix up prettier
Our prettier setup is all messed up after the merge, so this PR should
fix things

ghstack-source-id: f825460ea6
Pull Request resolved: https://github.com/facebook/react/pull/29213
2024-05-29 11:46:27 +09:00
Niklas Mollenhauer
a9a0106808 feat(compiler): Implement constant string concat propagation (#29621)
## Summary

Resolves #29617

## How did you test this change?
I verified the implementation using the test.
2024-05-28 16:15:46 -07:00
Sebastian Markbåge
18164761b1 [Flight] Check if a return value is a client reference before introspecting (#29611)
This didn't actually fail before but I'm just adding an extra check.

Currently Client References are always "function" proxies so they never
fall into this branch. However, we do in theory support objects as
client references too depending on environment. We have checks
elsewhere. So this just makes that consistent.
2024-05-28 19:07:30 -04:00
Joe Savona
bd4bb32fe7 compiler: fix for calls on builtin jsx/function types
When I added new builtin types for jsx and functions, i forget to add a shape definition. This meant that attempting to accesss a property or method on these types would cause an internal error with an unresolved shape. That wasn't obvious because we rarely call methods on these types.

I confirmed that the new fixtures here fail without the fix.

ghstack-source-id: aa8f8d75a3
Pull Request resolved: https://github.com/facebook/react/pull/29624
2024-05-28 15:17:49 -07:00
Joe Savona
46339720d7 compiler: error on reassigning to const
We currently don't report an error if the code attempts to reassign a const. Our thinking has been that we're not trying to catch all possible mistakes you could make in JavaScript — that's what ESLint, TypeScript, and Flow are for — and that we want to focus on React errors. However, accidentally reassigning a const is easy to catch and doesn't get in the way of other analysis so let's implement it.

Note that React Compiler's ESLint plugin won't report these errors by default, but they will show up in playground.

Fixes #29598

ghstack-source-id: a0af8b9a486d74a8991413322efddc3e3028c755
Pull Request resolved: https://github.com/facebook/react/pull/29619
2024-05-28 13:09:17 -07:00
Hendrik Liebau
97722ca3d4 Export version from react-dom entry with react-server condition (#29596) 2024-05-28 21:47:47 +02:00
Andrew Clark
163122766b Fix: Use action implementation at time of dispatch (#29618)
Fixes the behavior of actions that are queued by useActionState to use
the action function that was current at the time it was dispatched, not
at the time it eventually executes.

The conceptual model is that the action is immediately dispatched, as if
it were sent to a remote server/worker. It's the remote worker that
maintains the queue, not the client.

This is another property of actions makes them more like event handlers
than like reducers.
2024-05-28 15:08:59 -04:00
Jack Pope
2787eebe52 Clean up disableDOMTestUtils (#29610)
`disableDOMTestUtils` and the FB build `ReactTestUtilsFB` allowed us to
finish migrating internal callsites off of ReactTestUtils. Now that
usage is cleaned up, we can remove the flag, build artifact, and test
coverage for the deprecated utility methods.
2024-05-28 14:55:14 -04:00
Andrew Clark
681a4aa810 Throw if React and React DOM versions don't match (#29236)
Throw an error during module initialization if the version of the
"react-dom" package does not match the version of "react".

We used to be more relaxed about this, because the "react" package
changed so infrequently. However, we now have many more features that
rely on an internal protocol between the two packages, including Hooks,
Float, and the compiler runtime. So it's important that both packages
are versioned in lockstep.

Before this change, a version mismatch would often result in a cryptic
internal error with no indication of the root cause.

Instead, we will now compare the versions during module initialization
and immediately throw an error to catch mistakes as early as possible
and provide a clear error message.
2024-05-28 14:06:30 -04:00
Joseph Savona
4ec6a6f714 Repro function expr hoisting (#29615)
Modified version of @mofeiZ's #29232 with CI passing (had to run
prettier)

---------

Co-authored-by: Mofei Zhang <feifei0@meta.com>
2024-05-28 10:06:05 -07:00
Ruslan Lesiutin
6f23540c7d cleanup[react-devtools]: remove unused supportsProfiling flag from store config (#29193)
Looks like this is unused
2024-05-28 11:07:31 +01:00
Sebastian Markbåge
ea6e05912a [Fiber] Enable Native console.createTask Stacks When Available (#29223)
Stacked on #29206 and #29221.

This disables appending owner stacks to console when
`console.createTask` is available in the environment. Instead we rely on
native "async" stacks that end up looking like this with source maps and
ignore list enabled.

<img width="673" alt="Screenshot 2024-05-22 at 4 00 27 PM"
src="https://github.com/facebook/react/assets/63648/5313ed53-b298-4386-8f76-8eb85bdfbbc7">

Unfortunately Chrome requires a string name for each async stack and,
worse, a suffix of `(async)` is automatically added which is very
confusing since it seems like it might be an async component or
something which it is not.

In this case it's not so bad because it's nice to refer to the host
component which otherwise doesn't have a stack frame since it's
internal. However, if there were more owners here there would also be a
`<Counter> (async)` which ends up being kind of duplicative.

If the Chrome DevTools is not open from the start of the app, then
`console.createTask` is disabled and so you lose the stack for those
errors (or those parents if the devtools is opened later). Unlike our
appended ones that are always added. That's unfortunate and likely to be
a bit of a DX issue but it's also nice that it saves on perf in DEV mode
for those cases. Framework dialogs can still surface the stack since we
also track it in user space in parallel.

This currently doesn't track Server Components yet. We need a more
clever hack for that part in a follow up.

I think I probably need to also add something to React DevTools to
disable its stacks for this case too. Since it looks for stacks in the
console.error and adds a stack otherwise. Since we don't add them
anymore from the runtime, the DevTools adds them instead.
2024-05-26 17:55:57 -04:00
Sebastian Markbåge
b078c810c7 [Fiber] Replace setCurrentDebugFiberInDEV with runWithFiberInDEV (#29221)
Stacked on #29044.

To work with `console.createTask(...).run(...)` we need to be able to
run a function in the scope of the task.

The main concern with this, other than general performance, is that it
might add more stack frames on very deep stacks that hit the stack
limit. Such as with the commit phase where we recursively go down the
tree. These callbacks aren't really necessary in the recursive part but
only in the shallow invocation of the commit phase for each tag. So we
could refactor the commit phase so that only the shallow part at each
level is covered this way.
2024-05-25 11:58:40 -04:00
Sebastian Markbåge
d6cfa0f295 [Fiber] Use Owner/JSX Stack When Appending Stacks to Console (#29206)
This one should be fully behind the `enableOwnerStacks` flag.

Instead of printing the parent Component stack all the way to the root,
this now prints the owner stack of every JSX callsite. It also includes
intermediate callsites between the Component and the JSX call so it has
potentially more frames. Mainly it provides the line number of the JSX
callsite. In terms of the number of components is a subset of the parent
component stack so it's less information in that regard. This is usually
better since it's more focused on components that might affect the
output but if it's contextual based on rendering it's still good to have
parent stack. Therefore, I still use the parent stack when printing DOM
nesting warnings but I plan on switching that format to a diff view
format instead (Next.js already reformats the parent stack like this).

__Follow ups__

- Server Components show up in the owner stack for client logs but logs
done by Server Components don't yet get their owner stack printed as
they're replayed. They're also not yet printed in the server logs of the
RSC server.

- Server Component stack frames are formatted as the server and added to
the end but this might be a different format than the browser. E.g. if
server is running V8 and browser is running JSC or vice versa. Ideally
we can reformat them in terms of the client formatting.

- This doesn't yet update Fizz or DevTools. Those will be follow ups.
Fizz still prints parent stacks in the server side logs. The stacks
added to user space `console.error` calls by DevTools still get the
parent stacks instead.

- It also doesn't yet expose these to user space so there's no way to
get them inside `onCaughtError` for example or inside a custom
`console.error` override.

- In another follow up I'll use `console.createTask` instead and
completely remove these stacks if it's available.
2024-05-25 11:58:17 -04:00
Joe Savona
935180c7e0 compiler: only resolve globals and react imports
Updates Environment#getGlobalDeclaration() to only resolve "globals" if they are a true global or an import from react/react-dom. We still keep the logic to resolve hook-like names as custom hooks. Notably, this means that a local `Array` reference won't get confused with our Array global declaration, a local `useState` (or import from something other than React) won't get confused as `React.useState()`, etc.

I tried to write a proper fixture test to test that we react to changes to a custom setState setter function, but I think there may be an issue with snap and how it handles re-renders from effects. I think the tests are good here but open to feedback if we want to go down the rabbit hole of figuring out a proper snap test for this.

ghstack-source-id: 5e9a8f6e0d23659c72a9d041e8d394b83d6e526d
Pull Request resolved: https://github.com/facebook/react/pull/29190
2024-05-24 10:20:26 +01:00
Joe Savona
788ed90b18 compiler: getGlobalDeclaration() takes a NonLocalBinding
No-op refactor to make Environment#getGlobalDeclaration() take a NonLocalBinding instead of just a name. The idea is that in subsequent PRs we can use information about the binding to resolve a type more accurately. For example, we can resolve `Array` differently if its an import or local and not the global Array. Similar for resolving local `useState` differently than the one from React.

ghstack-source-id: c8063e6fb8acdd347a56477d6b06238dd54979b1
Pull Request resolved: https://github.com/facebook/react/pull/29189
2024-05-24 10:20:26 +01:00
Joe Savona
5061f31f4b compiler: distinguish globals/imports/module-locals
We currently use `LoadGlobal` and `StoreGlobal` to represent any read (or write) of a variable defined outside the component or hook that is being compiled. This is mostly fine, but for a lot of things we want to do going forward (resolving types across modules, for example) it helps to understand the actual source of a variable.

This PR is an incremental step in that direction. We continue to use LoadGlobal/StoreGlobal, but LoadGlobal now has a `binding:NonLocalBinding` instead of just the name of the global. The NonLocalBinding type tells us whether it was an import (and which kind, the source module name etc), a module-local binding, or a true global. By keeping the LoadGlobal/StoreGlobal instructions, most code that deals with "anything not declared locally" doesn't have to care about the difference. However, code that _does_ want to know the source of the value can figure it out.

ghstack-source-id: e701d4ebc0fb5681a0197198ac2c2a03b3e8aae9
Pull Request resolved: https://github.com/facebook/react/pull/29188
2024-05-24 10:20:26 +01:00
Andrew Clark
ee5c194930 Fix async batching in React.startTransition (#29226)
Note: Despite the similar-sounding description, this fix is unrelated to
the issue where updates that occur after an `await` in an async action
must also be wrapped in their own `startTransition`, due to the absence
of an AsyncContext mechanism in browsers today.

---

Discovered a flaw in the current implementation of the isomorphic
startTransition implementation (React.startTransition), related to async
actions. It only creates an async scope if something calls setState
within the synchronous part of the action (i.e. before the first
`await`). I had thought this was fine because if there's no update
during this part, then there's nothing that needs to be entangled. I
didn't think this through, though — if there are multiple async updates
interleaved throughout the rest of the action, we need the async scope
to have already been created so that _those_ are batched together.

An even easier way to observe this is to schedule an optimistic update
after an `await` — the optimistic update should not be reverted until
the async action is complete.

To implement, during the reconciler's module initialization, we compose
its startTransition implementation with any previous reconciler's
startTransition that was already initialized. Then, the isomorphic
startTransition is the composition of every
reconciler's startTransition.

```js
function startTransition(fn) {
  return startTransitionDOM(() => {
    return startTransitionART(() => {
      return startTransitionThreeFiber(() => {
        // and so on...
        return fn();
      });
    });
  });
}
```

This is basically how flushSync is implemented, too.
2024-05-23 17:19:09 -04:00
Josh Story
f55d172bcf [Fiber] clarify entry condition for suspensey commit recursion (#29222)
Previously Suspensey recursion would only trigger if the
ShouldSuspendCommit flag was true. However there is a dependence on the
Visibility flag embedded in this logic because these flags share a bit.
To make it clear that the semantics of Suspensey resources require
considering both flags I've added it to the condition even though this
extra or-ing is a noop when the bit is shared
2024-05-23 13:54:51 -07:00
Sebastian Markbåge
84239da896 Move createElement/JSX Warnings into the Renderer (#29088)
This is necessary to simplify the component stack handling to make way
for owner stacks. It also solves some hacks that we used to have but
don't quite make sense. It also solves the problem where things like key
warnings get silenced in RSC because they get deduped. It also surfaces
areas where we were missing key warnings to begin with.

Almost every type of warning is issued from the renderer. React Elements
are really not anything special themselves. They're just lazily invoked
functions and its really the renderer that determines there semantics.

We have three types of warnings that previously fired in
JSX/createElement:

- Fragment props validation.
- Type validation.
- Key warning.

It's nice to be able to do some validation in the JSX/createElement
because it has a more specific stack frame at the callsite. However,
that's the case for every type of component and validation. That's the
whole point of enableOwnerStacks. It's also not sufficient to do it in
JSX/createElement so we also have validation in the renderers too. So
this validation is really just an eager validation but also happens
again later.

The problem with these is that we don't really know what types are valid
until we get to the renderer. Additionally, by placing it in the
isomorphic code it becomes harder to do deduping of warnings in a way
that makes sense for that renderer. It also means we can't reuse logic
for managing stacks etc.

Fragment props validation really should just be part of the renderer
like any other component type. This also matters once we add Fragment
refs and other fragment features. So I moved this into Fiber. However,
since some Fragments don't have Fibers, I do the validation in
ChildFiber instead of beginWork where it would normally happen.

For `type` validation we already do validation when rendering. By
leaving it to the renderer we don't have to hard code an extra list.
This list also varies by context. E.g. class components aren't allowed
in RSC but client references are but we don't have an isomorphic way to
identify client references because they're defined by the host config so
the current logic is flawed anyway. I kept the early validation for now
without the `enableOwnerStacks` since it does provide a nicer stack
frame but with that flag on it'll be handled with nice stacks anyway. I
normalized some of the errors to ensure tests pass.

For `key` validation it's the same principle. The mechanism for the
heuristic is still the same - if it passes statically through a parent
JSX/createElement call then it's considered validated. We already did
print the error later from the renderer so this also disables the early
log in the `enableOwnerStacks` flag.

I also added logging to Fizz so that key warnings can print in SSR logs.

Flight is a bit more complex. For elements that end up on the client we
just pass the `validated` flag along to the client and let the client
renderer print the error once rendered. For server components we log the
error from Flight with the server component as the owner on the stack
which will allow us to print the right stack for context. The factoring
of this is a little tricky because we only want to warn if it's in an
array parent but we want to log the error later to get the right debug
info.

Fiber/Fizz has a similar factoring problem that causes us to create a
fake Fiber for the owner which means the logs won't be associated with
the right place in DevTools.
2024-05-23 12:48:57 -04:00
Joe Savona
5fe8c0b4ec compiler: repro for unmerged scopes due to intermediates
Repro of a case where we should ideally merge consecutive scopes, but where intermediate temporaries prevent the scopes from merging.

We'd need to reorder instructions in order to merge these.

ghstack-source-id: 4f05672604eeb547fc6c26ef99db6572843ac646
Pull Request resolved: https://github.com/facebook/react/pull/29197
2024-05-23 17:44:56 +01:00
Joe Savona
b687fd27b5 compiler: Use types to decide which scopes are eligible for merging
In MergeReactiveScopesThatInvalidateTogether when deciding which scopes were eligible for mergin at all, we looked specifically at the instructions whose lvalue produces the declaration. So if a scope declaration was `t0`, we'd love for the instruction where `t0` was the lvalue and look at the instruction type to decide if it is eligible for merging.

Here, we use the inferred type instead (now that the inferred types support the same set of types of instructions we looked at before). This allows us to find more cases where scopes can be merged.

ghstack-source-id: 0e3e05f24ea0ac6e3c43046bc3e114f906747a04
Pull Request resolved: https://github.com/facebook/react/pull/29157
2024-05-23 17:44:56 +01:00
Joe Savona
890896b2db compiler: Improve merging of memo scopes that invalidate together
Improves merging of consecutive scopes so that we now merge two scopes if the dependencies of the second scope are a subset of the previous scope's output *and* that dependency has a type that will always produce a new value (array, object, jsx, function) if it is re-evaluated.

To make this easier, we extend the set of builtin types to include ones for function expressions and JSX and to infer these types in InferTypes. This allows using the already inferred types in MergeReactiveScopesThatInvalidateTogether.

ghstack-source-id: e9119fc4e02b3665848113d71fdff0c5bac3348a
Pull Request resolved: https://github.com/facebook/react/pull/29156
2024-05-23 17:44:55 +01:00
Joe Savona
82a0a5f88a compiler: fixture for suboptimal jsx sibling memo block merging
React Compiler attempts to merge consecutive reactive scopes in order to reduce overhead. The basic idea is that if two consecutive scopes would always invalidate together then we should merge them. It gets more complicated, though, because values produced by the earlier scope may not always invalidate when their inputs do. For example, a scope that produces `fn(x)` may not invalidate on all changes to `x` if the function is `Math.max(x, 10)` (changing x from 8 to 9 won't change the output).

Previously we were conservative and only merged if either:
* the two scopes had the same dependencies
* the second scope's deps exactly matched the previous scope's outputs.

You can see this in the new fixture, where the second `<button>` gets its own scope, which happens because the preceding scope has an extra output that isn't a dep of the `<button>`'s scope.

ghstack-source-id: d869c8d4df5aa4105bbdae01b5dd7f106145b351
Pull Request resolved: https://github.com/facebook/react/pull/29155
2024-05-23 17:44:55 +01:00
Sebastian Markbåge
2e540e22b2 Set the current fiber to the source of the error during error reporting (#29044)
This lets us expose the component stack to the error reporting that
happens here as `console.error` patching. Now if you just call
`console.error` in the error handlers it'll get the component stack
added to the end by React DevTools.

However, unfortunately this happens a little too late so the Fiber will
be disconnected with its `.return` pointer set to null already. So it'll
be too late to extract a parent component stack from but you can at
least get the stack from source to error boundary. To work around this I
manually add the parent component stack in our default handlers when
owner stacks are off. We could potentially fix this but you can also
just include it yourself if you're calling `console.error` and it's not
a problem for owner stacks.

This is not a problem for owner stacks because we'll still have those
and so for those just calling `console.error` just works. However, the
main feature is that by letting React add them, we can switch to using
native error stacks when available.
2024-05-23 12:39:52 -04:00
Sebastian Markbåge
2e3e6a9b1c Unify ReactFiberCurrentOwner and ReactCurrentFiber (#29038)
We previously had two slightly different concepts for "current fiber".

There's the "owner" which is set inside of class components in prod if
string refs are enabled, and sometimes inside function components in DEV
but not other contexts.

Then we have the "current fiber" which is only set in DEV for various
warnings but is enabled in a bunch of contexts.

This unifies them into a single "current fiber".

The concept of string refs shouldn't really exist so this should really
be a DEV only concept. In the meantime, this sets the current fiber
inside class render only in prod, however, in DEV it's now enabled in
more contexts which can affect the string refs. That was already the
case that a string ref in a Function component was only connecting to
the owner in prod. Any string ref associated with any non-class won't
work regardless so that's not an issue. The practical change here is
that an element with a string ref created inside a life-cycle associated
with a class will work in DEV but not in prod. Since we need the current
fiber to be available in more contexts in DEV for the debugging
purposes. That wouldn't affect any old code since it would have a broken
ref anyway. New code shouldn't use string refs anyway.

The other implication is that "owner" doesn't necessarily mean
"rendering" since we need the "owner" to track other debug information
like stacks - in other contexts like useEffect, life cycles, etc.
Internally we have a separate `isRendering` flag that actually means
we're rendering but even that is a very overloaded concept. So anything
that uses "owner" to imply rendering might be wrong with this change.

This is a first step to a larger refactor for tracking current rendering
information.

---------

Co-authored-by: Sebastian Silbermann <silbermann.sebastian@gmail.com>
2024-05-23 12:25:23 -04:00
Henry Q. Dineen
4c2e457c7c compiler: Handle TSNonNullAssertion expressions (#29218)
## Summary

We ran React compiler against part of our codebase and collected
compiler errors. One of the more common non-actionable errors is caused
by usage of the `!` TypeScript non-null assertion operation:

```
(BuildHIR::lowerExpression) Handle TSNonNullExpression expressions
```

It seems like React Compiler _should_ be able to support this by just
ignoring the syntax and using the underlying expression. I'm sure a lot
of our non-null assertion usage should not exist and I understand if
React Compiler does not want to support this syntax. It wasn't obvious
to me if this omission was intentional or if there are future plans to
use `TSNonNullExpression` as part of the compiler's analysis. If there
are no future plans it seems like just ignoring it should be fine.

## How did you test this change?

```sh
❯ yarn snap --filter
yarn run v1.17.3
$ yarn workspace babel-plugin-react-compiler run snap --filter
$ node ../snap/dist/main.js --filter
 PASS  non-null-assertion
1 Tests, 1 Passed, 0 Failed
```
2024-05-22 23:42:06 +01:00
Sebastian Silbermann
f994737d14 [Flight] Allow temporary references in decodeReplyFromBusboy (#29219) 2024-05-22 21:15:14 +02:00
Sebastian Silbermann
3ac551e855 Dim console calls on additional Effect invocations due to StrictMode (#29007) 2024-05-22 11:39:54 +02:00
Josh Story
81c5ff2e04 [Flight Reply] retain listeners when resolving models with existing listeners (#29207)
In #29201 a fix was made to ensure we don't "forget" about some
listeners when handling cyclic chunks.
In #29204 another fix was made for a special case when the chunk already
has listeners before it first resolves.

This implements the followup fix for Flight Reply which was originally
missed in #29204

Co-authored-by: Janka Uryga <lolzatu2@gmail.com>
2024-05-21 16:16:20 -07:00
Josh Story
217b2ccf16 [Fiber] render boundary in fallback if it contains a new stylesheet during sync update (#28965)
Updates Suspensey instances and resources to preload even during urgent
updates and to potentially suspend.

The current implementation is unchanged for transitions but for sync
updates if there is a suspense boundary above the resource/instance it
will be rendered in fallback mode instead.

Note: This behavior is not what we want for images once we make them
suspense enabled. We will need to have forked behavior here to
distinguish between stylesheets which should never commit when not
loaded and images which should commit after a small delay
2024-05-21 16:03:46 -07:00
Lauren Tan
0f58454803 [compiler:playground] Update babel.config.js
Use new defaults

ghstack-source-id: d2da1df69db9f1b01578af6d52ea4a2613769f9b
Pull Request resolved: https://github.com/facebook/react/pull/29205
2024-05-21 18:12:30 -04:00
Lauren Tan
b759b71ead [compiler:playground] JS tab is expanded by default
When using the playground you typically want to see what it outputs, so
let's make the JS tab expanded by default.

ghstack-source-id: 721bc4c381c50db008058b31e1f976e92eab8548
Pull Request resolved: https://github.com/facebook/react/pull/29203
2024-05-21 18:12:30 -04:00
Janka Uryga
9b3f909cc1 [Flight] don't overwrite existing chunk listeners in 'wakeChunkIfInitialized' (#29204)
Follow up to https://github.com/facebook/react/pull/29201. If a chunk
had listeners attached already (e.g. because `.then` was called on the
chunk returned from `createFromReadableStream`),
`wakeChunkIfInitialized` would overwrite any listeners added during
chunk initialization. This caused cyclic [path
references](https://github.com/facebook/react/pull/28996) within that
chunk to never resolve. Fixed by merging the two arrays of listeners.
2024-05-21 14:04:46 -07:00
Lauren Tan
0a0a5c02f1 [compiler:playground] Wait for build before running playground
Explicitly waits for the build to finish since the playground requires
them to run

ghstack-source-id: 0bd7d5272d7fa09dc3a140b82a962dc4a3ae585b
Pull Request resolved: https://github.com/facebook/react/pull/29180
2024-05-21 15:44:04 -04:00
Sebastian Markbåge
8f3c0525f9 [Flight / Flight Reply] Don't clear pending listeners when entering blocked state (#29201)
Fixes #29200

The cyclic state might have added listeners that will still need to be
invoked. This happens if we have a cyclic reference AND end up blocked.

We have already cleared these before entering the parsing when we enter
the CYCLIC state so we they already have the right type. If listeners
are added during this phase they should carry over to the blocked state.

---------

Co-authored-by: Hendrik Liebau <mail@hendrik-liebau.de>
2024-05-21 14:12:20 -04:00
Sebastian Silbermann
5cc9f69a74 Fix assertConsoleErrorDev on message mismatch with withoutStack: true (#29198)
## Summary

```js
assertConsoleErrorDev([
  ['Hello', {withoutStack: true}]
])
```

now errors with a helpful diff message if the message mismatched. See
first commit for previous behavior.

## How did you test this change?

- `yarn test --watch
packages/internal-test-utils/__tests__/ReactInternalTestUtils-test.js`
2024-05-21 12:48:41 -04:00
Timothy Yung
7621466b1b Enable disableStringRefs and enableRefAsProp for React Native (Meta) (#29177)
## Summary

Enables the `disableStringRefs` and `enableRefAsProp` feature flags for
React Native (Meta).

## How did you test this change?

```
$ yarn test
$ yarn flow fabric
```
2024-05-21 11:19:12 +01:00
Sebastian Silbermann
55dd0b1d0e Stop using Scheduler.log to test double invocations (#29008) 2024-05-21 00:30:45 +02:00
Sebastian Silbermann
bf046e8653 React DOM: Treat toggle and beforetoggle as discrete events (#29176) 2024-05-20 23:44:51 +02:00
Sebastian Silbermann
6f90365128 React DOM: Add support for Popover API (#27981) 2024-05-20 22:01:39 +02:00
Abishek Ilango
d3ce0d3ea9 feat(compiler-healthcheck): Support strict mode check for nextjs apps (#29167)
## Summary

Closes #29130 

## How did you test this change?

Run the healthcheck in the compiler playground and the nodejs.org repo
for the next config with a `.mjs` extension. Sanity with Vite React
template.

Signed-off-by: abizek <abishekilango@protonmail.com>
2024-05-20 08:55:35 -07:00
Jack Youstra
57fbe3ba37 [Compiler playground] bold changed passes (#29159)
<!--
  Thanks for submitting a pull request!
We appreciate you spending the time to work on these changes. Please
provide enough information so that others can review your pull request.
The three fields below are mandatory.

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

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

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

## Summary

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

In the playground, it's hard to see at a glance what compiler passes are
involved in introducing changes.
This PR bolds every pass that introduces a change.

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

Before:
<img width="1728" alt="image"
src="https://github.com/facebook/react/assets/5144292/803ca786-0726-4456-b0db-520dc90a6771">

After:
<img width="1728" alt="image"
src="https://github.com/facebook/react/assets/5144292/38885644-00e9-4065-9c44-db533000d13a">
2024-05-20 08:05:48 -07:00
Ruslan Lesiutin
d14ce51327 refactor[react-devtools]: rewrite context menus (#29049)
## Summary
- While rolling out RDT 5.2.0 on Fusebox, we've discovered that context
menus don't work well with this environment. The reason for it is the
context menu state implementation - in a global context we define a map
of registered context menus, basically what is shown at the moment (see
deleted Contexts.js file). These maps are not invalidated on each
re-initialization of DevTools frontend, since the bundle
(react-devtools-fusebox module) is not reloaded, and this results into
RDT throwing an error that some context menu was already registered.
- We should not keep such data in a global state, since there is no
guarantee that this will be invalidated with each re-initialization of
DevTools (like with browser extension, for example).
- The new implementation is based on a `ContextMenuContainer` component,
which will add all required `contextmenu` event listeners to the
anchor-element. This component will also receive a list of `items` that
will be displayed in the shown context menu.
- The `ContextMenuContainer` component is also using
`useImperativeHandle` hook to extend the instance of the component, so
context menus can be managed imperatively via `ref`:
`contextMenu.current?.hide()`, for example.
- **Changed**: The option for copying value to clipboard is now hidden
for functions. The reasons for it are:
- It is broken in the current implementation, because we call
`JSON.stringify` on the value, see
`packages/react-devtools-shared/src/backend/utils.js`.
- I don't see any reasonable value in doing this for the user, since `Go
to definition` option is available and you can inspect the real code and
then copy it.
- We already filter out fields from objects, if their value is a
function, because the whole object is passed to `JSON.stringify`.

## How did you test this change?
### Works with element props and hooks:
- All context menu items work reliably for props items
- All context menu items work reliably or hooks items


https://github.com/facebook/react/assets/28902667/5e2d58b0-92fa-4624-ad1e-2bbd7f12678f

### Works with timeline profiler:
- All context menu items work reliably: copying, zooming, ...
- Context menu automatically closes on the scroll event


https://github.com/facebook/react/assets/28902667/de744cd0-372a-402a-9fa0-743857048d24

### Works with Fusebox:
- Produces no errors
- Copy to clipboard context menu item works reliably


https://github.com/facebook/react/assets/28902667/0288f5bf-0d44-435c-8842-6b57bc8a7a24
2024-05-20 15:12:21 +01:00
dependabot[bot]
c325aec1ee Bump word-wrap from 1.2.3 to 1.2.5 in /compiler (#29064)
Bumps [word-wrap](https://github.com/jonschlinkert/word-wrap) from 1.2.3
to 1.2.5.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a
href="https://github.com/jonschlinkert/word-wrap/releases">word-wrap's
releases</a>.</em></p>
<blockquote>
<h2>1.2.5</h2>
<p><strong>Changes</strong>:</p>
<p>Reverts default value for <code>options.indent</code> to two spaces
<code>' '</code>.</p>
<p><strong>Full Changelog</strong>: <a
href="https://github.com/jonschlinkert/word-wrap/compare/1.2.4...1.2.5">https://github.com/jonschlinkert/word-wrap/compare/1.2.4...1.2.5</a></p>
<h2>1.2.4</h2>
<h2>What's Changed</h2>
<ul>
<li>Remove default indent by <a
href="https://github.com/mohd-akram"><code>@​mohd-akram</code></a> in <a
href="https://redirect.github.com/jonschlinkert/word-wrap/pull/24">jonschlinkert/word-wrap#24</a></li>
<li>🔒fix: CVE 2023 26115 (2) by <a
href="https://github.com/OlafConijn"><code>@​OlafConijn</code></a> in <a
href="https://redirect.github.com/jonschlinkert/word-wrap/pull/41">jonschlinkert/word-wrap#41</a></li>
<li>🔒 fix: CVE-2023-26115 by <a
href="https://github.com/aashutoshrathi"><code>@​aashutoshrathi</code></a>
in <a
href="https://redirect.github.com/jonschlinkert/word-wrap/pull/33">jonschlinkert/word-wrap#33</a></li>
<li>chore: publish workflow by <a
href="https://github.com/OlafConijn"><code>@​OlafConijn</code></a> in <a
href="https://redirect.github.com/jonschlinkert/word-wrap/pull/42">jonschlinkert/word-wrap#42</a></li>
</ul>
<h2>New Contributors</h2>
<ul>
<li><a
href="https://github.com/mohd-akram"><code>@​mohd-akram</code></a> made
their first contribution in <a
href="https://redirect.github.com/jonschlinkert/word-wrap/pull/24">jonschlinkert/word-wrap#24</a></li>
<li><a
href="https://github.com/OlafConijn"><code>@​OlafConijn</code></a> made
their first contribution in <a
href="https://redirect.github.com/jonschlinkert/word-wrap/pull/41">jonschlinkert/word-wrap#41</a></li>
<li><a
href="https://github.com/aashutoshrathi"><code>@​aashutoshrathi</code></a>
made their first contribution in <a
href="https://redirect.github.com/jonschlinkert/word-wrap/pull/33">jonschlinkert/word-wrap#33</a></li>
</ul>
<p><strong>Full Changelog</strong>: <a
href="https://github.com/jonschlinkert/word-wrap/compare/1.2.3...1.2.4">https://github.com/jonschlinkert/word-wrap/compare/1.2.3...1.2.4</a></p>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="207044ebda"><code>207044e</code></a>
1.2.5</li>
<li><a
href="9894315485"><code>9894315</code></a>
revert default indent</li>
<li><a
href="f64b188c72"><code>f64b188</code></a>
run verb to generate README</li>
<li><a
href="03ea08256b"><code>03ea082</code></a>
Merge pull request <a
href="https://redirect.github.com/jonschlinkert/word-wrap/issues/42">#42</a>
from jonschlinkert/chore/publish-workflow</li>
<li><a
href="420dce9a24"><code>420dce9</code></a>
Merge pull request <a
href="https://redirect.github.com/jonschlinkert/word-wrap/issues/41">#41</a>
from jonschlinkert/fix/CVE-2023-26115-2</li>
<li><a
href="bfa694edf5"><code>bfa694e</code></a>
Update .github/workflows/publish.yml</li>
<li><a
href="ace0b3c78f"><code>ace0b3c</code></a>
chore: bump version to 1.2.4</li>
<li><a
href="6fd7275946"><code>6fd7275</code></a>
chore: add publish workflow</li>
<li><a
href="30d6daf60f"><code>30d6daf</code></a>
chore: fix test</li>
<li><a
href="655929cabe"><code>655929c</code></a>
chore: remove package-lock</li>
<li>Additional commits viewable in <a
href="https://github.com/jonschlinkert/word-wrap/compare/1.2.3...1.2.5">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=word-wrap&package-manager=npm_and_yarn&previous-version=1.2.3&new-version=1.2.5)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)
You can disable automated security fix PRs for this repo from the
[Security Alerts
page](https://github.com/facebook/react/network/alerts).

</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-05-20 12:03:55 +01:00
dependabot[bot]
ba51ebe03a Bump tough-cookie from 4.1.2 to 4.1.4 in /compiler (#29065)
Bumps [tough-cookie](https://github.com/salesforce/tough-cookie) from
4.1.2 to 4.1.4.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a
href="https://github.com/salesforce/tough-cookie/releases">tough-cookie's
releases</a>.</em></p>
<blockquote>
<h2>v4.1.4</h2>
<p><a
href="https://www.npmjs.com/package/tough-cookie/v/4.1.4">https://www.npmjs.com/package/tough-cookie/v/4.1.4</a></p>
<h2>What's Changed</h2>
<ul>
<li>Add local alias for <code>toString</code> by <a
href="https://github.com/corvidism"><code>@​corvidism</code></a> in <a
href="https://redirect.github.com/salesforce/tough-cookie/pull/409">salesforce/tough-cookie#409</a></li>
<li>Fix incorrect string validation for URL by <a
href="https://github.com/coditva"><code>@​coditva</code></a> in <a
href="https://redirect.github.com/salesforce/tough-cookie/pull/261">salesforce/tough-cookie#261</a></li>
</ul>
<h2>New Contributors</h2>
<ul>
<li><a href="https://github.com/corvidism"><code>@​corvidism</code></a>
made their first contribution in <a
href="https://redirect.github.com/salesforce/tough-cookie/pull/409">salesforce/tough-cookie#409</a></li>
<li><a href="https://github.com/coditva"><code>@​coditva</code></a> made
their first contribution in <a
href="https://redirect.github.com/salesforce/tough-cookie/pull/261">salesforce/tough-cookie#261</a></li>
</ul>
<p><strong>Full Changelog</strong>: <a
href="https://github.com/salesforce/tough-cookie/compare/v4.1.3...v4.1.4">https://github.com/salesforce/tough-cookie/compare/v4.1.3...v4.1.4</a></p>
<h2>4.1.3</h2>
<p>Security fix for Prototype Pollution discovery in <a
href="https://redirect.github.com/salesforce/tough-cookie/issues/282">#282</a>.
This is a minor release, although output from the <code>inspect</code>
utility is affected by this change, we felt this change was important
enough to be pushed into the next patch.</p>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="cacbc37936"><code>cacbc37</code></a>
Bump version to 4.1.4</li>
<li><a
href="a48fb3a6ba"><code>a48fb3a</code></a>
Add tests for url validation</li>
<li><a
href="50e69bf937"><code>50e69bf</code></a>
Merge pull request <a
href="https://redirect.github.com/salesforce/tough-cookie/issues/261">#261</a>
from postmanlabs/fix/url-string-validation</li>
<li><a
href="1253d58825"><code>1253d58</code></a>
Merge pull request <a
href="https://redirect.github.com/salesforce/tough-cookie/issues/409">#409</a>
from corvidism/validators-to-string</li>
<li><a
href="238367e2f1"><code>238367e</code></a>
Add local alias for <code>toString</code></li>
<li><a
href="4ff4d29f6c"><code>4ff4d29</code></a>
4.1.3 release preparation, update the package and lib/version to 4.1.3.
(<a
href="https://redirect.github.com/salesforce/tough-cookie/issues/284">#284</a>)</li>
<li><a
href="12d474791b"><code>12d4747</code></a>
Prevent prototype pollution in cookie memstore (<a
href="https://redirect.github.com/salesforce/tough-cookie/issues/283">#283</a>)</li>
<li><a
href="f06b72d1d4"><code>f06b72d</code></a>
Fix documentation for store.findCookies, missing allowSpecialUseDomain
proper...</li>
<li><a
href="cf6debd15f"><code>cf6debd</code></a>
Fix incorrect string validation for URL</li>
<li>See full diff in <a
href="https://github.com/salesforce/tough-cookie/compare/v4.1.2...v4.1.4">compare
view</a></li>
</ul>
</details>
<details>
<summary>Maintainer changes</summary>
<p>This version was pushed to npm by <a
href="https://www.npmjs.com/~ccasey">ccasey</a>, a new releaser for
tough-cookie since your current version.</p>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=tough-cookie&package-manager=npm_and_yarn&previous-version=4.1.2&new-version=4.1.4)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)
You can disable automated security fix PRs for this repo from the
[Security Alerts
page](https://github.com/facebook/react/network/alerts).

</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-05-20 12:03:29 +01:00
dependabot[bot]
9abea0cb7c Bump rustix from 0.37.22 to 0.37.27 in /compiler (#29173)
Bumps [rustix](https://github.com/bytecodealliance/rustix) from 0.37.22
to 0.37.27.
<details>
<summary>Commits</summary>
<ul>
<li><a
href="b38dc51262"><code>b38dc51</code></a>
chore: Release rustix version 0.37.27</li>
<li><a
href="a2d9c8ee1a"><code>a2d9c8e</code></a>
Fix p{read,write}v{,v2}'s encoding of the offset argument on Linux. (<a
href="https://redirect.github.com/bytecodealliance/rustix/issues/896">#896</a>)
(#...</li>
<li><a
href="dce2777622"><code>dce2777</code></a>
chore: Release rustix version 0.37.26</li>
<li><a
href="06dbe83c60"><code>06dbe83</code></a>
Fix <code>sendmsg_unix</code>'s address encoding. (<a
href="https://redirect.github.com/bytecodealliance/rustix/issues/885">#885</a>)
(<a
href="https://redirect.github.com/bytecodealliance/rustix/issues/886">#886</a>)</li>
<li><a
href="00b84d6aac"><code>00b84d6</code></a>
chore: Release rustix version 0.37.25</li>
<li><a
href="cad15a7076"><code>cad15a7</code></a>
Fixes for <code>Dir</code> on macOS, FreeBSD, and WASI.</li>
<li><a
href="df3c3a192c"><code>df3c3a1</code></a>
Merge pull request from GHSA-c827-hfw6-qwvm</li>
<li><a
href="b78aeff1a2"><code>b78aeff</code></a>
chore: Release rustix version 0.37.24</li>
<li><a
href="c0c3f01d7c"><code>c0c3f01</code></a>
Add GNU/Hurd support (<a
href="https://redirect.github.com/bytecodealliance/rustix/issues/852">#852</a>)</li>
<li><a
href="f416b6b27b"><code>f416b6b</code></a>
Fix the <code>test_ttyname_ok</code> test when /dev/stdin is
inaccessable. (<a
href="https://redirect.github.com/bytecodealliance/rustix/issues/821">#821</a>)</li>
<li>Additional commits viewable in <a
href="https://github.com/bytecodealliance/rustix/compare/v0.37.22...v0.37.27">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=rustix&package-manager=cargo&previous-version=0.37.22&new-version=0.37.27)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)
You can disable automated security fix PRs for this repo from the
[Security Alerts
page](https://github.com/facebook/react/network/alerts).

</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-05-20 12:02:35 +01:00
dependabot[bot]
8287cb9290 Bump postcss from 8.4.24 to 8.4.31 in /compiler (#29063)
Bumps [postcss](https://github.com/postcss/postcss) from 8.4.24 to
8.4.31.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a
href="https://github.com/postcss/postcss/releases">postcss's
releases</a>.</em></p>
<blockquote>
<h2>8.4.31</h2>
<ul>
<li>Fixed <code>\r</code> parsing to fix CVE-2023-44270.</li>
</ul>
<h2>8.4.30</h2>
<ul>
<li>Improved source map performance (by <a
href="https://github.com/romainmenke"><code>@​romainmenke</code></a>).</li>
</ul>
<h2>8.4.29</h2>
<ul>
<li>Fixed <code>Node#source.offset</code> (by <a
href="https://github.com/idoros"><code>@​idoros</code></a>).</li>
<li>Fixed docs (by <a
href="https://github.com/coliff"><code>@​coliff</code></a>).</li>
</ul>
<h2>8.4.28</h2>
<ul>
<li>Fixed <code>Root.source.end</code> for better source map (by <a
href="https://github.com/romainmenke"><code>@​romainmenke</code></a>).</li>
<li>Fixed <code>Result.root</code> types when <code>process()</code> has
no parser.</li>
</ul>
<h2>8.4.27</h2>
<ul>
<li>Fixed <code>Container</code> clone methods types.</li>
</ul>
<h2>8.4.26</h2>
<ul>
<li>Fixed clone methods types.</li>
</ul>
<h2>8.4.25</h2>
<ul>
<li>Improve stringify performance (by <a
href="https://github.com/romainmenke"><code>@​romainmenke</code></a>).</li>
<li>Fixed docs (by <a
href="https://github.com/vikaskaliramna07"><code>@​vikaskaliramna07</code></a>).</li>
</ul>
</blockquote>
</details>
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a
href="https://github.com/postcss/postcss/blob/main/CHANGELOG.md">postcss's
changelog</a>.</em></p>
<blockquote>
<h2>8.4.31</h2>
<ul>
<li>Fixed <code>\r</code> parsing to fix CVE-2023-44270.</li>
</ul>
<h2>8.4.30</h2>
<ul>
<li>Improved source map performance (by Romain Menke).</li>
</ul>
<h2>8.4.29</h2>
<ul>
<li>Fixed <code>Node#source.offset</code> (by Ido Rosenthal).</li>
<li>Fixed docs (by Christian Oliff).</li>
</ul>
<h2>8.4.28</h2>
<ul>
<li>Fixed <code>Root.source.end</code> for better source map (by Romain
Menke).</li>
<li>Fixed <code>Result.root</code> types when <code>process()</code> has
no parser.</li>
</ul>
<h2>8.4.27</h2>
<ul>
<li>Fixed <code>Container</code> clone methods types.</li>
</ul>
<h2>8.4.26</h2>
<ul>
<li>Fixed clone methods types.</li>
</ul>
<h2>8.4.25</h2>
<ul>
<li>Improve stringify performance (by Romain Menke).</li>
<li>Fixed docs (by <a
href="https://github.com/vikaskaliramna07"><code>@​vikaskaliramna07</code></a>).</li>
</ul>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="90208de880"><code>90208de</code></a>
Release 8.4.31 version</li>
<li><a
href="58cc860b4c"><code>58cc860</code></a>
Fix carrier return parsing</li>
<li><a
href="4fff8e4cdc"><code>4fff8e4</code></a>
Improve pnpm test output</li>
<li><a
href="cd43ed1232"><code>cd43ed1</code></a>
Update dependencies</li>
<li><a
href="caa916bdcb"><code>caa916b</code></a>
Update dependencies</li>
<li><a
href="8972f76923"><code>8972f76</code></a>
Typo</li>
<li><a
href="11a5286f78"><code>11a5286</code></a>
Typo</li>
<li><a
href="45c5501777"><code>45c5501</code></a>
Release 8.4.30 version</li>
<li><a
href="bc3c341f58"><code>bc3c341</code></a>
Update linter</li>
<li><a
href="b2be58a2eb"><code>b2be58a</code></a>
Merge pull request <a
href="https://redirect.github.com/postcss/postcss/issues/1881">#1881</a>
from romainmenke/improve-sourcemap-performance--phil...</li>
<li>Additional commits viewable in <a
href="https://github.com/postcss/postcss/compare/8.4.24...8.4.31">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=postcss&package-manager=npm_and_yarn&previous-version=8.4.24&new-version=8.4.31)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)
You can disable automated security fix PRs for this repo from the
[Security Alerts
page](https://github.com/facebook/react/network/alerts).

</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-05-20 11:47:51 +01:00
Herrington Darkholme
68de7d0535 [compiler:chore] fix SSA pdf reference link (#29162)
## Summary

This PR fixes the deadlink in the SSA comment. Previously the attached
link is down now.

## How did you test this change?

1. I can confirm the PDF in the new link is the same as the old now.
Reference: https://www.recompiled.dev/blog/ssa/
2. I can confirm the old link is down, and it is [not just
me](https://downforeveryoneorjustme.com/pp.info.uni-karlsruhe.de?proto=https)

<img width="580" alt="image"
src="https://github.com/facebook/react/assets/2883231/eeca5eda-6f61-4ac4-a113-1b04370533d9">

---------

Co-authored-by: Jan Kassens <jkassens@meta.com>
2024-05-20 11:10:10 +01:00
Joe Savona
cca15a2139 compiler: fix accidental propagation of function effects from StartMemoize/FinishMemoize
By default, React Compiler will skip compilation if it cannot preserve existing memoization. Ie, if the code has an existing `useMemo()` or `useCallback()` and the compiler cannot determine that it is safe to keep that memoization — or do even better — then we'll leave the code alone. The actual compilation doesn't use any hints from existing memo calls, this is purely to check and avoid regressing any specific memoization that developers may have already applied.

However, we were accidentally reporting some false-positive _validation_ errors due to the StartMemoize and FinishMemoize instructions that we emit to track where the memoization was in the source code. This is now fixed.

Fixes #29131
Fixes #29132

ghstack-source-id: 9f6b8dbc5074ccc96e6073cf11c4920b5375faf6
Pull Request resolved: https://github.com/facebook/react/pull/29154
2024-05-19 19:12:53 -07:00
Joe Savona
85923690e9 compiler: Improve ValidateNoRefAccessInRender to ignore access in effects
Improves ValidateNoRefAccessInRender (still disabled by default) to properly ignore ref access within effects. This includes allowing ref access within functions that are only transitively called from an effect.

While I was here I also added some extra test fixtures for allowing global mutation in effects.

ghstack-source-id: fb6352a1788b7bdbebb40d5b844b711ef87d6771
Pull Request resolved: https://github.com/facebook/react/pull/29151
2024-05-19 19:12:53 -07:00
Januda Bethmin
f74c5ccf94 feat(hyperlink): added a hyperlink to Node in README.md file (#28940)
As a fellow beginner to React, I didn't even know React runs on top of
Node when I started.

So, some beginners might get confused about what is Node and how to find
details about it or how to download it.

So, I thought to add a hyperlink to Node replacing the word Node in the
README.md file. I think this might be a valuable contribution.

- Januda
2024-05-18 23:17:52 -04:00
NickeSteenen
ccb06b0585 Add hyperlink for Good First Issues header (#29103)
## Summary

The "Good First Issues" header in the README was missing a hyperlink
where the other similar headlines had one.

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

## How did you test this change?

N/A

<!--
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.
-->
2024-05-18 23:17:28 -04:00
Risto Keravuori
ff60b11b1c Add packageManager fields for Corepack compat (#29114) 2024-05-18 10:21:41 -04:00
Lauren Tan
597ad74e38 Bump version to 0.0.0-experimental-f978439-20240517 2024-05-17 15:17:05 -07:00
Lauren Tan
630c6fb89b Bump version to 0.0.0-experimental-c8b3f72-20240517 2024-05-17 15:17:05 -07:00
Lauren Tan
c2a64b0713 Bump version to 0.0.0-experimental-592953e-20240517 2024-05-17 15:17:04 -07:00
Lauren Tan
1052a5f2dd [compiler:publish] Don't check branch in debug mode
ghstack-source-id: 465f5a358096c55310ebf5a0beef581646ab553e
Pull Request resolved: https://github.com/facebook/react/pull/29153
2024-05-17 15:11:17 -07:00
Lauren Tan
38d961f8ff [compiler:publish] Bump time to reconsider to 3s
ghstack-source-id: afc8976a8956db79ed824f30cf575d3f5cf93cfe
Pull Request resolved: https://github.com/facebook/react/pull/29150
2024-05-17 15:07:04 -07:00
Lauren Tan
b195a947de [compiler:publish] Prompt for OTP
Makes running the script a little more ergonomic by prompting for OTP
upfront.

ghstack-source-id: e9967bfde1ab01ff9417a848154743ae1926318d
Pull Request resolved: https://github.com/facebook/react/pull/29149
2024-05-17 15:07:04 -07:00
Lauren Tan
4fbc3a37f5 [compiler:publish] Don't hash node_modules
ghstack-source-id: 4ac2ecc8654b1a8c149ab9d00c06cb4c401473da
Pull Request resolved: https://github.com/facebook/react/pull/29147
2024-05-17 15:07:04 -07:00
Lauren Tan
e7673e496c [compiler:publish] Rename publish script
ghstack-source-id: 1cccc91b5d0e69240b2f4f539c60eab0f156e15f
Pull Request resolved: https://github.com/facebook/react/pull/29148
2024-05-17 15:07:04 -07:00
Joe Savona
5a12a0d330 compiler: workaround babel issue with html entity escaping
Babel doesn't seem to properly preserve escaping of HTML entities when emitting JSX text children, so this commit works around the issue by emitting a JsxExpressionContainer for JSX children that contain ">", "<", or "&" characters.

Closes #29100

ghstack-source-id: 2d0622397cc067c6336f3635073e07daef854084
Pull Request resolved: https://github.com/facebook/react/pull/29143
2024-05-17 14:36:28 -07:00
Abishek Ilango
541e3c516d [compiler:playground] Resizable tabs (#29133)
## Summary

Every tab wraps the text around but there is no way to resize it. It was
also hard to use the source map tab. It doesn't occupy the full height
nor is the tab resizable. So I made all the tabs resizable.
> Also,
> * make the source map tab occupy full height
> * make it a teeny tiny bit easier to work with the compiler playground
(especially source map)

## How did you test this change?


https://github.com/facebook/react/assets/91976421/cdec30e8-cadb-4958-8786-31c54ea83bd6

Signed-off-by: abizek <abishekilango@protonmail.com>
2024-05-17 15:31:24 -04:00
mofeiZ
1d6eebfb7f [Compiler][script] Dedupe error report counts before reporting in healthcheck (#29085)
Certain compiler passes currently may collect a few error events before
reporting (see
https://github.com/facebook/react/blob/main/compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Program.ts#L101-L107)
2024-05-17 11:58:15 -07:00
Joe Savona
6400172315 compiler: update comment on memo cache import code
ghstack-source-id: b6c98c78854c9125bef504731515b9854c01960d
Pull Request resolved: https://github.com/facebook/react/pull/29142
2024-05-17 11:37:16 -07:00
Lauren Tan
ecddf3cb07 Add issue template for React Compiler
Adds a GitHub issue template form so we can automatically categorize
issues and get more information upfront. I mostly referenced the
DevTools bug report template and made some tweaks.

ghstack-source-id: 5bfc728a625f367932fc21263e82681079d3ac65
Pull Request resolved: https://github.com/facebook/react/pull/29140
2024-05-17 11:33:53 -07:00
Joe Savona
be6712f72c compiler: Workaround Babel bug with unicode in jsx string attrs
Workaround for a bug in older versions of Babel, where strings with unicode are incorrectly escaped when emitted as JSX attributes, causing double-escaping by later processing.

Closes #29120
Closes #29124

ghstack-source-id: 065440d4fb97e164beb8a8f15f252f372a59c5a0
Pull Request resolved: https://github.com/facebook/react/pull/29141
2024-05-17 10:59:04 -07:00
Sebastian Markbåge
af3a55e67f Lazily freeze in case anything in the currently initializing chunk is blocked (#29139)
Fixed #29129.

---------

Co-authored-by: Hendrik Liebau <mail@hendrik-liebau.de>
2024-05-17 13:58:42 -04:00
Joe Savona
477a3d1ef5 [compiler] Todo for for-await loops
ghstack-source-id: 13f11edfbef2af2e2a9ab876c18b0a4013a3eae0
Pull Request resolved: https://github.com/facebook/react/pull/29118
2024-05-17 10:43:14 -07:00
Lauren Tan
3f1436cca1 [compiler:playground] Fix broken builds
Now that the compiler is public, the `*` version was grabbing the latest
version of the compiler off of npm and was resolving to my very first
push to npm (an empty package containing only a single package.json).
This was breaking the playground as it would attempt to load the
compiler but then crash the babel pipeline due to the node module not
being found.

ghstack-source-id: 695fd9caac
Pull Request resolved: https://github.com/facebook/react/pull/29122
2024-05-16 23:25:57 -07:00
Joseph Savona
5ab54718a5 compiler: merge reactive scopes across const StoreLocal (#29095)
@jbonta nerd-sniped me into making this optimization during conference
prep, posting this as a PR now that keynote is over.

Consider these two cases:

```javascript
export default function MyApp1({ count }) {
  const cb = () => count;
  return <div onclick={cb}>Hello World</div>;
}

export default function MyApp2({ count }) {
  return <div onclick={() => count}>Hello World</div>;
}
```

Previously, the former would create two reactive scopes (one for `cb`,
one for the div) while the latter would only have a single scope for the
`div` and its inline callback. The reason we created separate scopes
before is that there's a `StoreLocal 'cb' = t0` instruction in-between,
and i had conservatively implemented the merging pass to not allow
intervening StoreLocal instructions.

The observation is that intervening StoreLocals are fine _if_ the
assigned variable's last usage is the next scope. We already have a
check that the intervening lvalues are last-used at/before the next
scope, so it's trivial to extend this to support StoreLocal.

Note that we already don't merge scopes if there are intervening
terminals, so we don't have to worry about things like conditional
StoreLocal, conditional access of the resulting value, etc.
2024-05-16 17:29:05 -07:00
Yuta Sakou
7a149aa162 docs: fix typo DESIGN_GOALS.md (#29102)
## Summary
Fixes typo  DESIGN_GOALS.md  in react compiler docs

## How did you test this change?
it's document fix, so no tests needed.
2024-05-16 16:11:22 -07:00
Jason Bonta
91e88f94cc allow compiler playground to scroll horizontally 2024-05-16 13:15:13 -07:00
Jan Amann
94896cb8c5 [React Compiler] Fix rule name for ESLint plugin (#29096)
/cc @poteto

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

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

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

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

## Summary

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

Seems like the README of the package was outdated.

## How did you test this change?

Tried this configuration in a project of mine.

<!--
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.
-->
2024-05-16 12:36:22 -04:00
Kirill Zyusko
e8779a9a9a [React Compiler] use filename instead of context.filename in ESLint plugin (#29104)
<!--
  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

Use `filename` instead of `context.filename` in eslint compiler.

The problem is that in `react-native` + `typescript` project the context
may not have `filename`:

<img width="384" alt="image"
src="https://github.com/facebook/react/assets/22820318/e5d184fa-5ac9-4512-96b9-644baa3d5f25">

And eslint will crash with:

```bash
TypeError: Error while loading rule 'react-compiler/react-compiler': Cannot read properties of undefined (reading 'endsWith')
```

But in fact we already derive `filename` variable earlier so we can
simply reuse the variable (I guess).

## How did you test this change?

- add `eslint` plugin to RN project;
- run eslint
2024-05-16 12:35:52 -04:00
Lauren Tan
149b917c8a Bump version to 0.0.0-experimental-8d5174c-20240515 2024-05-15 17:43:42 -07:00
Lauren Tan
c912057093 Bump version to 0.0.0-experimental-53bb89e-20240515 2024-05-15 17:43:41 -07:00
Lauren Tan
f470ba3218 Bump version to 0.0.0-experimental-c23de8d-20240515 2024-05-15 17:43:40 -07:00
Lauren Tan
7f22c5243e [compiler:publish] Specify https for registry
Uses https for the npm registry so the publishing script isn't rejected.
Fixes:

```
Beginning October 4, 2021, all connections to the npm registry - including for package installation - must use TLS 1.2 or higher. You are currently using plaintext http to connect. Please visit the GitHub blog for more information: https://github.blog/2021-08-23-npm-registry-deprecating-tls-1-0-tls-1-1/
```

ghstack-source-id: b247d044ea48f3007cf8bd13445fb7ece0f5b02f
Pull Request resolved: https://github.com/facebook/react/pull/29087
2024-05-15 17:42:19 -07:00
Steven
5052bfba8b chore(docs): fix typo (plugion => plugin) in DESIGN_GOALS.md (#29086)
<!--
  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

This PR fixes a typo in `./compiler/docs/DESIGN_GOALS.md`.

I believe `plugion` should be `plugin`.

## How did you test this change?

Rendered the markdown to html.
2024-05-15 20:41:05 -04:00
Lauren Tan
50c999eb0e [compiler] Add readme for babel plugin
Adds a simple readme for the babel plugin with links to the docs.

ghstack-source-id: 4dac0b2a4b
Pull Request resolved: https://github.com/facebook/react/pull/29084
2024-05-15 17:29:49 -07:00
Lauren Tan
a0eb2653b8 [compiler] Check if current branch is main
This script needs to run from `main` since it commits version bumps for
packages, and those need to point to publicly available hashes. So,
throw an error if we're not already on main.

ghstack-source-id: ce0168e826
Pull Request resolved: https://github.com/facebook/react/pull/29083
2024-05-15 16:17:23 -07:00
Lauren Tan
5572edc929 [compiler] Various fixes for publishing script
- Specify a registry for npm publish because otherwise it tries to use
  the yarn registry
- `packages` option actually works

This _should_ work now (note last line of output), will test it once we
land this since i want to publish a new version of the eslint plugin
with some important fixes.

```
npm notice
npm notice 📦  eslint-plugin-react-compiler@0.0.0-experimental-53bb89e-20240515
npm notice === Tarball Contents ===
npm notice 827B  README.md
npm notice 2.1MB dist/index.js
npm notice 1.0kB package.json
npm notice === Tarball Details ===
npm notice name:          eslint-plugin-react-compiler
npm notice version:       0.0.0-experimental-53bb89e-20240515
npm notice filename:      eslint-plugin-react-compiler-0.0.0-experimental-53bb89e-20240515.tgz
npm notice package size:  300.9 kB
npm notice unpacked size: 2.1 MB
npm notice shasum:        cb99823f3a483c74f470085cac177bd020f7a85a
npm notice integrity:     sha512-L3HV9qja1dnCl[...]IaRSZJ3P/v6yQ==
npm notice total files:   3
npm notice
npm notice Publishing to http://registry.npmjs.org/ with tag latest and default access (dry-run)
```

ghstack-source-id: 63067ef772
Pull Request resolved: https://github.com/facebook/react/pull/29082
2024-05-15 16:17:23 -07:00
Lauren Tan
cf7d895db6 [compiler:eslint] Fix false positive with TS type param syntax
Previously we would attempt to parse code in the eslint plugin with the
HermesParser first as it can handle some TS syntax. However, this was
leading to a mis-parse of React hook calls with type params (eg,
`useRef<null>()` as a BinaryExpression rather than a CallExpression with
a type param. This triggered our validation that Hooks should not be
used as normal values.

To fix this, we now try to parse with the babel parser (with TS support)
for filenames that end with ts/tsx, and fallback to HermesParser for
regular JS files.

ghstack-source-id: 5b7231031c
Pull Request resolved: https://github.com/facebook/react/pull/29081
2024-05-15 15:44:21 -07:00
Joseph Savona
3adca7a477 compiler: fix jsx text attributes with double quotes (#29079)
Fixes #29069 by detecting the presence of double-quotes in JSX attribute
strings and falling back to using an expression container.
2024-05-15 14:40:33 -07:00
Sathya Gunasekaran
5e11e7fc20 [heathcheck] Check for namespaced StrictMode (#29076)
Previously, we only checked for StrictMode by searching for
`<StrictMode>` but we should also check for the namespaced version,
`<React.StrictMode>`.

Fixes https://github.com/facebook/react/issues/29075
2024-05-15 14:15:32 -07:00
Joseph Savona
c93c30f9d4 Fix ESLint and Prettier configs for React Compiler (#29073)
Fixes the top-level ESLint and Prettier configs to ignore the compiler.
For now the compiler has its own prettier and linting setup with
different versions/configs.
2024-05-15 14:02:57 -07:00
Christoph Nakazawa
cfeb491ee7 Add a main field to eslint-plugin-react-compiler, fixes #29068. (#29072)
## Summary

The main field is missing, this fixes it.

Fixes #29068.

## How did you test this change?

Manually patched the package and tried it in my codebase.
2024-05-15 17:02:20 -04:00
Joseph Savona
71565a932c Merge pull request #29061 from facebook/compiler
Open-source React Compiler
2024-05-15 11:16:19 -07:00
Joe Savona
575477a2e8 Publish React Compiler to open source 2024-05-15 10:58:51 -07:00
Lauren Tan
740b7c1b0a Bump version to 0.0.0-experimental-410375f-20240515 2024-05-15 08:05:02 -07:00
Lauren Tan
5501ebceec Bump version to 0.0.0-experimental-e04a001-20240515 2024-05-15 08:05:02 -07:00
Lauren Tan
d794e4a86e Bump version to 0.0.0-experimental-4690415-20240515 2024-05-15 08:05:01 -07:00
Lauren Tan
41142f306e Unthrow publish script 2024-05-15 08:03:50 -07:00
Andrew Clark
915b914b3a Bump React 19 beta to RC (#29060)
This updates the Canary label from "beta" to "rc".

We will publish an actual RC (e.g. 19.0.0-rc.0) too; this only changes
the label in the canary releases.
2024-05-15 11:01:28 -04:00
Lauren Tan
ecccaf6e01 Fix CI for compiler paths
ghstack-source-id: 43bb0c8c957fc550203445868c90fa706e3a8d11
Pull Request resolved: https://github.com/facebook/react-forget/pull/2968
2024-05-14 11:02:47 -04:00
Lauren Tan
6457343cd3 Don't emit types for babel-plugin-react-compiler
ghstack-source-id: a1776f97d5f7d4d8e02886906eb001e358628fc8
Pull Request resolved: https://github.com/facebook/react-forget/pull/2967
2024-05-14 11:02:30 -04:00
Lauren Tan
6948639df6 [publish] Add script to publish packages
Adds a script to publish babel-plugin-react-compiler,
eslint-plugin-react-compiler, and react-compiler-healthcheck to npm.

Instructions are in a comment in scripts/publish.js, please read
carefully before using this script!

Test plan:

```
$ yarn npm:publish

yarn run v1.22.10
$ node scripts/publish
ℹ Preparing to publish (dry run) [debug=false]
ℹ Building packages
✔ Successfully built babel-plugin-react-compiler
✔ Successfully built eslint-plugin-react-compiler
✔ Successfully built react-compiler-healthcheck
ℹ Dry run: Report tarball contents

========== babel-plugin-react-compiler ==========

⠴ Running npm pack --dry-run
npm WARN config init.author.name Use `--init-author-name` instead.
npm WARN config init.author.email Use `--init-author-email` instead.
⠦ Running npm pack --dry-run
npm notice
npm notice 📦  babel-plugin-react-compiler@0.0.1
npm notice === Tarball Contents ===
npm notice 11B    dist/__tests__/DisjointSet-test.d.ts
npm notice 11B    dist/__tests__/envConfig-test.d.ts
npm notice 11B    dist/__tests__/Logger-test.d.ts
npm notice 11B    dist/__tests__/parseConfigPragma-test.d.ts
npm notice 11B    dist/__tests__/Result-test.d.ts
npm notice 145B   dist/__tests__/test-utils/validateNoUseBeforeDefine.d.ts
npm notice 144B   dist/Babel/BabelPlugin.d.ts
npm notice 350B   dist/Babel/RunReactCompilerBabelPlugin.d.ts
npm notice 2.4kB  dist/CompilerError.d.ts
npm notice 455B   dist/Entrypoint/Gating.d.ts
npm notice 376B   dist/Entrypoint/Imports.d.ts
npm notice 166B   dist/Entrypoint/index.d.ts
npm notice 1.8kB  dist/Entrypoint/Options.d.ts
npm notice 1.3kB  dist/Entrypoint/Pipeline.d.ts
npm notice 819B   dist/Entrypoint/Program.d.ts
npm notice 295B   dist/Entrypoint/Reanimated.d.ts
npm notice 753B   dist/Entrypoint/Suppression.d.ts
npm notice 113B   dist/HIR/AssertConsistentIdentifiers.d.ts
npm notice 115B   dist/HIR/AssertTerminalSuccessorsExist.d.ts
npm notice 529B   dist/HIR/AssertValidBlockNesting.d.ts
npm notice 110B   dist/HIR/AssertValidMutableRanges.d.ts
npm notice 585B   dist/HIR/BuildHIR.d.ts
npm notice 116B   dist/HIR/BuildReactiveScopeTerminalsHIR.d.ts
npm notice 125B   dist/HIR/ComputeUnconditionalBlocks.d.ts
npm notice 602B   dist/HIR/Dominator.d.ts
npm notice 12.7kB dist/HIR/Environment.d.ts
npm notice 184B   dist/HIR/FindContextIdentifiers.d.ts
npm notice 401B   dist/HIR/Globals.d.ts
npm notice 22.2kB dist/HIR/HIR.d.ts
npm notice 2.8kB  dist/HIR/HIRBuilder.d.ts
npm notice 1.1kB  dist/HIR/index.d.ts
npm notice 108B   dist/HIR/MergeConsecutiveBlocks.d.ts
npm notice 115B   dist/HIR/MergeOverlappingReactiveScopesHIR.d.ts
npm notice 2.2kB  dist/HIR/ObjectShape.d.ts
npm notice 1.4kB  dist/HIR/PrintHIR.d.ts
npm notice 106B   dist/HIR/PruneUnusedLabelsHIR.d.ts
npm notice 1.1kB  dist/HIR/Types.d.ts
npm notice 1.9kB  dist/HIR/visitors.d.ts
npm notice 776B   dist/index.d.ts
npm notice 5.4MB  dist/index.js
npm notice 429B   dist/Inference/AnalyseFunctions.d.ts
npm notice 324B   dist/Inference/DropManualMemoization.d.ts
npm notice 436B   dist/Inference/index.d.ts
npm notice 224B   dist/Inference/InferAlias.d.ts
npm notice 204B   dist/Inference/InferAliasForPhis.d.ts
npm notice 206B   dist/Inference/InferAliasForStores.d.ts
npm notice 115B   dist/Inference/InferMutableContextVariables.d.ts
npm notice 151B   dist/Inference/InferMutableLifetimes.d.ts
npm notice 109B   dist/Inference/InferMutableRanges.d.ts
npm notice 212B   dist/Inference/InferMutableRangesForAlias.d.ts
npm notice 106B   dist/Inference/InferReactivePlaces.d.ts
npm notice 368B   dist/Inference/InferReferenceEffects.d.ts
npm notice 201B   dist/Inference/InferTryCatchAliases.d.ts
npm notice 130B   dist/Inference/InlineImmediatelyInvokedFunctionExpressions.d.ts
npm notice 106B   dist/Optimization/ConstantPropagation.d.ts
npm notice 258B   dist/Optimization/DeadCodeElimination.d.ts
npm notice 177B   dist/Optimization/index.d.ts
npm notice 103B   dist/Optimization/PruneMaybeThrows.d.ts
npm notice 108B   dist/ReactiveScopes/AlignMethodCallScopes.d.ts
npm notice 110B   dist/ReactiveScopes/AlignObjectMethodScopes.d.ts
npm notice 133B   dist/ReactiveScopes/AlignReactiveScopesToBlockScopes.d.ts
npm notice 126B   dist/ReactiveScopes/AlignReactiveScopesToBlockScopesHIR.d.ts
npm notice 132B   dist/ReactiveScopes/AssertScopeInstructionsWithinScope.d.ts
npm notice 125B   dist/ReactiveScopes/AssertWellFormedBreakTargets.d.ts
npm notice 363B   dist/ReactiveScopes/BuildReactiveBlocks.d.ts
npm notice 142B   dist/ReactiveScopes/BuildReactiveFunction.d.ts
npm notice 759B   dist/ReactiveScopes/CodegenReactiveFunction.d.ts
npm notice 154B   dist/ReactiveScopes/CollectReactiveIdentifiers.d.ts
npm notice 128B   dist/ReactiveScopes/CollectReferencedGlobals.d.ts
npm notice 698B   dist/ReactiveScopes/DeriveMinimalDependencies.d.ts
npm notice 138B   dist/ReactiveScopes/ExtractScopeDeclarationsFromDestructuring.d.ts
npm notice 121B   dist/ReactiveScopes/FlattenReactiveLoops.d.ts
npm notice 124B   dist/ReactiveScopes/FlattenScopesWithHooksOrUse.d.ts
npm notice 2.1kB  dist/ReactiveScopes/index.d.ts
npm notice 370B   dist/ReactiveScopes/InferReactiveScopeVariables.d.ts
npm notice 217B   dist/ReactiveScopes/MemoizeFbtOperandsInSameScope.d.ts
npm notice 127B   dist/ReactiveScopes/MergeOverlappingReactiveScopes.d.ts
npm notice 138B   dist/ReactiveScopes/MergeReactiveScopesThatInvalidateTogether.d.ts
npm notice 1.0kB  dist/ReactiveScopes/PrintReactiveFunction.d.ts
npm notice 123B   dist/ReactiveScopes/PromoteUsedTemporaries.d.ts
npm notice 118B   dist/ReactiveScopes/PropagateEarlyReturns.d.ts
npm notice 127B   dist/ReactiveScopes/PropagateScopeDependencies.d.ts
npm notice 123B   dist/ReactiveScopes/PruneAllReactiveScopes.d.ts
npm notice 126B   dist/ReactiveScopes/PruneAlwaysInvalidatingScopes.d.ts
npm notice 117B   dist/ReactiveScopes/PruneHoistedContexts.d.ts
npm notice 227B   dist/ReactiveScopes/PruneNonEscapingScopes.d.ts
npm notice 125B   dist/ReactiveScopes/PruneNonReactiveDependencies.d.ts
npm notice 122B   dist/ReactiveScopes/PruneTemporaryLValues.d.ts
npm notice 118B   dist/ReactiveScopes/PruneUnusedLabels.d.ts
npm notice 118B   dist/ReactiveScopes/PruneUnusedScopes.d.ts
npm notice 123B   dist/ReactiveScopes/RenameVariables.d.ts
npm notice 114B   dist/ReactiveScopes/StabilizeBlockIds.d.ts
npm notice 3.1kB  dist/ReactiveScopes/visitors.d.ts
npm notice 170B   dist/SSA/EliminateRedundantPhi.d.ts
npm notice 101B   dist/SSA/EnterSSA.d.ts
npm notice 154B   dist/SSA/index.d.ts
npm notice 99B    dist/SSA/LeaveSSA.d.ts
npm notice 63.5kB dist/tsconfig.tsbuildinfo
npm notice 43B    dist/TypeInference/index.d.ts
npm notice 103B   dist/TypeInference/InferTypes.d.ts
npm notice 352B   dist/Utils/ComponentDeclaration.d.ts
npm notice 256B   dist/Utils/DisjointSet.d.ts
npm notice 322B   dist/Utils/HookDeclaration.d.ts
npm notice 613B   dist/Utils/logger.d.ts
npm notice 2.3kB  dist/Utils/Result.d.ts
npm notice 119B   dist/Utils/RuntimeDiagnosticConstants.d.ts
npm notice 1.1kB  dist/Utils/Stack.d.ts
npm notice 149B   dist/Utils/todo.d.ts
npm notice 782B   dist/Utils/utils.d.ts
npm notice 603B   dist/Validation/index.d.ts
npm notice 117B   dist/Validation/ValidateContextVariableLValues.d.ts
npm notice 109B   dist/Validation/ValidateHooksUsage.d.ts
npm notice 214B   dist/Validation/ValidateMemoizedEffectDependencies.d.ts
npm notice 113B   dist/Validation/ValidateNoCapitalizedCalls.d.ts
npm notice 114B   dist/Validation/ValidateNoRefAccesInRender.d.ts
npm notice 113B   dist/Validation/ValidateNoSetStateInRender.d.ts
npm notice 131B   dist/Validation/ValidatePreservedManualMemoization.d.ts
npm notice 102B   dist/Validation/ValidateUseMemo.d.ts
npm notice 2.3kB  package.json
npm notice === Tarball Details ===
npm notice name:          babel-plugin-react-compiler
npm notice version:       0.0.1
npm notice filename:      babel-plugin-react-compiler-0.0.1.tgz
npm notice package size:  1.1 MB
npm notice unpacked size: 5.5 MB
npm notice shasum:        9a0fb71bdc904d6ab92432a506b0e037f10dd7ce
npm notice integrity:     sha512-hXtObyIEP4MbO[...]jstRbpztyLf4g==
npm notice total files:   119
npm notice

========== eslint-plugin-react-compiler ==========

⠴ Running npm pack --dry-run
npm WARN config init.author.name Use `--init-author-name` instead.
npm WARN config init.author.email Use `--init-author-email` instead.
⠋ Running npm pack --dry-run
npm notice
npm notice 📦  eslint-plugin-react-compiler@0.0.0
npm notice === Tarball Contents ===
npm notice 827B  README.md
npm notice 2.1MB dist/index.js
npm notice 968B  package.json
npm notice === Tarball Details ===
npm notice name:          eslint-plugin-react-compiler
npm notice version:       0.0.0
npm notice filename:      eslint-plugin-react-compiler-0.0.0.tgz
npm notice package size:  300.5 kB
npm notice unpacked size: 2.1 MB
npm notice shasum:        f24dab544b03d36d9bb676a16256f114bd5e0ed6
npm notice integrity:     sha512-8PcKZXZ+RVBDP[...]D7jFmkvHJoBeA==
npm notice total files:   3
npm notice

========== react-compiler-healthcheck ==========

⠼ Running npm pack --dry-run
npm WARN config init.author.name Use `--init-author-name` instead.
npm WARN config init.author.email Use `--init-author-email` instead.
⠏ Running npm pack --dry-run
npm notice
npm notice 📦  react-compiler-healthcheck@0.0.0
npm notice === Tarball Contents ===
npm notice 2.1MB dist/index.js
npm notice 677B  package.json
npm notice 1.8kB rollup.config.js
npm notice 1.1kB src/checks/libraryCompat.ts
npm notice 3.2kB src/checks/reactCompiler.ts
npm notice 759B  src/checks/strictMode.ts
npm notice 67B   src/config.ts
npm notice 1.5kB src/index.ts
npm notice 602B  tsconfig.json
npm notice === Tarball Details ===
npm notice name:          react-compiler-healthcheck
npm notice version:       0.0.0
npm notice filename:      react-compiler-healthcheck-0.0.0.tgz
npm notice package size:  290.4 kB
npm notice unpacked size: 2.1 MB
npm notice shasum:        55c0eb57aebc7305270a29e78ebf6c056044bae0
npm notice integrity:     sha512-nPVhGyh8i9PoO[...]v52c3U0tKGpzA==
npm notice total files:   9
npm notice
✔ Please confirm contents of packages before publishing. You can run this command again with --for-real to publish to npm
  Done in 61.19s.
```

```
$ yarn npm:publish --debug --for-real

yarn run v1.22.10
$ node scripts/publish --debug --for-real
ℹ Preparing to publish (for real) [debug=true]
ℹ Building packages
✔ Successfully built babel-plugin-react-compiler
✔ Successfully built eslint-plugin-react-compiler
✔ Successfully built react-compiler-healthcheck
✔ Bumped babel-plugin-react-compiler to 0.0.0-experimental-2769f7a-20240513
✔ Bumped eslint-plugin-react-compiler to 0.0.0-experimental-e04a001-20240513
✔ Bumped react-compiler-healthcheck to 0.0.0-experimental-410375f-20240513

========== babel-plugin-react-compiler ==========

⠋ Publishing babel-plugin-react-compiler to npm
Command that would have run: npm publish --dry-run
/Users/lauren/code/react-forget/compiler/scripts/publish.js:188
      throw new Error(
            ^

Error: This error is intentional, please double check scripts/publish.js and remove this error prior to publishing
    at main (/Users/lauren/code/react-forget/compiler/scripts/publish.js:188:13)

Node.js v20.11.0
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
```

On the day of launch, remove the hardcoded error, then run `yarn
npm:publish --debug --for-real` first as a sanity check. Confirm the
contents are correct.

Then when you are certain, run `yarn npm:publish --for-real`, and push
the commited version bumps to GitHub so the hashes that the packages
originate from are public.

ghstack-source-id: 403bc22d4b340056fd112fcfc38580f28ed6c986
Pull Request resolved: https://github.com/facebook/react-forget/pull/2966
2024-05-14 11:02:29 -04:00
Lauren Tan
67ea821e5f [publish] Fix files field for packages, invalid version range
The [`files` field](https://docs.npmjs.com/cli/v10/commands/npm-publish#files-included-in-package)
controls what files get included in the published package.

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

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

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

ghstack-source-id: 12b36c203fc9fd8d72a1995fb3fba2312de4aa51
Pull Request resolved: https://github.com/facebook/react-forget/pull/2965
2024-05-14 11:02:29 -04:00
Lauren Tan
5a842dbfb1 Fix healthcheck package.json bin field
ghstack-source-id: 28045c6edb342dea125ea8fcea564ce90626f21d
Pull Request resolved: https://github.com/facebook/react-forget/pull/2964
2024-05-14 11:02:29 -04:00
Jan Kassens
26f2496093 Remove 2 no longer existing files from inlinedHostConfig (#29027)
Remove 2 no longer existing files from inlinedHostConfig

While looking for `.classic` forks, I noticed these files no longer
exist.
2024-05-14 10:07:00 -04:00
Timothy Yung
5f28f51759 Enable enableUnifiedSyncLane for React Native (Meta) (#29052)
## Summary

Enables the `enableUnifiedSyncLane` feature flag for React Native
(Meta).

## How did you test this change?

```
$ yarn test
$ yarn flow fabric
```
2024-05-13 22:56:42 -07:00
Joe Savona
b956024f3d Fix Jest tests
ghstack-source-id: e2507b7285bb52ee02d2cece35aa16eb0bc0baa5
Pull Request resolved: https://github.com/facebook/react-forget/pull/2963
2024-05-13 14:10:16 -07:00
Lauren Tan
ce0c08eaad [healthcheck] Clean up ignorelist and check if deps exist
ghstack-source-id: b6d58988eeb86e657a6db2a481b6c2fe2fba0344
Pull Request resolved: https://github.com/facebook/react-forget/pull/2962
2024-05-13 17:08:31 -04:00
Jan Kassens
4cf7ee23fb CI: remove non-functional Rust compiler benchmark workflow (#2948)
`forget_napi` doesn't exist and given we're not currently working on the Rust compiler, I'm not sure we need to keep this around until we know that we do want to invest into this area again.
2024-05-13 17:04:18 -04:00
Joe Savona
7e3be125e8 Use unique name for c import local identifier
ghstack-source-id: 93055b972f
Pull Request resolved: https://github.com/facebook/react-forget/pull/2961
2024-05-13 12:59:19 -07:00
Lauren Tan
669e8d02b1 [healthcheck] Refine glob pattern
ghstack-source-id: 6f9e7f9534
Pull Request resolved: https://github.com/facebook/react-forget/pull/2960
2024-05-11 00:56:48 -04:00
Lauren Tan
9ef7557730 [healthcheck] Don't compile mjs
ghstack-source-id: 087985cd23
Pull Request resolved: https://github.com/facebook/react-forget/pull/2959
2024-05-11 00:56:48 -04:00
Lauren Tan
78da5becaf [healthcheck] Remove console.error
ghstack-source-id: c06d44960c
Pull Request resolved: https://github.com/facebook/react-forget/pull/2958
2024-05-11 00:56:48 -04:00
Lauren Tan
76b7331b0d [healthcheck] Only glob files with certain extensions by default
ghstack-source-id: b8db172669
Pull Request resolved: https://github.com/facebook/react-forget/pull/2957
2024-05-11 00:56:48 -04:00
Lauren Tan
63e5330260 [healthcheck] Rename to react-compiler-healthcheck
Don't really have time to implement the react-compiler/healthcheck
version of this script, so for now i propose we just publish this as
react-compiler-healthcheck

the command for running this would be

```
$ npx react-compiler-healthcheck --src 'whatever/**/*.*'
```

ghstack-source-id: e2c443a912
Pull Request resolved: https://github.com/facebook/react-forget/pull/2956
2024-05-11 00:56:48 -04:00
Lauren Tan
9a6ce3379d [healthcheck] Fix build
runReactBabelPluginReactCompiler brings in fbt which is unnecessary for
OSS so I removed it.

Also makes it so healthckeck is installed as an executable

ghstack-source-id: ec6c76f8be
Pull Request resolved: https://github.com/facebook/react-forget/pull/2955
2024-05-11 00:56:48 -04:00
Lauren Tan
db34843c42 [healthcheck] Build with rollup
ghstack-source-id: cd40da2ddc
Pull Request resolved: https://github.com/facebook/react-forget/pull/2954
2024-05-11 00:56:48 -04:00
Lauren Tan
9b0044e213 Better detection for reanimated
We found this issue through enabling the compiler on the React Conf app.

`babel-preset-expo` automatically adds the `react-native-animated`
plugin to apps that use the preset. This means that Expo apps sometimes
omit the react-native-animated plugin from their config, which was
failing our existing check. This PR copies the same detection that Expo
does for adding reanimated as a fallback

ghstack-source-id: 46f7aec0bc
Pull Request resolved: https://github.com/facebook/react-forget/pull/2953
2024-05-11 00:56:48 -04:00
Lauren Tan
c58142ba35 ReAnimated -> Reanimated
Fixes a small typo by request

ghstack-source-id: 00889150a9
Pull Request resolved: https://github.com/facebook/react-forget/pull/2952
2024-05-11 00:56:48 -04:00
Sebastian Markbåge
9d76c954cf [Flight] Error if a legacy React Element is attempted to be rendered (#29043)
This errors on the client normally but in the case the `type` is a
function - i.e. a Server Component - it wouldn't be transferred to error
on the client so you end up with a worse error message. So this just
implements the same check as ChildFiber.
2024-05-10 09:37:42 -04:00
Dmytro Rykun
2c022b847e Clean up the enableEarlyReturnForPropDiffing experiment (#29041)
## Summary

The experiment has shown no significant performance changes. This PR
removes it.

## How did you test this change?
```
yarn flow native
yarn lint
```
2024-05-10 11:00:03 +01:00
Sebastian Markbåge
6ef0dd4f2c [Flight] Enable Binary and ReadableStreams in Stable (#29035)
These are ready to ship in stable.
2024-05-09 20:56:15 -04:00
Sebastian Markbåge
6c409acefd [Flight Reply] Encode Objects Returned to the Client by Reference (#29010)
Stacked on #28997.

We can use the technique of referencing an object by its row + property
name path for temporary references - like we do for deduping. That way
we don't need to generate an ID for temporary references. Instead, they
can just be an opaque marker in the slot and it has the implicit ID of
the row + path.

Then we can stash all objects, even the ones that are actually available
to read on the server, as temporary references. Without adding anything
to the payload since the IDs are implicit. If the same object is
returned to the client, it can be referenced by reference instead of
serializing it back to the client. This also helps preserve object
identity.

We assume that the objects are immutable when they pass the boundary.

I'm not sure if this is worth it but with this mechanism, if you return
the `FormData` payload from a `useActionState` it doesn't have to be
serialized on the way back to the client. This is a common pattern for
having access to the last submission as "default value" to the form
fields. However you can still control it by replacing it with another
object if you want. In MPA mode, the temporary references are not
configured and so it needs to be serialized in that case. That's
required anyway for hydration purposes.

I'm not sure if people will actually use this in practice though or if
FormData will always be destructured into some other object like with a
library that turns it into typed data, and back. If so, the object
identity is lost.
2024-05-09 20:00:56 -04:00
Sebastian Markbåge
38d9f156b8 [Flight Reply] Dedupe Objects and Support Cyclic References (#28997)
Uses the same technique as in #28996 to encode references to already
emitted objects. This now means that Reply can support cyclic objects
too for parity.
2024-05-09 19:24:37 -04:00
Sebastian Markbåge
7a78d03028 [Flight] Encode references to existing objects by property path (#28996)
Instead of forcing an object to be outlined to be able to refer to it
later we can refer to it by the property path inside another parent
object.

E.g. this encodes such a reference as `'$123:props:children:foo:bar'`.

That way we don't have to preemptively outline object and we can dedupe
after the first time we've found it.

There's no cost on the client if it's not used because we're not storing
any additional information preemptively.

This works mainly because we only have simple JSON objects from the root
reference. Complex objects like Map, FormData etc. are stored as their
entries array in the look up and not the complex object. Other complex
objects like TypedArrays or imports don't have deeply nested objects in
them that can be referenced.

This solves the problem that we only dedupe after the third instance.
This dedupes at the second instance. It also solves the problem where
all nested objects inside deduped instances also are outlined.

The property paths can get pretty large. This is why a test on payload
size increased. We could potentially outline the reference itself at the
first dupe. That way we get a shorter ID to refer to in the third
instance.
2024-05-09 19:16:14 -04:00
Joe Savona
6b23c25ff9 Support HMR
Adds supports for hot module reloading (HMR) by resetting the cache if a hash of the source file changes. This is enabled via a compiler flag, but also enabled automatically via the babel plugin when NODE_ENV=development.

ghstack-source-id: 5cd1ad5c89
Pull Request resolved: https://github.com/facebook/react-forget/pull/2951
2024-05-09 13:59:31 -07:00
Andrew Clark
c3345638cb Support useFormStatus in progressively-enhanced forms (#29019)
Before this change, `useFormStatus` is only activated if a form is
submitted by an action function (either `<form action={actionFn}>` or
`<button formAction={actionFn}>`).

After this change, `useFormStatus` will also be activated if you call
`startTransition(actionFn)` inside a submit event handler that is
`preventDefault`-ed.

This is the last missing piece for implementing a custom `action` prop
that is progressively enhanced using `onSubmit` while maintaining the
same behavior as built-in form actions.

Here's the basic recipe for implementing a progressively-enhanced form
action. This would typically be implemented in your UI component
library, not regular application code:

```js
import {requestFormReset} from 'react-dom';

// To implement progressive enhancement, pass both a form action *and* a
// submit event handler. The action is used for submissions that happen
// before hydration, and the submit handler is used for submissions that
// happen after.
<form
  action={action}
  onSubmit={(event) => {
    // After hydration, we upgrade the form with additional client-
    // only behavior.
    event.preventDefault();

    // Manually dispatch the action.
    startTransition(async () => {
      // (Optional) Reset any uncontrolled inputs once the action is
      // complete, like built-in form actions do.
      requestFormReset(event.target);

      // ...Do extra action-y stuff in here, like setting a custom
      // optimistic state...

      // Call the user-provided action
      const formData = new FormData(event.target);
      await action(formData);
    });
  }}
/>
```
2024-05-09 13:16:08 -04:00
Sebastian Markbåge
151cce3740 Track Stack of JSX Calls (#29032)
This is the first step to experimenting with a new type of stack traces
behind the `enableOwnerStacks` flag - in DEV only.

The idea is to generate stacks that are more like if the JSX was a
direct call even though it's actually a lazy call. Not only can you see
which exact JSX call line number generated the erroring component but if
that's inside an abstraction function, which function called that
function and if it's a component, which component generated that
component. For this to make sense it really need to be the "owner" stack
rather than the parent stack like we do for other component stacks. On
one hand it has more precise information but on the other hand it also
loses context. For most types of problems the owner stack is the most
useful though since it tells you which component rendered this
component.

The problem with the platform in its current state is that there's two
ways to deal with stacks:

1) `new Error().stack` 
2) `console.createTask()`

The nice thing about `new Error().stack` is that we can extract the
frames and piece them together in whatever way we want. That is great
for constructing custom UIs like error dialogs. Unfortunately, we can't
take custom stacks and set them in the native UIs like Chrome DevTools.

The nice thing about `console.createTask()` is that the resulting stacks
are natively integrated into the Chrome DevTools in the console and the
breakpoint debugger. They also automatically follow source mapping and
ignoreLists. The downside is that there's no way to extract the async
stack outside the native UI itself so this information cannot be used
for custom UIs like errors dialogs. It also means we can't collect this
on the server and then pass it to the client for server components.

The solution here is that we use both techniques and collect both an
`Error` object and a `Task` object for every JSX call.

The main concern about this approach is the performance so that's the
main thing to test. It's certainly too slow for production but it might
also be too slow even for DEV.

This first PR doesn't actually use the stacks yet. It just collects them
as the first step. The next step is to start utilizing this information
in error printing etc.

For RSC we pass the stack along across over the wire. This can be
concatenated on the client following the owner path to create an owner
stack leading back into the server. We'll later use this information to
restore fake frames on the client for native integration. Since this
information quickly gets pretty heavy if we include all frames, we strip
out the top frame. We also strip out everything below the functions that
call into user space in the Flight runtime. To do this we need to figure
out the frames that represents calling out into user space. The
resulting stack is typically just the one frame inside the owner
component's JSX callsite. I also eagerly strip out things we expect to
be ignoreList:ed anyway - such as `node_modules` and Node.js internals.
2024-05-09 12:23:05 -04:00
Jon Jensen
04b058868c Upgrade jest and jsdom (#29026)
## Summary

This brings:
 - jest* up from 29.4.2 -> 29.7.0
 - jsdom up from 20.0.0 -> 22.1.0

While the latest version of jest-dom-environment still wants
`jsdom@^20.0.0`, it can safely use at least up to `jsdom@22.1.0`. See
https://github.com/jestjs/jest/pull/13825#issuecomment-1564015010 for
details.

Upgrading to latest versions lets us improve some WheelEvent tests and
will make it possible to test a much simpler FormData construction
approach (see #29018)

## How did you test this change?

Ran `yarn test` and `yarn test --prod` successfully
2024-05-08 13:57:25 -04:00
Jan Kassens
b1d4096396 Facebook: merge react index.classic.fb and index.modern.fb (#29025)
Facebook: merge react index.classic.fb and index.modern.fb

These export the same.

NOTE: The 2 builds are still different based on flags and other forked
files.
2024-05-08 13:37:47 -04:00
Jan Kassens
6946ebe620 Cleanup enableServerComponentKeys flag (#28743)
Cleanup enableServerComponentKeys flag

Flag is `true` everywhere but RN where it doesn't apply.
2024-05-08 10:52:49 -04:00
Ruslan Lesiutin
1717ab0171 React DevTools 5.1.0 -> 5.2.0 (#29022)
Full list of changes (not a public changelog):
* fix[react-devtools/ci]: fix configurations for e2e testing
([hoxyq](https://github.com/hoxyq) in
[#29016](https://github.com/facebook/react/pull/29016))
* feat[react-devtools]: display forget badge for components in profiling
session ([hoxyq](https://github.com/hoxyq) in
[#29014](https://github.com/facebook/react/pull/29014))
* fix[react-devtools]: add backwards compat with legacy element type
symbol ([hoxyq](https://github.com/hoxyq) in
[#28982](https://github.com/facebook/react/pull/28982))
* Expose "view source" options to Fusebox integration
([motiz88](https://github.com/motiz88) in
[#28973](https://github.com/facebook/react/pull/28973))
* Enable inspected element context menu in Fusebox
([motiz88](https://github.com/motiz88) in
[#28972](https://github.com/facebook/react/pull/28972))
* Check in `frontend.d.ts` for react-devtools-fusebox, include in build
output ([motiz88](https://github.com/motiz88) in
[#28970](https://github.com/facebook/react/pull/28970))
* Devtools: Fix build-for-devtools
([eps1lon](https://github.com/eps1lon) in
[#28976](https://github.com/facebook/react/pull/28976))
* Move useMemoCache hook to react/compiler-runtime
([kassens](https://github.com/kassens) in
[#28954](https://github.com/facebook/react/pull/28954))
* warn -> error for Test Renderer deprecation
([acdlite](https://github.com/acdlite) in
[#28904](https://github.com/facebook/react/pull/28904))
* [react-dom] move all client code to `react-dom/client`
([gnoff](https://github.com/gnoff) in
[#28271](https://github.com/facebook/react/pull/28271))
* Rename the react.element symbol to react.transitional.element
([sebmarkbage](https://github.com/sebmarkbage) in
[#28813](https://github.com/facebook/react/pull/28813))
* Rename Forget badge ([jbonta](https://github.com/jbonta) in
[#28858](https://github.com/facebook/react/pull/28858))
* Devtools: Add support for useFormStatus
([eps1lon](https://github.com/eps1lon) in
[#28413](https://github.com/facebook/react/pull/28413))
2024-05-08 13:26:14 +01:00
Ruslan Lesiutin
0e6ea6991e fix[react-devtools/InspectedElementView.css]: dont draw bottom border for empty badge list (#29023)
Forward fix to https://github.com/facebook/react/pull/29014, the bug was
discovered while testing v5.2.0.
2024-05-08 13:16:27 +01:00
Dmytro Rykun
b37e4b4e61 Clean up fastAddProperties and make it more correct (#29015)
## Summary

This PR makes some fixes to the `fastAddProperties` function:
- Use `if (!attributeConfig)` instead of `if (attributeConfig ===
undefined)` to account for `null`.
- If a prop has an Object `attributeConfig` with a `diff` function
defined on it, treat it as an atomic value to keep the semantics of
`diffProperties`.

## How did you test this change?

Build and run RNTester app.
2024-05-08 13:10:04 +01:00
Ruslan Lesiutin
e150a32425 fix[react-devtools/ci]: fix configurations for e2e testing (#29016)
This should fix failing DevTools e2e tests on `main`.

With these changes, running tests locally successfully passes all cases.
2024-05-08 12:04:51 +01:00
Sebastian Markbåge
ec15267a00 [Flight Reply] Resolve outlined models async in Reply just like in Flight Client (#28988)
This is the same change as #28780 but for the Flight Reply receiver.

While it's not possible to create an "async module" reference in this
case - resolving a server reference can still be async if loading it
requires loading chunks like in a new server instance.

Since extracting a typed array from a Blob is async, that's also a case
where a dependency can be async.
2024-05-07 22:19:59 -04:00
Sebastian Markbåge
6bac4f2f31 [Fizz] Fallback to client replaying actions if we're trying to serialize a Blob (#28987)
This follows the same principle as in #28611.

We cannot serialize Blobs of a form data into HTML because you can't
initialize a file input to some value. However the serialization of
state in an Action can contain blobs. In this case we do error but
outside the try/catch that recovers to error to client replaying instead
of MPA mode. This errors earlier to ensure that this works.

Testing this is a bit annoying because JSDOM doesn't have any of the
Blob methods but the Blob needs to be compatible with FormData and the
FormData needs to be compatible with `<form>` nodes in these tests. So I
polyfilled those in JSDOM with some hacks.

A possible future enhancement would be to encode these blobs in a base64
mode instead and have some way to receive them on the server. It's just
a matter of layering this. I think the RSC layer's `FORM_DATA`
implementation can pass some flag to encode as base64 and then have
decodeAction include some way to parse them. That way this case would
work in MPA mode too.
2024-05-07 21:53:10 -04:00
Sebastian Markbåge
826bf4e51e [Flight Reply] Encode binary streams as a single collapsed Blob (#28986)
Based on #28893.

For other streams we encode each chunk as a separate form field which is
a bit bloated. Especially for binary chunks since they also have an
indirection. We need some way to encode the chunks as separate anyway.
This way the streaming using busboy actually allows each chunk to stream
in over the network one at a time.

For binary streams the actual chunking is not important. The chunks can
be split and recombined in whatever size chunk makes sense.

Since we buffer the entire content anyway we can combine the chunks to
be consecutive. This PR does that with binary streams and also combine
them into a single Blob. That way there's no extra overhead when passing
through a binary stream.

Ideally, we'd be able to just use the stream from that one Blob but
Node.js doesn't return byob streams from Blob. Additionally, we don't
actually stream the content of Blobs due to the layering with busboy
atm. We could do that for binary streams in particular by replacing the
File layering with a stream and resolving each chunk as it comes in.
That could be a follow up.

If we stop buffering in the future, this set up still allows us to split
them and send other form fields in between while blocked since the
protocol is still the same.
2024-05-07 21:52:55 -04:00
Jan Kassens
5a1cbc77b6 CI: remove react.yml integration test workflow (#2947)
This was used to run React CI tests compiled with the React Compiler. This is currently no longer used.
2024-05-07 17:29:57 -04:00
Jan Kassens
f4c12cc4a8 CI: fix Compiler Playground workflow (#2945)
Also renamed the workflow to make more sense when merged into the main React repo.
2024-05-07 16:15:59 -04:00
Jan Kassens
257f22ac57 CI: fix Compiler TypeScript workflow (#2946) 2024-05-07 16:07:46 -04:00
Jan Kassens
fd873e8ddd Rust: add stub for ensure_sufficient_stack (#2943) 2024-05-07 15:41:03 -04:00
Ruslan Lesiutin
e7d213dfb0 feat[react-devtools]: display forget badge for components in profiling session (#29014)
# Summary
- `compiledWithForget` field for nodes is now propagated from the
backend to frontend profiler stores
- Corresponding node with such field will have a `` prefix displayed
before its displayName
<img width="1728" alt="Screenshot 2024-05-07 at 15 05 37"
src="https://github.com/facebook/react/assets/28902667/fe044d40-52cb-4169-867d-5a2d72e3275b">

- Badges are now displayed on the right panel when some fiber is
selected in a specific commit
<img width="1728" alt="Screenshot 2024-05-07 at 15 05 50"
src="https://github.com/facebook/react/assets/28902667/297ba5ca-404d-4172-b9bf-bfed7978afe5">

- Badges are also displayed when user hovers over some node in the tree
<img width="1728" alt="Screenshot 2024-05-07 at 15 25 22"
src="https://github.com/facebook/react/assets/28902667/bee47884-61d1-46b6-a483-717fc148893a">
2024-05-07 16:39:01 +01:00
Ruslan Lesiutin
c32ff0f4f1 fix[react-devtools]: add backwards compat with legacy element type symbol (#28982)
Follow-up to https://github.com/facebook/react/pull/28813.

RDT is using `typeOf` from `react-is` to determine the element display
name, I've forked an implementation of this method, but will be using
legacy element symbol.
2024-05-07 16:38:43 +01:00
Jan Kassens
90a5d48a2f CI: fix Rust CI workflows (#2942)
- update paths
- update working directory
- rename files for clarity when merged into the main react repo
2024-05-07 11:17:30 -04:00
Sebastian Silbermann
0fc9c84e63 Allow specifying timeout in tests via third argument (#29006) 2024-05-07 17:15:39 +02:00
Moti Zilberman
afe54bfcbf [DevTools] Expose "view source" options to Fusebox integration (#28973)
## Summary

Exposes the APIs needed by React Native DevTools (Fusebox) to implement
the "view element source" and "view attribute source" features.

## How did you test this change?

1. `yarn build` in `react-devtools-fusebox`
2. Copy artifacts to rn-chrome-devtools-frontend
3. Write some additional glue code to implement
`viewElementSourceFunction` in our CDT fork.
4. Test the feature manually.


https://github.com/facebook/react/assets/2246565/12667018-100a-4b3f-957a-06c07f2af41a
2024-05-07 16:06:36 +01:00
Jan Kassens
55d6c6efaa CI: move .github directory back to root (#2941)
We need this in the root to run the steps. It should merge cleanly with the React repo as there is no file name overlap.

Next step is to update the paths to make it work again.
2024-05-07 11:03:44 -04:00
Dmytro Rykun
7039834262 Create Fabric-specific version of ReactNativeAttributesPayload (#28841)
## Summary

This PR introduces Fabric-only version of
`ReactNativeAttributesPayload`. It is a copy-paste of
`ReactNativeAttributesPayload.js`, and is called
`ReactNativeAttributesPayloadFabric.js`.
The idea behind this change is that certain optimizations in prop
diffing may actually be a regression on the old architecture. For
example, removing custom diffing may result in larger updateProps
payloads. Which is, I guess, fine with JSI, but might be a problem with
the bridge.

## How did you test this change?

There should be no runtime effect of this change.
2024-05-07 11:53:36 +01:00
Lauren Tan
7caf071e01 Add failing test for eslint-plugin false positive
The eslint rule seems to false positive on this typescript syntax, but
strangely the compiler does not

ghstack-source-id: 19baa24ff7addd83f59e2b03fdb180af169a2794
Pull Request resolved: https://github.com/facebook/react-forget/pull/2913
2024-05-06 20:39:49 -04:00
Lauren Tan
b28c53dcf1 Clarify how to address ValidateNoCapitalizedCalls errors
Make it clearer how to address this error by allowlisting globals that
are known to be safe

ghstack-source-id: e7fa6464ebb561a7a1366ff70430842007c6552e
Pull Request resolved: https://github.com/facebook/react-forget/pull/2909
2024-05-06 20:13:45 -04:00
Lauren Tan
d0a51e7dfc Allow eslint rule reportable severity to be set
During the demo I might show an example of fixing a
CannotPreserveMemoization error. But I don't want to make that
reportable by default, so this PR allows configuration like so

```js
module.exports = {
  root: true,
  plugins: [
    'eslint-plugin-react-compiler',
  ],
  rules: {
    'react-compiler/react-compiler': [
      'error', {
        reportableLevels: new Set([
          'InvalidJs',
          'InvalidReact',
          'CannotPreserveMemoization'
        ])
      }
     ]
  }
}
```

ghstack-source-id: 984c6d3cb7e19c8fea2bb88108dd26335c031573
Pull Request resolved: https://github.com/facebook/react-forget/pull/2936
2024-05-06 20:07:36 -04:00
Lauren Tan
84d28ebcc5 Default to raising all errors in eslint plugin
We control what gets reported via another function anyway so it's better
to raise everything at the compiler config level. This lets us configure
what level of diagnostic is reportable later

ghstack-source-id: 996d3cbb8d8f3e1bbe943210b8d633420e0f3f3b
Pull Request resolved: https://github.com/facebook/react-forget/pull/2935
2024-05-06 20:07:35 -04:00
Jan Kassens
e2d47342be Use default runtimeModule setting in Snap tests (#2940)
Lots of updated snapshots. The only updated code is resolving this TODO:

2b14805f98/packages/snap/src/compiler.ts (L41)
2024-05-06 19:57:37 -04:00
Jan Kassens
3708c36cbd [easy] remove unstable_useMemoCache reference from a snapshot file (#2937)
This file is intended to test that the test will skip if it was already compiled.

This updates the import to remove the no longer used name `unstable_useMemoCache`.
2024-05-06 19:54:13 -04:00
Jan Kassens
e63d3d1491 Upgrade to React 19 beta (#2938)
- Updated all directly defined dependencies to the latest React 19 Beta
- `package.json`: used `resolutions` to force React 19 for `react-is` transitive dependency
- `package.json`: postinstall script to patch fbt for the React 19 element Symbol
- Match on the message in Snap to exclude a React 19 warning that `act` should be imported from `react` instead (from inside `@testing-library/react`)
- Some updated snapshots, I think due to now recovering behavior of `useMemoCache`, please review.

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

- Snapshots now use `react/compiler-runtime` as in prod, so the different default in Snap is no longer needed.
2024-05-06 19:48:39 -04:00
Joe Savona
95ba7dcff5 Update readme and other docs
ghstack-source-id: b25cc2a481dc1508bbb710dff472f2d23667ec98
Pull Request resolved: https://github.com/facebook/react-forget/pull/2939
2024-05-06 14:53:47 -07:00
Jan Kassens
b498834eab Set enableUseMemoCacheHook to true everywhere (#28964)
Set enableUseMemoCacheHook to true everywhere for the next major releases.
2024-05-06 14:20:08 -04:00
Timothy Yung
9b1300209e Setup Wave 2 of Feature Flags for React Native (#28990)
## Summary

Sets up dynamic feature flags for `disableStringRefs`, `enableFastJSX`,
and `enableRefAsProp` in React Native (at Meta).

## How did you test this change?

```
$ yarn test
$ yarn flow fabric
```
2024-05-06 10:30:40 -07:00
Jan Kassens
e1771545a2 Remove domain from playground font sources (#2934) 2024-05-06 12:00:55 -04:00
Jack Pope
5d29478716 Add FB build for ReactReconcilerConstants (#29003)
In order to integrate the `react-reconciler` build created in #28880
with third party libraries, we need to have matching
`react-reconciler/constants` to go with it.
2024-05-06 11:32:43 -04:00
Timothy Yung
46abd7b1de Update compiled-rn destination paths to vendor/react (#28989)
I'm changing the destination paths in fbsource from `vendor/*` to
`vendor/react/*`.
2024-05-03 15:46:43 -07:00
Sebastian Markbåge
ec9400dc41 [Flight Reply] Encode ReadableStream and AsyncIterables (#28893)
Same as #28847 but in the other direction.

Like other promises, this doesn't actually stream in the outgoing
direction. It buffers until the stream is done. This is mainly due to
our protocol remains compatible with Safari's lack of outgoing streams
until recently.

However, the stream chunks are encoded as separate fields and so does
support the busboy streaming on the receiving side.
2024-05-03 17:23:55 -04:00
Sebastian Markbåge
5fcfd71638 Use undici polyfill for tests in old Node versions (#28887)
We currently don't test FormData / File dependent features in CI because
we use an old Node.js version in CI. We should probably upgrade to 18
since that's really the minimum version that supports all the features
out of the box.

JSDOM is not a faithful/compatible implementation of these APIs. The
recommended way to use Flight together with FormData/Blob/File in older
Node.js versions, is to polyfill using the `undici` library.

However, even in these versions the Blob implementation isn't quite
faithful so the Reply client needs a slight tweak for multi-byte typed
arrays.
2024-05-03 16:29:09 -04:00
Sebastian Markbåge
d5c303427e [Flight] Track Owner on AsyncLocalStorage When Available (#28807)
Stacked on #28798.

Add another AsyncLocalStorage to the FlightServerConfig. This context
tracks data on a per component level. Currently the only thing we track
is the owner in DEV.

AsyncLocalStorage around each component comes with a performance cost so
we only do it DEV. It's not generally a particularly safe operation
because you can't necessarily associate side-effects with a component
based on execution scope. It can be a lazy initializer or cache():ed
code etc. We also don't support string refs anymore for a reason.

However, it's good enough for optional dev only information like the
owner.
2024-05-03 16:29:00 -04:00
Pieter Vanderwerff
738ddf7419 Support <fbs> in addition to <fbt>
ghstack-source-id: 1ab99ebb5cef3f42399682a338feb12c4cf55f4c
Pull Request resolved: https://github.com/facebook/react-forget/pull/2933
2024-05-03 13:27:51 -07:00
Jan Kassens
0a0a3af75a Bundle config: inline internal hook wrapper (#28978)
Bundle config: inline internal hook wrapper

Instead of reading this wrapper from 2 files for "start" and "end" and
then string modifying the templates, just inline them like the other
wrappers in this file.
2024-05-03 14:08:10 -04:00
Jon Janzen
38cd73b25b Stop committing resources to an external repo (#28963)
This has been integrated into this repo (`builds/facebook-fbsource`) so
we no longer need the extra repo
2024-05-03 11:01:53 -07:00
Joe Savona
90863beaa8 Expand the architecture doc
ghstack-source-id: 6ab453a3c5e23677d0c178cf4ea464c7a9e7ebf6
Pull Request resolved: https://github.com/facebook/react-forget/pull/2932
2024-05-03 10:46:36 -07:00
Moti Zilberman
e3fbb51db6 [DevTools] Enable inspected element context menu in Fusebox (#28972)
## Summary

Enables the inspected element context menu in React Native DevTools
(Fusebox).

## How did you test this change?

1. `yarn build` in `react-devtools-fusebox`
2. Copy artifacts to rn-chrome-devtools-frontend
3. Manually test the context menu


https://github.com/facebook/react/assets/2246565/b35cc20f-8d67-43b0-b863-7731e10fffac

NOTE: The serialised values sometimes expose React internals (e.g. Hook
data structures instead of just the values), but that seems to be a
problem equally on web, so I'm going for native<->web parity here.
2024-05-03 17:33:21 +01:00
Moti Zilberman
8f7dd5592b [DevTools] Check in frontend.d.ts for react-devtools-fusebox, include in build output (#28970)
## Summary

The `react-devtools-fusebox` private package is used in the React Native
DevTools (Fusebox) frontend by checking build artifacts into RN's
[fork]([`facebookexperimental/rn-chrome-devtools-frontend`](https://github.com/facebookexperimental/rn-chrome-devtools-frontend))
of the Chrome DevTools (CDT) repo - see
https://github.com/facebookexperimental/rn-chrome-devtools-frontend/pull/22.

Currently, the CDT fork also includes a [manually written TypeScript
definition
file](1d5f8d5209/front_end/third_party/react-devtools/package/frontend.d.ts)
which describes `react-devtools-fusebox`'s API. This PR moves that file
into the React repo, next to the implementation of
`react-devtools-fusebox`, so we can update it atomically with changes to
the package.

As this is the first bit of TypeScript in this repo, the PR adds minimal
support for formatting `.d.ts` files with Prettier. It also opts out
`react-devtools-fusebox/dist/` from linting/formatting as a drive-by
fix.

For now, we'll just maintain the `.d.ts` file manually, but we could
consider leveraging
[`flow-api-translator`](https://www.npmjs.com/package/flow-api-translator)
to auto-generate it in the future.

## How did you test this change?

Build `react-devtools-fusebox`, observe that `dist/frontend.d.ts`
exists.
2024-05-03 17:32:41 +01:00
Jack Pope
1beb73de0f Add flag to test fast jsx (#28816)
Following #28768, add a path to testing Fast JSX on www.

We want to measure the impact of Fast JSX and enable a path to testing
before string refs are completely removed in www (which is a work in
progress).

Without `disableStringRefs`, we need to copy any object with a `ref` key
so we can pass it through `coerceStringRef()` and copy it into the
object. This de-opt path is what is gated behind
`enableFastJSXWithStringRefs`.

The additional checks should have no perf impact in OSS as the flags
remain true there and the build output is not changed. For www, I've
benchmarked the addition of the boolean checks with values cached at
module scope. There is no significant change observed from our
benchmarks and any latency will apply to test and control branches
evenly. This added experiment complexity is temporary. We should be able
to clean it up, along with the flag checks for `enableRefAsProp` and
`disableStringRefs` shortly.
2024-05-03 10:47:13 -04:00
Timothy Yung
1d618a9cf3 Enable Wave 1 of Feature Flags for React Native (#28977) 2024-05-02 20:01:30 -07:00
Joe Savona
82137ec184 Rename react-compiler-runtime
ghstack-source-id: c6c825f5efdb4f9c413050b22b7713966871338c
Pull Request resolved: https://github.com/facebook/react-forget/pull/2931
2024-05-02 17:14:26 -07:00
Joe Savona
1c8f8bfb89 Rename ReactForgetBabelPlugin locals
ghstack-source-id: 9cd5fe41ae322632dfeb3d5c7468268678006d94
Pull Request resolved: https://github.com/facebook/react-forget/pull/2929
2024-05-02 17:14:25 -07:00
Joe Savona
95e3cdcfa1 Rename {r,R}unReactForgetBabelPlugin
ghstack-source-id: e7f00aab61dd749dc6ba11ce7e4d14603bfeeab9
Pull Request resolved: https://github.com/facebook/react-forget/pull/2928
2024-05-02 17:14:24 -07:00
Joe Savona
b844766e6c Update references to Forget to React Compiler
ghstack-source-id: cce73f26b7b3903b8d79b70dbc24cbee09693d81
Pull Request resolved: https://github.com/facebook/react-forget/pull/2927
2024-05-02 14:28:06 -07:00
Joe Savona
48e0c70292 Rename babel plugin
ghstack-source-id: bb66913e2d3c814696311371ed655f3da03d1199
Pull Request resolved: https://github.com/facebook/react-forget/pull/2926
2024-05-02 14:12:33 -07:00
Sebastian Silbermann
f5f2799a8d DevTools: Fix inspecting components with multiple reads of the same Context in React 17 (#28974) 2024-05-02 22:08:41 +02:00
Sebastian Silbermann
14f71db6b6 Devtools: Fix build-for-devtools (#28976) 2024-05-02 21:58:51 +02:00
Sebastian Silbermann
c44e9d1557 Devtools: Streamline getting extension from branch (#28975) 2024-05-02 21:47:18 +02:00
Dmytro Rykun
73bcdfbae5 Introduce a faster version of the addProperties function (#28969)
## Summary

This PR introduces a faster version of the `addProperties` function.
This new function is basically the `diffProperties` with `prevProps` set
to `null`, propagated constants, and all the unreachable code paths
collapsed.

## How did you test this change?

I've tested this change with [the benchmark
app](https://github.com/react-native-community/RNNewArchitectureApp/tree/new-architecture-benchmarks)
and got ~4.4% improvement in the view creation time.
2024-05-02 17:10:13 +01:00
Josh Story
c7b1ae5a9e [Tooling] Update critical artifact list (#28966)
When a React PR is opened CI will report large size changes. But for
critical packages like react-dom it reports always. In React 19 we moved
the build for react-dom the client reconciler from react-dom to
react-dom/client

This change adds react-dom-client artifacts for stable and oss channels
since that is originally what was being tracked. But since
react-dom/client always imports react-dom I left the original react-dom
packages as critical as well. They are small but it would be good to
keep an eye on them
2024-05-02 07:39:10 -07:00
Juan Pinilla
29d3c83f0a ReactDOM: Fix missing form data when the submitter is outside the form (#28056) 2024-05-02 13:06:28 +02:00
Lauren Tan
fddc0151fe Remove duplicated hermes-parser
ghstack-source-id: 79f3319d87909d05731ef821d0ffe86cb01b0432
Pull Request resolved: https://github.com/facebook/react-forget/pull/2920
2024-04-30 21:34:36 -04:00
Lauren Tan
f93529e0be Don't compile node_modules by default
To make a first time setup of the compiler truly config-less, default to
not compiling node_modules unless a user provided `sources` (advanced
option) is provided

ghstack-source-id: b0798052404d772ce6ee471e577699d4b0871d56
Pull Request resolved: https://github.com/facebook/react-forget/pull/2919
2024-04-30 21:34:33 -04:00
Jan Kassens
ebe58ee619 Update babel plugin to use runtime from react/compiler-runtime (#2918)
This uses the compiler runtime from `react/compiler-runtime` by default unless `compilerRuntime` is specifified in the Babel options which then imports the runtime from there. The `useMemoCache` hook is now named `c` in accordance with 4508873393

Unfortunately, I couldn't figure out how to import `react@beta` which already has that import as various react verstions were conflicting. If someone can figure this out it'd be fantastic. As a result, I had to update the default for the test runner to default the `compilerRuntime` option to `react` to preserve the previous behavior to import from `react`. Once upgraded to React 19, we should be able to remove that override.
2024-05-01 13:53:44 -04:00
Sathya Gunsasekaran
85e6e9b469 [hir] Mark MethodCalls as escaping
Treat MethodCalls similar to general CallExpressions and mark them
as escaping in PruneNonEscapingScopes pass.

ghstack-source-id: 3c81bdb17f58fbeef8be24e7cb363172d1867217
Pull Request resolved: https://github.com/facebook/react-forget/pull/2925
2024-05-01 15:58:57 +01:00
Sathya Gunsasekaran
4ce5c56fee [healthcheck] Refactor checks into separate files
Makes it easier to extend later, if we want to add more checks.

ghstack-source-id: 6fb3435555f1b988e1a185bfda8be9418eb622c5
Pull Request resolved: https://github.com/facebook/react-forget/pull/2924
2024-05-01 16:05:11 +01:00
Sathya Gunsasekaran
c464445b91 [healthcheck] Check for incompatible libraries
Add a configurable list of known incompatible libraries.

Check all package.jsons for any uses of known incompatible libraries and
warn if found.

ghstack-source-id: 7329e3792b57458e681780cba3140a14a9b1a60d
Pull Request resolved: https://github.com/facebook/react-forget/pull/2923
2024-05-01 15:34:40 +01:00
Sathya Gunsasekaran
36d775596f [healthcheck] Check for StrictMode
ghstack-source-id: f05222073be785b77346c4e8760bf4d0bb4d658e
Pull Request resolved: https://github.com/facebook/react-forget/pull/2922
2024-05-01 13:35:06 +01:00
Sathya Gunsasekaran
c88d356603 [healthcheck] Add status message
Show compiling status message and not just block
UI.

ghstack-source-id: 67761c5d32216e105c4aa6404dfa07d76ae22583
Pull Request resolved: https://github.com/facebook/react-forget/pull/2921
2024-05-01 13:35:03 +01:00
Lauren Tan
86e0f87a5b Dynamically detect reanimated plugin
Enables the Reanimated flag automatically if we find reanimated in the
user's list of plugins

ghstack-source-id: 20e83374612362a30d6c8cc7a903d9320e8cc23a
Pull Request resolved: https://github.com/facebook/react-forget/pull/2915
2024-04-30 14:24:03 -04:00
Jan Kassens
4508873393 Move useMemoCache hook to react/compiler-runtime (#28954)
Move useMemoCache hook to react/compiler-runtime

For Meta-internal purposes, we keep the export on `react` itself to
reduce churn.
2024-04-30 12:00:22 -04:00
Pieter De Baets
d779eba4b3 [react-native] Add unit test to ReactNativeAttributePayload (#28955)
## Summary

I'm looking at cleaning up some unnecessary manual property flattening
in React Native and wanted to verify this behaviour is working as
expected, where properties from nested objects will always overwrite
properties from the base object.

## How did you test this change?

Unit tests
2024-04-29 19:57:32 -07:00
Sebastian Silbermann
190cc990e0 Import correct prod version of jsx-dev-runtime for react-server (#28939) 2024-04-27 22:25:25 +02:00
Alex Yang
8090457c77 fix: add react-server condition for react/jsx-dev-runtime (#28921) 2024-04-27 21:45:52 +02:00
Ricky
4ddff7355f Add changelog for 18.3.1 (#28932) 2024-04-26 16:03:03 -04:00
Ricky
95e610da13 Add changelog for 18.3 (#28929)
Fixes https://github.com/facebook/react/issues/28924
2024-04-26 12:45:08 -04:00
Ricky
c4083616a2 Create React 19 issue template 2024-04-25 15:32:31 -04:00
Lauren Tan
1181043d80 Disable ValidateNoCapitalizedCalls by default
As discussed earlier, let's disable this validation pass by default for
oss since it still has many false positives

ghstack-source-id: fa3c21dde7cc4c3e4bb91dfa707e64bc7a9e088b
Pull Request resolved: https://github.com/facebook/react-forget/pull/2908
2024-04-25 14:19:21 -04:00
Mofei Zhang
18f4a388a9 [hir-rewrite] Remove breaks to HIR ScopeTerminal after converting to reactiveFunction IR
ghstack-source-id: 67e979e1533b23ced762973e239a4290111e2242
Pull Request resolved: https://github.com/facebook/react-forget/pull/2911
2024-04-29 14:08:30 -04:00
Mofei Zhang
6db5f36aa7 [tests] Add fixtures showing HIR rewrite changes
ghstack-source-id: 5e8b1680e95d112e1e5b2cb8c4e6c414360e0a77
Pull Request resolved: https://github.com/facebook/react-forget/pull/2900
2024-04-29 14:08:29 -04:00
Mofei Zhang
2b2d305199 [hir] Rewrite buildReactiveBlocks -> buildReactiveScopeTerminalsHIR
ghstack-source-id: 1e804dd31d4b5f74070c94c0ea56f55539e46703
Pull Request resolved: https://github.com/facebook/react-forget/pull/2853
2024-04-29 14:08:29 -04:00
Josh Story
94eed63c49 (Land #28798) Move Current Owner (and Cache) to an Async Dispatcher (#28912)
Rebasing and landing https://github.com/facebook/react/pull/28798

This PR was approved already but held back to give time for the sync.
Rebased and landing here without pushing to seb's remote to avoid
possibility of lost updates

---------

Co-authored-by: Sebastian Markbage <sebastian@calyptus.eu>
2024-04-25 10:40:40 -07:00
Andrew Clark
f8a8eac86b Update canary channel label to "beta" (#28905)
During the beta period, canaries will be published as
`19.0.0-beta-<COMMIT_SHA>-<DATE>`. They will also be tagged as `beta`
when published to npm.
2024-04-25 13:14:33 -04:00
Sebastian Silbermann
82d8129e58 Reconciler: Change commitUpdate signature to account for unused updatePayload parameter (#28909) 2024-04-25 19:14:06 +02:00
Andrew Clark
d285b3acba Go back to shared refs instance object (#28911)
It turns out we already made refs writable in #25696, which has been in
canary for over a year. The approach in that PR also has the benefit of
being slightly more perf sensitive because it still uses a shared object
until the fiber is mounted. So let's just go back to that.
2024-04-25 13:03:21 -04:00
Jan Kassens
ed71a3ad29 Support ref cleanup function for imperative handle refs (#28910)
Support ref cleanup function for imperative handle refs
2024-04-25 12:51:41 -04:00
Joe Savona
1c7e34cdb6 Stop reporting errors on mutations of primitives (and associated false positives)
ghstack-source-id: 4dc9b3c51953f8ed2184ebc5e438bc877959b5d0
Pull Request resolved: https://github.com/facebook/react-forget/pull/2903
2024-04-25 09:39:20 -07:00
Joe Savona
0a7f4427f1 Fix invariant on mutable context values
ghstack-source-id: cb105318bf66d876a546b1c52e28286839d30032
Pull Request resolved: https://github.com/facebook/react-forget/pull/2904
2024-04-25 08:00:56 -07:00
Mofei Zhang
59e37b088b [HIR] Detect more cases of invalid block nesting
ghstack-source-id: 9e08fa69807ee1b5e99675f9aefc8acd13c16827
Pull Request resolved: https://github.com/facebook/react-forget/pull/2899
2024-04-26 12:40:36 -04:00
Mofei Zhang
a44559b0a5 [hir] Re-implement mergeOverlappingReactiveScopes (+ bugfix)
ghstack-source-id: 06d49edffe5ae3c31eb6ef642078752c056c617c
Pull Request resolved: https://github.com/facebook/react-forget/pull/2852
2024-04-26 12:40:35 -04:00
Mofei Zhang
f196e1f703 [hir][patch] Fix small bug in duplicate scope merging logic
ghstack-source-id: 98966dd4c2b264329acad077427febc2a34a5edc
Pull Request resolved: https://github.com/facebook/react-forget/pull/2906
2024-04-25 11:07:22 -04:00
Jack Pope
cf5ab8b8b2 Add descriptions of new methods to the react-reconciler readme (#28750)
Add new reconciler methods since last breaking change to the README
based on usage and comments.

---------

Co-authored-by: Josh Story <josh.c.story@gmail.com>
2024-04-25 09:37:55 -04:00
Andrew Clark
c516cefc7d warn -> error for Test Renderer deprecation (#28904)
We use `console.error` for deprecations. `console.warn` is for less
critical issues, like performance anti-patterns.
2024-04-24 14:54:39 -04:00
Josh Story
cb151849e1 [react-dom] move all client code to react-dom/client (#28271)
This PR reorganizes the `react-dom` entrypoint to only pull in code that
is environment agnostic. Previously if you required anything from this
entrypoint in any environment the entire client reconciler was loaded.
In a prior release we added a server rendering stub which you could
alias in server environments to omit this unecessary code. After landing
this change this entrypoint should not load any environment specific
code.

While a few APIs are truly client (browser) only such as createRoot and
hydrateRoot many of the APIs you import from this package are only
useful in the browser but could concievably be imported in shared code
(components running in Fizz or shared components as part of an RSC app).
To avoid making these require opting into the client bundle we are
keeping them in the `react-dom` entrypoint and changing their
implementation so that in environments where they are not particularly
useful they do something benign and expected.

#### Removed APIs
The following APIs are being removed in the next major. Largely they
have all been deprecated already and are part of legacy rendering modes
where concurrent features of React are not available
* `render`
* `hydrate`
* `findDOMNode`
* `unmountComponentAtNode`
* `unstable_createEventHandle`
* `unstable_renderSubtreeIntoContainer`
* `unstable_runWithPrioirty`

#### moved Client APIs
These APIs were available on both `react-dom` (with a warning) and
`react-dom/client`. After this change they are only available on
`react-dom/client`
* `createRoot`
* `hydrateRoot`

#### retained APIs
These APIs still exist on the `react-dom` entrypoint but have normalized
behavior depending on which renderers are currently in scope
* `flushSync`: will execute the function (if provided) inside the
flushSync implemention of FlightServer, Fizz, and Fiber DOM renderers.
* `unstable_batchedUpdates`: This is a noop in concurrent mode because
it is now the only supported behavior because there is no legacy
rendering mode
* `createPortal`: This just produces an object. It can be called from
anywhere but since you will probably not have a handle on a DOM node to
pass to it it will likely warn in environments other than the browser
* preloading APIS such as `preload`: These methods will execute the
preload across all renderers currently in scope. Since we resolve the
Request object on the server using AsyncLocalStorage or the current
function stack in practice only one renderer should act upon the
preload.

In addition to these changes the server rendering stub now just rexports
everything from `react-dom`. In a future minor we will add a warning
when using the stub and in the next major we will remove the stub
altogether
2024-04-24 08:50:32 -07:00
Jan Kassens
b039be627d Unrevert "Support writing to this.refs from userspace" (#28879)
Reverts facebook/react#28877

We found the cause of the regression and should be able to land this
again.
2024-04-24 10:03:09 -04:00
Ricky
6f6e375fce Create short link for jsx warning (#28899)
Short link created in https://github.com/reactjs/react.dev/pull/6772
2024-04-24 09:32:11 -04:00
Sebastian Silbermann
6f18664b82 eslint-plugin-react-hooks: Add support for ESLint v9 (#28773) 2024-04-23 23:29:01 +02:00
Mofei Zhang
f22dd62ab8 [HIR] Followup to pruneUnusedLabelsHIR (#2866)
Followup to https://github.com/facebook/react-forget/pull/2866

ghstack-source-id: 087d5da53787cb7cff6495b6a791326ff8a952b4
Pull Request resolved: https://github.com/facebook/react-forget/pull/2896
2024-04-23 19:58:31 +01:00
Joe Savona
2d569a3353 Add detection of dynamic hooks
ghstack-source-id: 3acfa4fde5dfd65353fa407378057ca937ee3599
Pull Request resolved: https://github.com/facebook/react-forget/pull/2901
2024-04-24 15:15:34 -07:00
Lauren Tan
89f2f7fcef Make DropManualMemoization error message more accurate
This was probably a leftover from a previous time, but since this error
message throws when the dependency list is not an array literal, and not
just when its a rest spread, this PR updates the message to match.

ghstack-source-id: 28f2338212e56a67d3d477cea5abb6e9f3826488
Pull Request resolved: https://github.com/facebook/react-forget/pull/2902
2024-04-25 10:19:29 -04:00
Joe Savona
08b777d6dc [be] Rename NextIterableOf -> AdvanceIterator
ghstack-source-id: 024ec00511483cf342d851fde001c96348a2d3c6
Pull Request resolved: https://github.com/facebook/react-forget/pull/2898
2024-04-24 14:59:09 -07:00
Joe Savona
21b2af8ba0 More precisely model for..of semantics with separate init/test blocks
ghstack-source-id: 827c35466d04f7b7143ddf1adefeff926d4b22cd
Pull Request resolved: https://github.com/facebook/react-forget/pull/2893
2024-04-24 14:59:08 -07:00
Joe Savona
da004f1885 Add GetIterator instruction
ghstack-source-id: 8ed2deed7606c48414de74cb2781a5fde6cd6f59
Pull Request resolved: https://github.com/facebook/react-forget/pull/2892
2024-04-24 14:59:08 -07:00
Joe Savona
6304e98902 Repro for for..of scoping bug
ghstack-source-id: 6147b6e70d24203350664e8ab24691d1ec5c5b2a
Pull Request resolved: https://github.com/facebook/react-forget/pull/2891
2024-04-24 14:59:07 -07:00
Andrew Clark
a94838df1c Remove automatic fetch cache instrumentation (#28896)
This removes the automatic patching of the global `fetch` function in
Server Components environments to dedupe requests using `React.cache`, a
behavior that some RSC framework maintainers have objected to.

We may revisit this decision in the future, but for now it's not worth
the controversy.

Frameworks that have already shipped this behavior, like Next.js, can
reimplement it in userspace.

I considered keeping the implementation in the codebase and disabling it
by setting `enableFetchInstrumentation` to `false` everywhere, but since
that also disables the tests, it doesn't seem worth it because without
test coverage the behavior is likely to drift regardless. We can just
revert this PR later if desired.
2024-04-23 14:14:12 -04:00
Jack Pope
d4e78c42a9 Add ref callback test for cleanup fn vs null call (#28895)
Used this test scenario to clarify how callback refs work when detached
based on the availability of a cleanup function to update documentation
in https://github.com/reactjs/react.dev/pull/6770

Checking it in for additional test coverage and test-based documentation
2024-04-23 12:13:09 -04:00
Sathya Gunsasekaran
f8c0363a92 [healthcheck] Rename package to healthcheck
Make it one word, instead of two words and a hyphen.

ghstack-source-id: ef05e8acbd7cf17e2dd04c362dcee785eda79e82
Pull Request resolved: https://github.com/facebook/react-forget/pull/2895
2024-04-23 12:33:51 +01:00
Sathya Gunsasekaran
e0dbe47ad6 [healthcheck] Only count actionable failures
It's not useful to output count of all failures,
as it's not actionable for the developer.

We'll still capture all failures in case we want
to add a rage option to this script.

ghstack-source-id: 4d5a1dd6a9616e6fd5e1166bb97fa047829b9273
Pull Request resolved: https://github.com/facebook/react-forget/pull/2889
2024-04-23 12:28:43 +01:00
Sathya Gunsasekaran
dff05237c5 [healthcheck] Compile sources
Run the compiler on the globbed soruces.

The logger is used to capture the success and
failure compilation cases at the component level.
(If we were to compile the entire file directly,
we wouldn't get this granularity)

For now, we just log the number of success and
failures. In the future, we can provide a better
report building on this.

ghstack-source-id: 6d2d918190b6ed5d42b795491bbce29a950b9741
Pull Request resolved: https://github.com/facebook/react-forget/pull/2888
2024-04-23 12:28:42 +01:00
Sathya Gunsasekaran
8d234c64eb [hir] Remove hermes parser
Exporting the hermes parser breaks the playground
as the hermes parser can not work in the browser.

No one is using this directly anyway -- snap and
others bundle hermes parser on their own, so,
let's remove it.

ghstack-source-id: d448c346eb137f8ba6ada4ad113e41a90b29baff
Pull Request resolved: https://github.com/facebook/react-forget/pull/2890
2024-04-23 12:28:42 +01:00
Sathya Gunsasekaran
9e15ade177 [healthcheck] Read files from globbed path
ghstack-source-id: a79336c2b1c85ae4d5b941ffbeffb3df10816448
Pull Request resolved: https://github.com/facebook/react-forget/pull/2887
2024-04-23 12:28:41 +01:00
Sathya Gunsasekaran
a6cc5bc874 [healthcheck] Read glob of src path
Use yargs to parse input of glob expression
matching the path of src files to compile.

ghstack-source-id: 6a35e958428cd08ef5c96e0014e072d3faf04064
Pull Request resolved: https://github.com/facebook/react-forget/pull/2886
2024-04-23 12:28:41 +01:00
Sathya Gunsasekaran
706e04722f [healthcheck] Init tsconfig
ghstack-source-id: 52339f8e5cde29d4e132762de2e4e4b31f25f8c1
Pull Request resolved: https://github.com/facebook/react-forget/pull/2885
2024-04-23 12:28:40 +01:00
Sathya Gunsasekaran
6019ef0a43 [healthcheck] New package for checking violations
This package will be used to check for violations
of the rules of react and other heuristics to
determine the health of a codebase.

The health of a codebase gives an expectation of
how easy it will be onboard on to the compiler.

ghstack-source-id: b52fc4e44f704e0544f15066d8905825a256dc4a
Pull Request resolved: https://github.com/facebook/react-forget/pull/2884
2024-04-23 12:28:40 +01:00
Mofei Zhang
10e11c4a88 [HIR] Assert program blocks and scopes are properly nested
ghstack-source-id: e3fe9b5fb8d1314e16e562581f40ca2b2a555b97
Pull Request resolved: https://github.com/facebook/react-forget/pull/2867
2024-04-23 10:18:50 +01:00
Mofei Zhang
40474b8eaf [HIR] Naive implementation of pruneUnusedLabels in HIR
ghstack-source-id: 6d55db3d5c0fd7736a59d48c6afb2de9b5729d16
Pull Request resolved: https://github.com/facebook/react-forget/pull/2866
2024-04-23 10:18:50 +01:00
Mofei Zhang
555100ca83 [HIR] Nonnullable block fallthroughs
ghstack-source-id: 6f24b60056c741e5d4e9836f91bc4fce0f9e8fdd
Pull Request resolved: https://github.com/facebook/react-forget/pull/2865
2024-04-23 10:18:49 +01:00
Mofei Zhang
1efb3cae0a [HIR] Add new unreachable terminal
ghstack-source-id: cffdbbbd78a0aa7e1587a234ce27366ea626ee5e
Pull Request resolved: https://github.com/facebook/react-forget/pull/2864
2024-04-23 10:18:48 +01:00
Mofei Zhang
d87ba1b9df [be] Stabilize block ids
ghstack-source-id: 83aedf9f086ccb4819655eab803f25f944b75c7b
Pull Request resolved: https://github.com/facebook/react-forget/pull/2851
2024-04-23 10:18:48 +01:00
Mofei Zhang
b21ca44efc [repro] bug repro
ghstack-source-id: 64d3266bf39ce5b1b9e9b9470910e029f0e951eb
Pull Request resolved: https://github.com/facebook/react-forget/pull/2849
2024-04-23 10:18:47 +01:00
Sebastian Silbermann
699d03ce1a Cleanup replayFailedUnitOfWorkWithInvokeGuardedCallbackand enableProfilerNestedUpdateScheduledHook (#28891) 2024-04-22 21:35:11 +02:00
Sebastian Markbåge
9f2eebd807 [Fiber/Fizz] Support AsyncIterable as Children and AsyncGenerator Client Components (#28868)
Stacked on #28849, #28854, #28853. Behind a flag.

If you're following along from the side-lines. This is probably not what
you think it is.

It's NOT a way to get updates to a component over time. The
AsyncIterable works like an Iterable already works in React which is how
an Array works. I.e. it's a list of children - not the value of a child
over time.

It also doesn't actually render one component at a time. The way it
works is more like awaiting the entire list to become an array and then
it shows up. Before that it suspends the parent.

To actually get these to display one at a time, you have to opt-in with
`<SuspenseList>` to describe how they should appear. That's really the
interesting part and that not implemented yet.

Additionally, since these are effectively Async Functions and uncached
promises, they're not actually fully "supported" on the client yet for
the same reason rendering plain Promises and Async Functions aren't.
They warn. It's only really useful when paired with RSC that produces
instrumented versions of these. Ideally we'd published instrumented
helpers to help with map/filter style operations that yield new
instrumented AsyncIterables.

The way the implementation works basically just relies on unwrapThenable
and otherwise works like a plain Iterator.

There is one quirk with these that are different than just promises. We
ask for a new iterator each time we rerender. This means that upon retry
we kick off another iteration which itself might kick off new requests
that block iterating further. To solve this and make it actually
efficient enough to use on the client we'd need to stash something like
a buffer of the previous iteration and maybe iterator on the iterable so
that we can continue where we left off or synchronously iterate if we've
seen it before. Similar to our `.value` convention on Promises.

In Fizz, I had to do a special case because when we render an iterator
child we don't actually rerender the parent again like we do in Fiber.
However, it's more efficient to just continue on where we left off by
reusing the entries from the thenable state from before in that case.
2024-04-22 13:25:05 -04:00
Sebastian Markbåge
3b551c8284 Rename the react.element symbol to react.transitional.element (#28813)
We have changed the shape (and the runtime) of React Elements. To help
avoid precompiled or inlined JSX having subtle breakages or deopting
hidden classes, I renamed the symbol so that we can early error if
private implementation details are used or mismatching versions are
used.

Why "transitional"? Well, because this is not the last time we'll change
the shape. This is just a stepping stone to removing the `ref` field on
the elements in the next version so we'll likely have to do it again.
2024-04-22 12:39:56 -04:00
Joe Savona
896d1b0027 [dx] Improve error message from InferReferenceEffects
ghstack-source-id: 06265d9676b671a5b02ca05433a219dd219be4f1
Pull Request resolved: https://github.com/facebook/react-forget/pull/2883
2024-04-22 08:14:35 -07:00
Joe Savona
b11074772b InferReferenceEffects defers function effects until used
ghstack-source-id: 186951086ac1dd8ebd75d6fdfca5c1a41e54a33e
Pull Request resolved: https://github.com/facebook/react-forget/pull/2881
2024-04-22 08:14:34 -07:00
Jack Pope
db913d8e17 Remove warning for ref cleanup function (#28883)
Resources
- RFC: https://github.com/reactjs/rfcs/pull/205
- Warning implemented in https://github.com/facebook/react/pull/22313
- Warning enabled in https://github.com/facebook/react/pull/23145
- Feature added in https://github.com/facebook/react/pull/25686

We have warned to prevent the old behavior since 18.0.0.

The new feature has been on in canary for a while but still triggering
the warning. This PR cleans up the warning for 19
2024-04-22 10:57:31 -04:00
Sebastian Markbåge
5b903cdaa9 [Flight] Support (Async) Generator ServerComponent (#28849)
Stacked on #28853 and #28854.

React supports rendering `Iterable` and will soon support
`AsyncIterable`. As long as it's multi-shot since during an update we
may have to rerender with new inputs an loop over the iterable again.
Therefore the `Iterator` and `AsyncIterator` types are not supported
directly as a child of React - and really it shouldn't pass between
Hooks or components neither for this reason. For parity, that's also the
case when used in Server Components.

However, there is a special case when the component rendered itself is a
generator function. While it returns as a child an `Iterator`, the React
Element itself can act as an `Iterable` because we can re-evaluate the
function to create a new generator whenever we need to.

It's also very convenient to use generator functions over constructing
an `AsyncIterable`. So this is a proposal to special case the
`Generator`/`AsyncGenerator` returned by a (Async) Generator Function.

In Flight this means that when we render a Server Component we can
serialize this value as an `Iterable`/`AsyncIterable` since that's
effectively what rendering it on the server reduces down to. That way if
Fiber can receive the result in any position.

For SuspenseList this would also need another special case because the
children of SuspenseList represent "rows".

`<SuspenseList><Component /></SuspenseList>` currently is a single "row"
even if the component renders multiple children or is an iterator. This
is currently different if Component is a Server Component because it'll
reduce down to an array/AsyncIterable and therefore be treated as one
row per its child. This is different from `<SuspenseList><Component
/><Component /></SuspenseList>` since that has a wrapper array and so
this is always two rows.

It probably makes sense to special case a single-element child in
`SuspenseList` to represent a component that generates rows. That way
you can use an `AsyncGeneratorFunction` to do this.
2024-04-21 13:10:10 -04:00
Sebastian Markbåge
bf426f9b1d [Flight / Flight Reply] Encode Iterator separately from Iterable (#28854)
For [`AsyncIterable`](https://github.com/facebook/react/pull/28847) we
encode `AsyncIterator` as a separate tag.

Previously we encoded `Iterator` as just an Array. This adds a special
encoding for this. Technically this is a breaking change.

This is kind of an edge case that you'd care about the difference but it
becomes more important to treat these correctly for the warnings here
#28853.
2024-04-21 12:52:04 -04:00
Sebastian Markbåge
368202181e Warn for Child Iterator of all types but allow Generator Components (#28853)
This doesn't change production behavior. We always render Iterables to
our best effort in prod even if they're Iterators.

But this does change the DEV warnings which indicates which are valid
patterns to use.

It's a footgun to use an Iterator as a prop when you pass between
components because if an intermediate component rerenders without its
parent, React won't be able to iterate it again to reconcile and any
mappers won't be able to re-apply. This is actually typically not a
problem when passed only to React host components but as a pattern it's
a problem for composability.

We used to warn only for Generators - i.e. Iterators returned from
Generator functions. This adds a warning for Iterators created by other
means too (e.g. Flight or the native Iterator utils). The heuristic is
to check whether the Iterator is the same as the Iterable because that
means it's not possible to get new iterators out of it. This case used
to just yield non-sense like empty sets in DEV but not in prod.

However, a new realization is that when the Component itself is a
Generator Function, it's not actually a problem. That's because the
React Element itself works as an Iterable since we can ask for new
generators by calling the function again. So this adds a special case to
allow the Generator returned from a Generator Function's direct child.
The principle is “don’t pass iterators around” but in this case there is
no iterator floating around because it’s between React and the JS VM.

Also see #28849 for context on AsyncIterables.

Related to this, but Hooks should ideally be banned in these for the
same reason they're banned in Async Functions.
2024-04-21 12:51:45 -04:00
Joe Savona
f39dd1b82f InferReferenceEffects s/reference/referenceAndRecordEffects/
ghstack-source-id: 4d7439e7ada77e65991869593aa6a5d88d5ad600
Pull Request resolved: https://github.com/facebook/react-forget/pull/2882
2024-04-20 12:18:28 -07:00
Andrew Clark
857ee8cdf9 Don't minify symbols in production builds (#28881)
This disables symbol renaming in production builds. The original
variable and function names are preserved. All other forms of
compression applied by Closure (dead code elimination, inlining, etc)
are unchanged — the final program is identical to what we were producing
before, just in a more readable form.

The motivation is to make it easier to debug React issues that only
occur in production — the same reason we decided to start shipping
sourcemaps in #28827 and #28827.

However, because most apps run their own minification step on their npm
dependencies, it's not necessary for us to minify the symbols before
publishing — it'll be handled the app, if desired.

This is the same strategy Meta has used to ship React for years. The
React build itself has unminified symbols, but they get minified as part
of Meta's regular build pipeline.

Even if an app does not minify their npm dependencies, gzip covers most
of the cost of symbol renaming anyway.

This saves us from having to ship sourcemaps, which means even apps that
don't have sourcemaps configured will be able to debug the React build
as easily as they would any other npm dependency.
2024-04-20 11:23:46 -04:00
Joe Savona
c98c02f8e6 InferReferenceEffects propagates context effects with precise locations
ghstack-source-id: f9517b98013613a3a80a78b4a6110006ee8b4de7
Pull Request resolved: https://github.com/facebook/react-forget/pull/2880
2024-04-19 19:03:01 -07:00
Joe Savona
f7a643c7b2 Add ContextMutation variant of FunctionEffect
ghstack-source-id: f3da80ed22acd916db0cecad9f2b80ba4c01c6eb
Pull Request resolved: https://github.com/facebook/react-forget/pull/2879
2024-04-19 17:44:08 -07:00
Joe Savona
12f314fa98 Extend ValueReason w context identifiers
ghstack-source-id: 5157b988b0ff15299d585aa906831c1d640f6a40
Pull Request resolved: https://github.com/facebook/react-forget/pull/2878
2024-04-19 17:44:04 -07:00
Andrew Clark
ea26e38e33 [Experiment] Reuse memo cache after interruption (#28878)
Adds an experimental feature flag to the implementation of useMemoCache,
the internal cache used by the React Compiler (Forget).

When enabled, instead of treating the cache as copy-on-write, like we do
with fibers, we share the same cache instance across all render
attempts, even if the component is interrupted before it commits.

If an update is interrupted, either because it suspended or because of
another update, we can reuse the memoized computations from the previous
attempt. We can do this because the React Compiler performs atomic
writes to the memo cache, i.e. it will not record the inputs to a
memoization without also recording its output.

This gives us a form of "resuming" within components and hooks.

This only works when updating a component that already mounted. It has
no impact during initial render, because the memo cache is stored on the
fiber, and since we have not implemented resuming for fibers, it's
always a fresh memo cache, anyway.

However, this alone is pretty useful — it happens whenever you update
the UI with fresh data after a mutation/action, which is extremely
common in a Suspense-driven (e.g. RSC or Relay) app.

So the impact of this feature is faster data mutations/actions (when the
React Compiler is used).
2024-04-19 19:30:01 -04:00
Joe Savona
9f9f4a9f11 Fix gating mode hoisting check to skip type references
ghstack-source-id: f83e9e28c1cdf31dba718e62db12aaa3a5f9ddab
Pull Request resolved: https://github.com/facebook/react-forget/pull/2876
2024-04-19 15:16:19 -07:00
Joe Savona
07ba52bc1a Repro for false positive gating mode hoisting check
ghstack-source-id: c4f5777b85751e9d5f0323384160adfba55d883f
Pull Request resolved: https://github.com/facebook/react-forget/pull/2875
2024-04-19 15:16:15 -07:00
Sebastian Markbåge
446aa9a632 Build react-reconciler for FB builds (#28880)
Meta uses various tools built on top of the "react-reconciler" package
but that package needs to match the version of the "react" package.

This means that it should be synced at the same time. However, more than
that the feature flags between the "react" package and the
"react-reconciler" package needs to line up. Since FB has custom feature
flags, it can't use the OSS version of react-reconciler.
2024-04-19 18:06:01 -04:00
Andrew Clark
0e0b69321a Run Closure on non-minified prod builds, too (#28827)
In #26446 we started publishing non-minified versions of our production
build artifacts, along with source maps, for easier debugging of React
when running in production mode.

The way it's currently set up is that these builds are generated
*before* Closure compiler has run. Which means it's missing many of the
optimizations that are in the final build, like dead code elimination.

This PR changes the build process to run Closure on the non-minified
production builds, too, by moving the sourcemap generation to later in
the pipeline.

The non-minified builds will still preserve the original symbol names,
and we'll use Prettier to add back whitespace. This is the exact same
approach we've been using for years to generate production builds for
Meta.

The idea is that the only difference between the minified and non-
minified builds is whitespace and symbol mangling. The semantic
structure of the program should be identical.

To implement this, I disabled symbol mangling when running Closure
compiler. Then, in a later step, the symbols are mangled by Terser. This
is when the source maps are generated.
2024-04-19 14:22:38 -04:00
Jan Kassens
f5ce642dee Revert "Support writing to this.refs from userspace" (#28877)
Reverts facebook/react#28867

It broke some tests, reverting until we figure out why to avoid having
too much delay in the sync.
2024-04-19 12:35:06 -04:00
Josh Story
33a32441e9 Remove renderToStaticNodeStream (#28873)
Stacked on #28872 

renderToStaticNodeStream was not originally deprecated when
renderToNodeStream was deprecated because it did not yet have a clear
analog in the modern streaming implementation for SSR. In React 19 we
have already removed renderToNodeStream. This change removes
renderToStaticNodeStream as well because you can replicate it's
semantics using renderToPipeableStream with onAllReady or
renderToReadableStream with await stream.allready.
2024-04-18 21:06:04 -07:00
Josh Story
d329ff9d9e Deprecate renderToStaticNodeStream (#28872)
This commit adds warnings indicating that `renderToStaticNodeStream`
will be removed in an upcoming React release. This API has been legacy,
is not widely used (renderToStaticMarkup is more common) and has
semantically eqiuvalent implementations with renderToReadableStream and
renderToPipeableStream.
2024-04-18 18:33:53 -07:00
Josh Story
561c023708 [Fizz] escape <script> textContent similar to bootstrapScript (#28871)
stacked on #28870 

inline script children have been encoded as HTML for a while now but
this can easily break script parsing so practically if you were
rendering inline scripts you were using dangerouslySetInnerHTML. This is
not great because now there is no escaping at all so you have to be even
more careful. While care should always be taken when rendering untrusted
script content driving users to use dangerous APIs is not the right
approach and in this PR the escaping functionality used for
bootstrapScripts and importMaps is being extended to any inline script.

the approach is to escape 's' or 'S" with the appropriate unicode code
point if it is inside a <script or </script sequence. This has the nice
benefit of minimally escaping the text for readability while still
preserving full js parsing capabilities. As articulated when we
introduced this escaping for prior use cases this is only safe because
we are escaping the entire script content. It would be unsafe if we were
not escaping the entirety of the script because we would no longer be
able to ensure there are no earlier or later <script sequences that put
the parser in unexpected states.
2024-04-18 17:38:43 -07:00
Josh Story
aead514db2 [Fizz] escape <style> textContent as css (#28870)
style text content has historically been escaped as HTML which is
non-sensical and often leads users to using dangerouslySetInnerHTML as a
matter of course. While rendering untrusted style rules is a security
risk React doesn't really provide any special protection here and
forcing users to use a completely unescaped API is if anything worse. So
this PR updates the style escaping rules for Fizz to only escape the
text content to ensure the tag scope cannot be closed early. This is
accomplished by encoding "s" and "S" as hexadecimal unicode
representation "\73 " and "\53 " respectively when found within a
sequence like </style>. We have to be careful to support casing here
just like with the script closing tag regex for bootstrap scripts.
2024-04-18 17:24:27 -07:00
Jan Kassens
4c34a7ffc5 Add missing bundle types for ReactCacheOld (#28860)
Add missing bundle types for ReactCacheOld

These are used at FB and we need to update them for the SecretInternals
update.
2024-04-18 17:26:03 -04:00
Jason Bonta
92f5c3ac7b [Devtools] Rename Forget badge (#28858)
## Summary

The Forget codename needs to be hidden from the UI to avoid confusion.
Going forward, we'll be referring to this set of features as part of the
larger React compiler. We'll be describing the primary feature that
we've built so far as auto-memoization, and this badge helps devs see
which components have been automatically memoized by the compiler.

## How did you test this change?

- force Forget badge on with and without the presence of other badges
- confirm colors/UI in light and dark modes
- force badges on for `ElementBadges`, `InspectableElementBadges`,
`IndexableElementBadges`
- Running yarn start in packages/react-devtools-shell

[demo
video](https://github.com/facebook/react/assets/973058/fa829018-7644-4425-8395-c5cd84691f3c)
2024-04-18 13:55:53 -07:00
Joe Savona
a78da09640 Move global reassignment validation to InferReferenceEffects
ghstack-source-id: fcda8140310d6e1201df35f399020b22b6dccb08
Pull Request resolved: https://github.com/facebook/react-forget/pull/2872
2024-04-18 13:51:47 -07:00
Jan Kassens
1cd77a4ff7 Remove ReactFlightFB bundles (#28864)
Remove ReactFlightFB bundles
2024-04-18 16:41:04 -04:00
Joe Savona
d870c979a1 Add StoreGlobal instruction
ghstack-source-id: a715b1385da6648d867118d2b7486ffdb0ff89f6
Pull Request resolved: https://github.com/facebook/react-forget/pull/2871
2024-04-18 13:21:31 -07:00
Jon Janzen
1f0701c11e Write Diff Train import branch to this repo (#28869)
For fbsource we've historically used a separate repo for imports due to
internal limitations in Diff Train. Those have been lifted so we can now
commit this branch here and then we can import from this repo (and get
rid of the other repo)
2024-04-18 12:08:52 -07:00
Joe Savona
682f5a920a [dx] Update capitalized call error messages
ghstack-source-id: dbc012018ecc73007dfb3e745615605512ab6867
Pull Request resolved: https://github.com/facebook/react-forget/pull/2870
2024-04-18 11:07:10 -07:00
Andrew Clark
ea24427d16 Support writing to this.refs from userspace (#28867)
Previously, the `refs` property of a class component instance was
read-only by user code — only React could write to it, and until/unless
a string ref was used, it pointed to a shared empty object that was
frozen in dev to prevent userspace mutations.

Because string refs are deprecated, we want users to be able to codemod
all their string refs to callback refs. The safest way to do this is to
output a callback ref that assigns to `this.refs`.

So to support this, we need to make `this.refs` writable by userspace.
2024-04-18 13:37:54 -04:00
Joe Savona
a9732d65b4 [dx] Improve error messages for unpreserved memoization
ghstack-source-id: ff5bcaa7ab219035f57dc3dc3396c9a324896d4b
Pull Request resolved: https://github.com/facebook/react-forget/pull/2869
2024-04-18 09:49:27 -07:00
Dmytro Rykun
0061ca6cf4 Add early return to diffProperties (#28842)
## Summary

This PR adds early return to the `diff` function. We don't need to go
through all the entries of `nextProps`, process and deep-diff the values
if `nextProps` is the same object as `prevProps`. Roughly 6% of all
`diffProperties` calls can be skipped.

## How did you test this change?

RNTester.
2024-04-18 17:24:07 +01:00
Joe Savona
da6c4612a3 [dx] Consistently use backticks for quoting input in error messages
ghstack-source-id: 34e5507c08fb883c987c88f415158fac781a5f8e
Pull Request resolved: https://github.com/facebook/react-forget/pull/2863
2024-04-18 09:21:24 -07:00
Joe Savona
e3d0f4bce8 [dx] Update NoRefAccessInRender error messages
ghstack-source-id: a5623aa4f29e15c89d2dfbe855bab9843e240a8a
Pull Request resolved: https://github.com/facebook/react-forget/pull/2862
2024-04-18 09:21:23 -07:00
Joe Savona
8c8bd00c04 [dx] Update error messages for manual memo validation
ghstack-source-id: 1a88145049d7f7acb01748ad6ec4dd1500781766
Pull Request resolved: https://github.com/facebook/react-forget/pull/2861
2024-04-18 09:21:22 -07:00
zhangenming
36e62c6034 delete useless eslint-disable-next-line (#28859)
<!--
  Thanks for submitting a pull request!
We appreciate you spending the time to work on these changes. Please
provide enough information so that others can review your pull request.
The three fields below are mandatory.

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

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

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

## Summary

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

## How did you test this change?

<!--
Demonstrate the code is solid. Example: The exact commands you ran and
their output, screenshots / videos if the pull request changes the user
interface.
How exactly did you verify that your PR solves the issue you wanted to
solve?
  If you leave this empty, your PR will very likely be closed.
-->
2024-04-18 11:49:55 -04:00
Joe Savona
c84ff16afb [dx] Update error message for reassigning globals
ghstack-source-id: 48ce4b55a8b4b5a22c8ec29f6787732ab2a67778
Pull Request resolved: https://github.com/facebook/react-forget/pull/2860
2024-04-18 07:46:22 -07:00
Ricky
4fdbac075f Revert "convert circleci workflow devtools_regression_tests to github actions" (#28865)
Reverts facebook/react#27800, tests fail on main
2024-04-18 10:18:53 -04:00
Rob Anderson
496e8733bb convert circleci workflow devtools_regression_tests to github actions (#27800)
## Summary

This pull request converts the CircleCI workflows to GitHub actions
workflows. [Github Actions
Importer](https://github.com/github/gh-actions-importer) was used to
convert the workflows initially, then I edited them manually to correct
errors in translation.

**Issues**
1. facebook/react/devtools_regression_tests  
The scripts that this workflow calls need to be modified.

## How did you test this change?

I tested these changes in a forked repo. You can [view the logs of this
workflow in my fork](https://github.com/robandpdx/react/actions).

https://fburl.com/workplace/f6mz6tmw
2024-04-18 15:04:27 +01:00
Joe Savona
87993f333a [dx] Update suppression error messages
ghstack-source-id: 0c362a349de86a07b4e9e381b942939ce4a24e69
Pull Request resolved: https://github.com/facebook/react-forget/pull/2859
2024-04-17 18:25:40 -07:00
Joe Savona
4666bf8c17 [dx] Improve BuildHIR error messages
ghstack-source-id: cbf62aec4e768249a8c7f44fe6f3852183127415
Pull Request resolved: https://github.com/facebook/react-forget/pull/2858
2024-04-17 18:16:33 -07:00
Joe Savona
fc7467ac0e [dx] Update error messages for config parsing
ghstack-source-id: 693a3526a73f1fbd25f4e59416f8c65a0f8f1235
Pull Request resolved: https://github.com/facebook/react-forget/pull/2857
2024-04-17 18:16:32 -07:00
Ricky
b5e5ce8e0a Update ReactNativeTypes for root options (part 2) (#28857)
Forgot to push a change before mergin
https://github.com/facebook/react/pull/28850
2024-04-17 14:56:43 -04:00
Josh Story
da6ba53b10 [UMD] Remove umd builds (#28735)
In React 19 React will finally stop publishing UMD builds. This is
motivated primarily by the lack of use of UMD format and the added
complexity of maintaining build infra for these releases. Additionally
with ESM becoming more prevalent in browsers and services like esm.sh
which can host React as an ESM module there are other options for doing
script tag based react loading.

This PR removes all the UMD build configs and forks.

There are some fixtures that still have references to UMD builds however
many of them already do not work (for instance they are using legacy
features like ReactDOM.render) and rather than block the removal on
these fixtures being brought up to date we'll just move forward and fix
or removes fixtures as necessary in the future.
2024-04-17 11:15:27 -07:00
Sebastian Silbermann
0c245df1dc Complete the typo fix (#28856) 2024-04-17 20:04:22 +02:00
Andrew Clark
f82051d7ab console test utils fix: match entire string, not just first letter (#28855)
Fixes issue where if the first letter of the expected string appeared
anywhere in actual message, the assertion would pass, leading to false
negatives. We should check the entire expected string.

---------

Co-authored-by: Ricky <rickhanlonii@gmail.com>
2024-04-17 13:04:54 -04:00
Sebastian Markbåge
4ca20fd36b Test top level fragment inside lazy semantics (#28852)
This wasn't clearly articulated and tested why the code structure is
like this but I think the logic is correct - or at least consistent with
the weird semantics.

We place this top-level fragment check inside the recursion so that you
can resolve how many every Lazy or Usable wrappers you want and it still
preserves the same semantics if they weren't there (which they might not
be as a matter of a race condition).

However, we don't actually recurse with the top-level fragment
unwrapping itself because nesting a bunch of keyless fragments isn't the
same as a single fragment/element.
2024-04-17 12:37:51 -04:00
Sebastian Markbåge
c0cf7c696c Promote ASYNC_ITERATOR symbol to React Symbols (#28851)
So that when we end up referring to it in more places, it's only one.

We don't do this same pattern for regular `Symbol.iterator` because we
also support the string `"@@iterator"` for backwards compatibility.
2024-04-17 12:29:08 -04:00
Ricky
657428a9e9 Add ReactNativeTypes for root options (#28850)
Flow should have failed for this but didn't, we need these options
sync'd over in the types too.
2024-04-16 21:18:16 -04:00
Sebastian Markbåge
7909d8eabb [Flight] Encode ReadableStream and AsyncIterables (#28847)
This adds support in Flight for serializing four kinds of streams:

- `ReadableStream` with objects as a model. This is a single shot
iterator so you can read it only once. It can contain any value
including Server Components. Chunks are encoded as is so if you send in
10 typed arrays, you get the same typed arrays out on the other side.
- Binary `ReadableStream` with `type: 'bytes'` option. This supports the
BYOB protocol. In this mode, the receiving side just gets `Uint8Array`s
and they can be split across any single byte boundary into arbitrary
chunks.
- `AsyncIterable` where the `AsyncIterator` function is different than
the `AsyncIterable` itself. In this case we assume that this might be a
multi-shot iterable and so we buffer its value and you can iterate it
multiple times on the other side. We support the `return` value as a
value in the single completion slot, but you can't pass values in
`next()`. If you want single-shot, return the AsyncIterator instead.
- `AsyncIterator`. These gets serialized as a single-shot as it's just
an iterator.

`AsyncIterable`/`AsyncIterator` yield Promises that are instrumented
with our `.status`/`.value` convention so that they can be synchronously
looped over if available. They are also lazily parsed upon read.

We can't do this with `ReadableStream` because we use the native
implementation of `ReadableStream` which owns the promises.

The format is a leading row that indicates which type of stream it is.
Then a new row with the same ID is emitted for every chunk. Followed by
either an error or close row.

`AsyncIterable`s can also be returned as children of Server Components
and then they're conceptually the same as fragment arrays/iterables.
They can't actually be used as children in Fizz/Fiber but there's a
separate plan for that. Only `AsyncIterable` not `AsyncIterator` will be
valid as children - just like sync `Iterable` is already supported but
single-shot `Iterator` is not. Notably, neither of these streams
represent updates over time to a value. They represent multiple values
in a list.

When the server stream is aborted we also close the underlying stream.
However, closing a stream on the client, doesn't close the underlying
stream.

A couple of possible follow ups I'm not planning on doing right now:

- [ ] Free memory by releasing the buffer if an Iterator has been
exhausted. Single shots could be optimized further to release individual
items as you go.
- [ ] We could clean up the underlying stream if the only pending data
that's still flowing is from streams and all the streams have cleaned
up. It's not very reliable though. It's better to do cancellation for
the whole stream - e.g. at the framework level.
- [ ] Implement smarter Binary Stream chunk handling. Currently we wait
until we've received a whole row for binary chunks and copy them into
consecutive memory. We need this to preserve semantics when passing
typed arrays. However, for binary streams we don't need that. We can
just send whatever pieces we have so far.
2024-04-16 12:20:07 -04:00
Andrew Clark
13eb61d056 Move enableUseDeferredValueInitialArg to canary (#28818)
Per team discussion, this upgrades the `initialValue` argument for
`useDeferredValue` from experimental to canary.

- Original implementation PR:
https://github.com/facebook/react/pull/27500
- API documentation PR: https://github.com/reactjs/react.dev/pull/6747

I left it disabled at Meta for now in case there's old code somewhere
that is still passing an `options` object as the second argument.
2024-04-16 12:12:32 -04:00
Jan Kassens
8afa144bdc Enable flag disableClientCache (#28846)
Enable flag disableClientCache

Forcing a `__VARIANT__` in the mock file so we keep testing this until
fully removing it.
2024-04-16 10:59:36 -04:00
Sathya Gunsasekaran
6bf64df538 [babel] Add a sources option
This allows the plugin to be configured to run on an allowlist, rather
than compiling all files helping with an incremental rollout plan.

The sources option takes both an array of path strings or a function
to be flexible.

For now I've left this be optional but we can make it required.

ghstack-source-id: 282a33dc8d08d47f699894692e0fcc813dff5b77
Pull Request resolved: https://github.com/facebook/react-forget/pull/2855
2024-04-16 14:41:16 +01:00
Sathya Gunsasekaran
5bceb3cb3b [.gitignore] Add bundle script
No need to commit this in the repo, but keeping this locally helps with
building the feedback repo.

ghstack-source-id: 28f08992b1ab856567a5338af07e12ac820a7298
Pull Request resolved: https://github.com/facebook/react-forget/pull/2854
2024-04-16 14:41:13 +01:00
Sebastian Silbermann
734956ace6 Devtools: Add support for useFormStatus (#28413) 2024-04-16 10:28:16 +02:00
Sebastian Silbermann
8f212cc789 Ensure sizebot doesn't swallow large diffs (#28845) 2024-04-16 09:56:25 +02:00
Sebastian Markbåge
17e920c00d [Flight Reply] Encode Typed Arrays and Blobs (#28819)
With the enableBinaryFlight flag on we should encode typed arrays and
blobs in the Reply direction too for parity.

It's already possible to pass Blobs inside FormData but you should be
able to pass them inside objects too.

We encode typed arrays as blobs and then unwrap them automatically to
the right typed array type.

Unlike the other protocol, I encode the type as a reference tag instead
of row tag. Therefore I need to rename the tags to avoid conflicts with
other tags in references. We are running out of characters though.
2024-04-15 22:32:08 -04:00
Ricky
fd35655fae Delete AUTHORS.md (#28844)
This hasn't been updated in a long time, and it getting really large. 

You can view the authors locally via the git history with:

``
git shortlog -se | perl -spe 's/^\s+\d+\s+//'
``
2024-04-15 15:23:30 -04:00
Ricky
0347fcd007 Add on(Caught|Uncaught|Recoverable) opts to RN (#28836)
## Overview

There's currently a bug in RN now that we no longer re-throw errors. The
`showErrorDialog` function in React Native only logs the errors as soft
errors, and never a fatal. RN was depending on the global handler for
the fatal error handling and logging.

Instead of fixing this in `ReactFiberErrorDialog`, we can implement the
new root options in RN to handle caught/uncaught/recoverable in the
respective functions, and delete ReactFiberErrorDialog. I'll follow up
with a RN PR to implement these options and fix the error handling.
2024-04-15 12:03:28 -04:00
Kenta Iwasaki
c113503ad1 Flush direct streams in Bun (#28837)
<!--
  Thanks for submitting a pull request!
We appreciate you spending the time to work on these changes. Please
provide enough information so that others can review your pull request.
The three fields below are mandatory.

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

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

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

## Summary

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

The ReadableStreamController for [direct
streams](https://bun.sh/docs/api/streams#direct-readablestream) in Bun
supports a flush() method to flush all buffered items to its underlying
sink.

Without manually calling flush(), all buffered items are only flushed to
the underlying sink when the stream is closed. This behavior causes the
shell rendered against Suspense boundaries never to be flushed to the
underlying sink.

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

A lot of changes to the test runner will need to be made in order to
support the Bun runtime. A separate test was manually run in order to
ensure that the changes made are correct.

The test works by sanity-checking that the shell rendered against
Suspense boundaries are emitted first in the stream.

This test was written and run on Bun v1.1.3.

```ts
import { Suspense } from "react";
import { renderToReadableStream } from "react-dom/server";

if (!import.meta.resolveSync("react-dom/server").endsWith("server.bun.js")) {
  throw new Error("react-dom/server is not the correct version:\n  " + import.meta.resolveSync("react-dom/server"));
}

const A = async () => {
  await new Promise(resolve => setImmediate(resolve));
  return <div>hi</div>;
};

const B = async () => {
  return (
    <Suspense fallback={<div>loading</div>}>
      <A />
    </Suspense>
  );
};

const stream = await renderToReadableStream(<B />);

let text = "";
let count = 0;
for await (const chunk of stream) {
  text += new TextDecoder().decode(chunk);
  count++;
}

if (
  text !==
  `<!--$?--><template id="B:0"></template><div>loading</div><!--/$--><div hidden id="S:0"><div>hi</div></div><script>$RC=function(b,c,e){c=document.getElementById(c);c.parentNode.removeChild(c);var a=document.getElementById(b);if(a){b=a.previousSibling;if(e)b.data="$!",a.setAttribute("data-dgst",e);else{e=b.parentNode;a=b.nextSibling;var f=0;do{if(a&&8===a.nodeType){var d=a.data;if("/$"===d)if(0===f)break;else f--;else"$"!==d&&"$?"!==d&&"$!"!==d||f++}d=a.nextSibling;e.removeChild(a);a=d}while(a);for(;c.firstChild;)e.insertBefore(c.firstChild,a);b.data="$"}b._reactRetry&&b._reactRetry()}};$RC("B:0","S:0")</script>`
) {
  throw new Error("unexpected output");
}
if (count !== 2) {
  throw new Error("expected 2 chunks from react ssr stream");
}
```
2024-04-15 11:25:08 -04:00
Sathya Gunsasekaran
b28bb19e44 [codegen] Don't drop directives in simple arrow fn
The compiler has an optimisation where it transforms a simple arrow
function with only a return statement to a implicit arrow function.

In the case, there's a directive in this simple arrow function, the
directive gets dropped.

Instead of dropping the directive, the compiler should perform this
optimisation only if there are no directives.

ghstack-source-id: 514cd2440025986a2d6d950694a7339d779b09f2
Pull Request resolved: https://github.com/facebook/react-forget/pull/2848
2024-04-15 15:52:45 +01:00
Ruslan Lesiutin
2d128ff041 React DevTools 5.0.2 -> 5.1.0 (#28840)
Full list of changes:
* Look for a ReactMemoCacheSentinel on state
([gsathya](https://github.com/gsathya) in
[#28831](https://github.com/facebook/react/pull/28831))
* Use use() in the Cache if available
([sebmarkbage](https://github.com/sebmarkbage) in
[#28793](https://github.com/facebook/react/pull/28793))
* feat[devtools-fusebox]: support theme option
([hoxyq](https://github.com/hoxyq) in
[#28832](https://github.com/facebook/react/pull/28832))
* feat[devtools]: add package for fusebox integration
([hoxyq](https://github.com/hoxyq) in
[#28553](https://github.com/facebook/react/pull/28553))
* feat[devtools]: add method for connecting backend with custom
messaging protocol ([hoxyq](https://github.com/hoxyq) in
[#28552](https://github.com/facebook/react/pull/28552))
* Rename SECRET INTERNALS to
`__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE`
([sebmarkbage](https://github.com/sebmarkbage) in
[#28789](https://github.com/facebook/react/pull/28789))
* Flatten ReactSharedInternals
([sebmarkbage](https://github.com/sebmarkbage) in
[#28783](https://github.com/facebook/react/pull/28783))
* feat[devtools]: ship source maps for content scripts and ignore list
installHook script ([hoxyq](https://github.com/hoxyq) in
[#28730](https://github.com/facebook/react/pull/28730))
* Track Owner for Server Components in DEV
([sebmarkbage](https://github.com/sebmarkbage) in
[#28753](https://github.com/facebook/react/pull/28753))
* Move ReactDOMLegacy implementation into RootFB
([sebmarkbage](https://github.com/sebmarkbage) in
[#28656](https://github.com/facebook/react/pull/28656))
* Reland #28672: Remove IndeterminateComponent
([gnoff](https://github.com/gnoff) in
[#28681](https://github.com/facebook/react/pull/28681))
* Remove reference to deleted <Cache> in un-linted file
([josephsavona](https://github.com/josephsavona) in
[#28715](https://github.com/facebook/react/pull/28715))
* [be] Remove unshipped experimental <Cache> element type
([josephsavona](https://github.com/josephsavona) in
[#28698](https://github.com/facebook/react/pull/28698))
* Revert "Remove module pattern function component support"
([rickhanlonii](https://github.com/rickhanlonii) in
[#28670](https://github.com/facebook/react/pull/28670))
* Remove module pattern function component support
([gnoff](https://github.com/gnoff) in
[#27742](https://github.com/facebook/react/pull/27742))
* [RTR] Enable warning flag ([jackpope](https://github.com/jackpope) in
[#28419](https://github.com/facebook/react/pull/28419))
* Update error messages ([rickhanlonii](https://github.com/rickhanlonii)
in [#28652](https://github.com/facebook/react/pull/28652))
* fix[devtools/ci]: split profiling cache test for different react
versions and toEqual checker ([hoxyq](https://github.com/hoxyq) in
[#28628](https://github.com/facebook/react/pull/28628))
* Guard against legacy context not being supported in DevTools fixture
([eps1lon](https://github.com/eps1lon) in
[#28596](https://github.com/facebook/react/pull/28596))
* Use `declare const` instead of `declare var`
([kassens](https://github.com/kassens) in
[#28599](https://github.com/facebook/react/pull/28599))
* Update isConcurrent RTR option usage
([jackpope](https://github.com/jackpope) in
[#28546](https://github.com/facebook/react/pull/28546))
* Disable legacy context ([kassens](https://github.com/kassens) in
[#27991](https://github.com/facebook/react/pull/27991))
* Remove invokeGuardedCallback and replay trick
([sebmarkbage](https://github.com/sebmarkbage) in
[#28515](https://github.com/facebook/react/pull/28515))
* Remove remaining usages of ReactTestUtils in tests unrelated to
`react-dom/test-util` ([eps1lon](https://github.com/eps1lon) in
[#28534](https://github.com/facebook/react/pull/28534))
* fix[devtools/e2e]: fixed source inspection in e2e tests
([hoxyq](https://github.com/hoxyq) in
[#28518](https://github.com/facebook/react/pull/28518))
* Devtools: Display actual pending state when inspecting `useTransition`
([eps1lon](https://github.com/eps1lon) in
[#28499](https://github.com/facebook/react/pull/28499))
2024-04-15 14:56:57 +01:00
Sathya Gunasekaran
d486051de7 [Devtools] Look for a ReactMemoCacheSentinel on state (#28831)
The useMemoCache polyfill doesn't have access to the fiber, and it
simply uses state, which does not work with the existing devtools 
badge for the compiler.

With this PR, devtools will look on the very first hook's state for the
memo cache sentinel and display the Forget badge if present.

The polyfill will add this sentinel to it's state (the cache array).
2024-04-15 13:05:05 +01:00
Sebastian Markbåge
1683cb186c Use use() in the Cache if available (#28793)
This is a follow up to
https://github.com/facebook/react/pull/28789#discussion_r1557232202

Revert to use the old readContext detection if not to support older
React.

I haven't actually tested this. Just opening as a suggestion.
2024-04-15 13:03:29 +01:00
Sebastian Silbermann
9defcd56bc Remove redundant props assign (#28829) 2024-04-12 21:55:51 +02:00
Sebastian Markbåge
ed40236036 Fix mistaken "react-server" condition (#28835)
This is a Fizz server.
2024-04-12 15:53:41 -04:00
Josh Story
ba1a9797ee Remove flight-browser fixture (#28828)
The flight-browser fixtures doesn't make sense. It also uses UMD builds
which are being removed so we'd have to make it use esm.sh or something
and really it just won't work because it needs to be built by webpack to
not error. We could potentially shim the webpack globals but really the
right thing is to publish the esm version of react-server and use esm.sh
to load a browser only esm demo of react-server. This change removes the
flight-browser fixture
2024-04-12 09:48:40 -07:00
Ruslan Lesiutin
7625f0d501 feat[devtools-fusebox]: support theme option (#28832)
Support propagating theme from Chrome DevTools frontend, the field is
optional.

Next step, which is out of scope of this project and general improvement
for React DevTools: teach RDT to listen to theme changes and if the
theme preference is set to `auto` in settings, update the theme
accordingly with the browser devtools.
2024-04-12 17:26:37 +01:00
Sathya Gunsasekaran
441024318c [polyfill] Add sentinel to array
To make the polyfill work well with devtools, we add this sentinel.

Devtools will look for this sentinel before adding the Forget badge.

ghstack-source-id: d246040f67da48fa46f818753c8bf26dff56f390
Pull Request resolved: https://github.com/facebook/react-forget/pull/2847
2024-04-12 15:32:12 +01:00
Ruslan Lesiutin
96c5846610 feat[devtools]: add package for fusebox integration (#28553)
## Summary

Stacked on https://github.com/facebook/react/pull/28552. Review only the
[last commit at the
top](c69952f1bf).

These changes add new package `react-devtools-fusebox`, which is the
entrypoint for the RDT Frontend, which will be used in Chrome DevTools
panel. The main differences from other frontend shells (extension,
standalone) are:
1. This package builds scripts in ESM format, this is required by Chrome
DevTools, see webpack config:

c69952f1bf/packages/react-devtools-fusebox/webpack.config.frontend.js (L50-L52)
2. The build includes styles in a separate `.css` file, which is
required for Chrome DevTools: styles are loaded lazily once panel is
mounted.
2024-04-12 15:29:35 +01:00
Ruslan Lesiutin
d012a32f84 feat[devtools]: add method for connecting backend with custom messaging protocol (#28552)
## Summary

RDT backend will now expose method `connectWithCustomMessagingProtocol`,
which will be similar to the classic `connectToDevTools` one, but with
few differences:
1. It delegates the communication management between frontend and
backend to the owner (whos injecting RDT backend). Unlike the
`connectToDevTools`, which is relying on websocket connection and
receives host and port as an arguments.
2. It returns a callback, which can be used for unsubscribing the
current backend instance from the global DevTools hook.


This is a prerequisite for any non-browser RDT integration, which is not
designed to be based on websocket.
2024-04-12 15:17:07 +01:00
Josh Story
c8a035036d [Fizz] hoistables should never flush before the preamble (#28802)
Hoistables should never flush before the preamble however there is a
surprisingly easy way to trigger this to happen by suspending in the
shell of the app. This change modifies the flushing behavior to not emit
any hoistables before the preamble has written. It accomplishes this by
aborting the flush early if there are any pending root tasks remaining.
It's unfortunate we need this extra condition but it's essential that we
don't emit anything before the preamble and at the moment I don't see a
way to do that without introducing a new condition.

There is a test that began to fail with this update. It turns out that
in node the root can be blocked during a resume even for a component
inside a Suspense boundary if that boundary was part of the prerender.
This means that with the current heuristic in this PR boundaries cannot
be flushed during resume until the root is unblocked. This is not ideal
but this is already how Edge works because the root blocks the stream in
that case. This just makes Node deopt in a similar way to edge. We
should improve this but we ought to do so in a way that works for edge
too and it needs to be more comprehensive.
2024-04-11 15:13:04 -07:00
Sebastian Silbermann
4f5c812a3c DevTools: Rely on sourcemaps to compute hook name of built-in hooks in newer versions (#28593) 2024-04-11 22:00:54 +02:00
Jack Pope
4354159623 Backwards compatibility for string refs on WWW (#28826)
Seeing errors with undefined string ref values when trying to sync
https://github.com/facebook/react/pull/28473

Added a test that reproduces the failing pattern.

@acdlite pushed
a786481ae5
with fix

---------

Co-authored-by: Jack Pope <jackpope@meta.com>
Co-authored-by: Andrew Clark <git@andrewclark.io>
2024-04-11 15:30:37 -04:00
Sebastian Silbermann
adb7173938 Fix nightly release job for real (#28825) 2024-04-11 18:28:10 +02:00
Sebastian Silbermann
a2582074b8 Fix nightly release job (#28824) 2024-04-11 18:08:13 +02:00
Ricky
608edcc90a [tests] add assertConsole<method>Dev helpers (#28732)
## Overview
**Internal React repo tests only**

Depends on https://github.com/facebook/react/pull/28710

Adds three new assertions:
- `assertConsoleLogDev`
- `assertConsoleWarnDev`
- `assertConsoleErrorDev`

These will replace this pattern:

```js
await expect(async () => {
  await expect(async () => {
    await act(() => {
      root.render(<Fail />)
    });
  }).toThrow();
}).toWarnDev('Warning');
```

With this:

```js
await expect(async () => {
  await act(() => {
    root.render(<Fail />)
  });
}).toThrow();

assertConsoleWarnDev('Warning');
```

It works similar to our other `assertLog` matchers which clear the log
and assert on it, failing the tests if the log is not asserted before
the test ends.

## Diffs

There are a few improvements I also added including better log diffs and
more logging.

When there's a failure, the output will look something like:

<img width="655" alt="Screenshot 2024-04-03 at 11 50 08 AM"
src="https://github.com/facebook/react/assets/2440089/0c4bf1b2-5f63-4204-8af3-09e0c2d752ad">


Check out the test suite for snapshots of all the failures we may log.
2024-04-11 08:19:46 -04:00
Andrew Clark
da69b6af96 ReactDOM.requestFormReset (#28809)
Based on:

- #28808
- #28804 

---

This adds a React DOM method called requestFormReset that schedules a
form reset to occur when the current transition completes.

Internally, it's the same method that's called automatically whenever a
form action is submitted. It only affects uncontrolled form inputs. See
https://github.com/facebook/react/pull/28804 for details.

The reason for the public API is so UI libraries can implement their own
action-based APIs and maintain the form-resetting behavior, something
like this:

```js
function onSubmit(event) {
  // Disable default form submission behavior
  event.preventDefault();
  const form = event.target;
  startTransition(async () => {
    // Request the form to reset once the action
    // has completed
    requestFormReset(form);

    // Call the user-provided action prop
    await action(new FormData(form));
  })
}
```
2024-04-10 16:56:55 -04:00
Andrew Clark
374b5d26c2 Scaffolding for requestFormReset API (#28808)
Based on:

- #28804 

---

This sets adds a new ReactDOM export called requestFormReset, including
setting up the export and creating a method on the internal ReactDOM
dispatcher. It does not yet add any implementation.

Doing this in its own commit for review purposes.

The API itself will be explained in the next PR.
2024-04-10 16:55:15 -04:00
Andrew Clark
41950d14a5 Automatically reset forms after action finishes (#28804)
This updates the behavior of form actions to automatically reset the
form's uncontrolled inputs after the action finishes.

This is a frequent feature request for people using actions and it
aligns the behavior of client-side form submissions more closely with
MPA form submissions.

It has no impact on controlled form inputs. It's the same as if you
called `form.reset()` manually, except React handles the timing of when
the reset happens, which is tricky/impossible to get exactly right in
userspace.

The reset shouldn't happen until the UI has updated with the result of
the action. So, resetting inside the action is too early.

Resetting in `useEffect` is better, but it's later than ideal because
any effects that run before it will observe the state of the form before
it's been reset.

It needs to happen in the mutation phase of the transition. More
specifically, after all the DOM mutations caused by the transition have
been applied. That way the `defaultValue` of the inputs are updated
before the values are reset. The idea is that the `defaultValue`
represents the current, canonical value sent by the server.

Note: this change has no effect on form submissions that aren't
triggered by an action.
2024-04-10 16:54:24 -04:00
Josh Story
dc6a7e01e1 [Float] Don't preload images inside <noscript> (#28815)
`<noscript>` scopes should be considered inert from the perspective of
Fizz since we assume they'll only be used in rare and adverse
circumstances. When we added preload support for img tags we did not
include the noscript scope check in the opt-out for preloading. This
change adds it in

fixes: #27910
2024-04-10 12:15:04 -07:00
Mofei Zhang
d2018c51e1 [playground] Editing input shouldn't toggle diff view
ghstack-source-id: f9e80fc0c928e1ce1ec698d4d952e11402054843
Pull Request resolved: https://github.com/facebook/react-forget/pull/2833
2024-04-10 14:53:38 -04:00
Lauren Tan
c836a0158b Fix usage of renamed React internals
ghstack-source-id: d646c84815c324bd490584d34488a73f5e39d589
Pull Request resolved: https://github.com/facebook/react-forget/pull/2845
2024-04-11 11:10:42 -04:00
Lauren Tan
6e65445911 Fix playground e2e test for real
ghstack-source-id: 1b52cb312a5f26e8e058bfe4a29b586ffaeb25d7
Pull Request resolved: https://github.com/facebook/react-forget/pull/2843
2024-04-11 12:13:59 -04:00
Lauren Tan
ec05176fb3 Make string values for config case-insensitive
Fixes a tiny inconsistency with compiler options where one was all
uppercase and one all lowercase by normalizing to lowercase regardless
of the casing of the user's config.

ghstack-source-id: fe60a3259de89a1b3fdd7475950e16e96cc57f6b
Pull Request resolved: https://github.com/facebook/react-forget/pull/2832
2024-04-11 10:45:35 -04:00
Lauren Tan
9cdd6b243e Fix playground e2e test
ghstack-source-id: 3904ff9beea21ffbb79a6a15fcfbb72f04a2d170
Pull Request resolved: https://github.com/facebook/react-forget/pull/2842
2024-04-10 18:17:38 -04:00
Lauren Tan
200b0f2333 Add aria-label to playground tabs
ghstack-source-id: 1c23bbbb55c1582a03674897b57c5061b895be83
Pull Request resolved: https://github.com/facebook/react-forget/pull/2841
2024-04-10 18:17:37 -04:00
Lauren Tan
f990948a1f Small style tweaks to playground vertical tabs
ghstack-source-id: 56e72c56782274bdac92fdd131d2c9b33eb19052
Pull Request resolved: https://github.com/facebook/react-forget/pull/2840
2024-04-10 18:17:36 -04:00
Lauren Tan
ed3bad0c2f Add aria-label to playground header buttons
ghstack-source-id: 4fdf672f02144e550d50b17f396a5d6d82dab5bd
Pull Request resolved: https://github.com/facebook/react-forget/pull/2839
2024-04-10 18:17:36 -04:00
Lauren Tan
7083231f6d Add link to GitHub repo in playground header
ghstack-source-id: 9fd0c2f8d70f8782602b0e4f8535b6be3ed89782
Pull Request resolved: https://github.com/facebook/react-forget/pull/2838
2024-04-10 18:17:35 -04:00
Lauren Tan
b6c01f7f78 Remove playground wipe button
It was never clear to me what the difference between Wipe and Reset was.
Let's just get rid of one and reset to something more useful instead of
fibonacci.

ghstack-source-id: 4f88a1c1da2d0fd9e1f26e4859c12db0fc961af2
Pull Request resolved: https://github.com/facebook/react-forget/pull/2837
2024-04-10 17:46:35 -04:00
Lauren Tan
9ae3e74c3e Rename references to "forget" in playground
ghstack-source-id: fc2d58e4d5195c3ec157f65b3e1c94de39ff2070
Pull Request resolved: https://github.com/facebook/react-forget/pull/2836
2024-04-10 17:46:35 -04:00
Lauren Tan
594f335201 Show alert when url copied
ghstack-source-id: e8dba44d246d53f60a0858710cedf75c77c6c7e4
Pull Request resolved: https://github.com/facebook/react-forget/pull/2835
2024-04-10 17:46:34 -04:00
Lauren Tan
2f66d37cfd Use lz-string for playground state uri param
This compresses more efficiently than the base64 encoding we were
previously using, which makes sharing URLs a little less unwieldy and
takes up less space in local storage. Using
some real code as an example, lz-string compresses to 8040 bytes,
whereas the original base64 encoding we were using compresses to 16504
bytes

ghstack-source-id: b8f1089889b94b07d6f419606b798ffddb8863ba
Pull Request resolved: https://github.com/facebook/react-forget/pull/2834
2024-04-10 17:46:33 -04:00
Ricky
3f947b1b46 [tests] Assert scheduler log empty in internalAct (#28737)
We should force `assertLog` to be called before each `act` block to
ensure the queue is empty.

Requires fixing tests:
- https://github.com/facebook/react/pull/28745
- https://github.com/facebook/react/pull/28758
- https://github.com/facebook/react/pull/28759
- https://github.com/facebook/react/pull/28760
- https://github.com/facebook/react/pull/28761
- https://github.com/facebook/react/pull/28762
- https://github.com/facebook/react/pull/28763
- https://github.com/facebook/react/pull/28812
2024-04-10 14:13:46 -04:00
Ricky
870e4045ab [tests] add assertLog for legacy mode tests (#28814)
A few more tests for https://github.com/facebook/react/pull/28737
2024-04-10 14:01:59 -04:00
Josh Story
a8a83f7a59 Removes the react-interactions project which is unused (#28799)
Removes the react-interactions project which is unused

This project uses `unstable_createEventHandle` which is being removed
from React in version 19
2024-04-10 09:18:33 -07:00
Ricky
bf09089f64 Remove Scheduler.log from ReactSuspenseFuzz-test (#28812)
These test don't `assertLog` or `waitFor` so we don't need to
`Scheduler.log`. Ideally we would, but since they're fuzzers it's a bit
difficult to know what the expected log is from the helper.

Since this doesn't regress current test behavior, we can improve them
after this to unblock https://github.com/facebook/react/pull/28737
2024-04-10 11:40:22 -04:00
Ricky
84cb3b4cb2 Hardcode disableIEWorkarounds for www (#28811)
This has landed and is true everywhere, but let's keep the flag until it
lands in the stable release.
2024-04-10 11:14:33 -04:00
Ricky
2243b40aba [tests] assertLog before act in useEffectEvent (#28763)
Fixes tests blocking https://github.com/facebook/react/pull/28737
2024-04-10 10:34:34 -04:00
Ricky
dfc64c6e31 [tests] assertLog before act in ReactUse (#28762)
Fixes tests blocking https://github.com/facebook/react/pull/28737
2024-04-10 10:34:27 -04:00
Ricky
b02199d322 [tests] assertLog before act in ReactErrorBoundaries (#28761)
Fixes tests blocking https://github.com/facebook/react/pull/28737
2024-04-10 10:34:19 -04:00
Ricky
6e1e2f2198 [tests] assertLog before act in ReactUpdates (#28760)
Fixes tests blocking https://github.com/facebook/react/pull/28737
2024-04-10 10:34:11 -04:00
Ricky
88df5242d6 [tests] assertLog before act in ReactDOMServerSelectiveHydration (#28759)
Fixes tests blocking https://github.com/facebook/react/pull/28737
2024-04-10 10:34:02 -04:00
Ricky
e36ee763fa [tests] assertLog before act in ReactCompositeComponentState (#28758)
Fixes tests blocking https://github.com/facebook/react/pull/28737
2024-04-10 10:33:51 -04:00
Ricky
42eff4bc78 [tests] Fix assertions not flushed before act (#28745)
Fixes some easy cases blocking
https://github.com/facebook/react/pull/28737, I'll follow up with more
complex/interesting cases in other PRs.
2024-04-10 10:33:41 -04:00
Andrew Clark
ed3c65caf0 Warn if outdated JSX transform is detected (#28781)
We want to warn if we detect that an app is using an outdated JSX
transform. We can't just warn if `createElement` is called because we
still support `createElement` when it's called manually. We only want to
warn if `createElement` is output by the compiler.

The heuristic is to check for a `__self` prop, which is an optional,
internal prop that older transforms used to pass to `createElement` for
better debugging in development mode.

If `__self` is present, we `console.warn` once with advice to upgrade to
the modern JSX transform. Subsequent elements will not warn.

There's a special case we have to account for: when a static "key" prop
is defined _after_ a spread, the modern JSX transform outputs
`createElement` instead of `jsx`. (This is because with `jsx`, a spread
key always takes precedence over a static key, regardless of the order,
whereas `createElement` respects the order.) To avoid a false positive
warning, we skip the warning whenever a `key` prop is present.
2024-04-09 17:13:19 -04:00
Andrew Clark
3f9e237a2f Fix: Suspend while recovering from hydration error (#28800)
Fixes a bug that happens when an error occurs during hydration, React
switches to client rendering, and then the client render suspends. It
works correctly if there's a Suspense boundary on the stack, but not if
it happens in the shell of the app.

Prior to this fix, the app would crash with an "Unknown root exit
status" error.

I left a TODO comment for how we might refactor this code to be less
confusing in the future.
2024-04-09 17:11:46 -04:00
Joseph Savona
64c8d2d45d Attempt to fix diff syncing for Meta (#28801)
#28796 broke Meta's PR syncing tool, hoping this fixes it
2024-04-09 14:05:18 -07:00
Joseph Savona
7f5d25e23e Fix cloneElement using string ref w no owner (#28797)
Fix for an issue introduced in #28473 where cloneElement() with a string
ref fails due to lack of an owner. We should use the current owner in
this case.

---------

Co-authored-by: Rick Hanlon <rickhanlonii@fb.com>
2024-04-09 13:43:49 -07:00
Josh Story
bf40b02442 [Fizz] Stop publishing external-runtime to stable channel (#28796)
The external runtime is not vetted for stability yet. We should stop
publishing it with our stable build
2024-04-09 11:57:58 -07:00
Josh Story
67ff96e12d [Tests][Fizz] Test script runtime even when external runtime is available (#28794)
Previously if the external runtime was enabled Fizz tests would use it
exclusively. However now that this flag is enabled for OSS and Meta
builds this means we were no longer testing the inline script runtime.
This changes the test flags to produce some runs where we test the
inline script runtime and others where we test the external runtime

the external runtime will be tested if the flag is enabled and
* Meta Builds: variant is true
* OSS Builds: experiemental is true

this gives us decent coverage. long term we should probably bring
variant to OSS builds since we will eventually want to test both modes
even when the external runtime is stable.
2024-04-09 11:50:02 -07:00
Josh Story
7f93cb41c8 [DOM] Infer react-server entries bundles if not explicitly configured (#28795)
When packaging we want to infer that a bundle exists for a
`react-server` file even if it isn't explicitly configured. This is
useful in particular for the react-server entrypoints that error on
import that were recently added to `react-dom`

This change also cleans up a wayward comment left behind in a prior PR
2024-04-09 10:39:25 -07:00
Sebastian Markbåge
f613165357 Rename SECRET INTERNALS to __CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE (#28789)
Follow up to #28783 and #28786.

Since we've changed the implementations of these we can rename them to
something a bit more descriptive while we're at it, since anyone
depending on them will need to upgrade their code anyway.

"react" with no condition:
`__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE`
"react" with "react-server" condition:
`__SERVER_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE`
"react-dom":
`__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE`
2024-04-09 12:20:22 -04:00
Sebastian Silbermann
50895bc161 CI: Run with Node.js 18.20 (#28774) 2024-04-09 16:02:22 +02:00
Jan Kassens
cffbcac8e3 Run stale job hourly (#28769) 2024-04-09 09:21:20 -04:00
Ricky
9644d206e8 Soften useFormState warning (#28788)
It's not deprecated, it's really just renamed. Let's make the warning
less scary.
2024-04-08 23:22:17 -04:00
Sebastian Markbåge
c771016e19 Rename The Secret Export of Server Internals (#28786)
We have a different set of dispatchers that Flight uses. This also
includes the `jsx-runtime` which must also be aliased to use the right
version.

To ensure the right versions are used together we rename the export of
the SharedInternals from 'react' and alias it in relevant bundles.
2024-04-08 22:34:59 -04:00
Joe Savona
57d746e3c4 HIR terminal for representing reactive scopes
ghstack-source-id: f7d5b68bc5217555b6060ade3bfa253bb15660ad
Pull Request resolved: https://github.com/facebook/react-forget/pull/2830
2024-04-08 17:43:41 -07:00
Joe Savona
0c6fe1ba35 Cleanup range printing
ghstack-source-id: 42c49348a93921fc03ec5defcf68a364952a3f88
Pull Request resolved: https://github.com/facebook/react-forget/pull/2829
2024-04-08 17:31:35 -07:00
Joe Savona
f707cb5ff3 HIR-based MergeOverlappingScopes
ghstack-source-id: 93ac68114683044d7e6332fe7898b0dcc5dc6685
Pull Request resolved: https://github.com/facebook/react-forget/pull/2828
2024-04-08 17:09:07 -07:00
Sebastian Markbåge
d50323eb84 Flatten ReactSharedInternals (#28783)
This is similar to #28771 but for isomorphic. We need a make over for
these dispatchers anyway so this is the first step. Also helps flush out
some internals usage that will break anyway.

It flattens the inner mutable objects onto the ReactSharedInternals.
2024-04-08 19:23:23 -04:00
Josh Story
acef2f8111 [DOM] Fix package.json files for #28784 (#28785)
Missed some files for the react-server disallow client change in #28784
2024-04-08 15:49:18 -07:00
Josh Story
556a087de3 [DOM] disallow client entrypoints with react-server condition (#28784)
`react-server` precludes loading code that expects to be run in a client
context. This includes react-dom/client react-dom/server
react-dom/unstable_testing react-dom/profiling and react-dom/static

This update makes importing any of these client only entrypoints an
error
2024-04-08 15:37:06 -07:00
Josh Story
f62cf8c620 [Float] treat props.async in Float consistent with the rest of react-dom (#26760)
Treat async (boolean prop) consistently with Float. Previously float
checked if `props.async === true` (or not true) but the rest of
react-dom considers anything truthy that isn't a function or symbol as
`true`. This PR normalizes the Float behavior.
2024-04-08 14:26:58 -07:00
Hugo Sales
dfd3d5af83 Add support for transition{run,start,cancel} events (#27345) 2024-04-08 23:23:04 +02:00
Josh Story
1f8327f834 [Fiber] Use real event priority for hydration scheduling (#28765)
Stacked on #28751 

Historically explicit hydration scheduling used the reconciler's update
priority to schedule the hydration. There was a lingering todo to switch
to using event priority in the absence of an explicit update priority.
This change updates the hydration priority by referring to the event
priority if no update priority is set
2024-04-08 14:05:17 -07:00
Josh Story
97c90ed883 [DOM] Shrink ReactDOMCurrentDispatcher method names (#28770)
Stacked on #28771 

ReactDOMCurrentDispatcher has longer property names for various methods.
These methods are only ever called internally and don't need to be
represented with as many characters. This change shortens the names and
aligns them with the hint codes we use in Flight. This alignment is
passive since not all dispatcher methods will exist as flight
instructions but where they can line up it seems reasonable to make them
do so
2024-04-08 13:54:30 -07:00
Joe Savona
f4fbeb8803 HIR-based AlignReactiveScopesToBlockScopes
ghstack-source-id: ae560a93f24fdbdb4ed73cdd889feb084bb172e5
Pull Request resolved: https://github.com/facebook/react-forget/pull/2822
2024-04-08 13:48:22 -07:00
Josh Story
9007fdc8f1 [DOM] Shrink ReactDOMSharedInternals source representation (#28771)
Stacked on #28751 

ReactDOMSharedInternals uses properties of considerable length to model
mutuable state. These properties are not mangled during minification and
contribute a not insigificant amount to the uncompressed bundle size and
to a lesser degree compressed bundle size.

This change rewrites the DOMInternals in a way that shortens property
names so we can have smaller builds.
It also treats the entire object as a mutable container rather than
having different mutable sub objects.

The same treatment should be given to ReactSharedInternals
2024-04-08 13:39:39 -07:00
Sebastian Markbåge
14f50ad155 [Flight] Allow lazily resolving outlined models (#28780)
We used to assume that outlined models are emitted before the reference
(which was true before Blobs). However, it still wasn't safe to assume
that all the data will be available because an "import" (client
reference) can be async and therefore if it's directly a child of an
outlined model, it won't be able to update in place.

This is a similar problem as the one hit by @unstubbable in #28669 with
elements, but a little different since these don't follow the same way
of wrapping.

I don't love the structuring of this code which now needs to pass a
first class mapper instead of just being known code. It also shares the
host path which is just an identity function. It wouldn't necessarily
pass my own review but I don't have a better one for now. I'd really
prefer if this was done at a "row" level but that ends up creating even
more code.

Add test for Blob in FormData and async modules in Maps.
2024-04-08 15:40:11 -04:00
Josh Story
01bb3c5632 [TestUtils] Build limited test-utils (#28782)
We landed a flag to disable test utils in many builds but we need to
fork the entrypoint to make it work with tests properly. This also
removes test-utils implementations from builds that do not support it.
Currently in OSS builds the only thing in test-utils is a reexport of
`act`
2024-04-08 12:27:20 -07:00
Ruslan Lesiutin
6de7733e73 feat[devtools]: ship source maps for content scripts and ignore list installHook script (#28730)
## Summary

1. RDT browser extension's content scripts will now ship source maps
(without source in prod, to save some bundle size).
2. `installHook` content script will be ignore listed via `ignoreList`
field in the corresponding source map.
3. Previously, source map for backend file used `x_google_ignoreList`
naming, now `ignoreList`.

## How did you test this change?

1. `ignoreList-test.js`
2. Tested manually that I don't see `installHook` in stack traces when
`console.error` is called.
2024-04-08 18:10:09 +01:00
Josh Story
4c12339ce3 [DOM] move flushSync out of the reconciler (#28500)
This PR moves `flushSync` out of the reconciler. there is still an
internal implementation that is used when these semantics are needed for
React methods such as `unmount` on roots.

This new isomorphic `flushSync` is only used in builds that no longer
support legacy mode.

Additionally all the internal uses of flushSync in the reconciler have
been replaced with more direct methods. There is a new
`updateContainerSync` method which updates a container but forces it to
the Sync lane and flushes passive effects if necessary. This combined
with flushSyncWork can be used to replace flushSync for all instances of
internal usage.

We still maintain the original flushSync implementation as
`flushSyncFromReconciler` because it will be used as the flushSync
implementation for FB builds. This is because it has special legacy mode
handling that the new isomorphic implementation does not need to
consider. It will be removed from production OSS builds by closure
though
2024-04-08 09:03:20 -07:00
Josh Story
8e1462e8c4 [Fiber] Move updatePriority tracking to renderers (#28751)
Currently updatePriority is tracked in the reconciler. `flushSync` is
going to be implemented reconciler agnostic soon and we need to move the
tracking of this state to the renderer and out of reconciler. This
change implements new renderer bin dings for getCurrentUpdatePriority
and setCurrentUpdatePriority.

I was originally going to have the getter also do the event priority
defaulting using window.event so we eliminate getCur rentEventPriority
but this makes all the callsites where we store the true current
updatePriority on the stack harder to work with so for now they remain
separate.

I also moved runWithPriority to the renderer since it really belongs
whereever the state is being managed and it is only currently exposed in
the DOM renderer.

Additionally the current update priority is not stored on
ReactDOMSharedInternals. While not particularly meaningful in this
change it opens the door to implementing `flushSync` outside of the
reconciler
2024-04-08 08:53:17 -07:00
Lauren Tan
5bf2323880 Fix missing playground snapshot
ghstack-source-id: f2c8a542b525ab8c91beaad6327c128a96d122f6
Pull Request resolved: https://github.com/facebook/react-forget/pull/2827
2024-04-08 11:23:29 -04:00
Andrew Clark
0b3b8a6a35 jsx: Remove unnecessary hasOwnProperty check (#28775)
Follow up to #28768.

The modern JSX runtime (`jsx`) does not need to check if each prop is a
direct property with `hasOwnProperty` because the compiler always passes
a plain object.

I'll leave the check in the old JSX runtime (`createElement`) since that
one can be called manually with any kind of object, and if there were
old user code that relied on this for some reason, it would be using
that runtime.
2024-04-08 11:12:40 -04:00
Sebastian Silbermann
e63918d2cd Add Promise as a child test to Flight fixture (#28778) 2024-04-08 17:06:17 +02:00
Lauren Tan
9a6cb24150 [ez] Fix comments to be star blocks
ghstack-source-id: 6a9e844a3ba548d3bf2b7373dc023ad42c2e719b
Pull Request resolved: https://github.com/facebook/react-forget/pull/2826
2024-04-08 10:55:55 -04:00
Lauren Tan
0d0f7c2ad1 Update ValidatePreservedManualMemoization severity to
CannotPreserveMemoization

We do need to fix the error location to point to the "callsite" rather
than the definition of the useMemo callback, but that aside, even if the
error message were perfect, it's not meant to be actionable to the user.

So let's change the severity to CannotPreserveMemoization. This
preserves the validation, but the eslint plugin won't report it.

ghstack-source-id: 722c88922884de05e89030a7b001bd93e0a2a114
Pull Request resolved: https://github.com/facebook/react-forget/pull/2825
2024-04-08 10:55:54 -04:00
Lauren Tan
1f35f7e320 Add new ErrorSeverity.CannotPreserveMemoization
This adds a new category of error where the compiler cannot preserve
memoization exactly how as it was originally authored. We're adding a
new category here because it's not an actionable error, and allows us to
more specifically control whether it's reportable or not.

ghstack-source-id: 9693cd42ca64b980248c6202091bdd4c827e1cd4
Pull Request resolved: https://github.com/facebook/react-forget/pull/2824
2024-04-08 11:00:41 -04:00
Surav Shrestha
f86afca090 docs: fix typo in fixtures/nesting/README.md (#27507) 2024-04-06 19:11:19 +02:00
Sebastian Markbåge
2acfb7b609 [Flight] Support FormData from Server to Client (#28754)
We currently support FormData for Replies mainly for Form Actions. This
supports it in the other direction too which lets you return it from an
action as the response. Mainly for parity.

We don't really recommend that you just pass the original form data back
because the action is supposed to be able to clear fields and such but
you could potentially at least use this as the format and could clear
some fields.

We could potentially optimize this with a temporary reference if the
same object was passed to a reply in case you use it as a round trip to
avoid serializing it back again. That way the action has the ability to
override it to clear fields but if it doesn't you get back the same as
you sent.

#28755 adds support for Blobs when the `enableBinaryFlight` is enabled
which allows them to be used inside FormData too.
2024-04-05 14:32:18 -04:00
Andrew Clark
d1547defe3 Fast JSX: Don't clone props object (#28768)
(Unless "key" is spread onto the element.)

Historically, the JSX runtime clones the props object that is passed in.
We've done this for two reasons.

One reason is that there are certain prop names that are reserved by
React, like `key` and (before React 19) `ref`. These are not actual
props and are not observable by the target component; React uses them
internally but removes them from the props object before passing them to
userspace.

The second reason is that the classic JSX runtime, `createElement`, is
both a compiler target _and_ a public API that can be called manually.
Therefore, we can't assume that the props object that is passed into
`createElement` won't be mutated by userspace code after it is passed
in.

However, the new JSX runtime, `jsx`, is not a public API — it's solely a
compiler target, and the compiler _will_ always pass a fresh, inline
object. So the only reason to clone the props is if a reserved prop name
is used.

In React 19, `ref` is no longer a reserved prop name, and `key` will
only appear in the props object if it is spread onto the element.
(Because if `key` is statically defined, the compiler will pass it as a
separate argument to the `jsx` function.) So the only remaining reason
to clone the props object is if `key` is spread onto the element, which
is a rare case, and also triggers a warning in development.

In a future release, we will not remove a spread key from the props
object. (But we'll still warn.) We'll always pass the object straight
through.

The expected impact is much faster JSX element creation, which in many
apps is a significant slice of the overall runtime cost of rendering.
2024-04-05 13:25:24 -04:00
Andrew Clark
bfd8da807c Make class prop resolution faster (#28766)
`delete` causes an object (in V8, and maybe other engines) to deopt to a
dictionary instead of a class. Instead of `assign` + `delete`, manually
iterate over all the properties, like the JSX runtime does.

To avoid copying the object twice I moved the `ref` prop removal to come
before handling default props. If we already cloned the props to remove
`ref`, then we can skip cloning again to handle default props.
2024-04-05 13:06:39 -04:00
Sebastian Markbåge
cbb6f2b546 [Flight] Support Blobs from Server to Client (#28755)
We currently support Blobs when passing from Client to Server so this
adds it in the other direction for parity - when `enableFlightBinary` is
enabled.

We intentionally only support the `Blob` type to pass-through, not
subtype `File`. That's because passing additional meta data like
filename might be an accidental leak. You can still pass a `File`
through but it'll appear as a `Blob` on the other side. It's also not
possible to create a faithful File subclass in all environments without
it actually being backed by a file.

This implementation isn't great but at least it works. It creates a few
indirections. This is because we need to be able to asynchronously emit
the buffers but we have to "block" the parent object from resolving
while it's loading.

Ideally, we should be able to create the Blob on the client early and
then stream in it lazily. Because the Blob API doesn't guarantee that
the data is available synchronously. Unfortunately, the native APIs
doesn't have this. We could implement custom versions of all the data
read APIs but then the blobs still wouldn't work with native APIs. So we
just have to wait until Blob accepts a stream in the constructor.

We should be able to stream each chunk early in the protocol though even
though we can't unblock the parent until they've all loaded. I didn't do
this yet mostly because of code structure and I'm lazy.
2024-04-05 12:49:25 -04:00
Sebastian Markbåge
f33a6b69c6 Track Owner for Server Components in DEV (#28753)
This implements the concept of a DEV-only "owner" for Server Components.
The owner concept isn't really super useful. We barely use it anymore,
but we do have it as a concept in DevTools in a couple of cases so this
adds it for parity. However, this is mainly interesting because it could
be used to wire up future owner-based stacks.

I do this by outlining the DebugInfo for a Server Component
(ReactComponentInfo). Then I just rely on Flight deduping to refer to
that. I refer to the same thing by referential equality so that we can
associate a Server Component parent in DebugInfo with an owner.

If you suspend and replay a Server Component, we have to restore the
same owner. To do that, I did a little ugly hack and stashed it on the
thenable state object. Felt unnecessarily complicated to add a stateful
wrapper for this one dev-only case.

The owner could really be anything since it could be coming from a
different implementation. Because this is the first time we have an
owner other than Fiber, I have to fix up a bunch of places that assumes
Fiber. I mainly did the `typeof owner.tag === 'number'` to assume it's a
Fiber for now.

This also doesn't actually add it to DevTools / RN Inspector yet. I just
ignore them there for now.

Because Server Components can be async the owner isn't tracked after an
await. We need per-component AsyncLocalStorage for that. This can be
done in a follow up.
2024-04-05 12:48:52 -04:00
Andrew Clark
e3ebcd54b9 Move string ref coercion to JSX runtime (#28473)
Based on:

- #28464

---

This moves the entire string ref implementation out Fiber and into the
JSX runtime. The string is converted to a callback ref during element
creation. This is a subtle change in behavior, because it will have
already been converted to a callback ref if you access element.prop.ref
or element.ref. But this is only for Meta, because string refs are
disabled entirely in open source. And if it leads to an issue in
practice, the solution is to switch to a different ref type, which Meta
is going to do regardless.
2024-04-05 10:53:11 -04:00
Jan Kassens
76bb13cd26 First attempt at making the linter work with advanced TypeScript syntax
First attempt at making the linter work with advanced TypeScript syntax 

Falls back to the babel parser for some advanced syntax like string template 
syntax. 

This is pretty hacky as it doesn't take in any parsing options that are 
configured for the outer ESLint parser, not sure how that could be handled.
2024-04-04 18:31:31 -04:00
Sebastian Markbåge
fd0da3eef1 Remove _owner field from JSX elements in prod if string refs are disabled (#28739)
In prod, the `_owner` field is only used for string refs so if we have
string refs disabled, we don't need this field. In fact, that's one of
the big benefits of deprecating them.
2024-04-04 11:20:15 -04:00
Andrew Clark
48b4ecc901 Remove defaultProps support (except for classes) (#28733)
This removes defaultProps support for all component types except for
classes. We've chosen to continue supporting defaultProps for classes
because lots of older code relies on it, and unlike function components,
(which can use default params), there's no straightforward alternative.

By implication, it also removes support for setting defaultProps on
`React.lazy` wrapper. So this will not work:

```js
const MyClassComponent = React.lazy(() => import('./MyClassComponent'));
// MyClassComponent is not actually a class; it's a lazy wrapper. So
// defaultProps does not work.
MyClassComponent.defaultProps = { foo: 'bar' };
```

However, if you set the default props on the class itself, then it's
fine.

For classes, this change also moves where defaultProps are resolved.
Previously, defaultProps were resolved by the JSX runtime. This change
is only observable if you introspect a JSX element, which is relatively
rare but does happen.

In other words, previously `<ClassWithDefaultProp />.props.aDefaultProp`
would resolve to the default prop value, but now it does not.
2024-04-04 10:59:19 -04:00
Jack Pope
7966ccddc8 Enable stale action (#28729)
Follows #28695

Now that the action has run successfully in debug mode
([logs](https://github.com/facebook/react/actions/runs/8532177618/job/23372921455#step:2:35)),
let's enable it to persist changes.

Also changes the number of operations per run from the default of 30 to
100 since we have a large backlog of issues and PRs to work through.

Finally adds enhancement label as exempt from stale.
2024-04-04 10:27:29 -04:00
Sebastian Markbåge
6090cab099 Use a Wrapper Error for onRecoverableError with a "cause" Field for the real Error (#28736)
We basically have four kinds of recoverable errors:

- Hydration mismatches.
- Server errored but client didn't.
- Hydration render errored but client render didn't (in Root or Suspense
boundary).
- Concurrent render errored but synchronous render didn't.

For the first three we log an additional error that the root or Suspense
boundary didn't error. This provides some context about what happened.
However, the problem is that for hydration mismatches that's unnecessary
extra context that is confusing. We also don't log any additional
context for concurrent render errors that could recover. This used to be
the only recoverable error so it didn't need extra context but now we
need to distinguish them. When we log these to `reportError` it's
confusing to just see the error because you didn't see anything error on
the page. It's also hard to group them together as one.

In this PR, I remove the unnecessary context for hydration mismatches.

For hydration and concurrent errors, I now wrap them in an error that
describes that what happened but then use the new `cause` field to link
the original error so we can keep that as the cause. The error that
happened was that hydration client rendered or you deopted to sync
render, the cause of that error is some other error.

For server errors, we control the Error object so I already had added
some context to that error object's message. Since we hide the message
in prod, it's nice not to have the raw message in DEV neither. We could
potentially split these into two errors for parity though.
2024-04-03 21:53:07 -04:00
Sebastian Markbåge
583eb6770d Emit Server Error Prefix in the .stack Property Too (#28738)
Follow up to #28684.

V8 includes the message in the stack and printed errors include just the
stack property which is assumed to contain the message. Without this,
the prefix doesn't get printed in the console.

<img width="578" alt="Screenshot 2024-04-03 at 6 32 04 PM"
src="https://github.com/facebook/react/assets/63648/d98a2db4-6ebc-4805-b669-59f449dfd21f">

A possible alternative would be to use a nested error with a `cause`
like #28736 but that would need some more involved serializing since
this prefix is coming from the server. Perhaps as a separate attribute.
2024-04-03 21:52:54 -04:00
Lauren Tan
9a9e03b915 Add playground e2e to ci
This only runs on main since it takes a while to run (about ~4 mins)
2024-04-03 18:12:30 -04:00
Lauren Tan
07a3404c5f Add basic playwright e2e test to playground 2024-04-03 18:12:29 -04:00
Lauren Tan
ee24e3fc16 Dogfood uMC polyfill in playground 2024-04-03 18:12:29 -04:00
Ricky
a5aedd1e15 Move console mocks to internal-test-utils (#28710)
Moving this to `internal-test-utils` so I can add helpers in the next PR
for:
- assertLogDev
- assertWarnDev
- assertErrorDev

Which will be exported from `internal-test-utils`. This isn't strictly
necessary, but it makes the factoring nicer, so internal-test-until
doesn't need to depend on `scripts/jest`.
2024-04-03 16:02:04 -04:00
Jan Kassens
20e710aeab Cleanup enableUseRefAccessWarning flag (#28699)
Cleanup enableUseRefAccessWarning flag

I don't think this flag has a path forward in the current
implementation. The detection by stack trace is too brittle to detect
the lazy initialization pattern reliably (see e.g. some internal tests
that expect the warning because they use lazy intialization, but a
slightly different pattern then the expected pattern.

I think a new version of this could be to fully ban ref access during
render with an alternative API for the exceptional cases that today
require ref access during render.
2024-04-03 13:35:38 -04:00
Andrew Clark
3761acb42b Classes consume ref prop during SSR, too (#28731)
Same as #28719 but for SSR.
2024-04-03 12:55:57 -04:00
Joe Savona
f33e63838d Update copyrights to reference Meta instead of Facebook
Thanks @zpao!!! This was mostly his work, i just fixed up the last bit.
2024-04-03 08:43:36 -07:00
Jan Kassens
7a2609eedc Cleanup enableBigIntSupport flag (#28711)
Cleanup enableBigIntSupport flag
2024-04-03 09:25:02 -04:00
Jan Kassens
4e8121a75e Remove @providesModule remnants (#28720)
Remove @providesModule remnants

Removes `@providesModule` from the generated RN modules and CI
validation that no `@providesModule` is added which should no longer be
needed as this has been the case for years now.
2024-04-03 09:10:00 -04:00
Josh Story
cb6dc7a6a0 [FB] use modern entrypoint in tests (#28724)
Removes the entrypoint hack in tests since we gate legacy mode tests now
2024-04-02 22:23:54 -07:00
Joe Savona
0846daaa54 Commit message script captures non-ghstack messages
Tested by manually passing in the commit message from 
1028504dc8 
and verifying that it grabbed the description from GH.
2024-04-02 20:55:41 -07:00
Joe Savona
852301828b Remove reactive_ir crate 2024-04-02 21:03:25 -07:00
Andrew Clark
131f020c09 Enable feature flags for v19 (#28647)
The canary channel now represents v19, so we can turn these flags on.
2024-04-02 23:33:13 -04:00
Andrew Clark
dc545c8d6e Fix: Class components should "consume" ref prop (#28719)
When a ref is passed to a class component, the class instance is
attached to the ref's current property automatically. This different
from function components, where you have to do something extra to attach
a ref to an instance, like passing the ref to `useImperativeHandle`.

Existing class component code is written with the assumption that a ref
will not be passed through as a prop. For example, class components that
act as indirections often spread `this.props` onto a child component. To
maintain this expectation, we should remove the ref from the props
object ("consume" it) before passing it to lifecycle methods. Without
this change, much existing code will break because the ref will attach
to the inner component instead of the outer one.

This is not an issue for function components because we used to warn if
you passed a ref to a function component. Instead, you had to use
`forwardRef`, which also implements this "consuming" behavior.

There are a few places in the reconciler where we modify the fiber's
internal props object before passing it to userspace. The trickiest one
is class components, because the props object gets exposed in many
different places, including as a property on the class instance.

This was already accounted for when we added support for setting default
props on a lazy wrapper (i.e. `React.lazy` that resolves to a class
component).

In all of these same places, we will also need to remove the ref prop
when `enableRefAsProp` is on.

Closes #28602

---------

Co-authored-by: Jan Kassens <jan@kassens.net>
2024-04-02 23:15:04 -04:00
Sebastian Markbåge
8f55a6aa57 Move ReactDOMLegacy implementation into RootFB (#28656)
Only the FB entry point has legacy mode now so we can move the remaining
code in there.

Also enable disableLegacyMode in modern www builds since it doesn't
expose those entry points.

Now dependent on #28709.

---------

Co-authored-by: Josh Story <story@hey.com>
2024-04-02 21:56:23 -04:00
Sebastian Markbåge
5de8703646 Use the disableLegacyMode where ever we check the ConcurrentMode mode (#28657)
Saves some bytes and ensures that we're actually disabling it.

Turns out this flag wasn't disabling React Native/Fabric, React Noop and
React ART legacy modes so those are updated too.

Should be rebased on #28681.
2024-04-02 21:07:28 -04:00
Josh Story
5998a77519 Reland #28672: Remove IndeterminateComponent (#28681)
This PR relands #28672 on top of the flag removal and the test
demonstrating a breakage in Suspense for legacy mode.

React has deprecated module pattern Function Components for many years
at this point. Supporting this pattern required React to have a concept
of an indeterminate component so that when a component first renders it
can turn into either a ClassComponent or a FunctionComponent depending
on what it returns. While this feature was deprecated and put behind a
flag it is still in stable. This change remvoes the flag, removes the
warnings, and removes the concept of IndeterminateComponent from the
React codebase.

While removing IndeterminateComponent type Seb and I discovered that we
needed a concept of IncompleteFunctionComponent to support Suspense in
legacy mode. This new work tag is only needed as long as legacy mode is
around and ideally any code that considers this tag will be excludable
from OSS builds once we land extra gates using `disableLegacyMode` flag.
2024-04-02 17:42:43 -07:00
Joe Savona
8a43e954a2 s/Forget/React Compiler/ in Rust port 2024-04-02 16:49:31 -07:00
Joe Savona
5ec3f02ee5 Rename docs/architecture.md to design_goals per contents 2024-04-02 16:05:11 -07:00
Joe Savona
90dd2084e2 ValidateNoCapitalizedCalls checks capitalized methods 2024-04-03 08:02:40 -07:00
Joe Savona
4c1aae4f3b [be] Cleanup removed directories from prettier script 2024-04-03 08:02:39 -07:00
Joe Savona
94156d7014 Repro for unmemoized value due to assignment to a context variable 2024-04-03 08:02:38 -07:00
Joe Savona
284f776420 [be] Clean up already fixed "bug" fixtures
These are already fixed, renamed to clarify that they are just repros of 
previous bugs
2024-04-02 12:43:44 -07:00
Sebastian Markbåge
5fcaa0a832 Make ART Concurrent if Legacy Mode is disabled (#28662)
Pulling this out of #28657.

This runs react-art in concurrent mode if disableLegacyMode is true.
Effectively this means that the OSS version will be in concurrent mode
and the `.modern.js` version for Meta will be in concurrent mode, once
the flag flips for modern, but the `.classic.js` version for Meta will
be in legacy mode.

Updates flowing in from above flush synchronously so that they commit as
a unit. This also ensures that refs are resolved before the parent life
cycles. setStates deep in the tree will now be batched using "discrete"
priority but should still happen same task.
2024-04-02 15:00:30 -04:00
Joe Savona
a53f208f5e Fixture for conditional use()
This is mostly to ensure we don't flag this as a conditional hook, but since i'm 
here i made it a proper test.
2024-04-02 11:36:11 -07:00
Joe Savona
8b9edafa95 Support use operator
Implements support for use: 

* Teaches InferReactivePlaces to treat use() result as reactive 

* Teaches FlattenScopesWithHooks to also flatten scopes with use() 

Handles both `use()` and `React.use()`.
2024-04-02 11:28:01 -07:00
Joseph Savona
8cb6a1c034 [be] Remove unused, experimental getCacheSignal API (#28706)
Similar to #28698, this removes the `unstable_getCacheSignal()` API
since we don't intend to ship this to stable.
2024-04-02 10:54:31 -07:00
Lauren Tan
e61f983264 Fix yarn dev 2024-04-02 12:18:12 -04:00
Lauren Tan
5485ed0855 Standardize on banner2 plugin 2024-04-02 12:13:41 -04:00
Lauren Tan
f01f74d9e1 Also build react-forget-runtime with rollup
This adds rollup to the runtime and adds a new plugin to add the license banner 
+ inject the `"use no memo"` directive. We need to inject it there as rollup 
currently strips out unknown directives during bundling.
2024-04-02 12:13:40 -04:00
Lauren Tan
b4eeae6f5d Share rollup packages across workspace 2024-04-02 12:13:39 -04:00
Lauren Tan
91826d4924 Configure rollup to strip comments and whitespace
For now this configures rollup to strip out comments in DEV builds and 
whitespace. Unfortunately there's no easy way to do this in just terser alone or 
other minifiers/manglers, so I had to add prettier as well to re-format the 
minified code. This does make the build a little bit slower: 

``` before: yarn build  118.96s user 12.38s system 185% cpu 1:10.81 total after: 
 yarn build  121.55s user 12.90s system 183% cpu 1:13.17 total ``` 

Eventually I would like to have a similar setup to React's rollup config where 
we can have DEV and prod builds. After the repo merge we could probably share or 
reuse bits of React's rollup config.
2024-04-02 12:13:38 -04:00
Sebastian Markbåge
48ec17b865 Differentiate null and undefined in Custom Elements - removing sets to undefined (#28716)
In React DOM, in general, we don't differentiate between `null` and
`undefined` because we expect to target DOM APIs. When we're setting a
property on a Custom Element, in the new heuristic, the goal is to allow
passing whatever data type instead of normalizing it. Switching between
`undefined` and `null` as an explicit value should therefore be
respected.

However, in this mode if `undefined` is used for the initial value, we
don't actually set the property at all. If passing `null` we will now
initialize it to the value `null`. Meaning `undefined` kind of
represents the default.

### Removing Properties

There is a pretty complex edge case which is what should happen when a
prop used to exist but was removed from the props object. This doesn't
have any kind of defined semantics. It really should mean - return to
"default". Because in the declarative world it means the same as if it
was just created - i.e. we can't just leave it as it was.

The closest might be `delete object.property` but that's not really the
intended way that properties on custom elements / classes are supposed
to operate. Additionally, for a property to even hit our heuristic it
must pass the `in` test and must exist to being with so the default must
have a value.

Since the point of these properties is to contain any kind of type,
there isn't really a conceptual default value. E.g. a numeric default
value might be zero `0` while a default string might be empty `""` and
default object might `null`. Additionally, the conceptual default can
really be initialized to anything. There's also varied precedence in the
ecosystem here and really no consensus. Anything we pick would be kind
of wrong, so we used to just pick `null`.

_The safest way to consume a Custom Element is to always pass the same
set of props._

JS does have a concept of a "default value" though and that is described
as the value `undefined`. That's why default argument / object property
initializers are initialized if the value is `undefined`.

The problem with using `undefined` as value is that [you shouldn't
actually ever set the value of a class property to
`undefined`](https://twitter.com/sebmarkbage/status/1774082540296388752).
A property should always be initialized to some value. It can't be left
missing and shouldn't be initialized to the value `undefined` for hidden
class optimizations. If we just mutate it to be `undefined` it would be
potentially bad for perf and shouldn't really be the value after
removing property - it should be returned to default.

Every property should really have a setter to be useful since it is what
is used to trigger reactivity when it changes. Sometimes you can just
use the properties passively when something else happens but most of the
time it should be a setter but to reach parity with DOM it should really
be always so that the active value can be normalized.

Those setters can have default argument initializers to represent what
the default value should be. Therefore Custom Element properties should
be used like this:

```js
class CustomElement extends HTMLElement {
  _textLabel = '';
  _price = 0;
  _items = null;
  
  constructor() {
    super();
  }
  set textLabel(value = '') {
    this._textLabel = value;
  }
  get textLabel() {
    return this._textLabel;
  }
  set price(value = 0) {
    this._price = value;
  }
  get price() {
    return this._price;
  }
  set items(value = null) {
    this._items = value;
  }
  get items() {
    return this._items;
  }
}
```

The default initializer can be used to initialize a value back to its
original default when `undefined` is passed to it. Therefore, we pass
`undefined`, not because we expect that to be the value of a property
but because that's the value that represents "return to default".

This fixes #28203 but not really for the reason specified in the issue.
We don't expect you to actually store the `undefined` value but to use a
setter to set the property to something else that represents the
default. When we initialize the element the first time, we won't set
anything if it's the value `undefined` so we assume that the property
initializers running in the constructor is going to set the same default
value as if we set the property to `undefined`.

cc @josepharhar
2024-04-02 11:48:27 -04:00
Jack Pope
4ecea96c55 Update RTR readme (#28705) 2024-04-02 11:41:31 -04:00
Jan Kassens
ba5496d411 Hardcode enableLegacyFBSupport flag (#28701)
Hardcode enableLegacyFBSupport flag
2024-04-02 11:35:18 -04:00
Joseph Savona
e3afd026c8 Remove reference to deleted <Cache> in un-linted file (#28715)
I missed this in #28698 bc the file isn't linted
2024-04-02 08:13:15 -07:00
Sebastian Silbermann
28fc980ef2 Cleanup enableNewBooleanProps (#28712) 2024-04-02 17:09:43 +02:00
Jan Kassens
7659c4d9e0 Remove dynamic www flag for disableInputAttributeSyncing (#28703)
Remove dynamic www flag for disableInputAttributeSyncing
2024-04-02 10:57:23 -04:00
Joseph Savona
7319c61b18 [be] Remove unshipped experimental <Cache> element type (#28698)
Removes the `<Cache />` element type since we're going with a simpler
caching strategy.
2024-04-02 07:57:08 -07:00
Jan Kassens
c97564d7ac Upgrade flow to 0.232.0 (#28697)
Upgrade flow to 0.232.0
2024-04-02 10:40:03 -04:00
Jan Kassens
4eb241a94f Bump nvmrc to Node.js v18 (#28707)
Bump nvmrc to Node.js v18

Node.js v16 is long deprecated, seems like for v20 there's some more
stuff to fix.
2024-04-02 10:04:19 -04:00
Joe Savona
f0806c43fe Remove flag for enableEarlyReturnInReactiveScopes (always enable) 2024-04-01 15:37:03 -07:00
Joe Savona
ef285e0702 Remove memoizeJsxElements flag 2024-04-01 15:34:42 -07:00
Joe Savona
b00300c4cf Remove disableAllMemoization flag 2024-04-01 15:18:59 -07:00
Joe Savona
69f03dc4c4 Remove unused environment flags
These flags aren't used anymore
2024-04-01 15:16:31 -07:00
Sathya Gunasekaran
cd3f56bb18 [eslint] Enforce generic array type syntax
Fix and enforce generic array type syntax
2024-04-02 15:31:25 +01:00
Sathya Gunasekaran
1de6c5aea2 [eslint] Don't lint generated files
drive by fix multi line comments in .eslintrc
2024-04-02 12:03:26 +01:00
Lauren Tan
ba661c80f3 Remove comments in builds 2024-04-02 10:32:24 -04:00
Lauren Tan
4e6aa42773 Upgrade to typescript 5.4.3
This PR makes all packages share the same typescript version and updates us to 
latest versions of typescript, ts-node, typescript-eslint/eslint-plugin and 
typescript-eslint/parser. 

I also noticed that the tsconfig we were extending (node18-strictest) was 
deprecated, so I switched us over to one that's more up to date. 

Also had to make a couple of small changes to the playground so that continues 
to build correctly.
2024-04-02 10:32:23 -04:00
Lauren Tan
5516cbb708 [ez] Fix unneeded path in copyright script 2024-04-02 10:32:22 -04:00
Lauren Tan
0af58d6c9e [ez] Clean up unused test filters 2024-04-02 10:32:21 -04:00
Sathya Gunasekaran
d5b6e584fb [hir] Add support for directives
Previously, we would drop directives inside a component or hook but this is 
problematic with reanimated which uses `'worklet'` to mark components from 
compilation. 

This PR adds a directive to HIRFunction and ReactiveFunction and codegens the 
directive add the end. No processing is done on the directives themselves. 

Babel seems to store the directives on a BlockStatement, rather than on the 
Function but I've stored it on the Function types because we only support 
compiling functions and the spec defines directives as occuring in the initial 
statement list of a function: > A Directive Prologue is the longest sequence of 
ExpressionStatements > occurring as the initial StatementListItems or 
ModuleItems of a > FunctionBody, a ScriptBody, or a ModuleBody and where each > 
ExpressionStatement in the sequence consists entirely of a > StringLiteral token 
followed by a semicolon.
2024-04-02 11:25:10 +01:00
Joe Savona
1c3313707f ReactiveTerminal: add loc and id to all variants 2024-04-01 15:03:47 -07:00
Ricky
6e65010999 [tests] Disallow unasserted console.log (#28708)
Followup from https://github.com/facebook/react/pull/28693 and
https://github.com/facebook/react/pull/28680.

In CI, we fail the test for any unasserted console.log. In DEV, we don't
fail, but you can still use the matchers and we'll assert on them.
2024-04-01 17:45:49 -04:00
Joe Savona
832285fed2 Only create mutable ranges for phis *mutated* later
This PR was the result of a long chain of ~yak-shaving~ debugging kicked off as 
a result of fixing up invariants. Where this started was that i noticed some 
cases of loops where the first instance we saw of a reactive scope was after its 
starting instruction. Eg instruction N would have an operand with scope 
Start:End, where Start was _before_  N. One of the cases involved a phi with a 
backedge. Then i noticed that we assign scopes differently for phis with and 
without backedges: 

``` 

[1] let x0 = init; 

[2] if (x0 < limit) { 

[3] x1 += increment; 

} 

x2 = phi(x0, x1); 

[4] x2; 

``` 

The phi isn't mutated _or_ reassigned after its creation, so we don't assign a 
mutable range to the phi or any of its operands. We also don't create a scope 
for `x`. 

But change the `if` to a `while` and now the phi moves - now there's a backedge: 

``` 

[1] let x0 = init; 

[2] while (x0 < limit) { 

x2 = phi(x0, x2); // now this is "mutated" later!!! 

[3] x2 += increment; 

} 

[4] x2; 

``` 

What was happening here is that x2 has a mutable range which is "after" the phi 
instruction, so it would appear that the phi was actually being mutated later. 
Ie, this was treated equivalently to the original "if" version, but with a 
mutation: 

``` 

let x = []; 

if (cond) { 

x = {}; 

} 

mutate(x); // later mutation of the phi 

``` 

But these latter two cases are different! We only need to (should) create a 
mutable range for a phi _if its value is actually mutated_. If it's just being 
reassigned, well then it shouldn't matter if there are back edges or not. 

So this PR implements that intuition: only create a mutable range for a phi if 
it is actually _mutated_ later, ie don't assign a mutable range if it is only 
_reassigned_ later. Concretely in InferMutableRanges: 

* InferMutableLifetimes no longer has to initialize a range for phis during the 
first pass (inferMutableRangesForStores=false). We wait to see if the phi is 
mutated during the main fixpoint iteration of InferMutableRanges 

* The main fixpoint iteration in InferMutableRanges already aliases phi operands 
if the phi is later mutated, which will extend the end of the mutable range of 
all the operands accordingly. 

* Finally, InferMutableLifetimes's second run 
(inferMutableRangesForStores=true), we ensure that any phis mutated later have a 
valid mutable range, specifically setting the `start` of the range since the 
fixpoint only updates the `end` value.
2024-04-01 14:21:48 -07:00
Jack Pope
8833338c8f Convert deprecated stalebot to github action (#28695)
## Summary

This repo uses [Stalebot](https://github.com/probot/stale) to manage
stale Issues and PRs. Stalebot hasn't been maintained for a couple of
years and is officially archived. The number of open Issues and PRs has
increased rapidly since early 2022. Some of this looks like issues with
Stalebot reliability where labels were not applied or close actions were
not taken even when meeting the criteria in the config.

In order to make it easier for maintainers to spend time on current
Issues and PRs, let's upgrade to the Github Stale Action. For now this
PR applies the same config to the new action but we can iterate on it as
needed. The goal is to clean up abandoned and no-longer-relevant
submissions, not to close Issues that describe active bugs or feedback.

## How did you test this change?

Added `debug-only: 'true'` to this PR so we can run the action and
review the logs before allowing the action to run on schedule. We may
see a large amount of label changes and close actions on the first run
as the action clears out previously ignored stale submissions.
2024-04-01 14:32:28 -04:00
Ricky
5ab97b7345 Land useModernStrictMode in www (#28696)
this has landed
2024-04-01 13:05:08 -04:00
Hendrik Liebau
93f91795a0 [Flight] Update stale blocked values in createModelResolver (#28669)
Alternative to #28620.

Instead of emitting lazy references to not-yet-emitted models in the
Flight Server, this fixes the observed issue in
https://github.com/unstubbable/ai-rsc-test/pull/1 by adjusting the lazy
model resolution in the Flight Client to update stale blocked root
models, before assigning them as chunk values. In addition, the element
props are not outlined anymore in the Flight Server to avoid having to
also handle their staleness in blocked elements.

fixes #28595
2024-04-01 12:37:27 -04:00
Jack Pope
95e6f032cf Clarify RTR native feature flags are fb specific (#28679)
Make it more clear that these flags aren't used in RN OSS.
- Rename
`packages/shared/forks/ReactFeatureFlags.test-renderer.native.js` to
`packages/shared/forks/ReactFeatureFlags.test-renderer.native-fb.js`
- Remove RN OSS build cases consuming the feature flags since there is
no RN OSS RTR build.
2024-04-01 10:56:28 -04:00
Jean-François Greffier
496fd3da5a [ESLint] Update README links to react.dev (#28692)
Update ESLint plugin README to redirect to https://react.dev for more
details (instead of legacy docs)
2024-04-01 10:52:34 -04:00
Ricky
e9ae2c8f35 Clean up console.log tests (#28693)
Followups to https://github.com/facebook/react/pull/28680

One of these test don't need to use `console.log`. 

The others are specifically testing `console.log` behavior, so I added a
comment.
2024-04-01 10:50:48 -04:00
Sebastian Markbåge
df95577db0 Finish cleaning up digest from onRecoverableError (#28686)
Don't need to track it separately on the captured value anymore.

Shouldn't be in the types.

I used a getter for the warning instead because Proxies are kind of
heavy weight options for this kind of warning. We typically use getters.
2024-03-30 18:32:20 -04:00
Timothy Yung
9f835e69ab Suppress console output in unit tests (#28680) 2024-03-30 09:36:23 -07:00
Sebastian Markbåge
b9149cc6e6 Include regular stack trace in serialized errors from Fizz (#28684)
We previously only included the component stack.
    
Cleaned up the fields in Fizz server that wasn't using consistent hidden
classes in dev vs prod.

Added a prefix to errors serialized from server rendering. It can be a
bit confusing to see where this error came from otherwise since it
didn't come from elsewhere on the client. It's really kind of confusing
with other recoverable errors that happen on the client too.
2024-03-30 11:08:54 -04:00
Sebastian Markbåge
5d4b7587da Don't let error boundaries catch errors during hydration (#28675)
When an error boundary catches an error during hydration it'll try to
render the error state which will then try to hydrate that state,
causing hydration warnings.

When an error happens inside a Suspense boundary during hydration, we
instead let the boundary catch it and restart a client render from
there. However, when it's in the root we instead let it fail the root
and do the sync recovery pass. This didn't consider that we might hit an
error boundary first so this just skips the error boundary in that case.

We should probably instead let the root do a concurrent client render in
this same pass instead to unify with Suspense boundaries.
2024-03-29 16:43:22 -04:00
Jan Kassens
2aed507a76 Remove React.createFactory (#27798)
`React.createFactory` has been long deprecated. This removes it for the
next release.
2024-03-29 16:29:48 -04:00
Timothy Yung
13f35433bc Mock modules in tests using Module (#28678)
## Summary

Fixes a type validation error introduced in newer versions of Node.js
when calling `Module.prototype._compile` in our unit tests. (I tried but
have yet to pinpoint the precise change in Node.js that introduced this
vaildation.)

The specific error that currently occurs when running unit tests with
Node.js v18.16.1:

```
TypeError: The "mod" argument must be an instance of Module. Received an instance of Object

      80 |
      81 |     if (useServer) {
    > 82 |       originalCompile.apply(this, arguments);
         |                       ^
      83 |
      84 |       const moduleId: string = (url.pathToFileURL(filename).href: any);
      85 |
```

This fixes the type validation error by mocking modules using `new
Module()` instead of plain objects.

## How did you test this change?

Ran the unit tests successfully:

```
$ node --version
v18.16.1

$ yarn test
```
2024-03-29 13:19:54 -07:00
Jack Pope
6cd6ba703d Land enableNewBooleanProps everywhere (#28676)
Rolled out internally. Removing flag.
2024-03-29 16:02:32 -04:00
Timothy Yung
425f72bdd4 Align React Native OSS/Test Feature Flags (#28677)
## Summary

Makes a few changes to align React Native feature flags for open source
and internal test renderer configurations.

* Enable `enableSchedulingProfiler` for profiling builds.
* Align `ReactFeatureFlags.test-renderer.native.js` (with
`ReactFeatureFlags.native-fb.js`).
  * Enable `enableUseMemoCacheHook`.
  * Enable `enableFizzExternalRuntime`.
  * Disable `alwaysThrottleRetries`.

## How did you test this change?

Ran the following successfully:

```
$ yarn test
$ yarn flow native
$ yarn flow fabric
```
2024-03-29 12:47:00 -07:00
Jan Kassens
23b32d3f8d Test for ReactTestRenderer (#28674)
This is a repro for a breakage that #28672 would introduce for legacy
sync rendering.
2024-03-29 14:01:45 -04:00
Ricky
18812b645c Warn when using useFormState (#28668)
## Overview

useFormState has been replaced with useActionState. Warn when it's used.

Also removes the `experimental_useFormState` warnings.
2024-03-29 13:40:54 -04:00
Sophie Alpert
19c7c2929b Revert "Remove zoom from special cases list" (#28673)
Reverts facebook/react#26631

This got specced: https://github.com/w3c/csswg-drafts/pull/9699

I left msZoom because it seems plausible someone will still be using it
for backwards compat.
2024-03-29 10:39:12 -07:00
Andrey Lunyov
eb510a3304 Land enableCustomElementPropertySupport for React 19 (#27450)
We've rolled out this flag internally on WWW. This PR removed flag
`enableCustomElementPropertySupport`

Test plan:
 -- `yarn test`

Co-authored-by: Ricky Hanlon <rickhanlonii@gmail.com>
2024-03-29 13:06:07 -04:00
Lauren Tan
8d2cd323a4 Include package.json when bundling for oss
This was causing issues for an external partner's build pipeline which expected 
each package to have its own package.json.
2024-03-29 12:19:04 -04:00
Jan Kassens
a73c3450e1 Remove module pattern function component support (flag only) (#28671)
Remove module pattern function component support (flag only)

> This is a redo of #27742, but only including the flag removal,
excluding further simplifications.

The module pattern

```
function MyComponent() {
  return {
    render() {
      return this.state.foo
    }
  }
}
```

has been deprecated for approximately 5 years now. This PR removes
support for this pattern.
2024-03-29 11:16:17 -04:00
Ricky
f269074723 Revert "Remove module pattern function component support" (#28670)
This breaks internal tests, so must be something in the refactor. Since
it's the top commit let's revert and split into two PRs, one that
removes the flag and one that does the refactor, so we can find the bug.
2024-03-29 10:10:11 -04:00
Mofei Zhang
5656d5f078 [config] Change compiler defaults to prepare for oss 2024-03-29 09:31:09 -04:00
Josh Story
cc56bed38c Remove module pattern function component support (#27742)
The module pattern

```
function MyComponent() {
  return {
    render() {
      return this.state.foo
    }
  }
}
```

has been deprecated for approximately 5 years now. This PR removes
support for this pattern. It also simplifies a number of code paths in
particular related to the concept of `IndeterminateComponent` types.
2024-03-28 13:08:08 -07:00
Ricky
63651c49e0 Noop unstable_batchedUpdates (#28120)
## Overview

`unstable_batchedUpdates` is effectively a no-op outside of legacy mode,
this PR makes it an actual no-op outside legacy mode.
2024-03-28 14:15:37 -04:00
Marius Craciunoiu
78328c0c4d Add support for preload media to ReactDOM (#28635)
This PR adds support for `media` option to `ReactDOM.preload()`, which
is needed when images differ between screen sizes (for example mobile vs
desktop)
2024-03-28 10:04:59 -07:00
Ricky
05797ccebd s/form state/action state (#28631)
Rename internals from "form state" to "action state"
2024-03-28 11:34:24 -04:00
Josh Story
299a9c0598 [Fiber] Remove the digest property from errorInfo passed to onRecoverableError (#28222)
Removes the digest property from errorInfo passed to onRecoverableError
when handling an error propagated from the server. Previously we warned
in Dev but still provided the digest on the errorInfo object. This
change removes digest from error info but continues to warn if it is
accessed. The reason for retaining the warning is the version with the
warning was not released as stable but we will include this deprecated
removal in our next major so we should communicate this change at
runtime.
2024-03-28 08:01:35 -07:00
Lauren Tan
9d20aa2819 Don't compile node_modules on playground 2024-03-28 10:46:56 -04:00
Lauren Tan
7748ce8f3f Update compiler naming in remaining error text 2024-03-28 10:40:05 -04:00
Lauren Tan
df5ff9753a Fix jest script 2024-03-28 10:40:05 -04:00
Lauren Tan
f4229cdb7f Rename error type 2024-03-28 10:40:04 -04:00
Lauren Tan
638f8e3ddc Remove [ReactForget] prefix from error messages 2024-03-28 10:40:03 -04:00
Sebastian Markbåge
e10a7b5cd5 Don't log onRecoverableError if the current commit fail (#28665)
We didn't recover after all.

Currently we might log a recoverable error in the recovery pass. E.g.
the SSR server had an error. Then the client component fails to render
which errors again. This ends up double logging.

So if we fail to actually complete a fully successful commit, we ignore
any recoverable errors because we'll get real errors logged.

It's possible that this might cover up some other error that happened at
the same time.
2024-03-28 10:39:49 -04:00
Sebastian Markbåge
323b6e98a7 Remove errorHydratingContainer (#28664)
I originally added this in #21021 but I didn't mention why and I don't
quite remember why. Maybe because there were no other message? However
at the time the recoverable errors mechanism didn't exist.

Today I believe all cases where this happens will trigger another
recoverable error. Namely these two:


9f33f699e4/packages/react-reconciler/src/ReactFiberBeginWork.js (L1442-L1446)


9f33f699e4/packages/react-reconciler/src/ReactFiberBeginWork.js (L2962-L2965)

Therefore this is just an extra unnecessary log.
2024-03-27 23:48:18 -04:00
Mofei Zhang
5166869204 [patch] Fix control flow bug in PropagateScopeDeps
A dependency D from either an instruction or scope is poisoned if there may be a 
(non-linear) jump instruction between it and the start of its immediate parent 
scope. Poisoned dependencies are added as conditional dependencies to their 
parent scope. 

(done: reduce false positives in scopes that begin after return/throw) (done: 
fix bugs in recording and joining exhaustive conditional deps) (done: flesh out 
commit message, clean up PR, add more fixtures) 

--- \## Bug details: 

Take a simple example: ```js target: {   instrA;   if (...) {     instrB;     
break target;   } else {     instrC;   }   instrD;   // ... } instrE; // ... ``` 

This diagram shows how we represent this program in the reactive IR. - Blocks 
are represented as a list of nodes. - Green nodes show instructions and value 
blocks (simplified as a single instruction). - Pink nodes show terminals, which 
transfer control to a subtree of nodes. <img width="450" alt="image" 
src="https://github.com/facebook/react-forget/assets/34200447/930789f2-39cd-4ea8-b12a-530042807b46"> 

Prior to this PR, PropagateReactiveScopeDeps was incorrect because it assumed 
that a block's instructions are evaluated unconditionally (which is how HIR 
basic blocks work). E.g. if a reactive scope enclosed `block 1`, we assume that 
`instrA` and `instrD` both will evaluate unconditionally. 

This failed to account for `jump` instructions like break, continue, return, and 
throw. This may result in invalid hoisting of PropertyLoads (i.e. Forget output 
may throw when source does not throw). Note that other terminals (e.g. if and 
loops) are not affected as they are self contained subtrees that evaluate 
sequentially. 

With the changes in this PR, we mark `block 1` as poisoned upon encountering the 
`break` instruction. While `block 1` is active and poisoned, it will determine 
how visited dependencies are added. 

Here, added solid lines show unconditional dependencies, dashed lines show 
conditionally accessed dependencies: - dependencies from `instrB, instrC` are 
conditional because they are within conditional subtrees - dependencies from 
`instrD` are conditional because it is within a poisoned block within its parent 
scope. 

<img width="450" alt="image" 
src="https://github.com/facebook/react-forget/assets/34200447/81980f68-7e65-4bd7-ba94-3f0c26550e5c"> 

--- Recapping an offline discussion with @josephsavona: this pass would really 
benefit from operating on HIR. The minimal work needed for this pass to run on 
HIR is to rewrite and reorder  `AlignReactiveScopesToBlockScopes` to operate on 
HIR. 

The following diagram shows what HIR blocks look like for the same code. 
Evaluating hoistable PropertyLoad dependencies for a scope enclosing 
`instr{A-D}` is much simpler:  just evaluate whether the PropertyLoad evaluates 
for every path between `bb0` and `bb4`. <img width="250" alt="image" 
src="https://github.com/facebook/react-forget/assets/34200447/44b38939-defb-4b29-878d-4445ec6ccc06"> 

---
2024-03-27 20:26:18 -04:00
Mofei Zhang
b98b569017 [DeriveMinimalDeps] Account for conditional / poisoned accesses within
conditionals 

This change is needed for #2752. To minimize renaming `error.fixture` -> 
`fixture` files, I'm reordering this PR to earlier in the stack. 

Prior to the fix in #2752, we only expected unconditional accesses within 
`depsInCurrentConditional`, which records instructions directly within a 
conditional block (not including nested conditional blocks).
2024-03-27 20:26:18 -04:00
Mofei Zhang
2782fa2664 [rhir] Preserve block labels + target blockIds for break/continue terminals
RFC: we can either retain break/continue target ids (instead of pruning them in 
`buildReactiveFunction`) or re-implement the same logic in `propagateScopeDeps` 
(ignore implicit breaks; match unlabeled break / continues to their closest loop 
/ while parent terminal). 

If we go ahead with this approach, I'll clean up this PR (add relevant types and 
comments)
2024-03-27 20:26:17 -04:00
Mofei Zhang
877c490fa3 [visitors] Visit loop body before update 2024-03-27 20:26:16 -04:00
Mofei Zhang
1515cb3218 [be][sprout] Add ErrorBoundary to test exceptions in sequentialRenders 2024-03-27 20:26:15 -04:00
Mofei Zhang
4d37a599e3 [be][tests] Move PropagateScopeDep fixtures to separate directory 2024-03-27 20:26:14 -04:00
Mofei Zhang
a37f242f59 [be][DeriveMinimalDeps] Check current assumptions for conditional control flow 2024-03-27 20:26:13 -04:00
Sathya Gunasekaran
fd3ae0ca0a [type] Conservatively type return values from reanimated
Typing them as mixed read only seems safe because the fields are primitives but 
lets be conservative and type as Poly.
2024-03-28 12:32:25 +00:00
Sathya Gunasekaran
0a3d1c3d31 Add type defs for reanimated
The reanimated babel plugin specifically looks for args to their hooks that are 
callbacks, then it workletizes the body of that callback so it can run on the 
main thread. 

But, forget extracts that callback into a temporary variable and then replaces 
the previously inlined callback as an identifier, so that breaks reanimated's 
babel plugin. so what happens is some of the previously workletized functions no 
longer do after forget runs, which throws a runtime error about a non-worklet 
function running on the main thread. 

Reanimated expects this: ``` const animatedGProps = useAnimatedProp(function () 
{ ... }) ``` 

But forget does this: ``` const t0 =function () { ... } const animatedGProps = 
useAnimatedProp(t0) ``` 

With the type definitions, Forget no longer assumes the args to reanimated APIs 
escape so Forget does not memoize and they stay as is.
2024-03-28 12:26:22 +00:00
Sathya Gunasekaran
a6c6855dd1 [be] Remove unused properties arg from addHook
This is never used by any caller.
2024-03-28 12:26:22 +00:00
Ricky
9f33f699e4 Dymanic favorSafetyOverHydrationPerf (#28663)
For rollout
2024-03-27 17:43:25 -04:00
Josh Story
9ad40b1440 [react-dom] Remove findDOMNode from OSS builds (#28267)
In the next major `findDOMNode` is being removed. This PR removes the
API from the react-dom entrypoints for OSS builds and re-exposes the
implementation as part of internals.

`findDOMNode` is being retained for Meta builds and so all tests that
currently use it will continue to do so by accessing it from internals.
Once the replacement API ships in an upcoming minor any tests that were
using this API incidentally can be updated to use the new API and any
tests asserting `findDOMNode`'s behavior directly can stick around until
we remove it entirely (once Meta has moved away from it)
2024-03-27 14:43:12 -07:00
Josh Story
8436bcca62 [Fizz][Legacy] Remove renderToNodeStream (#28607)
Stacked on #28606 

renderToNodeStream has been deprecated since React 18 with a warning
indicating users should upgrade to renderToPipeableStream. This change
removes renderToNodeStream
2024-03-27 12:02:36 -07:00
Sebastian Silbermann
2b036d3f1f Deprecate act from react-dom/test-utils in favor of act from react (#28597) 2024-03-27 16:28:01 +01:00
Sebastian Silbermann
ec4d26ceb8 ReactDOM: Remove every test-util except act() (#28541) 2024-03-27 16:04:56 +01:00
Sebastian Silbermann
4cc0f8ee60 Remove orphaned disableJavaScriptURLs reference (#28660) 2024-03-27 14:53:42 +01:00
Sebastian Markbåge
a053716077 Make onUncaughtError and onCaughtError Configurable (#28641)
Stacked on #28627.

This makes error logging configurable using these
`createRoot`/`hydrateRoot` options:

```
onUncaughtError(error: mixed, errorInfo: {componentStack?: ?string}) => void
onCaughtError(error: mixed, errorInfo: {componentStack?: ?string, errorBoundary?: ?React.Component<any, any>}) => void
onRecoverableError(error: mixed, errorInfo: {digest?: ?string, componentStack?: ?string}) => void
```

We already have the `onRecoverableError` option since before.

Overriding these can be used to implement custom error dialogs (with
access to the `componentStack`).

It can also be used to silence caught errors when testing an error
boundary or if you prefer not getting logs for caught errors that you've
already handled in an error boundary.

I currently expose the error boundary instance but I think we should
probably remove that since it doesn't make sense for non-class error
boundaries and isn't very useful anyway. It's also unclear what it
should do when an error is rethrown from one boundary to another.

Since these are public APIs now we can implement the
ReactFiberErrorDialog forks using these options at the roots of the
builds. So I unforked those files and instead passed a custom option for
the native and www builds.

To do this I had to fork the ReactDOMLegacy file into ReactDOMRootFB
which is a duplication but that will go away as soon as the FB fork is
the only legacy root.
2024-03-27 00:51:37 -04:00
Ricky
9f8daa6cb5 [Breaking] Remove disableJavaScriptURLs (#28615)
## Overview

This has landed, so we can remove the flag

## Changelog

This change blocks using javascript URLs such as:

```html
<a href="javascript:notfine">p0wned</a>
```

We previously announced dropping support for this via a warning:

> A future version of React will block javascript: URLs as a security
precaution. Use event handlers instead if you can. If you need to
generate unsafe HTML try using dangerouslySetInnerHTML instead.
2024-03-26 23:45:34 -04:00
Sebastian Markbåge
6786563f3c [Fiber] Don't Rethrow Errors at the Root (#28627)
Stacked on top of #28498 for test fixes.

### Don't Rethrow

When we started React it was 1:1 setState calls a series of renders and
if they error, it errors where the setState was called. Simple. However,
then batching came and the error actually got thrown somewhere else.
With concurrent mode, it's not even possible to get setState itself to
throw anymore.

In fact, all APIs that can rethrow out of React are executed either at
the root of the scheduler or inside a DOM event handler.
If you throw inside a React.startTransition callback that's sync, then
that will bubble out of the startTransition but if you throw inside an
async callback or a useTransition we now need to handle it at the hook
site. So in 19 we need to make all React.startTransition swallow the
error (and report them to reportError).

The only one remaining that can throw is flushSync but it doesn't really
make sense for it to throw at the callsite neither because batching.
Just because something rendered in this flush doesn't mean it was
rendered due to what was just scheduled and doesn't mean that it should
abort any of the remaining code afterwards. setState is fire and forget.
It's send an instruction elsewhere, it's not part of the current
imperative code.

Error boundaries never rethrow. Since you should really always have
error boundaries, most of the time, it wouldn't rethrow anyway.

Rethrowing also actually currently drops errors on the floor since we
can only rethrow the first error, so to avoid that we'd need to call
reportError anyway. This happens in RN events.

The other issue with rethrowing is that it logs an extra console.error.
Since we're not sure that user code will actually log it anywhere we
still log it too just like we do with errors inside error boundaries
which leads all of these to log twice.
The goal of this PR is to never rethrow out of React instead, errors
outside of error boundaries get logged to reportError. Event system
errors too.

### Breaking Changes

The main thing this affects is testing where you want to inspect the
errors thrown. To make it easier to port, if you're inside `act` we
track the error into act in an aggregate error and then rethrow it at
the root of `act`. Unlike before though, if you flush synchronously
inside of act it'll still continue until the end of act before
rethrowing.

I expect most user code breakages would be to migrate from `flushSync`
to `act` if you assert on throwing.

However, in the React repo we also have `internalAct` and the
`waitForThrow` helpers. Since these have to use public production
implementations we track these using the global onerror or process
uncaughtException. Unlike regular act, includes both event handler
errors and onRecoverableError by default too. Not just render/commit
errors. So I had to account for that in our tests.

We restore logging an extra log for uncaught errors after the main log
with the component stack in it. We use `console.warn`. This is not yet
ignorable if you preventDefault to the main error event. To avoid
confusion if you don't end up logging the error to console I just added
`An error occurred`.

### Polyfill

All browsers we support really supports `reportError` but not all test
and server environments do, so I implemented a polyfill for browser and
node in `shared/reportGlobalError`. I don't love that this is included
in all builds and gets duplicated into isomorphic even though it's not
actually needed in production. Maybe in the future we can require a
polyfill for this.

### Follow Ups

In a follow up, I'll make caught vs uncaught error handling be
configurable too.

---------

Co-authored-by: Ricky Hanlon <rickhanlonii@gmail.com>
2024-03-26 23:44:07 -04:00
Sebastian Markbåge
5910eb3456 Add Flag to Favor Hydration Performance over User Safety (#28655)
If false, this ignores text comparison checks during hydration at the
risk of privacy safety.

Since React 18 we recreate the DOM starting from the nearest Suspense
boundary if any of the text content mismatches. This ensures that if we
have nodes that otherwise line up correctly such as if they're the same
type of Component but in a different order, then we don't accidentally
transfer state or attributes to the wrong one.

If we didn't do this e.g. attributes like image src might not line up
with the text. E.g. you might show the wrong profile picture with the
wrong name. However, the main reason we do this is because it's a
security/privacy concern if state from the original node can transfer to
the other one. For example if you start typing into a text field to
reply to a story but then it turns out that the hydration was in a
different order, you might submit that text into a different story than
you intended. Similarly, if you've already clicked an item and that gets
replayed using Action replaying or is synchronously force hydrated -
that click might end up applying to a different item in the list than
you intended. E.g. liking the wrong photo.

Unfortunately a common case where this happens is when Google Translate
is applied to a page. It'll always cause mismatches and recreate the
tree. Most of the time this wouldn't be visible to users because it'd
just recreate to the same thing and then translate again. It can affect
metrics that trace when this hydration happened though.

Meta can use this flag to decide if they favor this perf metric over the
risk to user privacy.

This is similar to the old enableClientRenderFallbackOnTextMismatch flag
except this flag doesn't patch up the text when there's a mismatch.
Because we don't have the patching anymore. The assumption is that it is
safe to ignore the safety concern because we assume it's a match and
therefore favoring not patching it will lead to better perf.
2024-03-26 22:52:46 -04:00
Sebastian Markbåge
2ec2aaea98 Add Diffs to Hydration Warnings (#28512)
Stacked on #28502.

This builds on the mechanism in #28502 by adding a diff of everything
we've collected so far to the thrown error or logged error.

This isn't actually a longest common subsequence diff. This means that
there are certain cases that can appear confusing such as a node being
added/removed when it really would've appeared later in the list. In
fact once a node mismatches, we abort rendering so we don't have the
context of what would've been rendered. It's not quite right to use the
result of the recovery render because it can use client-only code paths
using useSyncExternalStore which would yield false differences. That's
why diffing the HTML isn't quite right.

I also present abstract components in the stack, these are presented
with the client props and no diff since we don't have the props that
were on the server. The lack of difference might be confusing but it's
useful for context.

The main thing that's data new here is that we're adding some siblings
and props for context.

Examples in the [snapshot
commit](e14532fd8d).
2024-03-26 20:02:18 -04:00
Sebastian Markbåge
f7aa5e0aa3 Move Hydration Mismatch Errors to Throw or Log Once (Kind of) (#28502)
Stacked on #28476.

We used to `console.error` for every mismatch we found, up until the
error we threw for the hydration mismatch.

This changes it so that we build up a set of diffs up until we either
throw or complete hydrating the root/suspense boundary. If we throw, we
append the diff to the error message which gets passed to
onRecoverableError (which by default is also logged to console). If we
complete, we append it to a `console.error`.

Since we early abort when something throws, it effectively means that we
can only collect multiple diffs if there were preceding non-throwing
mismatches - i.e. only properties mismatched but tag name matched.

There can still be multiple logs if multiple siblings Suspense
boundaries all error hydrating but then they're separate errors
entirely.

We still log an extra line about something erroring but I think the goal
should be that it leads to a single recoverable or console.error.

This doesn't yet actually print the diff as part of this message. That's
in a follow up PR.
2024-03-26 20:01:41 -04:00
Sebastian Markbåge
4b8dfd6215 Move Hydration Warnings from the DOM Config into the Fiber reconciliation (#28476)
Stacked on #28458.

This doesn't actually really change the messages yet, it's just a
refactor.

Hydration warnings can be presented either as HTML or React JSX format.
If presented as HTML it makes more sense to make that a DOM specific
concept, however, I think it's actually better to present it in terms of
React JSX.

Most of the time the errors aren't going to be something messing with
them at the HTML/HTTP layer. It's because the JS code does something
different. Most of the time you're working in just React. People don't
necessarily even know what the HTML form of it looks like. So this takes
the approach that the warnings are presented in React JSX in their rich
object form.

Therefore, I'm moving the approach to yield diff data to the reconciler
but it's the reconciler that's actually printing all the warnings.
2024-03-26 19:04:18 -04:00
Jack Pope
bb66aa3cef Use concurrent root in RTR (#28498)
Based on
- https://github.com/facebook/react/pull/28497
- https://github.com/facebook/react/pull/28419

Reusing the disableLegacyMode flag, we set ReactTestRenderer to always
render with concurrent root where legacy APIs are no longer available.
If disableLegacyMode is false, we continue to allow the
unstable_isConcurrent option determine the root type.

Also checking a global `IS_REACT_NATIVE_TEST_ENVIRONMENT` so we can
maintain the existing behavior for RN until we remove legacy root
support there.
2024-03-26 18:53:09 -04:00
Jack Pope
1f9befef5c Remove react-test-renderer/shallow export (#28497)
Based on
- https://github.com/facebook/react/pull/28419

## Summary

The shallow renderer was extracted from the repo years ago and published
by enzyme: https://github.com/enzymejs/react-shallow-renderer

We no longer need to reexport under the react-test-renderer namespace.
People can import `react-shallow-renderer` as needed

## How did you test this change?

- Observe shallow.js in react-test-renderer package from standard build
- Run build with changes on this branch
- Observe no more shallow.js export in build output
2024-03-26 18:04:47 -04:00
Sebastian Markbåge
84c84d72f1 Remove enableClientRenderFallbackOnTextMismatch flag (#28458)
Build on top of #28440.

This lets us remove the path where updates are tracked on differences in
text.
2024-03-26 17:55:14 -04:00
Jack Pope
f73d11f092 [RTR] Enable warning flag (#28419)
## Summary

Based on
- https://github.com/facebook/react/pull/27903

This PR
- Silence warning in React tests
- Turn on flag

We want to finish cleaning up internal RTR usage, but let's prioritize
the deprecation process. We do this by silencing the internal warning
for now.

## How did you test this change?

`yarn build`
`yarn test ReactHooksInspectionIntegration -b`
2024-03-26 17:44:31 -04:00
Sebastian Markbåge
670d61bea2 Remove legacy hydration mode (#28440)
While Meta is still using legacy mode and we can't remove completely,
Meta is not using legacy hydration so we should be able to remove that.

This is just the first step. Once removed, we can vastly simplify the
DOMConfig for hydration.

This will have to be rebased when tests are upgraded.
2024-03-26 17:41:49 -04:00
Ricky
dbfbfb3312 Update error messages (#28652)
## Overview

The error messages that say:

> ReactDOM.hydrate is no longer supported in React 18

Don't make sense in the React 19 release. Instead, they should say:

> ReactDOM.hydrate was removed in React 19.

For legacy mode, they should say:

> ReactDOM.hydrate has not been supported since React 18.
2024-03-26 17:25:53 -04:00
Sebastian Markbåge
f24cf4a1af Remove zoom from special cases list (#26631)
Looks like [it's getting removed
anyway](https://groups.google.com/a/chromium.org/g/blink-dev/c/V7q43bgutbo/m/-7jneTl8CQAJ?pli=1).

Maybe should wait for a major though.
2024-03-26 17:19:02 -04:00
Ricky
1a6d36b1a3 Remove unmountComponentAtNode outside of legacy mode (#28650) 2024-03-26 16:32:43 -04:00
Joe Savona
91f7bc8be7 Ensure valid mutable ranges for all scopes; fix ranges for context vars
Our current validation fails to detect some invalid cases of mutable ranges — 
namely, ranges that are fully or partially uninitialized, with start or 
start+end still set to zero. 

This PR fixes these cases, starting by validating that the ranges for _all_ 
reactive scopes are valid: start >= 1, and end <= (last instr id + 1). This 
exposed the invalid cases, which are also fixed here: 

* During AnalyzeFunctions, we need to reset identifier ranges and scopes when 
exiting an inner function. This has to happen *after* the effects have been 
translated to the function deps/context operands, in order for 
InferRefenceEffects to continue working on the outer function. Previously I did 
this at the start of InferReactiveScopeVariables, but that's insufficient bc the 
incorrect ranges could also influence InferMutableRanges. AnalyzeFunctions is 
the point at which we compute the ranges for identifiers in the inner function, 
so it's the most ideal place to clean those up so they don't influence the outer 
function. 

* In InferMutableLifetimes, we need to ensure that context variable identifiers 
end up with a mutable range starting where they are declared, and ending with 
their last assignment. We now track declarations and extend their mutable range 
to account for each reassignment.
2024-03-26 13:29:24 -07:00
Andrew Clark
56efb2e227 Bump canary versions to v19-canary (#28646)
This bumps the canary versions to v19 to communicate that the next
release will be a major. Once this lands, we can start merging breaking
changes into `main`.
2024-03-26 15:31:57 -04:00
Jack Pope
738993da0b Turn on enableRenderableContext in experimental (#28645)
Let's get this into experimental to get more usage and allow other
renderers to test against the changes easier.
2024-03-26 14:17:43 -04:00
Ricky
0a44435674 Add useActionState to CHANGELOG-canary.md (#28632)
Co-authored-by: Sébastien Lorber <slorber@users.noreply.github.com>
2024-03-26 13:15:08 -04:00
Timothy Yung
6fd0cb9a9f Cleanup alwaysThrottleDisappearingFallbacks Flag (#28639)
## Summary

After realizing that this feature flag is entangled with
`alwaysThrottleRetries`, we're going to undo
https://github.com/facebook/react/pull/28550

## How did you test this change?

```
$ yarn test
$ yarn flow dom-browser
$ yarn flow dom-fb
$ yarn flow fabric
```
2024-03-26 10:01:38 -07:00
Jan Kassens
95319ab5af Switch facebook-www build version to file content hash (#28633)
Unifies the React version string pattern with RN just to simplify the
build script a tiny bit and not have 2 mechanisms for the Meta-internal
build.
2024-03-26 12:13:46 -04:00
Ricky
c3048aab4c Fix tests on main (#28643)
Not sure how these broke when merging
https://github.com/facebook/react/pull/28299 and
https://github.com/facebook/react/pull/28361
2024-03-26 11:26:42 -04:00
Ruslan Lesiutin
75de4ff72a fix[devtools/ci]: split profiling cache test for different react versions and toEqual checker (#28628)
This should fix the failing backwards-compatibility tests on CI:
-
https://app.circleci.com/pipelines/github/facebook/react/51347/workflows/9d319db5-7a29-4e9a-a3a0-8d49a24ee9bd/jobs/809381
-
https://app.circleci.com/pipelines/github/facebook/react/51347/workflows/9d319db5-7a29-4e9a-a3a0-8d49a24ee9bd/jobs/809386

Started failing after https://github.com/facebook/react/pull/27991.

Brief summary:
1. Revert changes to `profilingCache-test` in
https://github.com/facebook/react/pull/27991.
2. Scope previous test to react versions 16.9 - 18.2
3. Add a new test for react versions > 18.2 (includes testing react from
souce), which is also gated with `!disableLegacyContext`.

> [!IMPORTANT]
> `@gate` pragma expects the test to throw. Jest doesn't throw any
exceptions when snapshots are mismatched, this is why I've migrated test
from `toMatchInlineSnapshot` checker to `toEqual`.
> If the test doesn't throw, we will fail it manually:
>
5a75f9e785/scripts/jest/setupTests.js (L291-L295)
2024-03-26 10:55:07 +00:00
Joe Savona
fbd68eef7f Fix for invalid mutable range in phi with backedge
Fixes the repro added in 947832009997bf9149e88e583c46cc39f6a6136c - previously 
when computing mutable ranges of phis, we didn't check that all operands had 
been visited. This meant that a backedge could allow a phi's mutable range to 
start at 0. Then in PropagateScopeDeps, we might see reject dependencies of a 
scope since they appeared to start after a scope — only because the scope's 
start was incorrectly too early. 

The fix here is to initially set phi.id mutable ranges based on only on operands 
that are already visited. Then, during/after the fixpoint iteration of 
InferMutableRanges, we start account for all operands since we know they've been 
visited at least once and have a real range.
2024-03-25 21:36:33 -07:00
Ricky
07def0cc5a Add test for throttling suspended siblings (#28361)
# Overview

Adds a test to show the combination of the new throttling behavior and
not pre-rendering siblings results in pushing out content that could
have rendered much faster.

- Without the new throttling, the sibling content would render in 30ms.
- Without removing pre-rendering, the sibling content would render in
0ms.
- With both, the sibling content takes 600ms.

## Example


https://github.com/facebook/react/assets/2440089/abd62dc4-93f9-4b7b-a5aa-b795827c1a3a
2024-03-26 00:02:46 -04:00
Ricky
67e6fa6d17 Test for suspending with modern strict mode (#28513)
## Overview

Adds a test to show the cause of an infinite loop in Relay related to
[these effects in
Relay](448aa67d2a/packages/react-relay/relay-hooks/useLazyLoadQueryNode.js (L77-L104))
and `useModernStrictMode`. The bug is related to effect behavior when
committing trees that re-suspend after initial mount.

With `useModernStrictEffect`, when you:
- initial mount
- update
- suspend (to fallbacks)
- resolve
- re-commit

We fire strict effects during the second mount, like it's a new tree.
This creates weird cases, where if there was an update while we
suspended, we'll first fire only the effects that changed dependencies,
and then fire strict effects.

Creating a test to demonstrate the behavior to see if it's a bug.
2024-03-26 00:02:16 -04:00
Ricky
d3037405c4 Test showing mismatches after suspending force fallbacks to be shown (#28299)
While investigating https://github.com/facebook/react/issues/28285 I
found a possible bug in handling Suspense and mismatches. As the tests
show, if the first sibling in a boundary suspends, and the second has a
mismatch, we will NOT show a fallback. If the first sibling is a
mismatch, and the second sibling suspends, we WILL show a fallback.

[Here's a stackbliz showing the behavior on
Canary](https://stackblitz.com/edit/stackblitz-starters-bh3snf?file=src%2Fstyle.css,public%2Findex.html,src%2Findex.tsx).

This breakage was introduced by:
https://github.com/facebook/react/pull/26380. Before this PR, we would
not show a fallback in either case. That PR makes it so that we don't
pre-render siblings of suspended trees, so presumably, whatever
detection we had to avoid fallbacks on mismatches, requires knowing
there's a mismatch in the tree when we suspend.
2024-03-25 20:33:31 -04:00
Joe Savona
48ecaf92d5 Reset scopes from AnalyzeFunctions in InferReactiveScopeVariables
Updates InferReactiveScopeVariables to first prune scopes attached during 
AnalyzeFunctions. This ensures that after this pass the only scopes that exist 
on identifiers in the outer program are those that the pass explicitly inferred, 
and not accidentally leftover.
2024-03-25 15:31:23 -07:00
Joe Savona
29ab0f835e Repro for scopes from AnalyzeFunction influencing outer compilation
We share identifiers between outer functions and inner function expressions, 
which means that scopes inferred during AnalyzeFunctions can be retained on 
Identifiers in the outer function. If InferReactiveScopeVariables doesn't happen 
to visit an identifier we currently retain that scope information and use it 
when constructing scopes, even if there doesn't technically need to be a scope 
for that value. 

Fixed in the next PR.
2024-03-25 15:31:22 -07:00
Lauren Tan
e6ce5e4922 [eslint] Update devDep to match types 2024-03-25 15:00:34 -04:00
Lauren Tan
15abd38911 Cleanup unused eslint-browser and js-fuzzer packages
These were never used, so let's clean them up
2024-03-25 15:00:31 -04:00
Jan Kassens
5a75f9e785 Make enableBigIntSupport a dynamic flag for Meta (#28617)
Make enableBigIntSupport a dynamic flag for Meta

Should be an easy launch, but let's make this a dynamic flag to be safe.
2024-03-25 13:48:22 -04:00
dependabot[bot]
50cdf158d8 Bump webpack-dev-middleware from 5.3.3 to 5.3.4 in /fixtures/flight (#28618)
Bumps
[webpack-dev-middleware](https://github.com/webpack/webpack-dev-middleware)
from 5.3.3 to 5.3.4.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a
href="https://github.com/webpack/webpack-dev-middleware/releases">webpack-dev-middleware's
releases</a>.</em></p>
<blockquote>
<h2>v5.3.4</h2>
<h3><a
href="https://github.com/webpack/webpack-dev-middleware/compare/v5.3.3...v5.3.4">5.3.4</a>
(2024-03-20)</h3>
<h3>Bug Fixes</h3>
<ul>
<li><strong>security:</strong> do not allow to read files above (<a
href="https://redirect.github.com/webpack/webpack-dev-middleware/issues/1779">#1779</a>)
(<a
href="189c4ac7d2">189c4ac</a>)</li>
</ul>
</blockquote>
</details>
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a
href="https://github.com/webpack/webpack-dev-middleware/blob/v5.3.4/CHANGELOG.md">webpack-dev-middleware's
changelog</a>.</em></p>
<blockquote>
<h3><a
href="https://github.com/webpack/webpack-dev-middleware/compare/v5.3.3...v5.3.4">5.3.4</a>
(2024-03-20)</h3>
<h3>Bug Fixes</h3>
<ul>
<li><strong>security:</strong> do not allow to read files above (<a
href="https://redirect.github.com/webpack/webpack-dev-middleware/issues/1779">#1779</a>)
(<a
href="189c4ac7d2">189c4ac</a>)</li>
</ul>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="86071ead69"><code>86071ea</code></a>
chore(release): 5.3.4</li>
<li><a
href="189c4ac7d2"><code>189c4ac</code></a>
fix(security): do not allow to read files above (<a
href="https://redirect.github.com/webpack/webpack-dev-middleware/issues/1779">#1779</a>)</li>
<li>See full diff in <a
href="https://github.com/webpack/webpack-dev-middleware/compare/v5.3.3...v5.3.4">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=webpack-dev-middleware&package-manager=npm_and_yarn&previous-version=5.3.3&new-version=5.3.4)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)
You can disable automated security fix PRs for this repo from the
[Security Alerts
page](https://github.com/facebook/react/network/alerts).

</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-03-25 13:37:11 -04:00
dependabot[bot]
b35be36fb4 Bump webpack-dev-middleware from 5.3.3 to 5.3.4 (#28621)
Bumps
[webpack-dev-middleware](https://github.com/webpack/webpack-dev-middleware)
from 5.3.3 to 5.3.4.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a
href="https://github.com/webpack/webpack-dev-middleware/releases">webpack-dev-middleware's
releases</a>.</em></p>
<blockquote>
<h2>v5.3.4</h2>
<h3><a
href="https://github.com/webpack/webpack-dev-middleware/compare/v5.3.3...v5.3.4">5.3.4</a>
(2024-03-20)</h3>
<h3>Bug Fixes</h3>
<ul>
<li><strong>security:</strong> do not allow to read files above (<a
href="https://redirect.github.com/webpack/webpack-dev-middleware/issues/1779">#1779</a>)
(<a
href="189c4ac7d2">189c4ac</a>)</li>
</ul>
</blockquote>
</details>
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a
href="https://github.com/webpack/webpack-dev-middleware/blob/v5.3.4/CHANGELOG.md">webpack-dev-middleware's
changelog</a>.</em></p>
<blockquote>
<h3><a
href="https://github.com/webpack/webpack-dev-middleware/compare/v5.3.3...v5.3.4">5.3.4</a>
(2024-03-20)</h3>
<h3>Bug Fixes</h3>
<ul>
<li><strong>security:</strong> do not allow to read files above (<a
href="https://redirect.github.com/webpack/webpack-dev-middleware/issues/1779">#1779</a>)
(<a
href="189c4ac7d2">189c4ac</a>)</li>
</ul>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="86071ead69"><code>86071ea</code></a>
chore(release): 5.3.4</li>
<li><a
href="189c4ac7d2"><code>189c4ac</code></a>
fix(security): do not allow to read files above (<a
href="https://redirect.github.com/webpack/webpack-dev-middleware/issues/1779">#1779</a>)</li>
<li>See full diff in <a
href="https://github.com/webpack/webpack-dev-middleware/compare/v5.3.3...v5.3.4">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=webpack-dev-middleware&package-manager=npm_and_yarn&previous-version=5.3.3&new-version=5.3.4)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)
You can disable automated security fix PRs for this repo from the
[Security Alerts
page](https://github.com/facebook/react/network/alerts).

</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-03-25 13:36:03 -04:00
Jan Kassens
527ed72bfd Cleanup enableFormActions flag (#28614)
Cleanup enableFormActions flag
2024-03-25 13:25:14 -04:00
Sathya Gunasekaran
70302048a0 Update yarn.lock 2024-03-25 16:41:13 +00:00
Sebastian Silbermann
e373190faf Guard against legacy context not being supported in DevTools fixture (#28596) 2024-03-25 14:30:08 +01:00
Ricky
0711ff1763 Add Type: Feature Request to stalebot ignore (#28625)
Prevent issues like https://github.com/facebook/react/issues/12525 from
closing due to inactivity.
2024-03-24 12:48:12 -04:00
Joe Savona
2ce112dbf2 Repro for missing dep with while/if using externally declared "index" variable
What happens here is that the phi node for `i` has its mutable range set to 
start at 0, because it has a back edge and we haven't initialized the mutable 
ranges of all its operands yet when we iterate the operands and set range.start 
= min(start of operand starts). 

Then the corresponding scope has its range set to start at 0 too. When 
PropagateScopeDeps runs it sees that `b` is from instruction 1, which is after 
the start of the scope (0), so it thinks `b` isn't a valid dependency. 

The fix is in InferMutableRanges, where we need to make sure that phis ignore 
their operand's ranges until those ranges are initialized.
2024-03-22 21:49:39 -07:00
Sathya Gunasekaran
db7e7c7fae Support method call when validating useEffect
Treat MethodCall similarly to CallExpression when validation useEffect
2024-03-22 23:42:27 +00:00
Lauren Tan
1f45b13fda Update yarn.lock 2024-03-22 18:59:44 -04:00
Joe Savona
200d2c379d Fix for loops with value block index initial value 2024-03-22 14:51:36 -07:00
Joe Savona
f4ff1a28e7 Fix for destructuring with partial context variables 2024-03-22 14:32:50 -07:00
Joe Savona
73fa712108 Repro for destructuring with partial context variables 2024-03-22 14:32:47 -07:00
Jan Kassens
d7d82e7bee Correct eslint-plugin-react-compiler dependencies
Correct eslint-plugin-react-compiler dependencies 

- The eslint plugin doesn't actually depend on the babel plugin as it compiles 
in the dependencies. - `zod` and `zod-validation-error` were missing, but 
required to run the plugin. - Update to the `hermes-parser` dependency just to 
keep it updated.
2024-03-22 17:03:30 -04:00
Joe Savona
4575c8a5f6 Detect hoisting where the reference is a reassignment
Our logic to detect hoisting relies on Babel's `isReferencedIdentifier()` to 
determine whether a reference to an identifier is a reference or a declaration. 
The idea is that we want to find references to variables that may be hoistable, 
before the declaration — the definition of hoisting. But due to the bug in 
isReferencedIdentifier, we skipped over reassignments of hoisted variables. The 
hack here checks if an identifier is a direct child of an AssignmentExpression, 
ensuring we visit reassignments.
2024-03-22 13:49:50 -07:00
Joe Savona
fb0f7e5c39 Repro for closures reassigning hoisted let variables
Adds examples for closures that reassign hoisted let bindings. We currently 
compile these as context variables without hoisting, so we hit an invariant in 
InferReferenceEffects when the variable is referenced before being declared.
2024-03-22 11:53:29 -07:00
Joe Savona
e7d0c81d13 Add todo for for loops with context iterator variable
Detect the previous case — for loops where the iterator is a context variables — 
and throw a todo rather than hitting the invariant.
2024-03-22 11:46:28 -07:00
Jan Kassens
f09e1599d6 Fix test after merge conflict (#28616)
Something went wrong when rebasing #28491  and renaming the hook.
2024-03-22 14:05:55 -04:00
Ricky
5c65b27587 Add React.useActionState (#28491)
## Overview

_Depends on https://github.com/facebook/react/pull/28514_

This PR adds a new React hook called `useActionState` to replace and
improve the ReactDOM `useFormState` hook.

## Motivation

This hook intends to fix some of the confusion and limitations of the
`useFormState` hook.

The `useFormState` hook is only exported from the `ReactDOM` package and
implies that it is used only for the state of `<form>` actions, similar
to `useFormStatus` (which is only for `<form>` element status). This
leads to understandable confusion about why `useFormState` does not
provide a `pending` state value like `useFormStatus` does.

The key insight is that the `useFormState` hook does not actually return
the state of any particular form at all. Instead, it returns the state
of the _action_ passed to the hook, wrapping it and returning a
trackable action to add to a form, and returning the last returned value
of the action given. In fact, `useFormState` doesn't need to be used in
a `<form>` at all.

Thus, adding a `pending` value to `useFormState` as-is would thus be
confusing because it would only return the pending state of the _action_
given, not the `<form>` the action is passed to. Even if we wanted to
tie them together, the returned `action` can be passed to multiple
forms, creating confusing and conflicting pending states during multiple
form submissions.

Additionally, since the action is not related to any particular
`<form>`, the hook can be used in any renderer - not only `react-dom`.
For example, React Native could use the hook to wrap an action, pass it
to a component that will unwrap it, and return the form result state and
pending state. It's renderer agnostic.

To fix these issues, this PR:
- Renames `useFormState` to `useActionState`
- Adds a `pending` state to the returned tuple
- Moves the hook to the `'react'` package

## Reference

The `useFormState` hook allows you to track the pending state and return
value of a function (called an "action"). The function passed can be a
plain JavaScript client function, or a bound server action to a
reference on the server. It accepts an optional `initialState` value
used for the initial render, and an optional `permalink` argument for
renderer specific pre-hydration handling (such as a URL to support
progressive hydration in `react-dom`).

Type:

```ts
function useActionState<State>(
        action: (state: Awaited<State>) => State | Promise<State>,
        initialState: Awaited<State>,
        permalink?: string,
    ): [state: Awaited<State>, dispatch: () => void, boolean];
```

The hook returns a tuple with:
- `state`: the last state the action returned
- `dispatch`: the method to call to dispatch the wrapped action
- `pending`: the pending state of the action and any state updates
contained

Notably, state updates inside of the action dispatched are wrapped in a
transition to keep the page responsive while the action is completing
and the UI is updated based on the result.

## Usage

The `useActionState` hook can be used similar to `useFormState`:

```js
import { useActionState } from "react"; // not react-dom

function Form({ formAction }) {
  const [state, action, isPending] = useActionState(formAction);

  return (
    <form action={action}>
      <input type="email" name="email" disabled={isPending} />
      <button type="submit" disabled={isPending}>
        Submit
      </button>
      {state.errorMessage && <p>{state.errorMessage}</p>}
    </form>
  );
}
```

But it doesn't need to be used with a `<form/>` (neither did
`useFormState`, hence the confusion):

```js
import { useActionState, useRef } from "react";

function Form({ someAction }) {
  const ref = useRef(null);
  const [state, action, isPending] = useActionState(someAction);

  async function handleSubmit() {
    // See caveats below
    await action({ email: ref.current.value });
  }

  return (
    <div>
      <input ref={ref} type="email" name="email" disabled={isPending} />
      <button onClick={handleSubmit} disabled={isPending}>
        Submit
      </button>
      {state.errorMessage && <p>{state.errorMessage}</p>}
    </div>
  );
}
```

## Benefits

One of the benefits of using this hook is the automatic tracking of the
return value and pending states of the wrapped function. For example,
the above example could be accomplished via:

```js
import { useActionState, useRef } from "react";

function Form({ someAction }) {
  const ref = useRef(null);
  const [state, setState] = useState(null);
  const [isPending, setIsPending] = useTransition();

  function handleSubmit() {
    startTransition(async () => {
      const response = await someAction({ email: ref.current.value });
      setState(response);
    });
  }

  return (
    <div>
      <input ref={ref} type="email" name="email" disabled={isPending} />
      <button onClick={handleSubmit} disabled={isPending}>
        Submit
      </button>
      {state.errorMessage && <p>{state.errorMessage}</p>}
    </div>
  );
}
```

However, this hook adds more benefits when used with render specific
elements like react-dom `<form>` elements and Server Action. With
`<form>` elements, React will automatically support replay actions on
the form if it is submitted before hydration has completed, providing a
form of partial progressive enhancement: enhancement for when javascript
is enabled but not ready.

Additionally, with the `permalink` argument and Server Actions,
frameworks can provide full progressive enhancement support, submitting
the form to the URL provided along with the FormData from the form. On
submission, the Server Action will be called during the MPA navigation,
similar to any raw HTML app, server rendered, and the result returned to
the client without any JavaScript on the client.

## Caveats
There are a few Caveats to this new hook:
**Additional state update**: Since we cannot know whether you use the
pending state value returned by the hook, the hook will always set the
`isPending` state at the beginning of the first chained action,
resulting in an additional state update similar to `useTransition`. In
the future a type-aware compiler could optimize this for when the
pending state is not accessed.

**Pending state is for the action, not the handler**: The difference is
subtle but important, the pending state begins when the return action is
dispatched and will revert back after all actions and transitions have
settled. The mechanism for this under the hook is the same as
useOptimisitic.

Concretely, what this means is that the pending state of
`useActionState` will not represent any actions or sync work performed
before dispatching the action returned by `useActionState`. Hopefully
this is obvious based on the name and shape of the API, but there may be
some temporary confusion.

As an example, let's take the above example and await another action
inside of it:

```js
import { useActionState, useRef } from "react";

function Form({ someAction, someOtherAction }) {
  const ref = useRef(null);
  const [state, action, isPending] = useActionState(someAction);

  async function handleSubmit() {
    await someOtherAction();

    // The pending state does not start until this call.
    await action({ email: ref.current.value });
  }

  return (
    <div>
      <input ref={ref} type="email" name="email" disabled={isPending} />
      <button onClick={handleSubmit} disabled={isPending}>
        Submit
      </button>
      {state.errorMessage && <p>{state.errorMessage}</p>}
    </div>
  );
}

```

Since the pending state is related to the action, and not the handler or
form it's attached to, the pending state only changes when the action is
dispatched. To solve, there are two options.

First (recommended): place the other function call inside of the action
passed to `useActionState`:

```js
import { useActionState, useRef } from "react";

function Form({ someAction, someOtherAction }) {
  const ref = useRef(null);
  const [state, action, isPending] = useActionState(async (data) => {
    // Pending state is true already.
    await someOtherAction();
    return someAction(data);
  });

  async function handleSubmit() {
    // The pending state starts at this call.
    await action({ email: ref.current.value });
  }

  return (
    <div>
      <input ref={ref} type="email" name="email" disabled={isPending} />
      <button onClick={handleSubmit} disabled={isPending}>
        Submit
      </button>
      {state.errorMessage && <p>{state.errorMessage}</p>}
    </div>
  );
}
```

For greater control, you can also wrap both in a transition and use the
`isPending` state of the transition:

```js
import { useActionState, useTransition, useRef } from "react";

function Form({ someAction, someOtherAction }) {
  const ref = useRef(null);

  // isPending is used from the transition wrapping both action calls.
  const [isPending, startTransition] = useTransition();

  // isPending not used from the individual action.
  const [state, action] = useActionState(someAction);

  async function handleSubmit() {
    startTransition(async () => {
      // The transition pending state has begun.
      await someOtherAction();
      await action({ email: ref.current.value });
    });
  }

  return (
    <div>
      <input ref={ref} type="email" name="email" disabled={isPending} />
      <button onClick={handleSubmit} disabled={isPending}>
        Submit
      </button>
      {state.errorMessage && <p>{state.errorMessage}</p>}
    </div>
  );
}
```

A similar technique using `useOptimistic` is preferred over using
`useTransition` directly, and is left as an exercise to the reader.

## Thanks

Thanks to @ryanflorence @mjackson @wesbos
(https://github.com/facebook/react/issues/27980#issuecomment-1960685940)
and [Allan
Lasser](https://allanlasser.com/posts/2024-01-26-avoid-using-reacts-useformstatus)
for their feedback and suggestions on `useFormStatus` hook.
2024-03-22 13:03:44 -04:00
Ricky
fabd6d3a64 Better NEXT_MAJOR support for RN flags (#28583)
The `__NEXT_MAJOR__` value in the RN flags doesn't make sense because:

a) The flags are for the next RN major, since it only impacts the
renderers
b) The flags are off, so they're not currently in the next major, they
need enabled
c) the flag script didn't support it

This PR adds two aliases to the RN file:
- `__TODO_NEXT_RN_MAJOR__`: flags that need enabled before the next RN
major.
- `__NEXT_RN_MAJOR__`: flags that have been enabled since the last RN
major.

These values will need to be manually kept up to date when we cut a RN
version, but once RN switches to the canary build and aligns all the
flags, this entire file can be deleted.

## Script screen
Notably, I added a TODO value and a legend that prints at the end of the
script:

<img width="1078" alt="Screenshot 2024-03-18 at 8 11 27 PM"
src="https://github.com/facebook/react/assets/2440089/14da9066-f77d-437f-8188-830a31a843c5">
2024-03-22 13:02:04 -04:00
Ricky
fa0efa1ae3 Update RN dynamic flag types (#28427)
Updates the RN flag flow types to work like www does, so we can use the
`.native-fb-dynamic.js` file as the type/shim for the dynamically
imported file.
2024-03-22 12:23:38 -04:00
Jan Kassens
208ceeb46c Cleanup enableFloat flag (#28613)
Cleanup enableFloat flag
2024-03-22 12:22:30 -04:00
Joe Savona
bc516409a6 Repro of for loop with context variable iterator variable
`let` bindings of context variables are lowered to a DeclareContext + 
StoreContext, which breaks codegen for `for` loops which expect that all 
statements of the init block will lower to variable declarations. The two 
instructions produce a variable declaration and a reassignment.
2024-03-22 09:15:29 -07:00
Joe Savona
7dc08d79be PropagateScopeDeps treats switch w only default as unconditional
If we have a switch with only a default case, then that code will be executed 
unconditionally. PropagateScopeDeps can take advantage of this to record 
dependencies in these cases as unconditional, which avoids the issue seen in the 
previous PR.
2024-03-22 09:02:56 -07:00
Joe Savona
3229302222 Repro for "expect trees to be >=2 elements long" invariant
These cases have a switch with only a default, so we create a "conditional" 
child dependency tree and no other trees which hits the invariant.
2024-03-22 08:53:30 -07:00
Mofei Zhang
ee93b62f51 [ez] Patch BuildHIR to match unlabeled breaks to switch and loops 2024-03-22 16:34:09 -04:00
Mofei Zhang
f6472522da [repro] Fixture for incorrect lowering for break (label within loop)
--- 

unlabeled breaks must goto the nearest iteration or switch boundary (not labeled 
block) 

--- 

Sprout fails with the following: 

``` 

FAIL: bug-unlabeled-break-within-label-loop 

>> Unexpected error during test: 

Found differences in evaluator results 

Non-forget (expected): 

(kind: ok) ["0 @A","0 @B","0 @C","1 @A"] 

Forget: 

(kind: ok) ["0 @A","0 @B","0 @C","1 @A","1 @C"] 

```
2024-03-22 16:14:35 -04:00
Jan Kassens
6708115937 Use declare const instead of declare var (#28599)
Use `declare const` instead of `declare var`
2024-03-22 11:20:18 -04:00
Sebastian Markbåge
fee786a057 [Fizz] Recover from errors thrown by progressive enhancement form generation (#28611)
This a follow up to #28564. It's alternative to #28609 which takes
#28610 into account.

It used to be possible to return JSX from an action with
`useActionState`.

```js
async function action(errors, payload) {
  "use server";
  try {
    ...
  } catch (x) {
    return <div>Error message</div>;
  }
}
```

```js
const [errors, formAction] = useActionState(action);
return <div>{errors}</div>;
```

Returning JSX from an action is itself not anything problematic. It's
that it also has to return the previous state to the action reducer
again that's the problem. When this happens we accidentally could
serialize an Element back to the server.

I fixed this in #28564 so it's now blocked if you don't have a temporary
reference set.

However, you can't have that for the progressive enhancement case. The
reply is eagerly encoded as part of the SSR render. Typically you
wouldn't have these in the initial state so the common case is that they
show up after the first POST back that yields an error and it's only in
the no-JS case where this happens so it's hard to discover.

As noted in #28609 there's a security implication with allowing elements
to be sent across this kind of payload, so we can't just make it work.

When an error happens during SSR our general policy is to try to recover
on the client instead. After all, SSR is mainly a perf optimization in
React terms and it's not primarily intended for a no JS solution.

This PR takes the approach that if we fail to generate the progressive
enhancement payload. I.e. if the serialization of previous state /
closures throw. Then we fallback to the replaying semantics just client
actions instead which will succeed.

The effect of this is that this pattern mostly just works:

- First render in the typical case doesn't have any JSX in it so it just
renders a progressive enhanced form.
- If JS fails to hydrate or you click early we do a form POST. If that
hits an error and it tries to render it using JSX, then the new page
will render successfully - however this time with a Replaying form
instead.
- If you try to submit the form again it'll have to be using JS.

Meaning if you use JSX as the error return value of form state and you
make a first attempt that fails, then no JS won't work because either
the first or second attempt has to hydrate.

We have ideas for potentially optimizing away serializing unused
arguments like if you don't actually use previous state which would also
solve it but it wouldn't cover all cases such as if it was deeply nested
in complex state.

Another approach that I considered was to poison the prev state if you
passed an element back but let it through to the action but if you try
to render the poisoned value, it wouldn't work. The downside of this is
when to error. Because in the progressive enhancement case it wouldn't
error early but when you actually try to invoke it at which point it
would be too late to fallback to client replaying. It would probably
have to always error even on the client which is unfortunate since this
mostly just works as long as it hydrates.
2024-03-21 19:51:38 -04:00
Mofei Zhang
e047db8d03 [repro] Repro for control flow bug in PropagateScopeDependency
--- 

Thanks to @josephsavona for finding this bug. This is another example of why we 
really want hir-everywhere. 

Forget output currently nullthrows because we believe `obj.a` is run 
unconditionally in source (missing the break/returns out of this scope)
2024-03-21 17:44:13 -04:00
Joe Savona
3a6a2e7e4a Repro for "context variables are always mutable" error w callbacks
I haven't debugged to understand exactly why this pattern fails, but there are a 
few instances of this internally. It's especially weird because 

```javascript 

// @enableAssumeHooksFollowRulesOfReact 
@enableTransitivelyFreezeFunctionExpressions 

function Component(props) { 

const [_state, setState] = useState(); 

const a = () => { 

return b(); 

}; 

const b = () => { 

return ( 

<> 

<div onClick={() => onClick(true)} /> 

<div onClick={() => onClick(false)} /> // <---- only repros if there's a second 
call! 

</> 

); 

}; 

const onClick = (value) => { 

setState(value); 

}; 

return <div>{a()}</div>; 

} 

``` 

Here, if `b()` only had one nested function expression that called `onClick` it 
would work. Also, if we disable `@enableTransitivelyFreezeFunctionExpressions` 
then it works. 

But the combination of multiple calls plus that mode causes "context variables 
are always mutable". I'm guessing we're freezing `onClick` twice and the second 
time reports an error since it calls `setState`.
2024-03-21 21:40:02 -07:00
Joe Savona
f18a01bf59 Add todo for destructuring to context variables
We don't have `DestructureContext` yet, this adds a todo for the cases where we 
should use one.
2024-03-21 17:12:09 -07:00
Joe Savona
e8073ff16c Repro for destructure declaration of context variable
We don't have a `DestructureContext` equivalent of `StoreContext`, so variables 
that are declared via destructuring and later reassigned trigger the invariant 
that all mentions of a variable must be consistently local or context. The next 
PR adds a todo for this case.
2024-03-21 17:12:09 -07:00
Joe Savona
231f29f6f3 Fix using context variable as JSX element tag
Updates the lowering for JSX element tag names to check if the identifier is a 
context or local variable and use the appropriate instruction kind.
2024-03-21 17:12:08 -07:00
Joe Savona
21bb8f9e75 Repro for inconsistent context/local variable reference
We currently assume JSX element tags are always locals, and need to check which 
load kind to use. Fixed in the next PR.
2024-03-21 17:12:08 -07:00
Joe Savona
0e72e2a00e Repro for nested method calls causing promoted property load invariant 2024-03-21 14:11:07 -07:00
Joe Savona
1b6afa1879 Repro for uninitialized value due to shadowed function name 2024-03-21 14:11:06 -07:00
Joe Savona
a6b3adbe68 Repro for unsupported recursive function expressions 2024-03-21 14:11:06 -07:00
Joe Savona
d31e10b406 Fix for type aliases in function inferring as function deps 2024-03-21 14:11:05 -07:00
Joe Savona
4bc676d3db Repro for undefined "hoisted" variable from type alias
We inadvertently think the type annotation on the function expression param is 
an identifier and create a LoadLocal for it, which fails. This happens to trip 
up on the InferReferenceEffects initialization check, which we had assumed would 
only fire for invalid hoisting cases (hence the specific error message).
2024-03-21 14:11:04 -07:00
Joe Savona
241b35463c Fix PruneMaybeThrows to update phi operand predecessor ids
When PruneMaybeThrows removes maybe-throw terminals, it's possible that the 
block in question reassigned a value s.t. it appears as a later phi operand. 
That phi has to be rewritten to reflect the updated predecessor block. 

Here we track these rewrites (transitively) and rewrite phi operands 
accordingly.
2024-03-21 14:11:04 -07:00
Sebastian Markbåge
72e02a8350 [Flight Reply] Don't allow Symbols to be passed to a reply (#28610)
As mentioned in #28609 there's a potential security risk if you allow a
passed value to the server to spoof Elements because it allows a hacker
to POST cross origin. This is only an issue if your framework allows
this which it shouldn't but it seems like we should provide an extra
layer of security here.

```js
function action(errors, payload) {
  try {
    ...
  } catch (x) {
    return [newError].concat(errors);
  }
}
```
```js
const [errors, formAction] = useActionState(action);
return <div>{errors}</div>;
```
This would allow you to construct a payload where the previous "errors"
set includes something like `<script src="danger.js" />`.

We could block only elements from being received but it could
potentially be a risk with creating other React types like Context too.
We use symbols as a way to securely brand these.

Most JS don't use this kind of branding with symbols like we do. They're
generally properties which we don't support anyway. However in theory
someone else could be using them like we do. So in an abundance of
carefulness I just ban all symbols from being passed (except by
temporary reference) - not just ours.

This means that the format isn't fully symmetric even beyond just React
Nodes.

#28611 allows code that includes symbols/elements to continue working
but may have to bail out to replaying instead of no JS sometimes.
However, you still can't access the symbols inside the server - they're
by reference only.
2024-03-21 16:53:02 -04:00
Josh Story
c47fee55d9 [Fizz][Legacy] use static markup mode for renderToStaticNodeStream (#28606)
Since it was first implemented renderToStaticNodeStream never correctly
set the renderer state to mark the output as static markup which means
it was functionally the same as renderToNodeStream. This change fixes
this oversight. While we are removing renderToNodeStream in a future
version we never did deprecate the static version of this API because it
has no immediate analog in the modern APIs.
2024-03-21 11:03:09 -07:00
Jack Pope
7263b4f80a Update RTR usage in ReactLazy-test (#28598)
- Make all test cases in ReactLazy use RTR with concurrent root
- Except, two cases with "legacy mode" specified in description. These
are moved to a separate description block where the disableLegacyMode
flag is turned off to allow RTR to use legacy root after
https://github.com/facebook/react/pull/28498
2024-03-21 13:28:20 -04:00
Joe Savona
1cf8d9bc8b Repro for missing predecessor with try/catch
Found when running the compiler on a large swath of internal code. 
PruneMaybeThrows rewrites terminals, but the logic to update subsequent phis was 
incorrectly dropping phis rather than rewriting them. Fixed in the next PR.
2024-03-20 14:07:28 -07:00
Mofei Zhang
14d54869ed [patch][codegen] don't reuse babel nodes in codegen for dependencies
--- 

Reusing optionalMemberExpression nodes recently led to a bug when compiling 
Forget playground. 

```js 

// the two a?.b's here should be different nodes! 

if (a?.b !== $[0]) { 

// ... 

$[0] = a?.b; 

} 

``` 

Forget playground uses `babel-plugin-react-forget` and `next/babel`. Reusing the 
same node in two positions in the AST lead to invalid mutations: 

- the first `a?.b` is visited and transpiled to `a === void 0 ? ...`, which (1) 
inserts nodes between the original node and its parent and (2) mutates `a?.b` in 
place to a non-optional call 

- the second `a?.b` in source gets updated to `a.b` and does not get visited 
again 

```js 

// Source in `EditorImpl.tsx` 

compilerOutput.kind === "err" ? compilerOutput.error.details : [] 

// Forget transformed: 

if ($[2] !== compilerOutput.kind || $[3] !== compilerOutput.error?.details) { 

t4 = compilerOutput.kind === "err" ? compilerOutput.error.details : []; 

$[2] = compilerOutput.kind; 

// this is good! 

$[3] = compilerOutput.error?.details; 

$[4] = t4; 

} else { 

t4 = $[4]; 

} 

// After next/babel 

if ($[2] !== compilerOutput.kind || $[3] !== ((_compilerOutput$error = 
compilerOutput.error) === null || _compilerOutput$error === void 0 ? void 0 : 
_compilerOutput$error.details)) { 

t4 = compilerOutput.kind === "err" ? compilerOutput.error.details : []; 

$[2] = compilerOutput.kind; 

// Oh no!! 

$[3] = _compilerOutput$error.details; 

$[4] = t4; 

} else { 

t4 = $[4]; 

} 

```
2024-03-20 19:29:02 -04:00
Mofei Zhang
4daa4eceb7 [validation] More detailed error diagnostics for validatePreserveExistingMemo
--- 

This should make it easier to grep through error diagnostics to understand state 
of the codebase: 

- no matching dependences -> likely that source is ignoring eslint failures 

- differences in ref.current access -> non-backwards compatible refs 

- subpath -> should be fixable in the compiler (unless source is ignore eslint 
failures)
2024-03-20 16:05:24 -04:00
Mofei Zhang
63bb781781 [validation] Reduce false positives in validatePreserveExistingMemo
--- 

Previously (in #2663), we check that inferred dependencies exactly match source 
dependencies. As @validatePreserveExistingMemoizationGuarantees checks that 
Forget output does not invalidate *any more* than source, we now allow more 
specific inferred dependencies when neither the inferred dep or matching source 
dependency reads into a ref (based on `.current` access). 

See added comments for more details
2024-03-20 16:05:23 -04:00
Mofei Zhang
b35779c6a4 [logger] Add CompilerDiagnostic category, thread Logger into environment 2024-03-20 13:48:18 -04:00
Jack Pope
a4939017ff Concurrent RTR in ReactHooksInspectionIntegration-test (#28549)
More test updates to use concurrent root in RTR

`yarn test
packages/react-debug-tools/src/__tests__/ReactHooksInspectionIntegration-test.js`
2024-03-20 11:15:32 -04:00
Sebastian Silbermann
8ef14cf242 Ensure dispatch from useFormState works in StrictMode (#28557)
Co-authored-by: Andrew Clark <git@andrewclark.io>
2024-03-20 16:15:22 +01:00
Sebastian Silbermann
5cec48e145 DevTools: Read context values from context dependencies (#28467) 2024-03-20 12:16:42 +01:00
Andrew Clark
29a6ca33a5 Update gate pragma to detect global error events (#28591)
If a global error event is dispatched during a test, Jest reports that
test as a failure.

Our `@gate` pragma feature should account for this — if the gate
condition is false, and the global error event is dispatched, then the
test should be reported as a success.

The solution is to install an error event handler right before invoking
the test function. Because we install our own handler, Jest will not
report the test as a failure if a global error event is dispatched; it's
conceptually as if we wrapped the whole test event in a try-catch.
2024-03-19 21:08:37 -04:00
Joe Savona
346f6c13a8 Todo for fbt with multiple fbt:enum
I need to do more debugging to figure out exactly why the example earlier fails 
— but whatever it is, it's clearly a matter of the fbt plugin relying on some 
specifics of source locations. 

Here we just detect multiple instances of `<fbt:enum>` within a given `<fbt>` 
tag and throw a todo.
2024-03-19 16:39:05 -07:00
Joe Savona
f2b0b656b2 More accurate source locations for JSX opening/closing tags
<img width="553" alt="Screenshot 2024-03-19 at 4 41 15 PM" 
src="https://github.com/facebook/react-forget/assets/6425824/e87ee704-6c67-4e10-824b-71e97e7e19f5"> 

Slightly improves source locations for JSX elements so that the opening and 
closing tag have distinct locations that match up with source. The identifier 
itself within the closing tag still has the wrong location, but at least this is 
an improvement. 

Doesn't fix the fbt thing but it was worth a try.
2024-03-19 16:26:32 -07:00
Joe Savona
501481ccea Repro for fbt:enum source location issue
Fbt enums appear to rely on source locations and something that we're doing 
(maybe destructuring?) isn't preserving locations such that the fbt plugin 
breaks.
2024-03-19 15:21:55 -07:00
dependabot[bot]
82c6595e75 Bump es5-ext from 0.10.53 to 0.10.63 in /fixtures/dom (#28459)
Bumps [es5-ext](https://github.com/medikoo/es5-ext) from 0.10.53 to
0.10.63.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a
href="https://github.com/medikoo/es5-ext/releases">es5-ext's
releases</a>.</em></p>
<blockquote>
<h2>0.10.63 (2024-02-23)</h2>
<h3>Bug Fixes</h3>
<ul>
<li>Do not rely on problematic regex (<a
href="3551cdd7b2">3551cdd</a>),
addresses <a
href="https://redirect.github.com/medikoo/es5-ext/issues/201">#201</a></li>
<li>Support ES2015+ function definitions in
<code>function#toStringTokens()</code> (<a
href="a52e957366">a52e957</a>),
addresses <a
href="https://redirect.github.com/medikoo/es5-ext/issues/021">#021</a></li>
<li>Ensure postinstall script does not crash on Windows, fixes <a
href="https://redirect.github.com/medikoo/es5-ext/issues/181">#181</a>
(<a
href="bf8ed799d5">bf8ed79</a>)</li>
</ul>
<h3>Maintenance Improvements</h3>
<ul>
<li>Simplify the manifest message (<a
href="7855319f41">7855319</a>)</li>
</ul>
<hr />
<p><a
href="https://github.com/medikoo/es5-ext/compare/v0.10.62...v0.10.63">Comparison
since last release</a></p>
<h2>0.10.62 (2022-08-02)</h2>
<h3>Maintenance Improvements</h3>
<ul>
<li><strong>Manifest improvements:</strong>
<ul>
<li>(<a
href="https://redirect.github.com/medikoo/es5-ext/issues/190">#190</a>)
(<a
href="b8dc53fa43">b8dc53f</a>)</li>
<li>(<a
href="c51d552c03">c51d552</a>)</li>
</ul>
</li>
</ul>
<hr />
<p><a
href="https://github.com/medikoo/es5-ext/compare/v0.10.61...v0.10.62">Comparison
since last release</a></p>
<h2>0.10.61 (2022-04-20)</h2>
<h3>Bug Fixes</h3>
<ul>
<li>Ensure postinstall script does not error (<a
href="a0be4fdacd">a0be4fd</a>)</li>
</ul>
<h3>Maintenance Improvements</h3>
<ul>
<li>Bump dependencies (<a
href="d7e0a612b7">d7e0a61</a>)</li>
</ul>
<hr />
<p><a
href="https://github.com/medikoo/es5-ext/compare/v0.10.60...v0.10.61">Comparison
since last release</a></p>
<h2>0.10.60 (2022-04-07)</h2>
<h3>Maintenance Improvements</h3>
<ul>
<li>Improve <code>postinstall</code> script configuration (<a
href="ab6b121f0c">ab6b121</a>)</li>
</ul>
<hr />
<p><a
href="https://github.com/medikoo/es5-ext/compare/v0.10.59...v0.10.60">Comparison
since last release</a></p>
<h2>0.10.59 (2022-03-17)</h2>
<h3>Maintenance Improvements</h3>
<ul>
<li>Improve manifest wording (<a
href="https://redirect.github.com/medikoo/es5-ext/issues/122">#122</a>)
(<a
href="eb7ae59966">eb7ae59</a>)</li>
<li>Update data in manifest (<a
href="3d2935ac6f">3d2935a</a>)</li>
</ul>
<!-- raw HTML omitted -->
</blockquote>
<p>... (truncated)</p>
</details>
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a
href="https://github.com/medikoo/es5-ext/blob/main/CHANGELOG.md">es5-ext's
changelog</a>.</em></p>
<blockquote>
<h3><a
href="https://github.com/medikoo/es5-ext/compare/v0.10.62...v0.10.63">0.10.63</a>
(2024-02-23)</h3>
<h3>Bug Fixes</h3>
<ul>
<li>Do not rely on problematic regex (<a
href="3551cdd7b2">3551cdd</a>),
addresses <a
href="https://redirect.github.com/medikoo/es5-ext/issues/201">#201</a></li>
<li>Support ES2015+ function definitions in
<code>function#toStringTokens()</code> (<a
href="a52e957366">a52e957</a>),
addresses <a
href="https://redirect.github.com/medikoo/es5-ext/issues/021">#021</a></li>
<li>Ensure postinstall script does not crash on Windows, fixes <a
href="https://redirect.github.com/medikoo/es5-ext/issues/181">#181</a>
(<a
href="bf8ed799d5">bf8ed79</a>)</li>
</ul>
<h3>Maintenance Improvements</h3>
<ul>
<li>Simplify the manifest message (<a
href="7855319f41">7855319</a>)</li>
</ul>
<h3><a
href="https://github.com/medikoo/es5-ext/compare/v0.10.61...v0.10.62">0.10.62</a>
(2022-08-02)</h3>
<h3>Maintenance Improvements</h3>
<ul>
<li><strong>Manifest improvements:</strong>
<ul>
<li>(<a
href="https://redirect.github.com/medikoo/es5-ext/issues/190">#190</a>)
(<a
href="b8dc53fa43">b8dc53f</a>)</li>
<li>(<a
href="c51d552c03">c51d552</a>)</li>
</ul>
</li>
</ul>
<h3><a
href="https://github.com/medikoo/es5-ext/compare/v0.10.60...v0.10.61">0.10.61</a>
(2022-04-20)</h3>
<h3>Bug Fixes</h3>
<ul>
<li>Ensure postinstall script does not error (<a
href="a0be4fdacd">a0be4fd</a>)</li>
</ul>
<h3>Maintenance Improvements</h3>
<ul>
<li>Bump dependencies (<a
href="d7e0a612b7">d7e0a61</a>)</li>
</ul>
<h3><a
href="https://github.com/medikoo/es5-ext/compare/v0.10.59...v0.10.60">0.10.60</a>
(2022-04-07)</h3>
<h3>Maintenance Improvements</h3>
<ul>
<li>Improve <code>postinstall</code> script configuration (<a
href="ab6b121f0c">ab6b121</a>)</li>
</ul>
<h3><a
href="https://github.com/medikoo/es5-ext/compare/v0.10.58...v0.10.59">0.10.59</a>
(2022-03-17)</h3>
<h3>Maintenance Improvements</h3>
<ul>
<li>Improve manifest wording (<a
href="https://redirect.github.com/medikoo/es5-ext/issues/122">#122</a>)
(<a
href="eb7ae59966">eb7ae59</a>)</li>
<li>Update data in manifest (<a
href="3d2935ac6f">3d2935a</a>)</li>
</ul>
<h3><a
href="https://github.com/medikoo/es5-ext/compare/v0.10.57...v0.10.58">0.10.58</a>
(2022-03-11)</h3>
<h3>Maintenance Improvements</h3>
<ul>
<li>Improve &quot;call for peace&quot; manifest (<a
href="3beace4b3d">3beace4</a>)</li>
</ul>
<h3><a
href="https://github.com/medikoo/es5-ext/compare/v0.10.56...v0.10.57">0.10.57</a>
(2022-03-08)</h3>
<!-- raw HTML omitted -->
</blockquote>
<p>... (truncated)</p>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="de4e03c477"><code>de4e03c</code></a>
chore: Release v0.10.63</li>
<li><a
href="3fd53b755e"><code>3fd53b7</code></a>
chore: Upgrade<code> lint-staged</code> to v13</li>
<li><a
href="bf8ed799d5"><code>bf8ed79</code></a>
chore: Ensure postinstall script does not crash on Windows</li>
<li><a
href="2cbbb0717b"><code>2cbbb07</code></a>
chore: Bump dependencies</li>
<li><a
href="22d0416ea1"><code>22d0416</code></a>
chore: Bump LICENSE year</li>
<li><a
href="a52e957366"><code>a52e957</code></a>
fix: Support ES2015+ function definitions in
<code>function#toStringTokens()</code></li>
<li><a
href="3551cdd7b2"><code>3551cdd</code></a>
fix: Do not rely on problematic regex</li>
<li><a
href="7855319f41"><code>7855319</code></a>
chore: Simplify the manifest message</li>
<li><a
href="78e041fe78"><code>78e041f</code></a>
chore: Release v0.10.62</li>
<li><a
href="c51d552c03"><code>c51d552</code></a>
chore: Improve manifest</li>
<li>Additional commits viewable in <a
href="https://github.com/medikoo/es5-ext/compare/v0.10.53...v0.10.63">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=es5-ext&package-manager=npm_and_yarn&previous-version=0.10.53&new-version=0.10.63)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)
You can disable automated security fix PRs for this repo from the
[Security Alerts
page](https://github.com/facebook/react/network/alerts).

</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-03-19 18:13:39 -04:00
Joe Savona
7257c9b4f8 Fix for <fbt> with local import
Fbt violates the JSX spec by using a lowercase function as a tagname, even 
though lowercase names are reserved for builtins. Here we detect cases where 
there is an `<fbt>` tag where `fbt` is a local identifier and throw a todo.
2024-03-19 14:51:35 -07:00
Jan Kassens
37676aba76 Also apply content hash for experimental files (#28590)
Also apply content hash for experimental files

In #28582 I missed that experimental files have a copy of this build
function setting the version strings.
2024-03-19 17:50:24 -04:00
Sebastian Markbåge
83409a1fdd [Flight] Encode React Elements in Replies as Temporary References (#28564)
Currently you can accidentally pass React Element to a Server Action. It
warns but in prod it actually works because we can encode the symbol and
otherwise it's mostly a plain object. It only works if you only pass
host components and no function props etc. which makes it potentially
error later. The first thing this does it just early hard error for
elements.

I made Lazy work by unwrapping though since that will be replaced by
Promises later which works.

Our protocol is not fully symmetric in that elements flow from Server ->
Client. Only the Server can resolve Components and only the client
should really be able to receive host components. It's not intended that
a Server can actually do something with them other than passing them to
the client.

In the case of a Reply, we expect the client to be stateful. It's
waiting for a response. So anything we can't serialize we can still pass
by reference to an in memory object. So I introduce the concept of a
TemporaryReferenceSet which is an opaque object that you create before
encoding the reply. This then stashes any unserializable values in this
set and encode the slot by id. When a new response from the Action then
returns we pass the same temporary set into the parser which can then
restore the objects. This lets you pass a value by reference to the
server and back into another slot.

For example it can be used to render children inside a parent tree from
a server action:

```
export async function Component({ children }) {
  "use server";
  return <div>{children}</div>;
}
```

(You wouldn't normally do this due to the waterfalls but for advanced
cases.)

A common scenario where this comes up accidentally today is in
`useActionState`.

```
export function action(state, formData) {
  "use server";
   if (errored) {
     return <div>This action <strong>errored</strong></div>;
   }
   return null;
}
```

```
const [errors, formAction] = useActionState(action);
return <div>{errors}<div>;
```

It feels like I'm just passing the JSX from server to client. However,
because `useActionState` also sends the previous state *back* to the
server this should not actually be valid. Before this PR this actually
worked accidentally. You get a DEV warning but it used to work in prod.
Once you do something like pass a client reference it won't work tho. We
could perhaps make client references work by stashing where we got them
from but it wouldn't work with all possible JSX.

By adding temporary references to the action implementation this will
work again - on the client. It'll also be more efficient since we don't
send back the JSX content that you shouldn't introspect on the server
anyway.

However, a flaw here is that the progressive enhancement of this case
won't work because we can't use temporary references for progressive
enhancement since there's no in memory stash. What is worse is that it
won't error if you hydrate. ~It also will error late in the example
above because the first state is "undefined" so invoking the form once
works - it errors on the second attempt when it tries to send the error
state back again.~ It actually errors on the first invocation because we
need to eagerly serialize "previous state" into the form. So at least
that's better.

I think maybe the solution to this particular pattern would be to allow
JSX to serialize if you have no temporary reference set, and remember
client references so that client references can be returned back to the
server as client references. That way anything you could send from the
server could also be returned to the server. But it would only deopt to
serializing it for progressive enhancement. The consequence of that
would be that there's a lot of JSX that might accidentally seem like it
should work but it's only if you've gotten it from the server before
that it works. This would have to have pair them somehow though since
you can't take a client reference from one implementation of Flight and
use it with another.
2024-03-19 16:59:52 -04:00
Joe Savona
93e0815b26 Remove unnecessary scopes for value blocks
The example earlier in the stack had unreachable code in the output because 
there was an unnecessary memoization block around an assignment. This was a 
holdover from before we moved the logic to expand mutable ranges for phis from 
LeaveSSA to InferMutableRanges. We were conservatively assigning a mutable range 
to all variables with a phi, even those that didn't strictly need one. 

Removing the range extension logic in LeaveSSA fixed the issue, but uncovered 
the fact that AlignReactiveScopesToBlockScopes was missing a case to handle 
optionals. 

## Test Plan 

Synced internally and ran a snapshot/comparison of compilation before/after 
(P1197734337 for those curious). The majority of components get fewer memo slots 
thanks to not needing to memoize non-allocating value block expressions like 
ternaries/optionals. In a few cases, the fact that we're no longer assigning a 
mutable range for value blocks (unless there is actually a mutation!) means we 
get more fine-grained memoization and increase the number of memoization blocks. 
So overall this appears to be correct, improve memoization, and reduce code 
size.
2024-03-19 13:28:47 -07:00
Joe Savona
c03f1c809a Extract shared-runtime helper for validating memoization
Extracts a helper from the repro earlier in the stack into a helper in 
shared-runtime. This makes it easy to verify that memoization is actually 
working.
2024-03-19 13:28:47 -07:00
Joe Savona
57fcf7d305 Repro for nonproblematic unreachable code
This case is specific to early return inside an inlined IIFE (which can often 
occur as a result of dropping manual memoization). When we inline IIFEs, as a 
reminder we wrap the body in a labeled block and convert returns to assignment 
of a temporary + break out of the label. 

Those reassignments themselves are getting a reactive scope assigned since the 
reassigned value has a mutable range. They don't really need a mutable range or 
scope, though. And then the presence of the `break` statements means that we can 
sometimes exit out of the scope before reaching the end - leading to unreachable 
code. 

This can only occur though where _all the values are already memoized_. So the 
code works just fine and even memoizes just fine - it's just that we have some 
extraneous scopes and there is technically unreachable code. I'll fix in a 
follow-up, adding a repro here.
2024-03-19 13:28:46 -07:00
Jan Kassens
cb076b593c Change to content hash for RN canary VERSION strings (#28582)
With this change, the different files in RN will have *different*
hashes. This replaces the git hash and means that the file content
(including version) is only updated when the rest of the file content
actually changes. This should remove "noop" changes that need to be
synced that only update the version string.

A difference to the www implementation here is (and I'd be looking at
updating www as well if this lands well) that each file has an
individual hash instead of a combined content hash. This further reduces
the number of updated files and I couldn't find a reason we need to have
these in sync. The best I can gather is that this hash is used so folks
don't directly compare version string and make future updates harder.
2024-03-19 16:16:34 -04:00
Sathya Gunasekaran
b5a7fe4e1c [hir] Improve error message for mutating state 2024-03-19 17:06:17 +00:00
Sathya Gunasekaran
9358aeab34 [scripts] Add script to pull commit message from PR description 2024-03-19 11:23:43 +00:00
Jan Kassens
9c75cd5e84 Set disableModulePatternComponents flag to __NEXT_MAJOR__ (#28579) 2024-03-18 17:25:28 -04:00
Jack Pope
e02f87f139 Use RTR with concurrent root in ReactHooks-test.internal (#28578)
Continued cleanup of legacy root usage from RTR
2024-03-18 15:49:30 -04:00
Jack Pope
bc13750bdf Concurrent rendering for ReactART-test (#28521)
## Summary

We need to unblock flipping the default for RTR to be concurrent
rendering. Update ReactART-test to use `unstable_isConcurrent` in place.

## How did you test this change?

`yarn test packages/react-art/src/__tests__/ReactART-test.js`
2024-03-18 15:40:02 -04:00
Mofei Zhang
cea84a41bc validatePreserveExistingMemoizationGuarantees ensures compiler preserves subset
of dependencies from source 

--- 

`validatePreserveExistingMemoizationGuarantees` previously checked 

- manual memoization dependencies and declarations (the returned value) do not 
"lose" memoization due to inferred mutations 

``` 

function useFoo() { 

const y = {}; 

// bail out because we infer that y cannot be a dependency of x as its 
mutableRange 

// extends beyond 

const x = useMemo(() => maybeMutate(y), [y]); 

// similarly, bail out if we find that x or y are mutated here 

return x; 

} 

``` 

- manual memoization deps and decls do not get deopted due to hook calls 

``` 

function useBar() { 

const x = getArray(); 

useHook(); 

mutate(x); 

return useCallback(() => [x], [x]); 

} 

``` 

This PR updates `validatePreserveExistingMemoizationGuarantees` with the 
following correctness conditions: 

*major change* All inferred dependencies of reactive scopes between 
`StartMemoize` and `StopMemoize` instructions (e.g. scopes containing manual 
memoization code) must either: 

1. be produced from earlier within the same manual memoization block 

2. exactly match an element of depslist from source 

This assumes that the source codebase mostly follows the `exhaustive-deps` lint 
rule, which ensures that deps lists are (1) simple expressions composing of 
reads from named identifiers + property loads and (2) exactly match deps usages 
in the useMemo/useCallback itself. 

--- 

Validated that this does not change source by running internally on ~50k files 
(no validation on `main`, no validation on this PR, and validation on this PR).
2024-03-18 14:50:15 -04:00
Timothy Yung
0aab065eb3 Add alwaysThrottleDisappearingFallbacks Flag (#28550)
## Summary

Creates a new `alwaysThrottleDisappearingFallbacks` feature flag that
gates the changes from https://github.com/facebook/react/pull/26802
(instead of being controlled by `alwaysThrottleRetries`). The values of
this new flag mirror the current values of `alwaysThrottleRetries` such
that there is no behavior difference.

This additional feature flag allows us to incrementally validate the
change (arguably bug fix) from
https://github.com/facebook/react/pull/26802 independently from
`alwaysThrottleRetries`.

## How did you test this change?

```
$ yarn test
$ yarn flow dom-browser
$ yarn flow dom-fb
$ yarn flow fabric
```
2024-03-18 11:16:47 -07:00
Jan Kassens
7959a1dd28 Upgrade flow to 0.231.0 (#28576)
Upgrade flow to 0.231.0
2024-03-18 13:23:07 -04:00
Jack Pope
6a01aca75b Fix ReactHooksInspectionIntegration-test (#28577)
Resolve conflict between #28508 and #28546
2024-03-18 13:15:23 -04:00
Mofei Zhang
81695f62c2 [refactor] Refactor Memoize to two instructions: Start and Finish
--- 

Previously, we always emitted `Memoize dep` instructions after the function 
expression literal and depslist instructions 

```js 

// source 

useManualMemo(() => {...}, [arg]) 

// lowered 

$0 = FunctionExpression(...) 

$1 = LoadLocal (arg) 

$2 = ArrayExpression [$1] 

$3 = Memoize (arg) 

$4 = Call / LoadLocal 

$5 = Memoize $4 

``` 

Now, we insert `Memoize dep` before the corresponding function expression 
literal: 

```js 

// lowered 

$0 = StartMemoize (arg)      <---- this moved up! 

$1 = FunctionExpression(...) 

$2 = LoadLocal (arg) 

$3 = ArrayExpression [$2] 

$4 = Call / LoadLocal 

$5 = FinishMemoize $4 

``` 

Design considerations: 

- #2663 needs to understand which lowered instructions belong to a manual 
memoization block, so we need to emit `StartMemoize` instructions before the 
`useMemo/useCallback` function argument, which contains relevant memoized 
instructions 

- we choose to insert StartMemoize instructions to (1) avoid unsafe instruction 
reordering of source and (2) to ensure that Forget output does not change when 
enabling validation 

This PR only renames `Memoize` -> `Start/FinishMemoize` and hoists 
`StartMemoize` as described. The latter may help with stricter validation for 
`useCallback`s, although testing is left to the next PR. 

#2663 contains all validation changes
2024-03-18 12:09:37 -04:00
Mofei Zhang
37452089fb [ez] CompilerError: optional description and suggestions
--- 

Many compiler errors have neither descriptions nor suggestions (e.g. most `todo` 
or `invariant` errors), so let's make those optional
2024-03-18 12:09:36 -04:00
Jan Kassens
8c8e318bd4 Remove private header from playground
Remove private header from playground 

Before we miss removing this from the public release, I think we can remove this 
header now already. We're still behind a secret URL + password.
2024-03-18 16:53:47 -04:00
dependabot[bot]
74cb1bdfec Bump follow-redirects from 1.15.4 to 1.15.6 in /fixtures/ssr (#28571)
Bumps
[follow-redirects](https://github.com/follow-redirects/follow-redirects)
from 1.15.4 to 1.15.6.
<details>
<summary>Commits</summary>
<ul>
<li><a
href="35a517c586"><code>35a517c</code></a>
Release version 1.15.6 of the npm package.</li>
<li><a
href="c4f847f851"><code>c4f847f</code></a>
Drop Proxy-Authorization across hosts.</li>
<li><a
href="8526b4a1b2"><code>8526b4a</code></a>
Use GitHub for disclosure.</li>
<li><a
href="b1677ce001"><code>b1677ce</code></a>
Release version 1.15.5 of the npm package.</li>
<li><a
href="d8914f7982"><code>d8914f7</code></a>
Preserve fragment in responseUrl.</li>
<li>See full diff in <a
href="https://github.com/follow-redirects/follow-redirects/compare/v1.15.4...v1.15.6">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=follow-redirects&package-manager=npm_and_yarn&previous-version=1.15.4&new-version=1.15.6)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)
You can disable automated security fix PRs for this repo from the
[Security Alerts
page](https://github.com/facebook/react/network/alerts).

</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-03-18 11:59:57 -04:00
dependabot[bot]
c94110c5f3 Bump follow-redirects from 1.15.4 to 1.15.6 in /fixtures/concurrent/time-slicing (#28572)
Bumps
[follow-redirects](https://github.com/follow-redirects/follow-redirects)
from 1.15.4 to 1.15.6.
<details>
<summary>Commits</summary>
<ul>
<li><a
href="35a517c586"><code>35a517c</code></a>
Release version 1.15.6 of the npm package.</li>
<li><a
href="c4f847f851"><code>c4f847f</code></a>
Drop Proxy-Authorization across hosts.</li>
<li><a
href="8526b4a1b2"><code>8526b4a</code></a>
Use GitHub for disclosure.</li>
<li><a
href="b1677ce001"><code>b1677ce</code></a>
Release version 1.15.5 of the npm package.</li>
<li><a
href="d8914f7982"><code>d8914f7</code></a>
Preserve fragment in responseUrl.</li>
<li>See full diff in <a
href="https://github.com/follow-redirects/follow-redirects/compare/v1.15.4...v1.15.6">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=follow-redirects&package-manager=npm_and_yarn&previous-version=1.15.4&new-version=1.15.6)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)
You can disable automated security fix PRs for this repo from the
[Security Alerts
page](https://github.com/facebook/react/network/alerts).

</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-03-18 11:56:04 -04:00
dependabot[bot]
d79807537b Bump follow-redirects from 1.13.0 to 1.15.6 in /fixtures/dom (#28560)
Bumps
[follow-redirects](https://github.com/follow-redirects/follow-redirects)
from 1.13.0 to 1.15.6.
<details>
<summary>Commits</summary>
<ul>
<li><a
href="35a517c586"><code>35a517c</code></a>
Release version 1.15.6 of the npm package.</li>
<li><a
href="c4f847f851"><code>c4f847f</code></a>
Drop Proxy-Authorization across hosts.</li>
<li><a
href="8526b4a1b2"><code>8526b4a</code></a>
Use GitHub for disclosure.</li>
<li><a
href="b1677ce001"><code>b1677ce</code></a>
Release version 1.15.5 of the npm package.</li>
<li><a
href="d8914f7982"><code>d8914f7</code></a>
Preserve fragment in responseUrl.</li>
<li><a
href="65858205e5"><code>6585820</code></a>
Release version 1.15.4 of the npm package.</li>
<li><a
href="7a6567e16d"><code>7a6567e</code></a>
Disallow bracketed hostnames.</li>
<li><a
href="05629af696"><code>05629af</code></a>
Prefer native URL instead of deprecated url.parse.</li>
<li><a
href="1cba8e85fa"><code>1cba8e8</code></a>
Prefer native URL instead of legacy url.resolve.</li>
<li><a
href="72bc2a4229"><code>72bc2a4</code></a>
Simplify _processResponse error handling.</li>
<li>Additional commits viewable in <a
href="https://github.com/follow-redirects/follow-redirects/compare/v1.13.0...v1.15.6">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=follow-redirects&package-manager=npm_and_yarn&previous-version=1.13.0&new-version=1.15.6)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)
You can disable automated security fix PRs for this repo from the
[Security Alerts
page](https://github.com/facebook/react/network/alerts).

</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-03-18 11:55:56 -04:00
Rom Grk
4d686a2da1 Performance: avoid triggering map deopt in V8 (#28569)
The shape of the objects changed by this PR are both created in 2
locations with 2 different shapes, which most JS engines won't like.
I've noticed this in particular in V8 while benchmarking production
code.


1293047d60/packages/react-reconciler/src/ReactFiberCacheComponent.js (L66-L77)


1293047d60/packages/react-reconciler/src/ReactFiberHostContext.js (L47-L54)


1293047d60/packages/react-reconciler/src/ReactFiberHooks.js (L3530-L3531)


1293047d60/packages/react-reconciler/src/ReactFiberHooks.js (L3492-L3493)
2024-03-18 11:54:34 -04:00
dependabot[bot]
45d56071b8 Bump follow-redirects from 1.15.4 to 1.15.6 (#28573)
Bumps
[follow-redirects](https://github.com/follow-redirects/follow-redirects)
from 1.15.4 to 1.15.6.
<details>
<summary>Commits</summary>
<ul>
<li><a
href="35a517c586"><code>35a517c</code></a>
Release version 1.15.6 of the npm package.</li>
<li><a
href="c4f847f851"><code>c4f847f</code></a>
Drop Proxy-Authorization across hosts.</li>
<li><a
href="8526b4a1b2"><code>8526b4a</code></a>
Use GitHub for disclosure.</li>
<li><a
href="b1677ce001"><code>b1677ce</code></a>
Release version 1.15.5 of the npm package.</li>
<li><a
href="d8914f7982"><code>d8914f7</code></a>
Preserve fragment in responseUrl.</li>
<li>See full diff in <a
href="https://github.com/follow-redirects/follow-redirects/compare/v1.15.4...v1.15.6">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=follow-redirects&package-manager=npm_and_yarn&previous-version=1.15.4&new-version=1.15.6)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)
You can disable automated security fix PRs for this repo from the
[Security Alerts
page](https://github.com/facebook/react/network/alerts).

</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-03-18 11:49:53 -04:00
Jack Pope
38327309a4 Update isConcurrent RTR option usage (#28546)
Reverting some of https://github.com/facebook/react/pull/27804 which
renamed this option to stable. This PR just replaces internal usage to
make upcoming PRs cleaner.

Keeping isConcurrent unstable for the next major release in order to
enable a broader deprecation of RTR and be consistent with concurrent
rendering everywhere for next major.
(https://github.com/facebook/react/pull/28498)
- Next major will use concurrent root
- The old behavior (legacy root by default, concurrent root with
unstable option) will be preserved for React Native until new
architecture is fully shipped.
- Flag and legacy root usage can be removed after RN dependency is
unblocked without an additional breaking change
2024-03-18 11:35:16 -04:00
Josh Story
b09e102ff1 [Fizz] Prevent uncloned large precomputed chunks without relying on render-time assertions (#28568)
A while back we implemented a heuristic that if a chunk was large it was
assumed to be produced by the render and thus was safe to stream which
results in transferring the underlying object memory. Later we ran into
an issue where a precomputed chunk grew large enough to trigger this
hueristic and it started causing renders to fail because once a second
render had occurred the precomputed chunk would not have an underlying
buffer of bytes to send and these bytes would be omitted from the
stream. We implemented a technique to detect large precomputed chunks
and we enforced that these always be cloned before writing.
Unfortunately our test coverage was not perfect and there has been for a
very long time now a usage pattern where if you complete a boundary in
one flush and then complete a boundary that has stylehsheet dependencies
in another flush you can get a large precomputed chunk that was not
being cloned to be sent twice causing streaming errors.

I've thought about why we even went with this solution in the first
place and I think it was a mistake. It relies on a dev only check to
catch paired with potentially version specific order of operations on
the streaming side. This is too unreliable. Additionally the low limit
of view size for Edge is not used in Node.js but there is not real
justification for this.

In this change I updated the view size for edge streaming to match Node
at 2048 bytes which is still relatively small and we have no data one
way or another to preference 512 over this. Then I updated the assertion
logic to error anytime a precomputed chunk exceeds the size. This
eliminates the need to clone these chunks by just making sure our view
size is always larger than the largest precomputed chunk we can possibly
write. I'm generally in favor of this for a few reasons.

First, we'll always know during testing whether we've violated the limit
as long as we exercise each stream config because the precomputed chunks
are created in module scope. Second, we can always split up large chunks
so making sure the precomptued chunk is smaller than whatever view size
we actually desire is relatively trivial.
2024-03-16 12:39:37 -07:00
sweetliquid
1293047d60 Fix log assertion in cancels tasks in Scheduler-test (#28562) 2024-03-15 21:21:46 +01:00
Sebastian Silbermann
4d85c666a3 Remove excess ms prop from Suspense tests (#28566) 2024-03-15 20:57:42 +01:00
Rubén Norte
9372c63116 Revert rollout state of enableCache in React Native to next major only (#28565)
## Summary

We're working on enabling the use of microtasks in React Native by
default when using the new architecture. To enable this we need to
synchronize the RN renderers from React, but doing this causes an error
because the renderers now rely on an object defined in
`React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED`
(`ReactCurrentCache`) that's hasn't been released as a stable version
yet (cache).

This reverts the change done in #28519 to avoid enabling the cache API
in RN until we release a new version of React in npm.

## How did you test this change?

Manually built the RN renderer, copied it to the RN repository and
tested e2e in RNTester.
2024-03-15 18:02:46 +00:00
Sebastian Silbermann
a870b2d549 Make enableNewBooleanProps www dynamic (#28559)
Feature: https://github.com/facebook/react/pull/24730
2024-03-14 11:50:11 -04:00
Sebastian Silbermann
7268dacf70 Devtools: Ensure component control flow is consistent with commit when using `useDeferredValue (#28508) 2024-03-14 15:41:50 +01:00
Sebastian Silbermann
a540f53616 Add passing exhaustive-deps test for type parameters in TypeScript (#20432) 2024-03-14 15:41:37 +01:00
bubucuo
9ffe9102ff Fix a spelling mistake. (#28555) 2024-03-14 10:04:44 -04:00
Sebastian Silbermann
bbc571aee4 React DOM: Support boolean values for inert prop (#24730) 2024-03-13 23:10:41 +01:00
Joe Savona
d5e2d9f8d5 Handle fbt:param with only leading or trailing whitespace
Fixes T180504437. We expected `<fbt:param>` to always have no surrounding 
whitespace or have both leading and trailing whitespace, it can have one but not 
the other, though such cases are rare in practice.
2024-03-13 14:54:39 -07:00
Joe Savona
bf64a826a4 Repro for fbt with unexpected child count 2024-03-13 14:54:35 -07:00
Joe Savona
d5eca2ed85 Repro for scope with no declarations (already fixed on this stack)
Repro from T180504728 which reproduced internally and on playground, neither of 
which have #2687 yet. That PR (earlier in this stack) already fixes the issue, 
so i'm just adding the repro to help prevent regressions.
2024-03-15 08:26:43 -07:00
Joe Savona
ec3d36b865 Convert unhandled value block terminal to todo
While i'm here, we know that there are a variety of cases that are not supported 
yet around combining value blocks with other syntax constructs. Since we're 
aware of these cases and detect them, we can make this a todo instead of an 
invariant.
2024-03-13 22:25:18 -07:00
Joe Savona
1301e68ae6 Add todo for label as value block terminal
We need to revisit the conversion from value blocks into ReactiveFunction. Or 
just revisit ReactiveFunction altogether (see my post about what this would look 
like). For now, makes this case a todo.
2024-03-13 22:20:59 -07:00
Joe Savona
d70b2c2c4e Repro for unexpected label as value block terminal
This was one of the last invariants firing internally, this PR adds a minimal 
repro and the next PR makes it a todo.
2024-03-13 22:20:56 -07:00
Joe Savona
459679f91e Support type alias syntax
"Support" in the sense of dropping these on the floor and compiling, rather than 
bailing out with a todo. 

We already don't make any guarantees about which type annotations we'll preserve 
through to the output, so it seems fine for now to just drop type aliases.
2024-03-13 22:17:19 -07:00
Joe Savona
1b5ae0638e Fix block scoping of declarations with early return
I addressed some of the cases that lead to this invariant but there were still 
more. In this case, we have scopes like this: 

``` 

scope @1 declarations=[t$0] { 

let t$0 = ArrayExpression [] 

if (...) { 

return null; 

} 

} 

scope @2 deps=[t$0] declarations=[t$1] { 

let t$1 = Jsx children=[t$0] ... 

} 

``` 

Because scope 1 has an early return, PropagateEarlyReturns wraps its contents in 
a label and converts the returns to breaks: 

``` 

scope @1 declarations=[t$0] earlyReturn={t$2} { 

let t$2 

bb0: { 

let t$0 = ArrayExpression [] 

if (...) { 

t$2 = null; 

break bb0; 

} 

} 

} 

scope @2 deps=[t$0] declarations=[t$1] { 

let t$1 = Jsx children=[t$0] ... 

} 

``` 

But then MergeReactiveScopesThatInvalidateTogether smushes them together: 

``` 

scope @1 declarations=[t$1] earlyReturn={t$2} { 

let t$2 

bb0: { 

let t$0 = ArrayExpression [] // <--- Oops! We're inside a block now 

if (...) { 

t$2 = null; 

break bb0; 

} 

} 

let t$1 = Jsx children=[t$0] ... 

} 

``` 

Note that the `t$0` binding is now created inside the labeled block, so it's no 
longer accessible to the Jsx instruction which follows the labeled block. This 
isn't an issue with promoting temporaries or propagating outputs, but a simple 
issue of the labeled block (used for early return) introducing a new block 
scope. The solution here is to simply reorder the passes so that we transform 
for early returns after other optimizations. This means the jsx element will 
basically move inside the labeled block, solving the scoping issue: 

``` 

scope @1 declarations=[t$1] earlyReturn={t$2} { 

let t$2 

bb0: { 

let t$0 = ArrayExpression [] // ok, same block scope as its use 

if (...) { 

t$2 = null; 

break bb0; 

} 

let t$1 = Jsx children=[t$0] // note this moved inside the labeled block 

} 

} 

```
2024-03-13 21:29:58 -07:00
Joe Savona
f7ca10a0c7 Repro for "no value for temporary"
I addressed some of the cases that lead to this invariant but there were still 
more. In this case, we have scopes like this: 

``` 

scope @1 declarations=[t$0] { 

let t$0 = ArrayExpression [] 

if (...) { 

return null; 

} 

} 

scope @2 deps=[t$0] declarations=[t$1] { 

let t$1 = Jsx children=[t$0] ... 

} 

``` 

Because scope 1 has an early return, PropagateEarlyReturns wraps its contents in 
a label and converts the returns to breaks: 

``` 

scope @1 declarations=[t$0] earlyReturn={t$2} { 

let t$2 

bb0: { 

let t$0 = ArrayExpression [] 

if (...) { 

t$2 = null; 

break bb0; 

} 

} 

} 

scope @2 deps=[t$0] declarations=[t$1] { 

let t$1 = Jsx children=[t$0] ... 

} 

``` 

But then MergeReactiveScopesThatInvalidateTogether smushes them together: 

``` 

scope @1 declarations=[t$1] earlyReturn={t$2} { 

let t$2 

bb0: { 

let t$0 = ArrayExpression [] // <--- Oops! We're inside a block now 

if (...) { 

t$2 = null; 

break bb0; 

} 

} 

let t$1 = Jsx children=[t$0] ... 

} 

``` 

Note that the `t$0` binding is now created inside the labeled block, so it's no 
longer accessible to the Jsx instruction which follows the labeled block. This 
isn't an issue with promoting temporaries or propagating outputs, but a simple 
issue of the labeled block (used for early return) introducing a new block 
scope. The solution (in the next PR) is to simply reorder the passes so that we 
transform for early returns after other optimizations. This means the jsx 
element will basically move inside the labeled block, solving the scoping issue: 

``` 

scope @1 declarations=[t$1] earlyReturn={t$2} { 

let t$2 

bb0: { 

let t$0 = ArrayExpression [] // ok, same block scope as its use 

if (...) { 

t$2 = null; 

break bb0; 

} 

let t$1 = Jsx children=[t$0] // note this moved inside the labeled block 

} 

} 

```
2024-03-13 21:29:54 -07:00
Jan Kassens
72d374e978 [linter] rename ReactForgetDiagnostics to ReactCompilerRule
[linter] rename ReactForgetDiagnostics to ReactCompilerRule
2024-03-14 11:53:32 -04:00
Joe Savona
ca8e0d4527 Support multiple declarations in for init
This was an oversight in codegen. The entire pipeline supports multiple values 
in a for initializer, but codegen was dropping all but the first initializer.
2024-03-13 15:45:50 -07:00
Joe Savona
fe29f46de8 Repro for multiple declarations in for initializer codegen issue 2024-03-13 15:31:51 -07:00
Joe Savona
2940440dfb Fix for mutable ranges ended early with interleaving
Fixes T180504437. In MergeOverlappingReactiveScopes we track the active scopes 
and mark them as "ended" when reaching the first instruction after their mutable 
range. However, in cases of interleaving that will be merged, we could 
previously mark a scope as complete when it's original range was completed, even 
though the range would get extended post-merge. The fix here detects 
interleaving earlier, and eagerly updates the mutable ranges of the merged 
scopes to ensure that neither is "ended" earlier than it should. 

The repro here fails without this change.
2024-03-13 13:52:29 -07:00
Joe Savona
79e3fc0acb Fix for method call not memoizing in same scope as outer call
Fixes T175282980. InferReactiveScopeVariables had logic to force assigning a 
scope to MethodCall property lookups with the idea of forcing the method call 
lookup to be in the same scope as the method call itself. But this doesn't work 
if we never assign a scope to the method call! That can happen if we're able to 
infer that the method call produces a primitive and doesn't need memoization. 

This PR changes things so that: 

* InferReactiveScopeVariables no longer assumes that MethodCall property values 
need a scope 

* We run a separate pass that ensures that _if_ a MethodCall has a scope, that 
it's property is in the scope, and that otherwise its property doesn't get a 
scope. This is similar to the existing passes that force a single scope for 
related instructions like ObjectMethod+ObjectExpression and fbt operands/calls.
2024-03-13 13:52:29 -07:00
Joe Savona
dc7ed065c0 Fix missing declaration invariant for "for" within try/catch
Fixes T180509722. What happened is that the logic in LeaveSSA to find 
declarations within for initializers wasn't working with try/catch because the 
initializer block gets broken up with a maybe-throw after every instruction that 
can throw. These maybe-throws can then get turned into gotos by 
PruneMaybeThrows, so LeaveSSA has to handle both cases. 

The new logic scans from the start of the init block until reaching the end, and 
creates declarations for all StoreLocals. Note that we don't yet support 
maybe-throw in value blocks — that's already a todo — so the change here simply 
allows us to compile farther until reaching that other todo. But i've 
double-checked the HIR and it looks correct for this case, so it should just 
work once we fix that todo. I've also added a comment to help us remember (and 
of course, we'd have to add a snap fixture too)
2024-03-13 13:52:28 -07:00
Jan Kassens
b666bd1637 [lint] do not report issues when a matching flow suppression is present
Based on implementation of a similar case in D54776832.
2024-03-13 11:40:35 -04:00
Rubén Norte
bb0944fe5b [RN] Use microtasks in the RN renderer based on a global flag defined by RN (#28472)
## Summary

We want to enable the new event loop in React Native
(https://github.com/react-native-community/discussions-and-proposals/pull/744)
for all users in the new architecture (determined by the use of
bridgeless, not by the use of Fabric). In order to leverage that, we
need to also set the flag for the React reconciler to use microtasks for
scheduling (so we'll execute them at the right time in the new event
loop).

This migrates from the previous approach using a dynamic flag (to be
used at Meta) with the check of a global set by React Native. The reason
for doing this is:
1) We still need to determine this dynamically in OSS (based on
Bridgeless, not on Fabric).
2) We still need the ability to configure the behavior at Meta, and for
internal build system reasons we cannot access the flag that enables
microtasks in
[`ReactNativeFeatureFlags`](6c28c87c4d/packages/react-native/src/private/featureflags/ReactNativeFeatureFlags.js (L121)).

## How did you test this change?

Manually synchronized the changes to React Native and ran all tests for
the new architecture on it. Also tested manually.

> [!NOTE]
> This change depends on
https://github.com/facebook/react-native/pull/43397 which has been
merged already
2024-03-13 10:00:10 +00:00
Jan Kassens
d46989150e Disable legacy context (#27991)
Disable legacy context

This enables the `disableLegacyContext` flag for web and React Native.
2024-03-12 18:00:26 -04:00
Ricky
17eaacaac1 Add pending state to useFormState (#28514)
## Overview

Adds a `pending` state to useFormState, which will be replaced by
`useActionState` in the next diff. We will keep `useFormState` around
for backwards compatibility, but functionally it will work the same as
`useActionState`, which has an `isPending` state returned.
2024-03-12 15:50:11 -04:00
Jan Kassens
3e6bc7d2d7 Revert "Land enableClientRenderFallbackOnTextMismatch for www" (#28548)
We're looking to run further experiments on this.

Reverts facebook/react#28538
2024-03-12 15:29:41 -04:00
Jan Kassens
eb33bd7477 Remove renderSubtreeIntoContainer_DO_NOT_USE (#28526)
Since D54648741 we no longer need this shim. 

NOTE: There is still some work left to remove the
`unstable_renderSubtreeIntoContainer` export.
2024-03-12 11:31:34 -04:00
Sebastian Markbåge
89021fb4ec Remove invokeGuardedCallback and replay trick (#28515)
We broke the ability to "break on uncaught exceptions" by adding a
try/catch higher up in the scheduling. We're giving up on fixing that so
we can remove the replay trick inside an event handler.

The issue with that approach is that we end up double logging a lot of
errors in DEV since they get reported to the page.

It's also a lot of complexity around this feature.
2024-03-11 20:17:07 -04:00
Sebastian Silbermann
7d6f1e3c13 Remove ReactTestUtils from ReactBrowserEventEmitter-test (#28533) 2024-03-11 22:11:52 +01:00
Sebastian Silbermann
9c48fb25ec Remove ReactTestUtils from refs-destruction-test (#28532)
```diff
-expect(ReactTestUtils.isDOMComponent(maybeElement)).toBe(true);
+expect(maybeElement).toBeInstanceOf(Element);
```

It's not equivalent since `isDOMComponent` checks `maybeElement.nodeType
=== Element.ELEMENT_NODE && !!maybeElement.tagName` but `instanceof`
check seems sufficient here. Checking `nodeType` is mostly for
cross-realm checks and checking falsy `tagName` seems like a check
specifically for incomplete DOM implementations because tagName can't be
empty by spec I believe.
2024-03-11 22:11:40 +01:00
Sebastian Silbermann
58cd0ef35d Remove ReactTestUtils from ReactLegacyUpdates-test (#28531) 2024-03-11 22:11:31 +01:00
Lauren Tan
56d96ba203 [forget-runtime] Remove invariant dep
Reduces a dep needed to be installed by users of the polyfill
2024-03-11 16:31:46 -04:00
Jack Pope
eebdbf4454 Remove RTR from ReactProfiler-test (#28407)
## Summary

Internal cleanup of ReactTestRenderer

## How did you test this change?

`yarn test packages/react/src/__tests__/ReactProfiler-test.internal.js`
2024-03-11 15:07:58 -04:00
Jack Pope
605b7c018d Concurrent rendering in ReactDevToolsHooksIntegration-test (#28522)
## Summary

We need to unblock flipping the default for RTR to be concurrent
rendering. Update ReactDevToolsHooksIntegration-test to use
`unstable_isConcurrent` in place.

## How did you test this change?

`yarn test
packages/react-debug-tools/src/__tests__/ReactDevToolsHooksIntegration-test.js`
2024-03-11 15:06:35 -04:00
Mofei Zhang
e09c631aff [be][snap] Make testfilter file recognize glob patterns, remove @skip 2024-03-11 13:55:24 -04:00
Mofei Zhang
c84b817972 [be][snap] Warm up workers when in watch + filter mode 2024-03-11 13:55:22 -04:00
Mofei Zhang
2fc910d580 [optim] NewExpressions do not mutate the caller (class type)
``` 

function Foo() { 

const MyClass = getClass(); 

// following line is not expected to change MyClass 

return new MyClass(); 

} 

```
2024-03-11 13:03:45 -04:00
Ricky
56e20051c3 Land enableClientRenderFallbackOnTextMismatch for www (#28538)
This is landed, we can hardcode the flag
2024-03-11 11:40:48 -04:00
Noah Lemen
0d1ae5d753 cleanup enableProfilerNestedUpdateScheduledHook feature flag (#28509)
## Summary

Looks like this was added years ago for instrumentation at meta that
never ended up rolling out. Should be safe to clean up.

## How did you test this change?
`yarn test`
2024-03-11 11:37:17 -04:00
Sebastian Silbermann
dfaed55825 Remove remaining usages of ReactTestUtils in tests unrelated to react-dom/test-util (#28534)
Batched the remaining usages since these were straight forward.
Completes removal of `ReactTestUtils` from tests unrelated to
`react-dom/test-util` together with:
- https://github.com/facebook/react/pull/28531
- https://github.com/facebook/react/pull/28532
- https://github.com/facebook/react/pull/28533
2024-03-11 13:27:03 +01:00
Timothy Yung
706d95f486 Configure Dynamic Feature Flags for React Native (#28527)
## Summary

This PR is a subset of https://github.com/facebook/react/pull/28425,
which only includes the feature flags that will be configured as
dynamic.

The following list summarizes the feature flag changes:

* RN FB
  * Change to Dynamic
    * consoleManagedByDevToolsDuringStrictMode
    * enableAsyncActions
    * enableDeferRootSchedulingToMicrotask
    * enableRenderableContext
    * useModernStrictMode

## How did you test this change?

Ran the following successfully:

```
$ yarn test
$ yarn flow native
$ yarn flow fabric
```
2024-03-08 16:14:09 -08:00
Jan Kassens
71c4699de3 Upgrade flow to 0.230.0 (#28528)
Upgrade flow to 0.230.0

Ran
```
yarn add -W flow-bin flow-remove-types hermes-parser hermes-eslint
```
2024-03-08 17:39:27 -05:00
Mofei Zhang
df84152780 [hir] Attach fnType to HIRFunction
--- 

(This came out of running a sync and observing hundreds of bailouts due from 
this validation) 

Reading `fnType` from environment overgeneralizes, as inner functions are 
usually not the type of the outer react function. 

``` 

// Component type 

function Component() { 

// not Component type 

const helper = () => {...}; 

} 

``` 

Let's attach fnType to `HIRFunction` and use that for our inference + 
validations
2024-03-08 17:06:37 -05:00
Joe Savona
16852386a5 Support more cases of reassignment within value blocks
Fixes T175283039 — it's totally fine to have a StoreLocal as an instruction in a 
value block, so long as its a reassignment.
2024-03-08 13:59:22 -08:00
Joe Savona
5f3ed3f724 Fixture for reassignment within value block
Fixture from T175283039, a reassignment within an expression can sometimes 
generate a StoreLocal within a value block. Depending on the case this can end 
up as the last instruction of the block, which then hits an invariant.
2024-03-08 13:59:21 -08:00
Joe Savona
052f5fe973 Todo for "unreachable" possibly-hoisted functions
Adds a todo in HIRBuilder, before we prune unreachable code we check if there 
were any function expressions. Realistically that's only going to occur for 
hoisted functions, so this lets us target a todo rather than hit an invariant.
2024-03-08 13:59:20 -08:00
Joe Savona
7605e89a50 Repro for "unreachable" hoisted function
For T175282529. We already detect hoisted functions and have a specific todo for 
them, but in this case the function is in unreachable code that gets pruned 
during BuildHIR. The later check for hoisted functions doesn't find it.
2024-03-08 13:59:20 -08:00
Timothy Yung
4e2fe10fa3 Configure "Always On" Feature Flags for React Native (#28519)
## Summary

This PR is a subset of https://github.com/facebook/react/pull/28425,
which only includes the feature flags that will be configured as "always
on" (i.e. not "dynamic").

The following list summarizes the feature flag changes:

* RN FB
  * Always Enable
    * enableCache
    * enableCustomElementPropertySupport
* RN OSS
  * Always Enable
    * disableLegacyContext
    * enableCache
    * enableCustomElementPropertySupport
* RN Test
  * Always Enable
    * disableModulePatternComponents
    * enableCustomElementPropertySupport

## How did you test this change?

Ran the following successfully:

```
$ yarn test
$ yarn flow native
$ yarn flow fabric
```
2024-03-08 09:20:03 -08:00
Jack Pope
338dddc089 Remove RTR from DebugTracing-test (#28411)
## Summary

Internal cleanup of ReactTestRenderer

## How did you test this change?

`yarn test
packages/react-reconciler/src/__tests__/DebugTracing-test.internal.js`
2024-03-07 16:36:50 -05:00
Timothy Yung
c35b9b05fe Fix ReactHooksInspection-test.js (#28520)
## Summary

Currently, `ReactHooksInspection-test.js` fails because something is
polluting the resulting `Promise` with symbol properties. This changes
the unit test to be more resilient to such symbol properties.

## How did you test this change?

Ran the following successfully:

```
$ yarn test
```
2024-03-07 11:22:42 -08:00
Ruslan Lesiutin
447fc27e36 fix[devtools/e2e]: fixed source inspection in e2e tests (#28518)
DevTools e2e tests started to fail after landing
https://github.com/facebook/react/pull/28471:
-
https://app.circleci.com/pipelines/github/facebook/react/50984/workflows/a7be25ed-9547-40e9-87bd-b14d9d2e87da/jobs/798270
-
https://app.circleci.com/pipelines/github/facebook/react/50984/workflows/a7be25ed-9547-40e9-87bd-b14d9d2e87da/jobs/798275
-
https://app.circleci.com/pipelines/github/facebook/react/50984/workflows/a7be25ed-9547-40e9-87bd-b14d9d2e87da/jobs/798271
-
https://app.circleci.com/pipelines/github/facebook/react/50984/workflows/a7be25ed-9547-40e9-87bd-b14d9d2e87da/jobs/798274
-
https://app.circleci.com/pipelines/github/facebook/react/50984/workflows/a7be25ed-9547-40e9-87bd-b14d9d2e87da/jobs/798269

There are 2 reasons for that:
1. Versions 16.0 and 16.5 use legacy renderer, which doesn't support
source inspection by design:

850fac4915/packages/react-devtools-shared/src/backend/legacy/renderer.js (L831)

The corresponding e2e test is now gated for versions >=16.8
2. For other versions (>=16.8), the source is actually
`e2e-app-regression.js`, because these regression tests open a different
page (not the one we open for tests against React from source)

850fac4915/packages/react-devtools-inline/playwright.config.js (L15-L17)
2024-03-07 17:59:37 +00:00
Joe Savona
fe91bcefd2 Fix promotion of catch bindings w/in function expressions
One of our visitors wasn't visiting TryTerminal's handlerBinding, which meant 
that we missed renaming those identifiers in RenameVariables. I also updated the 
printers to print this binding.
2024-03-07 09:21:33 -08:00
Joe Savona
449aa70f99 Fix promotion of locals referenced outside of scopes 2024-03-06 16:19:28 -08:00
Joe Savona
854a810f05 Turn value block within try/catch into todo (from invariant)
Within a try/catch, every instruction is followed by a maybe-throw terminal. 
This currently breaks the logic in BuildReactiveFunction which tries to 
reassemble the value block, since it isn't expecting the maybe-throw. 
Conceptually the logic should just ignore it — we could even flatten away 
maybe-throw terminals before this pass — but for now since this pattern is rare 
we can just make it a todo.
2024-03-06 15:28:36 -08:00
Joe Savona
52875a72fe Invariant if codegen tries to emit a temporary as an identifier
For T181507827 — adds an invariant in codegen when emitting identifiers to 
ensure that we only create babel Identifier nodes for nodes that the compiler 
has explicitly promoted to valid, named identifiers. This means that we'll fail 
for unnamed temporaries (previously caught), as well as promoted temporaries 
that somehow didn't get renamed by RenameVariables (newly caught).
2024-03-06 21:50:03 -08:00
이동현
850fac4915 Link to reactjs/react.dev repo instead of reactjs/reactjs.org (#28493) 2024-03-07 00:20:57 +01:00
Joe Savona
ebbada309d MemoizeFbtOperandsInSameScope operates on HIR
Moves this pass to operate against HIRFunction instead of ReactiveFunction, no 
logic changes.
2024-03-06 14:02:18 -08:00
Joe Savona
e7fcc4e6a8 Rename promoteTemporary helpers
Renames the helpers for promoting temporaries to named identifiers, per feedback 
earlier in the stack.
2024-03-06 11:16:44 -08:00
Joe Savona
b7026ede39 Avoid generating conflicts w global names
Adds a visitor to collect all the globals that are referenced within the 
function, and then uses this list to avoid synthesizing variables with 
conflicting names. This is used in both RenameVariables (for promoted 
temporaries) and Codegen (for `$` and change variables only, so far, but this 
can be extended in follow-ups).
2024-03-06 11:07:11 -08:00
Joe Savona
8faed2af4c Avoid conflicting names for reactive scope codegen
This is a key part of avoiding generating conflicting names in our output. To 
start, RenameVariables now returns a Set of the unique identifier names that 
exist in the function. Codegen uses this to avoid generating duplicate names for 
change variables and for the `$` useMemoCache variable. Rather than always emit 
`$` or `c_N`, codegen checks that this name would not conflict and appends an 
incrementing suffix until it finds a unique name. 

Note that it's still possible for us to generate conflicts with global 
variables, both during RenameVariable and Codegen. The next step will be to 
avoid conflicts with globals.
2024-03-06 11:07:11 -08:00
Joe Savona
2ae0f36543 Promote and rename within nested functions
Another title for this PR could be "Yet another reason for HIR-everywhere" 

ReactiveFunctionVisitor doesn't traverse into HIRFunctions from 
FunctionExpression and ObjectMethod values. This means that 
PromoteUsedTemporaries and RenameVariables also weren't traversing into such 
functions, and those values weren't getting promoted and renamed correctly. 

This PR updates ReactiveFunctionVisitor with a method that can optionally be 
invoked to traverse an HIRFunction and call the appropriate visitor methods. 
PromoteUsedTemporaries and RenameVariables invoke this to ensure they visit all 
places, even in nested HIRFunctions.
2024-03-06 11:07:10 -08:00
Joe Savona
99b9da4b00 Move remaining promotion of temporaries out of codegen
I realized that codegen still had a fallback for generating identifier nodes for 
unnamed temporaries. This PR updates codegen to throw if it needs to generate an 
identifier for a temporary, and updates earlier passes to promote temporaries to 
named values in all the cases that were missed: 

* BuildHIR needs to promote temporaries for temporaries in destructuring 
bindings and catch clause bindings 

* PromoteUsedTemporaries has to promote temporaries for destructured function 
parameters or function params that are context variables.
2024-03-06 11:07:09 -08:00
Joe Savona
31e128a441 Use opaque type for Identifier.name for improved correctness
Uses an enum for Identifier.name to distinguish originally named identifiers vs 
promoted temporaries. An opaque type for the named identifier variant makes it 
hard to accidentally create that type.
2024-03-06 11:07:08 -08:00
Joe Savona
329bb555a0 [RFC] Stabilize naming of promoted temporaries
When the compiler promotes temporary values to named variables, we currently 
eagerly assign a name using the temporary's IdentifierId. This means that we're 
sort of stuck with this name later in compilation, and RenameVariables can't be 
100% sure whether a 't0' variable is a temporary or not. As a result, the names 
of these promoted temporaries is influenced by how many temporaries we happened 
to create during compilation (and what the next available identifier id was), 
making them fluctuate more as we iterate on the compiler. 

This is an RFC for showing how we can stabilize these names. The key elements: 

* Distinguish promoted temporaries from other named identifiers. Here we use a 
hack, naming them starting with '#t' or '#T', since '#' isn't a valid identifier 
starting point. This lets us keep all of our logic that looks for non-null 
identifiers names to distinguish named/unnamed, while also distinguishing real 
names from generated names (if this was Rust, we'd use an Enum and have a 
"isNamed()" method on it that was true for real/temporary names and false 
otherwise) 

* In RenameVariables, detect generated names and fall back to generating the 
next available `tN`-style name (or `TN` for JSX tags). 

* To reduce thrash overall, RenameVariables no longer keeps a global "next id" 
value that uses to distinguish all conflicting identifiers, instead we restart 
at 0 whenever we find a conflict, and keep bumping until we find a free name. 
Thus if both `foo` and `bar` had conflicts, we previously would end up with 
`foo$0` and `bar$1` as the deduped names, but now will end up with `foo$0` and 
`bar$0`. 

## RFC 

I'm open to feedback on the approach. Two main questions: 

* How to annotate promoted temporaries. The most type-safe option is to change 
`Identifier.name` to be a union of `{kind: 'named', value: string} | `{kind: 
'promoted', value: string} | `{kind: 'temporary'}` though TS then wouldn't allow 
`identifier.name.value` (even as nullable) since it doesn't exist on one of the 
variants. Maybe we could type the temporary one as `{kind: 'temporary', value?: 
null}` so the value has to be null but you can always access that property? 

* ?? Other concerns about the approach? We could keep the global 
auto-incrementing id rather than attempting to reset to 0 for each conflict.
2024-03-06 11:07:08 -08:00
Joe Savona
d1d6310f25 Conditional assignment of unmemoized value doesnt invalidate later scopes
The previous implementation used IdentifierId, but since this pass operates 
after LeaveSSA the identifier ids are no longer distinct for different SSA 
instances. Instead we use the Identifier instance, which preserves SSA 
information (even ever LeaveSSA) and allows distinguishing between variables 
whose value always changes vs variables that may be reassigned such that they 
don't always invalidate. 

In the future when we use HIR everywhere, this pass should use the HIR CFG to 
understand that phi nodes whose operands all will always invalidate can also be 
treated as always invalidating. 

## Test Plan 

Synced to www, 91 files have output changes 
(https://fburl.com/everpaste/3e3hjpjs). I spot checked these and confirmed that 
they are all from cases where there was already missing memoization of earlier 
values, where we now can prune later reactive scopes that depend on the 
un-memoized values.
2024-03-06 11:07:07 -08:00
bubucuo
64f354cf27 Remove unused returnFiber (#28504)
There is no use of `returnFiber` here, it can be removed.
2024-03-06 14:02:51 -05:00
Joe Savona
4af3ff1e75 Fixture for transitive invalidation of effect dep
This fixture shows that this optimization partially improves transitive checking 
for validateMemoizedEffectDependencies.
2024-03-06 09:28:03 -08:00
Joe Savona
f4455ef51a Prune scopes whose deps always invalidate
Implements the optimization described in the previous PR: if we know that a 
scope's dependency will _always_ invalidate (it is not memoized and it is 
guaranteed to be a new object if the instruction executes, such as an array or 
object literal), then we can prune that scope. The invalidation is transitive: 
we track always-invalidating types from within scopes, and if their scope gets 
invalidated we prune downstream scope that depend on them. 

## Test Plan 

Tested via #2639 - see https://fburl.com/everpaste/3e3hjpjs. 91 files change 
output due to reactive scopes which would always invalidate due to always 
invalidating dependencies.
2024-03-06 09:28:02 -08:00
Joe Savona
48e08c42be Fixtures where unmemoized value invalidates later scopes
These fixtures demonstrate how currently, even if the dependency of a scope 
doesn't get memoized (ie the scope gets pruned), we don't remove later scopes 
that depend on that value. Those later scopes will always invalidate, so we 
might as well remove them.
2024-03-06 09:28:01 -08:00
Sebastian Silbermann
0066e0b68d Devtools: Display actual pending state when inspecting useTransition (#28499) 2024-03-06 15:38:01 +01:00
Sebastian Markbåge
c11b196ae3 Move tail hydration mismatch back to hydration context (#28501)
In #23176 we added a special case in completeWork for SuspenseBoundaries
if they still have trailing children. However, that misses a case
because it doesn't log a recoverable error for the hydration mismatch.
So we get an error that we rerendered.

I think this special case was done to avoid contexts getting out of
sync. I don't know why we didn't just move where the pop happens though
so that's what I did here and let the regular pass throw instead. Seems
to be pass the tests.
2024-03-05 20:54:24 -05:00
Michael Vitousek
22ea72d4e9 Allow global mutation within useEffect (#2646)
Summary: Currently Forget bails on mutations to globals within any callback function. However, callbacks passed to useEffect should not bail and are not subject to the rules of react in the same way.

We allow this by instead of immediately raising errors when we see illegal writes, storing the error as part of the function. When the function is called, or passed to a position that could call it during rendering, we bail as before; but if it's passed to `useEffect`, we don't raise the errors.
2024-03-05 11:54:29 -08:00
Ruslan Lesiutin
966d17483c React DevTools 5.0.1 -> 5.0.2 (#28496)
* feat[devtools]: symbolicate source for inspected element
([hoxyq](https://github.com/hoxyq) in
[#28471](https://github.com/facebook/react/pull/28471))
* refactor[devtools]: lazily define source for fiber based on component
stacks ([hoxyq](https://github.com/hoxyq) in
[#28351](https://github.com/facebook/react/pull/28351))
* fix[devtools/tree/element]: onClick -> onMouseDown to handle first
click correctly ([hoxyq](https://github.com/hoxyq) in
[#28486](https://github.com/facebook/react/pull/28486))
* [DOM] disable legacy mode behind flag
([gnoff](https://github.com/gnoff) in
[#28468](https://github.com/facebook/react/pull/28468))
* Fix Broken Links In Documentation
([justindhillon](https://github.com/justindhillon) in
[#28321](https://github.com/facebook/react/pull/28321))
* Update /link URLs to react.dev
([rickhanlonii](https://github.com/rickhanlonii) in
[#28477](https://github.com/facebook/react/pull/28477))
* [tests] add support for @gate pragma
([gnoff](https://github.com/gnoff) in
[#28479](https://github.com/facebook/react/pull/28479))
* Devtools: Unwrap Promise in useFormState
([eps1lon](https://github.com/eps1lon) in
[#28319](https://github.com/facebook/react/pull/28319))
* Add support for rendering BigInt
([eps1lon](https://github.com/eps1lon) in
[#24580](https://github.com/facebook/react/pull/24580))
* Include server component names in the componentStack in DEV
([sebmarkbage](https://github.com/sebmarkbage) in
[#28415](https://github.com/facebook/react/pull/28415))
2024-03-05 14:11:30 +00:00
Ruslan Lesiutin
e5287287aa feat[devtools]: symbolicate source for inspected element (#28471)
Stacked on https://github.com/facebook/react/pull/28351, please review
only the last commit.

Top-level description of the approach:
1. Once user selects an element from the tree, frontend asks backend to
return the inspected element, this is where we simulate an error
happening in `render` function of the component and then we parse the
error stack. As an improvement, we should probably migrate from custom
implementation of error stack parser to `error-stack-parser` from npm.
2. When frontend receives the inspected element and this object is being
propagated, we create a Promise for symbolicated source, which is then
passed down to all components, which are using `source`.
3. These components use `use` hook for this promise and are wrapped in
Suspense.

Caching:
1. For browser extension, we cache Promises based on requested resource
+ key + column, also added use of
`chrome.devtools.inspectedWindow.getResource` API.
2. For standalone case (RN), we cache based on requested resource url,
we cache the content of it.
2024-03-05 12:32:11 +00:00
Ruslan Lesiutin
61bd00498d refactor[devtools]: lazily define source for fiber based on component stacks (#28351)
`_debugSource` was removed in
https://github.com/facebook/react/pull/28265.

This PR migrates DevTools to define `source` for Fiber based on
component stacks. This will be done lazily for inspected elements, once
user clicks on the element in the tree.

`DevToolsComponentStackFrame.js` was just copy-pasted from the
implementation in `ReactComponentStackFrame`.

Symbolication part is done in
https://github.com/facebook/react/pull/28471 and stacked on this commit.
2024-03-05 12:10:36 +00:00
Ruslan Lesiutin
aa4eae6b99 fix[devtools/tree/element]: onClick -> onMouseDown to handle first click correctly (#28486)
There is a weird behaviour in all shells of RDT: when user opens
`Components` tab and scrolls down a tree (without any prior click or
focus event), and then clicks on some element, the `click` event will
not be fired. Because `click` event hasn't been fired, the `focus` event
is fired for the whole list and we pre-select the first (root) element
in the tree:

034130c02f/packages/react-devtools-shared/src/devtools/views/Components/Tree.js (L217-L226)

Check the demo (before) what is happening. I don't know exactly why
`click` event is not fired there, but it only happens:
1. For elements, which were not previously rendered (for virtualization
purposes).
2. When HTML-element (div), which represents the container for the tree
was not focused previously.

Unlike the `click` event, the `mousedown` event is fired consistently.

### Before


https://github.com/facebook/react/assets/28902667/9f3ad75d-55d0-4c99-b2d0-ead63a120ea0

### After



https://github.com/facebook/react/assets/28902667/e34816be-644c-444c-8e32-562a79494e44


Tested that it works in all shells, including the select / deselect
features (with `metaKey` param in event).
2024-03-05 11:42:10 +00:00
Josh Story
0ae2b13412 [Test] Update flushSync tests to use react-dom (#28490)
Updates the `flushSync` tests to use react-dom instead of ReactNoop.
flushSync is primarily a react-dom API and asserting the implementation
of ReactNoop is not really ideal especially since we are going to be
refactoring flushSync soon to not be implemented in the reconciler
internals.

ReactNoop still have a flushSync api and it can still be used in other
tests that are primarily about testing other functionlity and use
ReactNoop as the renderer.
2024-03-04 21:40:15 -08:00
Jordan Brown
f5d99baf8e Add config option to ignore 'use no forget' directives
This will let us test without taking into account the existing 'use no forget' 
directives to better understand what validations we may need to build. 

There are two other files that look for this directive that do not seem to take 
compiler options: 

1. 
408617ec8a/react/scripts/babel/transform-forget.js (L25) 

2. 
408617ec8a/packages/babel-plugin-react-forget/scripts/jest/makeTransform.ts (L119) 

Do I need to do anything for those?
2024-03-04 19:00:48 -05:00
Josh Story
113ab9af08 [Flight][Fizz][Fiber] Chain HostDispatcher implementations (#28488)
The idea here is that host dispatchers are not bound to renders so we
need to be able to dispatch to them at any time. This updates the
implementation to chain these dispatchers so that each renderer can
respond to the dispatch. Semantically we don't always want every
renderer to do this for instance if Fizz handles a float method we don't
want Fiber to as well so each dispatcher implementation can decide if it
makes sense to forward the call or not. For float methods server
disaptchers will handle the call if they can resolve a Request otherwise
they will forward. For client dispatchers they will handle the call and
always forward. The choice needs to be made for each dispatcher method
and may have implications on correct renderer import order. For now we
just live with the restriction that if you want to use server and client
together (such as renderToString in the browser) you need to import the
server renderer after the client renderer.
2024-03-04 12:27:15 -08:00
Josh Story
1c02b9d2bd [DOM] disable legacy mode behind flag (#28468)
Adds a flag to disable legacy mode. Currently this flag is used to cause
legacy mode apis like render and hydrate to throw. This change also
removes render, hydrate, unmountComponentAtNode, and
unstable_renderSubtreeIntoContainer from the experiemntal entrypoint.
Right now for Meta builds this flag is off (legacy mode is still
supported). In OSS builds this flag matches __NEXT_MAJOR__ which means
it currently is on in experiemental. This means that after merging
legacy mode is effectively removed from experimental builds. While this
is a breaking change, experimental builds are not stable and users can
pin to older versions or update their use of react-dom to no longer use
legacy mode APIs.
2024-03-04 08:19:17 -08:00
Justin Dhillon
034130c02f Fix Broken Links In Documentation (#28321)
## Summary

I used [link-inspector](https://github.com/justindhillon/link-inspector)
to find a bunch of broken links in this projects documentation. Here is
what I fixed:

https://www.html5rocks.com/en/tutorials/canvas/hidpi/ -->
https://web.dev/articles/canvas-hidipi


https://w3c.github.io/webcomponents/spec/custom/#custom-elements-core-concepts
--> https://www.w3.org/TR/custom-elements/


https://github.com/facebookarchive/fixed-data-table/blob/main/src/vendor_upstream/dom/normalizeWheel.js
-->
https://github.com/facebookarchive/fixed-data-table/blob/master/src/vendor_upstream/dom/normalizeWheel.js

https://upload.wikimedia.org/wikipedia/commons/e/ee/Atom_%282%29.png -->
https://upload.wikimedia.org/wikipedia/commons/1/1b/Atom.png

## Support my work

I used [link-inspector](https://github.com/justindhillon/link-inspector)
to find and fix this issue. If you find this PR useful, give the repo a
2024-03-03 17:44:27 -05:00
Ricky
1940cb27b2 Update /link URLs to react.dev (#28477)
Depends on https://github.com/reactjs/react.dev/pull/6670 [merged]
2024-03-03 17:34:33 -05:00
Josh Story
30ae0baed1 [devtools][tests] add support for @gate pragma (#28479)
Adds support for `// @gate` pragma in devtools tests
Adds a couple gate test assertions to ensure they continue to work
2024-03-01 13:26:07 -08:00
dan
11828bf529 Remove loose-envify dep and browserify configs (#28480)
Browserify isn't widely used, and at this point I don't think it makes
sense to have a special config just for the sake of it. Let's remove it?
2024-03-01 20:49:51 +00:00
Ricky
5f2c6b74db Update homepage URLs to react.dev (#28478)
Updates the package.json "homepage" entry to react.dev
2024-03-01 14:35:18 -05:00
Andrew Clark
2f8f776022 Move ref type check to receiver (#28464)
The runtime contains a type check to determine if a user-provided ref is
a valid type — a function or object (or a string, when
`disableStringRefs` is off). This currently happens during child
reconciliation. This changes it to happen only when the ref is passed to
the component that the ref is being attached to.

This is a continuation of the "ref as prop" change — until you actually
pass a ref to a HostComponent, class, etc, ref is a normal prop that has
no special behavior.
2024-02-29 21:26:36 -05:00
Sebastian Markbåge
bb4b147da9 Clean up empty string special cases (#28475)
This was fixed in https://github.com/facebook/react/pull/22807 so we
don't need these special cases anymore.
2024-02-29 20:27:26 -05:00
Sathya Gunasekaran
7f994241b0 Infer type of ref argument
Extend type inference to infer second argument of component as a ref type
2024-02-29 14:47:52 -08:00
Sathya Gunasekaran
ad8f19675c Infer type of React function
Infer if a function is a component or hook when we're deciding to compile a 
function and store that in the environment. 

This is used in passes like InferReferenceEffects rather than having to re-parse 
the name in each pass.
2024-02-29 14:47:51 -08:00
Sathya Gunasekaran
19e44a4a69 Allow ref argument to be mutated
Previously, Forget would throw if _any_ of the arguments to a component are 
modified. This isn't quite right as a ref argument can be modified. 

This PR assumes the second argument of a component to be a ref and allows it to 
be mutable. 

A future PR will add types to this argument so the validateRefAccessDuringRender 
can catch if ref is mutated in render. This PR contains a todo test for this.
2024-02-29 14:47:49 -08:00
Jan Kassens
b8da12e8f8 Add dynamic flag for infinite loop detection on React Native FB (#28456)
Add dynamic flag for infinite loop detection on React Native FB
2024-02-29 13:19:12 -08:00
Mofei Zhang
9d25ced018 [instrument] Optional globalGating means no global gating 2024-02-29 10:04:37 -08:00
Mofei Zhang
01454d1414 [other] Make global gating (e.g. DEV) check configurable 2024-02-29 09:44:28 -08:00
Sebastian Silbermann
fb10a2c66a Devtools: Unwrap Promise in useFormState (#28319) 2024-02-28 23:52:59 +01:00
Joe Savona
6dbec55791 Support prefixed useState due to pre-bundling 2024-02-28 13:12:56 -08:00
Sebastian Silbermann
01ab35a9a7 Run yarn flags in CI (#28345) 2024-02-28 00:12:53 +01:00
Sebastian Silbermann
c6bb12edd0 Remove ReactTestUtils from ReactJSXRuntime (#28337) 2024-02-28 00:12:17 +01:00
Sebastian Silbermann
e7849b50bc Remove ReactTestUtils from ReactJSXElementValidator (#28335) 2024-02-28 00:12:08 +01:00
Ricky
d88fb321a3 Move enableRenderableContext back to dynamic (#28466) 2024-02-27 18:11:42 -05:00
Ricky
dee1aac77f Turn on disableJavaScriptURLs for experimental (#28462)
This is on everywhere, ready to turn on in the next major.
2024-02-27 16:33:14 -05:00
Joe Savona
9d5a01359f Move creation of scopes for primitives into a separate pass
Rather than force scopes to be created for primitives within
InferReactiveScopeVariables, here we move the creation of scopes for these
instructions to a later pass. Later in the pipeline we have more context, such
as whether e.g. a primitive or propertyload is being accessed within a scope or
not, and whether it therefore needs its own scope or not.
2024-02-27 12:01:32 -08:00
Joe Savona
45216dc3d9 Track next scope id on Environment
Currently we allocate all reactive scopes during a single pass, 
InferReactiveScopeVariables, using a local incrementing number to assign 
ScopeIds. This means we can't easily create additional scopes later since we 
don't know the next available scope id. 

Here we add `Environment.nextScopeId` and use that to synthesize scope ids.
2024-02-27 11:39:22 -08:00
Sathya Gunasekaran
130b809ac2 Allow property loads from hook
Looking up certain properties on a hook is a common pattern for logging. 

It's non-ideal but it's not a bug to do this. 

This updates Forget to not error on this pattern.
2024-02-28 16:19:43 -08:00
Sathya Gunasekaran
8879a2dd49 Remove sprout from package.json 2024-02-28 15:22:13 -08:00
Mofei Zhang
a06ded902a [other] Change instrumentation to use an optional gating identifier; record
filepath 

Internal rollout currently has a good number of test failures. 
`enableEmitInstrumentForget` can help developers understand which functions / 
files they should look at: 

``` 

// input 

function Foo() { 

userCode(); 

// ... 

} 

// output 

function Foo() { 

if (__DEV__ && inE2eTestMode) { 

logRender("Foo", "/path/to/filename.js"); 

} 

const $ = useMemoCache(...); 

userCode(); 

} 

```
2024-02-27 22:06:36 -08:00
Andrew Clark
c9798954e2 Remove string refs (behind flag) (#28322)
Depends on:

- https://github.com/facebook/react/pull/28398

---

This removes string refs, which has been deprecated in Strict Mode for
seven years.

I've left them behind a flag for Meta, but in open source this fully
removes the feature.
2024-02-27 11:43:04 -05:00
Noah Lemen
3bcd2de01b clean up isInputPending in Scheduler (#28444)
## Summary

`isInputPending` is not in use. This PR cleans up the flags controlling
its gating and parameters to simplify Scheduler.

Makes `frameYieldMs` feature flag static, set to 10ms in www, which we
found built on the wins provided by a broader yield interval via
`isInputPending`. Flag remains set to 5ms in OSS builds.

## How did you test this change?
`yarn test Scheduler`
2024-02-27 10:39:43 -05:00
Joe Savona
5acfc13575 Repro for invariant on value block in try/catch
The code for value block handling assumes a small set of terminal kinds, but 
try/catch causes the entire body to get wrapped in MaybeThrow terminals. We need 
to skip over these and delegate to the inner content.
2024-02-26 16:21:56 -08:00
Joe Savona
84ed1f2a37 Update scope declaration invariant to support error grouping
This invariant interpolated values into the `reason` which prevent our internal 
tooling from grouping related errors. This PR updates to make the reason static 
and interpolate the description.
2024-02-26 15:08:42 -08:00
Joe Savona
d81da8e2f5 Fix JSXMemberExpression dependency calculation
Fixes T173101142 — we previously computed incorrect function expression 
dependencies for JSXMemberExpressions. This PR applies similar logic to 
JSXMemberExpression as we use for MemberExpression. 

## Test Plan 

Synced internally, only one file changes output. I manually investigated to 
confirm — the change is that a function expression's dependencies are more 
precise and correct. See https://fburl.com/everpaste/4dqewxqv
2024-02-26 15:04:44 -08:00
Mofei Zhang
915a0b8389 [be] Consolidate sprout -> snap
--- 

No changes to snap or sprout's functionality. 

Tweaks to consolidate sprout into snap while keeping its simple interface and 
most developer patterns. 

- to keep `filter` mode fast, we do not run sprout in filter mode 

- sprout is run in non-filter mode for both test and update 

~~Small qol improvement: `--watch` will start you in `filter` mode~~ 

### Cost of this change 

`performance.now()` is quite noisy due to background processes and ThreadPool 
logic (especially with asymmetric task distribution), so I used 
`process.cpuUsage` which reports time spent in user-space. This was much less 
noisy (1-4% standard dev / mean) 

Running all tests becomes slower by ~50%. Initial runs are slower because they 
load in Forget's `require` chains. 

- 23.9s previous initial run 

- 34.6s current initial run 

- 11.5s previous subsequent runs 

- 15.4s current subsequent runs 

Running filtered tests remains very fast (~100ms on the average case) 

--- 

Additional modes or commands could be added as needed (e.g. run tests in filter 
mode, with sprout output)
2024-02-27 06:54:30 -08:00
Sebastian Silbermann
172a7f629a Convert ReactDOMServerIntegrationLegacyContextDisabled to createRoot (#28448) 2024-02-26 21:55:23 +01:00
Sebastian Silbermann
e6d8374728 Convert ReactDOMServerIntegrationLegacyContext to createRoot (#28449) 2024-02-26 21:55:03 +01:00
Sebastian Silbermann
2314227de5 Convert ReactTestUtils to createRoot (#28446)
it'll be removed soon anyway but until then let's unblock moving legacy
APIs behind a flag.
2024-02-26 21:54:46 +01:00
Sebastian Silbermann
f637f6a473 Convert ReactServerRenderingHydration to createRoot (#28447) 2024-02-26 20:59:43 +01:00
Sebastian Silbermann
2f240c91ed Add support for rendering BigInt (#24580) 2024-02-26 19:18:50 +01:00
Ricky
6c3b8dbfed Turn on enableRenderableContext for www (#28438)
We can land for www now
2024-02-26 10:08:47 -05:00
Ricky
239d06e2b8 Make enableClientRenderFallbackOnText dynamic (#28436) 2024-02-25 13:20:42 -05:00
Sebastian Silbermann
aed00dacfb devtools: Use context displayName for context hook name (#25954) 2024-02-24 11:54:26 +01:00
Sebastian Markbåge
118ad2afa7 Validate DOM nesting for hydration before the hydration warns / errors (#28434)
If there's invalid dom nesting, there will be mismatches following but
the nesting is the most important cause of the problem.

Previously we would include the DOM nesting when rerendering thanks to
the new model of throw and recovery. However, the log would come during
the recovery phase which is after we've already logged that there was a
hydration mismatch.

People would consistently miss this log. Which is fair because you
should always look at the first log first as the most probable cause.

This ensures that we log in the hydration phase if there's a dom nesting
issue. This assumes that the consequence of nesting will appear such
that the won't have a mismatch before this. That's typically the case
because the node will move up and to be a later sibling. So as long as
that happens and we keep hydrating depth first, it should hold true.
There might be an issue if there's a suspense boundary between the nodes
we'll find discover the new child in the outer path since suspense
boundaries as breadth first.

Before:

<img width="996" alt="Screenshot 2024-02-23 at 7 34 01 PM"
src="https://github.com/facebook/react/assets/63648/af70cf7f-898b-477f-be39-13b01cfe585f">

After:

<img width="853" alt="Screenshot 2024-02-23 at 7 22 24 PM"
src="https://github.com/facebook/react/assets/63648/896c6348-1620-4f99-881d-b6069263925e">

Cameo: RSC stacks.
2024-02-24 00:45:42 -05:00
Joe Savona
5261281985 move reassignment-related range adjustments to
InferReactiveScopeVariables
2024-02-23 16:58:10 -08:00
Joe Savona
d3589367b0 Handle scopes with reassignment (by expanding scopes to avoid it) 2024-02-23 14:41:27 -08:00
Joe Savona
a815d481c0 Support scopes with multiple declarations
Expands support for reactive scopes that have multiple declarations. We
return an array and destructure after, preserving the reactivity.
2024-02-23 14:41:26 -08:00
Joe Savona
ca1e92ad91 Compile partial reassignments into a single derived scope 2024-02-23 14:41:25 -08:00
Andrew Clark
16d3f7833d Delete use of source in JSX runtime (#28433)
Only remaining place it was being used was in a warning message.
2024-02-23 16:52:00 -05:00
Sebastian Markbåge
d579e77482 Remove method name prefix from warnings and errors (#28432)
This pattern is a petpeeve of mine. I don't consider this best practice
and so most don't have these prefixes. Very inconsistent.

At best this is useless and noisey that you have to parse because the
information is also in the stack trace.

At worse these are misleading because they're highlighting something
internal (like validateDOMNesting) which even suggests an internal bug.
Even the ones public to React aren't necessarily what you called because
you might be calling a wrapper around it.

That would be properly reflected in a stack trace - which can also
properly ignore list so that the first stack you see is your callsite,

Which might be like `render()` in react-testing-library rather than
`createRoot()` for example.
2024-02-23 15:16:54 -05:00
Sebastian Markbåge
8fb0233a84 Include server component names in the componentStack in DEV (#28415)
I'm a bit ambivalent about this one because it's not the main strategy
that I plan on pursuing. I plan on replacing most DEV-only specific
stacks like `console.error` stacks with a new take on owner stacks and
native stacks. The future owner stacks may or may not be exposed to
error boundaries in DEV but if they are they'd be a new errorInfo
property since they're owner based and not available in prod.

The use case in `console.error` mostly goes away in the future so this
PR is mainly for error boundaries. It doesn't hurt to have it in there
while I'm working on the better stacks though.

The `componentStack` property exposed to error boundaries is more like
production behavior similar to `new Error().stack` (which even in DEV
won't ever expose owner stacks because `console.createTask` doesn't
affect these). I'm not sure it's worth adding server components in DEV
(this PR) because then you have forked behavior between dev and prod.

However, since even in the future there won't be any other place to get
the *parent* stack, maybe this can be useful information even if it's
only dev. We could expose a third property on errorInfo that's DEV only
and parent stack but including server components. That doesn't seem
worth it over just having the stack differ in dev and prod.

I don't plan on adding line/column number to these particular stacks.

A follow up could be to add this to Fizz prerender too but only in DEV.
2024-02-23 12:04:55 -05:00
Jack Pope
66c8346401 [RTR] Add usage warning behind flag (#27903)
## Summary

Moving towards deprecation of ReactTestRenderer. Log a warning on each
render so we can remove the exports in a future major version.

We can enable this flag in web RTR without disrupting RN tests by
flipping the flag in
`packages/shared/forks/ReactFeatureFlags.test-renderer.js`

## How did you test this change?

`yarn test
packages/react-test-renderer/src/__tests__/ReactTestRenderer-test.js`
2024-02-23 11:33:18 -05:00
Ricky
98b8359f65 [RN] Move unifiedSyncLane back to dynamic (#28430)
This surfaced a bug because it wasn't on everywhere, moving back to
dynamic while we investigate the bug
2024-02-23 15:31:01 +00:00
Timothy Yung
aaa4acb128 Add enableComponentStackLocations to ReactNativeInternalFeatureFlags libdef (#28424)
## Summary

Fixing something I accidentally broke this in
25dbb3556e.

## How did you test this change?

Ran the following successfully:

```
$ yarn flow dom-node
```
2024-02-22 18:58:12 -05:00
Timothy Yung
25dbb3556e Dynamic enableComponentStackLocations Flag for React Native (FB) (#28400)
## Summary

Changes the `enableComponentStackLocations` feature flag to be dynamic
for React Native (FB), so that it can be evaluated for compatibility
before eventually being enabled for React Native.

## How did you test this change?

I'll be importing this PR to test it.
2024-02-22 15:40:12 -08:00
Ricky
07c2543e54 Ignore /fixtures for dependabot (#28422)
We'll keep these up to date out of band, they are just for testing and
don't ship in the npm packages.
2024-02-22 15:44:37 -05:00
Ricky
aaf85f3af8 Make enableRefAsProp www dynamic (#28423)
Going to start rolling this out
2024-02-22 15:35:52 -05:00
Ricky
e4b816ba1a s/getRootNode/ownerDocument (#28412)
getRootNode isn't always available, use ownerDocument instead
2024-02-22 14:53:02 -05:00
Ruslan Lesiutin
288cf747c9 React DevTools 5.0.0 -> 5.0.1 (#28418)
Full list of changes (not a public CHANGELOG):

* feature[REMOVED][devtools]: turn off / hide location based component
filters ([hoxyq](https://github.com/hoxyq) in
[#28417](https://github.com/facebook/react/pull/28417))
* Add useSyncExternalStore and useTransition to getPrimitiveStackCache
([jamesbvaughan](https://github.com/jamesbvaughan) in
[#28399](https://github.com/facebook/react/pull/28399))
* chore[devtools]: use react-window from npm and bump
react-virtualized-auto-sizer to ^1.0.23
([hoxyq](https://github.com/hoxyq) in
[#28408](https://github.com/facebook/react/pull/28408))
* Pass ref as normal prop ([acdlite](https://github.com/acdlite) in
[#28348](https://github.com/facebook/react/pull/28348))
* Combine createElement and JSX modules
([acdlite](https://github.com/acdlite) in
[#28320](https://github.com/facebook/react/pull/28320))
* [Debug Tools] Always use includeHooksSource option
([sebmarkbage](https://github.com/sebmarkbage) in
[#28309](https://github.com/facebook/react/pull/28309))
* Revert "[Tests] Reset modules by default"
([acdlite](https://github.com/acdlite) in
[#28318](https://github.com/facebook/react/pull/28318))
* Switch <Context> to mean <Context.Provider>
([gaearon](https://github.com/gaearon) in
[#28226](https://github.com/facebook/react/pull/28226))
* [Debug Tools] Introspect Promises in use()
([sebmarkbage](https://github.com/sebmarkbage) in
[#28297](https://github.com/facebook/react/pull/28297))
* fix[devtools/useModalDismissSignal]: use getRootNode for shadow root
case support ([hoxyq](https://github.com/hoxyq) in
[#28145](https://github.com/facebook/react/pull/28145))
* fix: define IS_ACT_ENVIRONMENT global for tests with concurrent mode
and synchronous act ([hoxyq](https://github.com/hoxyq) in
[#28296](https://github.com/facebook/react/pull/28296))
* chore: gate legacy apis for react-devtools-shell
([hoxyq](https://github.com/hoxyq) in
[#28273](https://github.com/facebook/react/pull/28273))
* DevTools: Add support for use(Context)
([eps1lon](https://github.com/eps1lon) in
[#28233](https://github.com/facebook/react/pull/28233))
* Remove __self and __source location from elements
([sebmarkbage](https://github.com/sebmarkbage) in
[#28265](https://github.com/facebook/react/pull/28265))
* chore: use versioned render in inspectedElement test
([hoxyq](https://github.com/hoxyq) in
[#28246](https://github.com/facebook/react/pull/28246))
* chore: use versioned render in TimelineProfiler test and gate some for
legacy rendering ([hoxyq](https://github.com/hoxyq) in
[#28218](https://github.com/facebook/react/pull/28218))
* [Tests] Reset modules by default
([rickhanlonii](https://github.com/rickhanlonii) in
[#28254](https://github.com/facebook/react/pull/28254))
* chore: use versioned render in preprocessData test and gate some for …
([hoxyq](https://github.com/hoxyq) in
[#28219](https://github.com/facebook/react/pull/28219))
* chore: use versioned render in storeStressSync test and gate them for
legacy rendering ([hoxyq](https://github.com/hoxyq) in
[#28216](https://github.com/facebook/react/pull/28216))
* Patch devtools before running useMemo function in strict mode
([gsathya](https://github.com/gsathya) in
[#28249](https://github.com/facebook/react/pull/28249))
* chore: use versioned render in storeComponentFilters test
([hoxyq](https://github.com/hoxyq) in
[#28241](https://github.com/facebook/react/pull/28241))
* chore: use versioned render in profilerContext test
([hoxyq](https://github.com/hoxyq) in
[#28243](https://github.com/facebook/react/pull/28243))
* chore: use versioned render in profilingCommitTreeBuilder test and
gate some for legacy rendering ([hoxyq](https://github.com/hoxyq) in
[#28236](https://github.com/facebook/react/pull/28236))
* chore: use versioned render in profilingHostRoot test and gate some
for legacy rendering ([hoxyq](https://github.com/hoxyq) in
[#28237](https://github.com/facebook/react/pull/28237))
* chore: use versioned render in profilingCache test
([hoxyq](https://github.com/hoxyq) in
[#28242](https://github.com/facebook/react/pull/28242))
* chore: use versioned render in ownersListContext test
([hoxyq](https://github.com/hoxyq) in
[#28240](https://github.com/facebook/react/pull/28240))
* chore: use versioned render in editing test
([hoxyq](https://github.com/hoxyq) in
[#28239](https://github.com/facebook/react/pull/28239))
* chore: use versioned render in treeContext test
([hoxyq](https://github.com/hoxyq) in
[#28245](https://github.com/facebook/react/pull/28245))
* chore: use versioned render in store test
([hoxyq](https://github.com/hoxyq) in
[#28244](https://github.com/facebook/react/pull/28244))
* chore: use versioned render in profilerStore test
([hoxyq](https://github.com/hoxyq) in
[#28238](https://github.com/facebook/react/pull/28238))
* chore: use versioned render in profilingCharts test
([hoxyq](https://github.com/hoxyq) in
[#28235](https://github.com/facebook/react/pull/28235))
* chore: use versioned render in profilerChangeDescriptions test
([hoxyq](https://github.com/hoxyq) in
[#28221](https://github.com/facebook/react/pull/28221))
* chore: use versioned render in storeOwners test
([hoxyq](https://github.com/hoxyq) in
[#28215](https://github.com/facebook/react/pull/28215))
* chore: use versioned render in componentStacks test
([hoxyq](https://github.com/hoxyq) in
[#28214](https://github.com/facebook/react/pull/28214))
* chore: use versioned render in console test
([hoxyq](https://github.com/hoxyq) in
[#28213](https://github.com/facebook/react/pull/28213))
* chore: use versioned render in useEditableValue test
([hoxyq](https://github.com/hoxyq) in
[#28212](https://github.com/facebook/react/pull/28212))
* chore: use versioned render in FastRefreshDevToolsIntegration test
([hoxyq](https://github.com/hoxyq) in
[#28211](https://github.com/facebook/react/pull/28211))
* chore: add versioned render implementation for DevTools tests
([hoxyq](https://github.com/hoxyq) in
[#28210](https://github.com/facebook/react/pull/28210))
* chore: add single versioned implementation of act for DevTools tests
([hoxyq](https://github.com/hoxyq) in
[#28186](https://github.com/facebook/react/pull/28186))
* DevTools: Add support for useFormState
([eps1lon](https://github.com/eps1lon) in
[#28232](https://github.com/facebook/react/pull/28232))
* DevTools: Add support for useOptimistic Hook
([eps1lon](https://github.com/eps1lon) in
[#27982](https://github.com/facebook/react/pull/27982))
* Add stable React.act export ([acdlite](https://github.com/acdlite) in
[#28160](https://github.com/facebook/react/pull/28160))
* [flow] upgrade to 0.225.1 ([kassens](https://github.com/kassens) in
[#27871](https://github.com/facebook/react/pull/27871))
* fix[devtools/e2e]: add fallback for act in integration tests
([hoxyq](https://github.com/hoxyq) in
[#27842](https://github.com/facebook/react/pull/27842))
* Add stable concurrent option to react-test-renderer
([jackpope](https://github.com/jackpope) in
[#27804](https://github.com/facebook/react/pull/27804))
* Update act references in tests ([gnoff](https://github.com/gnoff) in
[#27805](https://github.com/facebook/react/pull/27805))
* Flow: make more objects exact ([kassens](https://github.com/kassens)
in [#27790](https://github.com/facebook/react/pull/27790))
2024-02-22 19:45:55 +00:00
Ruslan Lesiutin
d54b4cf303 fix[devtools]: fixed Tree indentation logic after updating react-windows (#28421)
Forward-fixing the indentation after landing
https://github.com/facebook/react/pull/28408. Could potentially be
related to `ref` changes in `react`, but haven't validated yet.

Haven't occured while testing the previous PR, but reproduced while
testing the https://github.com/facebook/react/pull/28418, for which I've
rebuilt all dependencies, including `react`.

This change basically removes the props passing from original parent,
`rest` should include only `ref`:
efad3d8909/src/createListComponent.js (L382)
2024-02-22 19:18:30 +00:00
Ruslan Lesiutin
d4cac3f96c feature[REMOVED][devtools]: turn off / hide location based component filters (#28417)
Following https://github.com/facebook/react/pull/28265, this should
disable location-based component filters.

```
// Following __debugSource removal from Fiber, the new approach for finding the source location
// of a component, represented by the Fiber, is based on lazily generating and parsing component stack frames
// To find the original location, React DevTools will perform symbolication, source maps are required for that.
// In order to start filtering Fibers, we need to find location for all of them, which can't be done lazily.
// Eager symbolication can become quite expensive for large applications.
```

I am planning to publish a patch version of RDT soon, so I think its
better to remove this feature, instead of shipping it in a broken state.

The reason for filtering out these filters is a potential cases, where
we load filters from the backend (like in RN, where we storing some
settings on device), or these filters can be stored in user land
(`window.__REACT_DEVTOOLS_COMPONENT_FILTERS__`).

Explicitly tested the case when:
1. Load current RDT extension, add location-based component filter
2. Reload the page and observe that previously created component filter
is preserved
3. Re-load RDT extension with these changes, observe there is no
previously created component filter and user can't create a new
location-based filter
4. Reload RDT extension without these changes, no location-based filters
saved, user can create location-based filters
2024-02-22 16:59:29 +00:00
James Vaughan
47beb96ccf Add useSyncExternalStore and useTransition to getPrimitiveStackCache (#28399)
<!--
  Thanks for submitting a pull request!
We appreciate you spending the time to work on these changes. Please
provide enough information so that others can review your pull request.
The three fields below are mandatory.

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

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

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

## Summary

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

This solves the problem of the devtools extension failing to parse hook
names for components that make use of `useSyncExternalStore` or
`useTransition`.

See #27889 

## 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 against my own codebases and against the example repro
project that I linked in #27889.

To test, I opened up the Components tab of the dev tools extension,
selected a component with hooks that make use of `useSyncExternalStore`
or `useTransition`, clicked the "parse hook names" magic wand button,
and observed that it now succeeds.
2024-02-22 11:42:52 +00:00
Ruslan Lesiutin
404ed92658 chore[devtools]: use react-window from npm and bump react-virtualized-auto-sizer to ^1.0.23 (#28408)
1. Bumps `react-virtualized-auto-sizer` to 1.0.23, which has a fix for
cases with multiple realms -
https://github.com/bvaughn/react-virtualized-auto-sizer/pull/82
2. Removes `react-window` from react-devtools-shared/src/node_modules,
now listed as dependency in `package.json` and bumped to 1.8.10

Tested:
- Chrome extension
- Standalone shell with RN
2024-02-22 11:31:10 +00:00
Sebastian Silbermann
81d2a51a97 Add smoke test for flight fixture (#28350) 2024-02-21 23:47:36 +01:00
Jack Pope
59fe6c3ac1 Remove RTR from StrictEffectsMode-test (#28387)
## Summary

Cleaning up internal usage of ReactTestRenderer

## How did you test this change?

`yarn test
packages/react-reconciler/src/__tests__/StrictEffectsMode-test.js`
2024-02-21 15:17:52 -05:00
Sebastian Markbåge
c0274063f0 [Flight] Prefix Replayed Console Logs with a Badge (#28403)
Builds on top of #28384.

This prefixes each log with a badge similar to how we badge built-ins
like "ForwardRef" and "Memo" in the React DevTools. The idea is that we
can add such badges in DevTools for Server Components too to carry on
the consistency.

This puts the "environment" name in the badge which defaults to
"Server". So you know which source it is coming from.

We try to use the same styling as the React DevTools. We use light-dark
mode where available to support the two different color styles, but if
it's not available I use a fixed background so that it's always readable
even in dark mode.

In Terminals, instead of hard coding colors that might not look good
with some themes, I use the ANSI color code to flip
background/foreground colors in that case.

In earlier commits I had it on the end of the line similar to the
DevTools badges but for multiline I found it better to prefix it. We
could try various options tough.

In most cases we can use both ANSI and the `%c` CSS color specifier,
because node will only use ANSI and hide the other. Chrome supports both
but the color overrides ANSI if it comes later (and Chrome doesn't
support color inverting anyway). Safari/Firefox prints the ANSI, so it
can only use CSS colors.

Therefore in browser builds I exclude ANSI.

On the server I support both so if you use Chrome inspector on the
server, you get nice colors on both terminal and in the inspector.

Since Bun uses WebKit inspector and it prints the ANSI we can't safely
emit both there. However, we also can't emit just the color specifier
because then it prints in the terminal.
https://github.com/oven-sh/bun/issues/9021 So we just use a plain string
prefix for now with a bracket until that's fixed.

Screen shots:

<img width="758" alt="Screenshot 2024-02-21 at 12 56 02 AM"
src="https://github.com/facebook/react/assets/63648/4f887ffe-fffe-4402-bf2a-b7890986d60c">
<img width="759" alt="Screenshot 2024-02-21 at 12 56 24 AM"
src="https://github.com/facebook/react/assets/63648/f32d432f-f738-4872-a700-ea0a78e6c745">
<img width="514" alt="Screenshot 2024-02-21 at 12 57 10 AM"
src="https://github.com/facebook/react/assets/63648/205d2e82-75b7-4e2b-9d9c-aa9e2cbedf39">
<img width="489" alt="Screenshot 2024-02-21 at 12 57 34 AM"
src="https://github.com/facebook/react/assets/63648/ea52d1e4-b9fa-431d-ae9e-ccb87631f399">
<img width="516" alt="Screenshot 2024-02-21 at 12 58 23 AM"
src="https://github.com/facebook/react/assets/63648/52b50fac-bec0-471d-a457-1a10d8df9172">
<img width="956" alt="Screenshot 2024-02-21 at 12 58 56 AM"
src="https://github.com/facebook/react/assets/63648/0096ed61-5eff-4aa9-8a8a-2204e754bd1f">
2024-02-21 14:59:08 -05:00
Sebastian Markbåge
9a5b6bd84f [Flight] Instrument the Console in the RSC Environment and Replay Logs on the Client (#28384)
When developing in an RSC environment, you should be able to work in a
single environment as if it was a unified environment. With thrown
errors we already serialize them and then rethrow them on the client.

Since by default we log them via onError both in Flight and Fizz, you
can get the same log in the RSC runtime, the SSR runtime and on the
client.

With console logs made in SSR renders, you typically replay the same
code during hydration on the client. So for example warnings already
show up both in the SSR logs and on the client (although not guaranteed
to be the same). You could just spend your time in the client and you'd
be fine.

Previously, RSC logs would not be replayed because they don't hydrate.
So it's easy to miss warnings for example.

With this approach, we replay RSC logs both during SSR so they end up in
the SSR logs and on the client. That way you can just stay in the
browser window during normal development cycles. You shouldn't have to
care if your component is a server or client component when working on
logical things or iterating on a product.

With this change, you probably should mostly ignore the Flight log
stream and just look at the client or maybe the SSR one. Unless you're
digging into something specific. In particular if you just naively run
both Flight and Fizz in the same terminal you get duplicates. I like to
run out fixtures `yarn dev:region` and `yarn dev:global` in two separate
terminals.

Console logs may contain complex objects which can be inspected. Ideally
a DevTools inspector could reach into the RSC server and remotely
inspect objects using the remote inspection protocol. That way complex
objects can be loaded on demand as you expand into them. However, that
is a complex environment to set up and the server might not even be
alive anymore by the time you inspect the objects. Therefore, I do a
best effort to serialize the objects using the RSC protocol but limit
the depth that can be rendered.

This feature is only own in dev mode since it can be expensive.

In a follow up, I'll give the logs a special styling treatment to
clearly differentiate them from logs coming from the client. As well as
deal with stacks.
2024-02-21 14:47:55 -05:00
Noah Lemen
41b3c31bcb remove RTR from ReactCacheOld-test (#28409)
## Summary

swaps `react-test-renderer` for `react-noop-rendererer` in
ReactCacheOld-test

## How did you test this change?

`yarn test-www ReactCacheOld`
2024-02-21 13:31:43 -05:00
Andrew Clark
dc30644ca7 Convert string ref props to callback props (#28398)
When enableRefAsProp is on, we should always use the props as the source
of truth for refs. Not a field on the fiber.

In the case of string refs, this presents a problem, because string refs
are not passed around internally as strings; they are converted to
callback refs. The ref used by the reconciler is not the same as the one
the user provided.

But since this is a deprecated feature anyway, what we can do is clone
the props object and replace it with the internal callback ref. Then we
can continue to use the props object as the source of truth.

This means the internal callback ref will leak into userspace. The
receiving component will receive a callback ref even though the parent
passed a string. Which is weird, but again, this is a deprecated
feature, and we're only leaving it around behind a flag so that Meta can
keep using string refs temporarily while they finish migrating their
codebase.
2024-02-21 11:41:29 -05:00
bubucuo
ddd736d258 refactor: remove dead types of fiber (#28405)
The properties `firstEffect` and `lastEffect` of the Fiber are currently
not being used and are considered to be dead code, and can be removed.
2024-02-21 11:17:21 +00:00
dan
353ecd0516 Remove JSX propTypes validation (#28328)
This removes the remaining `propTypes` validation calls, making
declaring `propTypes` a no-op. In other words, React itself will no
longer validate the `propTypes` that you declare on your components.

In general, our recommendation is to use static type checking (e.g.
TypeScript). If you'd like to still run propTypes checks, you can do so
manually, same as you'd do outside React:

```js
import checkPropTypes from 'prop-types/checkPropTypes';

function Button(props) {
  checkPropTypes(Button.propTypes, prop, 'prop', Button.name)
  // ...
}
```

This could be automated as a Babel plugin if you want to keep these
checks implicit. (We will not be providing such a plugin, but someone in
community might be interested in building or maintaining one.)
2024-02-21 11:15:51 +00:00
Sebastian Markbåge
4ea424e63d Capitalize the default Flight environment (#28402)
It's cleaner and more in line with how we style other badges like "Memo"
and "ForwardRef" in DevTools.
2024-02-20 22:30:23 -05:00
Jack Pope
3b260007ed Remove RTR from ReactCreateRef-test (#28386)
## Summary

Cleaning up internal usage of ReactTestRenderer

## How did you test this change?

`yarn test packages/react/src/__tests__/ReactCreateRef-test.js`
2024-02-20 17:49:51 -05:00
Jack Pope
0778f61321 Remove RTR usage from useSubscription-test (#28388)
## Summary

Cleaning up internal usage of ReactTestRenderer

## How did you test this change?

`yarn test
packages/use-subscription/src/__tests__/useSubscription-test.js`
2024-02-20 17:49:26 -05:00
Sebastian Silbermann
cefc1c66c1 Remove unused ReactTestUtils from ReactDOMServerIntegration tests (#28379) 2024-02-20 22:49:34 +01:00
Masato Nakamura
51c9146072 Bump actions/checkout (#28383) 2024-02-20 22:46:43 +01:00
Jack Pope
90a0ae1015 Remove RTR from ReactSuspense-test (#28390)
## Summary

Cleaning up internal usage of ReactTestRenderer

## How did you test this change?

`yarn test
packages/react-reconciler/src/__tests__/ReactSuspense-test.internal.js`
2024-02-20 15:40:16 -05:00
bubucuo
49441e342f refactor: remove dead code of fiber (#28389)
The `nextEffect` property of the `fiber` is currently not being used and
has become dead code. It can be safely removed.
2024-02-20 14:31:15 -05:00
Sebastian Markbåge
8f012266dc Rename default FlightClientConfigs to FlightClientStreamConfig (#28382)
Since this is more about specifically the streaming protocol and I'll
add other dimensions that don't map 1:1.

E.g. some configs need to be the same across all servers.
2024-02-20 14:24:08 -05:00
Andrew Clark
fa2f82addc Pass ref as normal prop (#28348)
Depends on:

- #28317 
- #28320 

---

Changes the behavior of the JSX runtime to pass through `ref` as a
normal prop, rather than plucking it from the props object and storing
on the element.

This is a breaking change since it changes the type of the receiving
component. However, most code is unaffected since it's unlikely that a
component would have attempted to access a `ref` prop, since it was not
possible to get a reference to one.

`forwardRef` _will_ still pluck `ref` from the props object, though,
since it's extremely common for users to spread the props object onto
the inner component and pass `ref` as a differently named prop. This is
for maximum compatibility with existing code — the real impact of this
change is that `forwardRef` is no longer required.

Currently, refs are resolved during child reconciliation and stored on
the fiber. As a result of this change, we can move ref resolution to
happen only much later, and only for components that actually use them.
Then we can remove the `ref` field from the Fiber type. I have not yet
done that in this step, though.
2024-02-20 14:17:41 -05:00
Sebastian Silbermann
a515d753ba Annotate legacy mode tests in ReactDOMInput (#28333) 2024-02-20 16:52:49 +01:00
Sebastian Silbermann
1deda7690f Remove ReactTestUtils from ReactDOMComponent (#28334) 2024-02-20 16:52:30 +01:00
Sebastian Silbermann
48ca0e8298 Remove ReactTestUtils from ReactUpdates (#28378) 2024-02-20 16:52:11 +01:00
Sebastian Silbermann
7b196be091 Remove ReactTestUtils from ReactDOM-test (#28377) 2024-02-20 16:51:44 +01:00
Sebastian Silbermann
3c9560b29e Remove ReactTestUtils from ReactComponentLifeCycle (#28376) 2024-02-20 16:51:10 +01:00
Sebastian Silbermann
e68431c89f Remove ReactTestUtils from ReactJSXTransformIntegration (#28338) 2024-02-20 16:50:52 +01:00
Sebastian Silbermann
7ab84fb116 Remove usage of ReactTestUtils from ReactFunctionComponent (#28331) 2024-02-20 16:50:34 +01:00
Sebastian Silbermann
b559f5fefe Remove ReactTestUtils from refs-test (#28336) 2024-02-20 16:50:17 +01:00
Andrew Clark
5fb2c93f39 Combine createElement and JSX modules (#28320)
Depends on:

- #28317 

---

There's a ton of overlap between the createElement implementation and
the JSX implementation, so I combined them into a single module.

In the actual build output, the shared code between JSX and
createElement will get duplicated anyway, because react/jsx-runtime and
react (where createElement lives) are separate, flat build artifacts.

So this is more about code organization — with a few key exceptions, the
implementations of createElement and jsx are highly coupled.
2024-02-19 22:45:18 -05:00
Andrew Clark
ec160f32c2 Combine ReactJSXElementValidator with main module (#28317)
There are too many layers to the JSX runtime implementation. I think
basically everything should be implemented in a single file, so that's
what I'm going to do.

As a first step, this deletes ReactJSXElementValidator and moves all the
code into ReactJSXElement. I can already see how this will help us
remove more indirections in the future.

Next I'm going to do start moving the `createElement` runtime into this
module as well, since there's a lot of duplicated code.
2024-02-19 22:14:29 -05:00
Andrew Clark
c820097716 Move all markRef calls into begin phase (#28375)
Certain fiber types may have a ref attached to them. The main ones are
HostComponent and ClassComponent. During the render phase, we check if a
ref was passed to it, and if so, we schedule a Ref effect: `markRef`.

Currently, we're not consistent about whether we call `markRef` in the
begin phase or the complete phase. For some fiber types, I found that
`markRef` was called in both phases, causing redundant work.

After some investigation, I don't believe it's necessary to call
`markRef` in both the begin phase and the complete phase, as long as you
don't bail out before calling `markRef`.

I though that maybe it had to do with the
`attemptEarlyBailoutIfNoScheduledUpdates` branch, which is a fast path
that skips the regular begin phase if no new props, state, or context
were passed. But if the props haven't changed (referentially — the
`memo` and `shouldComponentUpdate` checks happen later), then it follows
that the ref couldn't have changed either. This is true even in the old
`createElement` runtime where `ref` is stored on the element instead of
as a prop, because there's no way to pass a new ref to an element
without also passing new props. You might argue this is a leaky
assumption, but since we're shifting ref to be just a regular prop
anyway, I think it's the correct way to think about it going forward.

I think the pattern of calling `markRef` in the complete phase may have
been left over from an earlier iteration of the implementation before
the bailout logic was structured like it is today.

So, I removed all the `markRef` calls from the complete phase. In the
case of ScopeComponent, which had no corresponding call in the begin
phase, I added one.

We already had a test that asserted that a ref is reattached even if the
component bails out, but I added some new ones to be extra safe.

The reason I'm changing this this is because I'm working on a different
change to move the ref handling logic in `coerceRef` to happen in render
phase of the component that accepts the ref, instead of during the
parent's reconciliation.
2024-02-19 21:06:43 -05:00
Sebastian Markbåge
2e84e16299 [Flight] Better error message if you pass a function as a child to a client component (#28367)
Similar to #28362 but if you pass it to a client component.
2024-02-19 12:36:16 -05:00
Sebastian Markbåge
65a0e2b25e [Flight] Warn if this argument is passed to .bind of a Server Reference (#28380)
This won't ever be serialized and is likely just a mistake.

This should be covered by the "use server" compiler since it ensures
that something that accepts a "this" won't be allowed to compile and if
it doesn't accept it, TypeScript should ideally forbid it to be passed.

So maybe this is unnecessary.
2024-02-19 11:50:13 -05:00
Sebastian Markbåge
017397d7d3 Recover from SSR error in Flight fixture (#28368)
If an error happens before the shell, we need to handle it. In this case
we choose the strategy of rendering a blank document and client
rendering the app. Which will intentionally have a hydration mismatch.
2024-02-19 11:50:04 -05:00
Sebastian Markbåge
9444c51c7e [Flight] Allow a Server Reference to be registered twice (#28343)
It's possible for the same function instance to appear more than once in
the same graph or even the same file.

Currently this errors on trying to reconfigure the property but it
really doesn't matter which one wins. First or last.

Regardless there will be an entry point generated that can get them.
2024-02-19 11:49:38 -05:00
Sebastian Markbåge
c323f8290c Encode better error messages when part of the context is a client reference (#28355)
Alternative to #28354.

If a client reference is one of the props being describes as part of
another error, we call toString on it, which errors.

We should error explicitly when a Symbol prop is extracted.

However, pragmatically I added the toString symbol tag even though we
don't know what the real tostring will be but we also lie about the
typeof.

We can however in addition to this give it a different description
because describing this property as an object isn't quite right.

We probably could extract the export name but that's kind of renderer
specific and I just added this shared module to Fizz which doesn't have
that which is unfortunate an consequence.

For default exports we don't have a good name of what the alias was in
the receiver. Could maybe call it "default" but for now I just call it
"client".
2024-02-19 11:49:25 -05:00
Sebastian Silbermann
59831c98cf Improve stack trace when gated test fails (#28374) 2024-02-18 18:17:02 +01:00
Sebastian Markbåge
c1fd2a91b1 Include the function name for context on invalid function child (#28362)
Also warn for symbols.

It's weird because for objects we throw a hard error but functions we do
a dev only check. Mainly because we have an object branch anyway.

In the object branch we have some built-ins that have bad errors like
forwardRef and memo but since they're going to become functions later, I
didn't bother updating those. Once they're functions those names will be
part of this.
2024-02-17 16:41:59 -05:00
Sebastian Silbermann
fef30c2e04 Fix crash running yarn flags --sort flag (#28344) 2024-02-17 15:28:35 +01:00
Sebastian Silbermann
62a9c7db18 Annotate legacy mode test in ReactDOMSingletonComponents (#28339)
These are mainly regression tests for legacy root.
2024-02-17 15:28:18 +01:00
Sebastian Markbåge
6a44f352ec Consume the RSC stream twice in the Flight fixture (#28353)
We have an unresolved conflict where the Flight client wants to execute
inside Fizz to emit side-effects like preloads (which can be early) into
that stream. However, the FormState API requires the state to be passed
at the root, so if you're getting that through the RSC payload it's a
Catch 22.

#27314 used a hack to mutate the form state array to fill it in later,
but that doesn't actually work because it's not always an array. It's
sometimes null like if there wasn't a POST. This lead to a bunch of
hydration errors - which doesn't have the best error message for this
case neither. It probably should error with something that specifies
that it's form state.

This fixes it by teeing the stream into two streams and consuming it
with two Flight clients. One to read the form state and one to emit
side-effects and read the root.
2024-02-16 18:25:09 -05:00
Joe Savona
d6406d8360 Validate hook calls in object methods
Adds some test cases for hook calls in object methods. Initially we didn't catch 
these because InferTypes doesn't actually visit ObjectMethod bodies. Once we fix 
that we correctly reject these examples.
2024-02-16 11:27:52 -08:00
Joe Savona
9c419dfd80 Disallow calling hooks in functions
> Don’t call Hooks inside loops, conditions, or nested functions 

Per https://react.dev/warnings/invalid-hook-call-warning#breaking-rules-of-hooks 
it is invalid to call hooks inside function expressions. We now validate this by 
default, i'll verify internally before landing. 

Note the validation is somewhat more conservative and we only disallow known 
hook calls here, this seems like a reasonable tradeoff but i'm open to 
suggestions. We could reuse the same known/potential hook mechanism here but it 
would take some more refactoring.
2024-02-16 11:00:56 -08:00
Joe Savona
a4234bcfbf infer mode only compiles component/hook decls
Forks the logic from Program.ts, letting us customize what
gets compiled.
2024-02-17 17:37:00 -08:00
Joe Savona
ca3d16c5ef Enable hook syntax support
Updates the compiler to understand Flow hook syntax. Like component syntax, in 
infer mode hooks are compiled by default unless opted out. 

Looking ahead, i can imagine splitting up our compilation modes as follows: 

* Annotations: opt-in explicitly 

* Declarations: annotations + component/hook declarations 

* Infer: annotations, component/hook declarations, + component/hook-like 
functions 

This also suggest an alternative annotation strategy: "use react" (or "use 
component" / "use hook") as a general way to tell the compiler that a function 
is intended for React. Then opting out of memoization could do "use 
react(nomemo)".
2024-02-17 17:31:47 -08:00
Joe Savona
1e3f9130f3 Rewrite reactive scopes to computed with lambda
Updates LowerReactiveScopes to rewrite to a ReactiveFunctionValue
(ReactiveFunction-based) instead of a FunctionExpression (HIR-based). This lets
us include terminals and even nested reactive scopes in the result.
2024-02-16 14:59:01 -08:00
Joe Savona
191064b55c Add ReactiveFunctionValue variant
Per the previous PR, we don't have a way to rewrite an arbitrary subset of a
ReactiveFunction into a function expression, since FunctionExpression's contents
is still in HIR.

While long-term our plan is to move to HIR everywhere, this PR adds a stopgap of
adding a ReactiveFunctionValue variant of ReactiveValue. As a reminder,
ReactiveValue is a union of (HIR) InstructionValue | SequenceExpression |
LogicalExpression | ConditionalExpression.

For now i did a first stab at the visitors and transforms with the idea that:

* By default, visitors/transforms _don't_ look into these function expressions,
since we didn't previously traverse into (HIR-based) FunctionExpression either

* But there is a visitor/transform method that you can override if you need to.
2024-02-16 14:59:00 -08:00
Joe Savona
03874a29b3 Repro for needing function body rewriting in ReactiveFunction phase
Adds an example demonstrating why we need the ability to rewrite parts of a
ReactiveFunction into a function expression. Here, the reactive scope needs to
contain an `if` terminal, but we can't put a ReactiveIfTerminal inside a
function expression, since that expects HIR.

There are two main paths forward:

* Use HIR everywhere. I wrote this up and we're all agreed, it's just a bunch of
work.

* Add an alternative FunctionExpression variant to ReactiveFunction

For now i'm going to take the second route.
2024-02-16 14:58:59 -08:00
Sathya Gunasekaran
770ca4ab3e [Babel] Add support for "use memo"
We want to start moving away from "Forget", so this PR adds support "use memo" 
and "use no memo" 

I've left "use forget" and "use no forget" directives unchanged for now, as we 
need to migrate existing users first and then come back and delete support for 
these directives.
2024-02-19 17:48:49 +00:00
Jack Pope
ef72271c2d Add useModernStrictMode as dynamic flag on www (#28346)
## Summary

Preparing modern strict mode rollout with dynamic feature flag

## How did you test this change?

![Screenshot 2024-02-15 at 10 09
49 AM](https://github.com/facebook/react/assets/8965173/9e90efc2-3578-4e63-ae2c-63d4a4e194b3)
2024-02-16 11:21:35 -05:00
Josh Story
a9cc32511a stash the component stack on the thrown value and reuse (#25790)
ErrorBoundaries are currently not fully composable. The reason is if you
decide your boundary cannot handle a particular error and rethrow it to
higher boundary the React runtime does not understand that this throw is
a forward and it recreates the component stack from the Boundary
position. This loses fidelity and is especially bad if the boundary is
limited it what it handles and high up in the component tree.

This implementation uses a WeakMap to store component stacks for values
that are objects. If an error is rethrown from an ErrorBoundary the
stack will be pulled from the map if it exists. This doesn't work for
thrown primitives but this is uncommon and stashing the stack on the
primitive also wouldn't work
2024-02-15 20:44:44 -08:00
Sebastian Markbåge
2ba1b78569 Downgrade pmmmwh/react-refresh-webpack-plugin in the Flight fixture (#28352)
The newer version triggers an error due to require() not being compiled.

This was upgraded in #27328. I'm not sure why that was needed. Maybe it
was just because it was allowed by the caret and something else upgraded
but I haven't been able to make it work with the newer version. So I'll
just pin it.
2024-02-15 22:23:30 -05:00
dan
fea900e454 Remove non-JSX propTypes checks (#28326)
Removes all `propTypes` validation called from outside the JSX
factories. Haven't touched JSX.

Tests that verify related behavior are stripped down to the
non-`propTypes` logic.
2024-02-16 00:35:22 +00:00
Jan Kassens
530f2c293d Add test fixture showing invalid location
Add test fixture showing invalid location 

The error should be on the node mutating the output, not in the read location.
2024-02-15 19:00:21 -05:00
Jan Kassens
ac89712750 Add code frame to snap errors
Add code frame to snap errors 

This should make it easier (possible) to see if errors point at the right lines. 

No idea why I had to add 1 to the column, you'd think it's all babel-standard 
(whatever it is) and there wouldn't be off by one errors, but I'm not quite in 
the mood to debug babel issues more then necessary right now...
2024-02-15 18:42:21 -05:00
Lauren Tan
d3bca420c0 Opt out react-forget-runtime from being Forgotten
This caused a build error when Forget was used in an Expo app as the 
react-forget-runtime package was itself being compiled with Forget. This broke 
Metro as metro serializes modules to iifes, but the import syntax that was 
injected by the useMemoCachePolyfill flag was left behind 

In practice I don't think the runtime package needs to ever be compiled by 
Forget, so this PR opts out the whole file. This would also prevent builds from 
breaking if someone decided to use the "all" compilation mode. 

Test plan: Ran the expo app and verified that it now builds with no errors
2024-02-15 17:44:44 -05:00
Lauren Tan
5142affc26 Allow module level "use no forget"
Currently we only allow adding the directive to function bodies, but there may 
be cases where we want to always opt out an entire module from being compiled by 
Forget
2024-02-15 17:44:44 -05:00
Hendrik Liebau
92686722ca [Flight] Fix reference param type in registerServerReference (#27688)
The `reference` that is passed into `registerServerReference` can be a
plain function. It does not need to have the three additonal properties
of a `ServerRefeference`. In fact, adding these properties (plus `bind`)
is precisely what `registerServerReference` does.
2024-02-15 16:09:25 -05:00
Sebastian Silbermann
0745e6bee9 Remove usage of ReactTestUtils from ReactContextValidator (#28329) 2024-02-15 19:14:35 +01:00
Sebastian Silbermann
710d5137e2 Remove ReactTestUtils from ReactIdentity (#28332) 2024-02-15 19:14:19 +01:00
Sebastian Markbåge
2e470a788e [Fizz] Align recoverable error serialization in dev mode (#28340)
Same as #28327 but for Fizz.

One thing that's weird about this recoverable error is that we don't
send the regular stack for it, just the component stack it seems. This
is missing some potential information and if we move toward integrated
since stacks it would be one thing.
2024-02-14 20:15:59 -05:00
Joe Savona
21c5631570 [be] Prune implicit breaks when flattening unused labels
A labeled block will generally end with an implicit break out of the label. 
However, if there are no _explicit_ breaks to the label, we'll end up with a 
ReactiveFunction along the lines of: 

``` 

bb1: { 

...instructions with no explicit `break bb1`... 

(implicit) break; 

} 

``` 

The `PruneUnusedLabels` pass removes such unused labels, inlining the content of 
label terminal into the surrounding block. However, we weren't pruning the 
`break`! This wasn't a problem in practice since codegen, and future passes, 
would just ignore this. But it's more correct to go and find these unnecessary 
implicit breaks and prune them, which this PR does. 

Again, this shouldn't have any impact other than producing cleaner 
ReactiveFunction data during debugging.
2024-02-14 15:36:40 -08:00
Joe Savona
ad5a272393 Skip functions using same rules as regular pipeline 2024-02-14 15:23:37 -08:00
Sebastian Markbåge
a7144f297c [Flight] Improve error message when it's not a real Error object (#28327)
Also deals with symbols. Alternative to #28312.

We currently always normalize rejections or thrown values into `Error`
objects. Partly because in prod it'll be an error object and you
shouldn't fork behavior on knowing the value outside a digest. We might
want to even make the message always opaque to avoid being tempted and
then discover in prod that it doesn't work.

However, we do include the message in DEV.

If this is a non-Error object we don't know what the properties mean.
Ofc, we don't want to include too much information in the rendered
string, so we use the general `describeObjectForErrorMessage` helper.
Unfortunately it's pretty conservative about emitting values so it's
likely to exclude any embedded string atm. Could potentially expand it a
bit.

We could in theory try to serialize as much as possible and re-throw the
actual object to allow for inspection to be expanded inside devtools
which is what I plan on for consoles, but since we're normalizing to an
Error this is in conflict with that approach.
2024-02-14 18:21:07 -05:00
Joe Savona
09d122a20e [be] Remove @enableMergeConsecutiveScopes flag, feature is stable
Continuing on my quest to clean up our feature flags, the logic for merging 
consecutive feature flags is stable. Let's remove 
`@enableMergeConsecutiveScopes` since this is enabled everywhere.
2024-02-14 15:13:00 -08:00
Jordan Brown
a927040b7a Add an optional validation to bail out on capitalized function calls
Some components stop being components over time and are used as regular 
functions instead, but they may have lingering hook calls. Those hook calls make 
it so the capitalized function calling them do not error (they appear to be a 
function to existing eslint rules), but they are nonetheless unsafe to memoize. 
This diff adds a conservative option to bail out on all capitalized function 
calls. 

There are a handful of known-non-component capitalized functions, like 
`Boolean`, `String`, and `Number`. This diff also adds the ability to supply 
capitalized function names that should not be considered in this analysis. 

I added three tests: 

1. Ensure an error occurs in the obvious case 

2. Ensure an error occurs when the value is aliased simply 

3. Ensure the allowlist works 

This is my first commit so please go hard on me. I was unsure about where this 
code should live, so please nitpick.
2024-02-14 13:23:32 -05:00
dan
adadb8169e Rewrite tests that depend on propTypes warnings (#28325)
In preparation for https://github.com/facebook/react/pull/28207.

These tests aren't actually testing propTypes, they just use them to
verify we can display a meaningful component name. We've mostly moved
away from warnings that display component names directly in favor of
component stacks. So let's just replace these with tests asserting the
component names show up in stacks.
2024-02-14 17:07:33 +00:00
dan
64e755d737 Remove propTypes checks for legacy context (#28324)
Part of https://github.com/facebook/react/pull/28207, this is easy to
land in isolation.

The approach I'm taking is slightly different — instead of leaving
validation on for legacy context, I disable the validation (it's
DEV-only) and leave just the parts that drive the runtime logic. I.e.
`contexTypes` and `childContextTypes` *values* are now ignored, the keys
are used just like before.
2024-02-14 16:22:30 +00:00
Sebastian Markbåge
f0e808e5bc [Debug Tools] Always use includeHooksSource option (#28309)
This option was added defensively but it's not needed. There's no cost
to including it always.

I suspect this optional was added mainly to avoid needing to update
tests. That's not a reason to have an unnecessary public API though.

We have a praxis for dealing with source location in tests to avoid them
failing tests. I also ported them to inline snapshots so that additions
to the protocol isn't such a pain.
2024-02-14 11:07:35 -05:00
Sebastian Markbåge
dc3178151b Add ignoreList to our source maps (#28310)
All our sources are considered third party and should be hidden in stack
traces unless expanded. Our internals aren't actionable anyway.

This doesn't really do much without tooling that actually forwards this
to new generated source maps, in which case they probably just add them
to ignorelist anyway.
2024-02-13 12:54:06 -05:00
Ricky
0d108f2182 Enable more noop RN flags (#28307) 2024-02-13 12:15:55 -05:00
Ricky
4867a3365e Enable disableJavaScriptURLs for RN (#28306)
This is DOM only
2024-02-13 12:15:44 -05:00
Ricky
5d445b50a6 Land enableAsyncActions enableFormActions in www (#28315) 2024-02-13 11:48:56 -05:00
Andrew Clark
015ff2ed66 Revert "[Tests] Reset modules by default" (#28318)
This was causing a slowdown in one of the tests
ESLintRuleExhaustiveDeps-test.js. Reverting until we figure out why.
2024-02-13 11:39:45 -05:00
dan
14fd9630ee Switch <Context> to mean <Context.Provider> (#28226)
Previously, `<Context>` was equivalent to `<Context.Consumer>`. However,
since the introduction of Hooks, the `<Context.Consumer>` API is rarely
used. The goal here is to make the common case cleaner:

```js
const ThemeContext = createContext('light')

function App() {
  return (
    <ThemeContext value="dark">
      ...
    </ThemeContext>
  )
}

function Button() {
  const theme = use(ThemeContext)
  // ...
}
```

This is technically a breaking change, but we've been warning about
rendering `<Context>` directly for several years by now, so it's
unlikely much code in the wild depends on the old behavior. [Proof that
it warns today (check
console).](https://codesandbox.io/p/sandbox/peaceful-nobel-pdxtfl)

---

**The relevant commit is 5696782b428a5ace96e66c1857e13249b6c07958.** It
switches `createContext` implementation so that `Context.Provider ===
Context`.

The main assumption that changed is that a Provider's fiber type is now
the context itself (rather than an intermediate object). Whereas a
Consumer's fiber type is now always an intermediate object (rather than
it being sometimes the context itself and sometimes an intermediate
object).

My methodology was to start with the relevant symbols, work tags, and
types, and work my way backwards to all usages.

This might break tooling that depends on inspecting React's internal
fields. I've added DevTools support in the second commit. This didn't
need explicit versioning—the structure tells us enough.
2024-02-13 10:04:49 -05:00
Ricky
32df74dba6 Fix jest inline snapshots (#28308)
Prettier 3 is not supported for jest inline snapshots:
https://jestjs.io/docs/configuration#prettierpath-string
2024-02-12 22:03:50 -05:00
Sebastian Markbåge
8d48183291 [Flight] Allow custom encoding of the form action (#27563)
There are three parts to an RSC set up:

- React
- Bundler
- Endpoints

Most customizability is in the bundler configs. We deal with those as
custom builds.

To create a full set up, you need to also configure ways to expose end
points for example to call a Server Action. That's typically not
something the bundler is responsible for even though it's responsible
for gathering the end points that needs generation. Exposing which
endpoints to generate is a responsibility for the bundler.

Typically a meta-framework is responsible for generating the end points.

There's two ways to "call" a Server Action. Through JS and through a
Form. Through JS we expose the `callServer` callback so that the
framework can call the end point.

Forms by default POST back to the current page with an action serialized
into form data, which we have a decoder helper for. However, this is not
something that React is really opinionated about just like we're not
opinionated about the protocol used by callServer.

This exposes an option to configure the encoding of the form props.
`encodeFormAction` is to the SSR is what `callServer` is to the Browser.
2024-02-12 20:02:42 -05:00
Sebastian Markbåge
7a32d718b9 [Debug Tools] Introspect Promises in use() (#28297)
Alternative to #28295.

Instead of stashing all of the Usables eagerly, we can extract them by
replaying the render when we need them like we do with any other hook.
We already had an implementation of `use()` but it wasn't quite
complete.

These can also include further DebugInfo on them such as what Server
Component rendered the Promise or async debug info. This is nice just to
see which use() calls were made in the side-panel but it can also be
used to gather everything that might have suspended.

Together with https://github.com/facebook/react/pull/28286 we cover the
case when a Promise was used a child and if it was unwrapped with use().
Notably we don't cover a Promise that was thrown (although we do support
that in a Server Component which maybe we shouldn't). Throwing a Promise
isn't officially supported though and that use case should move to the
use() Hook.

The pattern of conditionally suspending based on cache also isn't really
supported with the use() pattern. You should always call use() if you
previously called use() with the same input. This also ensures that we
can track what might have suspended rather than what actually did.

One limitation of this strategy is that it's hard to find all the places
something might suspend in a tree without rerendering all the fibers
again. So we might need to still add something to the tree to indicate
which Fibers may have further debug info / thenables.
2024-02-12 17:54:28 -05:00
Sebastian Markbåge
3f93ca1c8d [Fiber] Transfer _debugInfo from Arrays, Lazy, Thenables and Elements to the inner Fibers. (#28286)
That way we can use it for debug information like component stacks and
DevTools. I used an extra stack argument in Child Fiber to track this as
it's flowing down since it's not just elements where we have this info
readily available but parent arrays and lazy can merge this into the
Fiber too. It's not great that this is a dev-only argument and I could
track it globally but seems more likely to make mistakes.

It is possible for the same debug info to appear for multiple child
fibers like when it's attached to a fragment or a lazy that resolves to
a fragment at the root. The object identity could be used in these
scenarios to infer if that's really one server component that's a parent
of all children or if each child has a server component with the same
name.

This is effectively a public API because you can use it to stash
information on Promises from a third-party service - not just Server
Components. I started outline the types for this for some things I was
planning to add but it's not final.

I was also planning on storing it from `use(thenable)` for when you
suspend on a Promise. However, I realized that there's no Hook instance
for those to stash it on. So it might need a separate data structure to
stash the previous pass over of `use()` that resets each render.

No tests yet since I didn't want to test internals but it'll be covered
once we have debugging features like component stacks.
2024-02-12 14:56:59 -05:00
Sebastian Markbåge
9e7944f67c Suspend Thenable/Lazy if it's used in React.Children and unwrap (#28284)
This pains me because `React.Children` is really already
pseudo-deprecated.

`React.Children` takes any children that `React.Node` takes. We now
support Lazy and Thenable in this position elsewhere, but it errors in
`React.Children`.

This becomes an issue with async Server Components which can resolve
into a Lazy and in the future Lazy will just become Thenables. Which
causes this to error.

There are a few different semantics we could have:

1) Error like we already do (#28280). `React.Children` is about
introspecting children. It was always sketchy because you can't
introspect inside an abstraction anyway. With Server Components we fold
away the components so you can actually introspect inside of them kind
of but what they do is an implementation detail and you should be able
to turn it into a Client Component at any point. The type of an Element
passing the boundary actually reduces to `React.Node`.
2) Suspend and unwrap the Node (this PR). If we assume that Children is
called inside of render, then throwing a Promise if it's not already
loaded or unwrapping would treat it as if it wasn't there. Just like if
you rendered it in React. This lets you introspect what's inside which
isn't really something you should be able to do. This isn't compatible
with deprecating throwing-a-Promise and enable static compilation like
`use()` does. We'd have to deprecate `React.Children` before doing that
which we might anyway.
3) Wrap in a Fragment. If a Server Component was instead a Client
Component, you couldn't introspect through it anyway. Another
alternative might be to let it pass through but then it wouldn't be
given a flat key. We could also wrap it in a Fragment that is keyed.
That way you're always seeing an element. The issue with this solution
is that it wouldn't see the key of the Server Component since that gets
forwarded to the child that is yet to resolve. The nice thing about that
strategy is it doesn't depend on throw-a-Promise but it might not be
keyed correctly when things move.
2024-02-12 13:39:30 -05:00
Sebastian Markbåge
629541bcc0 [Flight] Transfer Debug Info in Server-to-Server Flight Requests (#28275)
A Flight Server can be a consumer of a stream from another Server. In
this case the meta data is attached to debugInfo properties on lazy,
Promises, Arrays or Elements that might in turn get forwarded to the
next stream. In this case we want to forward this debug information to
the client in the stream.

I also added a DEV only `environmentName` option to the Flight Server.
This lets you name the server that is producing the debug info so that
you can trace the origin of where that component is executing. This
defaults to `"server"`. DevTools could use this for badges or different
colors.
2024-02-12 13:38:14 -05:00
Ruslan Lesiutin
947e7962ad fix[devtools/useModalDismissSignal]: use getRootNode for shadow root case support (#28145)
In our custom implementation for handling modals dismiss signal, we use
element's `ownerDocument` field, which expectedly doesn't work well with
shadow root. Now using
[`getRootNode`](https://developer.mozilla.org/en-US/docs/Web/API/Node/getRootNode)
instead of `ownerDocument` to support shadow root case.

Without this, if RDT Frontend is hosted inside the shadow root, the
modal gets closed after any click, including on the buttons hosted by
modal:

00d42ac354/packages/react-devtools-shared/src/devtools/views/hooks.js (L228-L238)

Test plan:
- Modals work as expected for Chrome DevTools integration
- Modals work as expected at every other surfaces: browser extension,
electron wrapper for RN, inline version for web
2024-02-12 16:56:28 +00:00
dan
269edb88b2 Add jsx-runtime.react-server.js to file allowlist (#28301)
https://github.com/facebook/react/pull/28217 doesn't work without this
since it's not included in the files list.

See https://github.com/dai-shi/waku/pull/467#issuecomment-1936965080.

This should fix that.
2024-02-11 03:19:30 +00:00
dan
35b2c28178 Remove deprecated methods from react-is (#28224)
These aren't being used anywhere and don't even correspond to real APIs.
2024-02-11 00:25:17 +00:00
Mike Vitousek
8a3def923b Fixed sprout test failure 2024-02-09 16:48:13 -08:00
Mike Vitousek
11a5254b9c add output 2024-02-09 15:24:51 -08:00
Mike Vitousek
966932c525 fix again :( 2024-02-09 15:17:55 -08:00
Mike Vitousek
c10d711309 Further test fix 2024-02-09 15:09:26 -08:00
Mike Vitousek
8c7685ed40 Fix breakages and add fixture entrypoint 2024-02-09 15:00:05 -08:00
Mike Vitousek
48024b76bb Fix lints 2024-02-09 14:50:06 -08:00
Mike Vitousek
19476aa5f6 Option to bail on Flow react-rule suppressions 2024-02-09 14:21:07 -08:00
Joe Savona
24ed13e1f0 Update error message and comments 2024-02-13 16:45:18 -08:00
Joe Savona
fea7b5ac0d Move useMemoCache outside of hook guards
The hook guards are incompatible with using a forget-runtime. Specifically, 
forget-runtime needs to make a call to `useState()` or some other hook to attach 
data to the fiber, but all the builtin hooks are overridden to disallow calling 
them outside of explicit boundaries. We'd either have to wrap the useMemoCache 
call in a push/pop to allow it to call other hooks, or as in this PR, just move 
it outside the enforcement.
2024-02-13 16:45:18 -08:00
Joe Savona
6924786973 [be] Change validate functions to not return unnecessary Result
These validations needs to be able to transitively check for violations within 
function expressions, without immediately erroring. So the inner "-Impl" helpers 
return a Result. But the outer, exported validate functions don't need to return 
a Result, especially since TS has no Rust-style enforcement that return values 
are actually used. Unwrapping within the validation means the caller can't 
forget to do so and inadvertently silence the errors.
2024-02-13 16:45:17 -08:00
Joe Savona
19b4abed69 [be] Remove unused validateRefAccessDuringRenderFunctionExpressions flag
I had split this up from the main validation since function validation was less 
precise; now that previous PRs fix the false positives we can remove this extra 
flag.
2024-02-13 16:45:17 -08:00
Joe Savona
bde30f0284 [be] Remove ValidateFrozenLambdas
This pass doesn't really make sense in light of 
`@enableTransitivelyFreezeFunctionExpressions`. The original idea of 
ValidateFrozenLambdas was that trying to pass a "mutable" lambda to a frozen 
value was invalid. But since then we've realized that the better heuristic is 
that freezing a lambda is transitive.
2024-02-13 16:45:16 -08:00
Joe Savona
5f1b8fd57f Improve validateNoRefAccessInRender
Rewrites the validation to not rely on the mutable range of functions to 
determine whether they are called or not, since the range can be extended for 
other reasons (they happen to reference a mutable value that is mutated later, 
even though the function isn't called during render). 

Instead we use the same approach as validateNoSetStateInRender, explicitly 
tracking references to function expressions that access refs, and checking if 
those function expressions appear to be called. This can have false negatives, 
as with the setState validation, but catches lots of obviously incorrect code 
without false positives.
2024-02-13 16:45:15 -08:00
Joe Savona
6dae958eab [be] Extract computeUnconditionalBlocks() helper 2024-02-13 16:45:15 -08:00
Joe Savona
f7f05501e0 Support destructuring assignment of context variables
Fixes T178003134. Previously we did not check whether values reassigned during a 
destructuring assignment were context variables. This would either miscompile, 
or as of my fix earlier in #2579, would fail validation. Specifically, this 
happened on AssignmentEpression with an object/array pattern lvalue, where the 
pattern contained an identifier that is a context variable. 

This is now fixed: we track whether the outermost assignment is a normal 
assignment or destructuring, and force destructuring to a temporary whenever the 
identifier is a context variable. We apply the same logic to variable 
declarations that are destructuring to a context variable.
2024-02-13 16:45:14 -08:00
Mofei Zhang
a107ba81ed [BE] Remove navigator; edit sprout fixtures
--- 

I recall adding the navigator override because some React library file had done 
an unconditional access, but this doesn't seem to be the case anymore. 
Regardless, newer versions of nodejs comes with a global `navigator` [see 
thread](https://github.com/nodejs/node/issues/39540) that error on writes
2024-02-12 19:12:01 -05:00
Ricky
06e410ec60 Move modern strict to experimental (#28152)
Turn this on 

Edited: ope, nvm
<details>
Looks like there's still an outstanding issue with this. The original PR
turned off a strict effects test, which causes a stray
`componentWillUnmount` to fire.


5d1ce65139 (diff-19df471970763c4790c2cc0811fd2726cc6a891b0e1d5dedbf6d0599240c127aR70)


Before:
```js
expect(log).toEqual([
      'constructor',
      'constructor',
      'getDerivedStateFromProps',
      'getDerivedStateFromProps',
      'render',
      'render',
      'componentDidMount',
    ]);
```

After:

```js
expect(log).toEqual([
      'constructor',
      'constructor',
      'getDerivedStateFromProps',
      'getDerivedStateFromProps',
      'render',
      'render',
      'componentDidMount',
      'componentWillUnmount',
      'componentDidMount',
    ]);
```

So there's a bug somewhere
</details>
2024-02-09 16:59:47 -05:00
Mofei Zhang
5dd55e881b [lower][patch] Recognize UpdateExpression as lval assignment
--- 

Oops, I broke this in #2552. We never handled UpdateExpressions to context 
variables previously, so this PR also adds a todo bailout
2024-02-09 16:18:37 -05:00
Joe Savona
d4cdaf2523 Fix assignment expression with context variables
Fixes the one case discovered in the previous PR; for AssignmentExpression we 
correctly lowered the store instruction to a local/context, but then always used 
a `LoadLocal` to read the result back. 

The load instruction appears like it might be dangling - i think what was 
happening is that DCE cleaned up the unused LoadLocal whereas it leaves the 
LoadContext alone. But this works for now, we can always clean up the extra 
instruction later since this case isn't too common.
2024-02-09 14:25:33 -08:00
Joe Savona
6da1912eed Validate that all variable references are consistently local/context
Validates that all references to a variable (pre-SSA) are consistently "local" 
references or "context" references. Ie, if a variable is declared as 
DeclareContext, any accesses must be eg LoadContext or StoreContext, not 
LoadLocal/StoreLocal. This will help with the issue from #2577 (assuming that we 
know a variable _is_ a context variable) but also provides a more precise 
bailout for an existing case with destructuring assignment to a context 
variable.
2024-02-09 14:09:55 -08:00
Ruslan Lesiutin
374fd68a50 fix: define IS_ACT_ENVIRONMENT global for tests with concurrent mode and synchronous act (#28296) 2024-02-09 19:03:40 +00:00
Jan Kassens
d27c1ac112 Upgrade flow to 0.228.0 (#28294)
Upgrade flow to 0.228.0
2024-02-09 11:17:00 -05:00
Jan Kassens
d8c1fa6b0b Add infinite update loop detection (#28279)
This is a partial redo of https://github.com/facebook/react/pull/26625.
Since that was unlanded due to some detected breakages. This now
includes a feature flag to be careful in rolling this out.
2024-02-09 11:14:37 -05:00
Ruslan Lesiutin
03d6f7cf00 chore: gate legacy apis for react-devtools-shell (#28273)
- `react-devtools-shell` is only used for e2e tests
- Based on the React version we testing against, we will show/hide roots
using legacy render
2024-02-09 11:27:12 +00:00
Samuel Susla
36b078cc7a unify feature flags between fb and oss for React Native renderer (#28269)
# Affected flags:

### alwaysThrottleRetries

In RN OSS changed from `true` to `false`. This is what FB build uses.
This flag was a root cause for big perf regression internally.

### enableDeferRootSchedulingToMicrotask

In RN OSS build changed from `true` to `false`. This is what FB build
uses.

### debugRenderPhaseSideEffectsForStrictMode

Changed from true to __DEV__ in FB and OSS build. The flag is only used
in debug builds and was previously `false` in RN OSS builds

### enableUnifiedSyncLane

Changed from `__VARIANT__` to `true` in FB build. This is what OSS build
uses. This flag is shipped internally. cc @tyao1

### enableLegacyHidden

In RN FB changed from `true` to `false`.  This is what OSS uses.

### allowConcurrentByDefault

In RN FB changed from `true` to `false`. 




I ran `yarn flags --diff rn rn-fb` to get the difference between feature
flags and unify them.

## Before
```
yarn run v1.22.19
$ node ./scripts/flags/flags.js --diff rn rn-fb
┌───────────────────────────────────────────────┬────────┬───────┐
│                    (index)                    │ RN OSS │ RN FB │
├───────────────────────────────────────────────┼────────┼───────┤
│ allowConcurrentByDefault                      │  ''  │ ''  │
│ debugRenderPhaseSideEffectsForStrictMode      │  ''  │ ''  │
│ disableModulePatternComponents                │  ''  │ ''  │
│ enableCPUSuspense                             │  ''  │ ''  │
│ enableCacheElement                            │  ''  │ ''  │
│ enableGetInspectorDataForInstanceInProduction │  ''  │ ''  │
│ enableLegacyHidden                            │  ''  │ ''  │
│ enableSchedulingProfiler                      │  ''  │ '📊'  │
│ enableUseDeferredValueInitialArg              │  ''  │ ''  │
│ enableUseMemoCacheHook                        │  ''  │ ''  │
│ enableUseRefAccessWarning                     │  ''  │ '🧪'  │
│ passChildrenWhenCloningPersistedNodes         │  ''  │ '🧪'  │
│ useMicrotasksForSchedulingInFabric            │  ''  │ '🧪'  │
│ alwaysThrottleRetries                         │  ''  │ '🧪'  │
│ enableDeferRootSchedulingToMicrotask          │  ''  │ '🧪'  │
│ enableUnifiedSyncLane                         │  ''  │ '🧪'  │
└───────────────────────────────────────────────┴────────┴───────┘
```

## After
```
yarn run v1.22.19
$ node ./scripts/flags/flags.js --diff rn rn-fb
┌───────────────────────────────────────────────┬────────┬───────┐
│                    (index)                    │ RN OSS │ RN FB │
├───────────────────────────────────────────────┼────────┼───────┤
│ alwaysThrottleRetries                         │  ''  │ '🧪'  │
│ disableModulePatternComponents                │  ''  │ ''  │
│ enableCPUSuspense                             │  ''  │ ''  │
│ enableCacheElement                            │  ''  │ ''  │
│ enableDeferRootSchedulingToMicrotask          │  ''  │ '🧪'  │
│ enableGetInspectorDataForInstanceInProduction │  ''  │ ''  │
│ enableSchedulingProfiler                      │  ''  │ '📊'  │
│ enableUseDeferredValueInitialArg              │  ''  │ ''  │
│ enableUseMemoCacheHook                        │  ''  │ ''  │
│ enableUseRefAccessWarning                     │  ''  │ '🧪'  │
│ passChildrenWhenCloningPersistedNodes         │  ''  │ '🧪'  │
│ useMicrotasksForSchedulingInFabric            │  ''  │ '🧪'  │
└───────────────────────────────────────────────┴────────┴───────┘
```
2024-02-09 09:46:42 +00:00
Sebastian Markbåge
ba5e6a8329 [Flight] Serialize deduped elements by direct reference even if they suspend (#28283)
In #28123 I switched these to be lazy references. However that creates a
lazy wrapper even if they're synchronously available. We try to as much
as possible preserve the original data structure in these cases.

E.g. here in the dev outlining I only use a lazy wrapper if it didn't
complete synchronously:
https://github.com/facebook/react/pull/28272/files#diff-d4c9c509922b3671d3ecce4e051df66dd5c3d38ff913c7a7fe94abc3ba2ed72eR638

Unfortunately we don't have a data structure that tracks the status of
each emitted row. We could store the task in the map but then they
couldn't be GC:ed as they complete. We could maybe store the status of
each element but seems so heavy.

For now I just went back to direct reference which might be an issue
since it can suspend something higher up when deduped.
2024-02-08 18:45:40 -05:00
Sebastian Markbåge
e41ee9ea70 Throw a better error when Lazy/Promise is used in React.Children (#28280)
We could in theory actually support this case by throwing a Promise when
it's used inside a render. Allowing it to be synchronously unwrapped.
However, it's a bit sketchy because we officially only support this in
the render's child position or in `use()`.

Another alternative could be to actually pass the Promise/Lazy to the
callback so that you can reason about it and just return it again or
even unwrapping with `use()` - at least for the forEach case maybe.
2024-02-08 17:10:19 -05:00
Ricky
cd63ef7921 Add simulateEventDispatch to test ReactDOMEventListener (#28079)
## Overview

For events, the browser will yield to microtasks between calling event
handers, allowing time to flush work inbetween. For example, in the
browser, this code will log the flushes between events:

```js
<body onclick="console.log('body'); Promise.resolve().then(() => console.log('flush body'));">
  <div onclick="console.log('div'); Promise.resolve().then(() => console.log('flush div'));">
    hi
  </div>
</body>

// Logs
div 
flush div 
body 
flush body 
```


[Sandbox](https://codesandbox.io/s/eloquent-noether-mw2cjg?file=/index.html)

The problem is, `dispatchEvent` (either in the browser, or JSDOM) does
not yield to microtasks. Which means, this code will log the flushes
after the events:

```js
const target = document.getElementsByTagName("div")[0];
const nativeEvent = document.createEvent("Event");

nativeEvent.initEvent("click", true, true);
target.dispatchEvent(nativeEvent);

// Logs
div
body
flush div
flush body
```

## The problem
This mostly isn't a problem because React attaches event handler at the
root, and calls the event handlers on components via the synthetic event
system. We handle flushing between calling event handlers as needed.

However, if you're mixing capture and bubbling events, or using multiple
roots, then the problem of not flushing microtasks between events can
come into play. This was found when converting a test to `createRoot` in
https://github.com/facebook/react/pull/28050#discussion_r1462118422, and
that test is an example of where this is an issue with nested roots.

Here's a sandox for
[discrete](https://codesandbox.io/p/sandbox/red-http-2wg8k5) and
[continuous](https://codesandbox.io/p/sandbox/gracious-voice-6r7tsc?file=%2Fsrc%2Findex.js%3A25%2C28)
events, showing how the test should behave. The existing test, when
switched to `createRoot` matches the browser behavior for continuous
events, but not discrete. Continuous events should be batched, and
discrete should flush individually.

## The fix

This PR implements the fix suggested by @sebmarkbage, to manually
traverse the path up from the element and dispatch events, yielding
between each call.
2024-02-08 16:06:03 -05:00
Sebastian Silbermann
04b59928d8 DevTools: Add support for use(Context) (#28233) 2024-02-08 18:47:40 +01:00
Sathya Gunasekaran
da8ca6e954 [types] Check propType when checking if two types are equal 2024-02-08 16:19:55 +00:00
Sathya Gunasekaran
3c431f9afe [types] Check the shapeId as part of the object type equals check 2024-02-08 16:19:55 +00:00
Andrew Clark
d3def47935 Delete more redundant JSX code (#28276)
Found another redundant implementation of JSX code. Not being used
anywhere so safe to delete.
2024-02-08 11:04:09 -05:00
Sebastian Markbåge
b229f540e2 [Flight] Emit debug info for a Server Component (#28272)
This adds a new DEV-only row type `D` for DebugInfo. If we see this in
prod, that's an error. It can contain extra debug information about the
Server Components (or Promises) that were compiled away during the
server render. It's DEV-only since this can contain sensitive
information (similar to errors) and since it'll be a lot of data, but
it's worth using the same stream for simplicity rather than a
side-channel.

In this first pass it's just the Server Component's name but I'll keep
adding more debug info to the stream, and it won't always just be a
Server Component's stack frame.

Each row can get more debug rows data streaming in as it resolves and
renders multiple server components in a row.

The data structure is just a side-channel and it would be perfectly fine
to ignore the D rows and it would behave the same as prod. With this
data structure though the data is associated with the row ID / chunk, so
you can't have inline meta data. This means that an inline Server
Component that doesn't get an ID otherwise will need to be outlined. The
way I outline Server Components is using a direct reference where it's
synchronous though so on the client side it behaves the same (i.e.
there's no lazy wrapper in this case).

In most cases the `_debugInfo` is on the Promises that we yield and we
also expose this on the `React.Lazy` wrappers. In the case where it's a
synchronous render it might attach this data to Elements or Arrays
(fragments) too.

In a future PR I'll wire this information up with Fiber to stash it in
the Fiber data structures so that DevTools can pick it up. This property
and the information in it is not limited to Server Components. The name
of the property that we look for probably shouldn't be `_debugInfo`
since it's semi-public. Should consider the name we use for that.

If it's a synchronous render that returns a string or number (text node)
then we don't have anywhere to attach them to. We could add a
`React.Lazy` wrapper for those but I chose to prioritize keeping the
data structure untouched. Can be useful if you use Server Components to
render data instead of React Nodes.
2024-02-08 11:01:32 -05:00
Joe Savona
f0cffef0a2 Fix hook pattern matching for custom hooks 2024-02-07 17:34:10 -08:00
Sebastian Markbåge
37d901e2b8 Remove __self and __source location from elements (#28265)
Along with all the places using it like the `_debugSource` on Fiber.
This still lets them be passed into `createElement` (and JSX dev
runtime) since those can still be used in existing already compiled code
and we don't want that to start spreading to DOM attributes.

We used to have a DEV mode that compiles the source location of JSX into
the compiled output. This was nice because we could get the actual call
site of the JSX (instead of just somewhere in the component). It had a
bunch of issues though:

- It only works with JSX.
- The way this source location is compiled is different in all the
pipelines along the way. It relies on this transform being first and the
source location we want to extract but it doesn't get preserved along
source maps and don't have a way to be connected to the source hosted by
the source maps. Ideally it should just use the mechanism other source
maps use.
- Since it's expensive it only works in DEV so if it's used for
component stacks it would vary between dev and prod.
- It only captures the callsite of the JSX and not the stack between the
component and that callsite. In the happy case it's in the component but
not always.

Instead, we have another zero-cost trick to extract the call site of
each component lazily only if it's needed. This ensures that component
stacks are the same in DEV and PROD. At the cost of worse line number
information.

The better way to get the JSX call site would be to get it from `new
Error()` or `console.createTask()` inside the JSX runtime which can
capture the whole stack in a consistent way with other source mappings.
We might explore that in the future.

This removes source location info from React DevTools and React Native
Inspector. The "jump to source code" feature or inspection can be made
lazy instead by invoking the lazy component stack frame generation. That
way it can be made to work in prod too. The filtering based on file path
is a bit trickier.

When redesigned this UI should ideally also account for more than one
stack frame.

With this change the DEV only Babel transforms are effectively
deprecated since they're not necessary for anything.
2024-02-07 16:38:00 -05:00
Sebastian Markbåge
5c08662301 Add enableServerComponentKeys to NEXT_MAJOR (#28259) 2024-02-07 15:21:59 -05:00
Ricky
2cd19ed1dd Convert ReactRenderDocument to hydrateRoot (#28153)
Co-authored-by: Sebastian Silbermann <sebastian.silbermann@klarna.com>
2024-02-07 09:54:46 -05:00
Ruslan Lesiutin
bfdc12c191 chore: use versioned render in inspectedElement test (#28246) 2024-02-07 10:50:26 +00:00
Ruslan Lesiutin
d1829775ad chore: use versioned render in TimelineProfiler test and gate some for legacy rendering (#28218) 2024-02-07 10:30:54 +00:00
Josh Story
a1ace9d3c2 Improve flagging of React.cache to remove indirection in bundled code (#28263)
Uses a better technique for conditionally disabling cache on the client
2024-02-06 17:40:06 -08:00
Andrew Clark
91caa96e42 jsx(): Treat __self and __source as normal props (#28257)
These used to be reserved props because the classic React.createElement
runtime passed this data as props, whereas the jsxDEV() runtime passes
them as separate arguments.

This brings us incrementally closer to being able to pass the props
object directly through to React instead of cloning a subset into a new
object.

The React.createElement runtime is unaffected.
2024-02-06 20:03:02 -05:00
Sebastian Markbåge
f07ac1e268 [Flight] Unify plain Server Component and forwardRef under one function (#28261)
This used to be trivial but it's no longer trivial.

In Fizz and Fiber this is split into renderWithHooks and
finishFunctionComponent since they also support indeterminate
components.

Interestingly thanks to this unification we always call functions with
an arity of 2 which is a bit weird - with the second argument being
undefined in everything except forwardRef and legacy context consumers.

This makes Flight makes the same thing but we could also call it with an
arity of 1.

Since Flight errors early if you try to pass it a ref, and there's no
legacy context, the second arg is always undefined.

The practical change in this PR is that returning a Promise from a
forwardRef now turns it into a lazy. We previously didn't support async
forwardRef since it wasn't supported on the client. However, since
eventually this will be supported by child-as-a-promise it seems fine to
support it.
2024-02-06 19:41:05 -05:00
Andrew Clark
1beb94133a jsx(): Inline reserved prop checks (#28262)
The JSX runtime (both the new one and the classic createElement runtime)
check for reserved props like `key` and `ref` by doing a lookup in a
plain object map with `hasOwnProperty`.

There are only a few reserved props so this inlines the checks instead.
2024-02-06 18:56:18 -05:00
Sebastian Markbåge
0d11563b4a [Flight] Move pendingChunks ref count increment into createTask (#28260)
Every time we create a task we need to wait for it so we increase a ref
count. We can do this in `createTask`. This is in line with what Fizz
does too.

They differ in that Flight counts when they're actually flushed where as
Fizz decrements them when they complete.

Flight should probably count them when they complete so it's possible to
wait for the end before flushing for buffering purposes.
2024-02-06 16:17:59 -05:00
Andrew Clark
6692445759 Delete duplicate jsx() implementation (#28258)
Not sure how this happened but there are two identical implementations
of the jsx and jsxDEV functions. One of them was unreachable. I deleted
that one.
2024-02-06 15:05:08 -05:00
Damian Stasik
7cbd026ff4 [Fresh] Update the list of built-in hooks (#27864) 2024-02-06 19:57:46 +01:00
Ricky
30e2938e04 [Tests] Reset modules by default (#28254)
## Overview

Sets `resetModules: true` in the base Jest config, and deletes all the
`jest.resetModule()` calls we don't need.
2024-02-06 12:43:27 -05:00
Ruslan Lesiutin
8b5f0c43ad chore: use versioned render in preprocessData test and gate some for … (#28219) 2024-02-06 17:34:41 +00:00
Sebastian Silbermann
97fd3e7064 Ensure useState and useReducer initializer functions are double invoked in StrictMode (#28248) 2024-02-06 17:53:08 +01:00
Ruslan Lesiutin
08d6cef46a chore: use versioned render in storeStressSync test and gate them for legacy rendering (#28216) 2024-02-06 16:51:58 +00:00
Sathya Gunasekaran
db120f69ec Patch devtools before running useMemo function in strict mode (#28249)
This fixes a regression https://github.com/facebook/react/pull/25583
where we stopped patching before calling useMemo function.

Fixes https://github.com/facebook/react/issues/27989
2024-02-06 16:45:18 +00:00
Ruslan Lesiutin
12d56fca3d chore: use versioned render in storeComponentFilters test (#28241) 2024-02-06 16:25:03 +00:00
Ruslan Lesiutin
ad720f36ec chore: use versioned render in profilerContext test (#28243) 2024-02-06 15:58:11 +00:00
Ricky
5446b098a8 Convert ReactBrowserEventEmitter to createRoot (#28253)
pretty boring
2024-02-06 10:43:37 -05:00
Ruslan Lesiutin
65d95b837e fix: gate react/jsx-runtime upgrade only for React >= 17 tests (#28256)
https://github.com/facebook/react/pull/28252 broke RDT tests with React
16.x.

These changes gate the `jsx-runtime` upgrade only for cases when we are
testing against React >= 17.

Validated with:
```
 ./scripts/circleci/download_devtools_regression_build.js 16.0 --replaceBuild && node ./scripts/jest/jest-cli.js --build --project devtools --release-channel=experimental --reactVersion 16.0 --ci && ./scripts/circleci/download_devtools_regression_build.js 16.5 --replaceBuild && node ./scripts/jest/jest-cli.js --build --project devtools --release-channel=experimental --reactVersion 16.5 --ci && ./scripts/circleci/download_devtools_regression_build.js 16.8 --replaceBuild && node ./scripts/jest/jest-cli.js --build --project devtools --release-channel=experimental --reactVersion 16.8 --ci && ./scripts/circleci/download_devtools_regression_build.js 17.0 --replaceBuild && node ./scripts/jest/jest-cli.js --build --project devtools --release-channel=experimental --reactVersion 17.0 --ci && ./scripts/circleci/download_devtools_regression_build.js 18.0 --replaceBuild && node ./scripts/jest/jest-cli.js --build --project devtools --release-channel=experimental --reactVersion 18.0 --ci
 ```
2024-02-06 15:03:36 +00:00
Ruslan Lesiutin
103cddbb9d chore: use versioned render in profilingCommitTreeBuilder test and gate some for legacy rendering (#28236) 2024-02-06 12:26:50 +00:00
Ruslan Lesiutin
6fef0cb568 chore: use versioned render in profilingHostRoot test and gate some for legacy rendering (#28237) 2024-02-06 11:40:50 +00:00
Ruslan Lesiutin
cb78d2f1f3 chore: use versioned render in profilingCache test (#28242) 2024-02-06 11:24:54 +00:00
Joe Savona
af6e837b60 Fix destructuring with mixed local/scope declarations
Fixes T176436488. The logic for rewriting Destructure instructions was correct, 
but the visitor implementation was accidentally dropping subsequent Destructure 
instructions within a block after encountering one that needed a rewrite. 
Switching to use the transform infra (added after this pass was written) fixes 
it.
2024-02-05 22:29:53 -08:00
Josh Story
0a53c46574 Update ReactDOMServerSuspense-test to not use legacy rendering APIs (#28251)
Updates ReactDOMServerSuspense-test to not use legacy rendering APIs
Also removes an experimental only gate that is not necessary
2024-02-05 21:25:22 -08:00
Andrew Clark
952aa74f8e Upgrade tests to use react/jsx-runtime (#28252)
Instead of createElement.

We should have done this when we initially released jsx-runtime but
better late than never. The general principle is that our tests should
be written using the most up-to-date idioms that we recommend for users,
except when explicitly testing an edge case or legacy behavior, like for
backwards compatibility.

Most of the diff is related to tweaking test output and isn't very
interesting.

I did have to workaround an issue related to component stacks. The
component stack logic depends on shared state that lives in the React
module. The problem is that most of our tests reset the React module
state and re-require a fresh instance of React, React DOM, etc. However,
the JSX runtime is not re-required because it's injected by the compiler
as a static import. This means its copy of the shared state is no longer
the same as the one used by React, causing any warning logged by the JSX
runtime to not include a component stack. (This same issue also breaks
string refs, but since we're removing those soon I'm not so concerned
about that.) The solution I went with for now is to mock the JSX runtime
with a proxy that re-requires the module on every function invocation. I
don't love this but it will have to do for now. What we should really do
is migrate our tests away from manually resetting the module state and
use import syntax instead.
2024-02-05 23:07:41 -05:00
Josh Story
2bc7d336ae Add flag to disable caching behavior of React.cache on the client (#28250)
Adds a feature flag to control whether the client cache function is just
a passthrough. before we land breaking changes for the next major it
will be off and then we can flag it on when we want to break it.

flag is off for OSS for now and on elsewhere (though the parent flag
enableCache is off in some cases)
2024-02-05 16:32:03 -08:00
Joe Savona
0277bc4d54 Separate snap flags for watch/update/filter
This is not that big a deal but a constant papercut, i often want to jump 
directly to watch mode with a filter applied. I know @poteto likes to (or at 
least used to) run watch with update enabled. Now instead of passing a mode, you 
can pass `--watch`, `--filter`, and `--update` independently.
2024-02-05 15:55:08 -08:00
dan
472854820b [Flight] Delete Server Context (#28225)
Server Context was never documented, and has been deprecated in
https://github.com/facebook/react/pull/27424.

This PR removes it completely, including the implementation code.

Notably, `useContext` is removed from the shared subset, so importing it
from a React Server environment would now should be a build error in
environments that are able to enforce that.
2024-02-05 22:39:15 +00:00
Mofei Zhang
707d9643dd [logger] Log todo when encountering "use no forget"
--- 

This change simply logs on every function we encounter with a `use no forget` 
directive. A few nuances -- `compilationMode: "infer"` only compiles functions 
we infer to be 'react functions'. 

```js 

// `add` would not be compiled, as it has no jsx, no hook calls, 

// and is not named as a component or hook 

function add(a, b) { 

return a + b; 

} 

``` 

With this PR, we would report todos for functions that Forget wouldn't 
ordinarily try to compile. 

```js 

// Todo: Skipped due to "use no forget" directive. 

function add(a, b) { 

"use no forget"; 

return a + b; 

} 

``` 

This seems fine to me as (1) it's a bit nonsensical to have a `use no forget` 
direction on a non-react function, and (2) we're goalling on getting `use no 
forget`s down to 0.
2024-02-05 16:05:09 -05:00
Joe Savona
195b5e5a24 Fix sprout 2024-02-05 21:51:18 -08:00
Joe Savona
b79a5289fc Resolve type aliases
The goal of this PR is to move towards a uniform representation for all type
declarations, whether they are named type aliases, function declarations, or
inline annotations. We now assign every non-primitive type declaration (named or
anonymous) a unique DeclarationId. In the next PR, we'll also re-map inline
annotations back to this declaration id when encountering them.

This PR is extremely gross and my intent is to refactor a bunch of things in the
HIR to allow this to be less gross. Challenges:

* Babel name resolution requires using scopes but i really want to just work
with plain nodes, since NodePath and TypeScript do _not_ get along. So here, i
find all identifiers and store a mapping of identifier -> scope, so that i can
later look them up if necessary.

* HIR doesn't have a notion of a declaration id, and in general we don't want
to extend HIR. So i end up with a whole bunch of side table information and
indirection. For example, a function doesn't know it's own declaration id.
So we have to look it up. Function params don't track their Forest type, so
we have to look them up on the function declaration. Etc.
2024-02-05 21:51:13 -08:00
Joe Savona
292a247cc4 Add type to DeclareLocal 2024-02-05 21:51:11 -08:00
Joe Savona
76aaf32c55 HIR StoreLocal.type uses babel type 2024-02-05 21:51:09 -08:00
Joe Savona
9ec9331def Emit function param and return type annotations 2024-02-05 21:51:09 -08:00
Sebastian Markbåge
95ec128399 [Flight] Support Keyed Server Components (#28123)
Conceptually a Server Component in the tree is the same as a Client
Component.

When we render a Server Component with a key, that key should be used as
part of the reconciliation process to ensure the children's state are
preserved when they move in a set. The key of a child should also be
used to clear the state of the children when that key changes.

Conversely, if a Server Component doesn't have a key it should get an
implicit key based on the slot number. It should not inherit the key of
its children since the children don't know if that would collide with
other keys in the set the Server Component is rendered in.

A Client Component also has an identity based on the function's
implementation type. That mainly has to do with the state (or future
state after a refactor) that Component might contain. To transfer state
between two implementations it needs to be of the same state type. This
is not a concern for a Server Components since they never have state so
identity doesn't matter.

A Component returns a set of children. If it returns a single child,
that's the same as returning a fragment of one child. So if you
conditionally return a single child or a fragment, they should
technically reconcile against each other.

The simple way to do this is to simply emit a Fragment for every Server
Component. That would be correct in all cases. Unfortunately that is
also unfortunate since it bloats the payload in the common cases. It
also means that Fiber creates an extra indirection in the runtime.

Ideally we want to fold Server Component aways into zero cost on the
client. At least where possible. The common cases are that you don't
specify a key on a single return child, and that you do specify a key on
a Server Component in a dynamic set.

The approach in this PR treats a Server Component that returns other
Server Components or Lazy Nodes as a sequence that can be folded away.
I.e. the parts that don't generate any output in the RSC payload.
Instead, it keeps track of their keys on an internal "context". Which
gets reset after each new reified JSON node gets rendered.

Then we transfer the accumulated keys from any parent Server Components
onto the child element. In the simple case, the child just inherits the
key of the parent.

If the Server Component itself is keyless but a child isn't, we have to
add a wrapper fragment to ensure that this fragment gets the implicit
key but we can still use the key to reset state. This is unusual though
because typically if you keyed something it's because it was already in
a fragment.

In the case a Server Component is keyed but forks its children using a
fragment, we need to key that fragment so that the whole set can move
around as one. In theory this could be flattened into a parent array but
that gets tricky if something suspends, because then we can't send the
siblings early.

The main downside of this approach is that switching between single
child and fragment in a Server Component isn't always going to reconcile
against each other. That's because if we saw a single child first, we'd
have to add the fragment preemptively in case it forks later. This
semantic of React isn't very well known anyway and it might be ok to
break it here for pragmatic reasons. The tests document this
discrepancy.

Another compromise of this approach is that when combining keys we don't
escape them fully. We instead just use a simple `,` separated concat.
This is probably good enough in practice. Additionally, since we don't
encode the implicit 0 index slot key, you can move things around between
parents which shouldn't really reconcile but does. This keeps the keys
shorter and more human readable.
2024-02-05 09:33:35 -08:00
Ruslan Lesiutin
86b95edb0a chore: use versioned render in ownersListContext test (#28240) 2024-02-05 17:32:31 +00:00
Ruslan Lesiutin
6a21244671 chore: use versioned render in editing test (#28239) 2024-02-05 17:30:46 +00:00
Ruslan Lesiutin
09de4b2cfe chore: use versioned render in treeContext test (#28245) 2024-02-05 17:29:10 +00:00
Ruslan Lesiutin
23f318f23f chore: use versioned render in store test (#28244) 2024-02-05 17:24:22 +00:00
Ruslan Lesiutin
49d89b1497 chore: use versioned render in profilerStore test (#28238) 2024-02-05 17:20:05 +00:00
Ruslan Lesiutin
e6979aa142 chore: use versioned render in profilingCharts test (#28235) 2024-02-05 17:18:32 +00:00
Ruslan Lesiutin
761d5750ce chore: use versioned render in profilerChangeDescriptions test (#28221) 2024-02-05 17:17:07 +00:00
Ruslan Lesiutin
4f82bf4f59 chore: use versioned render in storeOwners test (#28215) 2024-02-05 17:15:16 +00:00
Ruslan Lesiutin
7e77e29ca9 chore: use versioned render in componentStacks test (#28214) 2024-02-05 17:14:00 +00:00
Ruslan Lesiutin
09c0769448 chore: use versioned render in console test (#28213) 2024-02-05 17:12:40 +00:00
Ruslan Lesiutin
f244fd3884 chore: use versioned render in useEditableValue test (#28212) 2024-02-05 17:11:22 +00:00
Ruslan Lesiutin
f3a70990a5 chore: use versioned render in FastRefreshDevToolsIntegration test (#28211) 2024-02-05 17:09:26 +00:00
Ruslan Lesiutin
88b0809447 fix: partially revert jest setup config removal to fix regression tests (#28247)
Partially reverting what has been removed in
https://github.com/facebook/react/pull/28186.

We need `'scheduler/tracing'` mock for React >= 16.8.
The error:
```
Invariant Violation: It is not supported to run the profiling version of a renderer (for example, `react-dom/profiling`) without also replacing the `scheduler/tracing` module with `scheduler/tracing-profiling`. Your bundler might have a setting for aliasing both modules. Learn more at http://fb.me/react-profiling
```

Validated by running regression tests for the whole version matrix:
```
./scripts/circleci/download_devtools_regression_build.js 16.0 --replaceBuild && node ./scripts/jest/jest-cli.js --build --project devtools --release-channel=experimental --reactVersion 16.0 --ci && ./scripts/circleci/download_devtools_regression_build.js 16.5 --replaceBuild && node ./scripts/jest/jest-cli.js --build --project devtools --release-channel=experimental --reactVersion 16.5 --ci && ./scripts/circleci/download_devtools_regression_build.js 16.8 --replaceBuild && node ./scripts/jest/jest-cli.js --build --project devtools --release-channel=experimental --reactVersion 16.8 --ci && ./scripts/circleci/download_devtools_regression_build.js 17.0 --replaceBuild && node ./scripts/jest/jest-cli.js --build --project devtools --release-channel=experimental --reactVersion 17.0 --ci && ./scripts/circleci/download_devtools_regression_build.js 18.0 --replaceBuild && node ./scripts/jest/jest-cli.js --build --project devtools --release-channel=experimental --reactVersion 18.0 --ci
```
2024-02-05 17:07:41 +00:00
Ruslan Lesiutin
596827f6a7 chore: add versioned render implementation for DevTools tests (#28210)
Adding getter-functions for renderer implementations, which can be used
for jest tests. If we are testing against React with version < 18, we
are going to use legacy rendering, otherwise the concurrent one.
2024-02-05 15:53:23 +00:00
Ruslan Lesiutin
9a1db2d21f chore: add single versioned implementation of act for DevTools tests (#28186)
- Moving `act` implementation to a single getter-function, which is
based on React version we are testing RDT against.
- Removing unused mocks for `act`, which were designed for legacy
versions of React, validated with running tests against React 16 build.
2024-02-05 15:38:48 +00:00
Sebastian Silbermann
56cd10beb4 DevTools: Add support for useFormState (#28232)
## Summary

Add support for `useFormState` Hook fixing "Unsupported hook in the
react-debug-tools package: Missing method in Dispatcher: useFormState"
when inspecting components using `useFormState`

## How did you test this change?

- Added test to ReactHooksInspectionIntegration
- Added dedicated section for form actions to devtools-shell
![Screenshot 2024-02-04 at 12 02
05](https://github.com/facebook/react/assets/12292047/bb274789-64b8-4594-963e-87c4b6962144)
2024-02-05 15:39:45 +01:00
Sebastian Silbermann
214fe84f53 Convert ReactMultiChildReconcile to createRoot (#28169) 2024-02-04 15:44:46 +01:00
Sebastian Silbermann
f5a3158a78 Convert ReactDOMEventPropagation to createRoot (#28177) 2024-02-04 11:29:06 +01:00
Sebastian Silbermann
93a5f40cbf Convert ReactFresh to createRoot (#28170) 2024-02-04 11:09:49 +01:00
Sebastian Silbermann
c7bf1c25ce Convert ReactDOMSuspensePlaceholder to createRoot (#28168) 2024-02-04 11:02:22 +01:00
Matt Carroll
3d6fcf9582 Convert ReactErrorBoundaries-test.internal.js to createRoot (#28122) 2024-02-02 17:41:56 -08:00
Sebastian Silbermann
85cc01743b DevTools: Add support for useOptimistic Hook (#27982)
## Summary

Add support for `useOptimistic` Hook fixing "Unsupported hook in the
react-debug-tools package: Missing method in Dispatcher: useOptimistic"
when inspecting components using `useOptimistic`

## How did you test this change?

- Added test following the same pattern as for `useDeferredValue`
2024-02-02 23:18:16 +01:00
Josh Story
00f9acb12c add RSC entrypoint for jsx-runtime (#28217)
Adds a new entrypoint for the production jsx-runtime when using
react-server condition. Currently the entrypoints are the same but in
the future we will potentially change the implementation of the runtime
in ways that can only be optimized for react-server constraints and we
want to have the entrypoint already separated so environments using it
will be pulling in the right version
2024-02-02 13:37:48 -08:00
Noah Lemen
cf925ebc3c convert ReactElementValidator-test to createRoot (#28223)
## Summary

Converts `ReactTestUtils.renderIntoDocument` and `ReactDOM.findDOMNode`
to `ReactDOMClient.createRoot`

## How did you test this change?
`yarn test ReactElementValidator`
2024-02-02 15:19:55 -05:00
Ricky
38ef167ee6 Convert ReactJSXElement to createRoot (#28208) 2024-02-02 12:56:30 -05:00
Ricky
7db2446c3d Convert ReactJSXElementValidator to createRoot (#28209) 2024-02-02 12:56:18 -05:00
Sathya Gunasekaran
29cb62ad6c Add type information for jsx/runtime 2024-02-02 10:56:44 -05:00
Sebastian Silbermann
4b2a1115a7 Convert SyntheticMouseEvent to createRoot (#28200) 2024-02-02 16:52:29 +01:00
Sebastian Silbermann
b3a79c4133 Convert BeforeInputEventPlugin to createRoot (#28199) 2024-02-02 16:52:19 +01:00
Sebastian Silbermann
fada283639 Convert multiple-copies-of-react to createRoot (#28198) 2024-02-02 09:15:53 +01:00
Sebastian Silbermann
7026806d4b Convert ReactDOMIframe to createRoot (#28197) 2024-02-02 09:15:43 +01:00
Sebastian Silbermann
02946228e1 Convert createReactClassIntegration to createRoot (#28196) 2024-02-02 09:15:33 +01:00
Sebastian Silbermann
c4e9ed3fef Convert ReactCompositeComponentDOMMinimalism to createRoot (#28194)
Not sure if this was also meant to test findDOMNode. But sounded like it
was more interested in the rendering aspect and findDOMNode was just
used as a utility. If we want to keep the findDOMNode tests, I'd just
rename it to a legacy test to indicate it needs to be flagged.
2024-02-02 09:15:19 +01:00
Sebastian Silbermann
3cfe0cc0c2 Convert ReactChildReconciler to createRoot (#28192) 2024-02-02 09:15:10 +01:00
Sebastian Silbermann
457ea7b9d6 Convert ReactChildren to createRoot (#28191) 2024-02-02 09:15:01 +01:00
Sebastian Silbermann
796d05e82c Convert EnterLeaveEventPlugin to createRoot (#28182) 2024-02-02 09:14:52 +01:00
Sebastian Silbermann
f8b26862d6 Convert CSSProperty to createRoot (#28181) 2024-02-02 09:14:43 +01:00
Sebastian Silbermann
f28f022f22 Convert InvalidEventListeners to createRoot (#28180) 2024-02-02 09:14:34 +01:00
Sebastian Silbermann
e9c13cde64 Convert ReactComponentLifeycle to createRoot (#28178) 2024-02-02 09:14:25 +01:00
Sebastian Silbermann
11aa263844 Remove usage of /test-utils in ReactLegacyCompositeComponent (#28201) 2024-02-02 09:14:05 +01:00
Sebastian Silbermann
7f8798a3f2 Convert ReactDOMSelection to createRoot (#28176) 2024-02-02 08:58:30 +01:00
Sebastian Silbermann
fa8a34bfac Convert ReactStrictMode to createRoot (#28162) 2024-02-02 08:57:56 +01:00
Ricky
b25dcd3958 Add ReactDOMClient to ServerIntegration tests (minor fixes) (#28131)
## Overview 

Branched off https://github.com/facebook/react/pull/28130

Converts to `createRoot`, with a few additional in-line conversions in
each file.
2024-02-01 19:01:16 -05:00
Sebastian Silbermann
2a45118b10 Convert ResponderEventPlugin to createRoot (#28190) 2024-02-01 18:53:25 -05:00
Sebastian Silbermann
2dc428f746 Convert ReactScope to createRoot (#28172) 2024-02-01 18:51:10 -05:00
Sebastian Silbermann
44952dc984 Convert ReactComponent to createRoot (#28171) 2024-02-01 18:50:38 -05:00
Sebastian Silbermann
a7f1622117 Convert SyntheticFocusEvent to createRoot (#28173) 2024-02-01 18:49:40 -05:00
Sebastian Silbermann
bc219090e3 Convert SyntheticClipboardEvent to createRoot (#28174) 2024-02-01 18:49:18 -05:00
Sebastian Silbermann
c39ec17e66 Convert ReactErrorBoundariesHooks to createRoot (#28175) 2024-02-01 18:48:58 -05:00
Ricky
4bd5e3ea5c Add ReactDOMClient to ServerIntegrationReconnecting (#28136)
## Overview

Branched off https://github.com/facebook/react/pull/28130

## Why

In https://github.com/facebook/react/pull/24276 we changed the new root
behavior to error when a client-render is forced for certain cases, so
these now expect a mismatch even though they're using
`suppressHydrationWarning`.
2024-02-01 18:32:38 -05:00
Ricky
fa6674b5bc Add ReactDOMClient to ServerIntegration(Hooks|NewContext) (#28135)
## Overview

Branched off https://github.com/facebook/react/pull/28130

### ~Failing~ Fixed by @eps1lon 
Most of the tests pass, but there are 3 tests that have additional
warnings due to client render error retries.

For example, before we would log:

```
Warning: Do not call Hooks inside useEffect(...), useMemo(...), or other built-in Hooks.
Warning: Expected server HTML to contain a matching text node for "0" in <div>.
```

And now we log

```
Warning: Do not call Hooks inside useEffect(...), useMemo(...), or other built-in Hooks.
Warning: Expected server HTML to contain a matching text node for "0" in <div>.
Warning: Do not call Hooks inside useEffect(...), useMemo(...), or other built-in Hooks.
```

We can't just update the expected error count for these tests, because
the additional error only happens on the client. So I need some guidance
on how to fix these.

---------

Co-authored-by: Sebastian Silbermann <sebastian.silbermann@klarna.com>
2024-02-01 18:32:27 -05:00
Ricky
c0d9277130 Add ReactDOMClient to ServerIntegrationElements (#28134)
## Overview 

Branched off https://github.com/facebook/react/pull/28130

## ~Failing~ Fixed by @eps1lon 

The tests are currently failing because of two tests covering special
characters. I've tried a few ways to fix, but I'm stuck and will need
some help understanding why they fail and how to fix.

---------

Co-authored-by: Sebastian Silbermann <sebastian.silbermann@klarna.com>
2024-02-01 18:32:18 -05:00
Ricky
278199b3de Add ReactDOMClient to ServerIntegrationBasic (#28133)
## Overview

Branched off https://github.com/facebook/react/pull/28130

In `hydrateRoot`, we now error if you pass `undefined`:

```
Warning: Must provide initial children as second argument to hydrateRoot. 
```

So we expect 1 error for this now.
2024-02-01 18:32:04 -05:00
Ricky
c42e7c7adc Add ReactDOMClient to ServerIntegrationSelect (#28132)
## Overview

Branched off https://github.com/facebook/react/pull/28130

## React for count changing
### Before
These tests are weird because on main they pass, but log to the console:

```
We expected 2 warning(s), but saw 1 warning(s).
We saw these warnings:
    Warning: Expected server HTML to contain a matching <select> in <div>.
        at select
```

The other one is ignored. The `expect(console.errors).toBeCalledWith(2)`
doesn't account for ignored calls, so the test passes with the two
expected (the +1 is in the test utiles). The ignored warning is

```
Warning: ReactDOM.hydrate is no longer supported in React 18. Use hydrateRoot instead. 
```

So the mismatch is in the ignored warnings. 

### After

After switching to `createRoot`, it still logs:

```
We expected 2 warning(s), but saw 1 warning(s).
We saw these warnings:
    Warning: Expected server HTML to contain a matching <select> in <div>.
        at select
```

But the test fails due to an unexpected error count. The new ignored
errors are:

```
Error: Uncaught [Error: Hydration failed because the initial UI does not match what was rendered on the server.]
Warning: An error occurred during hydration. The server HTML was replaced with client content in <div>.
Error: Hydration failed because the initial UI does not match what was rendered on the server.
Error: There was an error while hydrating. Because the error happened outside of a Suspense boundary, the entire root will switch to client rendering.
```

These seem to be the correct warnings to fire in `createRoot`, so the
fix is to update the number of warnings we expect.
2024-02-01 18:31:52 -05:00
Ricky
6054be9c86 Add ReactDOMClient to ServerIntegrationTestUtils (#28130)
## Overview

Adds support for `ReactDOMClient` for  `ServerIntegration*` tests. 

Also converts tests that pass without any other changes. Will follow up
with other PRs for more complex cases.
2024-02-01 18:26:33 -05:00
StyleShit
2efa38332a fix(eslint-plugin-react-hooks): accepting as expression as a callback (#28202)
## Summary

Closes #20750

## How did you test this change?

Added a test case
2024-02-01 21:08:21 +01:00
Ricky
3d1da1f9ab Remove createRootStrictEffectsByDefault flag (#28102)
There's no need to separate strict mode from strict effects mode any
more.

I didn't clean up the `StrictEffectMode` fiber flag, because it's used
to prevent strict effects in legacy mode. I could replace those checks
with `LegacyMode` checks, but when we remove legacy mode, we can remove
that flag and condense them into one StrictMode flag away.
2024-02-01 14:54:20 -05:00
Noah Lemen
4dd475c977 convert ReactElement-test from renderIntoDocument (#28161)
## Summary

refactors ReactElement-test to use `createRoot` instead of
`renderIntoDocument`, which uses `ReactDOM.render` under the hood

## How did you test this change?
`yarn test ReactElement`
2024-02-01 14:49:30 -05:00
Noah Lemen
94259cd57a convert ReactElementClone-test from renderIntoDocument (#28193)
## Summary

migrates to createRoot – renderIntoDocument uses ReactDOM.render

## How did you test this change?

yarn test ReactElementClone
2024-02-01 14:45:06 -05:00
Ricky
6f8f000592 Update react docs link in issue template (#28195) 2024-02-01 14:44:26 -05:00
StyleShit
a1433ca0ba fix(eslint-plugin-react-hooks): accepting as expressions as deps array (#28189)
## Summary

This PR closes #25844
The original issue talks about `as const`, but seems like it fails for
any `as X` expressions since it adds another nesting level to the AST.

EDIT: Also closes #20162

## How did you test this change?

Added unit tests
2024-02-01 20:30:17 +01:00
Andrew Clark
53b12e46a1 Add stable React.act export (#28160)
Starting in version 19, users can import the `act` testing API from the
`react` package instead of using a renderer specific API, like
`react-dom/test-utils`.
2024-02-01 13:28:14 -05:00
Jan Kassens
4384a7bcd3 [flow] ignore hidden directories (#28096)
[flow] ignore hidden directories
2024-02-01 11:24:04 -05:00
Lauren Tan
7bce302421 Make Other mutation validation message more generic
The current error message "This mutates a global or a variable after it 

was passed to React" no longer makes sense since we now have more 

specific error messages for different kinds of Effect.Mutate or 

Effect.Stores. This replaces the fallthrough "Other" case with a 

more generic message. It's not perfect, but it's a little more accurate 

than what is currently emitted 

The proper fix might be to treat functions as mutable objects and allow 

the mutation, or special case `Function.displayName`. For now though 

this PR just updates the message in the meantime so it's less 

confusing.
2024-02-01 11:02:30 -05:00
Lauren Tan
a0aa66ca8f Add test for function property mutation
There were no previous test paths that tested it, so I'm adding the example from 
https://github.com/facebookexternal/forget-feedback/issues/32 as a fixture
2024-02-01 11:02:30 -05:00
Josh Story
1219d57fc9 [Fizz] Support aborting with Postpone (#28183)
Semantically if you make your reason for aborting a Postpone instance
the render should not hit the error pathways but should instead follow
the postpone pathways. It's awkward today to actually get your hands on
a Postpone instance because you have to catch the throw from postpone
and then pass that into `abort()` or `AbortController.abort()`
(depending on the renderer API you are using)

This change makes it so that in most circumstances if you abort with a
postpone the `onPostpone` handler will be called and the Suspense
boundaries still pending will be put into client render mode with the
appropriate postpone digest to avoid trigger recoverable error pathways
on the client.

Similar to postponing in the shell during a resume or render however if
you abort before the shell is complete in a resume or render we will
fatally error. The fatal error is contextualized by React to avoid
passing the postpone object itself to the `onError` and related options.
2024-02-01 07:14:08 -08:00
Sebastian Silbermann
d29f7d973d Enable enableFilterEmptyStringAttributesDOM everywhere (#28125)
## Summary

Stacked on [#28124](https://github.com/facebook/react/pull/28124) ([Diff
against
#28124](https://github.com/facebook/react/compare/eps1lon:fix/anchor-href-empty...eps1lon:feat/enableFilterEmptyStringAttributesDOM-canary))

Enables `enableFilterEmptyStringAttributesDOM` everywhere. I don't think
this needs to be enabled behind `__VARIANT__` for RN since this flag is
only used in DOM.

## How did you test this change?

- CI
2024-01-31 08:23:21 -08:00
Ruslan Lesiutin
f7ce4164c9 chore: remove eslint-plugin-flowtype from dev dependencies (#28157)
While trying to resolve some issues with Flow in ESLint, noticed that we
are still listing `eslint-plugin-flowtype` as dev dependency, but it has
been deprecated in favour of `eslint-plugin-ft-flow`.
2024-01-31 14:52:52 +00:00
Ricky
45582c6c4d Add script to output flag values (#28115)
## Overview

Depends on: https://github.com/facebook/react/pull/28116

Add `yarn flags` to output at table of all feature flags. 

Provides options to output a csv file, diff two or more builds, and
sort.

### Options
<img width="1154" alt="Screenshot 2024-01-26 at 4 06 53 PM"
src="https://github.com/facebook/react/assets/2440089/c3dbd632-adb9-4416-9488-1c603ee4e789">

### `yarn flags --diff next canary`
<img width="637" alt="Screenshot 2024-01-26 at 4 15 03 PM"
src="https://github.com/facebook/react/assets/2440089/1a681ae8-ce33-42d0-9d1f-3f415a8e1c3d">


### `yarn flags --diff canary experimental`
<img width="637" alt="Screenshot 2024-01-26 at 4 14 51 PM"
src="https://github.com/facebook/react/assets/2440089/c66f66cb-3cee-4df6-a1d1-b24600ebd4b3">


### `yarn flags` (all flags)

<img width="1054" alt="Screenshot 2024-01-26 at 4 16 30 PM"
src="https://github.com/facebook/react/assets/2440089/4ce99c7c-825e-4bca-9b83-ca5d6e2bc1a9">
2024-01-30 23:15:50 -05:00
Joe Savona
d55420c430 Allow prefixed hooks for compiling bundled code
We're doing some internal benchmarking using a lightweight bundler that @pieterv 
wrote for experimentation purposes. It's designed to fully preserve Flow type 
annotations so we can experiment with type-driven compilation and test out what 
benefits we might get from "cross-module" compilation more easily (ie by just 
bundling together a few modules so we can see them all as one). 

However, the bundler renames local variables and imports, so that a reference to 
`useMemo()` might end up as `React$useMemo()` or similar. This PR adds a flag to 
tell the compiler that builtin hooks might be prefixed and resolve them 
appropriately.
2024-01-30 22:11:17 -05:00
Mofei Zhang
d0bb1fed61 [be] Explicit todo diagnostics for hoisting
--- 

Currently, we error on non-hoisted identifiers in EnterSSA with a somewhat 
cryptic message. This PR changes `BuildHIR` hoisting logic to find ALL hoistable 
bindings, then error when we try to lower hoisting for unsupported declaration 
types. 

Two benefits to this refactoring: 

- Dedups "unhandled identifier declaration" logic (previous to #2552 and this 
PR, we did this check in three places). 

- More explicit todo diagnostic messages when we cannot hoist a declaration
2024-01-31 10:59:25 -05:00
Mofei Zhang
69733c5ad8 [hoisting][patch] use Babel identifier apis in BuildHIR hoisting logic
--- 

Three functional changes: 

- Instead of visiting all identifier references, explicitly traverse only 
function decls/exprs. This avoids bugs like accidentally hoisting inline 
references 

```js 

// input 

const x = identity(y); 

const y = 2; 

// lowered HIR before this PR (simplified) 

[0] DeclareContext HoistedConst y$0 

[1] LoadContext y$0 

[2] StoreLocal Const x$5 = identity([1]) 

``` 

- Rely on `isReferencedIdentifier()` instead of manually checking member 
properties / assignments, which is error prone 

```js 

// added fixture hoisting-repro-variable-used-in-assignment 

const callbk = () => { 

// before this PR, we skip hoisting x because it's part of a declaration 

const copy = x; 

return copy; 

}; 

const x = 2; 

return callbk(); 

``` 

- Visit lvalues after rvalues. This allows for recursive self-references (e.g. 
factorial) 

From the Babel side, this change relies heavily on babel's scope binding 
resolution logic. My understanding is: 

- Babel guarantees node objects are uniqued (`node1 === node2` <--> node1 and 
node2 are the same node in the ast) 

- Each binding has exactly one `bindingIdentifier` (`binding.identifier`, 
`getBindingIdentifier`, etc) which is identifier node @ its declaration site 

```js 

// x is a binding identifier 

const x = 2; 

// foo is a binding identifier 

function foo() { 

} 

// param is a binding identifier 

(param) => {...} 

// this bar is a binding identifier 

let bar; 

// but not this bar 

bar = 2; 

```
2024-01-31 10:59:25 -05:00
Sebastian Silbermann
f3ce87ab65 Restore old behavior for empty href props on anchor tags (#28124)
Treat `<a href="" />` the same with and without
`enableFilterEmptyStringAttributesDOM`

in https://github.com/facebook/react/pull/18513 we started to warn and
ignore for empty `href` and `src` props since it usually hinted at a
mistake. However, for anchor tags there's a valid use case since `<a
href=""></a>` will by spec render a link to the current page. It could
be used to reload the page without having to rely on browser
affordances.

The implementation for Fizz is in the spirit of
https://github.com/facebook/react/pull/21153. I gated the fork behind
the flag so that the fork is DCE'd when the flag is off.
2024-01-31 00:43:40 +01:00
Sebastian Silbermann
af7e8c7a71 Convert trustedTypes to createRoot (#28163) 2024-01-30 22:22:33 +01:00
Sebastian Silbermann
13aae52aea Convert SimpleEventPlugin to createRoot (#28164) 2024-01-30 22:22:02 +01:00
Ricky
417188314d Update www flags (#28150)
Adds an experiment for `enableFormActions` and hardcodes
`enableCustomElementPropertySupport` on www since this is shipped.
2024-01-30 14:24:41 -05:00
Andrew Clark
178f435194 Always warn if client component suspends with an uncached promise (#28159)
Previously we only warned during a synchronous update, because we
eventually want to support async client components in controlled
scenarios, like during navigations. However, we're going to warn in all
cases for now until we figure out how that should work.
2024-01-30 14:23:39 -05:00
Josh Story
554fc49f41 [Fizz] improve Hoistable handling for Elements and Resources inside Suspense Boundaries (#28069)
Updates Fizz to handle Hoistables (Resources and Elements) in a way that
better aligns with Suspense fallbacks

1. Hoistable Elements inside a fallback (regardless of how deep and how
many additional boundaries are intermediate) will be ignored. The
reasoning is fallbacks are transient and since there is not good way to
clean up hoistables because they escape their Suspense container its
better to not emit them in the first place. SSR fallbacks are already
not full fidelity because they never hydrate so this aligns with that
somewhat.
2. Hoistable stylesheets in fallbacks will only block the reveal of a
parent suspense boundary if the fallback is going to flush with that
completed parent suspense boundary. Previously if you rendered a
stylesheet Resource inside a fallback any parent suspense boundaries
that completed after the shell flushed would include that resource in
the set required to resolve before the boundary reveal happens on the
client. This is not a semantic change, just a performance optimization
3. preconnect and preload hoistable queues are gone, if you want to
optimize resource loading you shoudl use `ReactDOM.preconnect` and
`ReactDOM.preload`. `viewport` meta tags get their own queue because
they need to go before any preloads since they affect the media state.

In addition to those functional changes this PR also refactors the
boundary resource tracking by moving it to the task rather than using
function calls at the start of each render and flush. Tasks also now
track whether they are a fallback task

supercedes prior work here: https://github.com/facebook/react/pull/27534
2024-01-30 10:14:59 -08:00
Josh Story
1c958aa4ab [Fiber] Use a safer strategy to track the last precedence (#28110)
Uses a safer strategy to track the last precedence to avoid the need to
consistently remember to preprend `'p'` to the precedence value
2024-01-30 10:10:19 -08:00
Sebastian Silbermann
2477384650 Complete DOMPluginEventSystem migration to createRoot (#28148)
Follow-up to
https://github.com/facebook/react/pull/28139#discussion_r1468852457

I mistakenly kept the tests using comment nodes as containers as legacy
tests. It's not that comments nodes aren't allowed in createRoot
entirely. Only behind `disableCommentsAsDOMContainers`. We already had
one test following that pattern so I just applied the same pattern to
the other tests for consistency.

Now `DOMPluginEventSystem` no longer uses any legacy roots.
2024-01-30 09:11:58 +01:00
Mofei Zhang
c3e9cba0bb [patch] PruneHoistedContexts should traverse lambdas 2024-01-29 17:45:44 -05:00
Mofei Zhang
74d8a18637 [optim] All nested properties in refs are ref values
Forget currently removes memoization of callbacks that have `mutate` effects on 
`ref` inner properties. @gsathya pointed out that our existing compiler behavior 
is to (1) NOT extend mutable ranges for functions that mutate `ref.current` and 
(2) extend mutable ranges for functions that mutate `ref.current.inner`. 

```js 

// input 

function Component() { 

const ref = useRef({ text: null }); 

const handleChange = useCallback((e) => { 

ref.current.text = e.target.value; 

}); 

return <input onChange={handleChange} />; 

} 

// output 

function Component() { 

const ref = useRef({ text: null }); 

// now unmemoized! 

const handleChange = (e) => { 

ref.current.text = e.target.value; 

};
2024-01-29 17:04:52 -05:00
Ricky
4d6c47baa3 Clean up experimental flags (#28116)
## Overview

Adds a new global to disambiguate experimental flags that we intend to
land when we can make breaking changes.
2024-01-29 14:03:39 -05:00
Ricky
4c73da8cbd Convert ReactCompositeComponent to createRoot (#28099)
Moves tests depending on legacy APIs to `ReactLegacyCompositeComponents`
and updates the rest.
2024-01-29 14:03:16 -05:00
Ricky
61df8caa3b Remove duplicate dynamic scheduler flags (#28100)
These were made dynamic again in
https://github.com/facebook/react/pull/27919, and already have the
dynamic flags set. It's a bummer to push this around, we should come up
with a better way.
2024-01-29 13:39:39 -05:00
Ricky
cc7d421629 Add lint tests that should fail (#28147)
These though fail.

Anon default export: https://github.com/facebook/react/issues/21181
Promise callbacks: https://github.com/facebook/react/issues/26186
Returning anon functions: https://github.com/facebook/react/issues/22520
2024-01-29 12:54:32 -05:00
Sebastian Silbermann
971b62f479 Convert useFocusWithin to createRoot (#28128) 2024-01-29 17:02:49 +01:00
Sebastian Silbermann
cdfaae73c4 Convert ReactDOMTextarea to createRoot (#28126)
Also removes usage of `ReactTestUtils`
2024-01-29 17:02:20 +01:00
Sebastian Silbermann
00d42ac354 Convert DOMPluginEventSystem to createRoot (#28139) 2024-01-29 09:12:20 +01:00
Sebastian Silbermann
6d2a1d0334 Convert ReactMultiChildText to createRoot (#28140) 2024-01-29 09:11:24 +01:00
Sebastian Silbermann
313e4d4129 Convert ReactDOMTextComponent to createRoot (#28141) 2024-01-29 09:11:02 +01:00
Sebastian Silbermann
1c8901f750 Convert ReactDOMSelect to createRoot (#28142) 2024-01-29 09:10:34 +01:00
Sebastian Silbermann
7aa45db6a2 Convert refs to createRoot (#28113) 2024-01-28 10:41:47 +01:00
Sebastian Silbermann
3e58b0af0c Convert ReactDOMInvalidARIAHook to createRoot (#28129) 2024-01-27 16:08:01 -05:00
Matt Carroll
e2b93afc60 Convert renderSubtreeIntoContainer-test.js to createRoot (#28114)
Co-authored-by: Ricky <rickhanlonii@gmail.com>
2024-01-26 19:30:02 -05:00
Jack Pope
407faf5a69 Remove ReactDOM.render tests in ReactDOMConsoleErrorReporting-test (#28053)
Each it block here was duplicated to cover ReactDOM.render and
ReactDOMClient.createRoot. Here we delete the ReactDOM.render coverage.

Co-authored-by: Jack Pope <jackpope@meta.com>
2024-01-26 19:29:45 -05:00
Jack Pope
91212b09ed Clean up legacy render from ReactTestUtilsAct-test (#28091)
Co-authored-by: Jack Pope <jackpope@meta.com>
2024-01-26 19:29:25 -05:00
Jack Pope
54f2314e9c Use createRoot in ReactMockedComponent-test (#28087)
Co-authored-by: Jack Pope <jackpope@meta.com>
2024-01-26 17:28:58 -05:00
Jack Pope
4c41c09ccc Use createRoot in ReactDOMComponentTree-test (#28112) 2024-01-26 17:18:03 -05:00
Jack Pope
38997cf19a Use createRoot in ReactTestUtilsActUnmockedScheduler-test (#28086) 2024-01-26 17:17:34 -05:00
Ricky
766eac46bb Remove outdated enableSchedulerDebugging flag (#28101)
This flag was moved to the scheduler feature flags, so these flags don't
do anything.
2024-01-26 16:53:01 -05:00
Matt Carroll
37bdff675c Convert ReactIdentity-test.js to createRoot (#28106) 2024-01-26 13:18:48 -08:00
Matt Carroll
759811b062 Convert ReactMultiChild-test.js to createRoot (#28117) 2024-01-26 13:18:19 -08:00
Matt Carroll
8f998bf93f Convert SyntheticEvent-test.js to createRoot (#28118) 2024-01-26 13:17:44 -08:00
Mofei Zhang
788182f709 [patch] Patch edge case: RenameVariables should visit lvalues
--- 

This is likely a rare edge case, but it does produce a parse error. 

RenameVariables visits all identifier references to ensure we don't end up 
producing conflicting variable declarations, using a stack of block scopes to 
check "in scope variables". 

This pass is currently built to be conservative -- we explicitly rename shadowed 
variables, and visit all rvalue references. The issue is for this IR: 

``` 

{ 

1.  decl t0; 

2.  scope 0 { 

3.    reassign t0 = ... 

4.    read(t0) 

5.  } 

6.  let t0 = ... 

7.  read(t0); 

} 

``` 

We currently visit t0 only on line 4 and 7 (and never rename t0). Instead we 
should visit lvalues (declaration sites) which occur earlier than rvalues 
(visiting lines 1 and 6 will show conflicting declarations)
2024-01-26 15:29:09 -05:00
Lauren Tan
4ec05660a2 [be] Update to node 20 actions
Node.js 16 which various github actions (v3) were using is no longer supported 
by github and was spewing a bunch of warnings
2024-01-30 15:46:19 -05:00
Joe Savona
bc145f6f1f Support customizable eslint suppressions
The compiler bails out of compiling code that contains suppressions of the 
official React ESLint rules. However, some apps may use additional rules that 
they want to trigger bailouts for, or use the official rules under a different 
name (we do this at Meta). This PR adds a compiler flag to specify a custom set 
of line rule names, suppression of which should trigger a bailout.
2024-01-29 16:58:49 -05:00
Lauren Tan
742a6f09bf [ez] Get rid of caniuse warning 2024-01-30 14:54:04 -05:00
Matt Carroll
7c79dafb71 Convert ReactDOMServerIntegrationUntrustedURL-test.js to createRoot (#28105) 2024-01-26 12:18:14 -08:00
Sebastian Silbermann
9aef5d225b Use modern rendering APIs for attribute-behavior fixture (#27883)
The attribute-behavior fixture now uses `createRoot().render()` and
`renderToReadableStream` instead of depdrecated APIs.

This revealed some changes to the snapshots that I annotated for
discussion.

I also added some new tests related to upcoming changes for easier
future diffing.

Also adds support for running the attribute-behavior fixture using Apple
Silicon chips (Apple MBP M-series).
2024-01-26 19:03:42 +01:00
Andrew Clark
60f190a559 Capture React.startTransition errors and pass to reportError (#28111)
To make React.startTransition more consistent with the hook form of
startTransition, we capture errors thrown by the scope function and pass
them to the global reportError function. (This is also what we do as a
default for onRecoverableError.)

This is a breaking change because it means that errors inside of
startTransition will no longer bubble up to the caller. You can still
catch the error by putting a try/catch block inside of the scope
function itself.

We do the same for async actions to prevent "unhandled promise
rejection" warnings.

The motivation is to avoid a refactor hazard when changing from a sync
to an async action, or from useTransition to startTransition.
2024-01-26 12:10:33 -05:00
Jack Pope
51c380d6ed Use createRoot in ReactEmptyComponent-test (#28095) 2024-01-26 11:37:51 -05:00
Tobias Koppers
763612647c fix incorrect insertion order of stylesheets (#28108)
## Summary

In the precendences Map every key is prefixed with `p`. This fixes one
case where this is missing.

## 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.
-->
2024-01-26 07:54:58 -08:00
Sebastian Silbermann
6c64428d90 Convert ChangeEventPlugin to createRoot (#28090) 2024-01-26 10:20:26 +01:00
Sebastian Silbermann
36baa43560 Convert ReactDOMAttribute to createRoot (#28089) 2024-01-26 10:17:26 +01:00
Sebastian Silbermann
0c45e83071 Convert SelectEventPlugin to createRoot (#28076) 2024-01-26 10:17:13 +01:00
Sebastian Silbermann
b30ec67c43 Convert ReactDOMSVG to createRoot (#28074) 2024-01-26 10:17:09 +01:00
Matt Carroll
fbb21066a2 Convert SyntheticWheelEvent-test.js to createRoot (#28103) 2024-01-26 03:05:08 -05:00
Ricky
9bad8ed9a6 Convert validateDOMNesting to createRoot (#28098)
ezpz
2024-01-25 22:30:56 -05:00
Andrew Clark
85b296e9b6 Async action support for React.startTransition (#28097)
This adds support for async actions to the "isomorphic" version of
startTransition (i.e. the one exported by the "react" package).
Previously, async actions were only supported by the startTransition
that is returned from the useTransition hook.

The interesting part about the isomorphic startTransition is that it's
not associated with any particular root. It must work with updates to
arbitrary roots, or even arbitrary React renderers in the same app. (For
example, both React DOM and React Three Fiber.)

The idea is that React.startTransition should behave as if every root
had an implicit useTransition hook, and you composed together all the
startTransitions provided by those hooks. Multiple updates to the same
root will be batched together. However, updates to one root will not be
batched with updates to other roots.

Features like useOptimistic work the same as with the hook version.

There is one difference from from the hook version of startTransition:
an error triggered inside an async action cannot be captured by an error
boundary, because it's not associated with any particular part of the
tree. You should handle errors the same way you would in a regular
event, e.g. with a global error event handler, or with a local
`try/catch`.
2024-01-25 21:54:45 -05:00
Sebastian Markbåge
382190c595 [Flight/Fizz] Reset ThenableState Only in Branches Where It's Added (#28068)
Before, we used to reset the thenable state and extract the previous
state very early so that it's only the retried task that can possibly
consume it. This is nice because we can't accidentally consume that
state for any other node.

However, it does add a lot of branches of code that has to pass this
around. It also adds extra bytes on the stack per node. Even though it's
mostly just null.

This changes it so that where ever we can create a thenable state (e.g.
entering a component with hooks) we first extract this from the task.
The principle is that whatever could've created the thenable state in
the first place, must always be rerendered so it'll take the same code
paths to get there and so we'll always consume it.
2024-01-25 19:52:00 -05:00
Jan Kassens
c7e735f625 Convert ReactLegacyContextDisabled-test.internal to createRoot (#28093)
Convert ReactLegacyContextDisabled-test.internal to createRoot
2024-01-25 16:02:13 -05:00
Jan Kassens
991b72a392 Upgrade flow to 0.227.0 (#28094)
Upgrade flow to 0.227.0
2024-01-25 16:01:40 -05:00
Jan Kassens
7724754573 Convert ReactFreshIntegration-test to createRoot (#28073)
Convert ReactFreshIntegration-test to createRoot
2024-01-25 15:07:57 -05:00
Jan Kassens
a7fa58d8b6 Convert ReactDOMInput-test to createRoot (#28084)
Convert ReactDOMInput-test to createRoot
2024-01-25 14:22:12 -05:00
Ricky
0b32b3edd2 Convert ReactCompositeComponentState to createRoot (#28063) 2024-01-25 13:36:04 -05:00
Sebastian Silbermann
43a3653b19 Convert ReactContextValidator to createRoot (#28085) 2024-01-25 18:37:07 +01:00
Jack Pope
a41ebfc5f6 Use createRoot in useFocus-test (#28083) 2024-01-25 12:10:56 -05:00
Sebastian Markbåge
b123b9c4f0 [Flight] Refactor the Render Loop to Behave More Like Fizz (#28065)
This refactors the Flight render loop to behave more like Fizz with
similar naming conventions. So it's easier to apply similar techniques
across both. This is not necessarily better/faster - at least not yet.

This doesn't yet implement serialization by writing segments to chunks
but we probably should do that since the built-in parts that
`JSON.stringify` gets us isn't really much anymore (except serializing
strings). When we switch to that it probably makes sense for the whole
thing to be recursive.

Right now it's not technically fully recursive because each recursive
render returns the next JSON value to encode. So it's kind of like a
trampoline. This means we can't have many contextual things on the
stack. It needs to use the Server Context `__POP` trick. However, it
does work for things that are contextual only for one sequence of server
component abstractions in a row. Since those are now recursive.

An interesting observation here is that `renderModel` means that
anything can suspend while still serializing the outer siblings.
Typically only Lazy or Components would suspend but in principle a Proxy
can suspend/postpone too and now that is left serialized by reference to
a future value. It's only if the thing that we rendered was something
that can reduce to Lazy e.g. an Element that we can serialize it as a
lazy.

Similarly to how Suspense boundaries in Fizz can catch errors, anything
that can be reduced to Lazy can also catch an error rather than bubbling
it. It only errors when the Lazy resolves. Unlike Suspense boundaries
though, those things don't render anything so they're otherwise going to
use the destructive form. To ensure that throwing in an Element can
reuse the current task, this must be handled by `renderModel`, not for
example `renderElement`.
2024-01-25 12:09:11 -05:00
Lauren Tan
6b49c4f2d5 [eslint-plugin] Cleanup package.json
Removes some unused packages and unused package.json fields
2024-01-25 10:29:32 -05:00
Ricky
8bb6ee1d33 Update ReactUpdates-test (#28061)
## Overview

These tests are important for `ReactDOM.render`, so instead of just
re-writing them to `createRoot` and losing coverage:
- Moved the `.render` tests to `ReactLegacyUpdates`
- Re-wrote the tests in `ReactUpdates` to use `createRoot`
- Remove `unstable_batchedUpdates` from `ReactUpdates`

In a future PR, when I flag `batchedUpdates` with a Noop, I can add the
gate to just the tests in `ReactLegacyUpdates`.
2024-01-25 01:17:03 -05:00
Ricky
696953fd51 Convert ReactDOMFiber to createRoot (#28077)
Copies the existing tests to `ReactDOMLegacyFiber`, and updates
`ReactDOMFiber` to new root.
2024-01-24 23:55:42 -05:00
Ricky
5420c4ea08 Convert ReactMount to createRoot (#28075)
To convert this file, I started replacing all the calls in line, and
quickly realized that we already have most of these tests covered in
other files. So I found the test that we didn't already have for
`create/hydrateRoot` and added them, then renamed `ReactMount` to
`ReactLegacyMount`.
2024-01-24 23:55:21 -05:00
Andrew Clark
11c9fd0c53 Batch async actions even if useTransition is unmounted (#28078)
If there are multiple updates inside an async action, they should all be
rendered in the same batch, even if they are separate by an async
operation (`await`). We currently implement this by suspending in the
`useTransition` hook to block the update from committing until all
possible updates have been scheduled by the action. The reason we did it
this way is so you can "cancel" an action by navigating away from the UI
that triggered it.

The problem with that approach, though, is that even if you navigate
away from the `useTransition` hook, the action may have updated shared
parts of the UI that are still in the tree. So we may need to continue
suspending even after the `useTransition` hook is deleted.

In other words, the lifetime of an async action scope is longer than the
lifetime of a particular `useTransition` hook.

The solution is to suspend whenever _any_ update that is part of the
async action scope is unwrapped during render. So, inside useState and
useReducer.

This fixes a related issue where an optimistic update is reverted before
the async action has finished, because we were relying on the
`useTransition` hook to prevent the optimistic update from finishing.

This also prepares us to support async actions being passed to the
non-hook form of `startTransition` (though this isn't implemented yet).
2024-01-24 23:54:53 -05:00
Ricky
2efb142606 Convert ReactDOMEventListener to createRoot (#28050) 2024-01-24 23:17:20 -05:00
Ricky
72411c45f9 Convert refs-destruction to createRoot (#28011) 2024-01-24 14:22:07 -05:00
Ricky
ee1eb4826f Use react@17 for useSyncExternalStore shim tests (#28055)
The tests for the shim need to test with ReactDOM.render in React 17.
2024-01-24 11:27:30 -05:00
Ricky
3d9b201327 Convert ReactCompositeComponentNestedState to createRoot (#28066) 2024-01-24 10:58:07 -05:00
Ricky
6480eea157 Convert ReactDOMFiberAsync to createRoot (#28067) 2024-01-24 10:57:47 -05:00
Jan Kassens
f161ceaa74 Convert ReactServerRenderingHydration-test to createRoot (partially) (#28010)
Convert ReactServerRenderingHydration-test to createRoot (partially)

Some tests seem to be specifically testing the legacy APIs, maybe we
need to keep those around. Keeping this PR to the simple updates.
2024-01-24 10:38:28 -05:00
Ricky
4217d324ae Convert ReactDOMTestSelectors-test.js to createRoot (#27993)
Straightforward adding createRoot and act
2024-01-23 23:01:53 -05:00
Jack Pope
46174f16ed Use createRoot in ReactEventIndependence-test (#28052) 2024-01-23 17:33:49 -05:00
Jack Pope
6e03d0df82 Use createRoot in ReactART-test (#28060)
Stacked on #28059

---------
2024-01-23 17:25:18 -05:00
Jack Pope
9e13800e57 Remove ReactTestUtils from ReactArt-test (#28059) 2024-01-23 17:05:01 -05:00
Joe Savona
c92ad38375 Fix block scoping issues from MergeConsecutiveBlocks
Fixes the issues from the previous PR. It's a simple fix — we don't merge 
consecutive blocks if the successor block is some terminal's fallthrough.
2024-01-23 11:41:00 -08:00
Joe Savona
b2f44c103b Fixtures demonstrating incorrect block scoping due to MergeConsecutiveBlocks
Fixtures from T173102122 and T173101739 demonstrating cases where 
MergeConsecutiveBlocks can move code out of its correct block scope, changing 
behavior or breaking the program, in cases where a control flow structure (such 
as switch) only has one non-returning control flow path. In these cases, the 
non-returning path gets merged with the fallthrough, effectively lifting that 
code out of the control flow structure and moving it into the outer scope. This 
can create dead code or just invalid code (with references to variables that are 
not in scope). 

Sprout fails on both of these fixtures: 

<img width="812" alt="Screenshot 2024-01-23 at 11 25 36 AM" 
src="https://github.com/facebook/react-forget/assets/6425824/d397ea22-3fa3-436e-b655-09a45781274b">
2024-01-23 11:40:56 -08:00
Joe Savona
f9f084087f Fixture for reactively-controlled context variables
Mofei considered this case, it works thanks to the handling for function 
expressions earlier in the stack.
2024-01-23 08:59:21 -08:00
Joe Savona
a023a2da72 Fixtures for control values that become reactive due to interleaving
See the previous PR, interleaved mutation can cause values that were not 
reactive to become reactive. I swear I had a case where this was observable, but 
I came up with it before reordering the PRs in this stack. I think my repro 
relied on an immutable reference to a mutable value, which is now handled in 
InferReactivePlaces. So here i'm just adding fixtures, and allowing this case 
since it's unobservable.
2024-01-23 08:59:20 -08:00
Jan Kassens
b2d637128c Convert ReactDOMComponent-test to createRoot (#28034)
Convert ReactDOMComponent-test to createRoot
2024-01-23 10:04:13 -05:00
Jan Kassens
cb9899955b Fix ReactFreshIntegration-test not running all tests as assumed (#28033)
Fix ReactFreshIntegration-test not running all tests as assumed

`testCommon` was executed twice without setting `compileDestructuring`
ever to true.
This fixes this and removes one layer of abstraction in this test by
using `describe.each`.
2024-01-23 09:59:14 -05:00
Sebastian Silbermann
bf32989264 Convert ReactMountDestruction (partially) to createRoot (#28004) 2024-01-23 10:30:19 +01:00
Joe Savona
4d84bee172 Propagate reactive scope dependencies transitively
During PruneNonReactiveDependencies, we sometimes need to promote a value from 
non-reactive to reactive if it ended up being grouped in the same reactive scope 
as some other reactive value. This generally happens due to interleaving 
mutations. 

In this case all downstream usage of the promoted value need to also be 
considered reactive. Fully propagating the reactivity requires re-running 
InferReactivePlaces, to account for things like control reactivity. We can't yet 
reuse that pass here though, because we haven't unified the pipeline on HIR yet. 

For now, we propagate the reactivity through local variables and downstream 
reactive scopes. See test fixtures for some examples that now correctly 
propagate reactivity and some that need the full reactivity inference to run 
correctly. The latter cases are handled in the next PR.
2024-01-22 15:35:56 -08:00
Joe Savona
57163f0a52 InferReactivePlaces account for immutable aliases of mutably aliased values
I found this by adding logic to reject inputs where reactivity gets newly 
propagated in PruneNonReactiveDependencies. It's possible to create a readonly 
alias to a mutable value such that we don't know the value is reactive yet when 
the alias is created. Thus we need to do a fixpoint iteration even if there are 
no loops in order to be able to revisit such aliases and reflow the reactivity 
forward. Example: 

```javascript 

const x = []; 

const y = x; 

const z = [y]; // y isn't reactive yet when we first visit this, so z is 
initially non-reactive 

y.push(props.value); // then we realize y is reactive. we need a fixpoint to 
propagate this back to z 

const a = [z]; // need an indirection to get past the partial propagation in 
PruneNonReactiveDependencies 

let b = 0; 

if (a[0][0]) { 

b = 1; 

} 

return [b]; 

``` 

Existing fixtures don't change because the basic reactivity propagation in 
PruneNonReactiveDependencies is enough to make common cases work. I confirmed 
that the new fixture does not work on previous PR in the stack.
2024-01-22 15:35:55 -08:00
Jack Pope
2f803b47c7 Use createRoot for ReactTreeTraversal-test (#28051) 2024-01-22 17:13:10 -05:00
Ricky
ec19db4266 Convert ReactElementJSX to createRoot (#28012) 2024-01-22 15:50:20 -05:00
Sebastian Silbermann
e1d20fc0c0 Convert describeComponentFrame to createRoot (#28001) 2024-01-22 15:08:39 +01:00
Sebastian Silbermann
206934f027 Convert ReactDOMOption to createRoot (#28002) 2024-01-22 09:21:40 +01:00
Joe Savona
0894e35d94 More fixtures for reactivity and mutable aliasing (property load case) 2024-01-19 19:12:58 -08:00
Joe Savona
8be56418d3 InferReactivePlaces accounts for mutable aliasing
Fixes T175227223. When inferring reactivity, mutation of a value with a reactive 
input marks the mutable value as reactive. However, we also need to account for 
aliases: 

```javascript 

const x = []; 

const y = x; 

y.push(props.value); 

``` 

Previously we would have only considered `y` reactive here, but `x` also becomes 
reactive. 

The implementation extracts out a helper from InferReactiveScopeVariables that 
builds a `DisjointSet<Identifier>` of disjoint sets of mutably aliased values. 
InferReactivePlaces then treats all instances of each mutable alias group as 
equivalent for reactivity purposes.
2024-01-19 16:03:58 -08:00
Ricky
29fbf6f626 Convert ReactError-test to createRoot (#27995) 2024-01-19 14:35:56 -05:00
Joe Savona
a272cf9b0c Reactive control fixtures use multipass evaluation
Updates all of the reactive control dependency fixtures to use multipass 
evaluation in sprout.
2024-01-19 11:04:18 -08:00
Jan Kassens
4c63dc7bdd Convert getEventKey-test to createRoot (#28006)
Convert getEventKey-test to createRoot
2024-01-19 13:51:20 -05:00
Jan Kassens
64d0c94724 Convert ReactUpdaters-test.internal to createRoot (#28005)
Convert ReactUpdaters-test.internal to createRoot
2024-01-19 13:37:10 -05:00
Jan Kassens
624b51388b Convert SyntheticKeyboardEvent-test to createRoot (#28007)
Convert SyntheticKeyboardEvent-test to createRoot
2024-01-19 13:36:05 -05:00
Jan Kassens
a2eaa21ac7 Convert dangerouslySetInnerHTML-test to createRoot (#28008)
Convert dangerouslySetInnerHTML-test to createRoot
2024-01-19 13:35:43 -05:00
Jan Kassens
24d1c6f0fa Convert ReactDOM-test to createRoot (#28009)
Convert ReactDOM-test to createRoot
2024-01-19 13:35:15 -05:00
Joe Savona
c8323f3b42 Mutation within a reactively controlled block propagates reactivity
In InferReactivePlaces, we already account for reactively controlled values: 
where a value is never assigned a non-reactive value, but _which_ value is 
assigned is based on a reactive condition (the test conditions of an if, switch, 
loop, etc). 

This PR extends that reactively-controlled inference to mutation that is 
conditioned upon a reactive value. From the test case: 

```javascript 

let x = []; 

if (props.cond) { 

// This mutation has no reactive inputs. 

// *But* the mutation conditionally occurs based on props.cond which is reactive 

x.push(1); 

} 

let y = false; 

if (x[0]) { // therefore the value observed here is reactive 

y = true; 

} 

// so the value of y here is reactive via the reactive control dependency x[0] 

return [y]; 

```
2024-01-19 10:03:51 -08:00
Mofei Zhang
34c89458f2 [entrypoint] Allow ref params to component functions 2024-01-19 14:59:52 -05:00
Sebastian Silbermann
4c58fc2ad8 Convert ReactFreshMultipleRenderer to createRoot (#28000) 2024-01-19 18:21:15 +01:00
Sebastian Silbermann
601dba8217 Convert ReactErrorLoggingRecovery to createRoot (#28003) 2024-01-19 18:07:08 +01:00
Ricky
feed8f3f95 Convert ReactFunctionComponent to createRoot (#27997) 2024-01-18 22:32:04 -05:00
Mofei Zhang
4aa60d32b9 [patch][dce] Patch dce to have separate mark and sweep phases
--- 

Previously, our logic was something like: 

```js 

fixed-point-loop { 

foreach instruction { 

mark referenced identifiers 

// assume that usages are always visited before declarations 

if (instruction is decl) { 

prune(instruction); 

} 

} 

foreach instruction { 

if not referenced { 

delete(instruction); 

} 

} 

``` 

This contained a bug, as not all usages of a variable are guaranteed to be 
visited before its declaration. 

```js 

// input 

let x = 0; 

while(x < 10) { 

x += 2; 

} 

return x; 

// hir 

entry: 

x$0 = 0 

goto loop-test 

loop-test: 

x$1 = phi(x$0, x$2) 

if ... goto loop-body else goto fallthrough 

loop-body: 

x$2 = x$1 ... 

goto loop-test 

fallthrough: 

return x$1 

``` 

In this example,`x$2` is defined by `loop-body` and used by `loop-test`. 
Similarly, `x$1` is defined by `loop-test` and used by `loop-body`. 

--- 

TODO: trying to come up with more test fixtures
2024-01-18 18:29:19 -05:00
Mofei Zhang
a0e90065c6 [patch][babel] check babel identifier before lowering to HoistedConst
Same babel identifier issue as #2510 but for HoistedConst 

Not sure how we should best test this -- one possibility is using constant prop. 
Currently, we have false positives for HoistedConst that prevent constant 
propagation. I don't want to over-rotate on babel apis tests in our fixtures 
(instead of semantically interesting ones) 

```js 

// input 

function Component() { 

{ x: 4 }; 

const x = 2; 

return x; 

} 

// output 

function Component() { 

const $ = useMemoCache(1); 

let x; 

if ($[0] === Symbol.for("react.memo_cache_sentinel")) { 

x = 2; 

$[0] = x; 

} else { 

x = $[0]; 

} 

return x; 

} 

```
2024-01-18 18:29:19 -05:00
Mofei Zhang
f88e7fe412 [repro] add fixture repro for destructuring bug 2024-01-18 18:29:18 -05:00
Mofei Zhang
241a615732 [babel][contextvar] Patch context identifier babel logic; only use referenced
identifiers 

--- 

A few fixes for finding context identifiers: 

Previously, we counted every babel identifier as a reference. This is 
problematic because babel counts every string symbol as an identifier. 

```js 

print(x);  // x is an identifier as expected 

obj.x      // x is.. also an identifier here 

{x: 2}     // x is also an identifier here 

``` 

This PR adds a check for `isReferencedIdentifier`. Note that only non-lval 
references pass this check 

```js 

print(x);  // isReferencedIdentifier(x) -> true 

obj.x      // isReferencedIdentifier(x) -> false 

{x: 2}     // isReferencedIdentifier(x) -> false 

x = 2      // isReferencedIdentifier(x) -> false 

``` 

Which brings us to change #2. 

Previously, we counted assignments as references due to the identifier visiting 
+ checking logic. The logic was roughly the following (from #1691) 

```js 

contextVars = intersection(reassigned, referencedByInnerFn); 

``` 

Now that assignments (lvals) and references (rvals) are tracked separately, the 
equivalent logic is this. Note that assignment to a context variable does not 
need to be modeled as a read (`console.log(x = 5)` always will evaluates and 
prints 5, regardless of the previous value of x). 

``` 

contextVars = union(reassignedByInnerFn, intersection(reassigned, 
referencedByInnerFn)) 

``` 

--- 

Note that variables that are never read do not need to be modeled as context 
variables, but this is unlikely to be a common pattern. 

```js 

function fn() { 

let x = 2; 

const inner = () => { 

x = 3; 

} 

} 

```
2024-01-18 18:29:18 -05:00
Mofei Zhang
8f18b8233f [patch][contextvars] Patch for variables reassigned after objectmethod
definitions
2024-01-18 18:29:18 -05:00
Mofei Zhang
f0ef0b7d0b Edit .git-blame-ignore-revs 2024-01-18 18:29:17 -05:00
Ricky
b300304710 Update error decoder URL (#27240)
Updates the error decoder to the URL for the new docs site.

- Switches the domain from reactjs.org to react.dev
- Switches to put the error code in the URL for SSG
- All params are still in the query

Example without args:

- Before: `https://reactjs.org/docs/error-decoder.html?invariant=200`
- After: ` https://react.dev/errors/200`

Example with args:
- Before:
`https://reactjs.org/docs/error-decoder.html?invariant=124?args[]=foo&args[]=bar
`
- After: ` https://react.dev/errors/124?args[]=foo&args[]=bar`


Requires: https://github.com/reactjs/react.dev/pull/6214

---------

Co-authored-by: Jan Kassens <jkassens@meta.com>
2024-01-17 21:41:07 -05:00
Andrew Clark
5c607369ce Remove client caching from cache() API (#27977)
We haven't yet decided how we want `cache` to work on the client. The
lifetime of the cache is more complex than on the server, where it only
has to live as long as a single request.

Since it's more important to ship this on the server, we're removing the
existing behavior from the client for now. On the client (i.e. not a
Server Components environment) `cache` will have not have any caching
behavior. `cache(fn)` will return the function as-is.

We intend to implement client caching in a future major release. In the
meantime, it's only exposed as an API so that Shared Components can use
per-request caching on the server without breaking on the client.
2024-01-16 20:27:15 -05:00
Andrew Clark
f16344ea6d Refactor React Server entrypoint to not depend on the client one (#27940)
This refactors the Server Components entrypoint for the `react` package
(ReactServer.js) so that it doesn't depend on the client entrypoint
(React.js). I also renamed React.js to ReactClient.js to make the
separation clearer.

This structure will make it easier to add client-only and server-only
features.
2024-01-16 20:19:01 -05:00
Andrew Clark
5d1b15a4f0 Rename "shared subset" to "server" (#27939)
The internal file ReactSharedSubset is what the `react` module resolves
to when imported from a Server Component environment. We gave it this
name because, originally, the idea was that Server Components can access
a subset of the APIs available on the client.

However, since then, we've also added APIs that can _only_ by accessed
on the server and not the client. In other words, it's no longer a
subset, it's a slightly different overlapping set.

So this commit renames ReactSharedSubet to ReactServer and updates all
the references. This does not affect the public API, only our internal
implementation.
2024-01-16 19:58:11 -05:00
Jan Kassens
da7c466f07 Rename eslint-plugin-react-forget to eslint-plugin-react-compiler
Rename eslint-plugin-react-forget to eslint-plugin-react-compiler
2024-01-16 17:36:37 -05:00
Jan Kassens
9b6605d313 Remove [ReactForget] prefix from eslint messages
Remove [ReactForget] prefix from eslint messages 

No other lint warnings have a prefix, removing this is cleaner.
2024-01-16 13:47:20 -05:00
Jan Kassens
fb0cf4f833 Make collapsed playground tabs more compact
Make collapsed playground tabs more compact 

We have a lot of steps creating a lot of tabs by now. This makes them visually a 
lot more compact without a full redesign. 

Makes it a bit harder to read and less modern looking, but I think usability was 
a bit bad with the wide tabs. 

**Before:** 


![image](https://github.com/facebook/react-forget/assets/11849/a87c8f7e-d60c-43c1-aaea-1a1f77e082d0) 

**After:** 


![image](https://github.com/facebook/react-forget/assets/11849/227ebf1e-055f-439a-bfc9-e69bae091f6a)
2024-01-16 13:10:32 -05:00
Sathya Gunasekaran
38d3423970 Treat function expression deps as conditional 2024-01-15 12:44:22 +00:00
Sathya Gunasekaran
121e72a342 Add flag for treating function deps as conditional 2024-01-15 12:44:22 +00:00
Sathya Gunasekaran
6d133111a9 Add test for function deps not treated as conditional
In the test, unconditionally reading props.bar.length will throw when props.bar 
is null.
2024-01-15 12:44:22 +00:00
Sathya Gunasekaran
25ec9fcea4 Add .git-blame-ignore-revs
Ignore commits that just change formatting and file structures
2024-01-15 12:44:22 +00:00
Andrew Clark
60a927d04a Fix: useOptimistic should return passthrough value when there are no updates pending (#27936)
This fixes a bug that happened when the canonical value passed to
useOptimistic without an accompanying call to setOptimistic. In this
scenario, useOptimistic should pass through the new canonical value.

I had written tests for the more complicated scenario, where a new value
is passed while there are still pending optimistic updates, but not this
simpler one.
2024-01-13 21:37:35 -05:00
Jan Kassens
33068c9db9 Upgrade ReactDOMShorthandCSSPropertyCollision-test to createRoot (#27924)
Upgrade ReactDOMShorthandCSSPropertyCollision-test to createRoot

Using the codemod from #27921 as a starting point, this migrates the
test to `createRoot`.
2024-01-12 15:51:31 -05:00
Joe Savona
90348cc873 [housekeeping] Remove disabled test262 setup
I sincerely appreciate the effort to get test262 up and running. This was my 
idea, it seemed like a really good way to test our correctness on edge cases of 
JS. Unfortunately test262 relies heavily on a few specific features that we 
don't support, like classes and `var`, which has meant that we never actually 
use this as a test suite. 

In the meantime we've created a pretty extensive test suite and have tools like 
Sprout to test actual memoization behavior at runtime, which is the right place 
to invest our energy. Let's remove?
2024-01-12 12:26:30 -08:00
Joe Savona
bcbbbec1f5 [housekeeping] Remove unused test fixtures
We don't use these fixtures, let's just clean them up.
2024-01-12 12:22:23 -08:00
Joe Savona
33118be835 [housekeeping] Remove fixtures/
Do we still use these? I'm happy to close this PR if we still want this but it 
feels like these may have served their purpose and no longer be necessary.
2024-01-12 12:22:19 -08:00
Joe Savona
653373141a Extra fixture for validating preserved memoization of non-escaping callbacks 2024-01-12 14:32:35 -08:00
Joe Savona
0c866672b0 Fix false positive on preserving memo of non-escaping values
Fixes the false positive in the previous PR. When we prune a scope because it's 
values are non-escaping, we now also remove any `Memoize` instructions for that 
scope. The intuition being that we're actively removing unnecessary memoization, 
so we don't need to check that the memoization occurred anymore.
2024-01-11 17:13:41 -08:00
Joe Savona
8e4d2fb69d Repro for false positive in validatePreserveMemoization on non-escaping value
This demonstrates a false positive in validatePreserveExistingManualMemoization. 
We prune memoization of non-escaping values, but the validation pass just sees 
that the value "should" have a scope and that scope doesn't exist, and thinks we 
failed to preserve memoization.
2024-01-11 16:52:57 -08:00
Joe Savona
c3a947643f Update hoisting error message to allow error aggregation
Interpolating values into the `reason` field of an error breaks our error 
aggregation. This PR moves the offending function name into the `description` 
field which isn't used for aggregation.
2024-01-11 15:54:55 -08:00
Jan Kassens
f6f042d747 Switch test262 submodule to https url
I had trouble checking out the repo using Sapling because the submodule couldn't 
clone properly. I got 

> Error: Permission denied (publickey) 

In my branch I tested that the https URL format seems to work okay with Sapling.
2024-01-12 15:07:24 -05:00
Jan Kassens
8a634bc1c0 Add frozen reason for props and hook arguments
Add frozen reason for props and hook arguments 

Improves the error message when mutating props or hook arguments. 

Previously, this would print a generic error about mutating global variables.
2024-01-12 14:51:59 -05:00
Sebastian Markbåge
0ac3ea471f Use getComponentNameFromType for debug info for the key warning (#27930)
If this is a client reference we shouldn't dot into it, which would
throw in the proxy.

Interestingly our client references don't really have a `name`
associated with them for debug information so a component type doesn't
show up in error logs even though it seems like it should.
2024-01-11 17:24:26 -05:00
Ruslan Lesiutin
6639ed3b3a refactor[isChildPublicInstance]: don't leak ReactNativeFiberHostComponent to Fabric implementation (#27923)
While inspecting the build artifacts for Fabric in
https://www.internalfb.com/diff/D51816108, I've noticed it has some
leaking implementation details from Paper, such as
`ReactNativeFiberHostComponent`.

The reason for it is the single implementation of
`isChildPublicInstance` in `ReactNativePublicCompat`, in which we were
using `instanceof ReactNativeFiberHostComponent`.

This new implementation removes the `ReactNativeFiberHostComponent`
leak, but decreases the Flow coverage.
2024-01-11 14:26:39 +00:00
Joe Savona
c80f0f022c useContext returns frozen values
This was an oversight in the original definition of useContext (oops my bad). 
Context values are owned by React and should not be modified. I found this 
because some cases of existing useMemo were not preserved (tested via the 
validatePreserveExistingManualMemo flag) due to function calls referencing 
context being assumed to mutate. 

This change will allow more memoization, it's also just more correct for the 
rules of React. Note the new ValueReason variant so that we can provide a 
precise error message about mutating context values.
2024-01-10 16:12:17 -08:00
Jan Kassens
49439b4db8 Upgrade Flow to 0.216.0 (#27922)
Upgrade Flow to 0.216.0

```
yarn add -W flow-bin flow-remove-types hermes-parser hermes-eslint
```
2024-01-10 13:43:04 -05:00
Jan Kassens
08cd087cad Convert ReactPureComponent-test to createRoot (#27917)
Convert ReactPureComponent-test to createRoot
2024-01-10 10:17:15 -05:00
Jan Kassens
2594caa09e Convert ReactComponentLifeCycle-test to createRoot (#27916)
Convert ReactComponentLifeCycle-test to createRoot
2024-01-10 10:16:51 -05:00
Jan Kassens
344a6675a9 Convert ReactElement-test to createRoot (#27918)
Convert ReactElement-test to createRoot
2024-01-10 10:16:38 -05:00
Noah Lemen
c81f4e02ba re-add dynamic feature flags for isInputPending (#27919)
## Summary

these were removed in https://github.com/facebook/react/pull/26617. adds
them back so we can conduct another experiment.

## How did you test this change?
`yarn test-www`
2024-01-09 17:20:42 -05:00
Jan Kassens
9723093df3 Convert createReactClassIntegration-test to createRoot (#27914)
Convert createReactClassIntegration-test to createRoot
2024-01-09 15:30:56 -05:00
Jan Kassens
ef2859d50b Convert DOMPropertyOperations-test to createRoot (#27911)
Convert DOMPropertyOperations-test to createRoot

---
[//]: # (BEGIN SAPLING FOOTER)
Stack created with [Sapling](https://sapling-scm.com). Best reviewed
with [ReviewStack](https://reviewstack.dev/facebook/react/pull/27911).
* #27914
* __->__ #27911
2024-01-09 15:30:27 -05:00
dependabot[bot]
9c08b96a78 Bump follow-redirects from 1.7.0 to 1.15.4 (#27909)
Bumps
[follow-redirects](https://github.com/follow-redirects/follow-redirects)
from 1.7.0 to 1.15.4.
<details>
<summary>Commits</summary>
<ul>
<li><a
href="65858205e5"><code>6585820</code></a>
Release version 1.15.4 of the npm package.</li>
<li><a
href="7a6567e16d"><code>7a6567e</code></a>
Disallow bracketed hostnames.</li>
<li><a
href="05629af696"><code>05629af</code></a>
Prefer native URL instead of deprecated url.parse.</li>
<li><a
href="1cba8e85fa"><code>1cba8e8</code></a>
Prefer native URL instead of legacy url.resolve.</li>
<li><a
href="72bc2a4229"><code>72bc2a4</code></a>
Simplify _processResponse error handling.</li>
<li><a
href="3d42aecdca"><code>3d42aec</code></a>
Add bracket tests.</li>
<li><a
href="bcbb096b32"><code>bcbb096</code></a>
Do not directly set Error properties.</li>
<li><a
href="192dbe7ce6"><code>192dbe7</code></a>
Release version 1.15.3 of the npm package.</li>
<li><a
href="bd8c81e4f3"><code>bd8c81e</code></a>
Fix resource leak on destroy.</li>
<li><a
href="9c728c314b"><code>9c728c3</code></a>
Split linting and testing.</li>
<li>Additional commits viewable in <a
href="https://github.com/follow-redirects/follow-redirects/compare/v1.7.0...v1.15.4">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=follow-redirects&package-manager=npm_and_yarn&previous-version=1.7.0&new-version=1.15.4)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)
You can disable automated security fix PRs for this repo from the
[Security Alerts
page](https://github.com/facebook/react/network/alerts).

</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-01-09 12:05:06 -05:00
dependabot[bot]
31603f19d7 Bump follow-redirects from 1.14.0 to 1.15.4 in /fixtures/concurrent/time-slicing (#27907)
Bumps
[follow-redirects](https://github.com/follow-redirects/follow-redirects)
from 1.14.0 to 1.15.4.
<details>
<summary>Commits</summary>
<ul>
<li><a
href="65858205e5"><code>6585820</code></a>
Release version 1.15.4 of the npm package.</li>
<li><a
href="7a6567e16d"><code>7a6567e</code></a>
Disallow bracketed hostnames.</li>
<li><a
href="05629af696"><code>05629af</code></a>
Prefer native URL instead of deprecated url.parse.</li>
<li><a
href="1cba8e85fa"><code>1cba8e8</code></a>
Prefer native URL instead of legacy url.resolve.</li>
<li><a
href="72bc2a4229"><code>72bc2a4</code></a>
Simplify _processResponse error handling.</li>
<li><a
href="3d42aecdca"><code>3d42aec</code></a>
Add bracket tests.</li>
<li><a
href="bcbb096b32"><code>bcbb096</code></a>
Do not directly set Error properties.</li>
<li><a
href="192dbe7ce6"><code>192dbe7</code></a>
Release version 1.15.3 of the npm package.</li>
<li><a
href="bd8c81e4f3"><code>bd8c81e</code></a>
Fix resource leak on destroy.</li>
<li><a
href="9c728c314b"><code>9c728c3</code></a>
Split linting and testing.</li>
<li>Additional commits viewable in <a
href="https://github.com/follow-redirects/follow-redirects/compare/v1.14.0...v1.15.4">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=follow-redirects&package-manager=npm_and_yarn&previous-version=1.14.0&new-version=1.15.4)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)
You can disable automated security fix PRs for this repo from the
[Security Alerts
page](https://github.com/facebook/react/network/alerts).

</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-01-09 11:05:08 -05:00
dependabot[bot]
531c7ad21e Bump follow-redirects from 1.13.3 to 1.15.4 in /fixtures/ssr (#27906)
Bumps
[follow-redirects](https://github.com/follow-redirects/follow-redirects)
from 1.13.3 to 1.15.4.
<details>
<summary>Commits</summary>
<ul>
<li><a
href="65858205e5"><code>6585820</code></a>
Release version 1.15.4 of the npm package.</li>
<li><a
href="7a6567e16d"><code>7a6567e</code></a>
Disallow bracketed hostnames.</li>
<li><a
href="05629af696"><code>05629af</code></a>
Prefer native URL instead of deprecated url.parse.</li>
<li><a
href="1cba8e85fa"><code>1cba8e8</code></a>
Prefer native URL instead of legacy url.resolve.</li>
<li><a
href="72bc2a4229"><code>72bc2a4</code></a>
Simplify _processResponse error handling.</li>
<li><a
href="3d42aecdca"><code>3d42aec</code></a>
Add bracket tests.</li>
<li><a
href="bcbb096b32"><code>bcbb096</code></a>
Do not directly set Error properties.</li>
<li><a
href="192dbe7ce6"><code>192dbe7</code></a>
Release version 1.15.3 of the npm package.</li>
<li><a
href="bd8c81e4f3"><code>bd8c81e</code></a>
Fix resource leak on destroy.</li>
<li><a
href="9c728c314b"><code>9c728c3</code></a>
Split linting and testing.</li>
<li>Additional commits viewable in <a
href="https://github.com/follow-redirects/follow-redirects/compare/v1.13.3...v1.15.4">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=follow-redirects&package-manager=npm_and_yarn&previous-version=1.13.3&new-version=1.15.4)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)
You can disable automated security fix PRs for this repo from the
[Security Alerts
page](https://github.com/facebook/react/network/alerts).

</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-01-09 11:04:58 -05:00
Sebastian Markbåge
f9dddcbbb1 [Fizz] Fix Client Render after Postpone (#27905)
If we end up client rendering a boundary due to an error after we have
already injected a postponed hole in that boundary we'll end up trying
to target a missing segment. Since we never insert segments for an
already errored boundary into the HTML. Normally an errored prerender
wouldn't be used but if it is, such as if it was an intentional client
error it triggers this case. Those should really be replaced with
postpones though.

This is a bit annoying since we eagerly build up the postponed path. I
took the easy route here and just cleared out the suspense boundary
itself from having any postponed slots. However, this still creates an
unnecessary replay path along the way to the boundary. We could probably
walk the path and remove any empty parent nodes.

What is worse is that if this is the only thing that postponed, we'd
still generate a postponed state even though there's actually nothing to
resume. Since this is a bit of an edge case already maybe it's fine.

In my test I added a check for the `error` event on `window` since this
error only surfaces by throwing an ignored error. We should really do
that globally for all tests. Our tests should fail by default if there's
an error logged to the window.
2024-01-08 23:52:33 -05:00
Andrew Clark
f1039be4a4 Fix: useDeferredValue initialValue suspends forever without switching to final (#27888)
Fixes a bug in the experimental `initialValue` option for
`useDeferredValue` (added in #27500).

If rendering the `initialValue` causes the tree to suspend, React should
skip it and switch to rendering the final value instead. It should not
wait for `initialValue` to resolve.

This is not just an optimization, because in some cases the initial
value may _never_ resolve — intentionally. For example, if the
application does not provide an instant fallback state. This capability
is, in fact, the primary motivation for the `initialValue` API.

I mostly implemented this correctly in the original PR, but I missed
some cases where it wasn't working:

- If there's no Suspense boundary between the `useDeferredValue` hook
and the component that suspends, and we're not in the shell of the
transition (i.e. there's a parent Suspense boundary wrapping the
`useDeferredValue` hook), the deferred task would get incorrectly
dropped.
- Similarly, if there's no Suspense boundary between the
`useDeferredValue` hook and the component that suspends, and we're
rendering a synchronous update, the deferred task would get incorrectly
dropped.

What these cases have in common is that it causes the `useDeferredValue`
hook itself to be replaced by a Suspense fallback. The fix was the same
for both. (It already worked in cases where there's no Suspense fallback
at all, because those are handled differently, at the root.)

The way I discovered this was when investigating a particular bug in
Next.js that would happen during a 'popstate' transition (back/forward),
but not during a regular navigation. That's because we render popstate
transitions synchronously to preserve browser's scroll position — which
in this case triggered the second scenario above.
2024-01-07 23:17:20 -05:00
Joe Savona
7ca3b004ae Early branch with new type inference foundation
It's starting to get complex just with a couple of extra
passes — we either need to substantially extend the HIR or (as i've done so far)
pass information from early passes to later ones. This PR changes things so that
very early in the babel plugin we fork into a separate mode. Forest has
its own `compileProgram()` equivalent, its own pipeline, its own codegen, etc.
2024-01-03 10:47:47 -08:00
Joe Savona
bd37fbe06a [wip] Fix phi inference, expose InferMutableRange issue
> Update: this is now passing all tests. The approach is likely wrong, and even 
if it's fine it needs some cleanup. Putting up for review as folks (esp 
@gsathya) have time. 

## Background 

InferTypes was intended to infer types for phi identifiers, but by accident we 
ended up storing the inferred type on `phi.type` instead of `phi.id.type`, which 
is the type that usages of the phi will reference. Because of this, we weren't 
actually inferring types for several cases, for example if both if/else branches 
assign `x` to an array literal, we'd ideally like the corresponding phi id to be 
typed as a BuiltInArray: 

```javascript 

let x; 

let y = { ... }; 

if (cond) { 

x = []; 

} else { 

x = []; 

} 

// x should be BuiltnArray here. We inferred that on Phi.type but the x here 
wouldn't get that type previously 

x.push(y); 

``` 

## Circular Types 

I started by removing the `Phi.type` property and updating inference to store 
the result of phi unification on `phi.id.type` — but this revealed other issues. 

First was this can create circular types when there are loops. The solution is 
to basically allow circular types _for phis only_, and when we detect them we 
remove the cycle. Basically whenever we have a situation where we have some type 
variable X, and a type Y that is a (nested) phi type one of whose transitive 
operands contains X, we remove X from the transitive type and attempt to 
collapse the phi type upwards if all of its remaining operands are the same: 

``` 

X=Type(1) 

Y=Phi [ 

Type(2), 

Type(3) = Phi [ 

Type(1), // <-- cycle but we can prune this 

Type(2), 

Type(2), 

] 

] 

=> 

X=Type(1) 

Y=Phi [ 

Type(2), 

Type(3) = Phi [ // all remaining operands are the same, we can prune this 

Type(2), 

Type(2), 

] 

] 

=> 

X=Type(1) 

Y=Phi [ // all remaining operands are the same, we can prune this 

Type(2), 

Type(2), 

] 

=> 

X=Type(1) 

Y=Type(2) 

``` 

We have to do this not just doing unify(), but also in `get()` since there are 
cases where we don't know yet which type variables we can remove from a phi. 
Without also doing the pruning in get, we get an infinite loop. 

## Reactive Scope Alignment 

The above fixed the circular types, but exposed some new cases that can occur in 
terms of mutable ranges and ast structures: it wasn't possible before to have a 
Store on a phi node in practice, since that relied on type information which we 
didn't have for phis. 

The new validation that all instructions for a scope are part of that scope 
caught a couple issues, which were basically like this: 

``` 

[1] Sequence 

... 

[9] StoreLocal x@0[9:28] 

[10] ... 

``` 

Note that scope 0 starts at instruction 9, but that instruction is not at the 
block scope level. The first instruction at the block scope level that is within 
the range of scope 0 is instruction 10, which is after the scope should have 
started! So I also had to update AlignScopesToBlockScopes to handle the case of 
logical, conditional, and sequence expressions: we sometime need to adjust a 
scope start earlier in case they contain instructions that should start a scope.
2024-01-02 15:31:57 -08:00
Jan Kassens
1d5667a127 [churn] remove Node 19 from dev engines, add 21 (#27870)
This allows running `yarn` with Node 21 installed, also removes Node 19
which is no longer supported according to
https://nodejs.org/en/about/previous-releases
2024-01-02 14:39:25 -05:00
Jan Kassens
45d61cf7ef [flow] upgrade to 0.225.1 (#27871)
This Flow upgrade includes 2 fixes:
- Remove `React$StatelessFunctionalComponent` as that was replaced by
just `React$AbstractComponent` as Flow doesn't make any guarantees, see
the Flow change here:
521317c48f
- Flow no longer allows `number` type indexing into objects which
discovered an incorrect type that is actually an array of the data.

Used this command to upgrade
```
yarn add -W flow-bin flow-remove-types hermes-parser hermes-eslint
```
and ran `yarn flow-ci` to check for errors in different configurations.
2024-01-02 14:39:14 -05:00
Joe Savona
bf859705b5 Enable early return support by default
This PR enables the new feature flag by default, but keeps the flag around so 
that we can quickly turn it off if there are issues.
2023-12-20 13:52:43 -08:00
Joe Savona
fcc2182641 Handle scopes with only early return and no decls/deps/reassigns
Fixes the case from the previous PR by using a different sentinel for 
uninitialized cache values and early returns. I confirmed with console.log that 
the reactive scope for `x` only evaluates on the first execution, after which we 
figure out that we don't need to execute it again.
2023-12-20 13:52:42 -08:00
Joe Savona
a753a326ad Fixture for only early return without decls/deps/reassigns 2023-12-20 13:52:41 -08:00
Joe Savona
ad57e661f4 Sprout support for rendering multiple times w different props
RFC. This is a quick sketch of adding support to Sprout to render the same 
component instance multiple times with different props. This doesn't test 
memoization (though it forms a basis for testing it, more below), but does allow 
us to test that the code properly reacts to inputs and doesn't get "stuck" 
always returning the same output even when inputs change. 

Possible extensions: 

- Support calling non-component functions multiple times 

- Test memoization by having the `toJSON()` helper track objects it has 
encountered before, assign each object a unique id, and then emit subsequent 
references to the same value as the id instead of the printed form of the 
object. 

For example if we call a memoized function with the same input twice in a row, 
today we might get output like: 

``` 

[{a: 1}], 

[{a: 1}], 

``` 

Which doesn't tell us if the object is equal. Instead we could emit output like: 

``` 

[{a: 1}] #0, 

#0, 

``` 

Which allows verifying that memoization actually happened. Or we could automate 
this and just assert that anything structurally equal has to be referentially 
equal — though there are cases with conditionals that break this.
2023-12-20 13:52:41 -08:00
Joe Savona
a86d279c46 Initial (flagged) support for reactive scopes with early return
Adds support for early returns within reactive scopes, behind a new feature 
flag. The flag is off by default, where this case continues to throw a Todo 
bailout. 

Since implementing a sketch of the codegen in the previous PR I realized that 
it's easy enough to implement the more optimal output, so i've updated that 
here. Rather than both the if and else branch of the reactive scope having an 
"if the return value was not a sentinel return it" check, we instead make the 
return temporary a proper declaration of the reactive scope. Then, since it's 
actually an output it's available in the outer block scope, and we could do a 
single if-return after the reactive scope. 

Edit: see comment below for thoughts on test cases.
2023-12-20 13:52:40 -08:00
Joe Savona
3175056935 Codegen for early returns in reactive scopes
Implements codegen for reactive scopes with early returns, though we don't ever 
construct such a case yet. See comments in the code. There is a slightly more 
optimal output that would require a larger refactor (also described in code 
comments), for now i'm starting with the simpler approach since this is 
relatively rare so we don't need to optimize code size / runtime as much.
2023-12-20 13:52:39 -08:00
Joe Savona
ed9d6a2ca1 Scaffolding for early return from reactive scopes
Adds a new `earlyReturnValue` property on ReactiveScope which will be set if the 
scope had one or more early returns, with information about the temporary 
identifier that the early return value will be assigned to, as well as the label 
to be used for breaking (to simulate the early-return). The next PR shows the 
intended codegen.
2023-12-20 13:52:38 -08:00
Joe Savona
4c68da2e60 Todo for early return within reactive scopes
Adds a new compiler pass that will eventually actually handle early returns 
within reactive scopes. For now it just detects them and throws a Todo error.
2023-12-20 13:52:37 -08:00
Sebastian Markbåge
c5b9375767 [Fizz] Only compute component stacks in DEV and prerenders (#27850)
If you have a lot of intentional throws (or postpones) from client-only
rendering then computing the stack is too much.
2023-12-19 18:04:11 -05:00
Andrey Lunyov
cb2439624f [RSC @ Meta] Simplify implementation of isClientReference, getClientReferenceKey, resolveClientReferenceMetadata (#27839)
For clientReferences we can just check the instance of the
`clientReference`.
The implementation of `isClientReference` is provided via configuration.
The class for ClientReference has to implement an interface that has
`getModuleId() method.
2023-12-19 09:17:40 -05:00
Joe Savona
f504eaa16e Add back transitive freeze functions option
Adds back a mode to transitively freeze function expressions, independently from 
the mode to preserve existing manual memoization. This lets us experiment with a 
few variants: 

* Preserve existing memoization 

* Validate existing memoization with: 

* `enableAssumeHooksFollowRulesOfReact` && 
`enableTransitivelyFreezeFunctionExpressions` 

* `enableAssumeHooksFollowRulesOfReact` only 

* neither of those flags 

Note that `enableTransitivelyFreezeFunctionExpressions` alone probably doesn't 
make sense, it's more aggressive than 

`enableAssumeHooksFollowRulesOfReact` so we might as well try them together.
2023-12-18 15:33:02 -08:00
Ruslan Lesiutin
3e00e58a6a fix[devtools/e2e]: add fallback for act in integration tests (#27842)
https://github.com/facebook/react/pull/27805 broke integration tests for
React DevTools with React 17, these changes introduce a fallback for
such case when `act` is not available in `react`, but available in
`react-dom`, like before.
2023-12-17 13:17:45 +00:00
Ondrysak
8b1547b671 docs: fix typo in README.md (#27841) 2023-12-16 18:37:42 -05:00
Sebastian Markbåge
8b8d265bd9 [Flight] Wire up async_hooks in Node.js DEV for inspecting Promises (#27840)
This wires up the use of `async_hooks` in the Node build (as well as the
Edge build when a global is available) in DEV mode only. This will be
used to track debug info about what suspended during an RSC pass.

Enabled behind a flag for now.
2023-12-15 21:38:01 -05:00
Josh Story
63310df2b2 [Fizz] Add Component Stacks to onError and onPostpone when in dev mode or during prerenders in prod mode (#27761)
Historically React would produce component stacks for dev builds only.
There is a cost to tracking component stacks and given the prod builds
try to optimize runtime performance these stacks were left out. More
recently React added production component stacks to Fiber in because it
can be immensely helpful in tracking down hard to debug production
issues. Fizz was not updated to have a similar behavior.

With the advent of prerendering however stacks for production in Fizz
are more relevant because prerendering is not really a dev-time task. If
you want the ability to reason about errors or postpones that happen
during a prerender having component stacks to interrogate is helpful and
these component stacks need to be available in production otherwise you
are really never going to see them. (it is possible that you could do
dev-mode prerenders but we don't expect this to be a common dev mode
workflow)

To better support the prerender use case and to make error logging in
Fizz more useful the following changes have been made

1. `onPostpone` now accepts a second `postponeInfo` argument which will
contain a componentStack. Postpones always originate from a component
render so the stack should be consistently available. The type however
will indicate the stack is optional so we can remove them in the future
if we decide the overhead is the wrong tradeoff in certain cases
2. `onError` now accepts a second `errorInfo` argument which may contain
a componentStack. If an error originated from a component a stack will
be included in the following cases.

This change entails tracking the component hierarchy in prod builds now.
While this isn't cost free it is implemented in a relatively lean
manner. Deferring the most expensive work (reifying the stack) until we
are actually in an error pathway.

In the course of implementing this change a number of simplifications
were made to the code which should make the stack tracking more
resilient. We no longer use a module global to curry the stack up to
some handler. This was delicate because you needed to always reset it
properly. We now curry the stack on the task itself.

Another change made was to track the component stack on SuspenseBoundary
instances so that we can provide the stack when aborting suspense
boundaries to help you determine which ones were affected by an abort.
2023-12-15 18:06:35 -08:00
Joe Savona
c77acb3ac6 Separate mode to validate preserving manual memoization
Adds a new mode which validates that existing manual memoization is preserved 
_without_ using information from the manual memoization to affect compilation. 
This gives us a way to try out the more aggressive version of Forget — ignoring 
manual memoization — first and see how much code bails out and what patterns 
cause this. 

We can then proceed to enable the mode to actually _preserve_ existing memo 
guarantees only where necessary.
2023-12-15 17:12:06 -08:00
Joe Savona
3e79c38604 More useCallback with ref fixtures 2023-12-15 16:59:19 -08:00
Joe Savona
af1aa8d0d3 Validation that useMemo/useCallback is preserved in the output
Extends `@enablePreserveExistingMemoization` to validate that all of the 
original values were actually memoized. This works nearly identically to how we 
validate effect deps are memoized. We look for Memoize instructions whose values 
need memoization but whose range extends past the memoize instruction, or where 
the value isn't memoized at all.
2023-12-15 16:22:17 -08:00
Joe Savona
0b32173d09 More fixtures for useCallback with refs
Extra fixture confirming that some usage of refs can break memoization, both in 
normal mode and in preserve-existing-memo mode.
2023-12-15 16:22:13 -08:00
Sathya Gunasekaran
721b6a4f91 [patch] Compile hooks with any number of args in infer mode 2023-12-18 13:35:56 +00:00
Joe Savona
c6200d1a2b Fix comments, extend fixtures 2023-12-15 15:19:41 -08:00
Joe Savona
6747d4e33c PreserveMemo for useCallback transitively freezes function exprs
Merges `@enableTransitivelyFreezeFunctionExpressions` into the new 
`@enablePreserveExistingMemoizationGuarantees` mode, since they are both 
motivated by the same use case of preserving effect behavior by preserving 
existing memoization behavior. 

The idea is that `useCallback` has an implicit assumption: that the variables 
captured by the callback aren't subsequently modified. Previous PRs treated the 
values directly captured by the callback as frozen. But if those variables were 
themselves another function expression, and that expression captured a mutable 
value, then we wouldn't consider the freeze to be transitive: 

```javascript 

const object = makeObject(); 

useHook(); // oops, hook call inside `object`'s mutable range, can't memoize 
object, log, or onClick! 

const log = () => { console.log(object) }; 

const onClick = useCallback(() => { log() }); 

maybeMutate(object); 

``` 

However, the assumption of such code is that it _doesn't_ modify such 
transitively captured values. So here we merge 
`@enableTransitivelyFreezeFunctionExpressions` mode into the 
memoization-preserving mode. Now, the memoize instructions emitted for 
useCallback (and useMemo) will transitively freeze captured function 
expressions, allowing us to memoize. 

The flip side of this is that some code may be violating these rules. We'll rely 
on runtime validation to detect such cases.
2023-12-15 15:19:40 -08:00
Joe Savona
08e92a3a8d More test cases for useCallback
Adds test cases per the previous PR for useCallback: 

* callback that references another callback, which in turn references a 
possibly-mutated value 

* callback that references a ref
2023-12-15 15:19:39 -08:00
Joe Savona
5bfd70ac6f Preserve memoization guarantees for useCallback
Improves `@enablePreserveExistingMemoizationGuarantees` for the useCallback 
case. Similar to useMemo, we add an explicit `Memoize` instruction for the 
callback function itself _and_ for its dependencies. This means we'll assume the 
callback doesn't mutate any captured variables. 

TODO: check this with cases involving refs (should be allowed, but also not 
accidentally freeze the ref) and reassignment of locals (should be disallowed, 
though that might just be a validation we're missing today)
2023-12-15 13:47:24 -08:00
Joe Savona
86e2edfa87 Prune memoize instructions in codegen
The previous PR introduced `memoize` instructions whose lvalues aren't used, but 
which can't be pruned by DCE due to pipeline ordering. Here we change to make 
memoize an instruction intended for its side effects only, and prune during 
codegen.
2023-12-15 13:47:23 -08:00
Joe Savona
723b616c67 enablePreserveMemo treats memo deps as frozen
See discussion on #2448 for full context. In the new 
`@enablePreserveExistingMemoizationGuarantees` mode, the goal is to preserve the 
existing referential equality guarantees from the original code. #2448 lays the 
groundwork by explicitly marking the _output_ of each useMemo block as memoized, 
hinting to the compiler that the value cannot subsequently change. This ensures 
the mutable range doesn't extend _later_, possibly overlapping a hook call and 
causing memoization to gett pruned. 

This PR fixes the other direction. There are cases where free variables 
referenced in the useMemo block could have been inferred as mutated, which could 
then extend the _start_ of the range earlier past a hook: 

```javascript 

const foo = createObject(); 

useBar(); 

const baz = useMemo(() => { 

const baz = createObject(); 

maybeMutate(foo, baz); 

return baz; 

}, [foo]); 

``` 

Here the compiler would infer that both `baz` and `foo` are mutable at the 
`maybeMutate()` call, grouping them in the same scope. But that scope would span 
the `useBar()` call, and be pruned, meaning that `baz` went unmemoized. 

However, useMemo blocks shouldn't be mutating free variables. Only variables 
newly created within the useMemo block should be mutable. So this PR extends the 
feature to treat all free variables referenced in a useMemo block as frozen as 
of the block itself.
2023-12-15 13:47:22 -08:00
Joe Savona
ec27708024 [be] Remove unnecessary check for SetState type in analyzefunctions
This was used as part of the previous ValidateNoSetStateInRender, but i rewrote 
that to not rely on the mutable range of function expressions.
2023-12-15 13:47:21 -08:00
Joe Savona
2abd439b43 Option to preserve existing memoization guarantees
Adds an option to preserve existing memoization guarantees for values produced 
with useMemo and useCallback. We still discard the calls to these hooks, but we 
preserve the information that the value is frozen at that point in the program. 
Because these values are produced solely within the useMemo/useCallback 
callback, their mutation cannot have any interspersed hook calls. This means 
that the values mutable range will never span a hook and end at the point of the 
useMemo, ensuring that they are memoized at the same point. 

The main things that can change (relative to the orignal code) are: 

* Forget will infer a precise set of dependencies, ignoring the user-provided 
values. In practice this should only occur if the original code had a lint 
violation, which Forget would bail out on. So in practice this shouldn't happen 
unless the code doesn't use the React linter. 

* Forget may start the memoization block earlier than the developer did if other 
values are mutated along with the value being produced. This can cause 
memoization to fail, but only in situations where it would have failed 
previously: 

```javascript 

const a = []; 

useFoo(); 

const b = useMemo(() => { 

const c = a; 

c.push(1); 

return c; 

}, [a]); 

``` 

In this example (sans Forget) the useMemo will invalidate on every render 
because `a` will always be a new array and its listed as a dependency of the 
useMemo. Forget would correctly determine that the memoization would have to 
work as follows: 

```javascript 

let c; 

if (...) { 

const a = [] 

useFoo(); // OOPS we made a hook call conditional 

const t0 = a; 

t0.push(1); 

c = t0; 

... 

} else { 

c = $[...] 

} 

``` 

Because this is invalid, Forget would (later in the pipeline) strip out this 
memoization block and (as with the original) leave `c` un-memoized. 

In this same example, removing the hook would cause Forget to be able to memoize 
a value that wasn't memoized before: 

```javascript 

const a = []; 

const b = useMemo(() => { 

const c = a; 

c.push(1); 

return c; 

}, [a]); 

``` 

This invalidates every render without Forget, but would memoize correctly with 
Forget (it would expand the memoization block to include the declaration of 
`a`).
2023-12-15 13:47:20 -08:00
Joe Savona
fc36043019 Fixture for pruning unmemoized nonreactive deps
Adds a fixture for our existing behavior that reactive scope dependencies 
exclude values which are non-reactive. The idea is that regardless of whether 
the value may actually get recreated over time or not, a "nonreactive" value 
cannot semantically change and therefore we can ignore changes in its pointer 
address.
2023-12-14 12:05:25 -08:00
Joe Savona
873a286029 Convert value block terminal invariant to todo 2023-12-12 16:52:24 -08:00
Joe Savona
a6e65e83e8 Prefer reporting conditional hook violations over "hook as value" violations
After running the latest hook validation internally, I found some cases where 
there was a violation but the error message was not ideal. For example on this 
code: 

```javascript 

usePossiblyNullHook?.(); 

``` 

We reported a "hooks can't be used as normal values" violation, when we'd 
ideally report a "hooks can't be called conditionally" violation. The solution 
in this PR is to track errors by source location, and upgrade the former 
violation to the latter, more serious violation. See fixtures for examples.
2023-12-12 16:42:51 -08:00
Jan Kassens
afbaa8d3ca Add a reason to ValueKind for better error messages (#2447) 2023-12-15 10:20:14 -05:00
Mofei Zhang
06376b906d [patch] Generate hook guards as function expressions
--- 

Arrow functions are not compatible with es3, which we sometimes target. This 
helps us make babel transform logic less complex
2023-12-14 19:42:24 -05:00
Sathya Gunasekaran
651d3448ac [vscode] update settings for v1.85
See https://code.visualstudio.com/updates/v1_85#_code-actions-on-save-and-auto
2023-12-14 15:47:38 +00:00
Sathya Gunasekaran
a3c48def1c Add Babel plugin to annotate react components
This can be used to figure out all the components in the bundle by grepping the 
bundle for the typeof check.
2023-12-14 15:52:17 +00:00
Sathya Gunasekaran
201b46d947 [eslint] Make the plugin configurable
As part of this PR, we remove the custom defined logger and use the logger from 
the plugin options.
2023-12-14 15:37:41 +00:00
Mofei Zhang
12de013aa4 [patch] ObjectMethods should have the same scope as their parent
ObjectExpressions 

--- 

Currently, we're removing all reactive scopes containing object methods. This 
could produce incorrect output as object method instructions may still be 
included in other reactive scopes (and will lose their dependencies).
2023-12-12 17:44:01 -05:00
Mofei Zhang
0966480d16 [be] More tests for object methods 2023-12-12 17:44:01 -05:00
Jan Kassens
493610f299 [ci] remove fuzz tests from CircleCI (#27831)
These have been migrated to GitHub Actions with
c01ac689e9.
2023-12-12 15:38:26 -05:00
Rob Anderson
c01ac689e9 convert circleci worklfow fuzz_tests to github actions (#27801)
## Summary

This pull request converts the CircleCI workflows to GitHub actions
workflows. [Github Actions
Importer](https://github.com/github/gh-actions-importer) was used to
convert the workflows initially, then I edited them manually to correct
errors in translation.

## How did you test this change?

I tested these changes in a forked repo. You can [view the logs of this
workflow in my fork](https://github.com/robandpdx/react/actions).

https://fburl.com/workplace/f6mz6tmw
2023-12-12 14:55:43 -05:00
Mofei Zhang
4c2b89288f [be][fixtures] Pass message directly instead of overwriting Error object
--- 

Started getting crashes in watch mode from trying to overwrite `error.message` 
(invalid setter or frozen object). This should fix
2023-12-11 22:59:33 -05:00
Mofei Zhang
bfa0aa2813 [be][test] use mutateAndReturn in test to render more values 2023-12-11 22:59:33 -05:00
Joe Savona
a1c7a26fc6 Put type-annotation-based inference behind feature flag 2023-12-11 11:34:29 -08:00
Joe Savona
12fbfc4fee Use variable type annotations to drive inference
Builds on the utilities added previously to infer types from type annotations on 
variable declarations. This is a limited form, where currently we only infer for 
local identifiers (not function parameters) and only infer a type for the 
variable initializer and not subsequent reassignments.
2023-12-11 11:34:29 -08:00
Joe Savona
8b3898c164 Use type assertions to drive inference
This PR uses the information from type cast expressions (`as`  or `(variable: 
type)`)  to inform type inference. BuildHIR converts the type annotation to our 
internal type format where possible, falling back to the generic `makeType()`. 
This is then used in InferTypes to help set the value's type.
2023-12-11 11:34:28 -08:00
Joe Savona
d163c0b7c3 Support TS type annotations in TypeCastExpression instr
Adds support for TSAsExpression in BuildHIR, which lowers to a 
TypeCastExpression, and to Codegen to reproduce the `as` expression.
2023-12-11 11:34:28 -08:00
Joe Savona
59b32f0813 🌲 Property/Computed load from props is a signal
Extends the previous analysis to work for PropertyLoad and ComputedLoad, so that 
if the object is a prop we track the resulting value as a signal. We also 
disallow PropertyLoad/ComputedLoad outside of a reactive scope where the object 
is a signal (since that would drop reactivity).
2023-12-11 11:34:27 -08:00
Joe Savona
3f4a9bd330 ReactiveFunctionTransform allows replacing values w transformValue
Previously the only way to replace a value was to override transformInstruction 
and transformTerminal, and to be careful to find nested values. This PR adds 
`ReactiveFunctionTransform#transformValue()` which allows returning an optional 
new value, which if present will replace the value in whatever context it 
appeared. ReactiveFunctionTransform now reimplements all the methods necessary 
to replace any value anywhere in the AST. See the next PR for an example usage.
2023-12-11 11:34:24 -08:00
Joe Savona
fa8f47eb41 InferReactivePlaces understands setState type
I realized this while working on Forest. When computing the dependencies of a 
reactive scope we can omit setState functions in the general case (exception 
described below). Currently that's implemented in PruneNonReactiveDependencies. 
However, this causes us to miss some optimizations — a value isn't reactive if 
its only dependency is a setState, and that may allow further downstreams values 
to become non-reactive. We lose out on that by only filtering out setStates in 
PruneNonReactiveDependencies — this logic really belongs in InferReactivePlaces. 

So this PR moves the check for setState types to that pass. The updated fixtures 
show that this already uncovers some wins. The _new_ fixtures covers the 
exception. It's possible for a value to be typed as being a setState function, 
but to still be reactive: if its a local that is conditionally assigned 
different setState function values. Currently this test happens to work because 
our phi type inference is incomplete (see #2296). I'm adding the test now though 
to prevent regressions when we fix phi type inference.
2023-12-11 11:34:24 -08:00
Joe Savona
9be2efdc57 🌲 Create scopes for primitive operations
In normal React certain operations don't allocate new objects (property loads, 
binary expressions, etc) and therefore don't need a reactive scope in Forget. 
For example, property loads only extract part of an existing value and don't 
allocate something new, while binary expressions are known to produce primitive 
values that don't allocate. We rely on the fact that whenever their inputs 
change we will re-run the component/hook and propagate the result forward. 

For Forest, the only way to propagate data is via reactive scopes: the component 
code is equivalent to a "setup" function. This PR updates some of our passes to 
ensure that we create (and don't prune) scopes for these types of operations. I 
started with a conservative set for now.
2023-12-11 11:34:23 -08:00
Joe Savona
1debb59830 🌲 Remove reactive scope handling from codegen
The previous PR converts reactive scopes to normal instructions, so that Forest 
mode won't have any scopes left by the time we reach codegen. This PR removes 
the now-unused codegen logic for forest.
2023-12-11 11:34:22 -08:00
Joe Savona
b3391295c8 🌲 Separate pass for lowering reactive scopes
For Forest, we previously converted reactive scopes into derived signals during 
Codegen. I'm moving this to a separate pass primarily to keep codegen simple 
since there's enough complexity just dealing with core JS semantics. Ideally 
we'd do a similar setup even for regular Forget, ie lower reactive scopes just 
prior to codegen. 

At the same time i also reordered the forget passes to be just before codegen, 
and cleaned things up a bit. For state lowering, we now just rewrite `useState` 
-> `createState`, because we actually need to keep around the setter function to 
trigger scheduling updates in addition to writing the signal value.
2023-12-11 11:34:22 -08:00
Joe Savona
1b5ef83b78 🌲 Separate flag for jsx compilation
Per discussion w @pieterv we'd like to have a mode where we compile JSX 
separately, so splitting this flag into two variants.
2023-12-11 11:34:21 -08:00
Jan Kassens
0cdfef19b9 Add feature flags for expiration times (#27821)
It seems worthwhile to me to run a test to experiment with different
expiration times. This moves the expiration times for scheduler and
reconciler into FeatureFlags for the facebook build. Non-facebook should
not be affected by these changes.
2023-12-11 09:58:18 -05:00
Jan Kassens
40f653d13c Remove WARNINGS file from FB (#27820)
The test was migrated to the generated JS file that allows Jest to track
the dependencies, we can now remove this file generation.
2023-12-08 16:21:15 -05:00
Josh Story
5bcade5fcf [Flight] Support postponing through a serialized promise (#27818)
Postponing in a promise that is being serialized to the client from the
server should be possible however prior to this change Flight treated
this case like an error rather than a postpone. This fix adds support
for postponing in this position and adds a test asserting you can
successfully prerender the root if you unwrap this promise inside a
suspense boundary.
2023-12-08 11:05:32 -08:00
Jan Kassens
8ff2c236a2 Add header to ReactAllWarnings Meta-only file (#27819)
Adds missing headers to the generated file.
2023-12-08 13:44:20 -05:00
Jan Kassens
d3ed07bce0 [ci] try to fix commit_artifacts step (#27817)
Tries to fix the failure from
https://github.com/facebook/react/actions/runs/7142005723/job/19450371514

I think it failed because we cannot `mv` into a folder with existing
files or folders.
2023-12-08 12:38:35 -05:00
Tianyu Yao
f193213d29 Add a regression test for an infinite suspense + Fix (#27703)
Add a regression test for the [minimal
repro](https://codesandbox.io/s/react-18-suspense-state-never-resolving-bug-hmlny5?file=/src/App.js)
from @kassens

And includes the fix from @acdlite: 
> This is another place we special-case Retry lanes to opt them out of
expiration. The reason is we rely on time slicing to unwrap uncached
promises (i.e. async functions during render). Since that ability is
still experimental, and enableRetryLaneExpiration is Meta-only, we can
remove the special case when enableRetryLaneExpiration is on, for now.

---------

Co-authored-by: Andrew Clark <git@andrewclark.io>
2023-12-08 09:21:36 -08:00
BIKI DAS
a3aae7fb01 feat:-added tests for more coverage in reactDom-input and reactText-area (#27796)
Small test similar to few tests added in #27740 , the `reactDom-input`
error message was just modified to match the error message, and the
`reactDomTextarea-test.js` has tests added to ensure more coverage.
2023-12-08 13:34:09 +00:00
Jan Kassens
af1fc87b54 [meta] copy ReactAllWarnings.js file (#27811)
I recently added generation of this file in #27786, which builds the
file in CircleCI, but missed actually copying it to the facebook build
on GitHub Actions.

This adds the later.
2023-12-07 17:08:52 -05:00
Mofei Zhang
9e267714db [patch] Compile hooks with any number of args in infer mode 2023-12-07 16:14:25 -05:00
Jack Pope
b36ae8d7aa Add stable concurrent option to react-test-renderer (#27804)
## Summary

Concurrent rendering has been the default since React 18 release.
ReactTestRenderer requires passing `{unstable_isConcurrent: true}` to
match this behavior, which means by default tests written with RTR use a
different rendering method than the code they test.

Eventually, RTR should only use ConcurrentRoot. As a first step, let's
add a version of the concurrent option that isn't marked unstable. Next
we will follow up with removing the unstable option when it is safe to
merge.

## How did you test this change?

`yarn test
packages/react-test-renderer/src/__tests__/ReactTestRendererAsync-test.js`
2023-12-07 10:26:33 -05:00
Jan Kassens
be8aa76873 Enable flag disableModulePatternComponents for native-fb (#27807)
#27742 will remove this feature flag altogether, this just already
removes the dynamic flag for the Meta React Native build ahead of time.
2023-12-06 16:02:52 -05:00
Josh Story
9cae4428a1 Update act references in tests (#27805)
As part of the process of removing the deprecated `react-dom/test-utils`
package references to `act` from this module are replaced with
references to `unstable_act` in `react`. It is likely that the unstable
act implementation will be made stable. The test utils act is just a
reexport of the unstable_act implementation in react itself.
2023-12-06 12:57:14 -08:00
Mofei Zhang
995f4b0528 [bugfix] Fix constant propagation to ObjectMethods 2023-12-06 13:20:50 -05:00
Mofei Zhang
d3e84d4dff [repro] repro for ContextVariable bug (ObjectMethod)
Found from eslint validator on www after doing a local sync + RunForget test of 
#2432 

P898168203 

> New Errors: 

> no-undef:'VARIABLE_NAME' is not defined.
2023-12-06 13:20:49 -05:00
Mofei Zhang
7e9f6ecfea [patch] Make holey array handling compatible with older babel versions
--- 

Copied from comments 

Older versions of babel have a validation bug fixed by 

- https://github.com/babel/babel/pull/10917 

- (code pointer) 
e7b80a2cb9 (diff-19b555d2f3904c206af406540d9df200b1e16befedb83ff39ebfcbd876f7fa8aL52) 

Link to buggy older version (observe that elements must be PatternLikes here) 


https://github.com/babel/babel/blob/v7.7.4/packages/babel-types/src/definitions/es2015.js#L50-L53 

Link to newer versions with correct validation (observe elements can be 
PatternLike | null) 


https://github.com/babel/babel/blob/v7.23.0/packages/babel-types/src/definitions/core.ts#L1306-L1311 

Tested on 3000+ components in fb: 

P898166848 

> Unexpected Errors 

> (count = 0) 

[patch] Make holey array handling compatible with older babel versions 

--- 

Copied from comments 

Older versions of babel have a validation bug fixed by 

- https://github.com/babel/babel/pull/10917 

- (code pointer) 
e7b80a2cb9 (diff-19b555d2f3904c206af406540d9df200b1e16befedb83ff39ebfcbd876f7fa8aL52) 

Link to buggy older version (observe that elements must be PatternLikes here) 


https://github.com/babel/babel/blob/v7.7.4/packages/babel-types/src/definitions/es2015.js#L50-L53 

Link to newer versions with correct validation (observe elements can be 
PatternLike | null) 


https://github.com/babel/babel/blob/v7.23.0/packages/babel-types/src/definitions/core.ts#L1306-L1311 

Tested on 3000+ components in fb: 

P898166848 

> Unexpected Errors 

> (count = 0)
2023-12-06 13:20:49 -05:00
Mofei Zhang
01c1b16db4 [patch] Make Codegen ObjectMethod call compatible with babel v7.7
--- 

Tested on - with RunForget 
([before](P897673438), 
[after](P897678035)) 

Compiles 12 more files
2023-12-06 13:20:48 -05:00
Mofei Zhang
41b164ed24 [validation] Runtime validation for hook calls
--- 

I modeled guards as try-finally blocks to be extremely explicit. An alternative 
implementation could flatten all nested hooks and only set / restore hook guards 
when entering / exiting a React function (i.e. hook or component) -- this 
alternative approach would be the easiest to represent as a separate pass 

```js 

// source 

function Foo() { 

const result = useHook(useContext(Context)); 

... 

} 

// current output 

function Foo() { 

try { 

pushHookGuard(); 

const result = (() => { 

try { 

pushEnableHook(); 

return useHook((() => { 

try { 

pushEnableHook(); 

return useContext(Context); 

} finally { 

popEnableHook(); 

} 

})()); 

} finally { 

popEnableHook(); 

}; 

})(); 

// ... 

} finally { 

popHookGuard(); 

} 

} 

// alternative output 

function Foo() { 

try { 

// check current is not lazyDispatcher; 

// save originalDispatcher, set lazyDispatcher 

pushHookGuard(); 

allowHook(); // always set originalDispatcher 

const t0 = useContext(Context); 

disallowHook(); // always set LazyDispatcher 

allowHook(); // always set originalDispatcher 

const result = useHook(t0); 

disallowHook(); // always set LazyDispatcher 

// ... 

} finally { 

popHookGuard(); // restore originalDispatcher 

} 

} 

``` 

Checked that IG Web works as expected 

Unless I add a sneaky useState: 

<img width="705" alt="Screenshot 2023-12-05 at 6 44 59 PM" 
src="https://github.com/facebook/react-forget/assets/34200447/3790bd76-7d71-44b5-a62e-f53256fb5736">
2023-12-05 15:02:34 -05:00
Mofei Zhang
37e1975050 [be] Move codegen logic Program.ts -> Codegen
--- 

Prior to this PR, we were mutating functions after CodegenReactiveFunction 
completes (in `Entrypoint/Program.ts`). 

The reasoning for this separation was that we wanted to keep non-compiler logic 
out of the core Pipeline. However, it made our code difficult to read and reason 
about. 

Open to other alternatives, like adding a pass after Codegen.
2023-12-05 15:02:33 -05:00
Mofei Zhang
346350f77d Revert: revert tsconfig module change for rollup
--- 

Currently on main, rollup does not inline source files 

```js 

// in packages/babel-plugin-react-forget 

// $yarn build 

// output 

var CompilerError_1 = require("./CompilerError"); 

Object.defineProperty(exports, "CompilerError", { enumerable: true, get: 
function () { return CompilerError_1.CompilerError; } }); 

// ... 

``` 

I debugged a bit but not familiar with node or rollup. 

- It seems that rollup fails to recognize source file imports with this setting, 
as resolveId no longer gets called 

- current `module` option defaults to `ESNext`, which works for some reason. 

Let's revert for now to unblock syncs. 

Sanity checked my repro by reinstalling node-modules and cleaning rollup cache.
2023-12-05 17:22:37 -05:00
Jan Kassens
aba93acb6c [easy] remove unused deps coveralls and @actuallyworks/node-fetch (#27792)
I do not see references to these modules. Unless there's some dynamic
loading going on (hopefully we should see that in CI) these seem like
they can be removed.
2023-12-05 14:15:23 -05:00
Ruslan Lesiutin
c29ca23af9 fix: add isChildPublicInstance to ReactNativeTypes (#27788)
Follow-up on https://github.com/facebook/react/pull/27783.

React Native is actually using `ReactNativeTypes`, which are synced from
this repo. In order to make `isChildPublicInstance` visible for
renderers inside React Native repository, we need to list it in
`ReactNativeTypes`.

Because of current circular dependency between React Native and React,
it is impossible to actually type it properly:
- Can't import any types in `ReactNativeTypes` from local files, because
it will break React Native, once synced.
- Implementations can't use real types in their definitions, because it
will break these checks:


223db40d5a/packages/react-native-renderer/fabric.js (L12-L13)


223db40d5a/packages/react-native-renderer/index.js (L12-L14)
2023-12-05 13:00:59 +00:00
Jan Kassens
5ab6bbb4b0 package.json: cleanup deprecated scripts (#26852)
I think these have been dead for a while now. If the purpose is
documentation, we should see if we need to improve `yarn test --help` or
something instead.
2023-12-04 16:20:49 -05:00
Jan Kassens
f498aa2992 Flow: make more objects exact (#27790)
This makes a couple objects more exact. Nothing critical, just noticed
this old branch I had created when doing some Flow upgrades in the past.
2023-12-04 16:10:36 -05:00
Joe Savona
1d36764ca9 [be] Align tsconfig module/moduleResolution settings 2023-12-04 11:19:41 -08:00
Jan Kassens
223db40d5a Create warnings JS file for Meta (#27786)
The `WARNINGS` file isn't picked up by the test dependency analyzer,
this creates a JS version of the file that I think should work.
2023-12-04 13:33:44 -05:00
Jan Kassens
f391cdab02 Update warnings extraction to hermes-parser (#27785)
`hermes-parser` is recommended for all Flow files as it supports the
latest features. I noticed we were still using babel here.

Test Plan:
no diff in output before and after
2023-12-04 13:25:53 -05:00
Ruslan Lesiutin
1729b499ed feat[Fabric/Paper]: support isChildPublicInstance api method (#27783)
Adds `isChildPublicInstance` method to both renderers (Fabric and
Paper), which will receive 2 public instances and return if first
argument is an ancestor of the second, based on fibers.

This will be used as a fallback when DOM node APIs are not available:
for Paper renderer or for Fabric without DOM node APIs.

How it is going to be used: to determine which `AppContainer` component
in RN is responsible for highlighting an inspected element on the
screen.
2023-12-04 17:22:03 +00:00
Jan Kassens
e3fb6ac862 [flow] upgrade to 0.213.2 (#27784)
No significant changes from Flow, just keeping us current.

[Changelog](https://github.com/facebook/flow/blob/main/Changelog.md)
2023-12-04 11:35:27 -05:00
Jan Kassens
640ccebb7d [lint] treat React.use() the same as use() (#27769)
We should probably treat `React.use()` the same as `use()` to allow it
within loops and conditionals.

Ideally this would implement a test that `React` is imported or required
from `'react'`, but we don't otherwise implement such a test.
2023-12-01 15:02:11 -05:00
dependabot[bot]
d7b45ec9b7 Bump @adobe/css-tools from 4.0.1 to 4.3.2 in /fixtures/flight (#27766)
Bumps [@adobe/css-tools](https://github.com/adobe/css-tools) from 4.0.1
to 4.3.2.
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a
href="https://github.com/adobe/css-tools/blob/main/History.md"><code>@​adobe/css-tools</code>'s
changelog</a>.</em></p>
<blockquote>
<h1>4.3.2 / 2023-11-28</h1>
<ul>
<li>Fix redos vulnerability with specific crafted css string -
CVE-2023-48631</li>
<li>Fix Problem parsing with :is() and nested :nth-child() <a
href="https://redirect.github.com/adobe/css-tools/issues/211">#211</a></li>
</ul>
<h1>4.3.1 / 2023-03-14</h1>
<ul>
<li>Fix redos vulnerability with specific crafted css string -
CVE-2023-26364</li>
</ul>
<h1>4.3.0 / 2023-03-07</h1>
<ul>
<li>Update build tools</li>
<li>Update exports path and files</li>
</ul>
<h1>4.2.0 / 2023-02-21</h1>
<ul>
<li>Add <a
href="https://github.com/container"><code>@​container</code></a>
support</li>
<li>Add <a href="https://github.com/layer"><code>@​layer</code></a>
support</li>
</ul>
<h1>4.1.0 / 2023-01-25</h1>
<ul>
<li>Support ESM Modules</li>
</ul>
<h1>4.0.2 / 2023-01-12</h1>
<ul>
<li><a
href="https://redirect.github.com/adobe/css-tools/issues/71">#71</a> :
<a href="https://github.com/import"><code>@​import</code></a> does not
work if url contains ';'</li>
<li><a
href="https://redirect.github.com/adobe/css-tools/issues/77">#77</a> :
Regression in selector parsing: Attribute selectors not parsed
correctly</li>
</ul>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li>See full diff in <a
href="https://github.com/adobe/css-tools/commits">compare view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=@adobe/css-tools&package-manager=npm_and_yarn&previous-version=4.0.1&new-version=4.3.2)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)
You can disable automated security fix PRs for this repo from the
[Security Alerts
page](https://github.com/facebook/react/network/alerts).

</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-12-01 14:56:14 -05:00
Mark Erikson
108fd8cab0 Add sideEffects flag to react-is for tree shaking (#27701)
## Summary

This PR:

- Adds the `"sideEffects": false` flag to the `react-is` package, to
enable proper tree-shaking

## How did you test this change?

React-Redux v9 beta switches its artifacts from separate JS files to
pre-bundled artifacts. While testing builds locally, I noticed that our
use of `react-is` was no longer getting tree-shaken from Vite builds,
despite `react-is` only being used by our `connect` API and `connect`
itself getting shaken out of the final bundle.

Hand-adding `"sideEffects": false` to the `react-is` package locally
convinced Vite (+Rollup) to properly tree-shake `react-is` out of the
bundle when it wasn't being used.

I'd love to see this published as v18.2.1 as soon as this PR is merged -
we're hoping to release React-Redux v9 in the next few weeks!
2023-12-01 14:38:15 -05:00
WilliamDecker
dc40571b3e Update .prettierrc.js (#27732)
jsxBracketSameLine deprecated in v2.4.0 of Prettier, replaced by
bracketSameLine.

https://prettier.io/docs/en/options.html#deprecated-jsx-brackets

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

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

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

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

## Summary

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

I've always wanted to contribute to open source, even if it's in the
smallest way possible. Resolves deprecated feature with currently used
version of Prettier (2.4+). Those doing things like using React as a
reference for their ".prettierrc" files will be using the non-deprecated
versions.

## How did you test this change?

Modified line 969 of App.js to push </h1> to line 971, saved the file,
then ran "yarn prettier" and formatting returned it to original position
confirming that jsxBracketSameLine acts in the same fashion to
bracketSameLine, but also is no longer deprecated that has additional
features which may be useful in the future to the project.


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

λ yarn prettier
yarn run v1.22.19
$ node ./scripts/prettier/index.js write-changed
> git merge-base HEAD main
> git diff --name-only --diff-filter=ACMRTUB
bbb9cb116d
> git ls-files --others --exclude-standard
Done in 1.52s.
2023-12-01 14:30:42 -05:00
BIKI DAS
5dd35968be fix: select console error to not suggest to set readonly to true (#27740)
fix #27657 

added test in the `ReactDOMSELECT-test.js` to not allow regession to
happen in future.

After changes this is what the error message looks like


https://github.com/facebook/react/assets/72331432/53dcbe2a-70d2-43d2-a52d-a4fc389fdfbf
2023-12-01 15:55:55 +00:00
Jack Pope
3e97c00deb Rename fork ReactSharedInternals -> ReactSharedInternalsClient (#27767)
## Summary

Follow up from #27717 based on feedback to rename the fork module itself

## How did you test this change?

- `yarn build`
- `yarn test
packages/scheduler/src/__tests__/SchedulerUMDBundle-test.internal.js`

Co-authored-by: Jack Pope <jackpope@meta.com>
2023-12-01 09:48:04 -05:00
Joe Savona
9fb3a26174 Add logging for number of memo *blocks* (in addition to slots)
Useful for understanding and comparing how much memoization Forget applies vs 
how much developers previously memoized by hand.
2023-11-30 15:20:01 -08:00
Joe Savona
3639704f2b Enable hooks validation in eslint 2023-12-04 08:22:51 -08:00
Joe Savona
0c0bedd377 New approach to hook validation
New approach to hooks validation per recent discussion. The idea is to avoid 
false positives while still preventing serious violations. See the comments in 
the file for more details about the approach. It uses a somewhat similar idea to 
InferReferenceEffects in that we track a "Kind" for each IdentifierId, and 
various instructions propagate or derive a result Kind from the operands. Kinds 
form a lattice and can be joined, allowing us to be more precise about known vs 
potential hooks, and known vs potential _sources_ of hooks.
2023-12-04 08:15:26 -08:00
Jan Kassens
b8be034f07 [lint] move use lint to non-experimental (#27768)
`use` is being stabilized, so let's make sure the lint is updated for
the next release.
2023-11-30 17:39:00 -05:00
Kathryn Middleton
60ad3693a5 Update README.md with react.dev links (#27765)
## Summary

Update legacy reactjs.org links and update to the corresponding ones on
react.dev

## How did you test this change?

Verify all links go to the expected pages
2023-11-30 12:08:44 -05:00
Joe Savona
7da906d648 Fix Array#at and similar cases to capture if receiver is mutable
The previous PR helped me realize we weren't handling Array#at correctly. If the 
receiver is a mutable value its effect should be Capture and the lvalue effect 
needs to be Store. This PR updates the definition for Array#at to make the 
receiver Capture, and then updates inference to automatically set the lvalue 
effect to Store if _any_ argument (or the receiver) was Capture.
2023-11-29 12:05:25 -08:00
Joe Savona
75c7fdcbd0 MutableIfOperandsAreMutable flag handles mutation via capturing
There was one missing piece to the optimization from the previous PR: Array#map 
can return an alias to the receiver in its output, which means that mutations of 
the result have to be treated as mutations of the receiver. This means we need 
to use a Capture effect on the receiver. If that doesn't get downgraded to a 
Read bc the value was immutable, we then also need to make the lvalue effect a 
Store (so that InferMutableRanges actually looks at it for aliasing).
2023-11-29 10:46:44 -08:00
Joe Savona
f7d16db544 [RFC] Refine memoization for Array#map with non-mutating callbacks
Improves memoization for cases such as #2409: 

```javascript 

const x = []; 

useEffect(...); 

return <div>{x.map(item => <span>{item}</span>)}</div>; 

``` 

We previously thought that the `x.map(...)` call mutated `x` since its kind was 
Mutable. However, in this case we can determine that the map call cannot mutate 
`x` (or anything else): the lambda does not mutate any free variables and does 
not mutate its arguments. 

This PR adds a new flag to function signatures, used for method calls only, that 
checks for such cases. The idea is that if the receiver is the only thing that 
is mutable — including that there are no args which are function expressions 
which mutate their parameters — then we can infer the effect as a read. See 
tests which confirm that function expressions which capture or mutate their 
params bypass the optimization.
2023-11-29 10:46:43 -08:00
Joe Savona
65c54e2d70 Repro for unmemoized array due to mutation surrounding hook
Distilled repro of an internal example we found. Forget determines a mutable 
range for the array, but that mutable range spans a hook call, so the reactive 
scope gets pruned. That's all working as expected. 

What isn't ideal though is that if we know `x` is an array and `f` can't mutate 
its arguments, then `x.map(f)` shouldn't count as a mutation of `x`, since 
Array.prototype.map can only mutate the receiver via the callback (if the 
callback mutates its args). 

Improving on this example requires a) we have to know it's an Array, via type 
information or bc we saw an array literal and b) being precise about which 
functions could possibly mutate their parameters, which is tricky because of 
indirect mutations via stores, etc.
2023-11-29 10:46:42 -08:00
Joe Savona
b952bc3d87 [be] Consistently use known returnValueKind from signatures
We were using `returnValueKind` from function signatures for CallExpression but 
not MethodCall; this PR changes to use this signature information for both 
instruction kinds.
2023-11-29 10:46:42 -08:00
Ruslan Lesiutin
87cb0bf182 React DevTools 4.28.5 -> 5.0.0 (#27759)
### Breaking
* refactor[devtools]: highlight an array of elements for native
([hoxyq](https://github.com/hoxyq) in
[#27734](https://github.com/facebook/react/pull/27734))

### Features
* feat[devtools]: display Forget badge for the relevant components
([hoxyq](https://github.com/hoxyq) in
[#27709](https://github.com/facebook/react/pull/27709))

### Other
* Added windows powershell syntax to build scripts
([PrathamLalwani](https://github.com/PrathamLalwani) in
[#27692](https://github.com/facebook/react/pull/27692))
* refactor[react-devtools-shared]: minor parsing improvements and
modifications ([hoxyq](https://github.com/hoxyq) in
[#27661](https://github.com/facebook/react/pull/27661))
2023-11-29 18:27:53 +00:00
Mofei Zhang
359b9b1589 [ez] Patch unsound array destructuring
--- 

Going to hold off on landing until after codefreeze, it's not urgent as we 
already fixed playground in #2404. All other internal pipelines do error 
handling through Entrypoint, which catches and creates UnexpectedErrors as 
needed.
2023-11-28 17:48:22 -05:00
Sathya Gunasekaran
0a6d3b31de Add compilation failure test for Logger 2023-11-28 15:35:48 +00:00
Sathya Gunasekaran
e53e944580 [test] Add test for Logger 2023-11-28 15:35:46 +00:00
Sathya Gunasekaran
18d4913406 [babel] Don't use source location for hoisting check
Instead of using the source location to check for hoisting, just stop checking 
for a given component after we reach it's declaration. 

By definition all references to it before are (potential) hoisting errors. 

Note that there could be false positives but that's ok.
2023-11-28 14:18:24 +00:00
Sathya Gunasekaran
42fa01ec87 [test] Add failing test for component syntax with refs
The desugaring of Component syntax with refs is not compatible with our gating 
lowering.
2023-11-28 14:18:24 +00:00
Sathya Gunasekaran
be03439687 [yarn] Update hermes-parser
Need new version for component syntax updates
2023-11-28 14:18:24 +00:00
Sathya Gunasekaran
1ebb7ae376 [eslint] Assume external modules are non side-effecting
This lets us tree shake out the `chalk` module entirely
2023-11-28 14:10:48 +00:00
Sathya Gunasekaran
0ba3065812 [eslint] Don't rollup zod 2023-11-28 14:10:48 +00:00
Andrey Lunyov
c17a27ef49 FB-specific builds of Flight Server, Flight Client, and React Shared Subset (#27579)
This PR adds a new FB-specific configuration of Flight. We also need to
bundle a version of ReactSharedSubset that will be used for running
Flight on the server.

This initial implementation does not support server actions yet.

The FB-Flight still uses the text protocol on the server (the flag
`enableBinaryFlight` is set to false). It looks like we need some
changes in Hermes to properly support this binary format.
2023-11-27 18:34:58 -05:00
Joe Savona
445baf9ae4 Extend effect dep validation to handle pruned memoization
Extends the validation that effect deps are memoized to handle an additional 
case that @gsathya  pointed out: when a dependency has a reactive scope but that 
scope ends up being pruned. We track reactive scopes which actually exist in the 
ReactiveFunction, and reject useEffect deps that have an associated reactive 
scope but where that scope does not exist (bc it got pruned).
2023-11-27 12:31:27 -08:00
Joe Savona
d7db416167 [RFC] useEffect dependency memoization check
This is one approach to testing whether useEffect dependencies are memoized. The 
idea is based off the observation that the only reason dependencies wouldn't be 
memoized (other than compiler bugs) is that they are mutated later. If they're 
mutated later, then the dep array will have a mutable range which encompasses 
the InstructionId of the useEffect call. So we look for that pattern and throw a 
validation error. 

The downside of this approach is that we might reject code that happens to be 
valid: specifically, that the lack of memoization isn't a problem in practice 
because the effect won't trigger a loop. But (per test plan) this doesn't seem 
to introduce that many new bailouts on www. Rather than implement a complex 
validation that checks whether we un-memoized something that was memoized in the 
input, it seems more practical to: 

1. Enable this more comprehensive validation against any form of un-memo'd 
effect dependency 

2. Flip the default for hooks (to assume they follow the rules), which will fix 
the primary cause of Forget pessimistically not memoizing dependencies. 

## Test Plan 

Synced to www and checked output via the upgrade script: a few components stop 
getting memoized bc they have un-memoized effect dependencies. Let's chat!
2023-11-27 10:20:43 -08:00
Ruslan Lesiutin
6c7b41da3d feat[devtools]: display Forget badge for the relevant components (#27709)
Adds `Forget` badge to all relevant components.

Changes:
- If component is compiled with Forget and using a built-in
`useMemoCache` hook, it will have a `Forget` badge next to its display
name in:
  - components tree
  - inspected element view
  - owners list
- Such badges are indexable, so Forget components can be searched using
search bar.

Fixes:
- Displaying the badges for owners list inside the inspected component
view

Implementation:
- React DevTools backend is responsible for identifying if component is
compiled with Forget, based on `fiber.updateQueue.memoCache`. It will
wrap component's display name with `Forget(...)` prefix before passing
operations to the frontend. On the frontend side, we will parse the
display name and strip Forget prefix, marking the corresponding element
by setting `compiledWithForget` field. Almost the same logic is
currently used for HOC display names.
2023-11-23 18:37:21 +00:00
Ruslan Lesiutin
fbc9b68d61 refactor[devtools]: highlight an array of elements for native (#27734)
We are currently just pass the first element, which diverges from the
implementation for web. This is especially bad if you are inspecting
something like a list, where host fiber can represent multiple elements.

This part runs on the backend of React DevTools, so it should not affect
cases for React Native when frontend version can be more up-to-date than
backend's. I will double-check it before merging.

Once version of `react-devtools-core` is updated in React Native, this
should be supported, I will work on that later.
2023-11-23 11:31:07 +00:00
Jan Kassens
a3172e933c Add dynamic disableModulePatternComponents flag for native-fb (#27739)
Makes `disableModulePatternComponents` a flag to allow us a slow rollout
for RN internally.
2023-11-22 13:05:24 -05:00
Mofei Zhang
5b8e94c6d8 [ez][wip] Make playground more resilient to crashes
--- 

<img width="1031" alt="image" 
src="https://github.com/facebook/react-forget/assets/34200447/8e475472-45c3-4ef0-aa4b-d187e72b999c"> 

Behold! No instacrash on `useMemo()`
2023-11-21 09:30:29 -06:00
Mofei Zhang
6a6ef0ab59 [repro] Forget outputs invalid code when we bailout
Sprout output: 

``` 

$ sprout --filter --verbose 

FAIL: bug-invalid-code-when-bailout 

Difference in forget and non-forget results. 

Expected result: { 

"kind": "ok", 

"value": "{}", 

"logs": [] 

} 

Found: { 

"kind": "exception", 

"value": "Cannot access 'bar' before initialization", 

"logs": [ 

"'The above error occurred in one of your React components:\\n' +\n  '\\n' +\n  
'    at globalThis.WrapperTestComponent 
(/Users/feifei0/fb/react-forget/packages/sprout/dist/runner-evaluator.js:30:26)\\n' 
+\n  '\\n' +\n  'Consider adding an error boundary to your tree to customize 
error handling behavior.\\n' +\n  'Visit 
https://reactjs.org/link/error-boundaries to learn more about error 
boundaries.'" 

] 

} 

```
2023-11-21 09:06:15 -06:00
Mofei Zhang
bfefbf3fce [repro] dce bug for JSX memberexpr tags in lambda 2023-11-21 09:06:14 -06:00
Jack Pope
bbb9cb116d Update fork for ReactSharedInternalsClient export (#27717)
## Summary

After changes in https://github.com/facebook/react/pull/27436, UMD
builds no longer expose Scheduler from ReactSharedInternals. This module
is forked in rollup for UMD builds and the path no longer matches. This
PR updates the path name to match the new module:
ReactSharedInternalsClient.

## How did you test this change?

- `yarn build`
- Inspect `react.development.js` UMD build, observe `Scheduler:
Scheduler` is set in `ReactSharedInternals`, matching
[18.2.0](https://unpkg.com/react@18.2.0/umd/react.development.js)
- ran attribute-behavior fixture app
- Observe no more error `Uncaught (in promise) TypeError: Cannot read
properties of undefined (reading 'unstable_cancelCallback')`

Co-authored-by: Jack Pope <jackpope@meta.com>
2023-11-17 09:00:56 -05:00
Joe Savona
8176ebb546 BuildHIR lowers FunctionDecl instead of rewriting to FuncExpr
We were modifying the Babel AST as a shortcut to lowering function declarations, 
instead we can explicitly lower them equivalently to a `let <id> = 
<function-expression>`.
2023-11-16 15:41:19 -08:00
Lauren Tan
a1e3891189 [rfc][babel] InvalidConfig always throws
When you have your panic threshold set to "NONE" as we recommend, it's easy to 
miss that your config is wrong (which makes everything not compile) because 
those errors were being silenced. This made debugging FluentUI and the 
forget-feedback testapp pretty difficult to figure out at first, and defeats the 
purpose of having config validation in the first place. 

This pr makes it so InvalidConfig errors always throw, regardless of the panic 
threshold set. In general our plugin should never throw at build time due to 
component bailouts, but because an InvalidConfig would bailout everything from 
being compiled at all, it seems reasonable to throw here
2023-11-17 12:01:20 -05:00
Lauren Tan
6d101435d4 [Babel] Fix up eslint suppression logic
Babel doesn't attach Comment nodes to anything, so they dangle off of 

the Program node while only specifying a range. This meant that 

previously we first had to traverse all of the Program's comments to 

find an eslint suppression of the rules of React, then during traversal 

of the individual functions, we would check if there were any *global* 

eslint suppressions, then bailout all components. 

This PR updates our logic to determine if individual functions are 

affected by an eslint suppression range: 

- If an eslint suppression range falls within its body; or 

- If an eslint suppression wraps the function
2023-11-17 10:22:46 -05:00
Lauren Tan
fbcc21c37a Add repro for bug with 'use no forget'
For some reason, when there are other hooks/components defined in the file, the 
'use no forget' directive stops working
2023-11-17 10:22:45 -05:00
Mofei Zhang
96f10e058b [be][tests] Change fixtures to evaluate successfully instead of throwing
--- 

Not dependent on changes from #2366, but now the fix is easy to review
2023-11-16 18:12:00 -05:00
Mofei Zhang
66748b00f2 [be][sprout] Snapshot files for sprout with shared utils
--- 

16 out of ~150 recently added sprout fixtures have exceptions that reflect 
easy-to-miss mistakes in the fixture input, like forgetting to import 
`useState`. 

This PR adds snapshot files for sprout to prevent these mistakes (or catch them 
at diff review time). This describes what it implements, but happy to take other 
suggestions as well! 

1. One sprout snapshot file for each input. 

This significantly increases the number of files we have, but makes it clear 
what the fixture is testing. I was hoping to expand on these snapshots to record 
the result of multiple re-renders, or mounts (with different parameters), but 
the tradeoff is that adding / changing fixtures will now require running `yarn 
sprout --mode update`. 

Some alternatives I've considered: 

- Only record snapshots for fixtures that error (`result.kind == "exception"`). 
This change would be pretty easy. This doesn't help sanity check sprout results 
for general mistakes though ("am I testing what I want to test?) 

- Warn loudly for fixtures that error -- seems like these are easy to ignore, 
but.. worth it for the convenience? 

- Some github action that runs and comments on your PR with sprout fixture 
changes; i.e. never manually update sprout files? 

2. Sprout and snap share a common snapshot file, with some parsing hackery. 

Previously, the implementation added new files to a separate sprout snapshot 
directory, assuming that devs don't need to read these often. 

After feedback from @josephsavona, I updated to have snap and sprout write to 
the same file for ease of reviewing / debugging (to be able to see the input / 
output side by side). 

- `snap --mode update` will update snap's part of the file. 

- `sprout --mode update` will update sprout's part 

- `snap` and `sprout` will both compare oldSnapshot (read from the file) with 
`newSnapshot = merge(oldSnapshot, newData)` to determine if a test pass. 

3. Some hacks 😅 Absolute paths to project directory (e.g. stack traces) are 
replaced with `<project_root>` in a mocked `console.log`
2023-11-16 18:12:00 -05:00
Mofei Zhang
fa07eb0b3b [be] make evaluator and worker easier to debug in sprout
--- 

jsdom and other libraries seem to cause jest workers to exit with 
`forceExit:true`. Not sure what option I set (or global I've overwritten) but 
console logs aren't flushed as a result, making debugging a bit confusing. 

This PR: 

- Moves some code from `eval(...)` to a typechecked real js function. I always 
had trouble debugging the `eval`ed code, so smaller code snippet is better here. 

- waits for jest workers to end before exiting
2023-11-16 18:12:00 -05:00
Jan Kassens
1a65d036ef [cleanup] remove enableHostSingletons feature flag (#27583)
The flag is enabled everywhere, I think we can remove it now.
2023-11-16 17:42:03 -05:00
dependabot[bot]
0de5b11485 Bump @babel/traverse from 7.14.2 to 7.23.3 in /fixtures/ssr2 (#27713)
Bumps
[@babel/traverse](https://github.com/babel/babel/tree/HEAD/packages/babel-traverse)
from 7.14.2 to 7.23.3.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a
href="https://github.com/babel/babel/releases"><code>@​babel/traverse</code>'s
releases</a>.</em></p>
<blockquote>
<h2>v7.23.3 (2023-11-09)</h2>
<h4>🐛 Bug Fix</h4>
<ul>
<li><code>babel-plugin-transform-typescript</code>
<ul>
<li><a
href="https://redirect.github.com/babel/babel/pull/16071">#16071</a>
Strip type-only TS namespaces (<a
href="https://github.com/colinaaa"><code>@​colinaaa</code></a>)</li>
</ul>
</li>
<li><code>babel-generator</code>
<ul>
<li><a
href="https://redirect.github.com/babel/babel/pull/16078">#16078</a> Fix
indentation when generating comments with <code>concise: true</code> (<a
href="https://github.com/liuxingbaoyu"><code>@​liuxingbaoyu</code></a>)</li>
</ul>
</li>
<li><code>babel-compat-data</code>,
<code>babel-plugin-bugfix-v8-static-class-fields-redefine-readonly</code>,
<code>babel-preset-env</code>
<ul>
<li><a
href="https://redirect.github.com/babel/babel/pull/14295">#14295</a> Add
a bugfix plugin for <a
href="https://crbug.com/v8/12421">https://crbug.com/v8/12421</a> (<a
href="https://github.com/nicolo-ribaudo"><code>@​nicolo-ribaudo</code></a>)</li>
</ul>
</li>
<li><code>babel-plugin-transform-object-super</code>
<ul>
<li><a
href="https://redirect.github.com/babel/babel/pull/15948">#15948</a>
fix: <code>super.x</code> in a loop (<a
href="https://github.com/liuxingbaoyu"><code>@​liuxingbaoyu</code></a>)</li>
</ul>
</li>
<li><code>babel-helper-module-transforms</code>,
<code>babel-plugin-transform-modules-amd</code>,
<code>babel-plugin-transform-modules-commonjs</code>,
<code>babel-plugin-transform-modules-umd</code>
<ul>
<li><a
href="https://redirect.github.com/babel/babel/pull/16015">#16015</a>
fix: handle <code>__proto__</code> exports name in CJS/AMD/UMD (<a
href="https://github.com/magic-akari"><code>@​magic-akari</code></a>)</li>
</ul>
</li>
</ul>
<h4>📝 Documentation</h4>
<ul>
<li><a
href="https://redirect.github.com/babel/babel/pull/16044">#16044</a>
docs: Update links in <code>@​babel/eslint-parser</code> README (<a
href="https://github.com/aryehb"><code>@​aryehb</code></a>)</li>
</ul>
<h4>🏠 Internal</h4>
<ul>
<li><code>babel-core</code>, <code>babel-preset-env</code>
<ul>
<li><a
href="https://redirect.github.com/babel/babel/pull/15988">#15988</a>
Refactor handling of modules plugins in <code>preset-env</code> (<a
href="https://github.com/nicolo-ribaudo"><code>@​nicolo-ribaudo</code></a>)</li>
</ul>
</li>
</ul>
<h4>🏃‍♀️ Performance</h4>
<ul>
<li><code>babel-generator</code>
<ul>
<li><a
href="https://redirect.github.com/babel/babel/pull/16061">#16061</a>
perf: Improve <code>@babel/generator</code> performance (<a
href="https://github.com/liuxingbaoyu"><code>@​liuxingbaoyu</code></a>)</li>
</ul>
</li>
<li><code>babel-traverse</code>
<ul>
<li><a
href="https://redirect.github.com/babel/babel/pull/16060">#16060</a>
Avoid dynamic dispatch when calling wrapCheck (<a
href="https://github.com/yepitschunked"><code>@​yepitschunked</code></a>)</li>
</ul>
</li>
</ul>
<h4>🔬 Output optimization</h4>
<ul>
<li><code>babel-plugin-transform-computed-properties</code>
<ul>
<li><a
href="https://redirect.github.com/babel/babel/pull/6652">#6652</a>
Optimize computed properties output (byte-wise) (<a
href="https://github.com/Andarist"><code>@​Andarist</code></a>)</li>
</ul>
</li>
</ul>
<h4>Committers: 9</h4>
<ul>
<li>Babel Bot (<a
href="https://github.com/babel-bot"><code>@​babel-bot</code></a>)</li>
<li>Colin (<a
href="https://github.com/colinaaa"><code>@​colinaaa</code></a>)</li>
<li>Huáng Jùnliàng (<a
href="https://github.com/JLHwung"><code>@​JLHwung</code></a>)</li>
<li>Mateusz Burzyński (<a
href="https://github.com/Andarist"><code>@​Andarist</code></a>)</li>
<li>Nicolò Ribaudo (<a
href="https://github.com/nicolo-ribaudo"><code>@​nicolo-ribaudo</code></a>)</li>
<li><a href="https://github.com/aryehb"><code>@​aryehb</code></a></li>
<li><a
href="https://github.com/liuxingbaoyu"><code>@​liuxingbaoyu</code></a></li>
<li><a
href="https://github.com/magic-akari"><code>@​magic-akari</code></a></li>
<li><a
href="https://github.com/yepitschunked"><code>@​yepitschunked</code></a></li>
</ul>
<h2>v7.23.2 (2023-10-11)</h2>
<p><strong>NOTE</strong>: This release also re-publishes
<code>@babel/core</code>, even if it does not appear in the linked
release commit.</p>
<p>Thanks <a
href="https://github.com/jimmydief"><code>@​jimmydief</code></a> for
your first PR!</p>
<h4>🐛 Bug Fix</h4>
<ul>
<li><code>babel-traverse</code></li>
</ul>
<!-- raw HTML omitted -->
</blockquote>
<p>... (truncated)</p>
</details>
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a
href="https://github.com/babel/babel/blob/main/CHANGELOG.md"><code>@​babel/traverse</code>'s
changelog</a>.</em></p>
<blockquote>
<h2>v7.23.3 (2023-11-09)</h2>
<h4>🐛 Bug Fix</h4>
<ul>
<li><code>babel-plugin-transform-typescript</code>
<ul>
<li><a
href="https://redirect.github.com/babel/babel/pull/16071">#16071</a>
Strip type-only TS namespaces (<a
href="https://github.com/colinaaa"><code>@​colinaaa</code></a>)</li>
</ul>
</li>
<li><code>babel-generator</code>
<ul>
<li><a
href="https://redirect.github.com/babel/babel/pull/16078">#16078</a> Fix
indentation when generating comments with <code>concise: true</code> (<a
href="https://github.com/liuxingbaoyu"><code>@​liuxingbaoyu</code></a>)</li>
</ul>
</li>
<li><code>babel-compat-data</code>,
<code>babel-plugin-bugfix-v8-static-class-fields-redefine-readonly</code>,
<code>babel-preset-env</code>
<ul>
<li><a
href="https://redirect.github.com/babel/babel/pull/14295">#14295</a> Add
a bugfix plugin for <a
href="https://crbug.com/v8/12421">https://crbug.com/v8/12421</a> (<a
href="https://github.com/nicolo-ribaudo"><code>@​nicolo-ribaudo</code></a>)</li>
</ul>
</li>
<li><code>babel-plugin-transform-object-super</code>
<ul>
<li><a
href="https://redirect.github.com/babel/babel/pull/15948">#15948</a>
fix: <code>super.x</code> in a loop (<a
href="https://github.com/liuxingbaoyu"><code>@​liuxingbaoyu</code></a>)</li>
</ul>
</li>
<li><code>babel-helper-module-transforms</code>,
<code>babel-plugin-transform-modules-amd</code>,
<code>babel-plugin-transform-modules-commonjs</code>,
<code>babel-plugin-transform-modules-umd</code>
<ul>
<li><a
href="https://redirect.github.com/babel/babel/pull/16015">#16015</a>
fix: handle <code>__proto__</code> exports name in CJS/AMD/UMD (<a
href="https://github.com/magic-akari"><code>@​magic-akari</code></a>)</li>
</ul>
</li>
</ul>
<h4>📝 Documentation</h4>
<ul>
<li><a
href="https://redirect.github.com/babel/babel/pull/16044">#16044</a>
docs: Update links in <code>@​babel/eslint-parser</code> README (<a
href="https://github.com/aryehb"><code>@​aryehb</code></a>)</li>
</ul>
<h4>🏠 Internal</h4>
<ul>
<li><code>babel-core</code>, <code>babel-preset-env</code>
<ul>
<li><a
href="https://redirect.github.com/babel/babel/pull/15988">#15988</a>
Refactor handling of modules plugins in <code>preset-env</code> (<a
href="https://github.com/nicolo-ribaudo"><code>@​nicolo-ribaudo</code></a>)</li>
</ul>
</li>
</ul>
<h4>🏃‍♀️ Performance</h4>
<ul>
<li><code>babel-generator</code>
<ul>
<li><a
href="https://redirect.github.com/babel/babel/pull/16061">#16061</a>
perf: Improve <code>@babel/generator</code> performance (<a
href="https://github.com/liuxingbaoyu"><code>@​liuxingbaoyu</code></a>)</li>
</ul>
</li>
<li><code>babel-traverse</code>
<ul>
<li><a
href="https://redirect.github.com/babel/babel/pull/16060">#16060</a>
Avoid dynamic dispatch when calling wrapCheck (<a
href="https://github.com/yepitschunked"><code>@​yepitschunked</code></a>)</li>
</ul>
</li>
</ul>
<h4>🔬 Output optimization</h4>
<ul>
<li><code>babel-plugin-transform-computed-properties</code>
<ul>
<li><a
href="https://redirect.github.com/babel/babel/pull/6652">#6652</a>
Optimize computed properties output (byte-wise) (<a
href="https://github.com/Andarist"><code>@​Andarist</code></a>)</li>
</ul>
</li>
</ul>
<h2>v7.23.2 (2023-10-11)</h2>
<h4>🐛 Bug Fix</h4>
<ul>
<li><code>babel-traverse</code>
<ul>
<li><a
href="https://redirect.github.com/babel/babel/pull/16033">#16033</a>
Only evaluate own String/Number/Math methods (<a
href="https://github.com/nicolo-ribaudo"><code>@​nicolo-ribaudo</code></a>)</li>
</ul>
</li>
<li><code>babel-preset-typescript</code>
<ul>
<li><a
href="https://redirect.github.com/babel/babel/pull/16022">#16022</a>
Rewrite <code>.tsx</code> extension when using
<code>rewriteImportExtensions</code> (<a
href="https://github.com/jimmydief"><code>@​jimmydief</code></a>)</li>
</ul>
</li>
<li><code>babel-helpers</code>
<ul>
<li><a
href="https://redirect.github.com/babel/babel/pull/16017">#16017</a>
Fix: fallback to typeof when toString is applied to incompatible object
(<a href="https://github.com/JLHwung"><code>@​JLHwung</code></a>)</li>
</ul>
</li>
<li><code>babel-helpers</code>,
<code>babel-plugin-transform-modules-commonjs</code>,
<code>babel-runtime-corejs2</code>, <code>babel-runtime-corejs3</code>,
<code>babel-runtime</code>
<ul>
<li><a
href="https://redirect.github.com/babel/babel/pull/16025">#16025</a>
Avoid override mistake in namespace imports (<a
href="https://github.com/nicolo-ribaudo"><code>@​nicolo-ribaudo</code></a>)</li>
</ul>
</li>
</ul>
<h2>v7.23.0 (2023-09-25)</h2>
<h4>🚀 New Feature</h4>
<ul>
<li><code>babel-plugin-proposal-import-wasm-source</code>,
<code>babel-plugin-syntax-import-source</code>,
<code>babel-plugin-transform-dynamic-import</code>
<ul>
<li><a
href="https://redirect.github.com/babel/babel/pull/15870">#15870</a>
Support transforming <code>import source</code> for wasm (<a
href="https://github.com/nicolo-ribaudo"><code>@​nicolo-ribaudo</code></a>)</li>
</ul>
</li>
<li><code>babel-helper-module-transforms</code>,
<code>babel-helpers</code>,
<code>babel-plugin-proposal-import-defer</code>,
<code>babel-plugin-syntax-import-defer</code>,
<code>babel-plugin-transform-modules-commonjs</code>,
<code>babel-runtime-corejs2</code>, <code>babel-runtime-corejs3</code>,
<code>babel-runtime</code>, <code>babel-standalone</code>
<ul>
<li><a
href="https://redirect.github.com/babel/babel/pull/15878">#15878</a>
Implement <code>import defer</code> proposal transform support (<a
href="https://github.com/nicolo-ribaudo"><code>@​nicolo-ribaudo</code></a>)</li>
</ul>
</li>
<li><code>babel-generator</code>, <code>babel-parser</code>,
<code>babel-types</code>
<ul>
<li><a
href="https://redirect.github.com/babel/babel/pull/15845">#15845</a>
Implement <code>import defer</code> parsing support (<a
href="https://github.com/nicolo-ribaudo"><code>@​nicolo-ribaudo</code></a>)</li>
</ul>
</li>
</ul>
<!-- raw HTML omitted -->
</blockquote>
<p>... (truncated)</p>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="1bce5c9d51"><code>1bce5c9</code></a>
v7.23.3</li>
<li><a
href="4fb4fa63e7"><code>4fb4fa6</code></a>
Avoid dynamic dispatch when calling wrapCheck (<a
href="https://github.com/babel/babel/tree/HEAD/packages/babel-traverse/issues/16060">#16060</a>)</li>
<li><a
href="6d9725cd62"><code>6d9725c</code></a>
[babel 8] Inline <code>toSequenceExpression</code> into
<code>@babel/traverse</code> (<a
href="https://github.com/babel/babel/tree/HEAD/packages/babel-traverse/issues/16057">#16057</a>)</li>
<li><a
href="b4b9942a6c"><code>b4b9942</code></a>
v7.23.2</li>
<li><a
href="b13376b346"><code>b13376b</code></a>
Only evaluate own String/Number/Math methods (<a
href="https://github.com/babel/babel/tree/HEAD/packages/babel-traverse/issues/16033">#16033</a>)</li>
<li><a
href="ca58ec15cb"><code>ca58ec1</code></a>
v7.23.0</li>
<li><a
href="0f333dafcf"><code>0f333da</code></a>
Add <code>createImportExpressions</code> parser option (<a
href="https://github.com/babel/babel/tree/HEAD/packages/babel-traverse/issues/15682">#15682</a>)</li>
<li><a
href="3744545649"><code>3744545</code></a>
Fix linting</li>
<li><a
href="c7e6806e21"><code>c7e6806</code></a>
Add <code>t.buildUndefinedNode</code> (<a
href="https://github.com/babel/babel/tree/HEAD/packages/babel-traverse/issues/15893">#15893</a>)</li>
<li><a
href="38ee8b4dd6"><code>38ee8b4</code></a>
Expand evaluation of global built-ins in <code>@babel/traverse</code>
(<a
href="https://github.com/babel/babel/tree/HEAD/packages/babel-traverse/issues/15797">#15797</a>)</li>
<li>Additional commits viewable in <a
href="https://github.com/babel/babel/commits/v7.23.3/packages/babel-traverse">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=@babel/traverse&package-manager=npm_and_yarn&previous-version=7.14.2&new-version=7.23.3)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)
You can disable automated security fix PRs for this repo from the
[Security Alerts
page](https://github.com/facebook/react/network/alerts).

</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-11-16 14:08:02 -05:00
Joe Savona
94348be2d9 Enable ValidateNoSetStateInRender in ESLint plugin
Same as previous: this rule is working accurately with no false positives, let's 
enable it.
2023-11-16 07:52:13 -08:00
PrathamLalwani
2c338b16fd Added windows powershell syntax to build scripts (#27692)
## Summary

I had to change the commands to be windows specific so that it doesn't
cause any crashes

## How did you test this change?

I successfully built the different types of devtools extenstions on my
personal computer. In future may need to add a github action with
windows config to test these errors

 #27193
2023-11-16 11:35:43 +00:00
Joe Savona
7b6b370638 Consolidate ValidateNoSetStateInRender flags
I ran the plugin with the extended version of ValidateNoSetStateInRender enabled 
(incl. function expressions) and there are no false positives. Let's remove the 
flag for the function expression case since the whole rule is working 
accurately.
2023-11-15 13:05:24 -08:00
Joe Savona
6a1343c82b Repro of undefined expressioncontainer expression
Repro from T169063835. This works, but since it came up it seems good to add a 
test case for it just in case there's something funny here that we could regress 
on w/o realizing it.
2023-11-15 14:23:53 -08:00
Joe Savona
df42058237 Fix variable-resolution hoisting issues
Fixes one category of bugs with const hoisting. The algorithm finds all consts 
that need to be hoisted, then looks through the statements of a block to find 
the first statement which references that const, delaying the emission of the 
HoistedConst instruction until its actually used. To determine if a statement 
references a const we find every identifier in the statement and check if its 
binding is one of the hoisted bindings. 

There's a very small bug here: when we resolve the binding of each identifier, 
we need to resolve it in its own scope. We're currently resolving these 
identifiers agains the outer block statement's scope, which can cause us to 
misattribute identifiers when there is shadowing: 

``` 

const items = props.items.map(x => x); // we scan this statement, resolve 'x' in 
the block statement scope, and mis-attribute it to the outer x. 

const x = 42; // (1) this x is a candidate for hoisting, so the binding is in 
the set of hoisted consts 

```
2023-11-15 16:55:01 -08:00
Joe Savona
b55ccb1b84 Repro for hoisting bug
I had added a repro for this earlier but hadn't realized it was due to const 
hoisting. Renaming this test to clarify what's causing the problem and to make 
it easier to find.
2023-11-15 16:34:28 -08:00
Sathya Gunasekaran
eacf189eca [playground] Remove button from error message
We show the entire error in panel, no need to click to console.log 

This makes it easier to copy the error now. 

Before: 


https://github.com/facebook/react-forget/assets/565765/4c13abfe-a06d-4580-b3d7-b02792f53e57 

After: 


https://github.com/facebook/react-forget/assets/565765/0dff95cc-5207-48a5-a0b6-2055cadcb780
2023-11-16 12:01:59 +00:00
Josh Story
ee68446ff1 [Fizz] handle errors in onHeaders (#27712)
`onHeaders` can throw however for now we can assume that headers are
optimistic values since the only things we produce for them are preload
links. This is a pragmatic decision because React could concievably have
headers in the future which were not optimistic and thus non-optional
however it is hard to imagine what these headers might be in practice.
If we need to change this behavior to be fatal in the future it would be
a breaking change.

This commit adds error logging when `onHeaders` throws and ensures the
request can continue to render successfully.
2023-11-15 12:53:38 -08:00
Sathya Gunasekaran
369c315ac4 [hir] Update error message to say global
This is non ideal but at least it's a step in the right direction. 

Getting the correct error requires us to track every identifier and global, 
which seems a bit excessive for now. 

We can revisit and improve this error if this is starting to confuse folks.
2023-11-15 17:03:55 +00:00
Sathya Gunasekaran
392a4fd9da [test] Add tests for mutating a global
The error is thrown correctly but the error message is incorrect.
2023-11-15 17:03:51 +00:00
Sathya Gunasekaran
306fe03e78 [printer] Print function name if available 2023-11-15 09:36:32 +00:00
Sathya Gunasekaran
58947d9075 [babel] Rename isReactFunction to isReactAPI
Disambiguates better between this and the existing `isReactFunctionLike` 
function.
2023-11-15 09:36:31 +00:00
Joe Savona
696434fed8 Fix ValidateNoSetStateInRender for loops 2023-11-14 11:33:39 -08:00
Ruslan Lesiutin
aec521a96d fix[devtools/useMemoCache]: implement a working copy of useMemoCache (#27659)
In https://github.com/facebook/react/pull/27472 I've removed broken
`useMemoCache` implementation and replaced it with a stub. It actually
produces errors when trying to inspect components, which are compiled
with Forget.

The main difference from the implementation in
https://github.com/facebook/react/pull/26696 is that we are using
corresponding `Fiber` here, which has patched `updateQueue` with
`memoCache`. Previously we would check it on a hook object, which
doesn't have `updateQueue`.

Tested on pages, which are using Forget and by inspecting elements,
which are transpiled with Forget.
2023-11-14 18:23:39 +00:00
Mofei Zhang
c434ef4b70 [validation] Patch false positives for hook calls after loops
--- 

We were throwing `InvalidReact` errors on valid inputs. 

```js 

// Input 

function Foo() { 

log("block0"); 

for (const _ of foo) { 

log("loop"); 

} 

useBar(); 

} 

// IR 

bb0: 

// log("block0"); 

ForOf init=bb2 loop=bb3 fallthrough=bb1 

bb2: 

// init 

Branch: then:bb3 else:bb1 

bb3: 

// log("loop") 

Goto(Continue) bb2 

bb1: 

// useBar(); 

Return 

``` 

We correctly compute post dominators here. 

```js 

// In validateUnconditionalHooks 

console.log(dominators.debug()); 

/* Output: 

(read x => y as x is the post-dominator for y (all paths from x to the exit must 
go through y)) 

"bb4" => "bb4", 

"bb1" => "bb4", 

"bb2" => "bb1", 

"bb3" => "bb2", 

"bb0" => "bb2", 

*/ 

``` 

However, `findBlocksWithBackEdges` prevented us from adding `bb1` to the 
`unconditionalBlocks` set as `bb2` (its post dominator) has a back edge. I'm not 
sure what the `findBlocksWithBackEdges` was doing previously, so I replaced it 
with an invariant asserting that the loop terminates.
2023-11-14 13:04:31 -05:00
Mofei Zhang
00abc5acf5 [be][tests] Run todo fixtures
--- 

Snap should compile all fixtures to record changes in results, even `todo` 
prefixed ones. Previously, they were skipped as we noted the correlation of `// 
@skip` pragmas and file naming. 

Now, no fixture should be skipped as our compiler pipeline should be able to 
handle every kind of error.
2023-11-14 13:04:28 -05:00
Jan Kassens
593ecee66a Add a feature flag to enable expiration of retry lanes (#27694)
An attempt to see if we can bring back expiration of retry lanes to
avoid cases resolving Suspense can be starved by frequent updates.

In the past, this caused increase browser crashes, but a lot of time has
passed since then. Just trying if we can re-enable this.

Old PR that reverted adding the timeout:
https://github.com/facebook/react/pull/21300
2023-11-14 10:15:17 -05:00
Sathya Gunasekaran
2efd85f145 Convert CompilationModeScham to zod type 2023-11-14 11:46:26 +00:00
Sathya Gunasekaran
084e4325b9 Convert PanicThresholdOptions to zod type 2023-11-14 11:46:23 +00:00
Sathya Gunasekaran
0821a57fa8 [playground] Capture Babel parsing errors
Before: 

<img width="1416" alt="Screenshot 2023-11-14 at 9 09 53 AM" 
src="https://github.com/facebook/react-forget/assets/565765/f53daf34-080a-4804-9a61-77c141c05d21"> 

After: 

<img width="1444" alt="Screenshot 2023-11-14 at 9 09 45 AM" 
src="https://github.com/facebook/react-forget/assets/565765/8861c266-9a49-4ff7-99cd-7240ca1750b1">
2023-11-14 18:24:38 +00:00
Sathya Gunasekaran
07d6c6d8aa [playground] Show error when compiling unsupported functions
Before: 

<img width="1117" alt="Screenshot 2023-11-14 at 9 11 28 AM" 
src="https://github.com/facebook/react-forget/assets/565765/d1ec2b5f-1bc5-4d29-9811-effcd39581e4"> 

After: 

<img width="1115" alt="Screenshot 2023-11-14 at 9 11 18 AM" 
src="https://github.com/facebook/react-forget/assets/565765/9a41889c-cf7b-4f31-8b6e-e26bfb204883">
2023-11-14 09:10:31 +00:00
Sathya Gunasekaran
0794aacdbf Turn off validateNoSetStateInRender in babel-plugin
There's false positives that we found in the Eslint plugin
2023-11-14 16:59:10 +00:00
Sathya Gunasekaran
1641f94a86 [eslint] Turn off validations
We're seeing false positives
2023-11-14 16:59:09 +00:00
Sebastian Markbåge
07cc4a0002 [Flight] Bound server references should be able to be bound again (#27695)
Wasn't consistent. Probably should use a shared helper maybe.
2023-11-13 22:45:40 -05:00
Sathya Gunasekaran
3da32312e7 [globals] type useEffect return value as primitive
useEffect returns undefined
2023-11-13 10:51:08 +00:00
Lauren Tan
480c11bdb1 [hoisting] Make hoisting related errors consolidatable
Noticed from our paste that we weren't correctly rolling up hoisting related 
errors due to specific information being in the error title, so this PR moves 
them into description instead.
2023-11-13 16:54:54 -05:00
Joe Savona
800b874ed1 fix main
Forgot to update snapshots when addressing PR feedback.
2023-11-13 13:14:27 -08:00
Joe Savona
e6c5c9a005 Improve NoSetStateInRender function expression check
Updates the approach used in ValidateNoSetStateInRender to detect function 
expressions called during render. We now do the following: 

* Track function expression which are known to unconditionally call setState 
themselves- if these functions get called, that’s equivalent to calling 
setState. We call the validation recursively to compute this. 

* Track LoadLocal/StoreLocal indirections for such function expressions. 

* Check CallExpressions where the callee is either a known SetState (via type 
info) _or_ (new) where the callee is in the set of known-to-setState function 
expressions. 

The Set is shared throughout the analysis, so we can even find multiple levels 
of indirection (see new test case).
2023-11-13 11:28:16 -08:00
Joe Savona
dcbdf06491 Extra test case related to memoization "within" freeze
I found an interesting edge case in the previous diff with mutation of a value 
that appears in the expression of an object key: 

```javascript 

const key = {} 

const object = { 

[mutateAndReturnOtherValue(key)]: 42, 

}; 

mutate(key); 

``` 

We analyze and represent this correctly all the way through to codegen, but then 
we hit the bug that @mofeiZ has noticed before: the temporary for `t = 
mutateAndReturnOtherValue(key)` isn't emitted immediately (bc its a temporary). 
It gets emitted inside the memo block for `object`, which is incorrect. 

I tried to reproduce that here with JSX and it works as expected. It's an 
interesting case though so let's land this to ensure we don't regress.
2023-11-13 11:03:00 -08:00
Joe Savona
8d41529600 Support computed object keys 2023-11-13 09:55:52 -08:00
Mofei Zhang
f47685c602 [be] Flag and test for unexpected exceptions during compilations 2023-11-12 14:56:10 -05:00
Mofei Zhang
7db2388fff [be] tsconfig: useUnknownInCatchVariables 2023-11-12 14:44:15 -05:00
Joe Savona
3d2a05490f Update eslint plugin to enable more safe validations 2023-11-10 17:08:26 -08:00
Joe Savona
fc85f24865 Separate flag for ref access violation within function expressions
Adds a separate compiler flag for enabling the incomplete validation of ref 
access within function expressions. Unlike the previous PR for 
set-state-in-render validation, ref access in render can be okay in some 
circumstances so i'm leaving this off by default. The point of splitting this up 
is that our linting will be able to enable the rule without risk of false 
positives.
2023-11-10 17:07:21 -08:00
Joe Savona
6e038f9699 Partially enable validateNoSetStateInRender
The approach i initially took to validating function expressions was to try to 
extend the mutable range if they are called during render, and then use the 
mutable range of a function to determine if it's called during render later. 
However there are cases where the range can be extended for other reasons, as 
@poteto discovered, so we can't rely on the range extension. We've had several 
of our validations completely off as a result of this. 

In this PR i'm re-enabling @poteto's ValidateNoSetStateInRender pass by default, 
but making the function expression checking use a separate compiler flag. This 
means we'll have some false negatives, but should guarantee that we avoid false 
positives. This means we can definitely catch things like: 

``` 

const [state, setState] = useState(false); 

setState(true); 

``` 

Which we would have allowed by default before.
2023-11-10 16:52:29 -08:00
Mofei Zhang
c08b7be34e [be] Add comments for LoggerEvent type 2023-11-10 17:09:31 -05:00
Mofei Zhang
9965db70bd Revert "[babel] Remove unused PipelineError"
This reverts commit 10d129a8406e9d226abdb6943bf8512e34ce91db 

--- 

Reverts #2311 due to undocumented assumptions being broken. I also added some 
comments to `LoggerEvents` to explain each event type. 

In `Program.ts`, we have something like the following code. `compile` could 
produce any number of errors (not just expected errors / instances of 
`CompilerError`). As an example, we sometimes error in `Codegen` due to babel 
version incompatibilities (`Error: ObjectMethod: Too many arguments passed. 
Received 7 but can receive no more than 5`). 

```js 

try { 

// any error could be thrown here 

compile(input); 

} catch (e) { 

// unknown type for e 

handleError(e, ...); 

} 

```
2023-11-10 17:09:29 -05:00
Jan Kassens
432b9f1d97 Upgrade Flow to 0.221.0 (#27689)
Upgrades Flow and dependencies
```
yarn add -W flow-bin flow-remove-types hermes-parser hermes-eslint
```
2023-11-10 14:14:53 -05:00
Rubén Norte
6b3834a45b Guard against unmounted components when accessing public instances on Fabric (#27687)
## Summary

This fixes an error in `getPublicInstanceFromInstanceHandle` where we
throw an error when trying to access the public instance from the fiber
of an unmounted component. This shouldn't throw but return `null`
instead.

## How did you test this change?

Updated unit tests.
Before: 
<img width="969" alt="Screenshot 2023-11-10 at 15 26 14"
src="https://github.com/facebook/react/assets/117921/ea161616-2775-4fab-8d74-da4bef48d09a">

After: 
<img width="1148" alt="Screenshot 2023-11-10 at 15 28 37"
src="https://github.com/facebook/react/assets/117921/db18b918-b6b6-4925-9cfc-3b4b2f3ab92d">
2023-11-10 15:49:07 +00:00
mofeiZ
6a7f3aa858 [FeatureFlags] Enable useMemoCache for ReactTestRenderer (#27677)
## Summary
Forget compiled code currently cannot be tested with ReactTestRender as
`useMemoCache` is not being set on the dispatcher. This PR ensures that
projects can execute unit tests with Forget compilation in the test
build pipeline.

```js
// source code
function Component(props) {
  // ...
}

// transformed code, which also should be evaluated in unit tests
function Component(props) {
  const $ = useMemoCache(...);
  // ...
}
```

This PR enables the `enableUseMemoCacheHook` feature flag for all bundle
variations of ReactTestRenderer. Forget *should* be the only caller of
useMemoCache, so this should be a reversible change (in the event we
need to change the implementation or api of the hook).

## How did you test this change?
* Check that generated ReactTestRenderer bundles contain `useMemoCache`.
* Synced to Meta and checked that unit tests that use Forget +
@testing-library/react pass.

I did not add new tests to check that useMemoCache can be called when
using the test renderer as `useMemoCache` is not yet stable. Happy to
add a test case here if that would be helpful to reviewers though (I'm
guessing that would go in
`packages/react-test-renderer/src/__tests__/ReactTestRenderer-test.js` )
2023-11-10 10:31:38 -05:00
Jan Kassens
c4c87e049b Small cleanup in ReactFiberCompleteWork (#27681)
These are all functionally equivalent changes.

- remove double negation and more explicit naming of
`hadNoMutationsEffects`
- use docblock syntax that's consumed by Flow
- remove useless cast
2023-11-10 10:20:52 -05:00
Sebastian Markbåge
0e352ea01c [Fizz] Fix for failing id overwrites for postpone (#27684)
When we postpone during a render we inject a new segment synchronously
which we postpone. That gets assigned an ID so we can refer to it
immediately in the postponed state.

When we do that, the parent segment may complete later even though it's
also synchronous. If that ends up not having any content in it, it'll
inline into the child and that will override the child's segment id
which is not correct since it was already assigned one.

To fix this, we simply opt-out of the optimization in that case which is
unfortunate because we'll generate many more unnecessary empty segments.
So we should come up with a new strategy for segment id assignment but
this fixes the bug.

Co-authored-by: Josh Story <story@hey.com>
2023-11-09 22:52:31 -05:00
Ruslan Lesiutin
78c71bc545 refactor[ci/build]: dont generate sourcemaps for BROWSER_SCRIPT bundles (#27665)
Instead of https://github.com/facebook/react/pull/27664, we can just
exclude `unstable_server-external-runtime.js` from having sourcemaps for
now.

We should consider removing manual copying of this artifact in
52d542ad6d/.github/workflows/commit_artifacts.yml (L136-L138)


As described in https://github.com/facebook/react/pull/27664, this
artifact doesn't have any effect on the `hash`, which is used for
generating React version identifier.
2023-11-09 16:11:17 +00:00
Ruslan Lesiutin
c47c306a7a refactor[ci/build]: preserve header format in artifacts (#27671)
In order to make Haste work with React's artifacts, It is important to
keep headers in this format:
```
/**
* ...
...
* ...
*/
```

For optimization purposes, Closure compiler will actually modify these
headers by removing * prefixes, which is expected.
We should pass sources to the compiler without license headers, with
these changes the current flow will be:
1. Apply top-level definitions. For UMD-bundles, for example, or
DEV-only bundles (e. g. `if (__DEV__) { ...`)
2. Apply licence headers for artifacts with sourcemaps: oss-production
and oss-profiling bundles, they don't need to preserve the header format
to comply with Haste. We need to apply these headers before passing
sources to Closure, so it can build correct mappings for sourcemaps.
3. Pass these sources to closure compiler for minification and
sourcemaps building.
4. Apply licence headers for artifacts without sourcemaps: dev bundles,
fb bundles. This way the header style will be preserved and not changed
by Closure.
2023-11-09 16:00:21 +00:00
Jan Kassens
7bdd7cc2d8 Upgrade Flow to 0.220.1 (#27680)
Upgrade Flow to latest using
```
yarn add -W flow-bin flow-remove-types hermes-parser hermes-eslint
```

This also updates `createFlowConfigs.js` to get the Flow version from
`package.json` to avoid needing to bump the version there in the future.
2023-11-09 10:53:08 -05:00
Sathya Gunasekaran
bd3661020e Add test for bailouts skipping compilation 2023-11-09 12:00:37 +00:00
Sathya Gunasekaran
69eb9ccccc [snap] Add option to set panicThreshold 2023-11-09 12:00:34 +00:00
Joe Savona
f92a058ca5 Codegen comments to explain output 2023-11-10 11:45:29 -08:00
Josh Story
7468903294 [Static][Fizz] bootstrap scripts should only emit once (#27674)
I introduced a bug in a recent change to how bootstrap scripts are
handled. Rather than clearing out the bootstrap script state from
ResumableState on completion of the prerender I did it during the
flushing phase which comes later after the postponed state has likely
been serialized. We should freeze these objects in dev so this is not
possible to do easily in test (nor in actual code in real systems).

This fixes the bug by eliminating the bootstrap config during
getPostponedState which is before the state can be serialized.
2023-11-08 17:51:47 -08:00
Josh Story
7508dcd5cc [Static][Fizz] Carry forward bootstrap config to resume if postponing in the shell (#27672)
Previously it was possible to postpone in the shell during a prerender
and then during a resume the bootstrap scripts would not be emitted
leading to no hydration on the client. This change moves the bootstrap
configuration to `ResumableState` where it can be serialized after
postponing if it wasn't flushed as part of the static shell.
2023-11-08 10:43:38 -08:00
Karim Piyar Ali
88b00dec47 Update stack diffing algorithm in describeNativeComponentFrame (#27132)
## Summary

There's a bug with the existing stack comparison algorithm in
`describeNativeComponentFrame` — specifically how it attempts to find a
common root frame between the control and sample stacks. This PR
attempts to fix that bug by injecting a frame that can have a guaranteed
string in it for us to search for in both stacks to find a common root.

## Brief Background/How it works now

Right now `describeNativeComponentFrame` does the following to leverage
native browser/VM stack frames to get details (e.g. script path, row and
col #s) for a single component:
1. Throwing and catching a control error in the function
2. Calling the component which should eventually throw an error (most of
the time), that we'll catch as our sample error.
3. Diffing the stacks in the control and sample errors to find the line
which should represent our component call.

## What's broken

To account for potential stack trace truncation, the stack diffing
algorithm first attempts to find a common "root" frame by inspecting the
earliest frame of the sample stack and searching for an identical frame
in the control stack starting from the bottom. However, there are a
couple of scenarios which I've hit that cause the above approach to not
work correctly.

First, it's possible that for render passes of extremely large component
trees to have a lot of repeating internal react function calls, which
can result in an incorrect common or "root" frame found. Here's a small
example from a stack trace using React Fizz for SSR.
Our control frame can look like this:
```
Error:
    at Fake (...)
    at construct (native)
    at describeNativeComponentFrame (...)
    at describeClassComponentFrame (...)
    at getStackByComponentStackNode (...)
    at getCurrentStackInDEV (...)
    at renderNodeDestructive (...)
    at renderElement (...)
    at renderNodeDestructiveImpl (...) // <-- Actual common root frame with the sample stack
    at renderNodeDestructive (...)
    at renderElement (...)
    at renderNodeDestructiveImpl (...) // <-- Incorrectly chosen common root frame
    at renderNodeDestructive (...)
```

And our sample stack can look like this:
```
Error:
    at set (...)
    at PureComponent (...)
    at call (native)
    at apply (native)
    at ErrorBoundary (...)
    at construct (native)
    at describeNativeComponentFrame (...)
    at describeClassComponentFrame (...)
    at getStackByComponentStackNode (...)
    at getCurrentStackInDEV (...)
    at renderNodeDestructive (...)
    at renderElement (...)
    at renderNodeDestructiveImpl (...) // <-- Root frame that's common in the control stack
```

Here you can see that the earliest trace in the sample stack, the
`renderNodeDestructiveImpl` call, can exactly match with multiple
`renderNodeDestructiveImpl` calls in the control stack (including file
path and line + col #s). Currently the algorithm will chose the
earliest/last frame with the `renderNodeDestructiveImpl` call (which is
the second last frame in our control stack), which is incorrect. The
actual matching frame in the control stack is the latest or first frame
(when traversing from the top) with the `renderNodeDestructiveImpl`
call. This leads to the rest of the stack diffing associating an
incorrect frame (`at getStackByComponentStackNode (...)`) for the
component.

Another issue with this approach is that it assumes all VMs will
truncate stack traces at the *bottom*, [which isn't the case for the
Hermes
VM](df07cf713a/lib/VM/JSError.cpp (L688-L699))
which **truncates stack traces in the middle**, placing a

```
    at renderNodeDestructiveImpl (...)
    ... skipping {n} frames
    at renderNodeDestructive (...)
```

line in the middle of the stack trace for all stacks that contain more
than 100 traces. This causes stack traces for React Native apps using
the Hermes VM to potentially break for large component trees. Although
for this specific case with Hermes, it's possible to account for this by
either manually grepping and removing the `... skipping` line and
everything below it (see draft PR: #26999), or by implementing the
non-standard `prepareStackTrace` API which Hermes also supports to
manually generate a stack trace that truncates from the bottom ([example
implementation](https://github.com/facebook/react/compare/main...KarimP:react:component-stack-hermes-fix)).

## The Fix

I found different ways to go about fixing this. The first was to search
for a common stack frame starting from the top/latest frame. It's a
relatively small change ([see
implementation](https://github.com/facebook/react/compare/main...KarimP:react:component-stack-fix-2)),
although it is less performant by being n^2 (albeit with `n`
realistically being <= 5 here). It's also a bit more buggy for class
components given that different VMs insert a different amount of
additional lines for new/construct calls...

Another fix would be to actually implement a [longest common
substring](https://en.wikipedia.org/wiki/Longest_common_substring)
algorithm, which can also be roughly n^2 time (assuming the longest
common substring between control and sample will be most of the sample
frame).

The fix I ended up going with was have the lines that throw the control
error and the lines that call/instantiate the component be inside a
distinct method under an object property
(`"DescribeNativeComponentFrameRoot"`). All major VMs (Safari's
JavaScriptCore, Firefox's SpiderMonkey, V8, Hermes, and Bun) should
display the object property name their stack trace. I've also set the
`name` and `displayName` properties for method as well to account for
minification, any advanced optimizations (e.g. key crushing), and VM
inconsistencies (both Bun and Safari seem to exclusively use the value
under `displayName` and not `name` in traces for methods defined under
an object's own property...).

We can then find this "common" frame by simply finding the line that has
our special method name (`"DescribeNativeComponentFrameRoot"`), and the
rest of the code to determine the actual component line works as
expected. If by any chance we don't find a frame with our special method
name in either control or sample stack traces, we then revert back to
the existing approach mentioned above by searching for the last line of
the sample frame in the control frame.

## How did you test this change?

1. There are bunch of existing tests that ensure a properly formatted
component trace is logged for certain scenarios, so I ensured the
existing full test suite passed
2. I threw an error in a component that's deep in the component
hierarchy of a large React app (facebook) to ensure there's stack trace
truncation, and ensured the correct component stack trace was logged for
Chrome, Safari, and Firefox, and with and without minification.
3. Ran a large React app (facebook) on the Hermes VM, threw an error in
a component that's deep in the component hierarchy, and ensured that
component frames are generated despite stack traces being truncated in
the middle.
2023-11-08 11:45:31 -05:00
Tianyu Yao
52d542ad6d Enable enableUnifiedSyncLane (#27646)
<!--
  Thanks for submitting a pull request!
We appreciate you spending the time to work on these changes. Please
provide enough information so that others can review your pull request.
The three fields below are mandatory.

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

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

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

## Summary

<!--
Explain the **motivation** for making this change. What existing problem
does the pull request solve?
-->
The flag has been tested internally on WWW, should be good to set to
true for OSS. Added a dynamic flag for fb RN.

## 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.
-->
yarn test
2023-11-07 16:45:33 -08:00
Mark Erikson
2c8a139a59 Generate sourcemaps for production build artifacts (#26446)
<!--
  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

This PR updates the Rollup build pipeline to generate sourcemaps for
production build artifacts like `react-dom.production.min.js`.
 
It requires the Rollup v3 changes that were just merged in #26442 .

Sourcemaps are currently _only_ generated for build artifacts that are
_truly_ "production" - no sourcemaps will be generated for development,
profiling, UMD, or `shouldStayReadable` artifacts.

The generated sourcemaps contain the bundled source contents right
before that chunk was minified by Closure, and _not_ the original source
files like `react-reconciler/src/*`. This better reflects the actual
code that is running as part of the bundle, with all the feature flags
and transformations that were applied to the source files to generate
that bundle. The sourcemaps _do_ still show comments and original
function names, thus improving debuggability for production usage.

Fixes #20186 .




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

This allows React users to actually debug a readable version of the
React bundle in production scenarios. It also allows other tools like
[Replay](https://replay.io) to do a better job inspecting the React
source when stepping through.

## How did you test this change?

- Generated numerous sourcemaps with various combinations of the React
bundle selections
- Viewed those sourcemaps in
https://evanw.github.io/source-map-visualization/ and confirmed via the
visualization that the generated mappings appear to be correct

I've attached a set of production files + their sourcemaps here:


[react-sourcemap-examples.zip](https://github.com/facebook/react/files/11023466/react-sourcemap-examples.zip)

You can drag JS+sourcemap file pairs into
https://evanw.github.io/source-map-visualization/ for viewing.

Examples:

- `react.production.min.js`:


![image](https://user-images.githubusercontent.com/1128784/226478247-e5cbdee0-83fd-4a19-bcf1-09961d3c7da4.png)

- `react-dom.production.min.js`:


![image](https://user-images.githubusercontent.com/1128784/226478433-b5ccbf0f-8f68-42fe-9db9-9ecb97770d46.png)

- `use-sync-external-store/with-selector.production.min.js`:


![image](https://user-images.githubusercontent.com/1128784/226478565-bc74699d-db14-4c39-9e2d-b775f8755561.png)


<!--
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.
-->
2023-11-07 18:59:27 +00:00
Josh Story
2983249dd2 [Fizz] implement onHeaders and headersLengthHint options (#27641)
Adds a new option to `react-dom/server` entrypoints.

`onHeaders: (headers: Headers) => void` (non node envs)
`onHeaders: (headers: { Link?: string }) => void` (node envs)

When any `renderTo...` or `prerender...` function is called and this
option is provided the supplied function will be called sometime on or
before completion of the render with some preload link headers.

When provided during a `renderTo...` the callback will usually be called
after the first pass at work. The idea here is we want to get a set of
headers to start the browser loading well before the shell is ready. We
don't wait for the shell because if we did we may as well send the
preloads as tags in the HTML.

When provided during a `prerender...` the callback will be called after
the entire prerender is complete. The idea here is we are not responding
to a live request and it is preferable to capture as much as possible
for preloading as Headers in case the prerender was unable to finish the
shell.

Currently the following resources are always preloaded as headers when
the option is provided
1. prefetchDNS and preconnects
2. font preloads
3. high priority image preloads

Additionally if we are providing headers when the shell is incomplete
(regardless of whether it is render or prerender) we will also include
any stylesheet Resources (ones with a precedence prop)

There is a second option `maxHeadersLength?: number` which allows you to
specify the maximum length of the header content in unicode code units.
This is what you get when you read the length property of a string in
javascript. It's improtant to note that this is not the same as the
utf-8 byte length when these headers are serialized in a Response. The
utf8 representation may be the same size, or larger but it will never be
smaller.

If you do not supply a `maxHeadersLength` we defaul to `2000`. This was
chosen as half the value of the max headers length supported by commonly
known web servers and CDNs. many browser and web server can support
significantly more headers than this so you can use this option to
increase the headers limit. You can also of course use it to be even
more conservative. Again it is important to keep in mind there is no
direct translation between the max length and the bytelength and so if
you want to stay under a certain byte length you need to be potentially
more aggressive in the maxHeadersLength you choose.

Conceptually `onHeaders` could be called more than once as new headers
are discovered however if we haven't started flushing yet but since most
APIs for the server including the web standard Response only allow you
to set headers once the current implementation will only call it one
time
2023-11-07 10:16:33 -08:00
Ruslan Lesiutin
c897260cff refactor[react-devtools-shared]: minor parsing improvements and modifications (#27661)
Had these stashed for some time, it includes:
- Some refactoring to remove unnecessary `FlowFixMe`s and type castings
via `any`.
- Optimized version of parsing component names. We encode string names
to utf8 and then pass it serialized from backend to frontend in a single
array of numbers. Previously we would call `slice` to get the
corresponding encoded string as a subarray and then parse each
character. New implementation skips `slice` step and just receives
`left` and `right` ranges for the string to parse.
- Early `break` instead of `continue` when Store receives unexpected
operation, like removing an element from the Store, which is not
registered yet.
2023-11-07 16:39:34 +00:00
Jan Kassens
ce2bc58a9f [activity] rename unstable_Offscreen to unstable_Activity (#27640)
`Activity` is the current candidate name. This PR starts the rename work
by renaming the exported unstable component name.

NOTE: downstream consumers need to rename the import when updating to
this commit.
2023-11-02 16:13:21 -04:00
Noah Lemen
a17467e7e2 SchedulerPostTask: Reuse original TaskController (#27595)
## Summary

It's not clear to me why we currently create a new TaskController in
`runTask` – ultimately, we use the same signal and priority from the
original created in `unstable_scheduleCallback`

## How did you test this change?
```
yarn test SchedulerPostTask
```
2023-11-02 11:03:30 -04:00
Joe Savona
956c1ee7e2 Repro for bug with incorrectly using context variables when name overlaps 2023-11-01 17:42:14 -07:00
Joe Savona
ab0f698585 More tests for fbt whitespace handling
I experimented with more variations but prettier collapses most of them: any run 
of consecutive whitespace within a jsxtext node will get collapsed into a single 
space, for example. So the main difference in practice is whether a jsxtext node 
(preceding a value) has a trailing space/newline or not: 

``` 

Text <fbt:param /> Text 

// vs 

Text<fbt:param />Text 

``` 

which we now have tests for.
2023-11-10 11:21:10 -08:00
Joe Savona
127b5df7ca [be] Group fbt fixtures in directory 2023-11-10 11:21:07 -08:00
Joe Savona
6f2fe1e7e9 Fix FBT whitespace handling (again (again))
Nice find, @mofeiZ! I really tried to thoroughly test all the examples I could 
think of for FBT whitespace but i missed the newline case. Initially Mofei found 
[this code potentially related to whitespace 
handling](https://github.com/facebook/fbt/blob/main/packages/babel-plugin-fbt/src/fbt-nodes/FbtImplicitParamNode.js#L230-L233) 
but Babel never seems to produce consecutive JsxText nodes — this looks like 
maybe a leftover from older babel versions. 

I noticed that code wasn't actually trimming the whitspace but clearly it was 
happening somewhere, so i grepped for 'trim' and found that [this 
code](0b4e0d13c3/packages/babel-plugin-fbt/src/babel-processors/JSXFbtProcessor.js (L143)) 
calls a 
[normalizeSpaces](0b4e0d13c3/packages/babel-plugin-fbt/src/FbtUtil.js (L86C10-L86C45)) 
helper. Updating our logic to handle whitespace similarly just for children of 
fbt nodes produces the expected result.
2023-11-10 10:21:10 -08:00
Lauren Tan
82ed13b8b4 [eslint] Don't inline everything
Turns out this will cause an OOM in node.js when running eslint as part of the 
IDE 

``` Before: 16M   packages/eslint-plugin-react-forget/dist/index.js After:  2.2M 
 packages/eslint-plugin-react-forget/dist/index.js ```
2023-11-10 13:49:30 -05:00
Joe Savona
2927792dca Extra tests for #2339 2023-11-10 09:25:40 -08:00
Joe Savona
4742d27f9e [be] Clarify naming in scope merging pass
Anytime we have a nested `.scope` in code my brain hurts. For example 
`scope.scope.dependencies`. This PR updates the scope merging pass to use the 
name `scopeBlock` for a ReactiveScopeBlock and `scope` only for ReactiveScope 
values, to make things a bit more clear.
2023-11-09 16:33:41 -08:00
Joe Savona
691cad6b51 Optimization for scope merging when no deps
Addresses T168684688 (#2242). MergeReactiveScopesThatInvalidateTogether does not 
merge scopes if their output is not guaranteed to change when their inputs do. 
So for example a case such as `{session_id: bar(props.bar)}` will not merge the 
scopes for `t0 = bar(props.bar)` and `t1 = {session_id: t0}`, because t0 isn't 
guaranteed to change when `props.bar` does, and we want to avoid recreating the 
t1 object unless it semantically changes. 

But there's a special case: if a scope has no dependencies, then we'll never 
execute it again anyway. So it doesn't matter what kind of value it produces and 
it's safe to merge with subsequent scopes: 

```javascript 

return {session_id: bar()} 

``` 

Without the reactive input, `bar()` will always return the same value since 
we'll only ever call it once anyway. So it's safe to then merge with the scope 
for the outer object literal.
2023-11-09 16:21:00 -08:00
Sathya Gunasekaran
e35df45eaf Test component name access in gated setup
Jesse flagged this as a potential bug internally but this looks correct to me. 

Adding a test case so that we don't regress in the future.
2023-11-09 10:30:54 +00:00
Sathya Gunasekaran
cdf39e7956 [sprout] Add ReactForgetFeatureFlag 2023-11-09 10:30:52 +00:00
Mofei Zhang
6c327b0f3e [repro] Repro for fbt preserve whitespace bug
Current sprout output (if you remove the line in `SproutTodoFilter`): 

``` 

Failures: 

FAIL: bug-fbt-preserve-whitespace 

Difference in forget and non-forget results. 

Expected result: { 

"kind": "ok", 

"value": "Before text hello world", 

"logs": [] 

} 

Found: { 

"kind": "ok", 

"value": "Before texthello world", 

"logs": [] 

} 

``` 

`fbt` transforms run before jsx ones, so our lowering should also account for 
[fbt's whitespace 
rules](https://github.com/facebook/fbt/blob/main/packages/babel-plugin-fbt/src/fbt-nodes/FbtImplicitParamNode.js#L230-L233) 
in `BuildHIR:trimJsxText`.
2023-11-09 18:55:06 -05:00
Mofei Zhang
59ddf537ed [tests][fixtures] Enable sprout on basic existing fbt tests
--- 

Output: 

``` 

$ yarn sprout:build && yarn sprout --verbose 

... 

PASS  fbt-call-complex-param-value 

ok <div>Hello, Sathya!</div> 

PASS  fbt-call 

ok <div>2 items</div> 

PASS  fbt-template-string-same-scope 

ok <div>{"children":"for 3 experiences"}</div> 

... 

```
2023-11-09 18:55:05 -05:00
Mofei Zhang
372696c541 [sprout] Add support for fbt
Fbt + typescript [seems](https://github.com/facebook/fbt/issues/49) [to 
be](https://github.com/facebook/sfbt/issues/72) a non-blessed workflow. We do 
want to allow for both flow and typescript tests, so I followed some 
instructions [from a 
guide](https://dev.to/retyui/how-to-add-support-typescript-for-fbt-an-internationalization-framework-3lo0) 
to add support. 

- fbt tags desugar to.. "fbt" strings. By default, typescript removes unused 
imports at parse step (and on autoformat steps). We pass special 
babel-typescript configs and change vscode settings to mitigate this. 

- I tried adding `fbt` to the global scope, but the fbt transform asserts that 
`fbt` is actually imported in the source program. 

- Other hacks are available, like saying we'll only allow for fbt in flow files, 
or always patching the source code to have an "fbt" import. This seemed the most 
reasonable and easiest to debug / follow when writing tests
2023-11-09 18:55:05 -05:00
Mofei Zhang
b25c14feb1 [tests][be] Clean up fixture selection logic
--- 

Refactor selection logic to be easier to read; add support for .jsx test files 
(feels a bit weird adding a `.jsx` fixture and not seeing it get run)
2023-11-09 16:50:00 -05:00
Lauren Tan
2726484823 Add license to rolledup output 2023-11-09 13:00:13 -05:00
Lauren Tan
a6e492d8d0 [feedback] Add script to build packages for testapp
In order to make changes to the testapp's dependencies, we need to update the 
lockfile which means modules need to actually exist. This adds a new script to 
just run a build of the packages we sync so that module resolution in the 
testapp will work
2023-11-09 11:31:33 -05:00
Sathya Gunasekaran
f13594280b [ez] Use BabelFn type 2023-11-09 08:38:00 +00:00
Lauren Tan
bb92520ba5 Some existing InvalidConfig errors should be invariants
Now that we have validation of the compiler config, these old errors weren't 
categorized correctly. Readjusted them to be invariants instead.
2023-11-08 14:10:18 -05:00
Lauren Tan
973ec414bd [eslint] Try inlining everything in build 2023-11-08 15:19:07 -05:00
Sathya Gunasekaran
7aca04a0d6 [babel] Refactor handleError to pass the error first
Pass the most important and required argument as the first parameter.
2023-11-08 16:09:19 +00:00
Sathya Gunasekaran
4e7d437880 [babel] Remove unused PipelineError
Most of the use cases are already handled with ErrorSeverity.InvalidConfig
2023-11-08 16:09:18 +00:00
Sathya Gunasekaran
0beeb1e7ad Remove unncessary nullcheck 2023-11-08 16:09:18 +00:00
Sathya Gunasekaran
521f056875 Always clone DEFAULT_HOOKS
Reusing DEFAULT_HOOKS instance is a bit scary in case we mutate it by mistake 
and this gets reflected across all compiles. 

This isn't a concern now as we can't change the config during compilation. But 
this PR keeps us safe in case we change this behavior in the future. 

The tradeoff is a bit of perf which I think is the right tradeoff here.
2023-11-08 16:09:17 +00:00
Sathya Gunasekaran
ec089d5454 [test] Add test to make sure stringy enums are parsed correct
Meta internal config is going to be stringy, so let's add tests.
2023-11-08 16:09:16 +00:00
Sathya Gunasekaran
6d2fce8eb5 Make CustomHooks optional and add default value
Don't propogate nullability into the plugin.
2023-11-08 16:09:16 +00:00
Sathya Gunasekaran
8b12f179d3 Add tests to make sure our config validation error message doesn't regress 2023-11-08 16:09:15 +00:00
Sathya Gunasekaran
3f7b9e23e3 Don't allow null to be passed to validateEnvironmentConfig
zod will throw an error if we pass null, so let's not do this. 

Adding a temporary workaround until we start validating PluginOptions.
2023-11-08 16:09:14 +00:00
Sathya Gunasekaran
42497b60f5 [error] Prefix side-effecting function names with throw
I did a double take when I thought we didn't handle returning the 

error when reading the code and when I edited the code, typescript told 

me that there's no need to return as creating the error will throw. 

This PR makes it clear from the name of the function that we will throw.
2023-11-08 16:09:13 +00:00
Sathya Gunasekaran
33ffde4836 [playground] turn of ppr 2023-11-08 15:46:43 +00:00
Sathya Gunasekaran
6405c980eb Use starred-block for multi line comments 2023-11-08 08:27:41 +00:00
Sathya Gunasekaran
3d6d81052d [be] Upgrade Eslint to 8.27.0 2023-11-08 08:27:41 +00:00
Joe Savona
702aadd82b Fix to only add imports if we compiled something
We should only add imports if we actually compiled anything, this is what caused 
the internal issue despite the file in question not having any functions 
opted-in to compilation.
2023-11-07 16:22:03 -08:00
Joe Savona
64dffe9e78 repro for gating error despite no compiled functions 2023-11-07 16:09:29 -08:00
Lauren Tan
9d5ff320ba [babel] Fix default value for environment option
When an `environment` isn't explicitly provided by the user's config, we used to 
default this to `null` in `parsePluginOptions` which is called right at the 
start of the Babel plugin. These parsed options were then being passed to zod, 
which was expecting an object type, not null. 

Zod can reify a default config based on the schema, if an empty object is passed 
in. So by changing our default value to `{}` this should fix the compiler 
bailing out incorrectly on valid compiler options 

Test plan: tested this manually on the external repo by modifying node_modules
2023-11-07 18:58:21 -05:00
Sathya Gunasekaran
00cb557b12 Add runtime validation for EnvironmentConfig 2023-11-07 11:04:37 +00:00
Sathya Gunasekaran
1c53385db5 Don't plumb PartialEnvironmentConfig
Let's do validation at the API level and pass around the fully parsed config 
inside the plugin.
2023-11-07 11:04:37 +00:00
Sathya Gunasekaran
58a10c0ac1 [babel] Outline insertNewFunctionDeclaration
This lets us use the parsed and validated `gating` and `instrumentForget` 
options.
2023-11-07 11:04:36 +00:00
Sathya Gunasekaran
d8734b5136 Remove hasForgetMutatedOriginalSource
Derive it from compiledFns rather than duplicating state
2023-11-07 11:04:35 +00:00
Sathya Gunasekaran
bccd06a632 [babel] Simplify noEmit and hasCriticalError check 2023-11-07 11:04:35 +00:00
Sathya Gunasekaran
688305a978 Check if critical error before throwing 2023-11-07 11:04:34 +00:00
Sathya Gunasekaran
cf70ef899e Validate options before replacing with compiled function 2023-11-07 11:04:34 +00:00
Sathya Gunasekaran
d6ff65ecc7 Add runtime validation for ExternalFunction
Use zod to do runtime validation and throw if incorrect. 

This PR only adds validation for ExternalFunction, will validate other options 
in follow on PRs.
2023-11-07 11:04:33 +00:00
Joe Savona
337c17a66f More React API coverage
Redo of #2248 in its own stack
2023-11-06 16:27:11 -08:00
Joe Savona
72c27b6893 Feature flag for transitively freezing values
This PR adds a feature flag to model a potential new-in-practice rule in React: 
that freezing a function expression also freezes its closed-over values, 
transitively. For example, in the following code `data` is frozen when the 
lambda that captures it is is passed to useEffect: 

```javascript 

const data = []; 

// useEffect freezes its argument (the function expr), which transitively 
freezes its captured value data 

useEffect(() => { 

foo(data); 

}, [data]); 

data.push(true); // ERROR: mutating a frozen value 

mutate(data); // we conservatively assume this doesn't mutate but could be wrong 

``` 

Note that this rule has never been written down or enforced. It is theoretically 
equivalent to the rule (already implemented in Forget) that values captured by 
JSX are frozen: 

```javascript 

const style = {...}; 

<div style={style}>...</div> 

style.width = 10; // ERROR: mutating a frozen value 

mutate(style); // we conservatively assume this doesn't mutate but could be 
wrong 

``` 

However, JSX is typically constructed toward the very end of a render function. 
Thus in practice there isn't much subsequent code that could even modify such a 
captured value. But for the useEffect case (and other hooks that take closures 
as arguments), they tend to occur much earlier in a render function. There's 
more code that can run later and still modify the captured values, without 
causing issues in practice. The _practical_ rule today is that you can't modify 
values captured by frozen lambdas _after the component returns_: it's fine in 
practice to modify captured values between calling eg useEffect and returning 
from render. 

Thus this feature flag is fairly likely to break some percent of real product 
code. I'm adding this so that we can experiment and see how unsafe it actually 
is.
2023-11-06 08:33:32 -08:00
Joe Savona
c424cbbfa7 Add validation against instructions not part of their scope
Adds an internal compiler assertion pass which checks that all the instructions 
which are necessary for constructing a given scope correctly end up within the 
corresponding ReactiveScopeBlock. All known cases where this can occur are fixed 
earlier in the stack, but this assertion will help us catch any other cases we 
haven't thought of. See docblock comment for more info. 

## Test Plan 

I manually reverted the fixes from the previous PRs while keeping the new 
fixtures, and verified that this new assertion pass flags the fixtures as 
invalid.
2023-11-06 08:33:31 -08:00
Joe Savona
35fee31355 Handle IIFE with logical mutated later
The previous changes mostly meant that we removed the label terminal and didn't 
have instructions for the same scope split in a way that we couldn't merge. But 
logicals were still causing a split because MergeConsecutiveScopes can't merge 
the blocks in that case. Here we move PruneUnusedLabels earlier in the pipeline 
to ensure that instructions from IIFEs have floated up to the parent block scope 
level.
2023-11-06 08:33:30 -08:00
Joe Savona
e502e69b2d Restore React.useMemo validation
This got lost by moving the validation earlier.
2023-11-06 08:33:30 -08:00
Joe Savona
0d3f3884b8 Fix for IIFE return values mutated later
Fixes for the previous PR. What was happening is that our inference was 
inferring the correct mutable ranges and reactive scopes, but the inlining 
process left the instructions from the IIFEs inside a separate block, with a 
'label' terminal preceding it. When we converted to ReactiveFunction this was 
preserved as a ReactiveLabelTerminal, which meant that the first instruction for 
the mutable range could be nested inside one LabelTerminal, while more would be 
in a subsequent LabelTerminal. But we close blocks based on the block scope! 
This meant that we'd have leftover instructions (in the second LabelTerminal) 
that got left out of the block. 

Furthermore, because inlining was happening after EnterSSA we weren't creating 
phis correctly. This PR fixes a bunch of these issues, and a subsequent PR 
handles the remaining cases: 

* We move DropManualMemo and InlineIIFEs before EnterSSA. This means we lose the 
ability to use type information, but we ensure that we create proper SSA ids and 
phis for any reassignments within the IIFE 

* We also update PruneUnusedLabels to not just remove the unused labels, but to 
actually remove LabelTerminals that don't need them.
2023-11-06 08:33:29 -08:00
Joe Savona
1607fb39c3 Repro for incorrect memoization of iife
We construct invalid mutable ranges in these cases because the range starts 
within a labeled block. We need to run merge consecutive scopes and EnterSSA 
after inlining so that the code is lifted out of the labeled block to the 
correct scope, and so that we create phis for reassignments within the IIFE.
2023-11-06 08:33:28 -08:00
Sathya Gunasekaran
60af6671d7 [ez] Check for use-before-decl only when gating is on 2023-11-02 12:32:40 -07:00
Lauren Tan
48e709e7ad [eslint] Add test for classes
This used to cause issues because I hadn't configured Babel in the eslint plugin 
properly, so adding this as a regression test
2023-11-03 16:32:53 -04:00
Lauren Tan
3634980183 [eslint] Switch compiler to "infer" mode 2023-11-03 16:27:20 -04:00
Lauren Tan
a2aa032276 [eslint] Plugin should never throw
This has caused issues for people when things like Babel cause issues. It's not 
actionable and it crashes eslint. Just like the Babel plugin, the eslint plugin 
should never throw. Instead, let's log the error so the data isn't lost.
2023-11-03 16:27:18 -04:00
Lauren Tan
fe147cb16a [babel] Add hermes-parser type definitions to babel-plugin 2023-11-03 15:22:53 -04:00
Lauren Tan
a030d05d95 [eslint] Add test for component syntax 2023-11-03 15:22:52 -04:00
Lauren Tan
a74982d660 [eslint] Update hermes-parser, add hermes-eslint 2023-11-03 11:49:02 -04:00
Sathya Gunasekaran
4afee45440 [ez] Add missing ts type 2023-11-02 11:10:33 -07:00
Sathya Gunasekaran
adadc21021 [babel] Check if the gated component is used before decl 2023-11-02 11:10:30 -07:00
Lauren Tan
d49eb8b580 [ez] Run copyright script 2023-11-02 12:43:35 -04:00
Lauren Tan
0cc473fc9a [ez] Move copyright script to top level 2023-11-02 12:43:33 -04:00
Lauren Tan
5bd9642578 [feedback] Combine bundle scripts and don't commit dist
This combines our scripts and makes it so we no longer need to create a separate 
commit to add the forget-feedback/dist directory into the react-forget repo. I 
originally did that so I could run tests here, but now that the external repo is 
created and has its test suite hooked up to CI, this is now unnecessary friction 
to run a sync
2023-11-02 11:58:11 -04:00
Lauren Tan
4a793bb86e [hoisting] Add more repros for hoisting bugs 2023-11-02 11:01:29 -04:00
Sathya Gunasekaran
dca54c8932 [playground] Use standalone prettier
All of these warnings go away: ``` ➜  playground git:(remove-prettier) ✗ yarn 
dev yarn run v1.22.19 $ NODE_ENV=development && next dev ready - started server 
on 0.0.0.0:3000, url: http://localhost:3000 warn  - You have enabled 
experimental feature (appDir) in next.config.js. warn  - Experimental features 
are not covered by semver, and may cause unexpected or broken application 
behavior. Use at your own risk. info  - Thank you for testing `appDir` please 
leave your feedback at https://nextjs.link/app-feedback 

event - compiled client and server successfully in 964 ms (199 modules) wait  - 
compiling /page (client and server)... warn  - 
../../node_modules/prettier/index.js Critical dependency: the request of a 
dependency is an expression 

../../node_modules/prettier/index.js Critical dependency: require function is 
used in a way in which dependencies cannot be statically extracted 

../../node_modules/prettier/index.js Critical dependency: the request of a 
dependency is an expression 

../../node_modules/prettier/index.js Critical dependency: the request of a 
dependency is an expression 

../../node_modules/prettier/third-party.js Critical dependency: the request of a 
dependency is an expression wait  - compiling... warn  - 
../../node_modules/prettier/index.js Critical dependency: the request of a 
dependency is an expression 

../../node_modules/prettier/index.js Critical dependency: require function is 
used in a way in which dependencies cannot be statically extracted 

../../node_modules/prettier/index.js Critical dependency: the request of a 
dependency is an expression 

../../node_modules/prettier/index.js Critical dependency: the request of a 
dependency is an expression 

../../node_modules/prettier/third-party.js Critical dependency: the request of a 
dependency is an expression ``` 

Standalone prettier is meant to be used in the browser: 
https://prettier.io/docs/en/browser
2023-11-02 07:00:05 -07:00
dependabot[bot]
faa65778b7 Bump browserify-sign from 4.0.4 to 4.2.2 in /fixtures/expiration (#27600) 2023-11-01 19:31:28 +00:00
dependabot[bot]
9ddfe614f2 Bump browserify-sign from 4.0.4 to 4.2.2 in /fixtures/packaging/brunch/prod (#27598) 2023-11-01 19:30:25 +00:00
George Zahariev
6bfc0e032a Support Flow as expressions in ESLint rules (#27590)
Support Flow `as` expressions in ESLint rules, e.g. `<expr> as <type>`.
This is the same syntax as TypeScript as expressions. I just looked for
any place referencing `TSAsExpression` (the TS node) or
`TypeCastExpression` (the previous Flow syntax) and added a case for
`AsExpression` as well.
2023-11-01 15:24:06 -04:00
dependabot[bot]
3eaa0c3871 Bump browserify-sign from 4.0.4 to 4.2.2 in /fixtures/packaging/brunch/dev (#27606)
Bumps
[browserify-sign](https://github.com/crypto-browserify/browserify-sign)
from 4.0.4 to 4.2.2.
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a
href="https://github.com/browserify/browserify-sign/blob/main/CHANGELOG.md">browserify-sign's
changelog</a>.</em></p>
<blockquote>
<h2><a
href="https://github.com/browserify/browserify-sign/compare/v4.2.1...v4.2.2">v4.2.2</a>
- 2023-10-25</h2>
<h3>Fixed</h3>
<ul>
<li>[Tests] log when openssl doesn't support cipher <a
href="https://redirect.github.com/browserify/browserify-sign/issues/37"><code>[#37](https://github.com/crypto-browserify/browserify-sign/issues/37)</code></a></li>
</ul>
<h3>Commits</h3>
<ul>
<li>Only apps should have lockfiles <a
href="09a8995939"><code>09a8995</code></a></li>
<li>[eslint] switch to eslint <a
href="83fe46374b"><code>83fe463</code></a></li>
<li>[meta] add <code>npmignore</code> and <code>auto-changelog</code> <a
href="44181838e7"><code>4418183</code></a></li>
<li>[meta] fix package.json indentation <a
href="9ac5a5eaaa"><code>9ac5a5e</code></a></li>
<li>[Tests] migrate from travis to github actions <a
href="d845d855de"><code>d845d85</code></a></li>
<li>[Fix] <code>sign</code>: throw on unsupported padding scheme <a
href="8767739a45"><code>8767739</code></a></li>
<li>[Fix] properly check the upper bound for DSA signatures <a
href="85994cd634"><code>85994cd</code></a></li>
<li>[Tests] handle openSSL not supporting a scheme <a
href="f5f17c27f9"><code>f5f17c2</code></a></li>
<li>[Deps] update <code>bn.js</code>, <code>browserify-rsa</code>,
<code>elliptic</code>, <code>parse-asn1</code>,
<code>readable-stream</code>, <code>safe-buffer</code> <a
href="a67d0eb4ff"><code>a67d0eb</code></a></li>
<li>[Dev Deps] update <code>nyc</code>, <code>standard</code>,
<code>tape</code> <a
href="cc5350b967"><code>cc5350b</code></a></li>
<li>[Tests] always run coverage; downgrade <code>nyc</code> <a
href="75ce1d5c49"><code>75ce1d5</code></a></li>
<li>[meta] add <code>safe-publish-latest</code> <a
href="dcf49ce85a"><code>dcf49ce</code></a></li>
<li>[Tests] add <code>npm run posttest</code> <a
href="75dd8fd6ce"><code>75dd8fd</code></a></li>
<li>[Dev Deps] update <code>tape</code> <a
href="3aec0386dc"><code>3aec038</code></a></li>
<li>[Tests] skip unsupported schemes <a
href="703c83ea72"><code>703c83e</code></a></li>
<li>[Tests] node &lt; 6 lacks array <code>includes</code> <a
href="3aa43cfbc1"><code>3aa43cf</code></a></li>
<li>[Dev Deps] fix eslint range <a
href="98d4e0d7ff"><code>98d4e0d</code></a></li>
</ul>
<h2><a
href="https://github.com/browserify/browserify-sign/compare/v4.2.0...v4.2.1">v4.2.1</a>
- 2020-08-04</h2>
<h3>Merged</h3>
<ul>
<li>bump elliptic <a
href="https://redirect.github.com/browserify/browserify-sign/pull/58"><code>[#58](https://github.com/crypto-browserify/browserify-sign/issues/58)</code></a></li>
</ul>
<h2><a
href="https://github.com/browserify/browserify-sign/compare/v4.1.0...v4.2.0">v4.2.0</a>
- 2020-05-18</h2>
<h3>Merged</h3>
<ul>
<li>switch to safe buffer <a
href="https://redirect.github.com/browserify/browserify-sign/pull/53"><code>[#53](https://github.com/crypto-browserify/browserify-sign/issues/53)</code></a></li>
</ul>
<h2><a
href="https://github.com/browserify/browserify-sign/compare/v4.0.4...v4.1.0">v4.1.0</a>
- 2020-05-05</h2>
<h3>Merged</h3>
<ul>
<li>update deps, modernise usage, use readable-stream <a
href="https://redirect.github.com/browserify/browserify-sign/pull/49"><code>[#49](https://github.com/crypto-browserify/browserify-sign/issues/49)</code></a></li>
</ul>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="4af5a90bf8"><code>4af5a90</code></a>
v4.2.2</li>
<li><a
href="3aec0386dc"><code>3aec038</code></a>
[Dev Deps] update <code>tape</code></li>
<li><a
href="85994cd634"><code>85994cd</code></a>
[Fix] properly check the upper bound for DSA signatures</li>
<li><a
href="9ac5a5eaaa"><code>9ac5a5e</code></a>
[meta] fix package.json indentation</li>
<li><a
href="dcf49ce85a"><code>dcf49ce</code></a>
[meta] add <code>safe-publish-latest</code></li>
<li><a
href="44181838e7"><code>4418183</code></a>
[meta] add <code>npmignore</code> and <code>auto-changelog</code></li>
<li><a
href="8767739a45"><code>8767739</code></a>
[Fix] <code>sign</code>: throw on unsupported padding scheme</li>
<li><a
href="5f6fb17559"><code>5f6fb17</code></a>
[Tests] log when openssl doesn't support cipher</li>
<li><a
href="f5f17c27f9"><code>f5f17c2</code></a>
[Tests] handle openSSL not supporting a scheme</li>
<li><a
href="d845d855de"><code>d845d85</code></a>
[Tests] migrate from travis to github actions</li>
<li>Additional commits viewable in <a
href="https://github.com/crypto-browserify/browserify-sign/compare/v4.0.4...v4.2.2">compare
view</a></li>
</ul>
</details>
<details>
<summary>Maintainer changes</summary>
<p>This version was pushed to npm by <a
href="https://www.npmjs.com/~ljharb">ljharb</a>, a new releaser for
browserify-sign since your current version.</p>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=browserify-sign&package-manager=npm_and_yarn&previous-version=4.0.4&new-version=4.2.2)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)
You can disable automated security fix PRs for this repo from the
[Security Alerts
page](https://github.com/facebook/react/network/alerts).

</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-11-01 15:20:57 -04:00
dependabot[bot]
0040951637 Bump browserify-sign from 4.2.1 to 4.2.2 in /fixtures/dom (#27608)
Bumps
[browserify-sign](https://github.com/crypto-browserify/browserify-sign)
from 4.2.1 to 4.2.2.
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a
href="https://github.com/browserify/browserify-sign/blob/main/CHANGELOG.md">browserify-sign's
changelog</a>.</em></p>
<blockquote>
<h2><a
href="https://github.com/browserify/browserify-sign/compare/v4.2.1...v4.2.2">v4.2.2</a>
- 2023-10-25</h2>
<h3>Fixed</h3>
<ul>
<li>[Tests] log when openssl doesn't support cipher <a
href="https://redirect.github.com/browserify/browserify-sign/issues/37"><code>[#37](https://github.com/crypto-browserify/browserify-sign/issues/37)</code></a></li>
</ul>
<h3>Commits</h3>
<ul>
<li>Only apps should have lockfiles <a
href="09a8995939"><code>09a8995</code></a></li>
<li>[eslint] switch to eslint <a
href="83fe46374b"><code>83fe463</code></a></li>
<li>[meta] add <code>npmignore</code> and <code>auto-changelog</code> <a
href="44181838e7"><code>4418183</code></a></li>
<li>[meta] fix package.json indentation <a
href="9ac5a5eaaa"><code>9ac5a5e</code></a></li>
<li>[Tests] migrate from travis to github actions <a
href="d845d855de"><code>d845d85</code></a></li>
<li>[Fix] <code>sign</code>: throw on unsupported padding scheme <a
href="8767739a45"><code>8767739</code></a></li>
<li>[Fix] properly check the upper bound for DSA signatures <a
href="85994cd634"><code>85994cd</code></a></li>
<li>[Tests] handle openSSL not supporting a scheme <a
href="f5f17c27f9"><code>f5f17c2</code></a></li>
<li>[Deps] update <code>bn.js</code>, <code>browserify-rsa</code>,
<code>elliptic</code>, <code>parse-asn1</code>,
<code>readable-stream</code>, <code>safe-buffer</code> <a
href="a67d0eb4ff"><code>a67d0eb</code></a></li>
<li>[Dev Deps] update <code>nyc</code>, <code>standard</code>,
<code>tape</code> <a
href="cc5350b967"><code>cc5350b</code></a></li>
<li>[Tests] always run coverage; downgrade <code>nyc</code> <a
href="75ce1d5c49"><code>75ce1d5</code></a></li>
<li>[meta] add <code>safe-publish-latest</code> <a
href="dcf49ce85a"><code>dcf49ce</code></a></li>
<li>[Tests] add <code>npm run posttest</code> <a
href="75dd8fd6ce"><code>75dd8fd</code></a></li>
<li>[Dev Deps] update <code>tape</code> <a
href="3aec0386dc"><code>3aec038</code></a></li>
<li>[Tests] skip unsupported schemes <a
href="703c83ea72"><code>703c83e</code></a></li>
<li>[Tests] node &lt; 6 lacks array <code>includes</code> <a
href="3aa43cfbc1"><code>3aa43cf</code></a></li>
<li>[Dev Deps] fix eslint range <a
href="98d4e0d7ff"><code>98d4e0d</code></a></li>
</ul>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="4af5a90bf8"><code>4af5a90</code></a>
v4.2.2</li>
<li><a
href="3aec0386dc"><code>3aec038</code></a>
[Dev Deps] update <code>tape</code></li>
<li><a
href="85994cd634"><code>85994cd</code></a>
[Fix] properly check the upper bound for DSA signatures</li>
<li><a
href="9ac5a5eaaa"><code>9ac5a5e</code></a>
[meta] fix package.json indentation</li>
<li><a
href="dcf49ce85a"><code>dcf49ce</code></a>
[meta] add <code>safe-publish-latest</code></li>
<li><a
href="44181838e7"><code>4418183</code></a>
[meta] add <code>npmignore</code> and <code>auto-changelog</code></li>
<li><a
href="8767739a45"><code>8767739</code></a>
[Fix] <code>sign</code>: throw on unsupported padding scheme</li>
<li><a
href="5f6fb17559"><code>5f6fb17</code></a>
[Tests] log when openssl doesn't support cipher</li>
<li><a
href="f5f17c27f9"><code>f5f17c2</code></a>
[Tests] handle openSSL not supporting a scheme</li>
<li><a
href="d845d855de"><code>d845d85</code></a>
[Tests] migrate from travis to github actions</li>
<li>Additional commits viewable in <a
href="https://github.com/crypto-browserify/browserify-sign/compare/v4.2.1...v4.2.2">compare
view</a></li>
</ul>
</details>
<details>
<summary>Maintainer changes</summary>
<p>This version was pushed to npm by <a
href="https://www.npmjs.com/~ljharb">ljharb</a>, a new releaser for
browserify-sign since your current version.</p>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=browserify-sign&package-manager=npm_and_yarn&previous-version=4.2.1&new-version=4.2.2)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)
You can disable automated security fix PRs for this repo from the
[Security Alerts
page](https://github.com/facebook/react/network/alerts).

</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-11-01 15:20:39 -04:00
dependabot[bot]
d0fcd36af4 Bump browserify-sign from 4.0.4 to 4.2.2 in /fixtures/attribute-behavior (#27601)
Bumps
[browserify-sign](https://github.com/crypto-browserify/browserify-sign)
from 4.0.4 to 4.2.2.
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a
href="https://github.com/browserify/browserify-sign/blob/main/CHANGELOG.md">browserify-sign's
changelog</a>.</em></p>
<blockquote>
<h2><a
href="https://github.com/browserify/browserify-sign/compare/v4.2.1...v4.2.2">v4.2.2</a>
- 2023-10-25</h2>
<h3>Fixed</h3>
<ul>
<li>[Tests] log when openssl doesn't support cipher <a
href="https://redirect.github.com/browserify/browserify-sign/issues/37"><code>[#37](https://github.com/crypto-browserify/browserify-sign/issues/37)</code></a></li>
</ul>
<h3>Commits</h3>
<ul>
<li>Only apps should have lockfiles <a
href="09a8995939"><code>09a8995</code></a></li>
<li>[eslint] switch to eslint <a
href="83fe46374b"><code>83fe463</code></a></li>
<li>[meta] add <code>npmignore</code> and <code>auto-changelog</code> <a
href="44181838e7"><code>4418183</code></a></li>
<li>[meta] fix package.json indentation <a
href="9ac5a5eaaa"><code>9ac5a5e</code></a></li>
<li>[Tests] migrate from travis to github actions <a
href="d845d855de"><code>d845d85</code></a></li>
<li>[Fix] <code>sign</code>: throw on unsupported padding scheme <a
href="8767739a45"><code>8767739</code></a></li>
<li>[Fix] properly check the upper bound for DSA signatures <a
href="85994cd634"><code>85994cd</code></a></li>
<li>[Tests] handle openSSL not supporting a scheme <a
href="f5f17c27f9"><code>f5f17c2</code></a></li>
<li>[Deps] update <code>bn.js</code>, <code>browserify-rsa</code>,
<code>elliptic</code>, <code>parse-asn1</code>,
<code>readable-stream</code>, <code>safe-buffer</code> <a
href="a67d0eb4ff"><code>a67d0eb</code></a></li>
<li>[Dev Deps] update <code>nyc</code>, <code>standard</code>,
<code>tape</code> <a
href="cc5350b967"><code>cc5350b</code></a></li>
<li>[Tests] always run coverage; downgrade <code>nyc</code> <a
href="75ce1d5c49"><code>75ce1d5</code></a></li>
<li>[meta] add <code>safe-publish-latest</code> <a
href="dcf49ce85a"><code>dcf49ce</code></a></li>
<li>[Tests] add <code>npm run posttest</code> <a
href="75dd8fd6ce"><code>75dd8fd</code></a></li>
<li>[Dev Deps] update <code>tape</code> <a
href="3aec0386dc"><code>3aec038</code></a></li>
<li>[Tests] skip unsupported schemes <a
href="703c83ea72"><code>703c83e</code></a></li>
<li>[Tests] node &lt; 6 lacks array <code>includes</code> <a
href="3aa43cfbc1"><code>3aa43cf</code></a></li>
<li>[Dev Deps] fix eslint range <a
href="98d4e0d7ff"><code>98d4e0d</code></a></li>
</ul>
<h2><a
href="https://github.com/browserify/browserify-sign/compare/v4.2.0...v4.2.1">v4.2.1</a>
- 2020-08-04</h2>
<h3>Merged</h3>
<ul>
<li>bump elliptic <a
href="https://redirect.github.com/browserify/browserify-sign/pull/58"><code>[#58](https://github.com/crypto-browserify/browserify-sign/issues/58)</code></a></li>
</ul>
<h2><a
href="https://github.com/browserify/browserify-sign/compare/v4.1.0...v4.2.0">v4.2.0</a>
- 2020-05-18</h2>
<h3>Merged</h3>
<ul>
<li>switch to safe buffer <a
href="https://redirect.github.com/browserify/browserify-sign/pull/53"><code>[#53](https://github.com/crypto-browserify/browserify-sign/issues/53)</code></a></li>
</ul>
<h2><a
href="https://github.com/browserify/browserify-sign/compare/v4.0.4...v4.1.0">v4.1.0</a>
- 2020-05-05</h2>
<h3>Merged</h3>
<ul>
<li>update deps, modernise usage, use readable-stream <a
href="https://redirect.github.com/browserify/browserify-sign/pull/49"><code>[#49](https://github.com/crypto-browserify/browserify-sign/issues/49)</code></a></li>
</ul>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="4af5a90bf8"><code>4af5a90</code></a>
v4.2.2</li>
<li><a
href="3aec0386dc"><code>3aec038</code></a>
[Dev Deps] update <code>tape</code></li>
<li><a
href="85994cd634"><code>85994cd</code></a>
[Fix] properly check the upper bound for DSA signatures</li>
<li><a
href="9ac5a5eaaa"><code>9ac5a5e</code></a>
[meta] fix package.json indentation</li>
<li><a
href="dcf49ce85a"><code>dcf49ce</code></a>
[meta] add <code>safe-publish-latest</code></li>
<li><a
href="44181838e7"><code>4418183</code></a>
[meta] add <code>npmignore</code> and <code>auto-changelog</code></li>
<li><a
href="8767739a45"><code>8767739</code></a>
[Fix] <code>sign</code>: throw on unsupported padding scheme</li>
<li><a
href="5f6fb17559"><code>5f6fb17</code></a>
[Tests] log when openssl doesn't support cipher</li>
<li><a
href="f5f17c27f9"><code>f5f17c2</code></a>
[Tests] handle openSSL not supporting a scheme</li>
<li><a
href="d845d855de"><code>d845d85</code></a>
[Tests] migrate from travis to github actions</li>
<li>Additional commits viewable in <a
href="https://github.com/crypto-browserify/browserify-sign/compare/v4.0.4...v4.2.2">compare
view</a></li>
</ul>
</details>
<details>
<summary>Maintainer changes</summary>
<p>This version was pushed to npm by <a
href="https://www.npmjs.com/~ljharb">ljharb</a>, a new releaser for
browserify-sign since your current version.</p>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=browserify-sign&package-manager=npm_and_yarn&previous-version=4.0.4&new-version=4.2.2)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)
You can disable automated security fix PRs for this repo from the
[Security Alerts
page](https://github.com/facebook/react/network/alerts).

</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-11-01 15:20:01 -04:00
dependabot[bot]
169d3350f0 Bump browserify-sign from 4.2.1 to 4.2.2 in /fixtures/ssr2 (#27616)
Bumps
[browserify-sign](https://github.com/crypto-browserify/browserify-sign)
from 4.2.1 to 4.2.2.
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a
href="https://github.com/browserify/browserify-sign/blob/main/CHANGELOG.md">browserify-sign's
changelog</a>.</em></p>
<blockquote>
<h2><a
href="https://github.com/browserify/browserify-sign/compare/v4.2.1...v4.2.2">v4.2.2</a>
- 2023-10-25</h2>
<h3>Fixed</h3>
<ul>
<li>[Tests] log when openssl doesn't support cipher <a
href="https://redirect.github.com/browserify/browserify-sign/issues/37"><code>[#37](https://github.com/crypto-browserify/browserify-sign/issues/37)</code></a></li>
</ul>
<h3>Commits</h3>
<ul>
<li>Only apps should have lockfiles <a
href="09a8995939"><code>09a8995</code></a></li>
<li>[eslint] switch to eslint <a
href="83fe46374b"><code>83fe463</code></a></li>
<li>[meta] add <code>npmignore</code> and <code>auto-changelog</code> <a
href="44181838e7"><code>4418183</code></a></li>
<li>[meta] fix package.json indentation <a
href="9ac5a5eaaa"><code>9ac5a5e</code></a></li>
<li>[Tests] migrate from travis to github actions <a
href="d845d855de"><code>d845d85</code></a></li>
<li>[Fix] <code>sign</code>: throw on unsupported padding scheme <a
href="8767739a45"><code>8767739</code></a></li>
<li>[Fix] properly check the upper bound for DSA signatures <a
href="85994cd634"><code>85994cd</code></a></li>
<li>[Tests] handle openSSL not supporting a scheme <a
href="f5f17c27f9"><code>f5f17c2</code></a></li>
<li>[Deps] update <code>bn.js</code>, <code>browserify-rsa</code>,
<code>elliptic</code>, <code>parse-asn1</code>,
<code>readable-stream</code>, <code>safe-buffer</code> <a
href="a67d0eb4ff"><code>a67d0eb</code></a></li>
<li>[Dev Deps] update <code>nyc</code>, <code>standard</code>,
<code>tape</code> <a
href="cc5350b967"><code>cc5350b</code></a></li>
<li>[Tests] always run coverage; downgrade <code>nyc</code> <a
href="75ce1d5c49"><code>75ce1d5</code></a></li>
<li>[meta] add <code>safe-publish-latest</code> <a
href="dcf49ce85a"><code>dcf49ce</code></a></li>
<li>[Tests] add <code>npm run posttest</code> <a
href="75dd8fd6ce"><code>75dd8fd</code></a></li>
<li>[Dev Deps] update <code>tape</code> <a
href="3aec0386dc"><code>3aec038</code></a></li>
<li>[Tests] skip unsupported schemes <a
href="703c83ea72"><code>703c83e</code></a></li>
<li>[Tests] node &lt; 6 lacks array <code>includes</code> <a
href="3aa43cfbc1"><code>3aa43cf</code></a></li>
<li>[Dev Deps] fix eslint range <a
href="98d4e0d7ff"><code>98d4e0d</code></a></li>
</ul>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="4af5a90bf8"><code>4af5a90</code></a>
v4.2.2</li>
<li><a
href="3aec0386dc"><code>3aec038</code></a>
[Dev Deps] update <code>tape</code></li>
<li><a
href="85994cd634"><code>85994cd</code></a>
[Fix] properly check the upper bound for DSA signatures</li>
<li><a
href="9ac5a5eaaa"><code>9ac5a5e</code></a>
[meta] fix package.json indentation</li>
<li><a
href="dcf49ce85a"><code>dcf49ce</code></a>
[meta] add <code>safe-publish-latest</code></li>
<li><a
href="44181838e7"><code>4418183</code></a>
[meta] add <code>npmignore</code> and <code>auto-changelog</code></li>
<li><a
href="8767739a45"><code>8767739</code></a>
[Fix] <code>sign</code>: throw on unsupported padding scheme</li>
<li><a
href="5f6fb17559"><code>5f6fb17</code></a>
[Tests] log when openssl doesn't support cipher</li>
<li><a
href="f5f17c27f9"><code>f5f17c2</code></a>
[Tests] handle openSSL not supporting a scheme</li>
<li><a
href="d845d855de"><code>d845d85</code></a>
[Tests] migrate from travis to github actions</li>
<li>Additional commits viewable in <a
href="https://github.com/crypto-browserify/browserify-sign/compare/v4.2.1...v4.2.2">compare
view</a></li>
</ul>
</details>
<details>
<summary>Maintainer changes</summary>
<p>This version was pushed to npm by <a
href="https://www.npmjs.com/~ljharb">ljharb</a>, a new releaser for
browserify-sign since your current version.</p>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=browserify-sign&package-manager=npm_and_yarn&previous-version=4.2.1&new-version=4.2.2)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)
You can disable automated security fix PRs for this repo from the
[Security Alerts
page](https://github.com/facebook/react/network/alerts).

</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-11-01 15:19:34 -04:00
dependabot[bot]
a675e5751b Bump browserify-sign from 4.2.1 to 4.2.2 in /fixtures/concurrent/time-slicing (#27615)
Bumps
[browserify-sign](https://github.com/crypto-browserify/browserify-sign)
from 4.2.1 to 4.2.2.
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a
href="https://github.com/browserify/browserify-sign/blob/main/CHANGELOG.md">browserify-sign's
changelog</a>.</em></p>
<blockquote>
<h2><a
href="https://github.com/browserify/browserify-sign/compare/v4.2.1...v4.2.2">v4.2.2</a>
- 2023-10-25</h2>
<h3>Fixed</h3>
<ul>
<li>[Tests] log when openssl doesn't support cipher <a
href="https://redirect.github.com/browserify/browserify-sign/issues/37"><code>[#37](https://github.com/crypto-browserify/browserify-sign/issues/37)</code></a></li>
</ul>
<h3>Commits</h3>
<ul>
<li>Only apps should have lockfiles <a
href="09a8995939"><code>09a8995</code></a></li>
<li>[eslint] switch to eslint <a
href="83fe46374b"><code>83fe463</code></a></li>
<li>[meta] add <code>npmignore</code> and <code>auto-changelog</code> <a
href="44181838e7"><code>4418183</code></a></li>
<li>[meta] fix package.json indentation <a
href="9ac5a5eaaa"><code>9ac5a5e</code></a></li>
<li>[Tests] migrate from travis to github actions <a
href="d845d855de"><code>d845d85</code></a></li>
<li>[Fix] <code>sign</code>: throw on unsupported padding scheme <a
href="8767739a45"><code>8767739</code></a></li>
<li>[Fix] properly check the upper bound for DSA signatures <a
href="85994cd634"><code>85994cd</code></a></li>
<li>[Tests] handle openSSL not supporting a scheme <a
href="f5f17c27f9"><code>f5f17c2</code></a></li>
<li>[Deps] update <code>bn.js</code>, <code>browserify-rsa</code>,
<code>elliptic</code>, <code>parse-asn1</code>,
<code>readable-stream</code>, <code>safe-buffer</code> <a
href="a67d0eb4ff"><code>a67d0eb</code></a></li>
<li>[Dev Deps] update <code>nyc</code>, <code>standard</code>,
<code>tape</code> <a
href="cc5350b967"><code>cc5350b</code></a></li>
<li>[Tests] always run coverage; downgrade <code>nyc</code> <a
href="75ce1d5c49"><code>75ce1d5</code></a></li>
<li>[meta] add <code>safe-publish-latest</code> <a
href="dcf49ce85a"><code>dcf49ce</code></a></li>
<li>[Tests] add <code>npm run posttest</code> <a
href="75dd8fd6ce"><code>75dd8fd</code></a></li>
<li>[Dev Deps] update <code>tape</code> <a
href="3aec0386dc"><code>3aec038</code></a></li>
<li>[Tests] skip unsupported schemes <a
href="703c83ea72"><code>703c83e</code></a></li>
<li>[Tests] node &lt; 6 lacks array <code>includes</code> <a
href="3aa43cfbc1"><code>3aa43cf</code></a></li>
<li>[Dev Deps] fix eslint range <a
href="98d4e0d7ff"><code>98d4e0d</code></a></li>
</ul>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="4af5a90bf8"><code>4af5a90</code></a>
v4.2.2</li>
<li><a
href="3aec0386dc"><code>3aec038</code></a>
[Dev Deps] update <code>tape</code></li>
<li><a
href="85994cd634"><code>85994cd</code></a>
[Fix] properly check the upper bound for DSA signatures</li>
<li><a
href="9ac5a5eaaa"><code>9ac5a5e</code></a>
[meta] fix package.json indentation</li>
<li><a
href="dcf49ce85a"><code>dcf49ce</code></a>
[meta] add <code>safe-publish-latest</code></li>
<li><a
href="44181838e7"><code>4418183</code></a>
[meta] add <code>npmignore</code> and <code>auto-changelog</code></li>
<li><a
href="8767739a45"><code>8767739</code></a>
[Fix] <code>sign</code>: throw on unsupported padding scheme</li>
<li><a
href="5f6fb17559"><code>5f6fb17</code></a>
[Tests] log when openssl doesn't support cipher</li>
<li><a
href="f5f17c27f9"><code>f5f17c2</code></a>
[Tests] handle openSSL not supporting a scheme</li>
<li><a
href="d845d855de"><code>d845d85</code></a>
[Tests] migrate from travis to github actions</li>
<li>Additional commits viewable in <a
href="https://github.com/crypto-browserify/browserify-sign/compare/v4.2.1...v4.2.2">compare
view</a></li>
</ul>
</details>
<details>
<summary>Maintainer changes</summary>
<p>This version was pushed to npm by <a
href="https://www.npmjs.com/~ljharb">ljharb</a>, a new releaser for
browserify-sign since your current version.</p>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=browserify-sign&package-manager=npm_and_yarn&previous-version=4.2.1&new-version=4.2.2)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)
You can disable automated security fix PRs for this repo from the
[Security Alerts
page](https://github.com/facebook/react/network/alerts).

</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-11-01 15:19:28 -04:00
dependabot[bot]
2bd946956d Bump browserify-sign from 4.2.1 to 4.2.2 in /fixtures/fizz (#27614)
Bumps
[browserify-sign](https://github.com/crypto-browserify/browserify-sign)
from 4.2.1 to 4.2.2.
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a
href="https://github.com/browserify/browserify-sign/blob/main/CHANGELOG.md">browserify-sign's
changelog</a>.</em></p>
<blockquote>
<h2><a
href="https://github.com/browserify/browserify-sign/compare/v4.2.1...v4.2.2">v4.2.2</a>
- 2023-10-25</h2>
<h3>Fixed</h3>
<ul>
<li>[Tests] log when openssl doesn't support cipher <a
href="https://redirect.github.com/browserify/browserify-sign/issues/37"><code>[#37](https://github.com/crypto-browserify/browserify-sign/issues/37)</code></a></li>
</ul>
<h3>Commits</h3>
<ul>
<li>Only apps should have lockfiles <a
href="09a8995939"><code>09a8995</code></a></li>
<li>[eslint] switch to eslint <a
href="83fe46374b"><code>83fe463</code></a></li>
<li>[meta] add <code>npmignore</code> and <code>auto-changelog</code> <a
href="44181838e7"><code>4418183</code></a></li>
<li>[meta] fix package.json indentation <a
href="9ac5a5eaaa"><code>9ac5a5e</code></a></li>
<li>[Tests] migrate from travis to github actions <a
href="d845d855de"><code>d845d85</code></a></li>
<li>[Fix] <code>sign</code>: throw on unsupported padding scheme <a
href="8767739a45"><code>8767739</code></a></li>
<li>[Fix] properly check the upper bound for DSA signatures <a
href="85994cd634"><code>85994cd</code></a></li>
<li>[Tests] handle openSSL not supporting a scheme <a
href="f5f17c27f9"><code>f5f17c2</code></a></li>
<li>[Deps] update <code>bn.js</code>, <code>browserify-rsa</code>,
<code>elliptic</code>, <code>parse-asn1</code>,
<code>readable-stream</code>, <code>safe-buffer</code> <a
href="a67d0eb4ff"><code>a67d0eb</code></a></li>
<li>[Dev Deps] update <code>nyc</code>, <code>standard</code>,
<code>tape</code> <a
href="cc5350b967"><code>cc5350b</code></a></li>
<li>[Tests] always run coverage; downgrade <code>nyc</code> <a
href="75ce1d5c49"><code>75ce1d5</code></a></li>
<li>[meta] add <code>safe-publish-latest</code> <a
href="dcf49ce85a"><code>dcf49ce</code></a></li>
<li>[Tests] add <code>npm run posttest</code> <a
href="75dd8fd6ce"><code>75dd8fd</code></a></li>
<li>[Dev Deps] update <code>tape</code> <a
href="3aec0386dc"><code>3aec038</code></a></li>
<li>[Tests] skip unsupported schemes <a
href="703c83ea72"><code>703c83e</code></a></li>
<li>[Tests] node &lt; 6 lacks array <code>includes</code> <a
href="3aa43cfbc1"><code>3aa43cf</code></a></li>
<li>[Dev Deps] fix eslint range <a
href="98d4e0d7ff"><code>98d4e0d</code></a></li>
</ul>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="4af5a90bf8"><code>4af5a90</code></a>
v4.2.2</li>
<li><a
href="3aec0386dc"><code>3aec038</code></a>
[Dev Deps] update <code>tape</code></li>
<li><a
href="85994cd634"><code>85994cd</code></a>
[Fix] properly check the upper bound for DSA signatures</li>
<li><a
href="9ac5a5eaaa"><code>9ac5a5e</code></a>
[meta] fix package.json indentation</li>
<li><a
href="dcf49ce85a"><code>dcf49ce</code></a>
[meta] add <code>safe-publish-latest</code></li>
<li><a
href="44181838e7"><code>4418183</code></a>
[meta] add <code>npmignore</code> and <code>auto-changelog</code></li>
<li><a
href="8767739a45"><code>8767739</code></a>
[Fix] <code>sign</code>: throw on unsupported padding scheme</li>
<li><a
href="5f6fb17559"><code>5f6fb17</code></a>
[Tests] log when openssl doesn't support cipher</li>
<li><a
href="f5f17c27f9"><code>f5f17c2</code></a>
[Tests] handle openSSL not supporting a scheme</li>
<li><a
href="d845d855de"><code>d845d85</code></a>
[Tests] migrate from travis to github actions</li>
<li>Additional commits viewable in <a
href="https://github.com/crypto-browserify/browserify-sign/compare/v4.2.1...v4.2.2">compare
view</a></li>
</ul>
</details>
<details>
<summary>Maintainer changes</summary>
<p>This version was pushed to npm by <a
href="https://www.npmjs.com/~ljharb">ljharb</a>, a new releaser for
browserify-sign since your current version.</p>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=browserify-sign&package-manager=npm_and_yarn&previous-version=4.2.1&new-version=4.2.2)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)
You can disable automated security fix PRs for this repo from the
[Security Alerts
page](https://github.com/facebook/react/network/alerts).

</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-11-01 15:19:22 -04:00
dependabot[bot]
a79b55df74 Bump browserify-sign from 4.0.4 to 4.2.2 in /fixtures/packaging/browserify/prod (#27599)
Bumps
[browserify-sign](https://github.com/crypto-browserify/browserify-sign)
from 4.0.4 to 4.2.2.
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a
href="https://github.com/browserify/browserify-sign/blob/main/CHANGELOG.md">browserify-sign's
changelog</a>.</em></p>
<blockquote>
<h2><a
href="https://github.com/browserify/browserify-sign/compare/v4.2.1...v4.2.2">v4.2.2</a>
- 2023-10-25</h2>
<h3>Fixed</h3>
<ul>
<li>[Tests] log when openssl doesn't support cipher <a
href="https://redirect.github.com/browserify/browserify-sign/issues/37"><code>[#37](https://github.com/crypto-browserify/browserify-sign/issues/37)</code></a></li>
</ul>
<h3>Commits</h3>
<ul>
<li>Only apps should have lockfiles <a
href="09a8995939"><code>09a8995</code></a></li>
<li>[eslint] switch to eslint <a
href="83fe46374b"><code>83fe463</code></a></li>
<li>[meta] add <code>npmignore</code> and <code>auto-changelog</code> <a
href="44181838e7"><code>4418183</code></a></li>
<li>[meta] fix package.json indentation <a
href="9ac5a5eaaa"><code>9ac5a5e</code></a></li>
<li>[Tests] migrate from travis to github actions <a
href="d845d855de"><code>d845d85</code></a></li>
<li>[Fix] <code>sign</code>: throw on unsupported padding scheme <a
href="8767739a45"><code>8767739</code></a></li>
<li>[Fix] properly check the upper bound for DSA signatures <a
href="85994cd634"><code>85994cd</code></a></li>
<li>[Tests] handle openSSL not supporting a scheme <a
href="f5f17c27f9"><code>f5f17c2</code></a></li>
<li>[Deps] update <code>bn.js</code>, <code>browserify-rsa</code>,
<code>elliptic</code>, <code>parse-asn1</code>,
<code>readable-stream</code>, <code>safe-buffer</code> <a
href="a67d0eb4ff"><code>a67d0eb</code></a></li>
<li>[Dev Deps] update <code>nyc</code>, <code>standard</code>,
<code>tape</code> <a
href="cc5350b967"><code>cc5350b</code></a></li>
<li>[Tests] always run coverage; downgrade <code>nyc</code> <a
href="75ce1d5c49"><code>75ce1d5</code></a></li>
<li>[meta] add <code>safe-publish-latest</code> <a
href="dcf49ce85a"><code>dcf49ce</code></a></li>
<li>[Tests] add <code>npm run posttest</code> <a
href="75dd8fd6ce"><code>75dd8fd</code></a></li>
<li>[Dev Deps] update <code>tape</code> <a
href="3aec0386dc"><code>3aec038</code></a></li>
<li>[Tests] skip unsupported schemes <a
href="703c83ea72"><code>703c83e</code></a></li>
<li>[Tests] node &lt; 6 lacks array <code>includes</code> <a
href="3aa43cfbc1"><code>3aa43cf</code></a></li>
<li>[Dev Deps] fix eslint range <a
href="98d4e0d7ff"><code>98d4e0d</code></a></li>
</ul>
<h2><a
href="https://github.com/browserify/browserify-sign/compare/v4.2.0...v4.2.1">v4.2.1</a>
- 2020-08-04</h2>
<h3>Merged</h3>
<ul>
<li>bump elliptic <a
href="https://redirect.github.com/browserify/browserify-sign/pull/58"><code>[#58](https://github.com/crypto-browserify/browserify-sign/issues/58)</code></a></li>
</ul>
<h2><a
href="https://github.com/browserify/browserify-sign/compare/v4.1.0...v4.2.0">v4.2.0</a>
- 2020-05-18</h2>
<h3>Merged</h3>
<ul>
<li>switch to safe buffer <a
href="https://redirect.github.com/browserify/browserify-sign/pull/53"><code>[#53](https://github.com/crypto-browserify/browserify-sign/issues/53)</code></a></li>
</ul>
<h2><a
href="https://github.com/browserify/browserify-sign/compare/v4.0.4...v4.1.0">v4.1.0</a>
- 2020-05-05</h2>
<h3>Merged</h3>
<ul>
<li>update deps, modernise usage, use readable-stream <a
href="https://redirect.github.com/browserify/browserify-sign/pull/49"><code>[#49](https://github.com/crypto-browserify/browserify-sign/issues/49)</code></a></li>
</ul>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="4af5a90bf8"><code>4af5a90</code></a>
v4.2.2</li>
<li><a
href="3aec0386dc"><code>3aec038</code></a>
[Dev Deps] update <code>tape</code></li>
<li><a
href="85994cd634"><code>85994cd</code></a>
[Fix] properly check the upper bound for DSA signatures</li>
<li><a
href="9ac5a5eaaa"><code>9ac5a5e</code></a>
[meta] fix package.json indentation</li>
<li><a
href="dcf49ce85a"><code>dcf49ce</code></a>
[meta] add <code>safe-publish-latest</code></li>
<li><a
href="44181838e7"><code>4418183</code></a>
[meta] add <code>npmignore</code> and <code>auto-changelog</code></li>
<li><a
href="8767739a45"><code>8767739</code></a>
[Fix] <code>sign</code>: throw on unsupported padding scheme</li>
<li><a
href="5f6fb17559"><code>5f6fb17</code></a>
[Tests] log when openssl doesn't support cipher</li>
<li><a
href="f5f17c27f9"><code>f5f17c2</code></a>
[Tests] handle openSSL not supporting a scheme</li>
<li><a
href="d845d855de"><code>d845d85</code></a>
[Tests] migrate from travis to github actions</li>
<li>Additional commits viewable in <a
href="https://github.com/crypto-browserify/browserify-sign/compare/v4.0.4...v4.2.2">compare
view</a></li>
</ul>
</details>
<details>
<summary>Maintainer changes</summary>
<p>This version was pushed to npm by <a
href="https://www.npmjs.com/~ljharb">ljharb</a>, a new releaser for
browserify-sign since your current version.</p>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=browserify-sign&package-manager=npm_and_yarn&previous-version=4.0.4&new-version=4.2.2)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)
You can disable automated security fix PRs for this repo from the
[Security Alerts
page](https://github.com/facebook/react/network/alerts).

</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-11-01 15:19:07 -04:00
dependabot[bot]
c988756f95 Bump browserify-sign from 4.0.4 to 4.2.2 in /fixtures/packaging/browserify/dev (#27597)
Bumps
[browserify-sign](https://github.com/crypto-browserify/browserify-sign)
from 4.0.4 to 4.2.2.
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a
href="https://github.com/browserify/browserify-sign/blob/main/CHANGELOG.md">browserify-sign's
changelog</a>.</em></p>
<blockquote>
<h2><a
href="https://github.com/browserify/browserify-sign/compare/v4.2.1...v4.2.2">v4.2.2</a>
- 2023-10-25</h2>
<h3>Fixed</h3>
<ul>
<li>[Tests] log when openssl doesn't support cipher <a
href="https://redirect.github.com/browserify/browserify-sign/issues/37"><code>[#37](https://github.com/crypto-browserify/browserify-sign/issues/37)</code></a></li>
</ul>
<h3>Commits</h3>
<ul>
<li>Only apps should have lockfiles <a
href="09a8995939"><code>09a8995</code></a></li>
<li>[eslint] switch to eslint <a
href="83fe46374b"><code>83fe463</code></a></li>
<li>[meta] add <code>npmignore</code> and <code>auto-changelog</code> <a
href="44181838e7"><code>4418183</code></a></li>
<li>[meta] fix package.json indentation <a
href="9ac5a5eaaa"><code>9ac5a5e</code></a></li>
<li>[Tests] migrate from travis to github actions <a
href="d845d855de"><code>d845d85</code></a></li>
<li>[Fix] <code>sign</code>: throw on unsupported padding scheme <a
href="8767739a45"><code>8767739</code></a></li>
<li>[Fix] properly check the upper bound for DSA signatures <a
href="85994cd634"><code>85994cd</code></a></li>
<li>[Tests] handle openSSL not supporting a scheme <a
href="f5f17c27f9"><code>f5f17c2</code></a></li>
<li>[Deps] update <code>bn.js</code>, <code>browserify-rsa</code>,
<code>elliptic</code>, <code>parse-asn1</code>,
<code>readable-stream</code>, <code>safe-buffer</code> <a
href="a67d0eb4ff"><code>a67d0eb</code></a></li>
<li>[Dev Deps] update <code>nyc</code>, <code>standard</code>,
<code>tape</code> <a
href="cc5350b967"><code>cc5350b</code></a></li>
<li>[Tests] always run coverage; downgrade <code>nyc</code> <a
href="75ce1d5c49"><code>75ce1d5</code></a></li>
<li>[meta] add <code>safe-publish-latest</code> <a
href="dcf49ce85a"><code>dcf49ce</code></a></li>
<li>[Tests] add <code>npm run posttest</code> <a
href="75dd8fd6ce"><code>75dd8fd</code></a></li>
<li>[Dev Deps] update <code>tape</code> <a
href="3aec0386dc"><code>3aec038</code></a></li>
<li>[Tests] skip unsupported schemes <a
href="703c83ea72"><code>703c83e</code></a></li>
<li>[Tests] node &lt; 6 lacks array <code>includes</code> <a
href="3aa43cfbc1"><code>3aa43cf</code></a></li>
<li>[Dev Deps] fix eslint range <a
href="98d4e0d7ff"><code>98d4e0d</code></a></li>
</ul>
<h2><a
href="https://github.com/browserify/browserify-sign/compare/v4.2.0...v4.2.1">v4.2.1</a>
- 2020-08-04</h2>
<h3>Merged</h3>
<ul>
<li>bump elliptic <a
href="https://redirect.github.com/browserify/browserify-sign/pull/58"><code>[#58](https://github.com/crypto-browserify/browserify-sign/issues/58)</code></a></li>
</ul>
<h2><a
href="https://github.com/browserify/browserify-sign/compare/v4.1.0...v4.2.0">v4.2.0</a>
- 2020-05-18</h2>
<h3>Merged</h3>
<ul>
<li>switch to safe buffer <a
href="https://redirect.github.com/browserify/browserify-sign/pull/53"><code>[#53](https://github.com/crypto-browserify/browserify-sign/issues/53)</code></a></li>
</ul>
<h2><a
href="https://github.com/browserify/browserify-sign/compare/v4.0.4...v4.1.0">v4.1.0</a>
- 2020-05-05</h2>
<h3>Merged</h3>
<ul>
<li>update deps, modernise usage, use readable-stream <a
href="https://redirect.github.com/browserify/browserify-sign/pull/49"><code>[#49](https://github.com/crypto-browserify/browserify-sign/issues/49)</code></a></li>
</ul>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="4af5a90bf8"><code>4af5a90</code></a>
v4.2.2</li>
<li><a
href="3aec0386dc"><code>3aec038</code></a>
[Dev Deps] update <code>tape</code></li>
<li><a
href="85994cd634"><code>85994cd</code></a>
[Fix] properly check the upper bound for DSA signatures</li>
<li><a
href="9ac5a5eaaa"><code>9ac5a5e</code></a>
[meta] fix package.json indentation</li>
<li><a
href="dcf49ce85a"><code>dcf49ce</code></a>
[meta] add <code>safe-publish-latest</code></li>
<li><a
href="44181838e7"><code>4418183</code></a>
[meta] add <code>npmignore</code> and <code>auto-changelog</code></li>
<li><a
href="8767739a45"><code>8767739</code></a>
[Fix] <code>sign</code>: throw on unsupported padding scheme</li>
<li><a
href="5f6fb17559"><code>5f6fb17</code></a>
[Tests] log when openssl doesn't support cipher</li>
<li><a
href="f5f17c27f9"><code>f5f17c2</code></a>
[Tests] handle openSSL not supporting a scheme</li>
<li><a
href="d845d855de"><code>d845d85</code></a>
[Tests] migrate from travis to github actions</li>
<li>Additional commits viewable in <a
href="https://github.com/crypto-browserify/browserify-sign/compare/v4.0.4...v4.2.2">compare
view</a></li>
</ul>
</details>
<details>
<summary>Maintainer changes</summary>
<p>This version was pushed to npm by <a
href="https://www.npmjs.com/~ljharb">ljharb</a>, a new releaser for
browserify-sign since your current version.</p>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=browserify-sign&package-manager=npm_and_yarn&previous-version=4.0.4&new-version=4.2.2)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)
You can disable automated security fix PRs for this repo from the
[Security Alerts
page](https://github.com/facebook/react/network/alerts).

</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-11-01 15:18:54 -04:00
Christoph Nakazawa
d947c2f110 Allow useEffect(fn, undefined) in react-hooks/exhaustive-deps. (#27525)
## Summary

There is a bug in the `react-hooks/exhaustive-deps` rule that forbids
the dependencies argument from being `undefined`. It triggers the error
that the dependency list is not an array literal. This makes sense in
pre ES5 strict-mode environments as undefined could be redefined, but
should not be a concern in today's JS environments.

**Justification:**
* The deps argument being undefined (for `useEffect` calls etc.) is a
valid use case for hooks that should re-run on every render.
* The deps argument being omitted is considered a valid use case by the
`exhaustive-deps` rule already.
* The TypeScript type definitions support passing `undefined` because
hooks are typed as `useEffect(effect: EffectCallback, deps?:
DependencyList): void;`.
* Since omitting an argument and passing `undefined` are considered
equivalent, this eslint rule should consider them as equivalent too.

Further, I accidentally forgot passing a dependency array to `useEffect`
in code that I shared on Twitter, and people started abusing me about
it. I'd like to create an eslint rule for my projects that requires me
to provide a dep argument in all cases (`undefined`, `[]` or the list of
dependencies) so that I can avoid such problems in the future. This
would also force me to always think about the dependencies instead of
accidentally forgetting them and my hook running on each render. In an
audit of my own codebase I had about 3% of hooks that I want to run on
each render, and adding an explicit `undefined` seems reasonable in
those situations.

It could be argued this could be an option or part of the
`exhaustive-deps` rule, but it's probably better to merge this PR, make
a release and see if my custom eslint rule gains traction in the future.

## How did you test this change?

* Added a test.
* `yarn test ESLintRuleExhaustiveDeps-test`
* Careful code inspection.
2023-11-01 15:05:55 -04:00
Andrew Clark
77c4ac2ce8 [useFormState] Allow sync actions (#27571)
Updates useFormState to allow a sync function to be passed as an action.

A form action is almost always async, because it needs to talk to the
server. But since we support client-side actions, too, there's no reason
we can't allow sync actions, too.

I originally chose not to allow them to keep the implementation simpler
but it's not really that much more complicated because we already
support this for actions passed to startTransition. So now it's
consistent: anywhere an action is accepted, a sync client function is a
valid input.
2023-10-31 23:32:31 -04:00
Josh Story
08a39539fc [Flight][Reply] Close Response after creating root chunk (#27634)
creating the root after closing the response can lead to a promise that
never rejects. This is not intended use of the decodeReply API but if
pathalogical cases where you pass a raw FormData into this fucntion with
no zero chunk it can hang forever. This reordering causes a connection
error instead

---------

Co-authored-by: Zack Tanner <zacktanner@gmail.com>
2023-10-31 18:31:10 -07:00
Sourabh singh
ca16c26356 validateDOMNesting: Allow hr as child of select (#27632)
fix #27572

---------

Co-authored-by: Sophie Alpert <git@sophiebits.com>
2023-10-31 14:43:16 -07:00
Ruslan Lesiutin
0c6348758f refactor[scripts/prettier]: respect .prettierignore when resolving js files via glob (#27627)
This script is used on CI in `yarn_lint` job. With current `glob` call
settings, it includes a bunch of build files, which are actually ignored
by listing them in `.prettierignore`. This check is not failing only
because there is no build step before it.

If you run `node ./scripts/prettier/index` with build files present, you
will see a bunch of files listed as non-formatted. These changes add a
simple logic to include all paths listed in `.prettierignore` to ignore
list of `glob` call with transforming them from gitignore-style to
glob-style.

This should unblock CI for https://github.com/facebook/react/pull/27612,
where `flow-typed` directory will be added, turned out that including it
in `.prettierignore` is not enough.
2023-10-30 15:32:40 +00:00
AZM
0965fbcab3 Update utils-test.js desciption (#27624)
<!--
  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
   Updated the typo in test description
<!--
Explain the **motivation** for making this change. What existing problem
does the pull request solve?
-->

## How did you test this change?
NA, correct test description improves readability of the code and
confusion for anyone who is new to the codebase.
<!--
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.
  
-->
2023-10-30 11:40:18 +00:00
Josh Story
3e09c27b88 [Float][Fiber] Fixes incorrect boolean logic around loading states for stylesheets (#27610)
the loading states of stylesheets found in the DOM during preinit should
be assumed to be loaded
2023-10-27 08:50:40 -07:00
dependabot[bot]
8039e6d0b9 Bump lodash from 4.17.4 to 4.17.21 in /fixtures/attribute-behavior (#27592)
[//]: # (dependabot-start)
⚠️  **Dependabot is rebasing this PR** ⚠️ 

Rebasing might not happen immediately, so don't worry if this takes some
time.

Note: if you make any changes to this PR yourself, they will take
precedence over the rebase.

---

[//]: # (dependabot-end)

Bumps [lodash](https://github.com/lodash/lodash) from 4.17.4 to 4.17.21.
<details>
<summary>Commits</summary>
<ul>
<li><a
href="f299b52f39"><code>f299b52</code></a>
Bump to v4.17.21</li>
<li><a
href="c4847ebe7d"><code>c4847eb</code></a>
Improve performance of <code>toNumber</code>, <code>trim</code> and
<code>trimEnd</code> on large input strings</li>
<li><a
href="3469357cff"><code>3469357</code></a>
Prevent command injection through <code>_.template</code>'s
<code>variable</code> option</li>
<li><a
href="ded9bc6658"><code>ded9bc6</code></a>
Bump to v4.17.20.</li>
<li><a
href="63150ef764"><code>63150ef</code></a>
Documentation fixes.</li>
<li><a
href="00f0f62a97"><code>00f0f62</code></a>
test.js: Remove trailing comma.</li>
<li><a
href="846e434c7a"><code>846e434</code></a>
Temporarily use a custom fork of <code>lodash-cli</code>.</li>
<li><a
href="5d046f39cb"><code>5d046f3</code></a>
Re-enable Travis tests on <code>4.17</code> branch.</li>
<li><a
href="aa816b36d4"><code>aa816b3</code></a>
Remove <code>/npm-package</code>.</li>
<li><a
href="d7fbc52ee0"><code>d7fbc52</code></a>
Bump to v4.17.19</li>
<li>Additional commits viewable in <a
href="https://github.com/lodash/lodash/compare/4.17.4...4.17.21">compare
view</a></li>
</ul>
</details>
<details>
<summary>Maintainer changes</summary>
<p>This version was pushed to npm by <a
href="https://www.npmjs.com/~bnjmnt4n">bnjmnt4n</a>, a new releaser for
lodash since your current version.</p>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=lodash&package-manager=npm_and_yarn&previous-version=4.17.4&new-version=4.17.21)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)
You can disable automated security fix PRs for this repo from the
[Security Alerts
page](https://github.com/facebook/react/network/alerts).

</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-10-26 09:48:28 -04:00
dependabot[bot]
54ea446971 Bump lodash from 4.17.4 to 4.17.21 in /fixtures/packaging/systemjs-builder/prod (#27593)
Bumps [lodash](https://github.com/lodash/lodash) from 4.17.4 to 4.17.21.
<details>
<summary>Commits</summary>
<ul>
<li><a
href="f299b52f39"><code>f299b52</code></a>
Bump to v4.17.21</li>
<li><a
href="c4847ebe7d"><code>c4847eb</code></a>
Improve performance of <code>toNumber</code>, <code>trim</code> and
<code>trimEnd</code> on large input strings</li>
<li><a
href="3469357cff"><code>3469357</code></a>
Prevent command injection through <code>_.template</code>'s
<code>variable</code> option</li>
<li><a
href="ded9bc6658"><code>ded9bc6</code></a>
Bump to v4.17.20.</li>
<li><a
href="63150ef764"><code>63150ef</code></a>
Documentation fixes.</li>
<li><a
href="00f0f62a97"><code>00f0f62</code></a>
test.js: Remove trailing comma.</li>
<li><a
href="846e434c7a"><code>846e434</code></a>
Temporarily use a custom fork of <code>lodash-cli</code>.</li>
<li><a
href="5d046f39cb"><code>5d046f3</code></a>
Re-enable Travis tests on <code>4.17</code> branch.</li>
<li><a
href="aa816b36d4"><code>aa816b3</code></a>
Remove <code>/npm-package</code>.</li>
<li><a
href="d7fbc52ee0"><code>d7fbc52</code></a>
Bump to v4.17.19</li>
<li>Additional commits viewable in <a
href="https://github.com/lodash/lodash/compare/4.17.4...4.17.21">compare
view</a></li>
</ul>
</details>
<details>
<summary>Maintainer changes</summary>
<p>This version was pushed to npm by <a
href="https://www.npmjs.com/~bnjmnt4n">bnjmnt4n</a>, a new releaser for
lodash since your current version.</p>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=lodash&package-manager=npm_and_yarn&previous-version=4.17.4&new-version=4.17.21)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)
You can disable automated security fix PRs for this repo from the
[Security Alerts
page](https://github.com/facebook/react/network/alerts).

</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-10-26 09:48:05 -04:00
dependabot[bot]
97b1e01824 Bump lodash from 4.17.15 to 4.17.21 in /fixtures/art (#27588)
Bumps [lodash](https://github.com/lodash/lodash) from 4.17.15 to
4.17.21.
<details>
<summary>Commits</summary>
<ul>
<li><a
href="f299b52f39"><code>f299b52</code></a>
Bump to v4.17.21</li>
<li><a
href="c4847ebe7d"><code>c4847eb</code></a>
Improve performance of <code>toNumber</code>, <code>trim</code> and
<code>trimEnd</code> on large input strings</li>
<li><a
href="3469357cff"><code>3469357</code></a>
Prevent command injection through <code>_.template</code>'s
<code>variable</code> option</li>
<li><a
href="ded9bc6658"><code>ded9bc6</code></a>
Bump to v4.17.20.</li>
<li><a
href="63150ef764"><code>63150ef</code></a>
Documentation fixes.</li>
<li><a
href="00f0f62a97"><code>00f0f62</code></a>
test.js: Remove trailing comma.</li>
<li><a
href="846e434c7a"><code>846e434</code></a>
Temporarily use a custom fork of <code>lodash-cli</code>.</li>
<li><a
href="5d046f39cb"><code>5d046f3</code></a>
Re-enable Travis tests on <code>4.17</code> branch.</li>
<li><a
href="aa816b36d4"><code>aa816b3</code></a>
Remove <code>/npm-package</code>.</li>
<li><a
href="d7fbc52ee0"><code>d7fbc52</code></a>
Bump to v4.17.19</li>
<li>Additional commits viewable in <a
href="https://github.com/lodash/lodash/compare/4.17.15...4.17.21">compare
view</a></li>
</ul>
</details>
<details>
<summary>Maintainer changes</summary>
<p>This version was pushed to npm by <a
href="https://www.npmjs.com/~bnjmnt4n">bnjmnt4n</a>, a new releaser for
lodash since your current version.</p>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=lodash&package-manager=npm_and_yarn&previous-version=4.17.15&new-version=4.17.21)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)
You can disable automated security fix PRs for this repo from the
[Security Alerts
page](https://github.com/facebook/react/network/alerts).

</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-10-26 09:47:51 -04:00
dependabot[bot]
de49d83f30 Bump lodash from 4.17.4 to 4.17.21 in /fixtures/expiration (#27591)
Bumps [lodash](https://github.com/lodash/lodash) from 4.17.4 to 4.17.21.
<details>
<summary>Commits</summary>
<ul>
<li><a
href="f299b52f39"><code>f299b52</code></a>
Bump to v4.17.21</li>
<li><a
href="c4847ebe7d"><code>c4847eb</code></a>
Improve performance of <code>toNumber</code>, <code>trim</code> and
<code>trimEnd</code> on large input strings</li>
<li><a
href="3469357cff"><code>3469357</code></a>
Prevent command injection through <code>_.template</code>'s
<code>variable</code> option</li>
<li><a
href="ded9bc6658"><code>ded9bc6</code></a>
Bump to v4.17.20.</li>
<li><a
href="63150ef764"><code>63150ef</code></a>
Documentation fixes.</li>
<li><a
href="00f0f62a97"><code>00f0f62</code></a>
test.js: Remove trailing comma.</li>
<li><a
href="846e434c7a"><code>846e434</code></a>
Temporarily use a custom fork of <code>lodash-cli</code>.</li>
<li><a
href="5d046f39cb"><code>5d046f3</code></a>
Re-enable Travis tests on <code>4.17</code> branch.</li>
<li><a
href="aa816b36d4"><code>aa816b3</code></a>
Remove <code>/npm-package</code>.</li>
<li><a
href="d7fbc52ee0"><code>d7fbc52</code></a>
Bump to v4.17.19</li>
<li>Additional commits viewable in <a
href="https://github.com/lodash/lodash/compare/4.17.4...4.17.21">compare
view</a></li>
</ul>
</details>
<details>
<summary>Maintainer changes</summary>
<p>This version was pushed to npm by <a
href="https://www.npmjs.com/~bnjmnt4n">bnjmnt4n</a>, a new releaser for
lodash since your current version.</p>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=lodash&package-manager=npm_and_yarn&previous-version=4.17.4&new-version=4.17.21)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)
You can disable automated security fix PRs for this repo from the
[Security Alerts
page](https://github.com/facebook/react/network/alerts).

</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-10-26 09:43:55 -04:00
dependabot[bot]
a82ff4c985 Bump lodash from 4.17.15 to 4.17.21 (#27587)
Bumps [lodash](https://github.com/lodash/lodash) from 4.17.15 to
4.17.21.
<details>
<summary>Commits</summary>
<ul>
<li><a
href="f299b52f39"><code>f299b52</code></a>
Bump to v4.17.21</li>
<li><a
href="c4847ebe7d"><code>c4847eb</code></a>
Improve performance of <code>toNumber</code>, <code>trim</code> and
<code>trimEnd</code> on large input strings</li>
<li><a
href="3469357cff"><code>3469357</code></a>
Prevent command injection through <code>_.template</code>'s
<code>variable</code> option</li>
<li><a
href="ded9bc6658"><code>ded9bc6</code></a>
Bump to v4.17.20.</li>
<li><a
href="63150ef764"><code>63150ef</code></a>
Documentation fixes.</li>
<li><a
href="00f0f62a97"><code>00f0f62</code></a>
test.js: Remove trailing comma.</li>
<li><a
href="846e434c7a"><code>846e434</code></a>
Temporarily use a custom fork of <code>lodash-cli</code>.</li>
<li><a
href="5d046f39cb"><code>5d046f3</code></a>
Re-enable Travis tests on <code>4.17</code> branch.</li>
<li><a
href="aa816b36d4"><code>aa816b3</code></a>
Remove <code>/npm-package</code>.</li>
<li><a
href="d7fbc52ee0"><code>d7fbc52</code></a>
Bump to v4.17.19</li>
<li>Additional commits viewable in <a
href="https://github.com/lodash/lodash/compare/4.17.15...4.17.21">compare
view</a></li>
</ul>
</details>
<details>
<summary>Maintainer changes</summary>
<p>This version was pushed to npm by <a
href="https://www.npmjs.com/~bnjmnt4n">bnjmnt4n</a>, a new releaser for
lodash since your current version.</p>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=lodash&package-manager=npm_and_yarn&previous-version=4.17.15&new-version=4.17.21)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)
You can disable automated security fix PRs for this repo from the
[Security Alerts
page](https://github.com/facebook/react/network/alerts).

</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-10-26 09:43:31 -04:00
Sebastian Markbåge
8c8ee9ee61 [Fizz] Pass task.childIndex in retryReplayTask (#27594)
This was missed that we track the child index on the task. The
equivalent in retryRenderTask already has this.

The effect is that a lazy node that suspends gets its child index reset
to -1 even though it should resume in the index it left off.
2023-10-26 02:20:24 -04:00
Jan Kassens
97047a810c Revert "Build: use content hash for facebook-react-native build" (#27584)
Reverts facebook/react#27577.

We also sync React Native OSS bundles which means this didn't work as
hoped unless we abandon the commit hash in OSS which seems useful.
2023-10-25 15:07:17 -04:00
Josh Story
a9985529f1 [Fizz] Do not reinsert stylesheets after initial insert (#27586)
The loading state tracking for suspensey CSS is too complicated. Prior
to this change it had a state it could enter into where a stylesheet was
already in the DOM but the loading state did not know it was inserted
causing a later transition to try to insert it again.

This fix is to add proper tracking of insertions on the codepaths that
were missing it. It also modifies the logic of when to suspend based on
whether the stylesheet has already been inserted or not.

This is not 100% correct semantics however because a prior commit could
have inserted a stylesheet and a later transition should ideally be able
to wait on that load before committing. I haven't attempted to fix this
yet however because the loading state tracking is too complicated as it
is and requires a more thorough refactor. Additionally it's not
particularly valuable to delay a transition on a loading stylesheet when
a previous commit also relied on that stylesheet but didn't wait for it
b/c it was sync. I will follow up with an improvement PR later

fixes: https://github.com/facebook/react/issues/27585
2023-10-25 11:51:01 -07:00
Jan Kassens
51ffd3564f Build: use content hash for facebook-react-native build (#27577)
Similar to #26734, this switches the RN builds for Meta to a content
hash instead of git commit number to make the builds reproducible and
avoid creating sync commits if the bundled content didn't change.
2023-10-25 09:50:15 -04:00
Sebastian Markbåge
960ed6ea43 [Flight] Aborting with a postpone instance as a reason should postpone remaining holes (#27576)
This lets you abort with postponing semantics.
2023-10-24 13:41:28 -07:00
Sathya Gunasekaran
3d3ad1b9ef [LeaveSSA] Process all phis in a block
I don't know if it's possible to write a test for this as I can't seem to get 
the codegen to change. 

For the following testcase: ``` function useFoo(setOne) {   let x;   let y;   if 
(setOne) {     x = 1;     y = 3;   } else {     x = 2;     y = 5;   } 

return { x, y }; } ``` 

The LeaveSSA changes from: ``` .... bb1 (block):   predecessor blocks: bb2 bb3   
x$36:TPrimitive: phi(bb2: x$19, bb3: x$19)   y$21[8:14]:TPrimitive: phi(bb2: 
y$21, bb3: y$21) 

... ``` 

to ``` ... bb1 (block):   predecessor blocks: bb2 bb3   x$36:TPrimitive: 
phi(bb2: x$19, bb3: x$19)   y$38:TPrimitive: phi(bb2: y$21, bb3: y$21) ... ``` 

Notice how `y`'s reassignment got skipped previously.
2023-10-24 16:09:08 +01:00
Joe Savona
3571dfa056 [be] remove dead code in InferReactiveScopeVariables 2023-11-01 17:13:06 -07:00
Joe Savona
3e157bbc27 Propagate reactivity to other operands accounting for mutable ranges
Previously if any operand was reactive, we transferred that reactivity to other 
operands that had a mutable effect (capture, conditionally mutate, mutate, or 
store). But a value can be captured without ever being modified again. This PR 
updates the logic to only transfer reactivity among operands that are actually 
mutable at the given instruction, based on the mutable range. This is strictly 
more precise.
2023-11-01 17:13:05 -07:00
Joe Savona
b34172c11e Reactivity inference is single-pass when no loops
We can complete in a single-pass if there are no loops, as a performance 
optimization.
2023-11-01 17:13:04 -07:00
Joe Savona
3ab47ac6bd Replace InferReactiveIdentifiers w new inference
This PR adds one remaining feature to InferReactivePlaces: tracking indirections 
like LoadLocal, PropertyLoad, and similar. Consider something like: 

``` 

// INPUT 

x.push(reactiveValue); 

// HIR 

t0 = LoadLocal 'x' 

t1 = PropertyLoad t0, 'push' 

t2 = LoadLocal 'reactiveValue' // reactive 

t3 = CallExpression mutate t0 . read t1 ( read t2 ) 

``` 

Because a reactive value (`t2`) flows into `t0`, we want to record t0 as 
reactive as well. But that's just the temporary for `LoadLocal 'x'` - what's 
really happening is that from this point, `x` is reactive. 
InferReactiveIdentifiers tracked this, and now that logic is ported into 
InferReactivePlaces as well. That lets us remove all the actual inference from 
InferReactiveIdentifiers.
2023-11-01 17:13:04 -07:00
Joe Savona
8610533ed1 Infer reactive control dependencies
Updates `InferReactivePlaces` to infer control dependencies. We build on the 
formal definition of control dependencies, which is that statement S2 is 
control-dependent on statement S1 if S1 is in the post-dominance-frontier of S2. 
Intuitively, if S1 decides whether S2 is reached or not, then S1 is a control 
dependency of S2. The post dominance frontier of a given statement S is the set 
of statements which may or may not reach S, and captures the intuitive notion. 

We take advantage of phis: phis are the point where a variable may have multiple 
values depending on the path we took. If a phi is not already known to be 
reactive from data dependencies we check for control dependencies. Specifically 
we look at each phi operand. We check if the block that the operand came from 
has any reactive control dependencies, and if so we mark the phi itself as 
reactive. 

The post-dominance-frontier (PDF) algorithm requires walking the post-dominator 
tree a bunch, so we cache the PDF of blocks so that we don't have to recalculate 
on subsequent iterations. 

In addition, `InferReactiveIdentifiers` now uses the _union_ of its own 
inference plus the new `InferReactivePlaces` output when deciding what 
identifiers are reactive. This ensures that control dependencies are recorded 
correctly, fixing the previous test cases. The next diff adds the remaining 
features to InferReactivePlaces so that it can fully replace 
InferReactiveIdentifiers.
2023-11-01 17:13:03 -07:00
Joe Savona
d5c3fb87e6 HIR-based reactive identifier analysis
See context from #2187 for background about control dependencies. 

Our current `PruneNonReactiveIdentifiers` pass runs on ReactiveFunction, after 
scope construction, and removes scope dependencies that aren't reactive. It 
works by first building up a set of reactive identifiers in 
`InferReactiveIdentifiers`, then walking the ReactiveFunction and pruning any 
scope dependencies that aren't in that set. 

The challenge is control variables, as demonstrated by the test cases in #2184. 
`InferReactiveIdentifiers` runs against ReactiveFunction, and when we initially 
wrote it we didn't consider control variables. To handle control variables we 
really need to use precise control- & data-flow analysis, which is much easier 
with HIR. 

This PR adds the start of `InferReactivePlaces`, which annotates each `Place` 
with whether it is reactive or not. This allows the annotation to survive 
LeaveSSA, which swaps out the identifiers of places but leaves other properties 
as-is. This version does _not_ yet handle control variables, but it's already 
more precise than our existing inference. In our current inference, if `x` is 
ever assigned a reactive value, then all `x`s are marked reactive. In our new 
inference, each instance of `x` (each Place) gets a separate flag based on 
whether x can actually be reactive at that point in the program. 

There are two main next steps (in follow-up PRs): 

* Update the mechanism by which we prune non-reactive dependencies from scopes. 

* Handle control variables. I think we may be able to use dominator trees to 
figure out the set of basic blocks whose reachability is gated by the control 
variables. This should clearly work for if/else and switch, as for loops i'm not 
sure but intuitively it seems right.
2023-11-01 17:13:02 -07:00
Joe Savona
748859a00e Add reactive flag to Place
This is part of a stack for inferring variables which are reactive via *control 
dependencies* as opposed to a data dependency. In compiler engineering, a 
statement S2 is control-dependent on statement S1 if S1 is in the post-dominance 
frontier of S2. Stated more intuitively: if S1 decides whether or not S2 is 
reached, then S1 is a control dependency of S2. 

As a start, we add `Place.reactive: boolean` so that individual places can track 
whether they are reactive or not. This lets us do fine-grained reactivity 
inference on the control-flow graph, even taking into account different SSA 
instances of a variable, so that we can say that a particular SSA version of `x` 
is reactive, while other "versions" of x (due to reassignment) are not.
2023-11-01 17:13:01 -07:00
Lauren Tan
5cdfa7cdc4 [feedback] Don't skip copying dist 2023-11-01 13:45:50 -04:00
Lauren Tan
c289d098d7 [babel] Rename useMemoCacheSource to enableUseMemoCachePolyfill 2023-11-01 13:28:18 -04:00
Lauren Tan
139336b87c [feedback] Specify react dep for react-forget-runtime 2023-11-01 13:12:09 -04:00
Lauren Tan
7042983f69 [feedback] Add changelog to build 2023-10-31 18:31:09 -04:00
Lauren Tan
8860faa65c [feedback] Add script to copy forget-feedback to new repo 2023-10-31 17:14:19 -04:00
Lauren Tan
776f2148b4 [feedback] More efficient userspace impl for uMC 2023-10-31 13:17:40 -04:00
Lauren Tan
a0de8e6d2d [babel] Disable ts declaration maps
This was unnecessary, switching it back to disabled
2023-10-31 13:06:19 -04:00
Lauren Tan
e4acd448f6 [feedback] Add script to bundle for oss 2023-10-31 12:42:39 -04:00
Lauren Tan
0a7bb7ac7a [babel] Clean up import logic a bit
Addressing feedback from #2218
2023-10-31 12:16:34 -04:00
Lauren Tan
847a6f0a09 [feedback] Make babel/types a dep not a peerDep 2023-10-31 12:16:33 -04:00
Lauren Tan
5ebc9fe388 [feedback] Add github action to run e2e test 2023-10-31 12:16:33 -04:00
Lauren Tan
3246dc641f [feedback] Add testapp with e2e test
Adds a toy next.js app which doesn't do anything interesting. It has a single 
e2e test which can be run via `npm run test:e2e`, which checks if a `$` variable 
was injected by the compiler, as a sanity check whenever we commit a new version 
of the compiler to the external repo.
2023-10-31 12:16:32 -04:00
Lauren Tan
ac170f4f0d [babel] Allow userspace useMemoCache
Not every consumer of Forget will be able to run an experimental version of 
React. In the meantime before useMemoCache is stable, provide a way for OSS to 
pass in a userspace impl.
2023-10-31 12:16:31 -04:00
Mofei Zhang
c7c57ec531 [playground] QoL use webpack to bundle monaco-editor's loader
--- 

This lets us load playground locally, entirely offline (e.g. on an airplane, 
when a cdn is down, at ReactAdvanced, etc) 

Before: 

See external script link 

<img width="691" alt="image" 
src="https://github.com/facebook/react-forget/assets/34200447/85500e86-c1a5-4dff-bdcd-58db0d6fd453"> 

Now: 

No external script 

<img width="476" alt="image" 
src="https://github.com/facebook/react-forget/assets/34200447/fdcbea09-0b5f-42e3-9310-35d8d1d726b7">
2023-10-30 14:53:00 -04:00
Mofei Zhang
16bef168c1 [playground] Move Editor/index for next PR (dynamic import) 2023-10-30 14:53:00 -04:00
Lauren Tan
0841caab8e [rollup] Include typescript definitions in build
Emit our TypeScript definitions as well in the build so things like options have 
typechecking
2023-10-30 13:58:03 -04:00
Lauren Tan
52afd8a566 [ext-preview] Inline @babel/generator
Turns out we were only using this in PrintHIR and in the logger, so it should be 
safe to inline and makes installing the plugin for external collaborators a 
little easier. 

I'm assuming inlining this is ok because we only need to defer to the host's 
Babel version(s) when it affects parsing or the final codegen output, hence why 
we continue to no-inline @babel/types – as it is responsible for creating AST 
nodes during codegen
2023-10-30 13:58:02 -04:00
Mofei Zhang
e2836eec5b [bugfix] do not hoist computed memberpaths in lambdas 2023-10-30 12:56:50 -04:00
Mofei Zhang
3e812df89c [repro] Test case for more variable naming collision bugs
--- 

bug repro from @JacksonGL 

(we currently bailout for references to `useMemoCache`, but not other variables 
that may collide with codegenned ones). 

``` 

% yarn sprout --filter 

yarn run v1.22.19 

$ node ../sprout/dist/main.js --filter 

FAIL  todo 

Failures: 

FAIL: todo 

Difference in forget and non-forget results. 

Expected result: { 

"kind": "ok", 

"value": "0", 

"logs": [ 

"'module_$'", 

"'module_t0'", 

"'module_c_0'" 

] 

} 

Found: { 

"kind": "ok", 

"value": "0", 

"logs": [ 

"[ 0, 0 ]", 

"0", 

"true" 

] 

} 

```
2023-10-30 12:01:24 -04:00
Sathya Gunasekaran
f648e4ce85 [test/react] Turn on react tests in CI 2023-10-25 12:39:20 +01:00
Sathya Gunasekaran
51baf5807e [test/react] Fix github workflow
The flattening broke the shell script because the directory structure changed. 

Instead of depending on a flaky shell script, this PR encodes the commands as 
part of the github workflow.
2023-10-25 12:36:55 +01:00
Lauren Tan
419310cd15 Bundle babel-plugin-react-forget with rollup
Attempt to bundle the plugin with rollup instead of just tsc. I'm intentionally 
not inlining babel related modules, as we should ideally rely on the host 
environment's version instead
2023-10-27 14:07:56 -04:00
Lauren Tan
473237ba1f Remove prettier from babel-plugin as dependency
We can now fully remove prettier from babel-plugin-react-forget. I moved it to 
devDependencies instead, to make the rollup build simpler and so we can continue 
to prettify our internal source code.
2023-10-27 14:07:56 -04:00
Lauren Tan
c72673bd8f [fixtures] Run prettier after babel-plugin
This moves prettier formatting into fixture-test-utils instead, so we can remove 
the dependency on prettier in the babel plugin. I want to do this because I 
don't want to include prettier in the rolledup artifact when we build the babel 
plugin.
2023-10-27 14:07:55 -04:00
Andrew Clark
b8e47d988e Bugfix: useFormState queues actions in wrong order (#27570)
I neglected to update the "last" pointer of the action queue. Since the
queue is circular, rather than dropping the update, the effect was to
add the update to the front of the queue instead of the back. I didn't
notice earlier because in my demos/tests, the actions would either
resolve really quickly or the actions weren't order dependent (like
incrementing a counter).
2023-10-23 17:52:15 -04:00
Sebastian Markbåge
05fbd1aab0 [Fizz] Postponing in the shell (#27569)
When we postpone a prerender in the shell, we should just leave an empty
prelude and resume from the root. While preserving any options passed
in.

Since we haven't flushed anything we can't assume we've already emitted
html/body tags or any resources tracked in the resumable state. This
introduces a resetResumableState function to reset anything we didn't
flush.

This is a bit hacky. Ideally, we probably shouldn't have tracked it as
already happened until it flushed or something like that.

Basically, it's like restarting the prerender with the same options and
then immediately aborting. When we add the preload headers, we'd track
those as preload() being emitted after the reset and so they get readded
to the resumable state in that case.
2023-10-23 15:53:59 -04:00
Andrew Clark
779d59374e useDeferredValue has higher priority than partial hydration (#27550)
By default, partial hydration is given the lowest possible priority,
because until a tree is updated, the server-rendered HTML is assumed to
match the final resolved HTML.

However, this isn't completely true because a component may choose to
"upgrade" itself upon hydration. The simplest example is a component
that calls setState in a useEffect to switch to a richer implementation
of the UI. Another example is a component that doesn't have a server-
rendered implementation, so it intentionally suspends to force a client-
only render.

useDeferredValue is an example, too: the server only renders the first
pass (the initialValue) argument, and relies on the client to upgrade to
the final value.

What we should really do in these cases is emit some information into
the Fizz stream so that Fiber knows to prioritize the hydration of
certain trees. We plan to add a mechanism for this in the future.

In the meantime, though, we can at least ensure that the priority of the
upgrade task is correct once it's "discovered" during hydration. In this
case, the priority of the task spawned by useDeferredValue should have
Transition priority, not Offscreen priority.
2023-10-23 13:48:48 -04:00
Sathya Gunasekaran
ad1fe50546 [playground] Turn on Forget
Runs Forget on the playground, so we can dogfood Forget and experiment with 
improvements to UX. 

Opts out of compiling the layout page because thats run on the server which 
doesn't seem to have access to useMemoCache.
2023-10-23 15:41:01 +01:00
Sathya Gunasekaran
1138ef00e3 [playground] Force nextjs to use experimental react
These experimental features aren't used by the playground, but turning it on 
forces nextjs to use experimental react which has the useMemoCache hook.
2023-10-23 15:41:00 +01:00
Sathya Gunasekaran
48d465eb22 [playground] Upgrade to latest nextjs 2023-10-23 15:41:00 +01:00
Sathya Gunasekaran
23a226227f Remove use of prettier in babel-plugin-react-forget
This kept throwing warnings in our playground build because prettier uses node 
APIs and is not meant to be bundled and run on the browser. 

There's a separate standalone version that runs on the browser. A follow on PR 
will make the playground use that but this PR is a first step towards using a 
standalone prettier.
2023-10-25 15:40:31 +01:00
Andrew Clark
6db7f4209e Bugfix: useDeferredValue loop during popstate transition (#27559)
During a popstate event, we attempt to render updates synchronously even
if they are transitions, to preserve scroll position if possible. We do
this by entangling the transition lane with the Sync lane.

However, if rendering the transition spawns additional transition
updates (e.g. a setState inside useEffect), there's no reason to render
those synchronously, too. We should use the normal transition behavior.

This fixes an issue where useDeferredValue during a popstate event would
spawn a transition update that was itself also synchronous.
2023-10-21 12:11:25 -04:00
Josh Story
90172d12e8 [Flight] Cleanup turbopack tests (#27552)
Renames turbopack flight test files. removes tests which are primarily
testing internal implemenation behavior of Flight Client itself
2023-10-20 23:21:31 -07:00
Matt Carroll
b9244f79ba Add initial canary changelog (#27504) 2023-10-20 19:11:07 -07:00
Jung Yujun
8c85b02996 [Fizz] Optimize end tags chunks (#27522)
Implements `endChunkForTag` to make writing end tags faster
2023-10-20 15:34:21 -07:00
Jan Kassens
d803f519ea Upgrade to Flow 0.219.0 (#27542)
This upgrade made the `React$Element` type opaque, which is good for
product code where accessing props of elements is code smell, but React
needs to use that internally. I overrode the type to restore it.
2023-10-20 11:09:44 -04:00
Lauren Tan
b049c14bb3 Repro of hoisting bug
Adds a test case reproducing an issue with hoisting. This seems like a case 
where hoisting was incorrectly applied as this example doesn't require it
2023-10-20 11:34:41 +01:00
Josh Story
3a1967b7d5 [Flight] Expose encodeReply from ReactFlightDOMClientEdge (#27551)
Adds encodeReply to ReactFlightDOMClientEdge in webpack and turbopack
bindings
2023-10-19 17:24:47 -07:00
Joe Savona
f8cee28f1d Retain minimal variable declarations in DCE
Currently DCE can remove variable declarations that are unused, ie where all 
control-flow paths to usage of the variable are overwritten by a reassignment. 
We then have to reconstruct the original variable declaration at the appropriate 
block scope during LeaveSSA, which is complex and can actually be incorrect in 
some cases. 

This PR updates to ensure that DCE will not remove the original variable 
declaration for any variable that is used (even in the case of always being 
reassigned before use). The main changes are: 

* DCE retains variable declarations, but if a variable declaration is always 
shadowed by reassignments then DCE will rewrite StoreLocal -> DeclareLocal so 
that it can DCE the unused initial value. 

* BuildHIR now has to change its handling for reassignment destructure 
instructions with nesting. Nesting uses a temporary which would appear as a 
declaration of a new variable, which is incompatible with other reassignments. 
See comments in the file. 

* LeaveSSA is quite a bit simpler now, since we never need to reconstruct a 
declaration.
2023-10-19 22:08:15 +01:00
Sebastian Markbåge
f172fa7461 [Flight] Detriplicate Objects (#27537)
Now that we no longer support Server Context, we can now deduplicate
objects. It's not completely safe for useId but only in the same way as
it's not safe if you reuse elements on the client, so it's not a new
issue.

This also solves cyclic object references.

The issue is that we prefer to inline objects into a plain JSON format
when an object is not going to get reused. In this case the object
doesn't have an id. We could potentially serialize a reference to an
existing model + a path to it but it bloats the format and complicates
the client.

In a smarter flush phase like we have in Fizz we could choose to inline
or outline depending on what we've discovered so far before a flush. We
can't do that here since we use native stringify. However, even in that
solution you might not know that you're going to discover the same
object later so it's not perfect deduping anyway.

Instead, I use a heuristic where I mark previously seen objects and if I
ever see that object again, then I'll outline it. The idea is that most
objects are just going to be emitted once and if it's more than once
it's fairly likely you have a shared reference to it somewhere and it
might be more than two.

The third object gets deduplicated (or "detriplicated").

It's not a perfect heuristic because when we write the second object we
will have already visited all the nested objects inside of it, which
causes us to outline every nested object too even those weren't
reference more than by that parent. Not sure how to solve for that.

If we for some other reason outline an object such as if it suspends,
then it's truly deduplicated since it already has an id.
2023-10-19 13:41:16 -04:00
Sebastian Markbåge
2eeb9f9226 [Flight Reply] Update error message (#27549)
This is in the reverse direction.
2023-10-19 13:40:24 -04:00
Andrey Lunyov
b67ddaa434 [meta-only] Move ReactServerStreamConfigFB to react-server from react-server-dom-fb (#27544)
Code organization PR.

It looks like the `ReactServerStreamConfigFB` is only used in the
`relay-server` package. This PR moves it to `react-server` from
`react-server-dom-fb` (similar to how we have config for bun, for
example). This avoids cross-package imports from `react-server` to
`react-server-dom-fb.`
2023-10-19 12:35:41 -04:00
Josh Story
9617d39eca [Fizz] Add proper assertion for stream fix (#27543)
In https://github.com/facebook/react/pull/27541 I added tests to assert
that the write after close bug was fixed. However the Node
implementation has an abort behavior preventing reproduction of the
original issue and the Browser build does not use AsyncLocalStorage
which also prevents reproduction. This change moves the Browser test to
a Edge runtime where AsyncLocalStorage is polyfilled. In this
implementation the test does correctly fail when the patch is removed.
2023-10-18 12:01:09 -07:00
Josh Story
601e5c3850 [Fizz][Float] Do not write after closing the stream (#27541)
Float methods can hang on to a reference to a Request after the request
is closed due to AsyncLocalStorage. If a Float method is called at this
point we do not want to attempt to flush anything. This change updates
the closing logic to also call `stopFlowing` which will ensure that any
checks against the destination properly reflect that we cannot do any
writes. In addition it updates the enqueueFlush logic to existence check
the destination inside the work function since it can change across the
work scheduling gap if it is async.

fixes: https://github.com/facebook/react/issues/27540
2023-10-18 10:05:18 -07:00
Ruslan Lesiutin
20c91b6534 React DevTools 4.28.4 -> 4.28.5 (#27538)
Changes:
* fix[devtools/useMemoCache]: add stub for useMemoCache in
ReactDebugHook ([hoxyq](https://github.com/hoxyq) in
[#27472](https://github.com/facebook/react/pull/27472))
* useDeferredValue should skip initialValue if it suspends
([acdlite](https://github.com/acdlite) in
[#27509](https://github.com/facebook/react/pull/27509))
* feat[react-devtools-extensions/logging]: initialize session id on the
client for logging ([hoxyq](https://github.com/hoxyq) in
[#27517](https://github.com/facebook/react/pull/27517))
* refactor[react-devtools-extensions]: use globals to eliminate dead
code ([hoxyq](https://github.com/hoxyq) in
[#27516](https://github.com/facebook/react/pull/27516))
* fix[devtools/inspectElement]: dont pause initial inspectElement call
when user switches tabs ([hoxyq](https://github.com/hoxyq) in
[#27488](https://github.com/facebook/react/pull/27488))
2023-10-18 14:08:23 +01:00
Sebastian Markbåge
e3748a0bde [Fizz] Pass cancellation reason to abort (#27536)
This was implemented correctly for Flight but not Fizz. Hard to keep
these many wrappers in sync.
2023-10-17 21:43:12 -04:00
Ruslan Lesiutin
a419575077 fix[devtools/useMemoCache]: add stub for useMemoCache in ReactDebugHook (#27472)
Currently, we have this error in our logs of the internal version of
React DevTools:
```
TypeError: Cannot read properties of undefined (reading 'memoCache')
    at Proxy.useMemoCache (chrome-extension://dnjnjgbfilfphmojnmhliehogmojhclc/build/react_devtools_backend_compact.js:151:71)
```

Looking at the build files of the extension, it fails here:
dddfe68820/packages/react-debug-tools/src/ReactDebugHooks.js (L333-L337)

Looks like `updateQueue` can be `undefined`, as it is not defined in
hook object here:
dddfe68820/packages/react-reconciler/src/ReactFiberHooks.js (L180-L186)

~~Also, it looks like `useMemoCache` implementation doesn't expect this,
so it should also result into TypeError here, line 1114:~~

dddfe68820/packages/react-reconciler/src/ReactFiberHooks.js (L1108-L1115)

~~Should this also be updated?~~
2023-10-17 18:39:10 +01:00
Andrew Clark
75c1bd7ee7 Prerendering support for useDeferredValue (#27512)
### Based on #27509 

Revealing a prerendered tree (hidden -> visible) is considered the same
as mounting a brand new tree. So, when an initialValue argument is
passed to useDeferredValue, and it's prerendered inside a hidden tree,
we should first prerender the initial value.

After the initial value has been prerendered, we switch to prerendering
the final one. This is the same sequence that we use when mounting new
visible tree. Depending on how much prerendering work has been finished
by the time the tree is revealed, we may or may not be able to skip all
the way to the final value.

This means we get the benefits of both prerendering and preview states:
if we have enough resources to prerender the whole thing, we do that. If
we don't, we have a preview state to show for immediate feedback.
2023-10-17 12:58:48 -04:00
Andrew Clark
b2a68a65c8 useDeferredValue should skip initialValue if it suspends (#27509)
### Based on https://github.com/facebook/react/pull/27505

If a parent render spawns a deferred task with useDeferredValue, but the
parent render suspends, we should not wait for the parent render to
complete before attempting to render the final value.

The reason is that the initialValue argument to useDeferredValue is
meant to represent an immediate preview of the final UI. If we can't
render it "immediately", we might as well skip it and go straight to the
"real" value.

This is an improvement over how a userspace implementation of
useDeferredValue would work, because a userspace implementation would
have to wait for the parent task to commit (useEffect) before spawning
the deferred task, creating a waterfall.
2023-10-17 12:48:11 -04:00
Ruslan Lesiutin
9abf6fa31c feat[react-devtools-extensions/logging]: initialize session id on the client for logging (#27517)
This code is executed once React DevTools panels are mounted, basically
when user opens browser's DevTools. Based on this fact, session in this
case is defined by browser's DevTools session, while they are open. A
session can involve debugging multiple React pages. `crypto.randomUUID`
is used to generate random user id.

Corresponding logger config changes -
[D50267871](https://www.internalfb.com/diff/D50267871).
2023-10-17 15:23:53 +01:00
Joe Savona
84da8994bd Test cases for reactive (control) dependencies
Adds test cases for all the cases of control dependencies that I can think of. 
We don't currently handle control dependencies correctly in any of these cases. 

There's also another test case which demonstrates why reactive dependency 
inference needs to be fixpoint, even for non-control dependencies.
2023-10-17 09:48:23 +01:00
Lauren Tan
4fc392e628 [qol] Add sprout to top level scripts 2023-10-16 16:05:08 +01:00
Lauren Tan
640994f49b [playground] Only log error to console when clicked 2023-10-16 15:54:33 +01:00
Lauren Tan
f5d1ff0a3c Update .gitignore for watchman-cookie 2023-10-16 15:54:30 +01:00
Asan Azimkulov
67cc9ba878 Fix: error messages (#27523)
<!--
  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
Changes `before before` to `before` in error messages.

<!--
Explain the **motivation** for making this change. What existing problem
does the pull request solve?
-->
I want to improve error logs

## 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.
-->
2023-10-16 15:05:42 +01:00
Ruslan Lesiutin
18a9dd1c60 refactor[react-devtools-extensions]: use globals to eliminate dead code (#27516)
Small change to eliminate dead code in builds for different browsers.

Tested by inspecting production sources.
2023-10-16 14:54:25 +01:00
Andrew Clark
309c8ad968 Track entangled lanes separately from update lane (#27505)
A small refactor to how the lane entanglement mechanism works. We can
now distinguish between the lane that "spawned" a render task (i.e. a
new update) versus the lanes that it's entangled with. Both the update
lane and the entangled lanes will be included while rendering, but by
keeping them separate, we don't lose the original priority.

In practical terms, this means we can now entangle a low priority update
with a higher priority lane while rendering at the lower priority.

To do this, lanes that are entangled at the root are now tracked using
the same variable that we use to track the "base lanes" when revealing a
previously hidden tree — conceptually, they are the same thing. I also
renamed this variable (from subtreeLanes to entangledRenderLanes) to
better reflect how it's used.

My primary motivation is related to useDeferredValue, which I'll address
in a later PR.
2023-10-15 12:29:52 -04:00
Sebastian Markbåge
09fbee89d6 [Fizz] Don't pop the replay stack if we've already rendered past an element (#27513)
This is the same problem as we had with keyPath before where if the
element itself suspends, we have to restore the replay node to what it
was before, however, if something below the element suspends we
shouldn't pop it because that will pop it back up the stack.

Instead of passing replay as an argument to every renderElement
function, I use a hack to compare if the node is still the same as the
one we tried to render, then that means we haven't stepped down into the
child yet. Maybe this is not quite correct because in theory you could
have a recursive node that just renders itself over and over until some
context bails out.

This solves an issue where if you suspended in an element it would retry
trying to replay from that element but using the postponed state from
the root.
2023-10-13 09:21:21 -04:00
Jakub Romańczyk
1b4ba74899 refactor: align ReactNativeViewConfigRegistry flow typing (#27514)
<!--
  Thanks for submitting a pull request!
We appreciate you spending the time to work on these changes. Please
provide enough information so that others can review your pull request.
The three fields below are mandatory.

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

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

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

## Summary

<!--
Explain the **motivation** for making this change. What existing problem
does the pull request solve?
-->
aligned the typing for `ReactNativeViewConfigRegistry` in
`react-native-host-hooks.js`
continuation of https://github.com/facebook/react/pull/27508

## 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.
-->
2023-10-13 10:33:55 +01:00
Joe Savona
fa2a67dd1d Feature flag to opt-in to emitting change variables 2023-10-12 16:26:42 -07:00
Josh Story
bb778528d1 [Fizz] Fix children rendering in custom elements with enableCustomElementPropertySupport (#27511)
The `enableCustomElementPropertySupport` flag changes React's handling
of custom elements in a way that is more useful that just treating every
prop as an attribute. However when server rendering we have no choice
but to serialize props as attributes. When this flag is on and React
supports more prop types on the client like functions and objects the
server implementation needs to be a bit more naunced in how it renders
these components. With this flag on `false`, function, and object props
are omitted entirely and `true` is normalized to `""`. There was a bug
however in the implementation which caused children more complex than a
single string to be omitted because it matched the object type filter.
This change reorganizes the code a bit to put these filters in the
default prop handline case, leaving children, style, and innerHTML to be
handled via normal logic.

fixes: https://github.com/facebook/react/issues/27286
2023-10-12 15:02:26 -07:00
Joe Savona
28767a7afb Inline reactive scope dep checks; no more change vars
Reactive scopes are currently preceded by individual variable declarations, one 
for each of the scope's dependencies. Only after checking independently if each 
of these dependencies has changed do we then do an "or" to check if we should 
actually recompute the body of the scope. 

But that's wasteful: it's more efficient to rely on `||` short-circuiting, and 
recompute as soon as any input changes. 

The main reason I can see not to do this is debugging. Having the change 
variables makes it easy to see what changed. But at this point I think it makes 
sense to optimize for code size and performance; we can always add back a 
dev-only mode that uses change variables if that turns out to help debugging.
2023-10-12 12:03:42 -07:00
Joe Savona
4fe0ab41e3 Repro for unnecessary memoization of array filter 2023-10-12 12:03:38 -07:00
Joe Savona
87b1549d5c Improve MergeConsecutiveScopes
Rewrites the core logic of MergeConsecutiveScopes to be easier to follow and fix 
bugs. We now do a two-pass approach: 

* First we iterate block instructions to identify scopes which can be merged, 
without actually merging the instructions themselves. 

* Then we iterate again, copying instructions from the block either into the new 
output block, or into their merged scope, as appropriate. 

I think the simplicity here is worth the performance cost, and we can always 
revisit later as necessary.
2023-10-12 09:47:26 -07:00
Jakub Romańczyk
ea8a8619ce refactor: use ESM exports in ReactNativeViewConfigRegistry (#27508)
## Summary

When transpiling `react-native` with `swc` this file caused some trouble
as it mixes ESM and CJS import/export syntax. This PR addresses this by
converting CJS exports to ESM exports. As
`ReactNativeViewConfigRegistry` is synced from `react` to `react-native`
repository, it's required to make the change here. I've also aligned the
mock of `ReactNativeViewConfigRegistry` to reflect current
implementation.

Related PR in `react-native`:
https://github.com/facebook/react-native/pull/40787
2023-10-12 17:28:32 +01:00
Sebastian Markbåge
e61a60fac0 [Flight] Enforce "simple object" rule in production (#27502)
We only allow plain objects that can be faithfully serialized and
deserialized through JSON to pass through the serialization boundary.

It's a bit too expensive to do all the possible checks in production so
we do most checks in DEV, so it's still possible to pass an object in
production by mistake. This is currently exaggerated by frameworks
because the logs on the server aren't visible enough. Even so, it's
possible to do a mistake without testing it in DEV or just testing a
conditional branch. That might have security implications if that object
wasn't supposed to be passed.

We can't rely on only checking if the prototype is `Object.prototype`
because that wouldn't work with cross-realm objects which is
unfortunate. However, if it isn't, we can check wether it has exactly
one prototype on the chain which would catch the common error of passing
a class instance.
2023-10-11 12:18:49 -04:00
Sebastian Markbåge
1fc58281af Disable ServerContext in canary (#27474)
We previously added a warning in #27424. This just removes it from
canary/stable channels but keeps it in experimental for now.
2023-10-11 12:13:09 -04:00
Devon Govett
537228f9fd Add support for onScrollEnd event (#26789)
## Summary

This adds support for the new
[scrollend](https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollend_event)
event. It was recently added to the spec, and is currently supported in
Firefox 109 and Chrome Canary (shipping in Chrome 114). You can read
more about this event
[here](https://developer.chrome.com/blog/scrollend-a-new-javascript-event/).
This PR adds support for the `onScrollEnd` prop, following the
implementation for `onScroll`.

## How did you test this change?

Added unit tests.
2023-10-10 21:00:57 -07:00
Andrew Clark
be67db46b6 Add optional initialValue argument to useDeferredValue (#27500)
Adds a second argument to useDeferredValue called initialValue:

```js
const value = useDeferredValue(finalValue, initialValue);
```

During the initial render of a component, useDeferredValue will return
initialValue. Once that render finishes, it will spawn an additional
render to switch to finalValue.

This same sequence should occur whenever the hook is hidden and revealed
again, i.e. by a Suspense or Activity, though this part is not yet
implemented.

When initialValue is not provided, useDeferredValue has no effect during
initial render, but during an update, it will remain on the previous
value, then spawn an additional render to switch to the new value. (This
is the same behavior that exists today.)

During SSR, initialValue is always used, if provided.

This feature is currently behind an experimental flag. We plan to ship
it in a non-breaking release.
2023-10-10 16:39:02 -04:00
Joe Savona
52c6a34da3 [be] Limit scope of temporaries in codegen
This morning @mofeiZ reminded me that our codegen doesn't really have any guards 
against reordering, since temporaries are lazily emitted. We're relying on the 
fact that our lowering and memoization carefully preserves order of evaluation, 
such that delaying the instructions in codegen doesn't change semantics. 

To help catch any mistakes with this, I had previously added code that reset the 
codegen context's temporaries before/after exiting a reactive scope. That 
ensured that temporaries from within the scope weren't accessible outside it. 
This PR extends that approach to _all_ blocks, so that temporaries created 
within a block aren't accessible outside it. 

I'm also going to explore more actively resetting temporaries after they 
"should" be used. There are a couple cases where temporaries are reused, though, 
which we have to change first.
2023-10-10 13:15:51 -07:00
Joe Savona
495fec19e7 [be] Update docblock comment for ConstantPropagation 2023-10-10 13:15:46 -07:00
Joe Savona
a92bfd7fdc [be] Factor out named type for JSXText instr variant 2023-10-10 13:15:42 -07:00
Joe Savona
ba23b990ac [be] Remove dead code in ConstantPropagation 2023-10-10 13:15:39 -07:00
Ruslan Lesiutin
77ec61885f fix[devtools/inspectElement]: dont pause initial inspectElement call when user switches tabs (#27488)
There are not so many changes, most of them are changing imports,
because I've moved types for UI in a single file.

In https://github.com/facebook/react/pull/27357 I've added support for
pausing polling events: when user inspects an element, we start polling
React DevTools backend for updates in props / state. If user switches
tabs, extension's service worker can be killed by browser and this
polling will start spamming errors.

What I've missed is that we also have a separate call for this API, but
which is executed only once when user selects an element. We don't
handle promise rejection here and this can lead to some errors when user
selects an element and switches tabs right after it.

The only change here is that this API now has
`shouldListenToPauseEvents` param, which is `true` for polling, so we
will pause polling once user switches tabs. It is `false` by default, so
we won't pause initial call by accident.


af8beeebf6/packages/react-devtools-shared/src/backendAPI.js (L96)
2023-10-10 18:10:17 +01:00
Pieter De Baets
151e75a128 [Fabric] Pass children when cloning (#27458)
## Summary

Currently when cloning nodes in Fabric, we reset a node's children on
each clone, and then repeatedly call appendChild to restore the previous
list of children (even if it was quasi-identical to before). This causes
unnecessary invalidation of the layout state in Fabric's ShadowNode data
(which in turn may require additional yoga clones) and extra JSI calls.

This PR adds a feature flag to pass in the children as part of the clone
call, so Fabric always has a complete view of the node that's being
mutated.

This feature flag requires matching changes in the react-native repo:
https://github.com/facebook/react-native/pull/39817

## How did you test this change?

Unit test added demonstrates the new behaviour 

```
yarn test -r www-modern ReactFabric-test
yarn test ReactFabric-test.internal
```

Tested a manual sync into React Native and verified core surfaces render
correctly.
2023-10-10 15:11:26 +01:00
Joe Savona
5a8c7594c5 Implement JSX whitespace rules
So far we've been preserving JSX whitespace all the way through to codegen. But 
JSX has clear rules around whitespace handling, which allows us to trim 
whitespace in the input in lots of cases. For the most part this doesn't change 
our output, but I think that’s generally because of prettier. This PR should 
make a big difference when debugging the compiler, by removing all the 
whitespace JsxText values. 

But in some edge-cases it really makes a difference in the output since we can 
avoid memo slots for strings like `"\n      "`.. 

## Test Plan 

* Experimented with our internal tool to verify transform output to confirm that 
JSXText whitespace does not impact fbt transform results. 

* Synced and tested profile page, looks fine
2023-10-09 16:35:47 -07:00
Joe Savona
b61dba64ad Enable MergeConsecutiveScopes by default
## Test Plan (wip) 

Sync internally, manually verify code changes and test products.
2023-10-09 16:15:30 -07:00
Joe Savona
a1461016df Improve MergeConsecutiveScopes
Rewrites the core logic of MergeConsecutiveScopes to be easier to follow and fix 
bugs. We now do a two-pass approach: 

* First we iterate block instructions to identify scopes which can be merged, 
without actually merging the instructions themselves. 

* Then we iterate again, copying instructions from the block either into the new 
output block, or into their merged scope, as appropriate. 

I think the simplicity here is worth the performance cost, and we can always 
revisit later as necessary.
2023-10-09 16:15:30 -07:00
Joe Savona
49d16ba7e5 Repro for scope merging bug
This is a repro for a bug that occurs when `enableMergeConsecutiveScopes` is 
enabled. Reminder that this feature is off by default and not enabled yet 
internally. 

I found this via #2121, where eliminating extraneous whitespace JSXText 
instructions meant that MergeConsecutiveScopes started merging a fixture 
differently, revealing a bug. This PR reproduces that case by keeping the 
identical structure, but using plain objects to represent the JSX elements 
instead of JSX syntax.
2023-10-09 16:15:29 -07:00
Joe Savona
529568c7db [be] Rename InlineUseMemo imports 2023-10-09 16:07:09 -07:00
Joe Savona
428c47581e Generalize InlineUseMemo to inline IIFEs
This PR completes the refactor. We now do the following sequence: 

* ValidateUseMemo. This is a new pass that extracts just the validation logic 
from the existing InlineUseMemo. This was always being run before, so this pass 
also always runs. 

* DropManualMemoization. As before, this converts useMemo calls into an IIFE 
(immediately invoked function expression). 

* InlineImmediatelyInvokedFunctionExpressions (prev InlineUseMemo). This pass 
now inlines _all_ IIFEs, including both useMemo calls that were dropped as well 
as IIFEs that the user wrote. 

The motivation for this change is that some codebases use IIFEs as a workaround 
for lack of if expressions, but we're unable to optimize within function 
expressions. This is the reason we originally added inlining for useMemo, but 
given that IIFEs are common it makes sense to generalize the inlining. 

## Test Plan 

* Manually checked changes in output 

* Synced internally and tested on profile page, no issues observed. Also 
spot-checked some of the changes in ouput and it looks as expected.
2023-10-09 15:56:10 -07:00
Joe Savona
444a1ad9c1 Reorder InlineUseMemo after type inference
The goal of this stack is to generalize `InlineUseMemo` into a pass that inlines 
all immediately invoked function expressions (IIFEs). Rather than specialize 
just useMemo calls, we'll rely on DropManualMemoization running first and 
turning useMemo calls into IIFEs. Then the generalized inlining pass can handle 
those IIFEs as well as others present in the source. 

For now, moving the order of the pass makes the output closer to what it will 
eventually be after this stack is complete.
2023-10-09 15:25:18 -07:00
Joe Savona
74c6c992ba [be] s/DropUseMemo/DropManualMemoization/
Renames this pass to clarify that it's dropping all manual memoization (within 
components), including both useMemo and useCallback.
2023-10-09 15:25:17 -07:00
Joe Savona
683a197a89 Manually revert #2127 (allow mutating context in callbacks)
#2127 introduced a special type for the result of `useContext()` that was sort 
of ref-like. The intent was to allow code like this: 

``` 

function Foo() { 

const cx = useContext(...); 

function onEvent() { 

cx.foo = true; 

}; 

return <Bar onEvent={onEvent} />; 

} 

``` 

However, that code actually is allowed by the compiler by default. It's only a 
bailout when `@validateFrozenLambdas` is enabled. The "fix" in #2127 therefore 
wasn't strictly necessary to unblock rollout, and it's also flawed in a few 
ways: 

* First, `useContext(FooContext)` should have equivalent behavior to a custom 
hooks which does the same thing, ie `function useFooContext() { return 
useContext(FooContext) }`. Specializing the type of useContext makes the 
behavior different. 

* Second, it meant that even readonly accesses of the context inside a callback 
marked the function as capturing, which in turn prevented those callbacks from 
being memoized. 

So i'm reverting this and we'll have to think a bit more about this case.
2023-10-09 15:21:12 -07:00
Mofei Zhang
b55cf78a4d [syntax] Lower empty jsx attributes to true
--- 

Found when enabling Forget for webamp 

``` 

% yarn sprout --filter --verbose 

yarn run v1.22.19 

$ node ../sprout/dist/main.js --filter --verbose 

PASS  jsx-attribute-default-to-true 

ok <div>{"truthyAttribute":true}</div> 

1 Tests, 1 Passed, 0 Failed 

  Done in 2.45s. 

```
2023-10-06 17:38:02 -04:00
Mofei Zhang
392d0b127b [patch] Patch import specifiers check for react
--- 

Patch for original patch of injecting `useMemoCache` logic 😅 This is failing on 
a good number React components internally (not in our current experiments)
2023-10-06 17:38:00 -04:00
Mofei Zhang
fd87c9b9e1 [patch] Bug in deriveMinimalDeps
Found when enabling Forget on Webamp
2023-10-06 17:37:57 -04:00
Joe Savona
2b417e2a52 Playground uses new pragma parser, shows config being used
The playground now uses the new pragma parser so it's guaranteed to use the 
right defaults and have consistent parsing with snap/sprout. In addition, we now 
emit a debug event from the compiler which contains pretty-printed environment 
config, making it easy to check which settings are being applied in playground. 

<img width="3008" alt="Screenshot 2023-10-05 at 11 05 58 AM" 
src="https://github.com/facebook/react-forget/assets/6425824/2417f40c-1320-4c39-a661-a4e34e3d69c4">
2023-10-05 11:06:56 -07:00
Joe Savona
ed9ea81e4a Snap/sprout use new pragma parser and compiler defaults
Updates Snap and Sprout to use the new pragma parser, which also means they will 
always use the same default flags as the compiler itself sets. A side benefit of 
this is that you no longer need to rebuild snap/sprout to update their flags, 
since they will take flags from the version of the compiler being executed.
2023-10-05 10:57:20 -07:00
Joe Savona
cadcf3de2d Reusable function for parsing config strings
Adds a helper function for parsing pragma strings to the compiler itself, and 
exports it. This will be used in follow-ups to make Snap, Sprout, and Playground 
all use the same pragma parser. The helper also starts from the default values, 
so adopting this will also make it easy for all those places to have the same 
defaults automatically.
2023-10-05 10:18:24 -07:00
Joe Savona
80d867d1bd Promote inlineUseMemo to stable (remove flag)
Per title, this feature flag is enabled everywhere and is clearly stable, let's 
promote to stable and remove the flag to simplify.
2023-10-05 09:20:19 -07:00
Joe Savona
3fdb237682 Promote enableNoAliasOptimizations to stable (remove flag)
Per title, this feature flag is enabled everywhere and is stable enough, let's 
promote to stable and remove the flag to simplify.
2023-10-05 09:20:14 -07:00
Joe Savona
11d03ffbe0 Promote enableFunctionCallSignatureOptimizations to stable (remove flag)
Per title, this feature flag is enabled everywhere and is clearly stable, let's 
promote to stable and remove the flag to simplify.
2023-10-05 09:20:09 -07:00
Joe Savona
0b0f8994ba Promote enableTreatHooksAsFunctions to stable (remove flag)
Per title, this feature flag is enabled everywhere and is clearly stable, let's 
promote to stable and remove the flag to simplify.
2023-10-05 09:20:05 -07:00
Josh Story
dddfe68820 pull implementations from the right react-dom (#27471)
should have imported from the stub implementation. this blew up the
server rendering stub size (effectively pulling in the entire client
bundle)
2023-10-05 09:14:57 -07:00
Josh Story
546178f910 react-dom/server-rendering-stub: restore experimental prefix for useFormState and useFormStatus (#27470)
in #27461 the experimental prefix was added back for `useFormState` and
`useFormStatus` in react-dom. However these functions are also exported
from the server rendering stub too and when using the stub with
experimental prefixes their absence causes unexpected errors.

This change adds back the experimental prefix for these two hooks to
match the experimental build of react-dom.
2023-10-05 08:53:14 -07:00
Sebastian Silbermann
16619f106a Reduce install network flake (#27464)
## Summary

Avoids potentially flaky network calls leading to failures such as
https://app.circleci.com/pipelines/github/facebook/react/47096/workflows/b7966c1d-199c-4185-8d17-ac6485235c3a/jobs/727782.
Also makes install faster since we don't need the binary in CI
seemingly.

Electron itself is used to start the standalone binary.

## How did you test this change?

- [x] CI still passes without the binary downloaded. I'm just trusting
[their
docs](https://www.electronjs.org/docs/latest/tutorial/installation) here
that setting this actually ensures the binary isn't downloaded.
2023-10-05 11:37:08 +02:00
Sebastian Markbåge
0fba3ecf73 [Fizz] Reset error component stack and fix error messages (#27456)
The way we collect component stacks right now are pretty fragile.

We expect that we'll call captureBoundaryErrorDetailsDev whenever an
error happens. That resets lastBoundaryErrorComponentStackDev to null
but if we don't, it just lingers and we don't set it to anything new
then which leaks the previous component stack into the next time we have
an error. So we need to reset it in a bunch of places.

This is still broken with erroredReplay because it has the inverse
problem that abortRemainingReplayNodes can call
captureBoundaryErrorDetailsDev more than one time. So the second
boundary won't get a stack.

We probably should try to figure out an alternative way to carry along
the stack. Perhaps WeakMap keyed by the error object.

This also fixes an issue where we weren't invoking the onShellReady
event if we error a replay. That event is a bit weird for resuming
because we're probably really supposed to just invoke it immediately if
we have already flushed the shell in the prerender which is always atm.
Right now, it gets invoked later than necessary because you could have a
resumed hole ready before a sibling in the shell is ready and that's
blocked.
2023-10-04 16:48:12 -04:00
Josh Story
6f13243957 Move ReactCurrentDispatcher back to shared internals (#27462)
The jsx-runtime uses the ReactCurrentDispatcher from shared internals.
Recently this was moved to ReactServerSharedInternals which broke
jsx-runtime. This change moves it back to ReactSharedInternals until we
can come up with a new forking mechanism.
2023-10-04 13:16:21 -07:00
Andrew Clark
ca237d6f0a Add back temporary experimental_ aliases for Server Actions APIs (#27461)
This adds back the `experimental_`-prefixed Server Actions APIs to the
experimental builds only, so that apps that use those don't immediately
break when upgrading. The APIs will log a warning to encourage people to
move to the unprefixed version, or to switch to the canary release
channel.

We can remove these in a few weeks after we've given people a chance to
upgrade.

This does not affect the canary builds at all, since they never had the
prefixed versions to begin with.
2023-10-04 15:58:08 -04:00
Joe Savona
8e8ae96478 Support empty catch clause
Adds support for empty catch clauses in a try/catch. We add a new block kind 
`catch` which prevents the empty catch block from being merged with other types 
of blocks, preserving the block structure within the HIR and allowing us to 
reconstruct the empty catch.
2023-10-04 12:24:19 -07:00
Andrew Clark
44d40a077a Remove prefix from formState option (#27460)
`useFormState` is now in canary.
2023-10-04 15:17:37 -04:00
Andrew Clark
bfefb22842 Upgrade Server Actions to canary (#27459)
Upgrades the stability of Server Actions from experimental to canary.

- Turns on enableAsyncActions and enableFormActions
- Removes "experimental_" prefix from useOptimistic, useFormStatus, and
useFormState
2023-10-04 14:51:36 -04:00
Mofei Zhang
1ec1a0ceb8 [fix] JSXElement identifiers now included in lambda capture deps
--- 

`gatherCapturedDeps` previously did not visit JSXElements, so Forget did not 
read any local JSX identifiers as dependencies (in lambdas)
2023-10-04 14:01:34 -04:00
Mofei Zhang
3f8831fb5c [snap][QoL] Pragma for implicit debug mode
--- 

Implements popular feature request  per feedback from a majority of snap users. 

**Add `@debug` to the first line of your `testfilter.txt` file to opt into 
implicit debug mode**, in which debug logging is enabled anytime filter mode is 
on + only one fixture file is found. 

- live edits to testfilter.txt are reflected in watch mode, so you can add / 
remove `@debug` to `testfilter.txt` in the middle of a watch session 

- I personally don't use debug mode all the time (I often a single file filtered 
+ a lot of console log traces), but it should be easy to add `@debug` to the top 
of `testfilter.txt` and leave it there forever.
2023-10-04 14:01:33 -04:00
Mofei Zhang
05d620521b [ez] missed TODO bailout for holey arrays
--- 

Missed this when adding #2114 (only found when running thousands of fb 
components through forget and noticing that holey arrays still fail)
2023-10-04 14:01:33 -04:00
Andrew Clark
88d56b8e81 Warn if optimistic state is updated outside of a transition (#27454)
### Based on #27453 

If optimistic state is updated, and there's no startTransition on the
stack, there are two likely scenarios.

One possibility is that the optimistic update is triggered by a regular
event handler (e.g. `onSubmit`) instead of an action. This is a mistake
and we will warn.

The other possibility is the optimistic update is inside an async
action, but after an `await`. In this case, we can make it "just work"
by associating the optimistic update with the pending async action.

Technically it's possible that the optimistic update is unrelated to the
pending action, but we don't have a way of knowing this for sure because
browsers currently do not provide a way to track async scope. (The
AsyncContext proposal, if it lands, will solve this in the future.)
However, this is no different than the problem of unrelated transitions
being grouped together — it's not wrong per se, but it's not ideal.

Once AsyncContext starts landing in browsers, we will provide better
warnings in development for these cases.
2023-10-04 10:57:55 -04:00
Pieter De Baets
bd6891742c Remove unreferenced react-native-host-hooks from flow (#27457)
## Summary

These modules are no longer referenced in the React codebase. We should
remove them to limit the API surface area between React and React
Native.

## How did you test this change?

`yarn flow native && yarn flow fabric`
2023-10-04 15:57:43 +01:00
Joe Savona
91dab8e19c [be] Dont copy default config values if key is present 2023-10-03 16:57:00 -07:00
Joe Savona
b96dd26be1 [qol] Improve printing of ReactiveFunction
This is a (hopefully) better approach at printing ReactiveFunction. The nesting 
wasn't always clear in the previous version, this should help. See playground to 
experiment.
2023-10-03 16:56:59 -07:00
Joe Savona
870a378ebb [be] Rename EnvironmentConfig type after refactor 2023-10-03 15:01:55 -07:00
Joe Savona
44a6a602a7 [be] Update feature defaults to reflect usage
Updates feature flag default values to match the flags we have turned on 
internally for some time w/o issues.
2023-10-03 14:49:58 -07:00
Joe Savona
34890556ec [be] Improve feature flags setup
Updates `Environment` to store all feature flags on a single `config` object. We 
now also define an object with all the default config values, and use this to 
populate defaults for any missing values in the user-provided config.
2023-10-03 13:58:05 -07:00
Andrew Clark
85c2b519b5 Fix: Optimistic update does not get reset (#27453)
I found a bug where if an optimistic update causes a component to
rerender, and there are no other state updates during that render, React
bails out without applying the update.

Whenever a hook detects a change, we must mark the component as dirty to
prevent a bailout. We check for changes by comparing the new state to
`hook.memoizedState`. However, when implementing optimistic state
rebasing, I incorrectly reset `hook.memoizedState` to the incoming base
state, even though I only needed to reset `hook.baseState`. This was
just a mistake on my part.

This wasn't caught by the existing tests because usually when the
optimistic state changes, there's also some other state that marks the
component as dirty in the same render.

I fixed the bug and added a regression test.
2023-10-03 15:01:40 -04:00
Joe Savona
9fc5e55b56 [be] Access all features flags through Environment
Most of our feature flags are accessed via the `Environment`, but a few cases 
have slipped in where we look at the `config` object directly. The problem is 
that the config object doesn't set defaults, so the check is effectively 
encoding what the default is. 

This PR moves to always accessing flags off of the environment, and adds a few 
flags that weren't yet defined there.
2023-10-03 11:46:33 -07:00
Sathya Gunasekaran
0f97ea4c71 [sprout] Make mutate incrementally attempt to add property
Previously, we stored a global count variable that was updated every time we 
added a property to the `arg` object. This was added to prevent collisions, and 
make sure we do actually mutate the object. 

But the count value was shared by the forget compiled and uncompiled versions, 
so the same object mutated in either versions would result in having different 
properties leading to potential test failures. 

Instead, let's make count local and attempt to incrementally mutate the object 
with different keys.
2023-10-04 12:36:04 +05:30
Sathya Gunasekaran
3aaf8be25c [hir] Use a stable identity for undefined value
InferReferenceEffects uses object identity to merge states, which breaks when we 
create a new object to model `undefined`. 

Two value objects representing `undefined` are not equal due to referential 
equality. 

Instead, let's use a singleton to represent `undefined` value.
2023-10-04 12:11:35 +05:30
Joe Savona
b7a14ecc8d Detect unknown hooks on React namespace
Handles an edge-case from earlier in the stack. When looking up a property on a 
shape, if the property is defined we return it. But if it isn't defined, and the 
property name is a hook, we treat it like a default custom hook.
2023-10-03 09:00:11 -07:00
Joe Savona
a2dd376820 Drop useMemo/useCallback when called via React namespace
Teaches `DropUseMemo` (which also handles useCallback) to also transform the 
methodcall case.
2023-10-03 08:47:07 -07:00
Joe Savona
989eaafa43 Support hooks/methods on the React namespace
Allows using hooks/methods off of the `React` namespace, for example 
`React.useState(sathya)`. Thanks to the previous PR we correctly handle things 
like validation of hooks called via propertyload syntax. The main change here is 
to teach the compiler about the `React` namespace. This is a bit of a hack since 
we treat it as a global, but we're transforming React code so this seems 
reasonable (?). 

There are a few additional touch-ups which I'll do in subsequent PRs to make 
review easier. For example, we need to teach our useMemo/useCallback flattening 
logic to also handle the case of `React.useMemo()` etc.
2023-10-03 08:47:06 -07:00
Joe Savona
b3d5e92667 Support/validate hooks called as methods
Hooks can be called via method call syntax, eg `Foo.useBar(sathya)`. This PR 
teaches the compiler about this form of hooks for things like flattening scopes 
with hooks, validating conditional hooks, etc. 

Note that we still disallow calls on the React namespace, so things like 
`React.useState()` continue to error. That's the next PR in the stack!
2023-10-03 08:47:05 -07:00
Joe Savona
216696dd88 Allow context values to be mutated in callbacks
Adds a new type for representing context values, which is transitive. So 
`useContext(a).b.c` also gets inferred as a context type. This allows us to 
refine our inference, and allow passing callbacks that modify context where a 
"frozen" lambda is exepcted.
2023-10-03 08:47:04 -07:00
Joe Savona
41cb3c722e Fix duplicate declaration from MergeConsecutiveScopes
This is a distilled version of the duplicate declaration @mofeiZ and I saw when 
trying to sync latest Forget internally, plus a fix to avoid the duplicate 
instruction.
2023-10-02 16:40:33 -07:00
Joe Savona
4779fa0f81 Wrap MergeConsecutiveScopes in a feature flag
I should have done this originally, but figured if there were issues on the sync 
we could just do it then. Here we are!
2023-10-02 15:46:04 -07:00
Joe Savona
e54e2e6ee4 Distinguish JSXText/StringLiteral during codegen
Fixes an issue with incorrect spacing where spaces were getting dropped, despite 
an explicit `{" "}` in the input. The issue is that we didn't maintain JSXText 
all the way through compilation. BuildHIR distinguishes string literals (such as 
the above, inside an expressioncontainer) from JSXText, and we propagate this 
distinction all the way through to codegen. 

But then codegen stores temporary values as `t.Expression` nodes, which means we 
have to convert the JSXText nodes to StringLiteral and we lose the distinction. 
This PR updates codegen to save temporaries as `t.Expression | t.JSXText` so 
that we can preserve the difference. In most places we just coerce the value to 
an expression, but the code for emitting JSX child items looks at the raw value 
so it can distinguish them. JSXText is emitted as-is, while StringLiterals are 
always wrapped in an expression container. 

See the new test case which demonstrates the expression being preserved.
2023-10-02 14:58:05 -07:00
Sathya Gunasekaran
e49a62c15d [hir] Do not memoize object methods separately
Object methods must not be cached independently, so this PR flattens the 
reactive scope to prevent memoization. 

In the future, we can combine the FlattenScopesWithObjectMethods and 
FlattedScopesWithHooks passes by making them more modular. But this works for 
now.
2023-10-02 20:22:49 +01:00
Sophie Alpert
db69f95e48 Fix checkbox and radio hydration (#27401)
Fixes whatever part of https://github.com/facebook/react/issues/26876
and https://github.com/vercel/next.js/issues/49499 that
https://github.com/facebook/react/pull/27394 didn't fix, probably.

From manual tests I believe this behavior brings us back to parity with
latest stable release (18.2.0). It's awkward that we keep the user's
state even for controlled inputs, so the DOM is out of sync with React
state.

Previously the .defaultChecked assignment done in updateInput() was
changing the actual checkedness because the dirty flag wasn't getting
set, meaning that hydrating could change which radio button is checked,
even in the absence of user interaction! Now we go back to always
detaching again.
2023-10-02 11:38:44 -07:00
Sophie Alpert
4f4c52a3c8 Fix controlled radios, maybe for real this time (#27443)
Fixes #26876 for real?

In 18.2.0 (last stable), we set .checked unconditionally:


https://github.com/facebook/react/blob/v18.2.0/packages/react-dom/src/client/ReactDOMInput.js#L129-L135

This is important because if we are updating two radios' checkedness
from (false, true) to (true, false), we need to make sure that
input2.checked is explicitly set to false, even though setting
`input1.checked = true` already unchecks input2.

I think this fix is not complete because there is no guarantee that all
the inputs rerender at the same time? Hence the TODO. But in practice
they usually would and I _think_ this is comparable to what we had
before.

Also treating function and symbol as false like we used to and like we
do on initial mount.
2023-10-02 11:38:13 -07:00
Sathya Gunasekaran
f8996476ff [hir] Wire up object method lowering and codegen
Object methods are lowered to functions and added to ObjectExpression. The 
codegen is interesting because we shouldn't emit code that lowers the object 
method into a separate statement and then stores it into an object expression. 

An shorthand object method has different semantics than an object method using 
the function syntax, so we need to preserve the shorthand object method syntax 
in the generated code. 

To do this, we don't immediately generate an AST node for the ObjectMethod but 
instead store it in a side table during codegen. Only when emitting code for an 
ObjectExpression, we lookup this side table and emit the object method inline in 
the body.
2023-10-02 19:26:00 +01:00
Sebastian Markbåge
843ec07021 [Flight] Taint APIs (#27445)
This lets a registered object or value be "tainted", which we block from
crossing the serialization boundary. It's only allowed to stay
in-memory.

This is an extra layer of protection against mistakes of transferring
data from a data access layer to a client. It doesn't provide perfect
protection, because it doesn't trace through derived values and
substrings. So it shouldn't be used as the only security layer but more
layers are better.

`taintObjectReference` is for specific object instances, not any nested
objects or values inside that object. It's useful to avoid specific
objects from getting passed as is. It ensures that you don't
accidentally leak values in a specific context. It can be for security
reasons like tokens, privacy reasons like personal data or performance
reasons like avoiding passing large objects over the wire.

It might be privacy violation to leak the age of a specific user, but
the number itself isn't blocked in any other context. As soon as the
value is extracted and passed specifically without the object, it can
therefore leak.

`taintUniqueValue` is useful for high entropy values such as hashes,
tokens or crypto keys that are very unique values. In that case it can
be useful to taint the actual primitive values themselves. These can be
encoded as a string, bigint or typed array. We don't currently check for
this value in a substring or inside other typed arrays.

Since values can be created from different sources they don't just
follow garbage collection. In this case an additional object must be
provided that defines the life time of this value for how long it should
be blocked. It can be `globalThis` for essentially forever, but that
risks leaking memory for ever when you're dealing with dynamic values
like reading a token from a database. So in that case the idea is that
you pass the object that might end up in cache.

A request is the only thing that is expected to do any work. The
principle is that you can derive values from out of a tainted
entry during a request. Including stashing it in a per request cache.
What you can't do is store a derived value in a global module level
cache. At least not without also tainting the object.
2023-10-02 13:55:39 -04:00
Rubén Norte
54baa7997c Add feature flag to use microtasks in the React Native Fabric renderer (#27364)
## Summary

This is part of an effort to align the event loop in React Native with
its behavior on the Web. In this case, we're going to test enabling
microtasks in React Native (Fabric) and we need React to schedule work
using microtasks if available there. This just adds a feature flag to
configure that behavior at runtime.

## How did you test this change?

* Reviewed the generated code, which looks ok.
* Did a manual sync of this PR to Meta's internal infra and tested it
with my changes to enable microtasks in RN/Hermes.
2023-10-02 17:12:35 +01:00
Sebastian Markbåge
a6ed60a8eb [Fizz] Don't double replay elements when it's the postpone point (#27440)
The `resumeElement` function wasn't actually doing the correct thing
because it was resuming the element itself but what the child slot means
is that we're supposed to resume in the direct child of the element.
This is difficult to check for since it's all the possible branches that
the element can render into, so instead we just check this in
renderNode. It means the hottest path always checks the task which is
unfortunate.

And also, resuming using the correct nextSegmentId.

Fixes two bugs surfaced by this test.

---------

Co-authored-by: Josh Story <josh.c.story@gmail.com>
2023-09-29 18:24:38 -04:00
Sebastian Markbåge
c7ba8c0988 Enforce that the "react-server" build of "react" is used (#27436)
I do this by simply renaming the secret export name in the "subset"
bundle and this renamed version is what the FlightServer uses.

This requires us to be more diligent about always using the correct
instance of "react" in our tests so there's a bunch of clean up for
that.
2023-09-29 18:24:05 -04:00
Andrew Clark
d900fadbf9 Bugfix: Selective hydration triggers false update loop error (#27439)
This adds a regression test and fix for a case where a sync update
triggers selective hydration, which then leads to a "Maximum update
depth exceeded" error, even though there was only a single update. This
happens when a single sync update flows into many sibling dehydrated
Suspense boundaries.

This fix is, if a commit was the result of selective hydration, we
should not increment the nested update count, because those renders
conceptually are not updates.

Ideally, they wouldn't even be in a separate commit — we should be able
to hydrate a tree and apply an update on top of it within the same
render phase. We could do this once we implement resumable context
stacks.
2023-09-29 14:29:35 -04:00
Andrew Clark
13d0225c7d Pass lanes as argument to performSyncWorkOnRoot (#26763)
`performSyncWorkOnRoot` has only a single caller, and the caller already
computes the next lanes (`getNextLanes`) before deciding to call the
function. So we can pass them as an argument instead of computing the
lanes again.

There was already a TODO comment about this, but it was mostly perf
related. However, @rickhanlonii noticed a discrepancy where the inner
`getNextLanes` call was not being passed the current work-in- progress
lanes. Usually this shouldn't matter because there should never be
work-in-progress sync work; it should finish immediately. There is one
case I'm aware of where we exit the work loop without finishing a sync
render, which is selective hydration, but even then it should switch to
the sync hydration lane, not the normal sync lane. So something else is
probably going on. I suspect it might be related to the
`enableUnifiedSyncLane` experiment.

This is likely related to a regression found internally at Meta. We're
still working on getting a proper regression test; I can come up with a
contrived one but I'm not confident it'll be the same as the actual
regression until we get a better repro.
2023-09-28 16:29:32 -04:00
Andrew Clark
62512bafc6 Test fix: Add missing warning assertion (#27434)
Adds a missing test assertion for Server Context deprecation.

The PR that added this warning was based on an older revision than the
PR that added the test.
2023-09-28 12:21:11 -04:00
Josh Story
5b5665342b Restore "publish react-server-dom-turbopack to canary channels (#27427)" (#27433)
Reverts facebook/react#27428 which restores facebook/react#27427

this will allow the publish script to publish
`react-server-dom-turbopack`
2023-09-28 09:13:49 -07:00
Sebastian Markbåge
1ebedbec2b Add Server Context deprecation warning (#27424)
As agreed, we're removing Server Context. This was never official
documented.

We've found that it's not that useful in practice. Often the better
options are:

- Read things off the url or global scope like params or cookies.
- Use the module system for global dependency injection.
- Use `React.cache()` to dedupe multiple things instead of computing
once and passing down.

There are still legit use cases for Server Context but you have to be
very careful not to pass any large data, so in generally we recommend
against it anyway.

Yes, prop drilling is annoying but it's not impossible for the cases
this is needed. I would personally always pick it over Server Context
anyway.

Semantically, Server Context also blocks object deduping due to how it
plays out with Server Components that can't be deduped. This is much
more important feature.

Since it's already in canary along with the rest of RSC, we're adding a
warning for a few versions before removing completely to help migration.

---------

Co-authored-by: Josh Story <josh.c.story@gmail.com>
2023-09-28 11:03:19 -04:00
Josh Story
34de2986df Revert "publish react-server-dom-turbopack to canary channels (#27427) (#27428)
Build fails because the package does not exist. I've added the package
to npm but we need the publishing account to be a collaborator. I'm
reverting until we get that sorted so we don't block canaries
2023-09-27 16:17:45 -07:00
Joe Savona
b61cfc01a5 Support rest params
Adds support for lowering rest element parameters to spreads. We eagerly create 
a temporary, similar to the approach for destructuring. In theory we could do 
something more optimal if you have a `...foo` (rest element where the argument 
is an Identifier) but it doesn't seem worth optimizing yet.
2023-09-27 14:04:02 -04:00
Joe Savona
be7f98d584 Scaffolding for rest params
Updates HIR to represent rest element function parameters. We don't construct 
these yet.
2023-09-27 14:04:02 -04:00
Joe Savona
687ad02e43 Dont merge if scope output is not guaranteed to change
As noted earlier in the stack and in chat, there are some cases where the output 
of a reactive scope is not guaranteed to change just because its inputs did. 
Consider a function `foo(x) { return x < 10 }`. If x was 0 and changes to 1, the 
result of `foo(x)` won't change. 

For code such as `[foo(x)]`, then, merging the scope for `t0 = foo(x)` and `t1 = 
[t0]` into a single `t1 = [foo(x)]` could cause us to invalidate `t1` 
unnecessarily. For example, x changing from 0 to 1 would allocate a new array of 
`[true]` even though the value didn't meaningfully change. This is the second 
category of merging, where we merge scopes A and B if the outputs of A are the 
inputs to B. 

With this change, we only do this type of merge if the outputs of the first 
scope are known to invalidate whenever the input does. We're conservative about 
this, and only consider function expressions, arrays, object, and jsx to always 
invalidate. Function calls _may_ invalidate, but as w the `foo()` example here 
they also may not. 

Note that this is purely about optimization and not correctness. We could always 
merge in this case (per earlier in the stack) but that might invalidate more 
often than we would like.
2023-09-27 14:04:01 -04:00
Joe Savona
66841aa9ac Prune declarations not used after merging
This is the optimization mentioned in #2113. When we merge scopes, often the 
declarations from the first scope become unnecessary, since those values are 
only consumed by the subsequent, now-merged scope. There's no point emitting 
those values as outputs of the merged scope since no one can consume them. 

Thanks to the logic in #2116 we now know the last place each identifier is used. 
We use that again here, to prune declarations that aren't used past the end of 
the merged scope. This is a pretty dramatic win on cache slots used.
2023-09-27 14:04:00 -04:00
Joe Savona
d1355179d7 Improved check for intermediate values for merged scopes
We can't merge scopes if the intervening instructions produce values that are 
used later on. This PR improves the mechanism for detecting this case: first we 
build up a mapping of the last time (max instruction id) each identifier is 
used. Then when we're about to merge scopes we check if all the intervening 
lvalues are last used at or before the scope. If so that means it's safe to 
merge. 

I can't think of any edge cases that are problematic in the old behavior, but 
this version is more trivially correct and should allow us to extend to other 
types of instructions more easily.
2023-09-27 14:04:00 -04:00
Joe Savona
959c6685be Merge consecutive reactive scopes that invalidate together
This is something we've wanted to do for a while, and which @sophiebits also 
brought up. The idea is to merge consecutive reactive scopes that will always 
invalidate together. There are two cases of this: 

* Both scopes have the exact same inputs 

* Or the inputs of the second scope are the outputs of the first 

In both these cases it's pure overhead to keep the scopes separate. In the first 
case where both scopes have the same inputs, merging allows us to check the 
inputs once instead of 2+ times. In the second case, we know that the second 
scope will invalidate when the first does so it's wasteful to recheck the 
outputs of the first scope for changes. 

This is already cutting down on memoization quite a bit in the fixtures. Note 
that there's an additional optimization we can do after merging the second 
category, which is to remove the first scope's declarations if they were only 
referenced by the second scope. I'll add that in a follow-up.
2023-09-27 14:03:59 -04:00
Josh Story
25fc9eaf8c publish react-server-dom-turbopack to canary channels (#27427)
When I added react-server-dom-turbopack I failed to mark the package as
stable so it did not get published with the canary release. This adds
the package to the stable set so it will be published correctly
2023-09-27 10:39:04 -07:00
Josh Story
f81c0f1ed9 [Flight] Implement react-server-dom-turbopack (#27315)
stacked on #27314 

Turbopack requires a different module loading strategy than Webpack and
as such this PR implements a new package `react-server-dom-turbopack`
which largely follows the `react-server-dom-webpack` but is implemented
for this new bundler
2023-09-27 10:03:57 -07:00
Josh Story
701ac2e572 [Flight][Float] Preinitialize module imports during SSR (#27314)
Currently when we SSR a Flight response we do not emit any resources for
module imports. This means that when the client hydrates it won't have
already loaded the necessary scripts to satisfy the Imports defined in
the Flight payload which will lead to a delay in hydration completing.

This change updates `react-server-dom-webpack` and
`react-server-dom-esm` to emit async script tags in the head when we
encounter a modules in the flight response.

To support this we need some additional server configuration. We need to
know the path prefix for chunk loading and whether the chunks will load
with CORS or not (and if so with what configuration).
2023-09-27 09:53:31 -07:00
Josh Story
49eba01930 [Fizz][Float] Refactor Resources (#27400)
Refactors Resources to have a more compact and memory efficient
struture. Resources generally are just an Array of chunks. A resource is
flushed when it's chunks is length zero. A resource does not have any
other state.

Stylesheets and Style tags are different and have been modeled as a unit
as a StyleQueue. This object stores the style rules to flush as part of
style tags using precedence as well as all the stylesheets associated
with the precedence. Stylesheets still need to track state because it
affects how we issue boundary completion instructions. Additionally
stylesheets encode chunks lazily because we may never write them as html
if they are discovered late.

The preload props transfer is now maximally compact (only stores the
props we would ever actually adopt) and only stores props for
stylesheets and scripts because other preloads have no resource
counterpart to adopt props into. The ResumableState maps that track
which keys have been observed are being overloaded. Previously if a key
was found it meant that a resource already exists (either in this render
or in a prior prerender). Now we discriminate between null and object
values. If map value is null we can assume the resource exists but if it
is an object that represents a prior preload for that resource and the
resource must still be constructed.
2023-09-26 09:59:39 -07:00
Sebastian Markbåge
bff6be8eb1 [Fizz] Track postpones in fallbacks (#27421)
This fixes so that you can postpone in a fallback. This postpones the
parent boundary. I track the fallbacks in a separate replay node so that
when we resume, we can replay the fallback itself and finish the
fallback and then possibly later the content. By doing this we also
ensure we don't complete the parent too early since now it has a render
task on it.

There is one case that this surfaces that isn't limited to
prerender/resume but also render/hydrateRoot. I left todos in the tests
for this.

If you postpone in a fallback, and suspend in the content but eventually
don't postpone in the content then we should be able to just skip
postponing since the content rendered and we no longer need the
fallback. This is a bit of a weird edge case though since fallbacks are
supposed to be very minimal.

This happens because in both cases the fallback starts rendering early
as soon as the content suspends. This also ensures that the parent
doesn't complete early by increasing the blocking tasks. Unfortunately,
the fallback will irreversibly postpone its parent boundary as soon as
it hits a postpone.

When you suspend, the same thing happens but we typically deal with this
by doing a "soft" abort on the fallback since we don't need it anymore
which unblocks the parent boundary. We can't do that with postpone right
now though since it's considered a terminal state.

I think I'll just leave this as is for now since it's an edge case but
it's an annoying exception in the model. Makes me feel I haven't quite
nailed it just yet.
2023-09-25 19:02:25 -04:00
Ruslan Lesiutin
94d5b5b2bf React DevTools 4.28.3 -> 4.28.4 (#27419)
* refactor[devtools/extension]: refactored messaging logic across
different parts of the extension ([hoxyq](https://github.com/hoxyq) in
[#27417](https://github.com/facebook/react/pull/27417))
* fix[devtools/extension]: added a workaround for proxy content script
injection in firefox ([hoxyq](https://github.com/hoxyq) in
[#27375](https://github.com/facebook/react/pull/27375))
* fix[devtools/useTransition]: don't check for dispatch property when
determining if hook is stateful ([hoxyq](https://github.com/hoxyq) in
[#27365](https://github.com/facebook/react/pull/27365))
* feat[devtools/extension]: show disclaimer when page doesnt run react
and refactor react polling logic ([hoxyq](https://github.com/hoxyq) in
[#27373](https://github.com/facebook/react/pull/27373))
* feat:-Added a delete all filters action and added title to the add
filter a… ([Biki-das](https://github.com/Biki-das) in
[#27332](https://github.com/facebook/react/pull/27332))
* fix[devtools/extension]: unregister dynamically injected content
scripts instead of filtering ([hoxyq](https://github.com/hoxyq) in
[#27369](https://github.com/facebook/react/pull/27369))
* refactor[devtools/extension]: more stable element updates polling to
avoid timed out errors ([hoxyq](https://github.com/hoxyq) in
[#27357](https://github.com/facebook/react/pull/27357))
* feat[devtools/extension]: add dark theme for popup
([rakleed](https://github.com/rakleed) in
[#27330](https://github.com/facebook/react/pull/27330))
2023-09-25 13:24:52 -04:00
Sebastian Markbåge
430e712bbd [Fizz] Restrict types of keyPath when it is known (#27418)
When we render an element, we provide the newly created keypath because
that means we're never at the root.
2023-09-25 12:26:17 -04:00
Ruslan Lesiutin
09285d5a7f refactor[devtools/extension]: refactored messaging logic across different parts of the extension (#27417)
1.
9fc04eaf3f (diff-2c5e1f5e80e74154e65b2813cf1c3638f85034530e99dae24809ab4ad70d0143)
introduced a vulnerability: we listen to `'fetch-file-with-cache'` event
from `window` to fetch sources of the file, in which we want to parse
hook names. We send this event via `window`, which means any page can
also use this and manipulate the extension to perform some `fetch()`
calls. With these changes, instead of transporting message via `window`,
we have a distinct content script, which is responsible for fetching
sources. It is notified via `chrome.runtime.sendMessage` api, so it
can't be manipulated.
2. Consistent structure of messages `{source: string, payload: object}`
in different parts of the extension
3. Added some wrappers around `chrome.scripting.executeScript` API in
`packages/react-devtools-extensions/src/background/executeScript.js`,
which support custom flow for Firefox, to simulate support of
`ExecutionWorld.MAIN`.
2023-09-25 12:02:13 -04:00
Sebastian Markbåge
69728fde0a [Flight] Dedupe suspense boundaries when it has already been found earlier (#27408)
If we track a postponed SuspenseBoundary parent that we have to replay
through before it has postponed and it postpones itself later, we need
to upgrade it to a postponed replay boundary instead of adding two.
2023-09-23 12:33:48 -04:00
Sophie Alpert
7f6201889e Ship diffInCommitPhase (#27409)
Performance tests at Meta showed neutral results.
2023-09-22 20:24:42 -07:00
Sebastian Markbåge
d9e00f795b Stop flowing and then abort if a stream is cancelled (#27405)
We currently abort a stream either it's explicitly told to abort (e.g.
by an abortsignal). In this case we still finish writing what we have as
well as instructions for the client about what happened so it can
trigger fallback cases and log appropriately.

We also abort a request if the stream itself cancels. E.g. if you can't
write anymore. In this case we should not write anything to the outgoing
stream since it's supposed to be closed already now. However, we should
still abort the request so that more work isn't performed and so that we
can log the reason for it to the onError callback.

We should also not do any work after aborting.

There we need to stop the "flow" of bytes - so I call stopFlowing in the
cancel case before aborting.

The tests were testing this case but we had changed the implementation
to only start flowing at initial read (pull) instead of start like we
used to. As a result, it was no longer covering this case. We have to
call reader.read() in the tests to start the flow so that we need to
cancel it.

We also were missing a final assertion on the error logs and since we
were tracking them explicitly the extra error was silenced.
2023-09-22 15:16:49 -04:00
Ruslan Lesiutin
f9d75e32ba fix[devtools/extension]: added a workaround for proxy content script injection in firefox (#27375)
Changes:
1. [Firefox-only] For some reason, Firefox might try to inject
dynamically registered content script in pages like `about:blank`. I
couldn't find a way to change this behaviour, `about:` is not a valid
scheme, so we can't exclude it and `match_about_blank` flag is not
supported in `chrome.scripting.registerContentScripts`.
2. While navigating the history in Firefox, some content scripts might
not be re-injected and still be alive. To handle this, we are now
patching `window` with `__REACT_DEVTOOLS_PROXY_INJECTED__` flag, to make
sure that proxy is injected and only once. This flag is cleared on
`pagehide` event.
2023-09-22 19:36:03 +01:00
Jan Kassens
9ba1bbd656 Upgrade to Flow 0.217.0 (#27407)
Just keeping React up to date.

[Changelog](https://github.com/facebook/flow/blob/main/Changelog.md)
2023-09-22 11:40:36 -04:00
Mofei Zhang
7b58600fb9 [tests] Repros for bugs and todos 2023-09-21 22:38:40 -04:00
Mofei Zhang
b9275f65bc [ez] Add TODO bailout on non-backward compatible holey arrays
--- 

(pasted from comment) 

Instead of handling holey arrays, bail out with a TODO error. 

Older versions of babel seem to have inconsistent handling of holey arrays, at 
least when paired with HermesParser. When using these versions, we should bail 
out instead of throwing a Babel validation error. 

Issue: 

The babel ast definition for array elements changed from Array<PatternLike> to 
Array<PatternLike | null>. Older versions do not expect null in the ArrayPattern 
ast and will throw a validation error during Codegen. 

- HermesParser will parse [, b] into [NodePath<null>, NodePath<Identifier>] 

- Forget will try to preserve this holey array when we codegen back to js 

(e.g. we call a babel builder function arrayPattern([null, identifier])) 

- Babel will fail with `TypeError: Property elements[0] of ArrayPattern    
expected node to be of a type ["PatternLike"] but instead got null` 

PR that changed the AST definition: 


https://github.com/babel/babel/pull/10917/files#diff-19b555d2f3904c206af406540d9df200b1e16befedb83ff39ebfcbd876f7fa8aL52-R56 

[ez] Add TODO bailout on non-backward compatible holey arrays 

--- 

(pasted from comment) 

Instead of handling holey arrays, bail out with a TODO error. 

Older versions of babel seem to have inconsistent handling of holey arrays, at 
least when paired with HermesParser. When using these versions, we should bail 
out instead of throwing a Babel validation error. 

Issue: 

The babel ast definition for array elements changed from Array<PatternLike> to 
Array<PatternLike | null>. Older versions do not expect null in the ArrayPattern 
ast and will throw a validation error during Codegen. 

- HermesParser will parse [, b] into [NodePath<null>, NodePath<Identifier>] 

- Forget will try to preserve this holey array when we codegen back to js 

(e.g. we call a babel builder function arrayPattern([null, identifier])) 

- Babel will fail with `TypeError: Property elements[0] of ArrayPattern    
expected node to be of a type ["PatternLike"] but instead got null` 

PR that changed the AST definition: 


https://github.com/babel/babel/pull/10917/files#diff-19b555d2f3904c206af406540d9df200b1e16befedb83ff39ebfcbd876f7fa8aL52-R56
2023-09-21 20:54:58 -04:00
Lauren Tan
8b679e9138 [ez] Fix prettier not formatting test fixtures in vscode
This was super annoying. Turns out we had a top level directory for old projects 
called fixtures that shared a name with our fixture directories.
2023-09-21 17:04:25 -04:00
Lauren Tan
1ce952e687 Support hoisting const variable declarations
This PR adds preliminary support for hoisting const variable declarations. We do 
this via BuildHIR when lowering top level statements in a BlockStatement, by 
first checking which bindings are in scope to be hoistable if referenced before 
they are declared. The declarations are then hoisted to their earliest point 
where they are referenced (ie the top level statement just before) as context 
variables. 

Later, prior to codegen, we restore the original source by removing the 
DeclareContexts and transforming their associated StoreContexts back. 

Support for hoisting other kinds of declarations will come in future PRs!
2023-09-21 17:00:04 -04:00
Ruslan Lesiutin
56b14477e9 fix[devtools/useTransition]: don't check for dispatch property when determining if hook is stateful (#27365)
https://github.com/facebook/react/pull/26740 introduced regression:
React DevTools doesn't record updates for `useTransition` hook. I can
add more details about things on DevTools side, if needed.

The root cause is
491aec5d61/packages/react-reconciler/src/ReactFiberHooks.js (L2728-L2730)

React DevTools expects dispatch to be present for stateful hooks that
can schedule an update -
2eed132847/packages/react-devtools-shared/src/backend/renderer.js (L1422-L1428)

With these changes, we still call dispatch in `startTransition`, but
also patch `queue` object with it, so that React DevTools can recognise
`useTransition` as stateful hook that can schedule update.

I am not sure if this is the right approach to fix this, can we
distinguish if `startTransition` was called from `useTransition` hook or
as a standalone function?
2023-09-21 21:26:20 +01:00
Andrew Clark
68ac6dbcf8 Use MurmurHash3 when native hashing function is not available (#27399) 2023-09-21 14:59:51 -04:00
Sebastian Markbåge
47fed6961f [Fizz] Simplify ReplayNode data structure (#27395)
The key is that instead of storing different tags of resumable points,
we just store if a replay node has any resumable slots and if that's at
the root `number` or if it has resumable slots by index.

This is a simpler and more compact format because we don't have to
separate the three Resume forms.

This helps deal with Postpone in fallbacks because it doesn't just
double all the cases.
2023-09-21 13:49:57 -04:00
Sophie Alpert
3c27178a2f Update tracked value after resetting radio group (#27394)
Fixes #26876, I think. Review each commit separately (all assertions
pass in main already, except the last assertInputTrackingIsClean in
"should control radio buttons").

I'm actually a little confused on two things here:
* All the isCheckedDirty assertions are true. But I don't think we set
.checked unconditionally? So how does this happen?
* https://github.com/facebook/react/issues/26876#issuecomment-1611662862
claims that
d962f35ca...1f248bdd7 contains
the faulty change, but it doesn't appear to change the restoration logic
that I've touched here. (One difference outside restoration is that
updateProperties did previously set `.checked` when `nextProp !==
lastProp` whereas the new logic in updateInput is to set it when
`node.checked !== !!checked`.)

But it seems to me like we need this call here anyway, and if it fixes
it then it fixes it? I think technically speaking we probably should do
all the updateInput() calls and then all the updateValueIfChanged()
calls—in particular I think if clicking A changed the checked radio
button from B to C then the code as I have it would be incorrect, but
that also seems unlikely so idk whether to care.

cc @zhengjitf @Luk-z who did some investigation on the original issue
2023-09-20 21:57:09 -07:00
Andrew Clark
2b3d582683 useFormState: Hash the component key path for more compact output (#27397)
To support MPA-style form submissions, useFormState sends down a key
that represents the identity of the hook on the page. It's based on the
key path of the component within the React tree; for deeply nested
hooks, this keypath can become very long. We can hash the key to make it
shorter.

Adds a method called createFastHash to the Stream Config interface.
We're not using this for security or obfuscation, only to generate a
more compact key without sacrificing too much collision resistance.

- In Node.js builds, createFastHash uses the built-in crypto module.
- In Bun builds, createFastHash uses Bun.hash. See:
https://bun.sh/docs/api/hashing#bun-hash

I have not yet implemented createFastHash in the Edge, Browser, or FB
(Hermes) stream configs because those environments do not have a
built-in hashing function that meets our requirements. (We can't use the
web standard `crypto` API because those methods are async, and yielding
to the main thread is too costly to be worth it for this particular use
case.) We'll likely use a pure JS implementation in those environments;
for now, they just return the original string without hashing it. I'll
address this in separate PRs.
2023-09-20 17:13:14 -04:00
Karim Piyar Ali
1f4936660d [Fizz] Allow passing a reason to abortStream (#26992)
## Summary

Currently `ReactFizzServer.abort` allows you to pass in the a `reason`
error, which then gets passed to the `onError` handler for each task
that ends up getting aborted. This adds in the ability to pass down that
same `reason` error to `ReactDOMServerFB.abortStream` as well.

## How did you test this change?

Added a test case to ReactDOMServerFB-test.internal.js
2023-09-20 16:41:12 -04:00
Sebastian Markbåge
b775564d35 [Fizz] Ensure Resumable State is Serializable (#27388)
Moves writing queues to renderState.

We shouldn't need the resource tracking's value. We just need to know if
that resource has already been emitted. We can use a Set for this. To
ensure that set is directly serializable we can just use a
dictionary-like object with no value.

See individual commits for special cases.
2023-09-20 12:21:53 -04:00
Ruslan Lesiutin
1b1dcb8a40 feat[devtools/extension]: show disclaimer when page doesnt run react and refactor react polling logic (#27373)
Changes:
1. Refactored react polling logic, now each `.eval()` call is wrapped in
Promise, so we can chain them properly.
2. When user has browser DevTools opened and React DevTools panels were
mounted, user might navigate to the page, which doesn't have React
running. Previously, we would show just blank white page, now we will
show disclaimer. Disclaimer appears after 5 failed attempts to find
React. We will also show this disclaimer if it takes too long to load
the page, but once any React instance is loaded and registered, we will
update the panels.
3. Dark theme support for this disclaimer and popups in Firefox &
Chromium-based browsers

**Important**: this is only valid for case when React DevTools panels
were already created, like when user started debugging React app and
then switched to non-React page. If user starts to debug non-React app
(by opening browser DevTools for it), we will not create these panels,
just like before.

Q: "Why do we poll to get information about react?"
A: To handle case when react is loaded after the page has been loaded,
some sandboxes for example.

| Before | After |
| --- | --- |
| <img width="1840" alt="Screenshot 2023-09-14 at 15 37 37"
src="https://github.com/facebook/react/assets/28902667/2e6ffb39-5698-461d-bfd6-be2defb41aad">
| <img width="1840" alt="Screenshot 2023-09-14 at 15 26 16"
src="https://github.com/facebook/react/assets/28902667/1c8ad2b7-0955-41c5-b8cc-d0fdb03e13ca">
|
2023-09-20 13:30:50 +01:00
BIKI DAS
a3743b2e44 feat:-Added a delete all filters action and added title to the add filter a… (#27332)
### changes

1. A small action added to delete all filters, it can be useful to
delete when someone has a bunch of them rather than clicking on them
selectively.

2.There was no title on the `add filter` button so added the same


https://github.com/facebook/react/assets/72331432/af6c0725-05b6-4f46-b8c9-8079bd933a8e



review @hoxyq

---------

Co-authored-by: BIKI DAS <bikidas@BIKIs-MacBook-Pro.local>
Co-authored-by: Ruslan Lesiutin <rdlesyutin@gmail.com>
2023-09-20 10:26:44 +01:00
Mofei Zhang
36f979d9d4 [patch] Repro and fix for duplicate import statements 2023-09-19 18:34:14 -04:00
Joe Savona
2fa04d128e Transitive mixed type, take 2
This is a redo of #1640 now that we've established the necessary infrastructure, 
most notably `Effect.ConditionallyMutate` and `noAlias` from #2103 earlier in 
this stack. We can now understand the semantics of hooks that return deeply 
readonly values composed of primitives, arrays, or objects such that any 
`.map()` or `.filter()` calls are guaranteed to be the corresponding array 
methods. That further allows us to refine, since we know that the lambdas passed 
to these calls can't alias, are conditionally mutable, etc. All in all this 
should let us memoize less in practice.
2023-09-18 16:42:25 -07:00
Joe Savona
32569d2113 noAlias support for CallExpr incl hooks
Adds `noAlias` support for CallExpression, including hooks. Note that we treat 
hook arguments as escaping by default — ie we assume that they don't just flow 
into the hook return value, but are just outright escape points equivalent to a 
return. A `noAlias` annotation on a hook definition disables both: this will 
allow us to avoid memoizing the `graphql` tag arguments to `useFragment`, for 
example.
2023-09-18 14:38:26 -07:00
Joe Savona
0810175bba More tests for noAlias
Adds another test for `noAlias` to show that if part of the receiver could 
escape that we still memoize it.
2023-09-18 14:25:12 -07:00
Joe Savona
b02f5a5e0e Dont compile code w useMemoCache
Skips compilation of code that has a reference to `useMemoCache()`, as a 
last-resort to avoid double-compilation of code. This is meant as a quick way to 
unblock since we're still seeing some double compilation issues when syncing 
internally.
2023-09-18 09:46:04 -07:00
Sebastian Markbåge
2807d781a0 [Fizz] Reuse rootSegmentID as the SuspenseBoundaryID (#27387)
Originally the intension was to have React assign an ID to a user
rendered DOM node inside a `fallback` while it was loading. If there
already were an explicit `id` defined on the DOM element we would reuse
that one instead. That's why this was a DOM Config option and not just
built in to Fizz.

This became tricky since it can load late and so we'd have to transfer
it down and detect it only once it finished rendering and if there is no
DOM element it doesn't work anyway. So instead, what we do in practice
is to always use a `<template>` tag with the ID. This has the downside
of an extra useless node and shifting child CSS selectors.

Maybe we'll get around to fixing this properly but it might not be worth
it.

This PR just gets rid of the SuspenseBoundaryID concept and instead we
just use the same ID number as the root segment ID of the boundary to
refer to the boundary to simplify the implementation.

This also solves the problem that SuspenseBoundaryID isn't currently
serializable (although that's easily fixable by itself if necessary).
2023-09-18 11:56:47 -04:00
Sebastian Markbåge
925c66a647 [Fizz] Client render the nearest child or parent suspense boundary if replay errors or is aborted (#27386)
Based on #27385.

When we error or abort during replay, that doesn't actually error the
component that errored because that has already rendered. The error only
affects any child that is not yet completed. Therefore the error kind of
gets thrown at the resumable point.

The resumable point might be a hole in the replay path, in which case
throwing there errors the parent boundary just the same as if the replay
component errored. If the hole is inside a deeper Suspense boundary
though, then it's that Suspense boundary that gets client rendered. I.e.
the child boundary. We can still finish any siblings.

In the shell all resumable points are inside a boundary since we must
have finished the shell. Therefore if you error in the root, we just
simply just turn all incomplete boundaries into client renders.
2023-09-18 11:25:56 -04:00
Sebastian Markbåge
df061b3966 [Fizz] Don't bail out of flushing if we still have pending root tasks (#27385)
The idea for this check is that we shouldn't flush anything before we
flush the shell. That may or may not hold true in future formats like
RN.

It is a problem for resuming because with resuming it's possible to have
root tasks that are used for resuming but the shell was already flushed
so we can have completed boundaries before the shell has fully resumed.
What matters is whether the parent has already flushed or not.

It's not technically necessary to bail early because there won't be
anything in partialBoundaries or completedBoundaries because nothing
gets added there unless the parent has already flushed.

It's not exactly slow to have to check the length of three arrays so
it's probably not a big deal.

Flush partials in an early preamble needs further consideration
regardless.
2023-09-18 11:25:21 -04:00
Joe Savona
1879fbe644 Option to not memoize non-aliased function parameters
This has been nagging at me for a _long_ time: we unnecessarily memoize function 
callbacks passed to things like Array.prototype.map, even though we know these 
functions can't escape. This PR fixes this as follows: 

* Adds a `noAlias?: boolean` flag to builtin function signatures, defaulting to 
false if not specified. 

* Adds a feature flag, `enableNoAliasOptimizations`, to gate optimizations based 
on the value of that new flag. 

* When the feature is enabled, `PruneNonEscapingScopes` now looks up the 
signature of method calls, and avoids memoizing the arguments if the signatures 
specifies `noAlias: true`. 

* Annotates Array.prototype.map and Array.prototype.filter as `noAlias`. 

This does not mean we'll never memoize arguments to Array.prototype.map, it just 
means that the argument itself won't be considered as escaping. If the function 
still escapes by some other means it will get memoized: 

``` 

function Component(props) { 

const f = () => {}; // memoized! 

const x = [].map(f); // not from here.. 

return [x, f]; // but bc it escapes here 

} 

``` 

Note: this delivers some of the wins from #1640. That PR tried to do a bunch of 
things, part of which I already landed w the introduction of 
ConditionallyMutate, which allowed us to type Array.prototype.map. This PR 
further gives us the ability to understand functions that don't alias their 
params at all. The remaining bit from #1640 is the idea of understanding that 
key hooks such as `useFragment()` return transitively readonly, transitively 
array/object/primitive values, and any `.map()` or `.filter()` calls must be on 
arrays, allowing us to optimize them. Without that extra step, we'll still have 
to memoize a lot of `array.map()` lambdas just because we aren't sure that the 
receiver is an Array. But this PR helps with some cases, and lays the groundwork 
for the rest of that PR.
2023-09-15 16:18:03 -07:00
Sebastian Markbåge
a5fc797db1 [Fizz] Replay Postponed Paths (#27379)
This forks Task into ReplayTask and RenderTask.

A RenderTask is the normal mode and it has a segment to write into.

A ReplayTask doesn't have a segment to write into because that has
already been written but instead it has a ReplayState which keeps track
of the next set of paths to follow. Once we hit a "Resume" node we
convert it into a RenderTask and continue rendering from there.

We can resume at either an Element position or a Slot position. An
Element pointing to a component doesn't mean we resume that component,
it means we resume in the child position directly below that component.
Slots are slots inside arrays.

Instead of statically forking most paths, I kept using the same path and
checked for the existence of a segment or replay state dynamically at
runtime.

However, there's still quite a bit of forking here like retryRenderTask
and retryReplayTask. Even in the new forks there's a lot of duplication
like resumeSuspenseBoundary, replaySuspenseBoundary and
renderSuspenseBoundary. There's opportunity to simplify this a bit.
2023-09-15 15:24:04 -04:00
Joe Savona
bde7875f20 fbt:param does not allow jsxfragment children 2023-09-15 12:10:51 -07:00
Andrew Clark
2d2f2af29b Restrict React DOM imports from Server Components (#27382)
Adds a separate entry point for the react-dom package when it's accessed
from a Server Component environment, using the "react-server" export
condition.

When you're inside a Server Component module, you won't be able to
import client-only APIs like useState. This applies to almost all React
DOM exports, except for Float ones like preload.
2023-09-15 14:53:19 -04:00
Joe Savona
dc4e63e2d5 fbt:param does not allow jsxtext children
Per the title, `<fbt:param>0</fbt:param>` is invalid FBT, you must wrap the text 
in an expression container. But that's not all, `fbt:param` can only have a 
single child, which means we have to strip out the text elements that occur from 
the whitespace in the source.
2023-09-15 11:30:01 -07:00
Joe Savona
e5e71dfd59 Memoize fbt children in same scope
Fixes another special-case rule of fbt that i wasn't aware of: apparently 
`<fbt:param>` elements don't have to appear as direct children of `<fbt>`, they 
can be nested, and in this case they must appear as direct children of the fbt 
and not via an identifier indirection. This PR recursively extends the scope of 
FBT operands to make this work.
2023-09-15 10:31:55 -07:00
Sathya Gunasekaran
35fb6e05e1 [hir] Refactor function lowering from lowerFunctionExpression
Split out the HIR generation bits from the lowering of the actual function. The 
lowering will get reused when we lower object methods.
2023-09-15 17:16:05 +01:00
Sathya Gunasekaran
b26cc58070 [hir] Add a "type" field to ObjectProperty
This will be used to distinguish between a property and a method.
2023-09-15 17:16:05 +01:00
Sathya Gunasekaran
88f65d44a7 [hir] Refactor out LoweredFunction from FunctionExpression 2023-09-15 17:16:04 +01:00
Sathya Gunasekaran
3bda9f78c3 [hir] Introduce ObjectMethod type
This will be used to store fields representing an object method.
2023-09-15 16:28:44 +01:00
Sathya Gunasekaran
365a88a8aa [hir] Refactor out ObjectPropertyKey
The type of ObjectProperty is specific to the key, not the ObjectProperty. In 
the future, we want to add a type to represent the value of the ObjectProperty. 

This PR moves out the fields related to the key of the ObjectProperty to a 
separate type.
2023-09-15 16:08:41 +01:00
Mofei Zhang
00e9888fb8 [ez][patch] Remove calls to NodePath.hasNode
--- 

Recent commits added calls to `NodePath.hasNode`, which does not exist in babel 
v7.1.6 (internal). Forget is failing with this error. 

```js 

TypeError: handlerPath.hasNode is not a function 

at lowerStatement (.../babel-plugin-react-forget/HIR/BuildHIR.js:924:58) 

... 

```
2023-09-15 13:55:33 +01:00
Joe Savona
c70e87f535 Wrap JSXElement in expr container (for JSXAttribute) 2023-09-14 21:48:04 -07:00
Joe Savona
14630c0618 Dont compile functions w multiple args (infer mode) 2023-09-14 16:22:06 -07:00
Joe Savona
ca1217be6d Wrap JSXFragment in expr container for attributes
@mofeiZ noticed that some configurations of prettier don't support JSXFragment 
appearing as a JSXAttribute value, in violation of the spec. Coincidentally I 
noticed that our internal build system also fails on this as i was trying to 
roll out on more surfaces. This PR makes sure we wrap fragments in an 
expressioncontainer if they appear as jsxattribute values.
2023-09-14 16:22:05 -07:00
Joe Savona
88b1a069c0 Add examples for phi type inference
Adds test cases that would demonstrate different output if we were to update 
InferTypes to infer the types of phi identifiers when their operands have the 
same type. We currently do infer such types, but attach them to phi.type instead 
of phi.id.type, so the type doesn't effect inference. Fixing that would cause 
the output on these examples to change — however, per the discussion on #2079, 
we'd also incorrectly set the mutable ranges in some cases and cause incorrect 
compilation. 

I did a thorough review of InferReferenceEffects and can't figure out how to 
trigger the bug in our current implementation — the bug only kicks in when phi 
operands would be mutated as a store instead of a mutate, and that cannot happen 
given our currently imprecise types on phi identifiers.
2023-09-14 11:56:09 -07:00
Mofei Zhang
f993f0c2a5 [pipeline] panicOnBailout -> panicThreshold; remove isDev logging
--- 

Changed `panicOnBailout: boolean` to `panicThreshold`, which has the following 
options. Note that `ALL_ERRORS` corresponds to `panicOnBailout = true` and 
`CRITICAL_ERRORS` corresponds to `panicOnBailout = false`. `NONE` is a new 
option. 

```js 

export type PanicThresholdOptions = 

// Bail out of compilation on all errors by throwing an exception. 

| "ALL_ERRORS" 

// Bail out of compilation only on critical or unrecognized errors. 

// Instead, silently skip the erroring function. 

| "CRITICAL_ERRORS" 

// Never bail out of compilation. Instead, silently skip the erroring 

// function or file. 

| "NONE"; 

``` 

Jest seems to run babel through a different pipeline than Metro and - 
(perhaps through its complex `require` interjection logic). When running jest 
tests, exceptions thrown by babel transforms will bubble up to the nearest 
exception boundary which is often the jest test itself. This may not be a useful 
signal to anyone running a jest test with Forget enabled, as the erroring code 
may be within Forget itself or a transitively required module. 

Another reason to immediately bailing out on critical errors is that we may want 
to record errors found in the rest of the file. 

--- 

I'm not convinced that this change makes sense. A counterargument is that any 
CriticalErrors *should* be reported as parse errors, regardless of the runtime 
mode. Anyhow, this would be useful long term for our static analysis scripts 
(e.g. collecting info on bailouts and compilation info e.g. # slots used for 
JSX) as we want to compile-as-much-as-possible in those.
2023-09-14 20:00:43 +01:00
Mofei Zhang
b2230f62a3 [pipeline] Make logging more structured
--- 

Add types for logged events, including a `CompileSuccess` event which can help 
us record successfully compiled Forget functions and their compilation details 
(e.g. # memoSlots used).
2023-09-14 19:40:39 +01:00
Mofei Zhang
869466bb0b Revamp compilation modes
We currently have multiple flags for targeting which functions to compile, but 
they are actually mutually exclusive. This PR consolidates to a single 
`compilationMode: 'annotation' | 'infer' | 'all'` flag: 

* Annotation compiles only functions that explicitly opt-in with "use forget" 

* Infer compiles explicitly opted-in functions (via "use forget") as well as any 
known/inferred components or hooks: 

* Component declarations 

* Component or hook-like functions (same rules as the ESLint plugin but with an 
extra check for whether it uses JSX or calls a hook) 

* All compiles all top-level functions. We should get rid of this in a follow-up 
and make tests use infer mode by default, and add explicit opt-ins where 
necessary. 

In all modes, "use no forget" always takes precedence and can be used to 
opt-out. The default mode is now "infer".
2023-09-14 19:40:39 +01:00
Mofei Zhang
b3730eb496 [ez][be] Make early return explicit in compileAndInsert 2023-09-14 19:40:38 +01:00
Andrew Clark
d6dcad6a8b useFormState: Only emit markers if postback state is provided (#27374)
This is an optimization where useFormState will only emit extra comment
markers if a form state is passed at the root. If no state is passed, we
don't need to emit anything because none of the hooks will match.
2023-09-14 11:46:16 -04:00
Ruslan Lesiutin
54c2f2a346 fix[devtools/extension]: unregister dynamically injected content scripts instead of filtering (#27369)
Same as https://github.com/facebook/react/pull/26765.
Related bug report -
https://bugs.chromium.org/p/chromium/issues/detail?id=1393762.

This was changed in https://github.com/facebook/react/pull/27215, when I
have refactored background logic in the extension. I've missed this
case, because the extension was working in incognito mode.

Turns out, it stops working after the first reload, and it stops only in
incognito mode, so I am rolling out back the previous workaround.

Tested on Chrome that it fixes the extension in incognito mode and that
it doesn't affect default mode.
2023-09-14 15:21:28 +01:00
Andrew Clark
caa716d50b useFormState: MPA submissions to a different page (#27372)
The permalink option of useFormState controls which page the form is
submitted to during an MPA form submission (i.e. a submission that
happens before hydration, or when JS is disabled). If the same
useFormState appears on the resulting page, and the permalink option
matches, it should receive the form state from the submission despite
the fact that the keypaths do not match.

So the logic for whether a form state instance is considered a match is:
- Both instances must be passed the same action signature
- If a permalink is provided, the permalinks must match.
- If a permalink is not provided, the keypaths must match.

Currently, if there are multiple matching useFormStates, they will all
match and receive the form state. We should probably only match the
first one, and/or warn when this happens. I've left this as a TODO for
now, pending further discussion.
2023-09-14 01:07:00 -04:00
Sebastian Markbåge
a6e4791b11 [Fizz] Fix root segment IDs (#27371)
Typically we assign IDs lazily when flushing to minimize the ids we have
to assign and we try to maximize inlining.

When we prerender we could always flush into a buffer before returning
but that's not actually what we do right now. We complete rendering
before returning but we don't actually run the flush path until someone
reads the resulting stream. We assign IDs eagerly when something
postpone so that we can refer to those ids in the holes without flushing
first.

This leads to some interesting conditions that needs to consider this.

This PR also deals with rootSegmentId which is the ID of the segment
that contains the body of a Suspense boundary. The boundary needs to
know this in addition to the Suspense Boundary's ID to know how to
inject the root segment into the boundary.

Why is the suspense boundary ID and the rootSegmentID just not the same
ID? Why don't segments and suspense boundary not share ID namespace?
That's a good question and I don't really remember. It might not be a
good reason and maybe they should just be the same.
2023-09-13 23:18:03 -04:00
Andrew Clark
95c9554bc7 useFormState: Compare action signatures when reusing form state (#27370)
During an MPA form submission, useFormState should only reuse the form
state if same action is passed both times. (We also compare the key
paths.)

We compare the identity of the inner closure function, disregarding the
value of the bound arguments. That way you can pass an inline Server
Action closure:

```js
function FormContainer({maxLength}) {
  function submitAction(prevState, formData) {
    'use server'
    if (formData.get('field').length > maxLength) {
      return { errorMsg: 'Too many characters' };
    }
    // ...
  }
  return <Form submitAction={submitAction} />
}
```
2023-09-13 20:46:22 -04:00
Andrew Clark
612b2b6601 useFormState: Reuse state from previous form submission (#27321)
If a Server Action is passed to useFormState, the action may be
submitted before it has hydrated. This will trigger a full page
(MPA-style) navigation. We can transfer the form state to the next page
by comparing the key path of the hook instance.

`ReactServerDOMServer.decodeFormState` is used by the server to extract
the form state from the submitted action. This value can then be passed
as an option when rendering the new page. It must be passed during both
SSR and hydration.

```js
const boundAction = await decodeAction(formData, serverManifest);
const result = await boundAction();
const formState = decodeFormState(result, formData, serverManifest);

// SSR
const response = createFromReadableStream(<App />);
const ssrStream = await renderToReadableStream(response, { formState })

// Hydration
hydrateRoot(container, <App />, { formState });
```

If the `formState` option is omitted, then the state won't be
transferred to the next page. However, it must be passed in both places,
or in neither; misconfiguring will result in a hydration mismatch.

(The `formState` option is currently prefixed with `experimental_`)
2023-09-13 18:30:40 -04:00
Sathya Gunasekaran
88186db690 [hir] Make hoisting a TODO bailout 2023-09-13 17:58:58 +01:00
Sebastian Markbåge
e5205658f4 [Fizz] Various smaller refactors (#27368)
Back ported from a larger PR.
2023-09-13 00:16:44 -04:00
Andrew Clark
69be472c11 Fix: Initialize childIndex in Task constructor (#27367)
This field was not being initialized. Although the property is part of
the Flow type, the type error wasn't caught because the constructor
itself is not covered by Flow, which is unfortunate. (I assume this is
related to the dev-only componentStack property.)
2023-09-12 22:17:03 -04:00
Andrew Clark
d07921eeda Don't modify keyPath until right before recursive renderNode call (#27366)
Currently, if a component suspends, the keyPath has already been
modified to include the identity of the component itself; the path is
set before the component body is called (akin to the begin phase in
Fiber). An accidental consequence is that when the promise resolves and
component is retried, the identity gets appended to the keyPath again,
leading to a duplicate node in the path.

To address this, we should only modify contexts after any code that may
suspend. For maximum safety, this should occur as late as possible:
right before the recursive renderNode call, before the children are
rendered.

I did not add a test yet because there's no feature that currently
observes it, but I do have tests in my other WIP PR for useFormState:
#27321
2023-09-12 21:27:23 -04:00
Sebastian Markbåge
7a3cb8f9cf Track the key path difference between right before the first array (#27360)
There's a subtle difference if you suspend before the first array or
after. In Fiber, we don't deal with this because we just suspend the
parent and replay it if lazy() or Usable are used in its child slots. In
Fizz we try to optimize this a bit more and enable resuming inside the
component.

Semantically, it's different if you suspend/postpone before the first
child array or inside that child array. Because when you resume the
inner result might be another array and either that's part of the parent
path or part of the inner slot.

There might be more clever way of structuring this but I just use -1 to
indicate that we're not yet inside the array and is in the root child
position. If that renders an element, then that's just the same as the 0
slot.

We need to also encode this in the resuming. I called that resuming the
element or resuming the slot.
2023-09-12 12:30:42 -04:00
Josh Story
bbc8530ed7 [Float] Refactor public interface and internal HostDispatcher implementation (#27361)
When Float was first developed the internal implementation and external
interface were the same. This is problematic for a few reasons. One, the
public interface is typed but it is also untrusted and we should not
assume that it is actually respected. Two, the internal implementations
can get called from places other than the the public interface and
having to construct an options argument that ends up being destructured
to process the request is computationally wasteful and may limit JIT
optimizations to some degree. Lastly, the wire format was not as
compressed as it could be and it was untyped.

This refactor aims to address that by separating the public interface
from the internal implementations so we can solve these challenges and
also make it easier to change Float in the future

* The internal dispatcher method preinit is now preinitStyle and
preinitScript.
* The internal dispatcher method preinitModule is now
preinitModuleScript in anticipation of different implementations for
other module types in the future.
* The wire format is explicitly typed and only includes options if they
are actually used omitting undefined and nulls.
* Some function arguments are not options even if they are optional. For
instance precedence can be null/undefined because we deafult it to
'default' however we don't cosnider this an option because it is not
something we transparently apply as props to the underlying instance.
* Fixes a problem with keying images in flight where srcset and sizes
were not being taken into account.
* Moves argument validation into the ReactDOMFloat file where it is
shared with all runtimes that expose these methods
* Fixes crossOrigin serialization to use empty string except when
'use-credentials'
2023-09-12 08:09:10 -07:00
Ruslan Lesiutin
2eed132847 refactor[devtools/extension]: more stable element updates polling to avoid timed out errors (#27357)
Some context:
- When user selects an element in tree inspector, we display current
state of the component. In order to display really current state, we
start polling the backend to get available updates for the element.

Previously:
- Straight-forward sending an event to get element updates each second.
Potential race condition is not handled in any form.
- If user navigates from the page, timeout wouldn't be cleared and we
would potentially throw "Timed out ..." error.
- Bridge disconnection is not handled in any form, if it was shut down,
we could spam with "Timed out ..." errors.

With these changes:
- Requests are now chained, so there can be a single request at a time.
- Handling both navigation and shut down events.

This should reduce the number of "Timed out ..." errors that we see in
our logs for the extension. Other surfaces will also benefit from it,
but not to the full extent, as long as they utilize
"resumeElementPolling" and "pauseElementPolling" events.

Tested this on Chrome, running React DevTools on multiple tabs,
explicitly checked the case when service worker is in idle state and we
return back to the tab.
2023-09-12 15:05:39 +01:00
Joe Savona
d2f46b1437 Delete now-unused mermaid visualization 2023-09-11 16:58:22 -07:00
Joe Savona
ade3235ca3 ForInStatement: specialize inference/types
Replaces the use of `NextIterableOf` in for-in with a new `NextPropertyOf` 
instruction. The key distinction is `for-of` invokes an arbitrary iterator, 
which means a) each iteration may mutate the collection being iterated and b) 
the returned value may be mutable. However, `for-in` invokes a language-level 
mechanism to iterate: simply iterating alone _cannot_ modify the collection, and 
the returned value is known to be a primitive.
2023-09-11 16:54:05 -07:00
Sebastian Markbåge
bb1d8d1667 Encode lazy Node slots properly in key path and resumable paths (#27359)
It's possible to postpone a specific node and not using a wrapper
component. Therefore we encode the resumable slot as the index slot.
When it's a plain client component that postpones, it's encoded as the
child slot inside that component which is the one that's postponed
rather than the component itself.

Since it's possible for a child slot to suspend (e.g. React.lazy's
microtask in this case) retryTask might need to keep its index around
when it resolves.
2023-09-11 19:25:24 -04:00
Joe Savona
51497c8c59 Basic ForInStatement support
First pass of ForInStatement support. This mostly just copies our handling of 
ForOfStatement, but the next PR updates to use a different instruction instead 
of `NextIterableOf`.
2023-09-11 15:56:49 -07:00
Andrew Clark
a4aceafc63 Fix: Skip hidden inputs before text instance (#27358)
Found a hydration bug that happens when you pass a Server Action to
`formAction` and the next node is a text instance.

The HTML generated by Fizz is something like this:

```html
<button name="$ACTION_REF_5" formAction="" formEncType="multipart/form-data" formMethod="POST">
  <input type="hidden" name="$ACTION_5:0" value="..."/>
  <input type="hidden" name="$ACTION_5:1" value="..."/>
  <input type="hidden" name="$ACTION_KEY" value="..."/>Count: <!-- -->0
</button>
```

Fiber is supposed to skip over the extra hidden inputs, but it doesn't
handle this correctly if the next expected node isn't a host instance.
In this case, it's a text instance.

Not sure if the proper fix is to change the HTML that is generated, or
to change the hydration logic, but in this PR I've done the latter.
2023-09-11 18:22:37 -04:00
Joe Savona
911c988453 Support ObjectPattern within RestElement
Supports ObjectPattern within RestElement, the `...{y}` in `const [x, ...{y}] = 
z`
2023-09-11 13:03:02 -07:00
Joe Savona
1ec445d8f9 Support reordering call expressions
Supports call expressions if the callee and args are themselves reorderable. As 
part of this I realized that we currently allow identifier references to be 
reordered. To be safe, this PR updates the logic to continue consider 
identifiers as reorderable, but considers an arrow function to be not 
reorderable if it contains a local variable reference. We can likely relax that 
rule, but this quickly unblocks the next experiment.
2023-09-11 12:49:47 -07:00
Joe Savona
b1f7ebfd47 Reodering of unary and arrow function expressions
Supports reordering of unary and arrow function expressions: 

* Supports a trivially safe subset of unary operators, rejects things like 
`void` just because we don't need it yet. 

* Supports arrow function expressions that are either an empty block statement 
or a single expression which is itself reorderable.
2023-09-11 12:49:47 -07:00
Pavel
627b7abd62 feat[devtools/extension]: add dark theme for popup (#27330)
## Summary

If the system/browser uses a dark theme, then the extension popup still
remains with a light background. And so that the eyes do not hurt in a
dark room, you need a dark theme.

## How did you test this change?

Make sure the dark theme is enabled on your system/browser.

**Before:**

![Screenshot 2023-09-02 at 22 20
56](https://github.com/facebook/react/assets/19418601/f7166ea7-f562-4d11-8851-be08fa9629a7)

**After:**

![Screenshot 2023-09-02 at 22 21
30](https://github.com/facebook/react/assets/19418601/e51ecd5f-3e71-4193-83ff-a548bce76bd4)
2023-09-11 14:02:54 +01:00
Joe Savona
de2b684bc5 TryStatement: handle edge case control flows
Adds handling for some cases where the handler is unreachable (or is provably 
unreachable after analysis & optimization), where the try/catch can be flattened 
away: 

* The try block is empty. Nothing can throw, so the handler is unreachable. 

* The try block will always return. It can't return anything interesting (ie the 
result of a function call or variable load) since those could throw, but a try 
block that always return a primitive means the handler is unreachable. 

* The same, except where we only determine that the try block always returns via 
constant propagation.
2023-09-08 13:54:45 -07:00
Joe Savona
c8cebdd946 TryStatement: handle mutation of try values via catch param 2023-09-08 11:03:55 -07:00
Joe Savona
edd9c52142 Sprout tests to double-check our destructuring
I wanted to double-check the semantics of when default values are used, so i 
wrote out some fixtures with sprout enabled.
2023-09-07 17:17:03 -07:00
Joe Savona
e8d130bd1d Support type casts and conditionals as default values 2023-09-07 17:07:34 -07:00
Joe Savona
0052f2e591 TryStatement: enable sprout on new tests
Enables sprout for all the new try/catch fixtures in this stack. I added new 
helpers and tried to make sure we're testing the most interesting codepath of 
each fixture. This is where property testing would help, since we could test 
multiple paths with a single block of code, but for now this seems like a good 
balance of coverage.
2023-09-07 16:50:24 -07:00
Joe Savona
ee77d91ca2 TryStatement: handle catch clause params
It's possible that the value thrown during a `try` block actually is a reference 
to some value defined outside the scope of the try block. If the catch clause 
param is also mutated, that means the mutable range of the variable would have 
to include the entire try/catch. 

We handle this by emitting a DeclareLocal temporary for the catch param prior to 
the try/catch. If it is modified during the catch block, that will extend its 
mutable range to cover the full try/catch. If any values are mutated inside the 
try, their range will also (naturally) extend around the full try/catch block. 
These ranges will overlap and be merged, ensuring that we capture the 
possibility that the value is mutated via the catch param. See unit test.
2023-09-07 16:32:55 -07:00
Joe Savona
e3622ee413 TryStatement: disallow throw inside try/catch
Modeling `throw` inside of a try/catch is awkward because it's basically a 
variable reassignment and a goto together. Thankfully that is an antipattern — 
using exceptions instead of control-flow — so it seems pretty reasonable to just 
put a todo here and leave it.
2023-09-07 16:32:54 -07:00
Joe Savona
ff0b05848b TryStatement: optimization pass, handle early returns
Adds an optimization pass to prune unnecessary maybe-throw terminals, when the 
block can be proven not to throw. For now we're _very_ conservative about what 
instructions we consider not to throw. There isn't too much of an advantage in 
pruning further, either. 

This PR also updates BuildReactiveFunction to handle the possibility of early 
returns within try or catch blocks, making sure we don't hit the invariant of 
emitting the same block twice.
2023-09-07 16:32:53 -07:00
Joe Savona
936b96b24f TryStatement: partial lowering
Implements the core lowering logic for try/catch: 

* Inside of the `try` block, we use the new HIRBuilder mode to wrap every 
instruction in a separate basic block with a maybe-throw terminal 

* We emit a 'try' terminal for the try/catch itself 

For basic examples this already works correctly. But we don't handle catch 
clause params yet.
2023-09-07 16:32:53 -07:00
Josh Story
41f0e9dae3 [Float][Fizz] include preloadModule and preinitModule on react-dom/server-rendering-stub (#27347)
When implementing `preloadModule` and `preinitModule` these methods were
not exposed on the server rendering stub when they should have been.
This PR corrects that omission.
2023-09-07 14:48:22 -07:00
Joe Savona
7f5bac171e TryStatement: try terminal scaffolding
This PR adds the other piece, a 'try' terminal which represents try/catch and 
the possibility of fallthrough to the code afterwards. For now `finally` is 
unsupported. We don't yet produce these terminals, see later in the stack.
2023-09-07 14:22:33 -07:00
Joe Savona
0977115440 TryStatement: maybe-throw terminal for per-instruction throw points
Adds a "maybe-throw" terminal which represents the possibility that the block 
may or may not throw, and can either continue forward or exit to an exception 
handler (`catch`). Also updates HIRBuilder to track the current mode, and when 
inside a try block to wrap every instruction inside a basic block that ends in a 
maybe-throw. 

So far this code isn't used yet, so doesn't affect output.
2023-09-07 14:22:28 -07:00
Andrew Clark
8b26f07a88 useFormState: Emit comment to mark whether state matches (#27307)
A planned feature of useFormState is that if the page load is the result
of an MPA-style form submission — i.e. a form was submitted before it
was hydrated, using Server Actions — the state of the hook should
transfer to the next page.

I haven't implemented that part yet, but as a prerequisite, we need some
way for Fizz to indicate whether a useFormState hook was rendered using
the "postback" state. That way we can do all state matching logic on the
server without having to replicate it on the client, too.

The approach here is to emit a comment node for each useFormState hook.
We use one of two comment types: `<!--F-->` for a normal useFormState
hook, and `<!--F!-->` for a hook that was rendered using the postback
state. React will read these markers during hydration. This is similar
to how we encode Suspense boundaries.

Again, the actual matching algorithm is not yet implemented — for now,
the "not matching" marker is always emitted.

We can optimize this further by not emitting any markers for a render
that is not the result of a form postback, which I'll do in subsequent
PRs.
2023-09-07 16:05:44 -04:00
Josh Story
3566de59e2 [Fizz][Float] <img> inside <picture> should not preload during SSR (#27346)
img tags inside picture tags should not automatically be preloaded
because usually the img is a fallback. We will consider a more
comprehensive way of preloading picture tags which may require a
technique like using an inline script to construct the image in the
browser but for now we simply omit the preloads to avoid harming load
times by loading fallbacks.
2023-09-07 12:48:40 -07:00
Sathya Gunasekaran
20203cd889 [hir] Remove unnecessary check for place kind 2023-09-07 13:57:02 +01:00
Sathya Gunasekaran
603d2179a8 [hir] Pretty print object property keys 2023-09-07 13:56:59 +01:00
Sathya Gunasekaran
f2027b9a4d [hir] Add support for string literal property keys
Mostly reuses existing analysis of an identifier property key. 

Adds a new type field to ObjectProperty to propogate the type of the key. This 
is used in codegen to correctly emit a string literal or an identifier.
2023-09-07 13:56:56 +01:00
Sebastian Markbåge
953cb02f6d [Fizz] Split createRequest into createRequest, createPrerenderRequest and resumeRequest (#27342)
Just moving some internal code around again.

I originally encoded what type of work using startRender vs
startPrerender. I had intended to do more forking of the work loop but
we've decided not to go with that strategy. It also turns out that
forking when we start working is actually too late because of a subtle
thing where you can call abort before work begins. Therefore it's
important that starting the work comes later.
2023-09-07 00:18:30 -04:00
Andrew Clark
ee7f9c9351 useId: Remove unnecessary try/finally blocks (#27340)
To generate IDs for useId, we modify a context variable whenever
multiple siblings are rendered, or when a component includes a useId
hook.

When this happens, we must ensure that the context is reset properly on
unwind if something errors or suspends. When I originally implemented
this, I did this by wrapping the child's rendering with a try/finally
block. But a better way to do this is by using the non-destructive
renderNode path instead of renderNodeDestructive.
2023-09-06 16:30:29 -04:00
Sathya Gunasekaran
59504e1cb4 [hir] Traverse function to capture deps, not just body node
Technically there is a body node created for implicit return expression in a 
arrow function, so the existing logic should've worked fine. But there seems to 
be a Babel bug, so let's work around it by traversing the function. 

Added a test case that captures a dep as a param -- this is currently 
unsupported  and also something that would've been ignored before this PR. Added 
a failing test to make sure we think about this case when we add support for 
default params.
2023-09-06 14:58:04 +01:00
Sathya Gunasekaran
a93aa8f322 [hir] Encapsulate pipeline from rest of Forget
Future passes will lead to inconsistent state between passes and will require
passes to run in a specific order, so let's make sure no one will misconfigure
the passes.
2023-09-06 14:12:11 +01:00
Lauren Tan
31f0f426e1 [hoisting] Add failing tests
The current plan is to add support for hoisting function declarations, let/const 
declarations, but not var yet
2023-09-05 17:04:03 -04:00
Joe Savona
ef51c92c8a first rendering test
Updates the rendering code and gets a first unit test working with a fully
static component (written by hand rather than compiled).
2023-09-05 14:03:22 -07:00
Josh Story
b9be4537c2 [Flight] provide property descriptors for client references (#27328)
Client reference proxy should implement getOwnPropertyDescriptor. One
practical place where this shows up is when consuming CJS module.exports
in ESM modules. Node creates named exports it statically infers from the
underlying source but it only sets the named export if the CJS exports
hasOwnProperty. This trap will allow the proxy to respond affirmatively.

I did not add unit tests because contriving the ESM <-> CJS scenario in
Jest is challenging. I did add new components to the flight fixture
which demonstrate that the named exports are properly constructed with
the client reference whereas they were not before.
2023-09-05 13:45:16 -07:00
Sebastian Markbåge
2c2bdd0ffe [Fizz] Move /static build into /server builds (#27327)
This joins the static (prerender) builds with the server builds but
doesn't change the public entry points.

The idea of two separate bundles is that we'd have a specialized build
for Fizz just for the prerender that could do a lot more. However, in
practice the code is implemented with a dynamic check so it's in both.
It's also not a lot of code.

At the same time if you do have a set up that includes both the
prerender and the render in the same build output, this just doubles the
server bundle size for no reason.

So we might as well merge them into one build. However, I don't expose
the `prerender` from `/server`. Instead it's just exposed from the
public `/static` entry point. This leaves us with the option to go back
to separate builds later if it diverges more in the future.
2023-09-05 15:55:20 -04:00
Sebastian Markbåge
3cc8a9347b [Fizz] Move formatContext tracking back to the task (#27325)
In https://github.com/facebook/react/pull/21113 I moved this over to the
segment from the task. This partially reverts this two use two fields
instead. I was just trying to micro-optimize by reusing a single field.

This is really conceptually two different values. Task is keeping track
of the working state of the currently executing context.

The segment just needs to keep track of which parent context it was
created in so that it can be wrapped correctly when a segment is
written. We just happened to rely on the working state returning to the
top before completing.

The main motivation is that there is no `segment` for replaying.
2023-09-05 15:55:07 -04:00
Lauren Tan
9d6170ab98 Update snap fixture
Missed this in my last PR
2023-09-05 15:07:37 -04:00
Ruslan Lesiutin
a374287fea React DevTools 4.28.2 -> 4.28.3 (#27337)
This is a patch version to fix some bugs in a previous internal release.
I am expecting this one also to be internal-only, need to make sure that
extension is stable in Chrome. Some changes and improvements are
expected for Firefox, though, before going public.

* refactor[devtools/extension]: handle ports disconnection, instead of
frequent reconnection ([hoxyq](https://github.com/hoxyq) in
[#27336](https://github.com/facebook/react/pull/27336))
* refactor[devtools/extension]: migrate from using setInterval for
polling if react is loaded ([hoxyq](https://github.com/hoxyq) in
[#27323](https://github.com/facebook/react/pull/27323))
* fix[devtools/extension]: fixed duplicating panels in firefox
([hoxyq](https://github.com/hoxyq) in
[#27320](https://github.com/facebook/react/pull/27320))
2023-09-05 18:58:27 +01:00
Ruslan Lesiutin
a27df56a5c refactor[devtools/extension]: handle ports disconnection, instead of frequent reconnection (#27336)
- Instead of reconnecting ports from devtools page and proxy content
script, now handling their disconnection properly
- `proxy.js` is now dynamically registered as a content script, which
loaded for each page. This will probably not work well for Firefox,
since we are still on manifest v2, I will try to fix this in the next
few PRs.
- Handling the case when devtools page port was reconnected and bridge
is still present. This could happen if user switches the tab and Chrome
decides to kill service worker, devtools page port gets disconnected,
and then user returns back to the tab. When port is reconnected, we
check if bridge message listener is present, connecting them if so.
- Added simple debounce when evaluating if page has react application
running. We start this check in `chrome.network.onNavigated` listener,
which is asynchronous. Also, this check itself is asynchronous, so
previously we could mount React DevTools multiple times if navigates
multiple times while `chrome.devtools.inspectedWindow.eval` (which is
also asynchronous) can be executed.
00b7c43318/packages/react-devtools-extensions/src/main/index.js (L575-L583)



https://github.com/facebook/react/assets/28902667/9d519a77-145e-413c-b142-b5063223d073
2023-09-05 18:41:39 +01:00
Lauren Tan
6a71868d4c [sprout] Convert for-of-mutate to sprout 2023-09-05 12:35:18 -04:00
Lauren Tan
375e2d8f33 [babel] Remove babel/plugin-syntax-jsx
Internal version of babel/core doesn't support the `inherits` property, so let's 
try removing it. The tests still seem to pass, so this might be vestigial from 
the first iteration of the compiler from last year
2023-09-05 12:08:01 -04:00
Lauren Tan
fdd6a1b8b1 Add rollup to eslint-plugin-react-forget 2023-09-05 12:08:00 -04:00
Sathya Gunasekaran
2d3507b0e1 Add signal codegen for ReactiveScopes
Instead of emitting a memo block, emit a function expression and pass it as an
argument to derived (which will then create a computed).

The naming of 'derived' needs to be tweaked.
2023-09-05 11:13:31 +01:00
Sathya Gunasekaran
4571979e46 Add pass to lower useState 2023-09-05 11:13:30 +01:00
Ruslan Lesiutin
9b4f847d93 refactor[devtools/extension]: migrate from using setInterval for polling if react is loaded (#27323)
`chrome.devtools.inspectedWindow.eval` is asynchronous, so using it in
`setInterval` is a mistake.
Sometimes this results into mounting React DevTools twice, and user sees
errors about duplicated fibers in store.

With these changes, `executeIfReactHasLoaded` executed recursively with
a threshold (in case if page doesn't have react).

Although we minimize the risk of mounting DevTools twice here, this
approach is not the best way to have this problem solved. Dumping some
thoughts and ideas that I've tried, but which are out of the scope for
this release, because they can be too risky and time-consuming.
Potential changes:
- Have 2 content scripts:
  - One `prepareInjection` to notify service worker on renderer attached
- One which runs on `document_idle` to finalize check, in case if there
is no react
- Service worker will notify devtools page that it is ready to mount
React DevTools panels or should show that there is no React to be found
- Extension port from devtools page should be persistent and connected
when `main.js` is executed
- Might require refactoring the logic of how we connect devtools and
proxy ports
  
  
Some corner cases:
- Navigating to restricted pages, like `chrome://<something>` and back
- When react is lazily loaded, like in an attached iframe, or just
opened modal
- In-tab navigation with pre-cached pages, I think only Chrome does it
- Firefox is still on manifest v2 and it doesn't allow running content
scripts in ExecutionWorld.MAIN, so it requires a different approach
2023-09-01 16:23:04 +01:00
Sathya Gunasekaran
403881c548 [forest] Turn off jsx memoization 2023-09-01 11:24:19 +01:00
Sathya Gunasekaran
9b037118c5 [test] Add basic test 2023-09-01 11:24:19 +01:00
Ruslan Lesiutin
7022e8d6a3 fix[devtools/extension]: fixed duplicating panels in firefox (#27320)
Multiple `chrome.panels.create` calls result into having duplicate
panels created in Firefox, these changes fix that.

Now calling `chrome.panels.create` only if there are no panels created
yet.
2023-08-31 18:24:26 +01:00
Sebastian Markbåge
b70a0d7022 [Fizz] Track postponed holes in the prerender pass (#27317)
This is basically the implementation for the prerender pass.

Instead of forking basically the whole implementation for prerender, I
just add a conditional field on the request. If it's `null` it behaves
like before. If it's non-`null` then instead of triggering client
rendered boundaries it triggers those into a "postponed" state which is
basically just a variant of "pending". It's supposed to be filled in
later.

It also builds up a serializable tree of which path can be followed to
find the holes. This is basically a reverse `KeyPath` tree.

It is unfortunate that this approach adds more code to the regular Fizz
builds but in practice. It seems like this side is not going to add much
code and we might instead just want to merge the builds so that it's
smaller when you have `prerender` and `resume` in the same bundle -
which I think will be common in practice.

This just implements the prerender side, and not the resume side, which
is why the tests have a TODO. That's in a follow up PR.
2023-08-31 12:23:26 -04:00
Sathya Gunasekaran
da61d47e87 Add flag 2023-08-31 11:15:41 +01:00
Sathya Gunasekaran
c456662318 [tsconfig] Specify module resolution to be nodenext 2023-08-31 11:15:37 +01:00
Joe Savona
41c23e87c5 Disable compilation of "Components" inside class methods
Minimal repro extracted from our internal codebase. Our inference mode sees that 
this arrow function is component-like and attempts to compile it, which then 
fails because the function accesses `this`  which we bailout on.
2023-08-31 23:16:27 +01:00
Ruslan Lesiutin
3808b01b3a React DevTools 4.28.1 -> 4.28.2 (#27318)
List of changes:
* fix[devtools/extension]: handle tab navigation events before react is
loaded ([hoxyq](https://github.com/hoxyq) in
[#27316](https://github.com/facebook/react/pull/27316))
2023-08-30 19:47:08 +01:00
Ruslan Lesiutin
29b405b2de fix[devtools/extension]: handle tab navigation events before react is loaded (#27316)
This is mostly hotfix for https://github.com/facebook/react/pull/27215.

Contains 3 fixes:
- Handle cases when `react` is not loaded yet and user performs in-tab
navigation. Previously, because of the uncleared interval we would try
to mount DevTools twice, resulting into multiple errors.
- Handle case when extension port disconnected (probably by the browser
or just due to its lifetime)
- Removed duplicate `render()` call on line 327
2023-08-30 19:31:18 +01:00
Mofei Zhang
e36c8cb395 [patch] tsconfig: unbreak vercel build on main 2023-08-30 10:36:46 -07:00
Josh Story
d23b8b5dbf [Flight] use opaque config for flight in dom-legacy renderer (#27313)
`dom-legacy` does not make sense for Flight. we could still type check
the files but it adds maintenance burden in the inlinedHostConfigs
whenever things change there. Going to make these configs opaque mixed
types to quiet flow since no entrypoints use the flight code
2023-08-30 10:32:25 -07:00
Andrew Clark
2fba484cd0 useFormState fix: action -> target (#27309)
I mixed these attributes up in
https://github.com/facebook/react/pull/27302
2023-08-29 22:17:15 -04:00
Mofei Zhang
7930a213d2 [sprout][QoL] remove isComponent annotation
--- 

quality of life improvement as this seemed to be confusing (oops, and thanks for 
the feedback!) 

We don't *really* need static annotations for whether a function returns jsx 
(e.g. should be rendered as a React element) or not (e.g. should be wrapped in a 
wrapper component. This PR adds check for returned jsx objects at runtime 

--- 

Tested by running diffing the output of `yarn sprout --verbose` between this PR 
and base.
2023-08-29 17:00:55 -07:00
Mofei Zhang
c7b5f2fde0 [yarn] Update typescript node16 -> node18 2023-08-29 16:51:32 -07:00
Joe Savona
8790324562 Workaround serious Babel bug
I ran into the same issue that @poteto and @gsathya (and probably @mofeiZ) have 
run into: "Duplicate declaration of '$'" caused by Babel visiting a function 
twice despite our calling `skip()`. This PR keeps a set of nodes that we have 
already visited to avoid visiting them again, as a workaround for skip not 
working. 

# Test Plan 

Synced to www and confirmed that the previous bug no longer reproduces, and the 
compiled output looks sane.
2023-08-30 13:21:51 +01:00
Joe Savona
4f55a66d5c Compile args to forwardRef/memo
Completes a todo (ie fixes a silly mistake) from a PR earlier in the stack, so 
we now correctly recognize and compile arguments to `React.forwardRef()` and 
`React.memo()`.
2023-08-29 22:09:42 +01:00
Joe Savona
ddc9f8030e Enable compilation of FunctionExpressions
Thanks to the previous diff we can trivially support components or hooks defined 
as a FunctionExpression.
2023-08-29 22:09:41 +01:00
Joe Savona
cee08ba750 [rfc] Dont convert ArrowFunction to FunctionDecl
This PR changes the way we compile ArrowFunctionExpression to allow compiling 
more cases, such as within `React.forwardRef()`. We no longer convert arrow 
functions to function declarations. Instead, CodeGenerator emits a generic 
`CodegenFunction` type, and `Program.ts` is responsible for converting that to 
the appropriate type. The rule is basically: 

* Retain the original node type by default. Function declaration in, function 
declaration out. Arrow function in, arrow function out. 

* When gating is enabled, we emit a ConditionalExpression instead of creating a 
temporary variable. If the original (and hence compiled) functions are function 
declarations, we force them into FunctionExpressions only here, since we need an 
expression for each branch of the conditional. Then the rules are: 

* If this is a `export function Foo` ie a named export, replace it with a 
variable declaration with the conditional expression as the initializer, and the 
function name as the variable name. 

* Else, just replace the original function node with the conditional. This works 
for all other cases. 

I'm open to feedback but this seems like a pretty robust approach and will allow 
us to support a lot of real-world cases that we didn't yet, so i think we need 
_something_ in this direction.
2023-08-29 22:09:41 +01:00
Joe Savona
7d11445d8e Revamp compilation modes
We currently have multiple flags for targeting which functions to compile, but 
they are actually mutually exclusive. This PR consolidates to a single 
`compilationMode: 'annotation' | 'infer' | 'all'` flag: 

* Annotation compiles only functions that explicitly opt-in with "use forget" 

* Infer compiles explicitly opted-in functions (via "use forget") as well as any 
known/inferred components or hooks: 

* Component declarations 

* Component or hook-like functions (same rules as the ESLint plugin but with an 
extra check for whether it uses JSX or calls a hook) 

* All compiles all top-level functions. We should get rid of this in a follow-up 
and make tests use infer mode by default, and add explicit opt-ins where 
necessary. 

In all modes, "use no forget" always takes precedence and can be used to 
opt-out. The default mode is now "infer".
2023-08-29 22:09:40 +01:00
Joe Savona
3653ae2de3 Option to infer React functions to compile
Adds a new option to infer which functions to compile, based on React's ESLint 
rule. The main difference is that in addition to checking the function name we 
also check that it creates JSX or calls a hook. This should cover a significant 
majority of components and reduce the chance of accidentally targeting 
non-components, but it will leave some false negatives. 

Note that some cases that the ESLint plugin infers as React functions don't work 
yet: we don't compile FunctionExpressions, only ArrowFunctionExpressions, and 
the way we handle ArrowFunctionExpression doesn't work with things like 
forwardRef or variable declarations. We'll need more updates to fully handle all 
these cases, which I'll do later in the stack.
2023-08-29 22:09:40 +01:00
Andrew Clark
ddff504695 useFormState's permalink option changes form target (#27302)
When the `permalink` option is passed to `useFormState`, and the form is
submitted before it has hydrated, the permalink will be used as the
target of the form action, enabling MPA-style form submissions.

(Note that submitting a form without hydration is a feature of Server
Actions; it doesn't work with regular client actions.)

It does not have any effect after the form has hydrated.
2023-08-29 11:58:44 -04:00
idango10
eaa696876e fix: devtools source field disappears after component remount (#27297)
## Summary

Fixes: https://github.com/facebook/react/issues/27296

On actions that cause a component to change its signature, and therefore
to remount, the `_debugSource` property of the fiber updates in delay
and causes the `devtools` source field to vanish.

This issue happens in
https://github.com/facebook/react/blob/main/packages/react-reconciler/src/ReactFiberBeginWork.js

```js
function beginWork(
  current: Fiber | null,
  workInProgress: Fiber,
  renderLanes: Lanes,
): Fiber | null {
  if (__DEV__) {
    if (workInProgress._debugNeedsRemount && current !== null) {
      // This will restart the begin phase with a new fiber.
      return remountFiber(
        current,
        workInProgress,
        createFiberFromTypeAndProps(
          workInProgress.type,
          workInProgress.key,
          workInProgress.pendingProps,
          workInProgress._debugOwner || null,
          workInProgress.mode,
          workInProgress.lanes,
        ),
      );
    }
  }

  // ...
```

`remountFiber` uses the 3rd parameter as the new fiber
(`createFiberFromTypeAndProps(...)`), but this parameter doesn’t contain
a `_debugSource`.

## How did you test this change?

Tested by monkey patching
`./node_modules/react-dom/cjs/react-dom.development.js`:
<img width="1749" alt="image"
src="https://github.com/facebook/react/assets/75563024/ccaf7fab-4cc9-4c05-a48b-64db6f55dc23">


https://github.com/facebook/react/assets/75563024/0650ae5c-b277-44d1-acbb-a08d98bd38e0
2023-08-29 16:42:35 +01:00
Noah Lemen
4129ea8c92 set priority on TaskController instead of on postTask/yield (#27295)
## Summary

passing both a signal and a priority to `postTask`/`yield` in chrome
causes memory to spike and potentially causes OOMs. a fix for this has
landed in chrome 118, but we can avoid the issue in earlier versions by
setting priority on just the TaskController instead.

https://bugs.chromium.org/p/chromium/issues/detail?id=1469367

## How did you test this change?
```
yarn test SchedulerPostTask
```
2023-08-29 09:06:25 -04:00
Ruslan Lesiutin
2f368725fb React DevTools 4.28.0 -> 4.28.1 (#27305)
List of changes:
* refactor: refactored devtools browser extension scripts to improve
port management and service worker lifetime
([hoxyq](https://github.com/hoxyq) in
[#27215](https://github.com/facebook/react/pull/27215))
* refactor[devtools/extension]: minify production builds to strip
comments ([hoxyq](https://github.com/hoxyq) in
[#27304](https://github.com/facebook/react/pull/27304))
* fix[devtools]: allow element updates polling only if bridge is alive
([hoxyq](https://github.com/hoxyq) in
[#27067](https://github.com/facebook/react/pull/27067))
* refactor: resolve browser via env variables based on build rather than
user agent ([hoxyq](https://github.com/hoxyq) in
[#27179](https://github.com/facebook/react/pull/27179))
* fix[devtools/updateFiberRecursively]: mount suspense fallback set in
timed out case ([hoxyq](https://github.com/hoxyq) in
[#27147](https://github.com/facebook/react/pull/27147))
* Feat:-Added open in editor to appear by default
([Biki-das](https://github.com/Biki-das) in
[#26949](https://github.com/facebook/react/pull/26949))
* fix[devtools/inspect]: null check memoized props before trying to call
hasOwnProperty ([hoxyq](https://github.com/hoxyq) in
[#27057](https://github.com/facebook/react/pull/27057))
* rename SuspenseList export to unstable_SuspenseList
([noahlemen](https://github.com/noahlemen) in
[#27061](https://github.com/facebook/react/pull/27061))
2023-08-29 13:37:35 +01:00
Ruslan Lesiutin
8fbd307942 refactor: refactored devtools browser extension scripts to improve port management and service worker lifetime (#27215)
Fixes https://github.com/facebook/react/issues/27119,
https://github.com/facebook/react/issues/27185.

Fixed:
- React DevTools now works as expected when user performs in-tab
navigation, previously it was just stuck.


https://github.com/facebook/react/assets/28902667/b11c5f84-7155-47a5-8b5a-7e90baca5347

- When user closes browser DevTools panel, we now do some cleanup to
disconnect ports and emit shutdown event for bridge. This should fix the
issue with registering duplicated fibers with the same id in Store.

Changed:
- We reconnect proxy port once in 25 seconds, in order to [keep service
worker
alive](https://developer.chrome.com/docs/extensions/whatsnew/#m110-sw-idle).
- Instead of unregistering dynamically injected content scripts, wen now
get list of already registered scripts and filter them out from scripts
that we want to inject again, see dynamicallyInjectContentScripts.js.
- Split `main.js` and `background.js` into multiple files.

Tested on Chromium and Firefox browsers.
2023-08-29 12:09:26 +01:00
Ruslan Lesiutin
f47956239f refactor[devtools/extension]: minify production builds to strip comments (#27304)
Currently, we are unable to publish a release to Firefox extensions
store, due to `parseHookNames` chunk size, which is ~5mb.

We were not minifying production builds on purpose, to have more
descriptive error messages. Now, Terser plugin will only:
- remove comments
- mangle, but keeping function names (for understandable bug reports)
2023-08-29 12:09:13 +01:00
Ruslan Lesiutin
41e9c17a69 fix[devtools]: allow element updates polling only if bridge is alive (#27067)
When some element is inspected in DevTools, we have a polling which
updates the data for this element.
Sometimes when service worker dies or bridge is getting shutdown, we
continue to poll this data and will spam with the same "timed out
error".

<img width="1728" alt="Screenshot 2023-07-28 at 17 39 23"
src="https://github.com/facebook/react/assets/28902667/220c4504-1ccc-4e87-9d78-bfff8b708230">


These changes add an explicit check that polling is allowed only while
bridge is alive.
2023-08-29 10:40:20 +01:00
Ruslan Lesiutin
2c4c847188 refactor: resolve browser via env variables based on build rather than user agent (#27179)
Fixes https://github.com/facebook/react/issues/26911,
https://github.com/facebook/react/issues/26860.

Currently, we are parsing user agent string to determine which browser
is running the extension. This doesn't work well with custom user
agents, and sometimes when user turns on mobile dev mode in Firefox, we
stop resolving that this is a Firefox browser, extension starts to use
Chrome API's and fails to inject.

Changes:
Since we are building different extensions for all supported browsers
(Chrome, Firefox, Edge), we predefine env variables for browser
resolution, which are populated in a build step.
2023-08-29 10:40:02 +01:00
Andrew Clark
456d153bb5 Client implementation of useFormState (#27278)
This implements useFormState in Fiber. (It does not include any
progressive enhancement features; those will be added later.)

useFormState is a hook for tracking state produced by async actions. It
has a signature similar to useReducer, but instead of a reducer, it
accepts an async action function.

```js
async function action(prevState, payload) {
  // ..
}
const [state, dispatch] = useFormState(action, initialState)
```

Calling dispatch runs the async action and updates the state to the
returned value.

Async actions run before React's render cycle, so unlike reducers, they
can contain arbitrary side effects.
2023-08-28 11:05:40 -04:00
Andrew Clark
9a01c8b54e Fix mount-or-update check in rerenderOptimistic (#27277)
I noticed this was wrong because it should call updateWorkInProgressHook
before it checks if currentHook is null.
2023-08-28 11:04:46 -04:00
Mofei Zhang
6dbc48075b [tests] bug repros 2023-08-26 14:00:43 -07:00
Sebastian Markbåge
b798223a62 Override .bind on Server References on the Client (#27282)
That way when you bind arguments to a Server Reference, it's still a
server reference and works with progressive enhancement.

This already works on the Server (RSC) layer.
2023-08-25 21:39:55 -04:00
Mofei Zhang
bcbcd37eb0 [sprout] Allow forwardRef and memo components 2023-08-25 16:54:21 -07:00
Andrew Clark
ab31a9ed28 Selective Hydration: Don't suspend if showing fallback (#27230)
A transition that flows into a dehydrated boundary should not suspend if
the boundary is showing a fallback.

This is related to another issue where Fizz streams in the initial HTML
after a client navigation has already happened. That issue is not fixed
by this commit, but it does make it less likely. Need to think more
about the larger issue.
2023-08-24 20:04:34 -04:00
Josh Story
9d4582dffd [Float][Fizz][Static] add importMap option to Fizz and Static server renderers (#27260)
Import maps need to be emitted before any scripts or preloads so the
browser can properly locate these resources.

Unlike most scripts, importmaps are singletons meaning you can only have
one per document and they must appear before any modules are loaded or
preloaded. In the future there may be a way to dynamically add more
mappings however the proposed API for this seems likely to be a
javascript API and not an html tag.

Given the unique constraints here this PR implements React's support of
importMaps as the following

1. an `importMap` option accepting a plain object mapping module
specifier to path is accepted in any API that renders a preamble (head
content). Notably this precludes resume rendering because in resume
cases the preamble should have already been produced as part of the
prerender step.
2. the importMap is stringified and emitted as a `<script
type="importmap">...</script>` in the preamble.
3. the importMap is escaped identically to how bootstrapScriptContent is
escaped, notably, isntances of `</script>` are escaped to avoid breaking
out of the script context

Users can still render importmap tags however with Float enabled this is
rather pointless as most modules will be hoisted above the importmap
that is rendered. In practice this means the only functional way to use
import maps with React is to use this config API.
2023-08-24 13:48:28 -07:00
Sathya Gunasekaran
56b0f971d0 [sprout] Port alias-capture-in-method-receiver-and-mutate test 2023-08-23 17:44:26 +01:00
Sathya Gunasekaran
aceacce5e2 [sprout] Add a mutate utility function 2023-08-23 17:37:54 +01:00
Lauren Tan
ce82a56fa6 [ci] Fix output of parser benchmark
yarn adds some other output, so just run the script directly
2023-08-24 10:14:28 -04:00
Lauren Tan
80efd75b8e [ci] Add benchmark comparison
Updates the parser-benchmark script to use a benchmarking framework, and 

also brings in yargs to make it easier to handle parsing arguments. 

Non-CI usage: 

``` 

$ cd bench/parser-benchmark 

$ yarn bench --help 

Options: 

--help        Show help                                              [boolean] 

--ci                                                [boolean] [default: false] 

--sampleSize                                             [number] [default: 1] 

$ yarn bench --sampleSize=3 

[ISOBENCH ENDED] Parser Benchmark (3 times) 

OXC           - 32 op/s. 3 samples in 9518 ms. 5.288x (BEST) 

SWC           - 20 op/s. 3 samples in 9487 ms. 3.256x 

HermesParser  - 6 op/s. 3 samples in 9124 ms. 1.000x (WORST) 

Forget (Rust) - 15 op/s. 3 samples in 9749 ms. 2.499x 

``` 

In CI this outputs JSON instead of logging to stdout. The results are 

stored in github's action cache and used as a point of comparison when 

new commits are pushed to main. The comparison should be shown on 

workflow [summary 
pages](https://github.com/facebook/react-forget/actions/runs/5956421081), but 
nothing will be populated until we merge this PR. 

We intentionally only run this workflow on main as any run would 

override the last cached result, so a PR with multiple pushes would then 

start having comparisons with itself.
2023-08-23 17:58:23 -04:00
Lauren Tan
aeae3ba0a7 [ci] Add rust-cache 2023-08-23 17:16:40 -04:00
Lauren Tan
fc506b5fed [ci] Run parser benchmark on ci
Example: 

![Screenshot 2023-08-23 at 11 22 55 
AM](https://github.com/facebook/react-forget/assets/1390709/158fa9f1-32f6-444e-8ea8-75f4f1475ee0)
2023-08-23 17:16:40 -04:00
Andrew Clark
b4cdd3e892 Scaffolding for useFormState (#27270)
This exposes, but does not yet implement, a new experimental API called
useFormState. It's gated behind the enableAsyncActions flag.

useFormState has a similar signature to useReducer, except instead of a
reducer it accepts an (async) action function. React will wait until the
promise resolves before updating the state:

```js
async function action(prevState, payload) {
  // ..
}
const [state, dispatch] = useFormState(action, initialState)
```

When used in combination with Server Actions, it will also support
progressive enhancement — a form that is submitted before it has
hydrated will have its state transferred to the next page. However, like
the other action-related hooks, it works with fully client-driven
actions, too.
2023-08-23 10:58:09 -04:00
Sebastian Markbåge
856dc5e433 Fix escaping in action error URL (#27273)
This URL is generated on the client (there's an equivalent but shorter
SSR version too) when a function is used as an action. It should never
happen but it'll be invoked if a form is manually submitted or event is
stopped early.

The `'` wasn't escaped so this yielded invalid syntax. Which is an error
too but much less helpful. `missing ) after argument list`. Added a test
that evals to make sure it's correct syntax.
2023-08-22 19:10:00 -04:00
Sebastian Markbåge
31034b6de7 [Fizz] Split ResponseState/Resources into RenderState/ResumableState (#27268)
This exposes a `resume()` API to go with the `prerender()` (only in
experimental). It doesn't work yet since we don't yet emit the postponed
state so not yet tested.

The main thing this does is rename ResponseState->RenderState and
Resources->ResumableState. We separated out resources into a separate
concept preemptively since it seemed like separate enough but probably
doesn't warrant being a separate concept. The result is that we have a
per RenderState in the Config which is really just temporary state and
things that must be flushed completely in the prerender. Most things
should be ResumableState.

Most options are specified in the `prerender()` and transferred into the
`resume()` but certain options that are unique per request can't be.
Notably `nonce` is special. This means that bootstrap scripts and
external runtime can't use `nonce` in this mode. They need to have a CSP
configured to deal with external scripts, but not inline.

We need to be able to restore state of things that we've already emitted
in the prerender. We could have separate snapshot/restore methods that
does this work when it happens but that means we have to explicitly do
that work. This design is trying to keep to the principle that we just
work with resumable data structures instead so that we're designing for
it with every feature. It also makes restoring faster since it's just
straight into the data structure.

This is not yet a serializable format. That can be done in a follow up.

We also need to vet that each step makes sense. Notably stylesToHoist is
a bit unclear how it'll work.
2023-08-22 15:21:36 -04:00
Lauren Tan
3a9be52f51 Update test262 2023-08-22 15:07:46 -04:00
lauren
a0dc166991 [rfc] Remove top level forget directory
Sorry about the thrash in advance! This removes the top level `forget` directory 
which adds unnecessary nesting to our repo 

Hopefully everything still works
2023-08-22 15:04:54 -04:00
Josh Story
86198b9231 [Float][Fizz][Legacy] hoisted elements no longer emit before <html> in legacy apis such as renderToString() (#27269)
renderToString is a legacy server API which used a trick to avoid having
the DOCTYPE included when rendering full documents by setting the root
formatcontext to HTML_MODE rather than ROOT_HTML_MODE. Previously this
was of little consequence but with Float the Root mode started to be
used for things like determining if we could flush hoistable elements
yet. In issue #27177 we see that hoisted elements can appear before the
<html> tag when using a legacy API `renderToString`.

This change exports a DOCTYPE from FizzConfigDOM and FizzConfigDOMLegacy
respectively, using an empty chunk in the legacy case. The only runtime
perf cost here is that for legacy APIs there is an extra empty chunk to
write when rendering a top level <html> tag which is trivial enough

Fixes #27177
2023-08-22 10:54:33 -07:00
Andrew Clark
dd480ef923 Fix: Stylesheet in error UI suspends indefinitely (#27265)
This fixes the regression test added in the previous commit. The
"Suspensey commit" implementation relies on the
`shouldRemainOnPreviousScreen` function to determine whether to 1)
suspend the commit 2) activate a parent fallback and schedule a retry.
The issue was that we were sometimes attempting option 2 even when there
was no parent fallback.

Part of the reason this bug landed is due to how `throwException` is
structured. In the case of Suspensey commits, we pass a special "noop"
thenable to `throwException` as a way to trigger the Suspense path. This
special thenable must never have a listener attached to it. This is not
a great way to structure the logic, it's just a consequence of how the
code evolved over time. We should refactor it into multiple functions so
we can trigger a fallback directly without having to check the type. In
the meantime, I added an internal warning to help detect similar
mistakes in the future.
2023-08-22 11:22:30 -04:00
Jan Kassens
e76a5aca78 [easy] remove unused file MaxInts.js (#27259)
While poking around, I noticed this wasn't used.
2023-08-22 10:42:27 -04:00
Jan Kassens
29556a6b0a Flow: upgrade to 0.215.0 (#27264)
Simple bump of Flow and Hermes parser to keep us current.
2023-08-22 10:41:04 -04:00
Jan Kassens
3f5b8c214f Jest: remove haste config (#27257)
Since we're not using haste at all, we can just remove the config to
disable haste instead of enabling, just to inject an implementation that
blocks any haste modules from being recognized.

Test Plan:
Creating a module and required it to get the expected error that the
module doesn't exist.
2023-08-22 10:12:28 -04:00
Joe Savona
a13df48d4e [rust] Serialize range as array
ESTree expects the `range` value to be an array of `[start, end]`, we support 
deserializing from that format but serialized as an object of `{start,end}`, now 
we serialize to the array form.
2023-08-21 21:55:08 -07:00
Andrew Clark
7d1c3c1589 Regression test: Stylesheet suspends indefinitely when part of error boundary UI during initial hydration (#27258)
Adds a failing test for a case discovered by Next.js. An error boundary
is triggered during initial hydration, and the error fallback includes a
stylesheet. If the stylesheet has not yet been loaded, the commit
suspends, but never resolves even after the stylesheet finishes loading.

Triggering this bug depends on several very specific code paths being
triggered simultaneously. There are a few ways we could fix the bug;
I'll submit as one or more separate PRs to show that each one is
sufficient.
2023-08-21 19:14:56 -04:00
Joe Savona
9c13e4413c [rust] Expose parse function to napi
Updates the `forget_napi` crate to call the parser and semantic analyzer and 
convert their values to JS.
2023-08-21 16:04:03 -07:00
Joe Savona
7fc7488ac8 [rust] Scaffolding for napi-backed npm package
Scaffolds out a `forget_napi` crate following the guide for https://napi.rs/. 
This crate will be the public JS api for interacting with Forget.
2023-08-21 14:51:10 -07:00
Mofei Zhang
1c56843518 [tests] Allow .ts, .tsx fixture files 2023-08-22 12:54:01 -04:00
Jan Kassens
b277259232 [flow] upgrade to 0.214.0 (#27187)
Simple upgrade without any code changes required.

Changelog: https://github.com/facebook/flow/blob/main/Changelog.md
2023-08-21 11:23:47 -04:00
Lauren Tan
6be03b681e [ci] Split out babel-plugin-react-forget jest to its own job 2023-08-18 17:06:52 -04:00
Lauren Tan
e426cb553d [ci] Split out babel-plugin-react-forget prettier/eslint to its own job 2023-08-18 15:22:09 -04:00
Joe Savona
bcd692fca4 Promote enableOptimizeFunctionExpressions to default/only option
We’ve had this feature turned on internally for a while with only a couple minor 
bugs and no fundamental issues. It’s a necessary change for simplifying function 
expression dependencies and context variables, so let’s remove the feature flag 
and fix forward for any issues.
2023-08-18 12:06:16 -07:00
Lauren Tan
c4d000ce49 [ci] Rename TS ci to be consistent with other workflows 2023-08-18 14:16:21 -04:00
Lauren Tan
9e332ee05a [ci] Run yarn workspace tests in parallel 2023-08-18 14:10:41 -04:00
Sebastian Markbåge
98f3f14d2e [Fizz] Track Key Path (#27243)
Tracks the currently executing parent path of a task, using the name of
the component and the key or index.

This can be used to uniquely identify an instance of a component between
requests - assuming nothing in the parents has changed. Even if it has
changed, if things are properly keyed, it should still line up.

It's not used yet but we'll need this for two separate features so
should land this so we can stack on top.

Can be passed to `JSON.stringify(...)` to generate a unique key.
2023-08-18 10:18:33 -04:00
Joe Savona
a905a02901 [rust] Add SAFETY comments for unsafe blocks
Adds SAFETY comments for the two instances of unsafe blocks that are *not* just 
FFI. It seems like overkill to annotate all the FFI calls so i'm skipping that, 
let me know if anyone has strong preferences otherwise.
2023-08-17 15:23:46 -07:00
Josh Story
5623f2acf9 Updating forking implementation to match against more general fork implementations (#27205)
Search for more generic fork files if an exact match does not exist. If
`forks/MyFile.dom.js` exists but `forks/MyFile.dom-node.js` does not
then use it when trying to resolve forks for the `"dom-node"` renderer
in flow, tests, and build

consolidate certain fork files that were identical and make semantic
sense to be generalized
add `dom-browser-esm` bundle and use it for
`react-server-dom-esm/client.browser` build
2023-08-17 15:17:46 -07:00
Joe Savona
d5a8e80157 [rust][ci] Run cargo check/fmt
Formats the codebase, fixes some clippy lints, and updates CI to check that code 
is formatted.
2023-08-17 12:59:29 -07:00
Josh Story
e505316920 [Float][Flight][Fizz][Fiber] Implement preloadModule and preinitModule (#27220)
Stacked on #27224 

### Implements `ReactDOM.preloadModule()`
`preloadModule` is a function to preload modules of various types.
Similar to `preload` this is useful when you expect to use a Resource
soon but can't render that resource directly. At the moment the only
sensible module to preload is script modules along with some other `as`
variants such as `as="serviceworker"`. In the future when there is some
notion of how to preload style module script or json module scripts this
API will be extended to support those as well.

##### Arguments
1. `href: string` -> the href or src value you want to preload.
2. `options?: {...}` -> 
2.1. `options.as?: string` -> the `as` property the modulepreload link
should render with. If not provided it will be omitted which will cause
the modulepreload to be treated like a script module
2.2. `options.crossOrigin?: string` -> modules always load with CORS but
you can provide `use-credentials` if you want to change the default
behavior
2.3. `options.integrity?: string` -> an integrity hash for subresource
integrity APIs
  
##### Rendering
each preloaded module will emit a `<link rel="modulepreload" href="..."
/>`
if `as` is specified and is something other than `"script"` the as
attribute will also be included
if crossOrigin or integrity as specified their attributes will also be
included

During SSR these script tags will be emitted before content. If we have
not yet flushed the document head they will be emitted there after
things that block paint such as font preloads, img preloads, and
stylesheets.

On the client these link tags will be appended to the document.head.
  
### Implements `ReactDOM.preinitModule()`
`preinitModule` is a function to loading module scripts before they are
required. It has the same use cases as `preinit`.

During SSR you would use this to tell the browsers to start fetching
code that will be used without having to wait for bootstrapping to
initiate module fetches.

ON the client you would use this to start fetching a module script early
for an anticipated navigation or other event that is likely to depend on
this module script.

the `as` property for Float methods drew inspiration from the `as`
attribute of the `<link rel="preload" ... >` tag but it is used as a
sort of tag for the kind of thing being targetted by Float methods. For
`preinitModule` we currently only support `as: "script"` and this is
also the assumed default type so you current never need to specify this
`as` value. In the future `preinitModule` will support additional module
script types such as `style` or `json`. The support of these types will
correspond to [Module Import
Attributes](https://github.com/tc39/proposal-import-attributes).

##### Arguments
1. `href: string` -> the href or src value you want to preinitialize
2. `options?: {...}` ->
2.1 `options.as?: string` -> only supports `script` and this is the
default behavior. Until we support import attributes such as `json` and
`style` there will not be much reason to provide an `as` option.
2.2. `options.crossOrigin?: string`: modules always load with CORS but
you can provide `use-credentials` if you want to change the default
behavior
2.3 `options.integrity?: string` -> an integrity hash for subresource
integrity APIs

##### Rendering
each preinitialized `script` module will emit a `<script type="module"
async="" src"...">` During SSR these will appear behind display blocking
resources such as font preloads, img preloads, and stylesheets. In the
browser these will be appende to the head.

Note that for other `as` types the rendered output will be slightly
different. `<script type="module">import "..." with {type: "json"
}</script>`. Since this tag is an inline script variants of React that
do not use inline scripts will simply omit these preinitialization tags
from the SSR output. This is not implemented in this PR but will appear
in a future update.
2023-08-17 10:30:00 -07:00
Sebastian Markbåge
ac1a16c67e Add Postpone API (#27238)
This adds an experimental `unstable_postpone(reason)` API.

Currently we don't have a way to model effectively an Infinite Promise.
I.e. something that suspends but never resolves. The reason this is
useful is because you might have something else that unblocks it later.
E.g. by updating in place later, or by client rendering.

On the client this works to model as an Infinite Promise (in fact,
that's what this implementation does). However, in Fizz and Flight that
doesn't work because the stream needs to end at some point. We don't
have any way of knowing that we're suspended on infinite promises. It's
not enough to tag the promises because you could await those and thus
creating new promises. The only way we really have to signal this
through a series of indirections like async functions, is by throwing.
It's not 100% safe because these values can be caught but it's the best
we can do.

Effectively `postpone(reason)` behaves like a built-in [Catch
Boundary](https://github.com/facebook/react/pull/26854). It's like
`raise(Postpone, reason)` except it's built-in so it needs to be able to
be encoded and caught by Suspense boundaries.

In Flight and Fizz these behave pretty much the same as errors. Flight
just forwards it to retrigger on the client. In Fizz they just trigger
client rendering which itself might just postpone again or fill in the
value. The difference is how they get logged.

In Flight and Fizz they log to `onPostpone(reason)` instead of
`onError(error)`. This log is meant to help find deopts on the server
like finding places where you fall back to client rendering. The reason
that you pass in is for that purpose to help the reason for any deopts.

I do track the stack trace in DEV but I don't currently expose it to
`onPostpone`. This seems like a limitation. It might be better to expose
the Postpone object which is an Error object but that's more of an
implementation detail. I could also pass it as a second argument.

On the client after hydration they don't get passed to
`onRecoverableError`. There's no global `onPostpone` API to capture
postponed things on the client just like there's no `onError`. At that
point it's just assumed to be intentional. It doesn't have any `digest`
or reason passed to the client since it's not logged.

There are some hacky solutions that currently just tries to reuse as
much of the existing code as possible but should be more properly
implemented.
- Fiber is currently just converting it to a fake Promise object so that
it behaves like an infinite Promise.
- Fizz is encoding the magic digest string `"POSTPONE"` in the HTML so
we know to ignore it but it should probably just be something neater
that doesn't share namespace with digests.

Next I plan on using this in the `/static` entry points for additional
features.

Why "postpone"? It's basically a synonym to "defer" but we plan on using
"defer" for other purposes and it's overloaded anyway.
2023-08-17 13:26:14 -04:00
Joe Savona
5b6370234c Update readme to mention Rust CI config
This is mostly to test that the new configuration skips the Rust CI step if 
there are no rust changes - yay, that worked! But also worth mentioning in the 
readme so lets land.
2023-08-17 10:15:59 -07:00
Joe Savona
514916d9ce [rust][ci] Only run Rust actions when relevant files change 2023-08-17 10:10:44 -07:00
Joe Savona
3ce4116930 [rust][sema] Only create one scope per function/class
Fixes up function and class handling to not create nested scopes in some cases. 
Doesn't affect name resolution otherwise.
2023-08-17 10:03:00 -07:00
Joe Savona
543d27c2f0 [rust][sema] Support classes
Adds name resolution support for class declarations and expressions. Mostly this 
involves _not_ visiting some `Identifier` nodes that don't actually represent 
variables. For example, method names don't introduce new variables (but if they 
are computed, they may _refer_ to variables).
2023-08-17 10:02:56 -07:00
Joe Savona
dafa468765 [rust][sema] Allow defining/resolving known globals
Adds an option to pass a list of known globals into the semantic analyzer so 
that references to globals can be checked. As a follow-up we'll need to 
distinguish between different types of semantic analysis errors, so that callers 
which don't want to validate globals can ignore "unknown variable" reference 
errors while still handling definite errors such as duplicate declarations.
2023-08-16 16:44:40 -07:00
Sebastian Markbåge
ade82b8dd9 [Flight] Refactor emit and process functions (#27234)
Since we no longer have externally configured "process" methods, I just
inlined all of those.

The main thing in this refactor is that I just inlined all the error
branches into just `emitErrorChunk`. I'm not sure why it was split up an
repeated before but this seems simpler. I need it since I'm going to be
doing similar copies of this.
2023-08-16 17:04:21 -04:00
Joe Savona
bfb7d2bfbd [rust][sema] Handle var/let/const redeclaration
JavaScript has ~sane~ fun rules around where variables can be redeclared or not, 
and which kinds of variables this applies to. Actually the rules are pretty 
straightforward: 

* `var` can be redeclared any number of times. 

* In strict mode, other declarations cannot be redeclared within the same scope. 
This implies that a `var` declaration cannot conflict with these other forms, 
which must take into account hoisting. So you can't have a `var a; let a` in the 
same scope, but you also can't have a `let a` at a scope and then a `var a` 
which will hoist to that same scope.
2023-08-16 12:26:04 -07:00
Joe Savona
796080f4d1 [rust][sema] Statically detect some TDZ violations
The [temporal dead 
zone](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#temporal_dead_zone_tdz), 
often abbreviated TDZ, is the period between the start of its declaring block 
and the line that contains the let/const/class declaration. Not all instances of 
TDZ can be detected statically, because whether or not a TDZ error will occur at 
runtime is a property of which control flow path is taken and whether some other 
code has initialized the value. However, a subset of cases can be detected, and 
that's what we implement here. 

When we encounter a variable reference we record the next declaration id at that 
point in time. Then when resolving references after visiting the program, we can 
check: did the reference end up referring to a let/const/class binding whose id 
is equal or greater to that "next declaration"? If so, it means the reference 
refers to a variable that is provably declared later and is a known TDZ 
violation. The catch is that when resolving references, we reset the "next 
declaration" limit value when we bubble up out of a function scope. That's 
because references to let/const within a function may occur after the 
declaration, and we can't statically validate them.
2023-08-15 17:20:34 -07:00
Joe Savona
2edf66ecdf [rust][sema] Resolve all references after traversing program
Previously we attempted to resolve each reference at the close of its defining 
scope, and if it couldn't be resolved yet we bubbled the unresolved reference up 
to the parent scope. That approach isn't ideal for two reasons: 

* First, it's inefficient since we may have to make multiple attempts to resolve 
the same reference. 

* Second, it's incorrect. There can be cases where we think we can resolve a 
reference to a value defined in an outer scope, but there is a hoisted 
declaration from an intermediate scope that we haven't seen yet. 

The safest and most optimal thing is to just queue all references and resolve 
them at the end.
2023-08-15 12:33:45 -07:00
Joe Savona
34914796b2 [rust][sema] Set root scope kind based on program source type
Rather than always create a Global scope and then immediately add a Module child 
node, we now set the kind of the root scope to global (for scripts) or module 
(for modules) based on the program node.
2023-08-15 12:24:38 -07:00
Joe Savona
875d7175ac [rust] cargo fix 2023-08-15 09:31:49 -07:00
Joe Savona
b133b6c0b4 [rust][sema] Visit imports as declarations
Teaches the semantic analyzer about import statements. We now treat imports as 
declarations, so that subsequent references to the imported value can be 
resolved.
2023-08-15 09:30:43 -07:00
Joe Savona
15e0ecaa8f [rust] Convert Hermes source locations to ESTree SourceRange
Teaches the hermes->estree conversion to convert source ranges. This means our 
diagnostics now point to the actual source of the error: 

<img width="903" alt="Screenshot 2023-08-14 at 5 39 50 PM" 
src="https://github.com/facebook/react-forget/assets/6425824/2960d114-0cc6-4531-9e7d-00ff3bfb1eb3"> 

Of course I still need to teach our semantic analysis about imports, but that's 
a separate issue!
2023-08-14 17:36:58 -07:00
Joe Savona
f2a1a6a6e4 [rust][sema] Test for function hoisting 2023-08-14 17:36:54 -07:00
Mofei Zhang
1ad0460693 [sprout] Add shared runtime, improve error reporting
--- 

I added ~20 more tests to Sprout to get more of a feel for what the test 
framework would need to support all fixtures. I'm relatively confident that the 
approach outlined in [the original workplace 
post](https://fburl.com/workplace/ftu8woch) works to migrate almost all existing 
fixture tests to sprout (TLDR: use shared functions when possible, otherwise 
write helper functions in-file). 

Add `shared-runtime` file to reduce the amount of overhead needed to set up a 
fixture test. 

- All generalizable functions and values should be added here (e.g. 
`shallowCopy`, `deepCopy`, `sum`). 

- Editor integration is set up through a custom tsconfig, so importing from 
`shared-runtime` should just work (with hover annotations, click-to-definition, 
etc). 

<img width="682" alt="Screenshot 2023-08-17 at 11 09 47 AM" 
src="https://github.com/facebook/react-forget/assets/34200447/78c3dff9-ba10-4057-b3f6-2fa842d19b1d"> 

--- 

Tested new test fixtures added to sprout by adding them to `testfilter.txt` and 
running with `--verbose --filter`. 

Note that there are no unexpected exceptions, and all logs + returned values 
match. 

``` 

feifei0@feifei0-mbp babel-plugin-react-forget % yarn sprout:build && yarn sprout 
--verbose --filter 

yarn run v1.22.19 

$ yarn workspace sprout run build 

$ rimraf dist && tsc --build 

  Done in 2.07s. 

yarn run v1.22.19 

$ node ../sprout/dist/main.js --verbose --filter 

PASS  console-readonly 

ok {"a":1,"b":2} [ 

"{ a: 1, b: 2 }", 

"{ a: 1, b: 2 }", 

"{ a: 1, b: 2 }", 

"{ a: 1, b: 2 }", 

"{ a: 1, b: 2 }" 

] 

PASS  constant-propagate-global-phis-constant 

ok <div>global string 0</div> 

PASS  constant-propagate-global-phis 

ok <div>global string 1</div> 

PASS  dce-loop 

ok 10 

PASS  destructure-capture-global 

ok {"a":"value 1","someGlobal":{}} 

PASS  destructuring-mixed-scope-and-local-variables-with-default 

ok {"media":null,"allUrls":["url1","url2","url3"],"onClick":"[[ function 
params=1 ]]"} 

PASS  holey-array-expr 

ok [null,"global string 0",{"a":1,"b":2}] 

PASS  infer-global-object 

ok {"primitiveVal1":2,"primitiveVal2":null,"primitiveVal3":null} 

PASS  infer-phi-primitive 

ok 1 

PASS  infer-types-through-type-cast.flow 

ok 4 

PASS  issue933-disjoint-set-infinite-loop 

ok [2] 

PASS  jsx-tag-evaluation-order-non-global 

ok <div>StaticText1<div>StaticText2</div></div> 

PASS  jsx-tag-evaluation-order 

ok <div>StaticText1string value 1<div>StaticText2</div></div> 

PASS  method-call 

ok 4 

PASS  mutable-lifetime-loops 

ok {"a":{"value":6},"b":{"value":5},"c":{"value":4},"d":{"value":6}} 

PASS  mutable-lifetime-with-aliasing 

ok {"b":[{}],"value":[{"c":{},"value":"[[ cyclic ref *0 ]]"},null]} 

PASS  update-expression-in-sequence 

ok [4,2,3,4] 

PASS  update-expression-on-function-parameter 

ok [4,1,4,2,4,3,1,4,4] 

PASS  update-expression 

ok {"x":1,"y":1,"z":2} 

PASS  useMemo-multiple-if-else 

ok 2 

20 Tests, 20 Passed, 0 Failed 

  Done in 4.11s. 

```
2023-08-17 13:28:08 -04:00
Mofei Zhang
2b4a1d86ff [pipeline] Recognize "use no forget" directive
--- 

Add "use no forget", not gated behind a feature flag for simplicity ("use no 
forget" should always tell Forget to not compile a component, right?)
2023-08-17 11:03:20 -04:00
Mofei Zhang
28688ade9f [sprout] Add copyright headers etc 2023-08-17 11:03:18 -04:00
Lauren Tan
74aec8aa35 [ez] Add concurrently labels to yarn dev 2023-08-17 12:01:42 -04:00
Lauren Tan
9c2ce7a8c8 Try running tests for babel-plugin-react-forget concurrently
Unscientifically seems to be a little faster. I made sure to preserve the 
ordering of the logs even though the processes will run concurrently, so the ci 
output should still be readable 

![Screenshot 2023-08-17 at 11 51 45 
AM](https://github.com/facebook/react-forget/assets/1390709/b9878983-ed0c-4b93-bc10-61109ff8103d)
2023-08-17 11:58:15 -04:00
Mofei Zhang
5448b33eb0 [yarn workspaces] Add typescript dependencies to tsconfig
--- 

Previously, I used `yarn workspace build fixture-test-utils` and `yarn workspace 
build babel-plugin-react-forget` to recompile dependencies on sprout. However, 
tsc supports project references which was intended to solve this problem 
https://www.typescriptlang.org/docs/handbook/project-references.html 

Note that apparently this places `.tsbuildinfo` in package roots, according to 
https://github.com/microsoft/TypeScript/issues/30925
2023-08-16 15:38:30 -04:00
Mofei Zhang
d6dea6b9b9 [sprout][fixtures] Annotate some fixtures
--- 

This PR is an example of how to update fixture to add sprout annotations. 

Running with `yarn sprout --verbose --filter` shows the fixture outputs. 

``` 

PASS  array-access-assignment 

ok [[2],[[2],[],[3]]] 

PASS  array-expression-spread 

ok [0,1,2,3,null,4,5,6,"z"] 

PASS  array-map-frozen-array 

ok [[],[]] 

PASS  array-map-mutable-array-mutating-lambda 

ok [[],[]] 

PASS  array-pattern-params 

ok [{"a":"val1"},{"b":"val2"}] 

PASS  array-properties 

ok {"a":[[1,2],2,"hello"],"x":3,"y":"[[ function params=1 ]]","z":"[[ function 
params=1 ]]"} 

PASS  array-property-call 

ok {"a":[1,2,"hello",42],"x":4,"y":1} 

PASS  assignment-expression-computed 

ok [7] 

PASS  assignment-expression-nested-path 

ok {"b":{"c":6}} 

PASS  capturing-func-mutate-2 

ok {"a":2} 

PASS  capturing-function-alias-computed-load-2 

ok "val2" 

PASS  capturing-function-alias-computed-load-4 

ok "val2" 

```
2023-08-16 15:38:29 -04:00
Mofei Zhang
9d1a842a83 [sprout] Enable sprout on all new fixtures
--- 

Rename `SproutOnlyFilterTodoRemove.ts` to `SproutTodoFilter.ts`. I've tried to 
group the skipped fixtures by difficulty and add comments about what need to be 
done, also happy to change the structure of this. 

From this point, sprout will run on all new fixtures by default. If the fixture 
forgets to export a `FIXTURE_ENTRYPOINT`, sprout will fail with this error. 

<img width="853" alt="Screenshot 2023-08-15 at 5 59 32 PM" 
src="https://github.com/facebook/react-forget/assets/34200447/0f80d650-1dc1-4df4-9710-e49acbb424b0"> 

See #1961 for an example of how to annotate existing skipped fixtures or new 
ones. The `README.md` is also updated with a guide.
2023-08-16 15:38:28 -04:00
Mofei Zhang
c4ae2a48dc [sprout] patch bug + add verbose mode
--- 

``` 

yarn sprout --verbose 

``` 

Verbose mode prints out all outputs of tests. The test output is a status (`ok` 
or `exception`), a returned or thrown value, and a set of console logs. 

Currently as of #1960 , this is the output: 

```sh 

$ yarn workspace babel-plugin-react-forget run build && node 
../sprout/dist/main.js --verbose 

$ rimraf dist && tsc 

PASS  alias-nested-member-path 

ok {"y":{"z":[]}} 

PASS  assignment-variations-complex-lvalue 

ok {"y":{"z":4}} 

PASS  assignment-variations 

ok 1 

PASS  chained-assignment-expressions 

ok {"z":null} 

PASS  computed-call-evaluation-order 

ok {"f":"[[ function params=0 ]]"} [ 

"A", 

"B", 

"arg", 

"original" 

] 

PASS  const-propagation-into-function-expression-primitive 

ok 42 [ 

"42" 

] 

PASS  constant-propagation-for 

ok 0 

PASS  constant-propagation-while 

ok 0 

PASS  constant-propagation 

ok -6 [ 

"foo" 

] 

PASS  controlled-input 

ok <input value="0"> 

PASS  do-while-continue 

ok [1.5,1,0.5] 

PASS  do-while-simple 

ok [6,4,2] 

PASS  expression-with-assignment 

ok 5 

PASS  for-of-break 

ok [] 

PASS  for-of-conditional-break 

ok [] 

PASS  for-of-continue 

ok [0.5,1,1.5] 

PASS  for-of-destructure 

ok [0,2,4] 

PASS  for-of-simple 

ok [0,2,4] 

PASS  function-declaration-reassign 

ok {} 

PASS  function-declaration-redeclare 

ok "[[ function params=0 ]]" 

PASS  lambda-reassign-primitive 

ok 41 

PASS  lambda-reassign-shadowed-primitive 

ok {} 

PASS  property-call-evaluation-order 

ok {"f":"[[ function params=0 ]]"} [ 

"A", 

"arg", 

"original" 

] 

PASS  reactive-scope-grouping 

ok {"y":[{}]} 

PASS  sequentially-constant-progagatable-if-test-conditions 

ok "ok" 

PASS  simple-function-1 

ok "[[ function params=1 ]]" 

PASS  ssa-complex-multiple-if 

ok 

PASS  ssa-complex-single-if 

ok 

PASS  ssa-for 

ok 11 

PASS  ssa-if-else 

ok 

PASS  ssa-objectexpression-phi 

ok {"x":1,"y":3} 

PASS  ssa-property-call 

ok {"x":[[]]} 

PASS  ssa-property 

ok {"x":[]} 

PASS  ssa-return 

ok 2 

PASS  ssa-simple-phi 

ok 

PASS  ssa-simple 

ok 

PASS  ssa-single-if 

ok 

PASS  ssa-switch 

ok 

PASS  ssa-throw 

exception undefined 

PASS  ssa-while 

ok 10 

PASS  type-field-load 

ok 1 

PASS  type-test-field-store 

ok {} 

PASS  type-test-primitive 

ok 2 

PASS  update-expression-constant-propagation 

ok {"a":0,"b":0,"c":2,"d":2,"e":0} 

44 Tests, 44 Passed, 0 Failed 

  Done in 9.27s. 

```
2023-08-16 15:32:15 -04:00
Mofei Zhang
9d1f2c86ed [sprout] Codemod: add todos for test fixtures
--- 

Codemod to add an `export FIXTURE_ENTRYPOINT` with todo values for params for 
tests with at least one param and 0 refs to external values
2023-08-16 15:32:15 -04:00
Mofei Zhang
43e3cd61f8 [snap] Use sync fs apis to stop crashes
--- 

Not sure why, but snap kept silently crashing when I used fs/promises to write 
to many file handles. I tried a `.catch(...)`, but couldn't figure it out. This 
diff changes snap to use sync fs apis to avoid crashes, but I'd love to get 
feedback if someone knows how to debug this.
2023-08-16 15:32:14 -04:00
Mofei Zhang
ce015a164b [sprout] Codemod: add isComponent: false annotations to current fixtures
To keep the type signature simple, let's always have the same set of keys in 
`FIXTURE_ENTRYPOINT`
2023-08-16 15:32:13 -04:00
Lauren Tan
6b242c12a9 [ci] Don't run yarn build in ci
Can't recall why we added this, but it shouldn't be necessary and should shave 
off ~2 mins from ci
2023-08-16 12:16:51 -04:00
Lauren Tan
a59e15d40f [ci] Try to cache node_modules to speed up ci 2023-08-16 11:04:53 -04:00
Sathya Gunasekaran
b968d4da48 [hir] Validate globals are equal before propagating
Make sure the value of the globals in phi operands are the same before constant 
propagating them.
2023-08-16 15:39:01 +01:00
Sathya Gunasekaran
b686b5dd9d [hir] Refactor constant propagation of phis
This PR moves the phi evaluation to a separate function. 

Most importantly, it inverts the default case to _not_ constant propagate unless 
we have explicit validation of the phi operands.
2023-08-16 15:39:00 +01:00
Sathya Gunasekaran
c7210bac93 [test] Add failing test for constant propogation of globals as phi operands 2023-08-16 15:39:00 +01:00
Mofei Zhang
a418e35bf9 [sprout] QoL: use cli args, report pretty results
--- 

- Added sprout to Github Actions by updating `yarn test` command 

- Added cli args (`filter` and `sync`) 

- use chalk to make results nicer  

Tested locally: 

<img width="900" alt="Screenshot 2023-08-14 at 6 04 28 PM" 
src="https://github.com/facebook/react-forget/assets/34200447/b5481bbc-6a50-40c6-a85f-d2443130dd2a">
2023-08-14 19:26:05 -04:00
Mofei Zhang
d2983888f4 [sprout] Initial draft of sprout 🌱 test runner
--- 

## Sprout 🌱 Overview 

**(Overview copied from 
[sprout/README.md](0468ddf8bb/forget/packages/sprout/README.md))** 

React Forget test framework that executes compiler fixtures. 

Currently, Sprout runs each fixture with a known set of inputs and annotations. 
We hope to add fuzzing capabilities to Sprout, synthesizing sets of program 
inputs based on type and/or effect annotations. 

Sprout is currently WIP and only executes files listed in 
`src/SproutOnlyFilterTodoRemove.ts`. 

### Milestones: 

- [] Render fixtures with React runtime / `testing-library/react`. 

- [ ] Make Sprout CLI -runnable and report results in process exit code. 

After this point: 

- Sprout can be enabled by default and added to the Github Actions pipeline. 

- `SproutOnlyFilterTodoRemove` can be renamed to `SproutSkipFilter`. 

- All new tests should provide a `FIXTURE_ENTRYPOINT`. 

- [ ] Annotate `FIXTURE_ENTRYPOINT` (fn entrypoint and params) for rest of 
fixtures. 

- [ ] Edit rest of fixtures to use shared functions or define their own helpers. 

- [ ] *(optional)* Store Sprout output as snapshot files. i.e. each fixture 
could have a `fixture.js`, `fixture.snap.md`, and `fixture.sprout.md`. 

### Constraints 

Each fixture test executed by Sprout needs to export a `FIXTURE_ENTRYPOINT`, a 
single function and parameter set with the following type signature. 

```js 

type FIXTURE_ENTRYPOINT<T> = { 

// function to be invoked 

fn: ((...params: Array<T>) => any), 

// params to pass to fn 

params: Array<T>, 

// true if fn should be rendered as a React Component 

//  i.e. returns jsx or primitives 

isComponent?: boolean, 

} 

``` 

Example: 

```js 

// test.js 

function MyComponent(props) { 

return <div>{props.a + props.b}</div>; 

} 

export const FIXTURE_ENTRYPOINT = { 

fn: MyComponent, 

params: [{a: "hello ", b: "world"}], 

isComponent: true, 

}; 

``` 

--- 

## Implementation Details 

- jest-worker test orchestrator (similar to Snap 🫰). 

I chose to write a test runner instead of directly using Jest for flexibility 
and speed. 

- Sprout 🌱 currently runs much more code per fixture (2 babel transform 
pipelines + 2 `exec(...)` than snap, so all scaling concerns apply. 

- Sprout may need more customization in the future (e.g. fuzzing component 
inputs, caching artifacts) 

- We probably want to add snapshot files for Sprout, which is much easier with a 
custom runner. 

This is also one of the main reasons we wrote Snap. Jest consolidates all 
external snapshots (i.e. non-inline snapshots) from a test into [a single 
file](d0a006ffa9/forget/src/__tests__/__snapshots__/compiler-test.ts.snap). 
This was painful mainly for rebasing changes, but also for small papercuts (e.g. 
needing to run `yarn test -u` twice when deleting a fixture) 

- Currently does not save output to snapshot file, but we can easily add this 
later (i.e. each test would have a `.snap.md` and `.sprout.md` file) 

- Supports filter mode (same testfilter.txt file as snap) 

- Currently does not support watch mode. I expect that sprout's primary use will 
be catching bugs in the PR / Github Actions phase. Can be changed if we need to 
iterate on sprout output while developing. 

- All tests are run with `react-test-renderer` to access the React Runtime, 
which is needed for calls to `useMemoCache` (and other potential hooks). 

- react-test-renderer required a mocked DOM, so I ~~used js-dom~~ did a terrible 
js-dom hack to add document, window, and other browser globals to the 
jest-worker globals, then exec the test code in the jest worker global. 

I can clean this up later by bundling library code (e.g. react, 
react-test-renderer) to not use `require(...)`, then calling `exec` on all "test 
client code" in the js-dom mock global (instead of the real jest worker one) 

- Tests marked `isComponent` need to return valid jsx or primitives. Values 
returned by all other tests are converted to a string primitive via 
JSON.stringify. 

```sh 

# install new dependencies to node_modules 

$ yarn 

$ cd forget/packages/babel-plugin-react-forget 

$ yarn sprout:build && yarn sprout 

PASS  alias-nested-member-path 

PASS  assignment-variations-complex-lvalue 

PASS  assignment-variations 

PASS  chained-assignment-expressions 

PASS  computed-call-evaluation-order 

PASS  const-propagation-into-function-expression-primitive 

PASS  constant-propagation-for 

PASS  constant-propagation-while 

PASS  constant-propagation 

... 

  Done in 3.91s. 

```
2023-08-14 19:26:02 -04:00
Mofei Zhang
904ea6c9e4 [sprout] codemod for tests that can be run out of the box 2023-08-14 19:26:02 -04:00
Mofei Zhang
5669fc73c0 [snap] Refactor fixture utils to separate package
--- 

Move shared functions to `fixture-test-utils` package.
2023-08-14 19:26:01 -04:00
Mofei Zhang
02e8cf9790 [snap][easy] typecheck forget babel plugin options 2023-08-14 19:26:01 -04:00
Joe Savona
45d884bb6b Fix LeaveSSA missing param declarations
Nice find from @mofeiz, we weren't adding declarations for function params in 
LeaveSSA. This caused us to hit an invariant for update expressions that updated 
params which assumed that all named variables had a declaration. This is why 
it's helpful to add invariants, it helps you find places where you violate them 
:-)
2023-08-14 15:48:05 -07:00
Joe Savona
cb2ba7118f [rust][sema] Support hoisting semantics
Adds basic support for hoisting semantics: * Resolution of variable references 
is _always_ deferred in case the correct binding   hasn't been seet yet due to 
hoisting. * Var and function declarations bubble to the appropriate scope 

There are lots of subtleties that aren't implemented yet but these rules cover a 
lot.
2023-08-14 12:24:05 -07:00
Josh Story
0fb5b61ac6 Float integrity bugfix (#27224)
Stacked on #27223

When a script resource adopts certain props from a preload for that
resource the integrity prop was incorrectly getting assinged to the
referrerPolicy prop instead. This is now fixed.
2023-08-14 10:10:24 -07:00
Josh Story
5ea1397b2b Remove excess validation (#27223)
stacked on #27222 

When I initially developed Float I was trying to be extremely clever in
how to explain when there are mismatching Resource instances. I still
think that we should do some kind of validation here but I want to
implement something much simpler. In practice there are not many cases
where you would accidentally create the same resource twice but with
differing props. Since I am going to land `preloadModule` and
`preinitModule` soon and I want to avoid adding to the overly complex
dev validation there I am going to remove it now and add something later
that is simplified.
2023-08-14 10:08:55 -07:00
Joe Savona
011570a078 [rust][sema] Bubble unresolved references (for hoisting)
This is a precursor to adding support for hoisting in semantic analysis. 
Previously when we encountered an unknown reference we immediately reported an 
error. But hoisted variables may be referenced before they're defined, so we 
don't know for sure when we see an unknown variable if its actually unbound or 
not. 

This PR adds the first part of hoistingn support: rather than immediately report 
an error when encountering an unbound variable we store it in a list of 
unresolved references on the current scope. As we close each scope we recheck 
and see if the variable can now be resolved. If yes we record that, otherwise we 
bubble up the unresolved reference to the parent scope (and try again there). 

The next PR(s) will handle hoisting of `var` and other syntax to the apropriate 
nearest scope boundary (function/module).
2023-08-14 10:08:02 -07:00
Josh Story
5ad8ef5772 Should not export functions that are not imported (#27222)
These functions are not imported anywhere and should have not been
exported to begin with
2023-08-14 10:06:46 -07:00
Joe Savona
57f648009c [rust] Cleanup visitors 2023-08-14 09:54:29 -07:00
Joe Savona
e248534184 [rust] SSA fixes after operand refactor
When updating the data model for operands from instruction indices to 
identifiers, I forgot to rewrite terminal operands.Doing so required a refactor 
to use the new BlockRewriter helper.
2023-08-14 09:54:26 -07:00
Josh Story
1a001dac62 [Fizz][Float] When src or srcSet is a data URI we should not preload the image (#27218)
Data URI's in images can't effectively be preloaded (the URI contains
the data so preloading only duplicates the data in the stream. If we
encounter an image with this protocol in the src attribute we should
avoid preloading it.
2023-08-12 09:21:45 -07:00
Joe Savona
a49335f72a [rust] Support destructuring
Adds a `Destructure` instruction closely following the design of the TS-based 
compiler. The main change is fairly small: the TS compiler doesn't support rest 
spreads that are not identifiers, such as the `...y[]` in `const [x, ...[y]] = 
z`. I added support for this in the Rust compiler.
2023-08-11 15:13:21 -04:00
Lauren Tan
298bf55f25 Address feedback 2023-08-14 12:05:52 -04:00
Lauren Tan
3ec95c531b [be] More babel plugin Program cleanup
Give a more descriptive name
2023-08-11 16:39:03 -04:00
Lauren Tan
25e3575c38 [be] Move more logic into Imports module 2023-08-11 16:39:01 -04:00
Lauren Tan
ac8d874711 [eslint-plugin] Silence babel warnings in test
be quiet Babel!
2023-08-11 16:38:59 -04:00
Lauren Tan
d2990f1592 [be] Extract import logic to own module
Extracting logic around inserting import statements into its own module, with 
more descriptive function names
2023-08-11 16:38:57 -04:00
Lauren Tan
ebd8ed5c71 [be] Extract gating logic to its own module
Just moving code around to another module.
2023-08-11 16:38:55 -04:00
Lauren Tan
dd8b743f6a [be] Refactor gating logic in babel plugin
`compileProgram` was getting complex, so this extracts some of the logic into 
smaller functions. Additionally, the `try` block now only wraps the `compileFn` 
generator from Pipeline, which means not accidentally catching other non-Forget 
errors
2023-08-11 16:38:52 -04:00
Josh Story
4e3618ae41 [Float][Fizz] Fix srcSet and sizes handling for suspensey img preloads (#27217)
imageSrcSet should have been srcSet when referencing an img tag.
imageSizes should have been sizes. This caused preloads for img tags
using srcSet and sizes to incorrectly render as having a href only,
dropping the srcSet and sizes part of the preload
2023-08-11 11:27:22 -07:00
Lauren Tan
6c719f62a0 [ez] ComponentDeclaration transforms only into FunctionDeclaration
ComponentDeclarations can only be transformed into FunctionDeclarations, so the 
types were wrong
2023-08-11 13:31:06 -04:00
Josh Story
533fc28c1b Forgot to gate pushImg (#27212)
`pushImg` should have been gated by enableFloat

Added in #27191
2023-08-10 16:42:40 -07:00
Josh Story
f359f9b41a [Fizz] Preload "suspensey" images (#27191)
Eventually we will treat images without `loading="lazy"` as suspensey
meaning we will coordinate the reveal of boundaries when these images
have loaded and ideally decoded. As a step in that direction this change
prioritizes these images for preloading to ensure the highest chance
that they are loaded before boundaries reveal (or initial paint). every
img rendered that is non lazy loading will emit a preload just behind
fonts.

This change implements a new resource queue for high priority image
preloads

There are a number of scenarios where we end up putting a preload in
this queue

1. If you render a non-lazy image and there are fewer than 10 high
priority image preloads
2. if you render a non-lazy image with fetchPriority "high"
3. if you preload as "image" with fetchPriority "high"

This means that by default we won't overrsaturate this queue with every
img rendered on the page but the earlier encountered ones will go first.
Essentially this is React's own implementation of fetchPriority="auto".

If however you specify that the fetchPriority is higher then in theory
an unlimited number of images can preload in this queue. This gives
users some control over queuing while still providing a good default
that does not require any opting into

Additionally we use fetchPriority "low" as a signal that an image does
not require preloading. This may end up being pointless if not using
lazy (which also opts out of preloading) because it might delay initial
paint but we'll start with this hueristic and consider changes in the
future when we have more information
2023-08-10 15:39:19 -07:00
Lauren Tan
c3ec002d69 Invert shouldVisitNode logic 2023-08-10 17:24:22 -04:00
Lauren Tan
ec44c4789b Add ComponentDeclaration util 2023-08-10 17:24:21 -04:00
Sathya Gunasekaran
e70dfbb5a4 [babel] Lookup magic prop directly 2023-08-10 13:31:46 -04:00
Sathya Gunasekaran
c1c35407ba [test] Test with non component declaration 2023-08-10 12:02:08 -04:00
Joe Savona
c3ad8a86b1 [rust] Semantic analysis resolves break/continue 2023-08-10 10:59:51 -04:00
Joe Savona
ee13c30d10 [rust] Sketch of ReactiveIR (prev ReactiveFunction)
Initial data types for `forget_reactive_ir`, which is the Rust analogue of 
`ReactiveFunction` in the TS compiler. I'm renaming here for clarity, though 
naming suggestions are very welcome!
2023-08-10 10:59:51 -04:00
Joe Savona
7c38b15078 [rust] Align instruction data model closer to JS
Aligns the data model for `Instruction` closer to JS: * Adds an `lvalue: 
IdentifierOperand` property (Identifier + Effect) * Changes rvalues from being a 
reference to the definining instruction by   instruction offset (InstrIx) to be 
a variable reference (IdentifierOperand) 

There are pros and cons to the previous offset-based approach. It's definitely 
convenient to be able to jump directly to the instruction that defined an 
operand value. However: * Many passes need to track things like basic 
reassignments, which mean they need to build   up mappings of IdentifierId to 
some data. When all operands are IdentifierOperands, this   can be a single 
mapping. * It aligns closer to JS, which makes porting a bit easier. 

But most of all: porting the `ReactiveFunction` data type — which is in tree 
form - is non-trivial with the offset-based approach. As we map HIR to the tree 
form, we'd have to remap every operand offset. Using identifiers for operands 
simplifies this. 

We can always revisit this design choice later.
2023-08-10 10:59:50 -04:00
Joe Savona
cbb815e907 [rust] Port EliminateRedundantPhi fix 2023-08-10 10:59:50 -04:00
Joe Savona
74a062ba9d [rust] Autofix lints 2023-08-10 10:59:50 -04:00
Joe Savona
b8f1d37b6a [rust] Remove SWC
After the previous PR we no longer depend on SWC for the critical path of 
development/testing. Notably this unblocks adding support for the rest of the 
language: the new `forget_hermes_parser` crate automatically converts Hermes 
Parser's AST into our `forget_estree` format via codegen. Achieving full 
language support with SWC would have required manually defining the remaining 
conversions for the rest of the language. 

Long-term we'll need to revisit how to integrate into SWC, and more generally 
into setups build atop SWC such as Next.js's Turbopack-based build 
configuration. But i'll delete for now since we don't depend on it for 
iteration, it's slow to build, and requires us to opt-in to nightly Rust.
2023-08-10 10:59:49 -04:00
Joe Savona
7feaabfe68 [rust] Use hermes parser for Forget fixture tests
Replaces the use of SWC parser in the Forget fixture tests with Hermes Parser. 
This includes aligning on a single type to represent JS Values and numbers 
(combining semi-duplicated code from forget_hir and forget_estree) and adding 
support for lowering babel-style 
NumericLiteral/BooleanLiteral/StringLiteral/NullLiteral node types (since Hermes 
Parser produces a mix of estree/babel node types)
2023-08-10 10:59:49 -04:00
Joe Savona
6bca9fb7a3 [rust] Update HIR builder to use new semantic analysis
Updates HIR builder to rely on the new semantic analysis instead of assuming 
that the ast nodes will already have binding info attached. That was a stopgap 
until we had our own name resolution :-) 

Once this lands we can remove SWC and switch everything to forget_hermes_parser, 
and also remove the non-spec Identifier.binding field (which stored the 
temporary name resolution data).
2023-08-10 10:59:48 -04:00
Sathya Gunasekaran
5d8587b81c Add option to compile ReactScript 2023-08-09 14:49:29 -04:00
Sathya Gunasekaran
27f38ec321 Add hermes-parser 2023-08-09 14:47:56 -04:00
Sathya Gunasekaran
6075d7ea34 Upgrade babel 2023-08-09 14:47:56 -04:00
Semako
a20eea2519 Update README.md (#27209)
Update links from the old documentation to the new version

<!--
  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
I changed the links to get started with react from the old documentation
that is no longer being updated to the new one
<!--
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.
-->
2023-08-09 13:21:43 -04:00
Andrew Clark
201becd3d2 Bugfix: Fix crash when suspending in shell during useSES re-render (#27199)
This adds a regression test for a bug where, after a store mutation, the
updated data causes the shell of the app to suspend.

When re-rendering due to a concurrent store mutation, we must check for
the RootDidNotComplete exit status again.

As a follow-up, I'm going to look into to cleaning up the places where
we check the exit status, so bugs like these are less likely. I think we
might be able to combine most of it into a single switch statement.
2023-08-08 14:11:11 -04:00
Josh Story
cb3404a0cc [Fizz]: Unify preload queue (#27190)
Currently React attempts to prioritize certain preloads over others
based on their type. This is at odds with allowing the user to control
priority by ordering which calls are made first. There are some asset
types that generally should just be prioritized first such as fonts
since we don't know when fonts will be used and they either block
display or may lead to fallback fonts being used. But for scripts and
stylesheets we can emit them in the order received with other arbitrary
preload types.

We will eventually add support for emitting suspensey image preloads
before other resources because these also block display however that
implementation will look at which images are actually rendered rather
than simply preloaded.
2023-08-07 15:51:20 -07:00
Josh Story
9edf470d6e [Fizz] declare bootstrap script preloads to be fetchPriority: 'low' (#27189)
Generally scripts should not be preloaded before images but if they
arrive earlier than image preloads (or images) the network (or server)
may be saturated responding to inflight script preloads and not
sufficiently prioritize images arriving later. This change marks the
preloaded bootstrap script with a `low` fetch priority to signal to
supporting browsers that the request should be deprioritized. This
should make the preload operate similar to async script fetch priority
which is low by default according to https://web.dev/fetch-priority/

Additionally the bootstrap script preloads will emit before
preinitialized scripts do. Normal script preloads will continue to be
prioritized after stylesheets

This change can land separatrely but is part of a larger effort to
implement elevating image loading and making script loading less
blocking. Later changes will emit used suspensey images earlier in the
queue and will stop favoring scripts over images that are explicitly
preloaded
2023-08-07 15:44:34 -07:00
Josh Story
ea17cc18f4 [Fizz][Float] emit viewport meta before preloads (#27201)
Fixes: #27200 

preloads for images that appear before the viewport meta may be loaded
twice because the proper device image information is not used with the
preload but is with the image itself. The viewport meta should be
emitted earlier than all preloads to avoid this.

this change moves the queue for the viewport meta to preconnects which
already has the right priority for this tag
2023-08-07 15:22:48 -07:00
Joe Savona
43677da7e4 Add instructions for UpdateExpression variants
Adds new instructions to accurately model UpdateExpression semantics, since 
`x++` is un-intuitively not the same as `x = x + 1`. There are a few different 
ways to model the combination of prefix/postfix and increment/decrement: 

* One instruction for all combinations of prefix/postfix and 
increment/decrement, eg 'UpdateExpression' 

* Instructions for Increment/Decrement, each with a property to distinguish 
prefix/postfix 

* Instructions for Prefix/Postfix, each with aproperty to distinguish 
increment/decrement. 

I chose the latter, `PrefixUpdate` and `PostfixUpdate`, because it keeps the 
number of new instructions minimal while keeping separate instructions for the 
most important distinction: whether the result of the instruction is the value 
before applying the operation or after. I'm open to suggestions about this 
though. 

A few quick notes: 

* Constant propagation is supported but only for numbers (we don't support 
bigint yet anyway) 

* LeaveSSA needs to know about these instructions since their presence requires 
making the original variable declaration Let, not Const. 

* EnterSSA mapped lvalues before rvalues, which is out of order but didn't 
previously matter. I just had to flip the order and everything worked.
2023-08-07 13:50:32 -07:00
Mofei Zhang
e33c9c43cc [ssa] Patch: propagate every rewrite to function expressions
--- 

#1899 only propagated eliminated phi nodes to function expressions on the first 
iteration through blocks. However, this was buggy as later iterations could 
introduce rewrites that need to be propagated. 

[playground 
repro](https://0xeac7-forget.vercel.app/#eyJzb3VyY2UiOiJmdW5jdGlvbiBDb21wb25lbnQoKSB7XG4gIGNvbnN0IHggPSA0O1xuXG4gIGNvbnN0IGdldDQgPSAoKSA9PiB7XG4gICAgd2hpbGUgKGJhcigpKSB7XG4gICAgICBpZiAoYmF6KSB7XG4gICAgICAgIGJhcigpO1xuICAgICAgfVxuICAgIH1cbiAgICByZXR1cm4gKCkgPT4geDtcbiAgfTtcblxuICByZXR1cm4gZ2V0NDtcbn0ifQ==). 

I manually synced #1907 to check that this fix works for the VR Store codebase.
2023-08-07 17:41:35 -04:00
Mofei Zhang
ff2f2e0685 [patch] Gate EliminatePhi fix behind feature flag 2023-08-07 17:41:34 -04:00
Sathya Gunasekaran
adfae63f20 [hir] Remove unnecessary rewrite of instr.lvalue
The for loop over eachInstructionLValue already rewrites instr.lvalue: ```       
  for (const place of eachInstructionLValue(instr)) {           
rewritePlace(place, rewrites);         } ```
2023-08-07 13:41:59 -04:00
Joe Savona
461083d7bd [rust] Deprecate old manual ast visitor 2023-08-04 14:44:54 -07:00
Joe Savona
ab5213e8f4 [rust][sema] Comments 2023-08-04 12:16:08 -07:00
Joe Savona
3df04725bd [rust][sema] For statements and JSX
Adds semantic analysis support for normal `for` statements and for JSX. The main 
catch with JSX is that there are a bunch of identifiers that we have to ignore 
since they aren't variable references: jsx attribute names, namespace names, jsx 
member expression properties, and closing elements.
2023-08-04 12:02:21 -07:00
Joe Savona
4756c5ab26 [rust][sema] Shared logic for for-in/for-of
Shares the code for for..in and for..of, along with a few other internal 
refactorings.
2023-08-04 12:02:18 -07:00
Joe Savona
e6e2d9437e [rust] Improved name resolution
This is the start of an improved semantic analysis pass, reusing the 
ScopeManager added earlier in the stack but with new analysis built using the 
new visitor trait. The logic is a rough port of 


https://github.com/facebook/hermes/blob/main/tools/hermes-parser/js/hermes-eslint/src/scope-manager/referencer/Referencer.js 

Lots of bits are still missing, i'm starting with the parts that Forget needs.
2023-08-04 09:45:56 -07:00
Joe Savona
c6ae535e94 [rust] Codegen AST visitor
Updates `estree` codegen to emit a Visitor trait (temporarily named `Visitor2` 
since there is a hand-rolled one that some code is using). We use knowledge of 
the grammar to only visit fields whose type is a Node or Enum, or an "object" 
type that opts into being visitable. The latter is used for Function and Class. 

This will make it much easier to write the semantic analyzer.
2023-08-03 17:00:02 -07:00
Joe Savona
a67fefdebd [rust] Data structures for semantic analysis
This is two things: 

* A toy semantic analysis that handles a tiny subset of JS, including labeled 
statements, labeled break/continue, and variable 
declaration/reference/reassignment. This only exists as a way to prove out the 
API for the more important bit: 

* More importantly, this defines a data model for the semantic analysis results 
and an API for building up the semantic analysis. 

Subsequent diffs will replace the first bit (toy analysis impl), while keeping 
the second part.
2023-08-03 12:41:50 -07:00
Ruslan Lesiutin
997f52fbb3 fix[devtools/updateFiberRecursively]: mount suspense fallback set in timed out case (#27147)
Fixes https://github.com/facebook/react/issues/26793.

I have received a constantly reproducible example of the error, that is
mentioned in the issue above.
When starting `Reload and Profile` in DevTools, React reports an unmount
of a functional component inside Suspense's fallback via
[`onCommitFiberUnmount`](3ff846d106/packages/react-devtools-shared/src/hook.js (L408-L413))
in
[`commitDeletionEffectsOnFiber`](https://github.com/facebook/react/blob/main/packages/react-reconciler/src/ReactFiberCommitWork.js#L2025),
but this fiber was never registered as mounted in DevTools.

While debugging, I've noticed that in timed-out case for Suspense trees
we only check if both previous fallback child set and next fiber
fallback child set are non-null, but in these recursive calls there is
also a case when previous fallback child set is null and next set is
non-null, so we were skipping the branch.

<img width="1746" alt="Screenshot 2023-07-25 at 15 26 07"
src="https://github.com/facebook/react/assets/28902667/da21a682-9973-43ec-9653-254ba98a0a3f">

After these changes, the issue is no longer reproducible, but I am not
sure if this is the right solution, since I don't know if this case is
correct from reconciler perspective.
2023-08-03 20:02:18 +01:00
Joe Savona
8042970ea4 [rust] Scaffolding for semantic analysis 2023-08-01 15:55:53 -07:00
Sathya Gunasekaran
3e9e3a1c92 [e2e] Add test for useState 2023-08-04 15:50:42 +01:00
Mofei Zhang
015029dc65 [patch] Fix for constant propagation bug in VR Store
--- 

Changes in `@enableOptimizeFunctionExpressions` caused a bug in the last Forget 
sync to VR Store. The repro can be summarized to something like this: 

```js 

function foo() { 

const x = true; // some constant or global 

// Add some branching for type inference 

// This can be a Logical expression as well (e.g. `4 || 5`) 

if (...) { } 

// In this HIR block, SSA inserts a `x$2 = phi(x$1, x$1)`. 

// EliminateRedundantPhiNodes needs to rewrite all references of `x$2` to `x$1` 

const accessXInLambda = () => x; 

return accessXInLambda; 

}
2023-08-02 17:30:57 -04:00
Mofei Zhang
50b0954279 [tests] Add typed CompilerOptions for e2e tests 2023-08-02 17:30:56 -04:00
Mofei Zhang
2a5a8d552f [tests] Revive Forget e2e tests
--- 

Revives e2e test infra from #587. 

- All React component-like functions are compiled. 

- `yarn jest` runs each e2e test twice (forget and no forget) 

Github Actions is already running `yarn test`, which includes all jest tests 

``` 

Run yarn test 

yarn run v1.22.19 

$ yarn workspaces run test 

> babel-plugin-react-forget 

$ yarn jest && yarn snap:build && yarn snap 

$ tsc && jest 

PASS main src/__tests__/Result-test.ts 

PASS main src/__tests__/DisjointSet-test.ts 

PASS e2e with forget src/__tests__/e2e/hello.e2e.js 

PASS e2e no forget src/__tests__/e2e/hello.e2e.js 

Test Suites: 
[4](https://github.com/facebook/react-forget/actions/runs/5732016200/job/15534129231?pr=1881#step:8:5) 
passed, 4 total 

Tests:       23 passed, 23 total 

Snapshots:   11 passed, 11 total 

Time:        
6.1[5](https://github.com/facebook/react-forget/actions/runs/5732016200/job/15534129231?pr=1881#step:8:6)3 
s 

```
2023-08-02 17:30:55 -04:00
Lauren Tan
2d8da0d32d [babel] Don't console.error on unknown options
Internally these are considered errors in our pipelines
2023-08-02 12:34:18 -04:00
Joe Savona
203d5ad43b [rust] ESTree cleanup 2023-08-01 13:55:19 -07:00
Joe Savona
c09bfff04c [rust] Tests for HermesParser->ESTree conversion 2023-08-01 13:55:17 -07:00
Joe Savona
e353f3702e [rust][wip] Codegen conversion from HermesParser (C++) 2023-08-01 13:55:13 -07:00
Joe Savona
ce2725eda5 [rust] Very rough sketch of consuming Hermes parser results 2023-07-28 16:12:18 -07:00
Joe Savona
b61a47eb2c Parser benchmark 2023-07-28 16:12:17 -07:00
Joe Savona
01ad9d895e [rust] Remove arena allocator
Using an arena allocator can be faster, but it comes with several challenges: 

* It requires tediously tagging nearly every value with a lifetime. Any function 
that has to deal with arena-allocated data (which is every meaningful function) 
ends up with a lifetime parameter. Bleh. We also have to thread the allocator 
itself wherever we need to allocate, though this is less of a problem since 
_most_ functions already need the Environment and we can store the allocator 
there. 

* There is not yet widespread support in the Rust ecosystem for using custom 
allocators with custom data types. This means that things like HashMap/Set and 
IndexMap/Set can't be arena allocated. This means that either we have to add 
support to these data types (by upstreaming or forking) or just accept that 
we're only partially using the arena allocator. 

* Finally, `bumpalo`'s `Box` cannot be moved out of, which turns out to be an 
annoying limitation that i've already had to work around several times. 

In the end i'm not sure arena allocators are worth it at this stage of the 
project. Relay Compiler has been successful without one, and other Rust-based 
internal compilers get by without them too.
2023-07-28 16:12:17 -07:00
Joe Savona
0e4656ac1c [rust][wip] swc->estree for jsx 2023-07-28 16:12:16 -07:00
Lauren Tan
5230e6d849 Add failing test case for ValidateNoSetStateInRender bug
The current heuristic to check if setState is called in render is based on 
whether the lambda containing the call to setState has a mutable range that got 
extended. This doesn't seem to work in all cases so this validation needs a bit 
more work before we can turn it on by default
2023-07-27 17:08:01 -04:00
Lauren Tan
e77d975b16 Flag ValidateNoSetStateInRender
This needs a bit more work before we can turn it on by default, see the next PR 
for a failing test case.
2023-07-27 17:08:01 -04:00
BIKI DAS
493f72b0a7 Feat:-Added open in editor to appear by default (#26949)
Currently the Open in editor just is a placeholder input where the
developer would need to type the whole Vscode file path being shown as a
placeholder, we can make this process a little easier by just already
setting the URL .




https://github.com/facebook/react/assets/72331432/96f43230-6c49-45f7-907c-c99a0d3d8bf7

Earlier it used to be a placeholder describing the URL
<img width="1284" alt="Screenshot 2023-06-14 at 7 55 38 PM"
src="https://github.com/facebook/react/assets/72331432/4e8234ad-e1cd-4b55-8ef8-46dea82a9c7c">


cc @hoxyq

---------

Co-authored-by: Ruslan Lesiutin <rdlesyutin@gmail.com>
Co-authored-by: BIKI <biki@BIKIs-MacBook-Pro.local>
2023-07-27 17:04:16 +01:00
Lauren Tan
12e6cee06f [eslint-plugin] Update hermes-parser to 0.15.0
This includes a fix where the HermesToBabelAdapter was incorrectly outputting a 
`ClassMethod` instead of `ClassPrivateMethod` in certain scenarios. This was 
causing issues with our eslint plugin as it would crash on any file containing 
private methods because a malformed AST was formed.
2023-07-27 11:46:50 -04:00
Lauren Tan
20b175fcd5 [ci] Pass correct flags to yarn install
Turns out `--immutable` and `--immutable-cache` are for yarn 2, yarn 1.x needs 
to use the `--frozen-lockfile` flag instead
2023-07-27 11:06:29 -04:00
Lauren Tan
f45a4611e7 [ci] Don't run build on react
Building artifacts shouldn't be required for the tests, this should shave off a 
few minutes from CI
2023-07-27 11:06:27 -04:00
Lauren Tan
8405d8644f [eslint] Add plugin-proposal-private-methods
There was a bug in our internal Hermes to Babel adapter which caused some 
malformed AST to be constructed, which babel would then validate as being 
incorrect. That bug was fixed, but we still have to add this plugin so that 
private class methods can be parsed by babel. 

Tested internally
2023-07-27 10:52:28 -04:00
Joseph Savona
6912c31056 [CI] Run cargo build/test
Adds GitHub actions to build and test the Rust version of Forget on every commit 
to main. I didn't enable this on PRs for now just to avoid slowing down other 
folks, this seemed like a reasonable compromise while we're still in the 
experimentation phase. I test locally, and CI will catch if I or anyone else 
slips up.
2023-07-26 14:01:57 -07:00
Joe Savona
d4a1356eca [rust] swc->estree for optional chaining
Handles conversion of optional chains from swc -> estree.
2023-07-25 16:56:29 -07:00
Joe Savona
8bc6184728 [rust] deny unused fields on non-node structs
Rejects unknown fields during deserialization of helper structs (which don't 
have a `type` field). This would be super useful for AST `Node` types, too, but 
that requires implementing a custom deserializer so i'm punting on that for now.
2023-07-25 16:22:57 -07:00
Joe Savona
f21270a97d [rust] Complete estree through ES2021
Adds more AST types to handle the full ES2021 spec. At least, in theory I 
defined the schema correctly, and we'll have to just fix any bugs as we 
encounter them.
2023-07-25 15:58:58 -07:00
Joe Savona
90c3a3866d [rust] Improve estree serialization
Updates to use our own codegen'd `Serialize` implementation for AST node types. 
Notably, this allows us to ensure that we always emit a `type` field, even when 
the type is obvious from context (serde doesn't do this) and avoid 
double-emitting `type` fields (which serde can do if you try to force a tag to 
be emitted). We still use the Deserialize impl because it works fine for our 
purposes.
2023-07-25 15:16:22 -07:00
Joe Savona
c19286fce7 [rust] More es2015 ast types
Adds almost all the remaining AST types from ES2015 to `estree`, and updates the 
swc->estree->hir conversions accordingly. In a few places i punted with a 
`Diagnostic::todo()`.
2023-07-25 14:08:09 -07:00
Anatolii Kurochkin
fdb368d9e7 Uninstall unused Webpack 4 packages (#27058)
<!--
  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

 - Remove unused webpack 4 dependencies

## How did you test this change?

 - Ran `yarn test --prod`
 - Ran `yarn test`

## Related PRs:
 - https://github.com/facebook/react/pull/26887
2023-07-25 18:55:05 +01:00
Joe Savona
59c1f22057 [rust] port inline_use_memo
Ports InlineUseMemo to Rust, this is the only missing transform pass on the 
pipeline up through constant propagation. I wanted to finish this so that we 
could do benchmarking of the early phase of compilation. UseMemo does a bunch of 
rewriting so it seemed worth comparing performance. 

Included: 

* Add swc -> estree and estree -> HIR conversions for arrow functions and call 
expressions 

* Add HIR definition for labeled terminals and call expressions 

* Utility for inlining one function into another — note that this requires 
remapping InstrIx operands since instruction indices will change. An alternative 
would be to store all the instructions for both outer/inner functions in the 
same array, in which case we wouldn't need to remap. 

* Helpers for mutably iterating the operands of an instruction or terminal. 

* The actual inline_use_memo() function. The overall logic is similar, i just 
had to slightly shuffle the order of operations to satisfy the borrow checker.
2023-07-25 09:24:19 -07:00
Sathya Gunasekaran
4976f5c1be [deps] Update ts-jest version
Console warnings when running tests: ``` ts-jest[versions] (WARN) Version 5.1.3 
of typescript installed has not been tested with ts-jest. ``` 

Our typescript version is ahead of what's supported in ts-jest. This PR updates 
ts-jest to work with the latest typescript compiler.
2023-07-26 12:11:53 +01:00
Sathya Gunasekaran
25527b3c0a [hir] Add support for holey arrays
This PR adds a Hole kind that can be present in both ArrayExpression and 
ArrayPatterns. 

This Hole type is not interesting for our inference passes and is skipped over 
for all of the pipeline.
2023-07-26 12:03:19 +01:00
Sathya Gunasekaran
dcb6549dda [hir] Bailout when reading from React namespace
Forget doesn't understand the React namespace object and generates incorrect 
code when compiling code that loads props from this namespace object. 

This PR makes Forget bailout when we see a property load from React namespace 
object.
2023-07-25 16:08:32 +01:00
Sathya Gunasekaran
3f0afcbe47 [test] Failing test for using hooks from React namespace
Forget assumes hooks are imported and used directly without the React namespace 
and generates incorrect code when if there's a namespace.
2023-07-25 15:56:46 +01:00
Sathya Gunasekaran
82e426e229 [CI] Run react test suite on every PR
Add a new workflow to run test suite to run on every PR. 

Updates the build step to just build the UMD variant of react & react-dom for 
the tests.
2023-07-25 13:34:50 +01:00
Jan Kassens
3ff846d106 Flow: upgrade to 0.213.0 (#27142)
Simple upgrade that doesn't require changes.
2023-07-24 11:50:00 -04:00
Timothy Yung
49cf3b4038 [deps] Upgrade to hermes-parser@^0.14.0 and prettier@2.8.8
Upgrades every dependency on `hermes-parser` and `prettier` to the versions that 
we're using in the rest of our other codebases. Notably, these package versions 
are necessary for our other codebases to make use of mapped types in Flow.
2023-07-21 09:19:17 -07:00
Timothy Yung
fc9db4c487 [ez] Delete unnecessary yarn.lock files
8d021e5d797c5ef3b4e18a0be735c04005f2ae7a configured `./forget` as a workspace 
root, so these `yarn.lock` files in `app/*` and `packages/*` are no longer 
relevant. This PR deletes them to reduce noise and confusion.
2023-07-21 09:15:28 -07:00
tjallingt
587ae49d71 chore: remove unused argument from schedule requestHostCallback (#27133)
Noticed this argument was left in the cleanup from
https://github.com/facebook/react/pull/27130
It seems to me like it would benefit from being cleaned up too.
2023-07-20 10:30:30 -04:00
Andrew Clark
899cb95f52 Remove unused/redundant variables from Scheduler implementation (#27130)
Tidying up some redundant code left from previous iterations of the
implementation
2023-07-19 14:29:56 -04:00
Tianyu Yao
d445cee60f Make temporary NoStrictPassiveEffects option work with useModernStrictMode (#27105)
## Summary
Since we are enabling `useModernStrictMode` flag internally, to make
sure the internal testing of half StrictMode doesn't suddenly break,
this PR makes sure it also works with `useModernStrictMode` true.


## Test plan:
Manually set `useModernStrictMode` to true.
`yarn test ReactOffscreenStrictMode-test -r=www-modern --env=development
--variant=true`
`yarn test ReactStrictMode-test.internal -r=www-modern --env=development
--variant=true`
2023-07-18 11:58:01 -07:00
Noah Lemen
9f4fbec5f7 export dynamic disableSchedulerTimeoutInWorkLoop flag in www (#27117)
## Summary

This was not exposed as a dynamic flag in the build for facebook www. By
adding it, we'll be able to roll this out incrementally before cleaning
up this code altogether.

## How did you test this change?

`yarn build`

Before changes, `disableSchedulerTimeoutInWorkLoop` flag is not included
in ReactDOM-* build output for facebook www. Afterwards, it is included.
2023-07-17 15:44:45 -04:00
Lauren Tan
5ac909172e Validate unconditional setState in render 2023-07-17 13:00:38 -04:00
Joe Savona
bac24ffd78 [rust] Use new block helper for more passes 2023-07-14 22:47:21 +09:00
Joe Savona
de0c2393ad [rust] MergeConsecutiveBlocks and block helpers
Ports `MergeConsecutiveBlocks` to Rust. This was a tricky one: as we iterate 
through the blocks _if_ the block ends up being merged with its predecessor we 
need to consume it and modify its predecessor block (ie, mutating two things 
from the same data structure - shared mutation!). But if we _don't_ need to 
merge, then we need to not drop the current block. Ie, we sort of need to 
conditionally take ownership of the current block during iteration and put it 
back. 

I added a `BlockRewriter` helper type for this which has a helper to iterate 
safely. It calls the iterator lambda, moving blocks one at a time into the 
lambda. The lambda returns either `Keep(block)` to give the block back and keep 
it or `Remove` to tell the rewriter to drop the block. Thanks to making the 
Blocks data structure hold `Option<Box<BasicBlock>>` items, "moving" the block 
actually just means nulling out the option and conceptually giving ownership of 
the pointer to the callback - the data itself never moves. 

This involved creating a custom `Blocks` wrapper type, which i had been putting 
off doing. This cleans up a bunch of other logic around traversing blocks.
2023-07-14 18:00:16 +09:00
Joe Savona
32286b74ac [rust] enter_ssa uses new diagnostic type 2023-07-14 15:56:53 +09:00
Joe Savona
a39545a575 [rust] mark generated code, skip formatting 2023-07-14 15:46:57 +09:00
Joe Savona
0a79974d0e [rust] Extract HIR initialization passes to hir crate 2023-07-14 15:46:51 +09:00
Joe Savona
19b0a49967 [rust] add+apply rustfmt config 2023-07-14 15:33:06 +09:00
Joe Savona
18f7481ebf [rust] General-purpose diagnostic type and helpers
This PR adapts the `Diagnostic` type and helpers from Relay Compiler to Forget. 
The main changes are: 

* Removing some fields it doesn't seem we'll use for a while, if ever (like 
machine-readable arbitrary key/value data) 

* Switching from Relay Compiler's `Location` type to our SourceRange type 

* Using the severity enum previously established in the `forget_build_hir` 
crate, with Todo/Unsupported/InvalidSyntax/InvalidReact/Invariant variants 

* Adding support for translating our `Diagnostic` into a `miette::Diagnostic` so 
we can use miette's pretty printing 

With the new Diagnostic type in place i updated the existing build_hir code to 
use it and confirmed that the errors are now even nicer (when we attach extra 
data to annotate labels): 

<img width="860" alt="Screenshot 2023-07-14 at 3 10 00 PM" 
src="https://github.com/facebook/react-forget/assets/6425824/9d29425a-938b-4872-b999-aa174a3c329a"> 

This addresses (or brings us closer to addressing) many of your comments on the 
last diagnostics PR, @poteto!
2023-07-14 15:21:45 +09:00
Joe Savona
3e317b8bbf [rust] Contributing guide and readmes for every crate
Per the title, this updates the main readme file with a guide to contributing to 
the Rust compiler, and ensures that we have a brief description of every crate 
in local readme.md files. The `forget_hir` one is the most extensive and 
describes the high-level design of the HIR.
2023-07-14 12:24:19 +09:00
Joe Savona
68b0effca3 [rust] Workspace hygiene
I've primarily used what Cargo calls virtual workspaces, where the top-level 
Cargo.toml just lists a bunch of packages and they each have their own 
dependencies. This is fine, but i've noticed that more repos are using real 
workspaces and they offer a bunch of benefits. You define the dependencies in 
the top-level Cargo.toml and then can easily refer to them from multiple crates, 
ensuring all the versions match up. It makes it easier to refer to other crates 
in the workspace, too, because you define the path once at the root, then every 
other crate can just say `forget_foo = { workspace = true }`. 

I also renamed all the crates to be prefixed with `forget_`, in some cases 
removing the redundant `hir` name, So `hir-optimization` became 
`forget_optimization`, `hir-ssa` became `forget_ssa`. Also note the switch from 
hyphenated names to underscores everywhere, since at the end of the day you have 
to write the name with underscores in source code. 

I also deleted the demo crate that i started with since we don't need it 
anymore. 

And finally, i added an explicit publish = false to all the crates just to 
prevent mistakes.
2023-07-14 11:39:46 +09:00
Joe Savona
8ed6c6ab08 [rust] simplify function context visitor 2023-07-14 10:46:42 +09:00
Ruslan Lesiutin
546fe4681c fix[devtools/inspect]: null check memoized props before trying to call hasOwnProperty (#27057)
Simple check to avoid `TypeError`, quite rare case, but still.
2023-07-13 14:13:19 +01:00
Joe Savona
ea22dfe0b7 [rust] update estree snapshots 2023-07-13 16:07:53 +09:00
Joe Savona
19ba002a12 [rust] First pass of function context analysis
This is a quick "good enough" first pass at computing function expression 
context variables. It definitely needs to be overhauled, but it's enough to make 
a lot of common cases work correctly. 

First, this PR adds a hand-rolled Visitor trait for `estree`. Long-term that 
should probably be code-generated, but there are some subtleties to it such as 
the `visit_lvalue(callback)` helper which has to be wrapped around various calls 
(or we need some other way to distinguish identifiers within lvalues from 
identifiers within rvaluess). So for now it makes sense to hand-roll it until we 
are more confident in exactly how it should work. 

Given that visitor, i was able to port part of the existing 
`gatherCapturedDeps()` to Rust with some modifications. Note that we assume 
_something_ has run name resolution on the estree to match up identifiers to the 
declaration they refer to. But we don't store information about parent scopes so 
we can't walk up to check where things were defined. Instead we do the 
following: 

* Build up a list of all referenced identifiers 

* Also build up a set of bindings defined in the function itself 

* After visiting, filter our the first list to only include identifiers not 
defined by the function itself, and to eliminate duplicates. 

This covers the majority of cases: the most obvious gap is nested function 
expressions though actually that should just work.
2023-07-13 15:57:27 +09:00
Joe Savona
f3d40c8c24 [rust] Recurse into functions in other passes
Updates eliminate_redundant_phis and constant_propagation to recurse into 
function expressions. I also realized there was a bug in EliminateRedundantPhis 
in which we wouldn't traverse into function expressions encountered after 
finding a back edge, so i fixed that logic in both versions.
2023-07-13 13:34:10 +09:00
Joe Savona
4762208b0f [rust] enter_ssa recurses into function expressions
Updates `enter_ssa()` to recurse into function expressions. In the TS compiler 
we use a single Builder instance and copy (references to) the function 
expression's blocks into the builder. That type of sharing just does not play 
nicely with Rust. But... we don't need to do that! We already know the context 
variables of the function expression, so we can lookup each of them to find 
their re-mapped identifier, and set that as the starting state for the entry 
block of the function expression. That lets us use normal recursion and 
otherwise not share any information between the outer and inner builders. 

Of course to make this work we actually have to populate Function.context, but 
the algorithm _should_ work.
2023-07-13 12:24:55 +09:00
Joe Savona
c16124f255 [rust] Helpers for arena allocating box/vec 2023-07-13 11:26:42 +09:00
Joe Savona
dbe1af601b [rust] Start of function expression support
Start of function expression support: 

* Basic structure for representing function expressions in the HIR 

* Printer support 

* swc -> estree -> hir conversion for function expression _bodies_. Dependencies 
and context are not handled yet.
2023-07-13 11:14:42 +09:00
Joe Savona
1d5d89b8be [js/rust] Improve constant propagation
Makes the same improvement to constant propagation in both the JS and Rust 
versions. The core algorithm only populates phi variables if all operands have a 
known value (no back edges) and all those values are the same: this allows us to 
propagate constants in most cases and simply punts on handling propagating 
values that are affected by loops. However, since we collapse if statements into 
gotos when the test condition is a constant, there can be cases where a phi that 
originally existed will be pruned out: 

``` 

// bb0 

let x1; 

if (true) { 

// bb1 

x2 = 1; 

} else { 

// bb2 

x3 = 2; // this block becomes unreachable 

} 

// bb3 

x4 = phi(bb1: x2, bb2: x3); // this phi will get pruned s.t. x4 = x2 = 1 

return x4; 

``` 

However, the algorithm doesn't prune phis until _after_ applying constants, so 
currently we would see this phi node w different inputs and not propagate a 
constant for the final usage of x, even though it will clearly be `1`. 

The change is to make constant propagation use fixpoint iteration, iterating so 
long as terminals changed on the previous iteration. If no terminals change the 
algorithm completes in a single pass, but if terminals do change then we update 
phis and continue. As you can see from the new test case this allows us to find 
arbitrary length sequences of values and terminals that can be pruned.
2023-07-13 09:53:36 +09:00
Steven
9377e10105 Add referrerPolicy option to ReactDOM.preload() (#27096) 2023-07-12 14:32:56 -07:00
Joe Savona
8ada08f11e [rust] Port constant propagation
Ports constant propagation to Rust. The algorithm is broadly similar to the TS 
version, and most of the differences come from the slightly different HIR data 
model (operands are instruction indices not identifier ids). What this means is 
that the Constants map that we build up is really only used for variables that 
existed in the original program, and only comes into play with instructions like 
LoadLocal and StoreLocal. Other instructions such as Binary just look up their 
operands directly, ie they load the referenced instruction to check if both 
left/right are primitives. 

Note that with SSA form and the index-based operands we could actually get rid 
of StoreLocal/LoadLocal completely, which would further simplify constant 
propagation. However: 

* we'd need to add a Phi instruction kind, not a big deal but it diverges even 
more 

* more importantly, it makes it super hard to implement LeaveSSA 

That second point is a deal-breaker so unless someone has a great idea for how 
to exit SSA form without having Load/Stores, let's keep them.
2023-07-12 17:33:54 +09:00
Joe Savona
2fb14138d4 [rust] Port EliminateRedundantPhis
This is a nearly 1:1 port of EliminateRedundantPhis to Rust, the algorithm is 
identical and all differences are superficial. There are few things missing (an 
invariant instead of a panic in one place, recursing into function expressions) 
but the Rust version is still going to end up shorter despite keeping all the 
comments.
2023-07-12 14:54:49 +09:00
Joe Savona
e029e22a9a [rust] fix lints 2023-07-12 13:01:42 +09:00
Joe Savona
c7ccc5dd30 [rust] Initial port of EnterSSA
This is a first pass at porting EnterSSA to Rust. First pass in the sense that 
it's hard to fully test it, and also in the sense that we'll likely figure out 
even better ways to work w the HIR as we iterate. Oh and i didn't do recusing 
into function expressions yet, since we can't even represent function 
expressions yet, and that may require modifying the design a bit (though i have 
an idea that i think will work, which is for the Builder to have an optional 
parent. When we encounter a block with no predecessors, we check the parent. I 
_think_ this will make all the borrowing "just work"). 

A few notes: 

Rust's compilation model parallelizes and incrementally computes at the crate 
granularity, so builds are faster if we split up our code into more but smaller 
crates. Setting up a clean dependency graph can dramatically improve build 
performance too. For example, to run the `fixtures` tests we can build `estree` 
and `hir` in parallel, then once those build _all_ of our other crates can be 
built in parallel until we get to `fixtures` which depends on the everything 
else. The various passes don't have any build dependencies on each other so they 
can build in parallel. Hence the new code for SSA stuff is in a separate 
`hir-ssa` crate. We should similarly group other passes (approximately one crate 
per folder in the babel-plugin-react-forget/src/ directory, eg SSA, Inference, 
Optimization, etc). 

Second, shared mutable ownership can be modeled in Rust but requires wrappers 
such as `Rc<RefCell<>>`. It's generally more efficient and more idiomatic to 
rethink the data model and algorithm. For EnterSSA, the Builder object holds a 
reference into the HIR that it only ever reads, and the pass (which drives the 
builder) also holds a reference into the HIR, which it mutates. The previous PR 
split up Blocks and Instructions, and the value of that is more apparent in 
`enter_ssa()`. The Rust equivalent of the builder holds a _shared_ (immutable) 
reference to just the HIR's blocks, while the pass (driving the builder) holds a 
_unique_ (mutable) reference to just the HIR's instructions. This lets us keep 
the overall feel of the algorithm while keeping Rust happy. 

Also note that the other change — to making operands be InstrIx indices into the 
instructions array — means that the SSA logic is simpler. Most instructions 
don't have to be visited at all, since they don't deal with loads/stores. 
Terminals also don't need to be visited, since they reference instructions, not 
identifiers. The Phi concept seems to just work too. 

I also updated the printer to print predecessors and phis.
2023-07-12 12:38:13 +09:00
Noah Lemen
0a360642dc integrate scheduler.yield in SchedulerPostTask (#27069)
## Summary

`scheduler.yield` is entering [Origin Trial soon in Chrome
115](https://chromestatus.com/feature/6266249336586240). This diff adds
it to `SchedulerPostTask` when scheduling continuations to allow Origin
Trial participation for early feedback on the new API.

It seems the difference here versus the current use of `postTask` will
be minor – the intent behind `scheduler.yield` seems to mostly be better
ergonomics for scheduling continuations, but it may be interesting to
see if the follow aspect of it results in any tangible difference in
scheduling (from
[here](https://github.com/WICG/scheduling-apis/blob/main/explainers/yield-and-continuation.md#introduction)):

> To mitigate yielding performance penalty concerns, UAs prioritize
scheduler.yield() continuations over tasks of the same priority or
similar task sources.

## How did you test this change?

```
yarn test SchedulerPostTask                
```
2023-07-11 14:35:53 -04:00
Joe Savona
e9d2822e92 [rust] New data model for HIR
This change is motivated by starting to explore porting EnterSSA to Rust. It's a 
good medium complexity pass and quickly demonstrates why a direct port of our 
existing data model and algorithms won't work so well. For examples just these 
first lines at the top of the transform create multiple references to the 
function body/blocks: 


58da89888e/forget/packages/babel-plugin-react-forget/src/SSA/EnterSSA.ts (L230-L231) 

But more generally it's always felt wrong that instructions have an LValue that 
isn't really used. So here i'm exploring making operands a newtype index into a 
single instructions array (shared for the entire function), and using different 
types for identifier references in SetLocal and LoadLocal. Incidentally this 
also declutters the printed HIR quite a bit. 

I'm not going to land this until i actually finish enter_ssa() and some other 
passes. We definitely need to balance fidelity to the existing code (to 
facilitate porting) with using idiomatic Rust (to facilitate porting in the 
sense of not fighting the borrow checker).
2023-07-11 16:59:08 +09:00
Joe Savona
f452ed2971 [rust] estree support for jsx 2023-07-11 14:08:46 +09:00
Joe Savona
61d7e6ae3d [js] optimize function expressions by default
This mode improves compilation and makes optimizations easier, let's make it the 
default. I previously confirmed that enabling this mode didn't affect output 
when synced internally, and I'll do that again before landing the PR.
2023-07-11 13:06:13 +09:00
Joe Savona
830127f680 [js] Remove InstrValue::ExpressionStatement
I added this as a quick workaround, since we didn't support unused 
logical/conditional expression statements. Now that we handle them we don't need 
InstructionValue::ExpressionStatement anymore. I found this when porting our 
lowering to Rust.
2023-07-11 11:52:33 +09:00
Joe Savona
bdd50d522d [rust] Update swc->estree->hir conversion for new estree
The previous PRs to make `estree` use codegen broke the swc->estree and 
estree->hir conversions. This PR updates those conversions so everything builds 
now.
2023-07-11 11:52:32 +09:00
Joe Savona
17ed6cc9a9 [rust] Custom deserialization for more precise errors
The overall goal of this workstream is to have a Rust representation of ESTree 
that we can use as the input and output of the compiler. In Rust environments we 
can convert between the native AST of SWC or OXC and ESTree, and when invoked 
from JavaScript we can serialize to/from ESTree-compliant JSON. Given that our 
first target is to plug into a JS-based compilation toolchain, we need to have a 
working serialization to/from ESTree JSON. The point of the codegen-based 
`estree` crate is to allow us to model estree as ergonomic, idiomatic Rust (to 
make consuming it in code easier) while also allowing us to serialize to/from 
spec-compliant ESTree. This PR flushes out one remaining piece. 

Updates our estree codegen to generate a custom `Deserialize` implementation 
instead of using the derived one from serde. ESTree has some enums whose 
variants are themselves enums, for example we have 

```rust 

enum ModuleItem { 

ImportExportDeclaration(ImportExportDeclaration), 

Statement(Statement), 

} 

enum ImportExportDeclaration { ... } 

enum Statement { ... } 

``` 

This sort of works with serde's derive implementation: you have to use the "tag" 
representation for the inner enums, and an "untagged" representation for the 
outer one (ModuleItem). The problem is that with an untagged representation, 
serde doesn't know what type of data it's expecting. All it can do is go one by 
one and try to parse the data as the first variant (eg ImportExportDeclaration) 
then the next one (Statement) and fail when it gets to the end of the list. If 
the data isn't valid for any reason, deserialization will fail with a "not a 
valid ModuleItem" error. That's true but not helpful, especially if you're 
developing estree, are confident that the input json is valid, and need to 
figure out where you messed up the definition. It's also not helpful as an 
end-user if you're not sure your input json is valid. 

So this PR updates our codegen to emit a custom derive implementation that is 
identical for both regular enums (like Statement) and recursive ones (like 
ModuleItem). We first extract the tag to know what type the value is, then 
deserialize exactly as that type. So in the above case, rather than have to 
first try parsing every ModuleItem as an ImportExportDeclaration and then fall 
through to statement, we just decode the tag (`type` in our case, for example 
say it's an "ForStatement"), then deserialize directly as that type (eg, as 
ForStatement), then wrap it in the enum variant (ModuleItem::Statement(...)). 
For recursive enums like ModuleItem we add an extra wrapper as necessary. 

The end result is that we get much more precise errors and deserialization is 
more efficient: we always decode just the tag, then as exactly that type. 

Note that our serialization is also not perfect right now, because we don't 
always emit the `type` key. Serde only emits it when a value appears in an enum. 
We can similarly generate custom serializers for all our types to always emit 
the tag. That will be straightforward when it's necessary. The current PR was 
more of a blocker, because it was really hard to figure out mistakes in the 
estree definition given the ambiguous errors. Thanks to this PR we now get 
precise errors along the lines of "unknown type `JSXElement`" which are easy to 
resolve.
2023-07-08 23:00:01 +09:00
Joe Savona
1abea6c49d [rust] allow complex types in estree codegen
Uses the `syn` crate, which can parse various Rust syntax forms, to parse the 
`type` field from json schema description. This allows us to describe complex 
types like `"type": "Vec<Option<ArrayElement>>"` directly, rather than requiring 
flags like nullable, plural, and nullable_item. The main flag that i'm keeping 
is "optional", which is used to indicate when the field itself (not the value) 
is optional.
2023-07-08 23:00:00 +09:00
Joe Savona
3983e882b8 [rust] estree codegen cleanup 2023-07-08 22:59:59 +09:00
Joe Savona
750b1e6adb [rust] Partial ES2015 support in estree codegen
Adds some parts of the ES2015 spec, such as imports and ForOfStatement. This is 
enough to get a few more fixtures compiling. The last one uses JSX which I 
haven't defined yet.
2023-07-08 22:59:58 +09:00
Joe Savona
0c1193ecd7 [rust] estree codegen for improved serialization
This is meant to replace the initial `estree` crate with a version that is 
generated from a JSON description of ESTree. The idea is to make it easy to 
experiment with slightly different representations to balance ergonomic usage of 
the data at runtime with serialization compatible with ESTree spec. The JSON 
schema looks like this (somewhat abbreviated): 

``` 

{ 

// Objects are struct types that don't have a `type` and can't appear as an enum 
variant 

objects: { 

Position: { 

line: {type: "NonZeroU32"}, 

column: {type: "u32"} 

}, 

... 

}, 

// Nodes are struct types with a `type` and which can appear as enum variants 
(statements, expressions, patterns, etc) 

nodes: { 

ArrayExpression: { 

elements: { 

type: "Expression", 

plural: true, 

nullable_item: true, 

} 

} 

... 

}, 

// Categories of nodes with multiple variants, represented as enums. 

// Can be recursive, eg ForInit can be VariableDeclaration or Expression, 

// where Expression is also an enum 

enums: { 

Expression: [ 

"ArrayExpression", 

... 

] 

}, 

// Simple enums which have a corresponding string value. Used primarily for 
operators (binary/unary/logical/etc) 

// but also for things like variable declaration kind (var/const/let) 

operators: { 

BinaryOperator: { 

Plus: "+", 

Instanceof: "instanceof", 

} 

} 

} 

``` 

The core estree files are now generated using Cargo's build script mechanism. 
Right now i only defined the types and fields from ES5, so i'll have to flush 
out the rest of the modern JS spec and extensions like JSX, TypeScript, and 
Flow. But already the for-statement example works, showing that this approach 
can handle complex cases such as unions of types or other unions (ForStatement 
initializer is tricky bc it can be a VariableDeclaration or an Expression - that 
works now!). 

This is still WIP a bit - now that the ESTree definition is more precise i can 
go back and clean up some other code (have to, because the swc -> estree 
conversion needs some tweaks now).
2023-07-08 22:59:56 +09:00
Joe Savona
a32a2baa73 [rust] Start of error handling
Until now i've freely used `panic!`, `unwrap()`, and friends for "error 
handling". This PR switches to consistently returning `Result` within the HIR 
builder, using a structured error representation that exploits helpers from 
`thiserror` and `miette` crates. Miette has a super graphical formatter for 
diagnostics as you can see in the screenshot (also see the 
[repo](https://docs.rs/miette/5.9.0/miette/index.html)). 

This is just a first pass and we'll need to flush out the error handing story 
more. Two obvious directions to go next: 

* Make HIR construction error-tolerant, so that it can find as many errors as 
possible at once rather than failing on the first error. We did this in Relay 
Compiler as well, and we can likely borrow some of its helpers. 

* Decouple from `miette`. It's very nice but less flexible than I'd like. We can 
define our own more generic diagnostic type that contains structured data, then 
have a generic conversion mechanism into a miette type so we can use their 
display logic. 

<img width="789" alt="Screenshot 2023-07-06 at 3 55 38 PM" 
src="https://github.com/facebook/react-forget/assets/6425824/e1f1ed4b-5188-4af5-9af4-8f6c5c345023">
2023-07-08 22:59:55 +09:00
Joe Savona
8176f25719 [rust] ForStatement support
Implements support for `ForStatement` from swc -> estree -> hir, flushing out 
more of the HIR representation and porting pieces from HIRBuilder as necessary.
2023-07-08 22:59:54 +09:00
Sebastian Markbåge
fdc8c81e07 [Flight] Client and Server Reference Creation into Runtime (#27033)
We already did this for Server References on the Client so this brings
us parity with that. This gives us some more flexibility with changing
the runtime implementation without having to affect the loaders.

We can also do more in the runtime such as adding `.bind()` support to
Server References.

I also moved the CommonJS Proxy creation into the runtime helper from
the register so that it can be handled in one place.

This lets us remove the forks from Next.js since the loaders can be
simplified there to just use these helpers.

This PR doesn't change the protocol or shape of the objects. They're
still specific to each bundler but ideally we should probably move this
to shared helpers that can be used by multiple bundler implementations.
2023-07-07 11:09:45 -04:00
Lauren Tan
58a8d0bdc7 [ez] Update gitignore for Rust 2023-07-06 16:25:18 -04:00
Noah Lemen
eb2c2f7c2c rename SuspenseList export to unstable_SuspenseList (#27061)
## Summary

as we began [discussing
yesterday](https://github.com/facebook/react/pull/27056#discussion_r1253282784),
`SuspenseList` is not actually stable yet, and should likely be exported
with the `unstable_` prefix.

the conversation yesterday began discussing this in the context of the
fb-specific packages, but changing it there without updating everywhere
else leads to test failures, so here the change is made across packages.

## How did you test this change?

```
yarn flow dom-browser
yarn test
```
2023-07-06 14:09:53 -04:00
Josh Story
a19bbebbe3 When selecting a package variant from an export map we should favor n… (#27030)
When selecting a package variant from an export map we should favor node
over edge-light

edge-light represents a runtime with some minimal set of web apis
generally found across edge runtimes. However some environments might be
both edge-light compatible and node compatible and (node is adding many
web APIs) and when both conditions exist we want to favor the node
implementations. A followup to this change will add the web streams APIs
to Flight and Fizz so the node version exports the same interfaces for
web streams that edge does in addition to the node specific
implementations.
2023-07-06 10:50:59 -07:00
Sathya Gunasekaran
853d0b1b69 [fuzzer] Make fuzzer work with Forget
Remove v8 specific bits. It's still not very useful as we barely have any tests 
that can be used as input corpus.
2023-07-06 11:44:14 +05:30
Sathya Gunasekaran
31ec959e9b [fuzzer] Initial import of v8's fuzzer
Copied from  
https://chromium.googlesource.com/v8/v8/+/master/tools/clusterfuzz/js_fuzzer/
2023-07-06 11:44:14 +05:30
Joe Savona
1bf00e6b6e [rust] lint 2023-07-06 09:24:53 +09:00
Joe Savona
357e9de19b [rust] IfStatement support
Lowering for IfStatements, which includes porting some of the HIRBuilder helpers 
like enter() and reserve().
2023-07-06 09:24:52 +09:00
Joe Savona
c59ac387ae [rust] Assignment expressions 2023-07-06 09:24:51 +09:00
Joe Savona
d99da01698 [rust] basic VariableDeclaration support 2023-07-06 09:24:50 +09:00
Joe Savona
2eb7c897f3 [rust][ez] cleanup 2023-07-06 09:24:49 +09:00
Joe Savona
f6957e9a32 [rust] Partial handling of identifiers
Fundamentally this PR is about lowering identifiers during construction of HIR. 
For now i'm punting on context variables and assuming all variables are either 
global, module-scoped, or locals. The implementation involves a few pieces: 

* `estree::Identifer` gets extended with optional binding information. The idea 
is that _some_ name resolution mechanism will populate this. Eventually our own, 
but we can also borrow data from another source... 

* `estree-swc` now configures SWC's (possibly broken?) name resolution mechanism 
and sets the above binding data when translating identifiers from swc into our 
estree format. 

* hir `Builder` tracks identifiers based on `(name, BindingId)` pairs, and 
assigns a unique `hir::Identifier` instance for each pair. `Identifiers` are 
clone-able (shared). 

* Tangential: i updated the printer to handle more instruction variants, 
including the now-ported LoadGlobal instr. 

I don't love this but it's a start. Long-term we definitely should have our own 
name resolution mechanism which we run on the estree prior to lowering to HIR.
2023-07-06 09:24:48 +09:00
Joe Savona
08e51d3fd7 [rust] Pretty-printer for HIR
Implements a pretty-printer for the HIR and switches the fixture tests to use 
this instead of the debug format. It's much more readable now! 

Note that not all types are properly printed, I only implemented the 
instructions and terminals used in the example. For others we fall back to the 
Debug impl so we at least print something.
2023-07-06 09:24:47 +09:00
Joe Savona
d3b9948b5e [rust] Fixture tests for parsing and lowering
Adds a new `fixtures` crate intended for running end-to-end tests of the 
compiler. As we expand the compiler this will eventually match our JS fixture 
setup, where we have .js files as input and produce memoized JS output. 

For now, this does the following: 

* Parses with SWC (omg this was painful to setup) 

* Runs SWC's name resolution, which annotates the SWC ast in-place 

* Convert the SWC ast into our `estree` representation 

* Convert `estree` into `hir` for each top-level function declaration in the 
input program 

* Print the Rust `Debug` view of the resulting HIR 

As a next step i'll add a pretty-printer for the HIR to roughly match what we 
have in JS.
2023-07-06 09:24:46 +09:00
Joe Savona
1d2e7ee747 [rust] Use Rc<RefCell<>> for shared identifiers
Multiple Place instances can share a reference to a given Identifier in our JS 
implementation. For simplicity of the initial port I’m using Rc (for sharing) 
and RefCell (for runtime-checked mutability). This is the standard pattern for 
shared mutable references in Rust when you don’t need multi-threaded support. We 
don’t need HIR to be accessible by multiple threads so this is fine, if we do 
multiple threads it will be to parallelize compilation of separate functions. 

There are other idioms w less runtime overhead, such as Place holding an index 
into a separate vec of identifiers, but that would make the port much less 
straightforward.
2023-07-06 09:24:45 +09:00
Joe Savona
b1c8cb358b [rust] Start of lowering (BuildHIR)
Starts to port BuildHIR, in the Rust case this means the ESTree -> HIR 
conversion. This necessitated flushing out the Builder struct a bit more. Mostly 
the logic translates over very directly, and if anything it's cleaner because of 
the lack of noise dealing with TypeScript unsoundness for Babel typedefs and 
switch statements.
2023-07-06 09:24:44 +09:00
Joe Savona
2ac69bf7d9 [rust] Passes from HIRBuilder
This is a start to porting HIRBuilder, with a largely complete implementation of 
`build()`. Notably this includes all the passes which build() calls, and the 
helper functions those passes call in turn: 

```rust 

reverse_postorder_blocks(&mut hir); 

remove_unreachable_for_updates(&mut hir); 

remove_unreachable_fallthroughs(&mut hir); 

remove_unreachable_do_while_statements(&mut hir); 

mark_instruction_ids(&mut hir)?; 

mark_predecessors(&mut hir); 

``` 

This was pretty straightforward. I ran into one borrow checker issue with (iirc) 
`remove_unreachable_for_updates` where i needed to simultaneously hold a mutable 
reference into the HIR (to write the ForTerminal) and also get an immutable 
reference to check if the update block is reachable. The challenge is this: 

```rust 

for block in hir.blocks.values_mut() { 

^^^^^^^^^^^^^^^^^^^^^^^ hir borrowed mutably here 

if let TerminalValue::ForTerminal(terminal) = &mut block.terminal.value { 

if let Some(update) = terminal.update { 

if !hir.blocks.contains(&update) { 

^^^^^^^^^^ borrowed immutably here 

terminal.update = None; 

^^^^^^^^ mutable borrow still active here (and also bc of the loop) 

} 

} 

} 

} 

``` 

I quickly worked around this as we do in the other passes here by first building 
a set of the block ids contained in the function (so that the 
`hir.blocks.contains()` call becomes a call to the copied set of block ids). 

An alternative would be to add a helper function for mutable iteration which 
takes the desired value out of the data structure so that you can safely mutate 
it and reference the rest of the HIR. Usage might look like this: 

```rust 

hir.blocks.each_mut(|mut block, hir| { 

if let TerminalValue::ForTerminal(terminal) = &mut block.terminal.value { 

if let Some(update) = terminal.update { 

if !hir.blocks.contains(&update) { 

terminal.update = None; 

} 

} 

} 

}) 

``` 

The lambda would receive the current `block` as a mutable reference, and for the 
duration of the call `hir.blocks[block.id]` would be set to a sentinel value 
that would crash if accessed. Meanwhile, `hir` would be a readonly reference to 
the HIR, allowing the lambda to otherwise lookup information on the HIR but not 
mutate it. This seems...kinda fine? But also not immediately necessary as 
there's an easy and efficient-enough-workaround for the cases i've encountered 
so far.
2023-07-06 09:24:43 +09:00
Joe Savona
6c3792e8d5 [rust] Initial translation of HIR and related types
This is an initial translation of HIR (minus the ReactiveFunction bits). It's 
mostly a straightforward translation. A few differences: 

* Instead of Effect having an Unknown variant, we type `Place.effect: 
Option<Effect>`. Maybe i'll revert that but it seems right. 

* Terminal is divided into `Terminal { id: InstructionId, value: TerminalValue 
}` and `enum TerminalValue { ... }`, so that we can reference the terminal's id 
without caring about which kind of terminal it is. 

* Each instruction value variant gets a named struct, whereas in JS we had lots 
of anonymous InstructionValue variants. 

* Rust generators are still an unstable nightly feature and likely to change 
syntax enough that it seems safer not to rely on them. So 
`eachTerminalSuccessor()` returns a `Vec<BlockId>`. If the perf of this is bad 
enough we can switch to something like SmallVec (a popular crate) which stores a 
few elements inline on the stack to optimize for small vecs (which our case 
should be). 

Perhaps more importantly, what's _not different_: I kept the existing approach 
of BasicBlocks having a Vec of owned instruction instances, with 
InstructionValue variant operands as Places rather than indices into a shared 
instruction array. If this works out it will make porting straightforward. 

However there's one aspect of this that is incorrect: right now each `Place` 
owns its `Identifier`, whereas in JS the Identifier instances are shared mutable 
references. I'll definitely need to refactor the data structures to allow 
sharing Identifiers in some form, at which point we may want to change other 
things too.
2023-07-06 09:24:40 +09:00
Joe Savona
4c0122f4cf [rust] Small improvements plus snapshot testing for estree 2023-07-06 09:24:39 +09:00
Joe Savona
2b168ad673 [rust] SWC->ESTree conversion
Start of converting swc's representation into our estree format.
2023-07-06 09:24:38 +09:00
Joe Savona
4230eb63d8 [rust] ESTree representation with basic serialization support
Start of an `estree` crate for representing ESTree with serialization to/from 
ESTree JSON. To get the serialization to work quickly I took some shortcuts and 
uses a slightly less precise modeling. Longer-term we can write some custom 
serialization code and get more precise types (eg avoid the `ExpressionLike` 
enum in favor of proper Expression and ExpressionOrFoo types).
2023-07-06 09:24:37 +09:00
Joe Savona
292f07e19f [rust] SWC usage example
Basic example of parsing some code with SWC and then running name resolution.
2023-07-06 09:24:36 +09:00
Noah Lemen
e91142dd69 Cleanup unused unstable_startTransition, unstable_useTransition, unstable_useDeferredValue exports from fb packages (#27056)
## Summary

came across these TODOs – an internal grep indicated that remaining
callsites have been cleaned up, so these can now be removed.

## How did you test this change?

```
yarn flow dom-browser
yarn test
```
2023-07-05 17:23:43 -04:00
Andrew Clark
7118f5dd7b [ESLint] Disallow hooks in async functions (#27045)
Hooks cannot be called in async functions, on either the client or the
server. This mistake sometimes happens when using Server Components,
especially when refactoring a Server Component to a Client Component.

React logs a warning at runtime, but it's even better to catch this with
a lint rule since it will show immediate inline feedback in the editor.

I added this to the existing "Rules of Hooks" ESLint rule.
2023-07-05 11:44:28 -04:00
Sathya Gunasekaran
d10885ae0e [snap] Blow up if testfilter is not found in filter mode
No more failing silently when testfilter file is not found.
2023-07-05 18:53:18 +05:30
Sathya Gunasekaran
4a8b36b8b1 [hir] Check for globals while lowering UpdateExpression
lowerIdentifierForAssignment does extra checks such as checking if globals are 
lvalues. 

UpdateExpression lowers into an assignment and previously we missed out on such 
checks.
2023-07-05 20:21:09 +05:30
Sathya Gunasekaran
8eca031508 [test] Add failing test for mutating global 2023-07-05 20:21:05 +05:30
Ruslan Lesiutin
035a41c4e2 React DevTools 4.27.8 -> 4.28.0 (#27051)
List of changes:
* Devtools:-Removed unused CSS ([Biki-das](https://github.com/Biki-das)
in [#27032](https://github.com/facebook/react/pull/27032))
* fix[devtools/profilingCache-test]: specify correct version gate for
test ([hoxyq](https://github.com/hoxyq) in
[#27008](https://github.com/facebook/react/pull/27008))
* fix[devtools/ci]: fixed incorrect condition calculation for
@reactVersion annotation ([hoxyq](https://github.com/hoxyq) in
[#26997](https://github.com/facebook/react/pull/26997))
* fix[ci]: fixed jest configuration not to skip too many devtools tests
([hoxyq](https://github.com/hoxyq) in
[#26955](https://github.com/facebook/react/pull/26955))
* fix[devtools/standalone]: update webpack configurations
([hoxyq](https://github.com/hoxyq) in
[#26963](https://github.com/facebook/react/pull/26963))
* fix[devtools]: check if fiber is unmounted before trying to highlight
([hoxyq](https://github.com/hoxyq) in
[#26983](https://github.com/facebook/react/pull/26983))
* feat[devtools]: support x_google_ignoreList source maps extension
([hoxyq](https://github.com/hoxyq) in
[#26951](https://github.com/facebook/react/pull/26951))
* chore[devtools]: upgrade to webpack v5
([hoxyq](https://github.com/hoxyq) in
[#26887](https://github.com/facebook/react/pull/26887))
* fix[devtools]: display NaN as string in values
([hoxyq](https://github.com/hoxyq) in
[#26947](https://github.com/facebook/react/pull/26947))
* fix: devtools cannot be closed correctly
([Jack-Works](https://github.com/Jack-Works) in
[#25510](https://github.com/facebook/react/pull/25510))
* Fix:- Fixed dev tools inspect mode on Shadow dom
([Biki-das](https://github.com/Biki-das) in
[#26888](https://github.com/facebook/react/pull/26888))
* Updated copyright text to Copyright (c) Meta Platforms, Inc. and its …
([denmo530](https://github.com/denmo530) in
[#26830](https://github.com/facebook/react/pull/26830))
* Fix strict mode badge URL ([ibrahemid](https://github.com/ibrahemid)
in [#26825](https://github.com/facebook/react/pull/26825))
2023-07-04 09:11:14 +01:00
Lauren Tan
6e6ecfc4d9 [eslint-plugin] Remove babel/traverse and babel/parser
These are unused since we switched over to hermes-parser
2023-07-03 12:25:37 -04:00
Lauren Tan
2a882d798b [eslint-plugin][ez] Remove unused scripts 2023-07-03 12:25:35 -04:00
Lauren Tan
c6b437b402 [eslint-plugin] Remove fbt dependencies
I incorrectly included these as deps, we were only using these to verify 
codegen. It seems fine to leave in but when I imported it internally vscode 
would error, so just remove it
2023-07-03 12:25:33 -04:00
BIKI DAS
53ac219378 Devtools:-Removed unused CSS (#27032)
I tried to check out for the CSS bundle using the
[eslint-plugin-css-modules](https://www.npmjs.com/package/eslint-plugin-css-modules),
and ran it locally , seems like There are lot of unused styles and
classes present .
I have attached the output below after running the lint command.

https://gist.github.com/Biki-das/647ceb7383b43cca9c8619e1dc33fe0d

All the shared.css files should not be touched i feel as they are being
used randomly by some file

Thoughts @hoxyq
2023-07-03 12:16:04 +01:00
Sathya Gunasekaran
cff435ca3d [plugin] Remove duplicate export statement 2023-07-03 15:51:05 +05:30
Andrew Clark
5c8dabf886 Detect and warn about native async function components in development (#27031)
Adds a development warning to complement the error introduced by
https://github.com/facebook/react/pull/27019.

We can detect and warn about async client components by checking the
prototype of the function. This won't work for environments where async
functions are transpiled, but for native async functions, it allows us
to log an earlier warning during development, including in cases that
don't trigger the infinite loop guard added in
https://github.com/facebook/react/pull/27019. It does not supersede the
infinite loop guard, though, because that mechanism also prevents the
app from crashing.

I also added a warning for calling a hook inside an async function. This
one fires even during a transition. We could add a corresponding warning
to Flight, since hooks are not allowed in async Server Components,
either. (Though in both environments, this is better handled by a lint
rule.)
2023-07-01 22:44:41 -04:00
Andrew Clark
47385f8fa4 Don't transpile async/await in tests (#27029)
Modern runtimes support native async/await, as does the version of Node
we use for our tests. To match how most of our users run React, this
disables the transpilation of async/await in our test suite.
2023-06-30 16:29:23 -04:00
Josh Story
1fdacbefd6 [DOM] Add unstable_batchedUpdates to server-rendering-stub (#27028)
`unstable_batchedUpdates` shouldn't really be called on the server but
the semantics are clear enough and we can provide a trivial
implementation that calls the provided callback so we are adding it to
the server-rendering-stub.

This means we will also keep it around when we make the top level
react-dom exports match the server-rendering-stub in the next major
2023-06-30 11:19:18 -07:00
Jan Kassens
7f362de158 Revert "Fix: Detect infinite update loops caused by render phase updates (#26625)" (#27027)
This reverts commit 822386f252.

This broke a number of tests when synced internally. We'll need to
investigate the breakages before relanding this.
2023-06-30 12:51:11 -04:00
Andrew Clark
fc801116c8 Detect crashes caused by Async Client Components (#27019)
Suspending with an uncached promise is not yet supported. We only
support suspending on promises that are cached between render attempts.
(We do plan to partially support this in the future, at least in certain
constrained cases, like during a route transition.)

This includes the case where a component returns an uncached promise,
which is effectively what happens if a Client Component is authored
using async/await syntax.

This is an easy mistake to make in a Server Components app, because
async/await _is_ available in Server Components.

In the current behavior, this can sometimes cause the app to crash with
an infinite loop, because React will repeatedly keep trying to render
the component, which will result in a fresh promise, which will result
in a new render attempt, and so on. We have some strategies we can use
to prevent this — during a concurrent render, we can suspend the work
loop until the promise resolves. If it's not a concurrent render, we can
show a Suspense fallback and try again at concurrent priority.

There's one case where neither of these strategies work, though: during
a sync render when there's no parent Suspense boundary. (We refer to
this as the "shell" of the app because it exists outside of any loading
UI.)

Since we don't have any great options for this scenario, we should at
least error gracefully instead of crashing the app.

So this commit adds a detection mechanism for render loops caused by
async client components. The way it works is, if an app suspends
repeatedly in the shell during a synchronous render, without committing
anything in between, we will count the number of attempts and eventually
trigger an error once the count exceeds a threshold.

In the future, we will consider ways to make this case a warning instead
of a hard error.

See https://github.com/facebook/react/issues/26801 for more details.
2023-06-29 16:05:00 -04:00
Sebastian Markbåge
d9c333199e [Flight] Add Serialization of Typed Arrays / ArrayBuffer / DataView (#26954)
This uses the same mechanism as [large
strings](https://github.com/facebook/react/pull/26932) to encode chunks
of length based binary data in the RSC payload behind a flag.

I introduce a new BinaryChunk type that's specific to each stream and
ways to convert into it. That's because we sometimes need all chunks to
be Uint8Array for the output, even if the source is another array buffer
view, and sometimes we need to clone it before transferring.

Each type of typed array is its own row tag. This lets us ensure that
the instance is directly in the right format in the cached entry instead
of creating a wrapper at each reference. Ideally this is also how
Map/Set should work but those are lazy which complicates that approach a
bit.

We assume both server and client use little-endian for now. If we want
to support other modes, we'd convert it to/from little-endian so that
the transfer protocol is always little-endian. That way the common
clients can be the fastest possible.

So far this only implements Server to Client. Still need to implement
Client to Server for parity.

NOTE: This is the first time we make RSC effectively a binary format.
This is not compatible with existing SSR techniques which serialize the
stream as unicode in the HTML. To be compatible, those implementations
would have to use base64 or something like that. Which is what we'll do
when we move this technique to be built-in to Fizz.
2023-06-29 13:16:12 -04:00
Sebastian Markbåge
2153a29661 [Flight] createServerReference should export $$FORM_ACTION on the Server (#26987)
Currently, only the browser build exposes the `$$FORM_ACTION` helper.
It's used for creating progressive enhancement fro Server Actions
imported from Client Components. This helper is only useful in SSR
builds so it should be included in the Edge/Node builds of the client.

I also removed it from the browser build. We assume that only the Edge
or Node builds of the client are used
together with SSR. On the client this feature is not needed so we can
exclude the code. This might be a bit unnecessary because it's not that
much code and in theory you might use SSR in a Service Worker or
something where the Browser build would be used but currently we assume
that build is only for the client. That's why it also don't take an
option for reverse
look up of file names.
2023-06-28 19:12:34 -04:00
Sebastian Markbåge
5945e068ab [Flight] Instrument the Promise for Async Module instead of using a Module Cache (#26985)
Currently, since we use a module cache for async modules, it doesn't
automatically get updated when the module registry gets updated (HMR).

This technique ensures that if Webpack replaces the module (HMR) then
we'll get the new Promise when we require it again.

This technique doesn't work for ESM and probably not Vite since ESM will
provide a new Promise each time you call `import()` but in the
Webpack/CJS approach this Promise is an entry in the module cache and
not a promise for the entry.

I tried to replicate the original issue in the fixture but it's tricky
to replicate because 1) we can't really use async modules the same way
without compiling both server and client 2) even then I'm not quite sure
how to repro the HMR issue.
2023-06-28 14:30:09 -04:00
Sebastian Markbåge
a1c62b8a76 [Flight] Add Support for Map and Set (#26933)
We already support these in the sense that they're Iterable so they just
get serialized as arrays. However, these are part of the Structured
Clone algorithm [and should be
supported](https://github.com/facebook/react/issues/25687).

The encoding is simply the same form as the Iterable, which is
conveniently the same as the constructor argument. The difference is
that now there's a separate reference to it.

It's a bit awkward because for multiple reference to the same value,
it'd be a new Map/Set instance for each reference. So to encode sharing,
it needs one level of indirection with its own ID. That's not really a
big deal for other types since they're inline anyway - but since this
needs to be outlined it creates possibly two ids where there only needs
to be one or zero.

One variant would be to encode this in the row type. Another variant
would be something like what we do for React Elements where they're
arrays but tagged with a symbol. For simplicity I stick with the simple
outlining for now.
2023-06-27 17:10:35 -04:00
Andrew Clark
822386f252 Fix: Detect infinite update loops caused by render phase updates (#26625)
This PR contains a regression test and two separate fixes: a targeted
fix, and a more general one that's designed as a last-resort guard
against these types of bugs (both bugs in app code and bugs in React).

I confirmed that each of these fixes separately are sufficient to fix
the regression test I added.

We can't realistically detect all infinite update loop scenarios because
they could be async; even a single microtask can foil our attempts to
detect a cycle. But this improves our strategy for detecting the most
common kind.

See commit messages for more details.
2023-06-27 13:26:35 -04:00
Noah Lemen
80d9a40114 Remove useMutableSource (#27011)
## Summary

This PR cleans up `useMutableSource`. This has been blocked by a
remaining dependency internally at Meta, but that has now been deleted.

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

## How did you test this change?

```
yarn flow
yarn lint
yarn test --prod
```

<!--
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.
-->
2023-06-27 12:45:46 -04:00
Ruslan Lesiutin
6aacd3fa15 fix[devtools/profilingCache-test]: specify correct version gate for test (#27008)
- Correctly gate the test to `[18.0.0, 18.2.0]` versions of react, as it
was initially defined before
https://github.com/facebook/react/pull/26742
- I have recently fixed the gating logic in
https://github.com/facebook/react/pull/26955 and
https://github.com/facebook/react/pull/26997, should be stable now
- I have added a non-gated version of this test, which should run only
for the current version of react, the one we build from sources
- The test version for react `v[18.0.0, 18.2.0]` should expect
`"priorityLevel": "Immediate"`, the other `"priorityLevel": "Normal"`,
as it was changed in https://github.com/facebook/react/pull/26512
2023-06-26 17:37:53 +01:00
Ruslan Lesiutin
8ec962d825 fix[devtools/ci]: fixed incorrect condition calculation for @reactVersion annotation (#26997)
Suppose that you have this setup for devtools test:
```
// @reactVersion <= 18.1
// @reactVersion >= 17.1
```

With previous implementation, the accumulated condition will be `"<=
18.1" && ">= 17.1"`, which is just `">= 17.1"`, when evaluated. That's
why we executed some tests for old versions of react on main (and
failed).

With these changes the resulting condition will be `"<= 18.1 >= 17.1"`,
not using `&&`, because semver does not support this operator. All
currently failing tests will be skipped now as expected.

Also increased timeout value for shell server to start
2023-06-23 16:45:53 +01:00
Sathya Gunasekaran
64637ac84c [playground] Refactor pragma parsing into separate function 2023-06-23 14:56:00 +05:30
Sathya Gunasekaran
3883eb9507 [playground] Make all options configurable 2023-06-23 14:55:59 +05:30
Lauren Tan
0892e305bc [eslint-plugin] Clean up error message
Omits some unncessary details from the error message surfaced in eslint
2023-06-28 11:43:56 -04:00
Lauren Tan
f850d3b265 Improve remaining InvalidReact error messages 2023-06-28 11:43:56 -04:00
Lauren Tan
dda59d093a Add InvalidJS error severity 2023-06-28 11:43:55 -04:00
Lauren Tan
3fb8937391 Add first example of error suggestion 2023-06-27 14:01:40 -04:00
Lauren Tan
448ed2b67b Refactor CompilerErrorDetails
- Made most static methods on CompilerError take a single options object   as an 
argument. With the exception of invariant which takes a condition and an options 
object. - Added a new `suggestions` field on CompilerErrorDetail, which we'll   
use to provide eslint suggestions - Updated eslint-plugin-react-forget to handle 
suggestions
2023-06-27 14:01:39 -04:00
Lauren Tan
c3d6789857 Reclassify existing errors
Most of these errors were incorrectly using InvalidInput as a catchall for 
rejecting code. I went through each one and manually updated them to be more 
accurate
2023-06-27 14:01:39 -04:00
Lauren Tan
6c4318e5c2 Add InvalidReact and InvalidConfig error severities 2023-06-27 14:01:38 -04:00
Sathya Gunasekaran
e762d5730b [test] Update stale test expectations 2023-06-23 14:51:38 +05:30
Tianyu Yao
70e998a106 Fix disableStrictPassiveEffect not working under Suspense (#26989)
In https://github.com/facebook/react/pull/26914 I added an extra logic
to turn off double useEffect if there is an `Offscreen`
tag. But `Suspense` uses `Offscreen` tag internally and that turns off
`disableStrictPassiveEffect` for everything.
2023-06-22 13:12:30 -07:00
Ruslan Lesiutin
c8deb5db66 fix[ci]: fixed jest configuration not to skip too many devtools tests (#26955)
## Summary
Running `yarn test --project devtools --build` currently skips all
non-gated (without `@reactVersion` directives) devtools tests. This is
not expected behaviour, these changes are fixing it.

There were multiple related PRs to it:
- https://github.com/facebook/react/pull/26742
- https://github.com/facebook/react/pull/25712
- https://github.com/facebook/react/pull/24555

With these changes, the resulting behaviour will be:
- If `REACT_VERSION` env variable is specified:
    - jest will not include all non-gated test cases in the test run
- jest will run only a specific test case, when specified
`REACT_VERSION` value satisfies the range defined by `@reactVersion`
directives for this test case

- If `REACT_VERSION` env variable is not specified, jest will run all
non-gated tests:
   - jest will include all non-gated test cases in the test run
- jest will run all non-gated test cases, the only skipped test cases
will be those, which specified the range that does not include the next
stable version of react, which will be imported from `ReactVersions.js`

## How did you test this change?
Running `profilingCache` test suite without specifying `reactVersion`
now skips gated (>= 17 & < 18) test
<img width="1447" alt="Screenshot 2023-06-15 at 11 18 22"
src="https://github.com/facebook/react/assets/28902667/cad58994-2cb3-44b3-9eb2-1699c01a1eb3">

Running `profilingCache` test suite with specifying `reactVersion` to
`17` now runs this test case and skips others correctly
<img width="1447" alt="Screenshot 2023-06-15 at 11 20 11"
src="https://github.com/facebook/react/assets/28902667/d308960a-c172-4422-ba6f-9c0dbcd6f7d5">

Running `yarn test --project devtools ...` without specifying
`reactVersion` now runs all non-gated test cases
<img width="398" alt="Screenshot 2023-06-15 at 12 25 12"
src="https://github.com/facebook/react/assets/28902667/2b329634-0efd-4c4c-b460-889696bbc9e1">

Running `yarn test --project devtools ...` with specifying
`reactVersion` (to `17` in this example) now includes only gated tests
<img width="414" alt="Screenshot 2023-06-15 at 12 26 31"
src="https://github.com/facebook/react/assets/28902667/a702c27e-4c35-4b12-834c-e5bb06728997">
2023-06-22 09:33:05 +01:00
Ruslan Lesiutin
6c84b505c7 fix[devtools/standalone]: update webpack configurations (#26963)
## Summary
Overlooked when was working on
https://github.com/facebook/react/pull/26887.

- Added `webpack` packages as dev dependencies to `react-devtools-core`,
because it calls webpack to build
- Added `process` package as dev dependency, because it is injected with
`ProvidePlugin` (otherwise fails with Safari usage)
- Updated rule for sourcemaps
- Listed required externals for `standalone` build

Tested on RN application & Safari
2023-06-22 08:55:20 +01:00
Ruslan Lesiutin
794b770dbd fix[devtools]: check if fiber is unmounted before trying to highlight (#26983)
For React Native environment, we sometimes spam the console with
warnings `"Could not find Fiber with id ..."`.

This is an attempt to fix this or at least reduce the amount of such
potential warnings being thrown.

Now checking if fiber is already unnmounted before trying to get native
nodes for fiber. This might happen if you try to inspect an element in
DevTools, but at the time when event has been received, the element was
already unmounted.
2023-06-22 08:51:24 +01:00
Tianyu Yao
254cbdbd6d Add a temporary internal option to disable double useEffect in legacy strict mode (#26914)
<!--
  Thanks for submitting a pull request!
We appreciate you spending the time to work on these changes. Please
provide enough information so that others can review your pull request.
The three fields below are mandatory.

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

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

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

## Summary

<!--
Explain the **motivation** for making this change. What existing problem
does the pull request solve?
-->
We are upgrading React 17 codebase to React18, and `StrictMode` has been
great for surfacing potential production bugs on React18 for class
components. There are non-trivial number of test failures caused by
double `useEffect` in StrictMode. To prioritize surfacing and fixing
issues that will break in production now, we need a flag to turn off
double `useEffect` for now in StrictMode temporarily. This is a
Meta-only hack for rolling out `createRoot` and we will fast follow to
remove it and use full strict mode.

## 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.
-->
jest
2023-06-21 11:14:57 -07:00
Ruslan Lesiutin
e3fb7c1de1 feat[devtools]: support x_google_ignoreList source maps extension (#26951)
## Summary
This was originally implemented by Mengdi @mondaychen in
https://github.com/facebook/react/pull/26506.

Because we patch console methods (to append components stack and some
other features), errors in console will include
`react_devtools_backend-....js` in its stack traces. Example:
<img width="763" alt="Screenshot 2023-06-15 at 13 31 49"
src="https://github.com/facebook/react/assets/28902667/fa9c3d26-b6c5-4965-af71-62d100cd806d">

Using https://github.com/mondaychen/devtools-ignore-webpack-plugin to
support [x_google_ignoreList source maps
extension](https://developer.chrome.com/blog/devtools-better-angular-debugging/#the-x_google_ignorelist-source-map-extension).

@mondaychen created a react app, which throws an error via
`console.error`, when user click on the button -
https://3owqsn.csb.app/.

Stack trace with these changes: 
<img width="759" alt="Screenshot 2023-06-14 at 14 26 38"
src="https://github.com/facebook/react/assets/28902667/b118b168-3200-4a47-9718-39fc455ea993">
2023-06-21 12:36:48 +01:00
Sathya Gunasekaran
0897cc8a0f Add failing test for DropMemoCalls failing to DCE dep array
Found this while running Forget on the React tests. 

This isn't a high priority because the ESLint plugin would've caught this. But 
it'd be nice if either our validation rules caught this or if our compiler did 
correctly eliminate the dep array.
2023-06-20 14:58:36 +01:00
Sathya Gunasekaran
2ca614cb4f [playground] Sync playground flags to Store experiment flags 2023-06-23 14:36:56 +05:30
Sathya Gunasekaran
7caa18c4b9 [playground] Parse pragma in playground 2023-06-23 14:36:55 +05:30
Lauren Tan
dfb9e09984 [eslint-plugin][ez] Plugin options are const 2023-06-22 10:18:43 -04:00
Lauren Tan
9c033a481d [eslint-plugin] Only report on InvalidInput errors
Invariants aren't actionable by users, so we can omit reporting them in eslint 
as errors (while continuing to throw in the compiler itself)
2023-06-22 10:18:43 -04:00
Lauren Tan
e7e67f335a Use CompilerError.invariant consistently
This PR updates all current usages of invariant to CompilerError.invariant along 
with any available locs
2023-06-22 10:18:42 -04:00
Lauren Tan
e9faa5b90d SourceLocation can be null 2023-06-22 10:18:42 -04:00
Lauren Tan
3f2b346ba0 Make CompilerError.invariant assert the condition
This allows us to mimic the `invariant` api, which means you can just assert 
that something holds true after execution proceeds to the next line without 
throwing
2023-06-22 10:18:41 -04:00
Lauren Tan
6c425f6b36 Remove codeframe/nodepath options from CompilerError
These were effectively unused since we almost always passed in null when 
creating errors, so remove them and instead pass in a `loc` explicitly. The 
downside is that we no longer will see Babel codeframes in our test fixtures, 
which doesn't seem like a huge loss
2023-06-22 10:18:41 -04:00
Joe Savona
ba75c96077 Fix mutable range validation in PrintHIR
Fixes the mutable range validation in PrintHIR: when we checked the identifier 
scope's range we failed to allow end=start=0 cases which are also valid. 

While I was here, I created a separate assertion pass to check all ranges, that 
way we aren't relying on the printer to validate them. The pass is on for 
playground and tests, but disabled by default so it can't break internal apps.
2023-06-21 16:08:44 -07:00
Joe Savona
fa913b423e Distinguish internal invariant passes from user code validation
Distinguishes between two types of "validation" passes: 

- Passes which assert the validity of the HIR. These remain in HIR/ but are 
renamed "assertFoo". 

- Passes which validate that the user code is correct. These move to 
Validation/.
2023-06-20 15:16:57 -07:00
Joe Savona
bbb5840e73 Handle phi nodes for ValidateFrozenLambdas
Extends ValidateFrozenLambdas to find cases where a mutable lambda flows into a 
phi node and the phi is later frozen.
2023-06-20 15:16:56 -07:00
Joe Savona
6efd1f99d7 Make function name a string not an identifier
Fixes #1751. Function ids can be plain strings, and we can refer to them as 
globals rather than via a local identifier. In addition to the bug from $1751 
this also cleans up an existing todo.
2023-06-20 15:16:55 -07:00
Joe Savona
4a36b83796 Ref validation allows passing refs as props
Updates ValidateNoRefAccessInRender to allow passing refs to JSX, but continue 
disallowing passing ref values (so `ref` is okay but not `ref.current`)
2023-06-20 10:11:56 -07:00
Sebastian Markbåge
d1c8cdae3b Ensure updates are applied when diffInCommitPhase is on (#26977)
When we diffInCommitPhase there's no updatePayload, which caused no
update to be applied.

This is unfortunate because it would've been a lot easier to see this
oversight if we didn't have to support both flags.

I also carified that updateHostComponent is unnecessary in the new flag.
We reuse updateHostComponent for HostSingleton and HostHoistables since
it has a somewhat complex path but that means you have to remember when
editing updateHostComponent that it's not just used for that tag.
Luckily with the new flag, this is actually unnecessary since we just
need to mark it for update if any props have changed and then we diff it
later.
2023-06-19 21:24:53 -04:00
Joe Savona
a9868cc2b1 Fix memoization of lambdas in @enableOptimizeFunctionExpr feature
This is a fix specifically for the `enableOptimizeFunctionExpression` feature 
(disabled by default). I tried running all of our fixtures with that flag on 
everywhere, and this was the only issue. It's actually extracted from another 
fixture which is more complicated, this is a distilled version. There were two 
bugs: 

* DCE was running after LeaveSSA when it needs to run before. Fixing the order 
means code inside the function expression stops getting removed. 

* In the feature flag, context variables share Identifier instances with the 
surrounding code, whereas they are distinct instances without the feature. This 
meant that mutable ranges from inside the function propagated outside the 
function, throwing off our inference. The fix was to reset the ranges of context 
variables after inferring the function expression's effects.
2023-06-16 14:42:19 -07:00
Joe Savona
04f4b50997 Integrate mutable context identifier inference, improve frozen function
inference 

Integrates the new inference to detect definitive mutations of context 
variables. This allows us to more precisely infer mutable function expressions 
and validate that they aren't passed where frozen values are expected.
2023-06-16 14:42:19 -07:00
Joe Savona
a2af8776a4 Add InferMutableContextVariables (unused)
New pass to infer context variables which are definitively mutated, 
distinguishing from context variables which _may_  have been mutated. See the 
code comment on the new pass for more details.
2023-06-16 14:42:18 -07:00
Joe Savona
59a1f2a5b0 AnalyzeFunction: ref values take priority over other mutations
Small tweak necessary for the subsequent PRs, refs and ref values take 
precedence over other mutations when computing the effect type of context 
variables. We always want to record ref access within a function as capture 
(since we have later validation) rather than a mutation. For now this has no 
impact, either order records a Capture. But it allows later diffs to make 
non-ref cases have other effects.
2023-06-16 14:42:17 -07:00
Joe Savona
278c7f56ba ValidateFrozenLambdas: visit terminals
The original version of the code wasn't checking return values. I missed this 
since my examples were passing functions _into_ the return value, as opposed to 
return the functions directly. This revealed some existing test fixtures that 
were technically invalid, but easy to fix by changing the return value.
2023-06-16 14:42:16 -07:00
Joe Savona
1db2619807 InferReferenceEffects: distinguish conditional mutations in HIR
In InferReferenceEffects, locations that are ConditionallyMutate are either 
recorded as a Mutate or Read, which means we lose the distinction btw 
conditional/unconditional mutation in later passes. This PR changes to remember 
that these places were conditionally mutable, used in later analysis.
2023-06-16 14:42:16 -07:00
Joe Savona
19976d5f83 [ez] Real location for function context values 2023-06-16 14:42:15 -07:00
Lauren Tan
f467774487 [babel-plugin][ez] Rename shouldCompile to shouldVisitNode 2023-06-20 12:30:07 -04:00
Lauren Tan
46fa83d854 [eslint-plugin] Disambiguate compiler errors without instanceof
Babel re-emits errors from plugins so the `instanceof` check was no longer 
working
2023-06-20 12:30:07 -04:00
Lauren Tan
2f0ab0ec9d [eslint-plugin] Temporarily disable validateFrozenLambdas 2023-06-20 12:30:06 -04:00
Lauren Tan
98633d10a6 Add a noEmit compiler option
Defaults to false, ie it runs the codegen pass. When enabled it will simply run 
all passes up to codegen and then skip over it. Naming of this option is copied 
from [TypeScript](https://www.typescriptlang.org/tsconfig#noEmit) which has the 
same named option that makes the compiler only perform typechecking. 

I'm adding this option primarily to get around some issues running the eslint 
plugin on Meta code. The plugin would error because Forget would report 
duplicate Babel AST nodes, which I presume would only occur during codegen. It 
should also make it a tiny bit faster to not run codegen, which is a nice plus.
2023-06-20 12:30:06 -04:00
Lauren Tan
79dbf6fc19 [eslint-plugin] Try using HermesParser 2023-06-20 12:30:05 -04:00
Lauren Tan
059365d726 [eslint-plugin] Temporarily only lint on 'use forget'
Temporarily enabling 'use forget' only mode for the linter to address #1751 so 
we can land the stack internally
2023-06-20 12:30:05 -04:00
Lauren Tan
5c0622af39 Add failing test for InferReferenceEffects bug 2023-06-20 12:30:04 -04:00
Lauren Tan
e378eed0f3 [eslint-plugin] Use babel plugin instead of manual traversal
This was causing some issues in the eslint plugin where the babel `hub` wasn't 
defined. afaik the hub is only setup when running the plugin as part of a babel 
pipeline, instead of a manual parse/traversal. We're using some of that infra 
for printing codeframes
2023-06-16 16:23:18 -04:00
Lauren Tan
a90b5371cc [eslint-plugin] babel-plugin-fbt is a dependency 2023-06-16 14:12:35 -04:00
Lauren Tan
daa23543ef [ci] Run all tests
CI will now run tests for all packages
2023-06-16 14:05:45 -04:00
Lauren Tan
0fc4c94ef1 Echo 'no tests' for packages without tests 2023-06-16 14:05:43 -04:00
Lauren Tan
a558b1536a [babel-plugin] buildFunctionDeclaration errors are todos
The existing errors thrown were marked as InvalidInput, which is now considered 
critical. This was causing an error in the sync since we had 2 occurrences of 
the errors being thrown. These are really todos and not invalid code.
2023-06-16 12:18:45 -04:00
Jan Kassens
613e6f5fca [flow] upgrade to 0.209.0 (#26958)
Small update keeping us current with the latest version of Flow.

Flow changelog: https://github.com/facebook/flow/blob/main/Changelog.md
2023-06-16 09:57:03 -04:00
Josh Story
fc929cf4ea [Float][Fizz][Fiber] support imagesrcset and imagesizes for ReactDOM.preload() (#26940)
For float methods the href argument is usually all we need to uniquely
key the request. However when preloading responsive images it is
possible that you may need more than one preload for differing
imagesizes attributes. When using imagesrcset for preloads the href
attribute acts more like a fallback href. For keying purposes the
imagesrcset becomes the primary key conceptually.

This change updates the keying logic for `ReactDOM.preload()` when you
pass `{as: "image"}`

1. If `options.imageSrcSet` is a non-emtpy string the key is defined as
`options.imageSrcSet + options.imageSizes`. The `href` argument is still
required but does not participate in keying.
2. If `options.imageSrcSet` is empty, missing, or an invalid format the
key is defined as the `href`. Changing the `options.imageSizes` does not
affect the key as this option is inert when not using
`options.imageSrcSet`

Additionally, currently there is a bug in webkit (Safari) that causes
preload links to fail to use imageSrcSet and fallback to href even when
the browser will correctly resolve srcset on an `<img>` tag. Because the
drawbacks of preloading the wrong image (href over imagesrcset) in a
modern browser outweight the drawbacks of not preloading anything for
responsive images in browsers that do not support srcset at all we will
omit the `href` attribute whenever `options.imageSrcSet` is provided. We
still require you provide an href since we want to be able to revert
this behavior once all major browsers support it

bug link: https://bugs.webkit.org/show_bug.cgi?id=231150
2023-06-15 14:50:22 -07:00
Josh Story
86acc10f25 [Float] Nonce preload support (#26939)
Some browsers, with some CSP configuration, will not preload a script if
the prelaod link tag does not provide a valid nonce attribute. This
change adds the ability to specify a nonce for `ReactDOM.preload(..., {
as: "script" })`
2023-06-15 13:39:48 -07:00
Lauren Tan
501cf92f1e Unify UnsafeInput and InvalidInput 2023-06-15 15:13:37 -04:00
Lauren Tan
0d01d5f69c [eslint-plugin] Enable validation passes 2023-06-15 14:57:10 -04:00
Lauren Tan
0fdb1e5ac7 [eslint-plugin] Add test for invariants
Turning off this flag makes only critical errors throw, so TODO errors will no 
longer be surfaced by the plugin. The previously failing test for unsupported 
syntax is now valid.
2023-06-15 14:57:07 -04:00
Lauren Tan
87a39e1995 Mark InvalidInput errors as critical 2023-06-15 14:34:49 -04:00
Lauren Tan
b68c409a6b [eslint-plugin] Throw non CompilerErrors 2023-06-15 14:34:46 -04:00
Lauren Tan
fe91cd8ac1 [eslint-plugin] Parse flow 2023-06-15 14:34:43 -04:00
Lauren Tan
c402d8de76 [eslint-plugin] Fall back to context.getSourceCode()
Older versions of eslint use the deprecated method, so add a fallback in the 
event a modern version of eslint isn't available
2023-06-15 12:52:57 -04:00
Lauren Tan
c416fb16ca [make-read-only] Make tsconfig more consistent with other pkgs 2023-06-15 12:52:56 -04:00
Lauren Tan
6810ddbf56 [react-forget-runtime] Compile with typescript 2023-06-15 12:52:55 -04:00
Lauren Tan
b6c1ca9718 [build] yarn bundle:meta builds and uploads all packages
Some changes to our build infra to create a Meta bundle containing all packages. 
Needs corresponding changes in the internal upgrade commands
2023-06-15 12:52:55 -04:00
Joe Savona
aae9b01f91 Test cases for inferring mutability of function expressions (as values)
This PR contains just the test cases from #1717, showing some tricky cases 
around function expression mutability inference.
2023-06-15 09:32:30 -07:00
Ruslan Lesiutin
4ddc019aca chore[devtools]: upgrade to webpack v5 (#26887)
## Summary
- Updated `webpack` (and all related packages) to v5 in
`react-devtools-*` packages.
- I haven't touched any `TODO (Webpack 5)`. Tried to poke it, but each
my attempt failed and parsing hook names feature stopped working. I will
work on this in a separate PR.
- This work is one of prerequisites for updating Firefox extension to
manifests v3

related PRs:
https://github.com/facebook/react/pull/22267
https://github.com/facebook/react/pull/26506

## How did you test this change?
Tested on all surfaces, explicitly checked that parsing hook names
feature still works.
2023-06-14 13:15:52 +01:00
Ruslan Lesiutin
f5c249db8b fix[devtools]: display NaN as string in values (#26947)
## Summary

>Warning: Received NaN for the `children` attribute. If this is
expected, cast the value to a string.

Fixes this warning, when we try to display NaN as NaN in key-value list.
2023-06-14 11:45:30 +01:00
Sebastian Markbåge
a1723e18fd [Flight] Only skip past the end boundary if there is a newline character (#26945)
Follow up to #26932

For regular rows, we're increasing the index by one to skip past the
last trailing newline character which acts a boundary. For length
encoded rows we shouldn't skip an extra byte because it'll leave us
missing one.

This only accidentally worked because this was also the end of the
current chunk which tests don't account for since we're just passing
through the chunks. So I added some noise by splitting and joining the
chunks so that this gets tested.
2023-06-14 00:51:42 -04:00
Josh Story
a7bf5ba614 [Float][Fizz] add crossOrigin support for preloading bootstrap scripts and bootstrap modules (#26942)
The recently merged support for crossorigin in bootstrap scripts did not
implement the functionality for preloading. This adds it

see #26844
2023-06-13 13:59:45 -07:00
Josh Story
7ed6084c39 [Float] use common float types (#26938)
Float types are currently spread out. this moves them to a single place
to ensure we properly handle the public type interface in all three
renderers.

This is a step towards moving the public interface and validation to a
common file shared by all three runtimes. Will also probably change the
function interface to be flatter
2023-06-13 13:30:26 -07:00
Henrique Limas
90229eb925 Add support for 'crossorigin' attribute on bootstrapScripts and bootstrapModules (#26844)
base build ci job failing but this change is unrelated and I think it is just flake with the builds host application
2023-06-13 09:12:10 -07:00
Jack Works
88df88f944 fix: devtools cannot be closed correctly (#25510)
<!--
  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

Fix devtools cannot be shutdown by bridge.shutdown().

<!--
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.
-->
2023-06-13 10:04:38 +01:00
Sebastian Markbåge
db50164dba [Flight] Optimize Large Strings by Not Escaping Them (#26932)
This introduces a Text row (T) which is essentially a string blob and
refactors the parsing to now happen at the binary level.

```
RowID + ":" + "T" + ByteLengthInHex + "," + Text
```

Today, we encode all row data in JSON, which conveniently never has
newline characters and so we use newline as the line terminator. We
can't do that if we pass arbitrary unicode without escaping it. Instead,
we pass the byte length (in hexadecimal) in the leading header for this
row tag followed by a comma.

We could be clever and use fixed or variable-length binary integers for
the row id and length but it's not worth the more difficult
debuggability so we keep these human readable in text.

Before this PR, we used to decode the binary stream into UTF-8 strings
before parsing them. This is inefficient because sometimes the slices
end up having to be copied so it's better to decode it directly into the
format. The follow up to this is also to add support for binary data and
then we can't assume the entire payload is UTF-8 anyway. So this
refactors the parser to parse the rows in binary and then decode the
result into UTF-8. It does add some overhead to decoding on a per row
basis though.

Since we do this, we need to encode the byte length that we want decode
- not the string length. Therefore, this requires clients to receive
binary data and why I had to delete the string option.

It also means that I had to add a way to get the byteLength from a chunk
since they're not always binary. For Web streams it's easy since they're
always typed arrays. For Node streams it's trickier so we use the
byteLength helper which may not be very efficient. Might be worth
eagerly encoding them to UTF8 - perhaps only for this case.
2023-06-12 22:16:47 -04:00
Joe Savona
8fcceb715c Rename feature flag for function expr optimization
This got lost in a rebase, just renaming for clarity.
2023-06-12 15:56:48 -07:00
Joe Savona
a21660de00 Fix calculation of nested function dependencies
We were incorrectly calculating the dependencies of nested lambdas, because the 
"component" scope was incorrectly set to the next closest parent rather than 
outermost React function (component/hook) being compiled.
2023-06-14 14:04:26 -07:00
Sebastian Markbåge
ce6842d8f5 Delete processStringChunk (#26896)
Follow up to #26827.

These can't include binary data and we don't really have any use cases
that really require these to already be strings.

When the stream is encoded inside another protocol - such as HTML we
need a different format that encode binary offsets and binary data.
2023-06-10 16:59:45 -04:00
Ruslan Lesiutin
21a161fa37 refactor[renderer]: expose getInspectorDataForInstance in rendererConfig (#26913)
## Summary
This is required for the case when we have an instance and want to get
inspector data for it. Such case occurs when RN's application being
debugged via React DevTools.

React DevTools sends instance to RN, which then gets all auxiliary data
to highlight some elements. Having `getInspectorDataForInstance` method
exposed makes it possible to easily get current props from fiber, which
then can be used to display some margins & paddings for hovered element
(via props.style).

I see that `getInspectorDataForInstance` is being exported at the top
level of the renderer, but feels like this should also be inside
DevTools global hook, the same way we use it for
[`getInspectorDataForViewAtPoint`](e7d3662904/packages/react-native/Libraries/Inspector/getInspectorDataForViewAtPoint.js).
2023-06-09 10:55:34 +01:00
Joe Savona
a8fff7cc5c Feature to optimize function expressions
This PR adds a new feature which enables additional validation/optimization of 
function expressions, gated by the `enableOptimizeFunctionExpressions` feature 
flag. When disabled, we actually revert the changes earlier in this stack, and 
do all our lowering of function expressions in AnalyzeFunctions. 

When the feature is enabled, we incrementally process function expressions in 
the various compilation stages, eg InferTypes infers into function expressions, 
ConstantPropagation propagates constants into function expressions, etc. Because 
this stage optimizes function expressions, in this mode codegen uses the HIR as 
the source rather than the original babel node. 

The feature is disabled by default so it has no impact on generated code. For 
now i've enabled the feature on just one test to demonstrate constant 
propagation into a function expression.
2023-06-08 18:05:41 -04:00
Joe Savona
4d7d2cf4dc Type inference across function expressions boundaries
Updates InferTypes to perform type inference across function boundaries. 
Specifically InferTypes is now responsible for driving type inference of 
function expressions (rather than deferring to AnalyzeFunctions to infer 
functions), and type inference now traverses into function expressions and 
infers types of free variables taking into account information from the outer 
context. This relies on the fact that identifier ids are consistent across 
function expression boundaries and that all free variables in functions are 
guaranteed to be effectively `const`, since we promote non-const variables used 
in function expressions to context variables.
2023-06-08 14:02:04 -04:00
Joe Savona
5775102b85 InferTypes traverses function expressions 2023-06-08 14:02:04 -04:00
Joe Savona
11d4ff430f ConstantPropagation traverses function expressions 2023-06-08 14:02:03 -04:00
Joe Savona
e39855d251 EliminateRedundantPhi traverses function expressions 2023-06-08 14:02:03 -04:00
Joe Savona
638e45c928 EnterSSA traverses function expressions 2023-06-08 14:02:02 -04:00
Joe Savona
c2c221a452 MergeConsecutiveBlocks traverses function expressions
Currently the process of lowering function expression bodies is deferred until 
AnalyzeFunctions. However, per the motivation of the previous PR, we'd like to 
be able to perform inference across function expression boundaries. To do that 
we need to use consistent identifier ids across function expression boundaries. 
This requires SSA conversion of function expressions at the same time as we 
enter SSA. 

To start, this PR moves MergeConsecutiveBlocks for function expressions into 
that phase.
2023-06-08 14:02:02 -04:00
Lauren Tan
3673272ca4 [eslint-plugin] Add basic test for unsupported syntax
Kinda works?
2023-06-07 15:41:22 -04:00
Mofei Zhang
246936ca57 [prettier] add expected prettierrc file 2023-06-08 14:32:22 -04:00
Mofei Zhang
166f47a41e [snap] Fix snap ignored paths 2023-06-08 14:32:22 -04:00
Joe Savona
8192cd253d Fix missing memoization of scope-less variable being reassigned 2023-06-07 22:15:59 -04:00
Lauren Tan
5673672ff9 Move playground to apps
Generally we should reserve the `packages` directory for packages that 

are needed to run the compiler, while `apps` is for frontends that might 

make use of the compiler (and optionally, related packages)
2023-06-07 14:40:42 -04:00
BIKI DAS
910045696b Fix:- Fixed dev tools inspect mode on Shadow dom (#26888)
Fixes #26200 

### PR explanation

I tried to induce the change by the `event.composed` to check whether
the event was created in a ShadowRoot, And replaced `pointerOver` with
`pointerMove`, pointerOver event did not fired correctly

Before PR:-


https://github.com/facebook/react/assets/72331432/67a33dcd-447f-4c68-9c3c-ad954baddeb8

After PR:-


https://github.com/facebook/react/assets/72331432/9f986ff2-785f-4cba-a504-44f82ea9fc5a

---------

Co-authored-by: Biki das <bikidas@Bikis-MacBook-Pro.local>
2023-06-07 16:38:38 +01:00
Joe Savona
bf631a0bb6 Change rules for context variable promotion
This PR updates the conditions for which variables are promoted to context 
variables. 

The previous rule was to promote any variable where the variable was reassigned 
in some function expression other than the function that declared the variable. 
Notably, this meant that we did not use context variables for variables which 
were captured in a function expression, but reassigned _outside_ a function 
expression. 

The new rule is more consistent: we promote any variable which is a) reassigned 
somewhere and b) referenced in some function expression outside of their 
declaring function. The implementation builds two sets of identifiers, one for 
each criteria, then takes the union of these two sets. 

## Motivation 

The motivation for this change is to unblock additional validations and 
optimizations of function expressions. It's currently difficult to translate 
metadata that we infer about identifiers outside of a function expression into 
metadata about the identifiers within a function expression — for example to 
infer types within function expression bodies based on type information outside, 
propagate constants into functions, infer reference effects, etc. 

After this change, the only free variables inside function expressions will be 
variables that are effectively `const` - never reassigned anywhere. Thus it will 
be safe to renumber those identifiers to match the outer context (during 
EnterSSA), making it trivial to map metadata from outside the function into the 
function. 

This change also more closely models the runtime representation — any variable 
referenced in a function, and reassigned somewhere, would have to be compiled 
(ie in a JS engine) to use a context variable.
2023-06-05 22:11:08 -04:00
Lauren Tan
4e22fa6451 Try to fix test262 in ci 2023-06-06 15:25:20 -04:00
Lauren Tan
5ebb7f1a8e Try to compile with Forget in eslint plugin
Nothing interesting for now, but it does seem to successfully run the compiler
2023-06-06 10:56:21 -04:00
Lauren Tan
359df9e85c Enable TypeScript in eslint-plugin-react-forget 2023-06-06 10:56:21 -04:00
Lauren Tan
5c1faa901e Add workspace command to run all tests 2023-06-06 10:56:20 -04:00
Lauren Tan
cd56c55e87 Basic noop rule for ReactForgetDiagnostics 2023-06-06 10:56:20 -04:00
Lauren Tan
f82de29e73 Bootstrap new eslint plugin
Just scaffolds a new eslint plugin
2023-06-06 10:56:20 -04:00
Joe Savona
04d6bad1ae [ez] Update completed todo comment
lol at how out of date this comment is :-)
2023-06-05 16:46:38 -04:00
Joe Savona
39d837d918 Update fixtures from workspace rebase
I updated these yesterday, looks like they got added back in the workspace PR. 
Rebases are hard, all good!
2023-06-05 14:16:14 -04:00
Joe Savona
66ca1c75cb Fix dropped constant declaration bug 2023-06-05 14:08:29 -04:00
Joe Savona
ad32811b64 [RFC] Improve validation against ref access in render
The goal of this PR is to improve ValidateNoRefAccessInRender to find function 
expressions which a) access refs and b) may be called during render. Currently 
we always allow ref access in any function expression, but that's obviously 
optimistic. 

For the approach, the observation is that we already have a system that tells us 
whether a function may get called — mutable range inference. So long as we 
consider a function "mutable", we'll infer a range for it, but the problem is 
that we don't currently view functions which depend on refs to be mutable. So 
here I'm doing ~~sort of~~ a hack to force function deps on refs to be treated 
as Effect.Capture. This is enough for the function to be considered mutable, for 
a mutable range to be assigned, and for us to detect that during ref validation. 

I don't love the hack, i'm open to other ideas!
2023-06-05 14:08:26 -04:00
Mofei Zhang
b160ee8522 [tests] Tests and patch for context variables
--- 

- [patch] Find context variables within FunctionDeclarations (previously 
missing) 

- [todo] Need to fix non-allocating values / variables being DCE'd 

One approach is to label everything referenced by a lambda as context variables. 
I couldn't come up with other examples that break without this change, so I 
wonder if something lighter / hackier works just as well. (My only hesitation is 
that we may end up losing out on potential optimizations for everything aliased 
to these variables).
2023-06-05 15:04:46 -04:00
Mofei Zhang
6d1d05ff91 [runtime] Update makeReadOnly runtime
--- 

(wip, waiting for feedback on workplace post) 

- remove calls to `isInROMode`, as we want to log all mutations after 'freezing' 
a value (both within and outside of render cycle) 

- add `source` parameter -- this is the function name of the parent component / 
hook
2023-06-05 14:46:59 -04:00
Mofei Zhang
5ba0a03e00 [config] Clean up codegen imports and gating
- Gating checks for debugging / profiling can be moved to within the 
instrumentation or makeReadOnly functions. This simplifies codegen and reduces 
code bloat. 

- Warn if importing conflicting identifiers 

- Aggregate imports from the same source
2023-06-05 14:46:59 -04:00
Mofei Zhang
a65e9cd1f1 [devx] emit calls to makeReadOnly for debugging
--- 

Emit calls to makeReadOnly for memoized values. 

```js 

function MyComponent() { 

let x; 

if (c_0) { 

x = // ... (recompute x) 

$[0] = __DEV__ ? makeReadOnly(x, "MyComponent") : x; 

} else { 

x = $[0] 

} 

} 

``` 

- import source / specifier should be configurable, as 

- we'll likely want to add gk gating to `makeReadOnly` itself to reduce codesize 
bloat 

- each Forget project needs different logging and filter configurations 

- codegen function name as an argument for easier debugging 

- only freeze memoized outputs
2023-06-05 14:46:58 -04:00
Lauren Tan
40d1459115 Scaffold workspaces
![image](https://github.com/facebook/react-forget/assets/1390709/bb27e33f-6a88-4b71-8ce2-aeb8db0372f7) 

This is an attempt to scaffold yarn workspaces into our repo with as minimal as 
possible changes to our current setup and directory structure. Essentially this 
PR moves current `src` into `packages/babel-plugin-react-forget` as a first step 
to keep everything working. Later on when we're ready we can split out a 
`react-compiler` package that is decoupled from Babel, but it's too early for 
that now
2023-06-05 13:35:39 -04:00
Joe Savona
3744930728 Fix last(?) order of evaluation bug
Not to get ahead of myself (sorry i had to), but i think this is the last order 
of evaluation bug. At least it's the last one we know of[1]. Per the previous 
PR, the issue is that constant propagation can copy the last value of a sequence 
expression to where the sequence is used, leaving the original sequence 
expression out of order after other instructions are moved around. We fix that 
here by explicitly skipping constant propagation for the last value of a 
sequence block. 

[1] There are some places where we _would_ have evaluation order bugs if we 
allowed arbitrary expressions, but we explicitly limit the expressions we allow 
in those places. For the curious: switch test case values and destructuring 
default values.
2023-06-04 21:41:27 -04:00
Joe Savona
1e0eb25cd0 Use sequence terminal, fix most remaining order-of-evaluation bugs
Changes the lowering for sequence expressions to use the new terminal. When 
converting to a ReactiveFunction, we convert these terminals into 
ReactiveSequenceValues, which nests the instructions and preserves order of 
evaluation in the output. 

The only catch is constant propagation — constant propagation breaks 
order-of-evaluation because it can effectively copy the final value of a 
sequence elsewhere, leaving the original sequence in the wrong place. I'll 
address that in a follow-up.
2023-06-04 21:26:01 -04:00
Joe Savona
cd115ec128 Scaffold for sequence terminal
I realized that we can use our value block system to fix _most_ of the remaining 
order-of-evaluation issues we had with sequence expressions. This PR adds a new 
SequenceTerminal to HIR; there is already a ReactiveFunction equivalent 
(ReactiveSequenceValue) that the next PR will convert this terminal into.
2023-06-04 21:25:59 -04:00
Joe Savona
e410815aeb Infer more primitive types
Handles three more cases: 

* Template literals 

* deletion (property/computed) 

* type casts 

Only the latter has an observable impact, though i added tests for deletion just 
in case and found a bug. For type casts, they're reasonably common internally 
for fixmes, so this PR will help to ensure we don't drop type information just 
because of a cast.
2023-06-04 20:27:24 -04:00
Joe Savona
084edadaa1 Distinguish error fixtures for invalid code
Renames some error fixtures for clarity, "error.invalid-*" are fixtures that are 
expected to fail for invalid input, where other "error.*" fixtures are basically 
todos. While i was here i clarified the error messages for invalid useMemo 
callbacks, and changes the error severity from Invariant to InvalidInput.
2023-06-04 11:41:42 -07:00
Joe Savona
e41a8d6a1e Validate destructuring assignment to globals
Fixes one more category of bug. For assignment expressions, we validating 
against redeclaring a global variable when the assignment target was an 
identifier, but not when the global was reassigned via destructuring. This PR 
adds a `lowerIdentifierForAssignment()` helper and uses it for assignment of all 
identifier variants, including destructuring.
2023-06-04 11:29:55 -07:00
Joe Savona
2ae3592d29 Fix/review bug repros, mark fixed
I reviewed the test cases we have marked as bugs ("_bug.*") and realized that 
several of them are already fixed — woohoo! Then one wasn't fixed _yet_: our 
type inference loses track of refs if you stash them inside an object/array. But 
that's why I added the ValidateNoRefAccessInRender pass, which i've updated to 
detect and reject these invalid cases. There are now only a few bugs left (more 
fixes coming).
2023-06-04 11:08:54 -07:00
Sebastian Markbåge
e6fae308e9 Remove XHR support from Flight (#26827)
We currently support passing an XHR request to Flight for broader compat
and possibly better perf than `fetch()`. However, it's a little tricky
because ideally the RSC protocol is really meant to support binary data
too. XHR does support binary but it doesn't support it while also
streaming.

We could maybe support this only when you know it's going to be only
text streams but it has some limitations in how we can encode separators
if we can't use binary.

Nobody is really asking for this so we might as well delete it.
2023-06-03 16:03:11 -04:00
Sebastian Markbåge
f181ba8aa6 [Flight] Add bundler-less version of RSC using plain ESM (#26889)
This isn't really meant to be actually used, there are many issues with
this approach, but it shows the capabilities as a proof-of-concept.

It's a new reference implementation package `react-server-dom-esm` as
well as a fixture in `fixtures/flight-esm` (fork of `fixtures/flight`).
This works pretty much the same as pieces we already have in the Webpack
implementation but instead of loading modules using Webpack on the
client it uses native browser ESM.

To really show it off, I don't use any JSX in the fixture and so it also
doesn't use Babel or any compilation of the files.

This works because we don't actually bundle the server in the reference
implementation in the first place. We instead use [Node.js
Loaders](https://nodejs.org/api/esm.html#loaders) to intercept files
that contain `"use client"` and `"use server"` and replace them. There's
a simple check for those exact bytes, and no parsing, so this is very
fast.

Since the client isn't actually bundled, there's no module map needed.
We can just send the file path to the file we want to load in the RSC
payload for client references.

Since the existing reference implementation for Node.js already used ESM
to load modules on the server, that all works the same, including Server
Actions. No bundling.

There is one case that isn't implemented here. Importing a `"use
server"` file from a Client Component. We don't have that implemented in
the Webpack reference implementation neither - only in Next.js atm. In
Webpack it would be implemented as a Webpack loader.

There are a few ways this can be implemented without a bundler:

- We can intercept the request from the browser importing this file in
the HTTP server, and do a quick scan for `"use server"` in the file and
replace it just like we do with loaders in Node.js. This is effectively
how Vite works and likely how anyone using this technique would have to
support JSX anyway.
- We can use native browser "loaders" once that's eventually available
in the same way as in Node.js.
- We can generate import maps for each file and replace it with a
pointer to a placeholder file. This requires scanning these ahead of
time which defeats the purposes.

Another case that's not implemented is the inline `"use server"` closure
in a Server Component. That would require the existing loader to be a
bit smarter but would still only "compile" files that contains those
bytes in the fast path check. This would also happen in the loader that
already exists so wouldn't do anything substantially different than what
we currently have here.
2023-06-03 15:58:24 -04:00
Lauren Tan
6d6518161a Cleanup packages directory
Prepare to move to a yarn workspaces setup
2023-06-02 13:06:36 -04:00
Lauren Tan
479ef4045b Move entrypoint into its own directory 2023-06-02 13:06:35 -04:00
Lauren Tan
2eded946f8 Make CompilerEntrypoint a little more generic
These are still quite Babel specific, but the interface is slightly more 
generic: CompilerEntrypoint takes a non-Babel specific CompilerPass as an 
argument instead of passing Babel's PluginPass directly. 

In the future we can consider lowering the whole Program into HIR but that 
involves a significant lift in our representation and a small amount of new 
syntax to support (eg import statements), so this PR is the extent of this stack 
for now
2023-06-02 13:06:35 -04:00
Lauren Tan
b98ee34f45 Delegate BabelPlugin to CompilerEntrypoint
Moves the existing logic in BabelPlugin to its own files
2023-06-02 13:06:34 -04:00
Lauren Tan
9077ac1f27 Copy files from src/Babel to src/ 2023-06-02 13:06:34 -04:00
Josh Story
e1ad4aa361 [Fizz][Float] stop automatically preloading scripts that are not script resources (#26877)
Currently we preload all scripts that are not hoisted. One of the
original reasons for this is we stopped SSR rendering async scripts that
had an onLoad/onError because we needed to be able to distinguish
between Float scripts and non-Float scripts during hydration. Hydration
has been refactored a bit and we can not get around this limitation so
we can just emit the async script in place. However, sync and defer
scripts are also preloaded. While this is sometimes desirable it is not
universally so and there are issues with conveying priority properly
(see fetchpriority) so with this change we remove the automatic
preloading of non-Float scripts altogether.

For this change to make sense we also need to emit async scripts with
loading handlers during SSR. we previously only preloaded them during
SSR because it was necessary to keep async scripts as unambiguously
resources when hydrating. One ancillary benefit was that load handlers
would always fire b/c there was no chance the script would run before
hydration. With this change we go back to having the ability to have
load handlers fired before hydration. This is already a problem with
images and we don't have a generalized solution for it however our
likely approach to this sort of thing where you need to wait for a
script to load is to use something akin to `importScripts()` rather than
rendering a script with onLoad.
2023-06-01 13:34:36 -07:00
Josh Story
5fb2c15a89 [Fizz][Float] stop preloading stylesheets that are not stylesheet resources (#26873)
We previously preloaded stylesheets that were rendered in Fizz. The idea
was we'd get a headstart fetching these resources since we know they are
going to be rendered. However to really be effective non-float
stylesheets need to rendered in the head and the preload here is not
helpful and potentially hurtful to perf in a minor way. This change
removes this functionality to make the code smaller and simpler
2023-06-01 13:23:53 -07:00
Josh Story
042d8f606c [Float] support fetchpriority on ReactDOM.preload() and ReactDOM.preinit() (#26880)
exposes fetchPriority as an option for `ReactDOM.preload()` and
`ReactDOM.preinit()`

the typings should be `'high' | 'low' | 'auto'`
2023-06-01 13:10:55 -07:00
Tianyu Yao
811022232e Always trigger componentWillUnmount in StrictMode (#26842)
<!--
  Thanks for submitting a pull request!
We appreciate you spending the time to work on these changes. Please
provide enough information so that others can review your pull request.
The three fields below are mandatory.

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

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

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

## Summary

<!--
Explain the **motivation** for making this change. What existing problem
does the pull request solve?
-->
In StrictMode, React currently only triggers `componentWillUnmount` if
`componentDidMount` is defined. This would miss detecting issues like
initializing resources in constructor or componentWillMount, for
example:
```
class Component {
  constructor() {
     this._subscriptions = new Subscriptions();
  }
  componentWillUnmount() {
     this._subscriptions.reset();
  } 
}
``` 

The PR makes `componentWillUnmount` always run in StrictMode.


## 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.
-->
`yarn test ci`
2023-06-01 10:34:31 -07:00
Ricky
018c58c9c6 Clean up enableSyncDefaultUpdates flag a bit (#26858)
## Overview

Does a few things:
- Renames `enableSyncDefaultUpdates` to
`forceConcurrentByDefaultForTesting`
- Changes the way it's used so it's dead-code eliminated separate from
`allowConcurrentByDefault`
- Deletes a bunch of the gated code

The gates that are deleted are unnecessary now. We were keeping them
when we originally thought we would come back to being concurrent by
default. But we've shifted and now sync-by default is the desired
behavior long term, so there's no need to keep all these forked tests
around.

I'll follow up to delete more of the forked behavior if possible.
Ideally we wouldn't need this flag even if we're still using
`allowConcurrentByDefault`.
2023-06-01 09:24:56 -04:00
Josh Story
ae31d2ea3c [Fizz] preload bootstrapModules (#26754)
stacked on #26753 

Adds support for preloading bootstrapModules. We don't yet support
modules in Float's public interface but this implementation should be
compatible with what we do when we add it.
2023-05-31 16:48:27 -07:00
Josh Story
b864ad4397 [Fizz] preload bootstrapScripts (#26753)
This PR adds a preload for bootstrapScripts. preloads are captured
synchronously when you create a new Request and as such the normal logic
to check if a preload already exists is skipped.
2023-05-31 16:25:35 -07:00
Joe Savona
7fddf42d06 [ez] Hooks dont escape, their args do 2023-05-31 16:05:07 -07:00
Joe Savona
0ae37f1568 Treat setState as non-reactive
Updates PruneNonReactiveDependencies to treat setState functions as 
non-reactive, since we know they have a stable identity. This is based on type 
inference and our recently added definitions for useState and its return type, 
so it's conservative and will only work when our inference can prove that the 
scope dependency has the SetState type. 

Note that this approach is simple and has limitations, notably the fact that the 
setState is non-reactive doesn't propagate. But it's simple, trivially correct, 
and already improves codegen somewhat, so i figured it's worth landing for now. 

## Test Plan 

Tested on internal app
2023-05-31 14:29:31 -07:00
Joe Savona
9c453ad26f Validate frozen lambdas are actually frozen
Adds validation to reject freezing mutable lambdas, since lambdas cannot _be_ 
frozen, they're either frozen or not. Example invalid code: 

```javascript 

function Component(props) { 

const x = {value: ""}; 

const onChange = (e) => { 

// MUTATION!!!!! 

x.value = e.target.value; 

setX(x); 

}; 

return <input value={x.value} onChange={onChange} />; 

} 

``` 

Note that there is a separate issue in which we are not detecting lambdas that 
would definitely modify immutable values. We may need to distinguish 
ConditionallyCapture (captures if the value is mutable, otherwise readonly) from 
Capture (definitely mutates) in order to make that case work. But already this 
validation helps prevent some invalid code.
2023-05-31 14:03:02 -07:00
Joe Savona
8e341294d0 [be] Upgrade to TypeScript 5.1
The functional changes in 5.1 don't seem that compelling but there are some perf 
improvements, supposedly.
2023-06-01 13:23:09 -07:00
Josh Story
e1e68b9f7f [Fiber][Float] preinitialized stylesheets should support integrity option (#26881)
preinitialized stylesheets did not render the integrity option on the
client implementation of Float. This was an oversight.
2023-05-31 13:48:19 -07:00
Joe Savona
a5a86c302a Validate against ref access in render 2023-05-31 09:38:28 -07:00
Joe Savona
af94b075c0 Option to disable memoization
Adds a `removeAllMemoization` flag that runs the entire compiler pipeline but 
strips out all memoization. The intent is to be able to compare (in limited 
use-cases) the performance of an existing app with all memoization removed, vs 
the performance with manual memoization, vs the performance with Forget enabled. 

In terms of how this works: we already strip out useMemo/useCallback since 
Forget is more accurate. The new option adds an extra pass that strips out all 
reactive scopes. Collectively this leaves ~zero memoization within components 
(this does leave React.memo, but close enough).
2023-05-31 08:03:36 -07:00
Sathya Gunasekaran
793b69243f [hir] Track context refs when inferring reactive ids 2023-05-31 15:37:39 +01:00
Sathya Gunasekaran
b447c93edc [test] Add failing test for lambda turning value reactive 2023-05-31 15:37:35 +01:00
Sathya Gunasekaran
2c8f6888e6 [hir] Failing test for adding ref as dep incorrectly 2023-05-31 13:55:00 +01:00
Sathya Gunasekaran
91f41f5ee3 [hir] Don't track ref value as a valid dep 2023-05-31 13:54:59 +01:00
Sathya Gunasekaran
bedf0cc6c5 [hir] Don't track ref.current as a valid dep 2023-05-31 13:54:58 +01:00
Josh Story
1cea384480 [Fiber] retain scripts on clearContainer and clearSingleton (#26871)
clearContainer and clearSingleton both assumed scripts could be safely
removed from the DOM because normally once a script has been inserted
into the DOM it is executable and removing it, even synchronously, will
not prevent it from running. However There is an edge case in a couple
browsers (Chrome at least) where during HTML streaming if a script is
opened and not yet closed the script will be inserted into the document
but not yet executed. If the script is removed from the document before
the end tag is parsed then the script will not run. This change causes
clearContainer and clearSingleton to retain script elements. This is
generally thought to be safe because if we are calling these methods we
are no longer hydrating the container or the singleton and the scripts
execution will happen regardless.
2023-05-30 13:12:56 -07:00
Sathya Gunasekaran
1d536af4f7 [hir] Refactor checkValidDependencyId to accept a dep 2023-05-30 13:44:30 +01:00
Mofei Zhang
fc13557d30 [tests] remove jest fixture tests
--- 

Remove jest fixture tests in favor of snap runner. Main reasons: 

- maintaining feature flags and compatible behavior required syncing all changes 
to 3 files (`generateTestsFromFixtures`, `compiler-test`, and `compiler-worker`) 

- jest snapshot test file causes rebase conflicts on most rebases 

- speed 🙌 

$ time yarn test compiler-test 

(the extra test here is `has a consistent extension for input fixtures`) 

``` 

Test Suites: 1 passed, 1 total 

Tests:       37 skipped, 480 passed, 517 total 

Snapshots:   479 passed, 479 total 

Time:        27.668 s 

Ran all test suites matching /compiler-test/i. 

  Done in 43.18s. 

yarn test compiler-test  57.05s user 3.85s system 139% cpu 43.546 total 

``` 

$ time yarn snap 

``` 

478 Tests, 478 Passed, 0 Failed 

  Done in 13.12s. 

yarn snap  53.96s user 9.35s system 468% cpu 13.518 total 

``` 

Jest and snap should have the same set of features: 

- report test failures via exit status (used by Git Actions) 

- watch mode 

- breakpoints + `debugger` statements 

- note that `--sync` is not required for this 

- skip `todo.` prefixed fixtures 

- fixtures in nested directories e.g. `rules-of-hooks/testname.js` 

- filter mode (via editing `testfilter.txt`) 

- filter + debug mode 

(1) edit `testfilter.txt` to filter out all but one test 

(2) add `@debug` pragma to the first line of the test 

testfilter.txt 

```js 

// @only 

testfixture_basename1 

testfixture_basename2 

```
2023-05-26 13:18:38 -04:00
Mofei Zhang
71c9743e38 [snap] Fix vscode debugger attaching to forked proc
Turns out I just forgot to forward `process.env` when forking 😅 

`debugger` statements and breakpoints should work with both `--sync` and 
`--no-sync` (default) modes
2023-05-26 13:18:37 -04:00
Sebastian Markbåge
a1f97589fd Compare name when hydrating hidden fields to filter out extra form action fields (#26846)
This solves an issue where if you inject a hidden field in the beginning
of the form, we might mistakenly hydrate the injected one that was part
of an action.

I'm not too happy about how specific this becomes. It's similar to Float
but in general we don't do this deep comparison.

See https://github.com/vercel/next.js/issues/50087
2023-05-26 12:54:01 -04:00
Ricky
0210f0b082 Update enableSyncDefaultUpdates for www (#26857)
If this is false, it dead code eliminates the path to use the root flag.
Will follow up to clean this up.
2023-05-25 21:33:07 -04:00
Andrew Clark
4daccade04 Remove temporary CircleCI workaround (#26855)
There was a CircleCI bug that prevented the sizebot job from accessing
the artifacts API. I had added a temporary workaround to pull from a
mirror instead. This seems to have been fixed, so I can remove the
workaround.
2023-05-25 13:38:39 -04:00
Jan Kassens
18dedde6a7 [flow] upgrade to 0.206.0 (#26850)
Small upgrade. The one impact was deprecation of `$Shape` where it seems
like we can just use a plain object with optional key.
2023-05-25 13:37:31 -04:00
Jan Kassens
9a72e62271 run SchedulerFeatureFlags with variant flags again (#26851)
With df12d7eac4 I accidentally made it so
that tests aren't run with the 2 variant modes for most
SchedulerFeatureFlags anymore. This fixes it with the same approach as
ee4233bdbc.

Test Plan:
Run and notice the boolean flags follow the variant:
```
yarn test-www --variant=true
yarn test-www --variant=false
```
2023-05-25 10:38:33 -04:00
Ricky
ee4233bdbc Move enableSyncDefaultUpdates to test config (#26847) 2023-05-24 18:25:30 -04:00
Samuel Susla
6fc3333b68 Add $FlowFixMe to fix React Native DiffTrain (#26841) 2023-05-24 17:42:16 +01:00
Joe Savona
99257aa430 Enable more flags on playground 2023-05-23 16:55:10 -07:00
Joe Savona
91dcf24e67 Add test case for invalid lambdas
This is the example we discussed in our design sync. 

```javascript 

function Component(props) { 

const [x, setX] = useState({ value: "" }); 

const onChange = (e) => { 

// INVALID! should use copy-on-write and pass the new value 

x.value = e.target.value; 

setX(x); 

}; 

return <input value={x.value} onChange={onChange} />; 

} 

``` 

Here `onChange` is a mutable lambda, and it should be invalid to pass a mutable 
lambda where a frozen value is expected. This is because unlike other value 
types, you cannot freeze a lambda — the only choice is to not call it at all. 

Note that there is a harder case to catch: 

```js 

function Component(props) { 

const [x, setX] = useState({ value: "" }); 

const onChange = (e) => { 

// INVALID! should use copy-on-write and pass the new value 

x.value = e.target.value; 

setX(x); 

}; 

const x = constructAValueThatMaybeAliasesItsInput(onChange); 

return <input value={x.value} onChange={x.maybeGetTheLambdaBack()} />; 

} 

``` 

This case demonstrates how mutable lambdas can be captured and then accessed 
later — the analysis to catch this case is more sophisticated bc it involves 
inferring that `x` aliases a mutable lambda. But we also can't be sure that `x` 
does alias the lambda, so disallowing this code could prevent a lot of valid 
code from compiling. My hypothesis is that we should start with at least 
validating the example at the top, while allowing the second case for now.
2023-05-25 16:08:10 -07:00
Joe Savona
edbb6e2bdb Test case for Array.push on frozen array
Just making sure that we reject this
2023-05-25 16:00:35 -07:00
Joe Savona
3381ce7ea8 Array.prototype.join
Trivial
2023-05-25 15:57:09 -07:00
Joe Savona
8be5423e3b Type Array.prototype.map/filter
We can now type `Array.prototype.{map,filter}`: 

* The callee is ConditionallyMutable because, although the array itself is not 
modified, its items flow into the lambda and may be modified there. 

* The argument is ConditionallyMutable because it accepts both mutable and 
immutable lambdas. Mutate would disallow immutable lambdas (wrong), while Read 
would be incorrect for mutable lambdas since calling them triggers mutation.
2023-05-25 14:50:14 -07:00
Joe Savona
75a1972584 More tests for effect enforcement
Adds test cases to ensure we're correctly inferring mutative builtin operations 
— property store, computed property store, property deletion, and computed 
property deletion — as definite mutation and that we're rejecting inputs where 
these operations are used on immutable/frozen values.
2023-05-25 14:33:02 -07:00
Joe Savona
9766e19805 Add Effect.Mutate for known mutation
Adds back `Effect.Mutate`, and changes so that `Effect.ConditionallyMutate` 
never rejects frozen/immutable values, while `Effect.Mutate` _always_ rejects 
frozen/immutable values.
2023-05-25 13:54:35 -07:00
Joe Savona
40cf400f72 Rename Effect.Mutate -> ConditionallyMutate
We currently use `Effect.Mutate` both for places that _may_ mutate (ie untyped 
function calls) and for places that have known mutation (typed function calls, 
or operations like `delete x.y`). We then use a separate mechanism to decide 
whether to reject the input, with some call paths checking the effect and others 
not. 

This stack refactors this logic in InferReferenceEffects per our discussion, so 
that `Effect.ConditionallyMutate` is for "may or may not mutate" either because 
we're not 100% sure (untyped function) or because the mutation depends on the 
operand (ie, a callback arg that will be invoked and thus will mutate if the 
lambda is mutable, not mutate if the lambda is immutable). Later diffs add back 
`Effect.Mutate` as "definitely 100% mutating".
2023-05-25 13:41:09 -07:00
Joe Savona
37d044763b Define types for useState/useRef
Defines 4 new types: 

* Return type of `useState()`, which has properties "0" and "1" to allow us to 
infer the types when destructuring 

* Type of useState() set state function 

* Return type of `useRef()` so we know what is a ref 

* Type of ref.current, so we know what is a ref *value* 

Example: 

<img width="1670" alt="Screenshot 2023-05-24 at 9 59 37 AM" 
src="https://github.com/facebook/react-forget/assets/6425824/3ee7d04a-fda3-4b7b-89b7-d205d9a6fd0d">
2023-05-24 09:54:10 -07:00
Joe Savona
c87a1916f4 Infer property types for destructuring 2023-05-24 09:54:07 -07:00
Mofei Zhang
ecc730c587 [FeatureFlag] Toggle enableTreatHooksAsFunctions default to true
--- 

Toggle default to true, since this should be a no-op refactor. 

Tests: 

- test fixtures 

- ran on Store + - and saw no difference in compiled output 

- [diff](P744101621) with 
`enableTreatHooksAsFunctions=false` 

- [diff](P744105565) with 
`enableTreatHooksAsFunctions=true`
2023-05-23 16:11:38 -04:00
Mofei Zhang
08a8891245 Test: unknown hooks should not assert effects 2023-05-23 13:55:12 -04:00
Mofei Zhang
b76ee1ab32 [types] Consolidate Hook and Function types: Hooks are functions 2023-05-23 13:55:10 -04:00
Yen-Wei Liu
535c038d15 Update preload links to support nonce and fetchpriority (#26826)
Currently when React generates rel=preload link tags for script/stylesheet resources, it will not carryover nonce and fetchpriority values if specified on the original elements.

This change ensures that the preload links use the nonce and fetchPriority values if they were specified.
2023-05-22 22:56:17 -04:00
Mofei Zhang
47e9a2b8a5 [FeatureFlag] add enableTreatHooksAsFunctions 2023-05-22 19:37:53 -04:00
Mofei Zhang
19cf39f50b [effects] Track return ValueKind for function signatures 2023-05-22 19:37:50 -04:00
Joe Savona
d456e4a78c Memoize based on inferred return type, not signature 2023-05-22 09:20:16 -07:00
Dennis Moradkhani
4b877b6c66 Updated copyright text to Copyright (c) Meta Platforms, Inc. and its … (#26830)
…affiliates.

## Summary

There were 8 different places where the copyright comment was wrong.
Rewrote from "Copyright (c) Facebook, Inc. and its affiliates." to
"Copyright (c) Meta Platforms, Inc. and its affiliates."

## How did you test this change?
No code was changed. Comment was still a comment after changes.

Co-authored-by: Dennis Moradkhani <denmo530@student.liu.se>
2023-05-19 17:52:17 -07:00
Sanket Singh
7bd330e0b0 Updated Copyright comment from Facebook to Meta (#26833)
## Summary
Changed the comment in react/packages/react
/react.shared-subset.js saying 
```
Copyright (c) Facebook, Inc. and affiliates ..
```
To 
```
Copyright (c) Meta Platforms, Inc. and affiliates ..
```
as raised in the following issues:
https://github.com/facebook/react/issues/26829

Files Changed: 
react/packages/react/react.shared-subset.js

## How did you test this change?

Tests Required: No
2023-05-19 17:51:44 -07:00
Joe Savona
4ce22ebcfe Option to assume hooks follow the rules
Adds a new feature flag which tells the compiler to assume that hooks follow the 
Rules of React. Specifically, the idea that since any hook could be wrapped in a 
giant `useMemo()` call, all arguments to hooks have to be treated as if they're 
owned by React — and therefore become immutable — and that the return value of 
the hook is immutable. 

Our default is to assume that hooks break the rules, but in practice nearly 
every component follows them.
2023-05-19 11:05:04 -07:00
Joe Savona
7e10c51532 Put optimizations in this stack behind a feature flag
Wraps all the optimizations from this stack behind a feature flag so we can 
quickly disable if there are problems when integrating.
2023-05-18 16:20:28 -07:00
Joe Savona
94e2ae5893 Dont memoize calls that produce primitive values
Teaches InferReactiveScopeVariables that calls can produce primitives that don't 
need a scope.
2023-05-18 16:05:32 -07:00
Joe Savona
5008448d74 Rename function for clarity
Cleanup now that we use this for two things
2023-05-18 15:52:51 -07:00
Joe Savona
0322e4dbd4 InferReferenceEffects uses function types for CallExpression
Updates the InferReferenceEffects logic for CallExpression to work similarly to 
MethodCall, where we take into account the function signature (if present) when 
inferring the effects and return kind.
2023-05-18 15:52:11 -07:00
Joe Savona
c0a5d86902 Reorder similar cases in InferReferenceEffects
Moves the CallExpression case next to MethodCall to make it easier to compare
2023-05-18 15:52:07 -07:00
Joe Savona
a325eed472 Define Boolean/Number/String globals
Defines the `Boolean`, `String`, and `Number` global functions. This will be 
useful for allowing developers to wrap statements that produce a primitive in a 
way that Forget knows about in order to optimize better.
2023-05-18 15:52:03 -07:00
Joe Savona
46417a4ed7 Fix bug with partially memoized destructuring 2023-05-18 09:25:28 -07:00
Joe Savona
a933d5e307 Repro for bug with partially memoized destructuring 2023-05-18 09:25:24 -07:00
Sebastian Markbåge
5309f10285 Remove Flight Relay DOM/Native (#26828)
The bindings upstream in Relay has been removed so we don't need these
builds anymore. The idea is to revisit an FB integration of Flight but
it wouldn't use the Relay specific bindings. It's a bit unclear how it
would look but likely more like the OSS version so not worth keeping
these around.

The `dom-relay` name also included the FB specific Fizz implementation
of the streaming config so I renamed that to `dom-fb`. There's no Fizz
implementation for Native yet so I just removed `native-relay`.

We created a configurable fork for how to encode the output of Flight
and the Relay implementation encoded it as JSON objects instead of
strings/streams. The new implementation would likely be more stream-like
and just encode it directly as string/binary chunks. So I removed those
indirections so that this can just be declared inline in
ReactFlightServer/Client.
2023-05-17 20:33:25 -04:00
Joe Savona
3603ee00a6 Retain original structure of labeled blocks
Handles some edge-cases where we previously flattened away some of the structure 
of a labeled block, instead ensuring that we retain the original shape. See the 
output. 

## Test Plan 

Tested on the internal app we're focused on (w useMemo inlining enabled), it 
works fine.
2023-05-17 15:55:54 -07:00
Joe Savona
7831ac2189 Enable InlineUseMemo in playground 2023-05-17 15:55:54 -07:00
Joe Savona
f0b8cfbf25 More concise output for labeled blocks 2023-05-17 15:55:53 -07:00
Joe Savona
f30041b0f0 More useMemo inlining test cases
More test cases for useMemo inlining, including the problematic case we found 
internally and some similar tricky cases with labels.
2023-05-17 15:55:52 -07:00
Joe Savona
329809de81 Dramatically simplify InlineUseMemo
I realized a wayyyy simpler approach to inlining a lambda: wrap it in a labeled 
block. The transformation is roughly as follows: 

```javascript 

// Before 

const x = useMemo(() => { 

if (a) { 

return b; 

} 

return c; 

}, [a, b, c]); 

return x; 

// After 

let x; 

label: { 

if (a) { 

x = b; 

break label; 

} 

x = c; 

break label; 

} 

return x; 

``` 

The key to making this work is fixing up some edge cases in labeled blocks, 
hence the previous PRs.
2023-05-17 15:55:51 -07:00
Joe Savona
5ee23af1a6 Elide empty if alternate blocks in codegen 2023-05-17 15:55:51 -07:00
Joe Savona
84a356274a Stop shrinking HIR to preserve fallthrough nodes
This is part of a stack to fix some edge cases in inlining of useMemo closures. 
In this first step, I'm disabling `shrink()` in order to retain more information 
about the data flow. For example, 

``` 

label: if (cond) { 

break label; 

} 

return foo; 

``` 

Would previously have shrunk away the if body, making the IfTerminal.consequent 
point directly to the fallthrough block (w the return). Now we retain a separate 
block.
2023-05-17 15:55:50 -07:00
Mofei Zhang
f070cab870 [snap] add memoizeJSX flag
--- 

#1603 for snap
2023-05-17 14:39:29 -04:00
Mofei Zhang
8b38651986 [snap] Add jest test capabilities to snap
- delete output files when we detect input files are deleted 

- enable test fixtures in nested directories 

- exit with error code when we detect failures 

Note that the test failure on this PR is expected and will be fixed by #1608 (or 
happy to abandon that PR and fold the changes)
2023-05-17 14:39:28 -04:00
Mofei Zhang
7ba638ef8d [tests] delete stale .expect files
--- 

Looks like we delete `.js` files but missed `.expect` files. Jest probably 
didn't catch this because the basename of the fixtures had duplicates (in 
rule-of-hooks)
2023-05-17 14:39:28 -04:00
Mofei Zhang
0b697d1903 [babel plugin] Add codegen for useRenderCounter 2023-05-17 14:39:27 -04:00
Mofei Zhang
bceb786c5a [runtime] useRenderCounter
--- 

(`react-forget-runtime` package seems to be synced to -.) 

RFC: useRenderCounter hook: 

- tracks # renders (increments on render path) 

- exposes a global renderCounterRegistry (counting # renders in alive / mounted 
components) 

Next PR will modify BabelPlugin to add codegen 

```js 

// Similar to how we're currently importing `isForgetEnabled` 

import {isInstrumentForgetEnabled_Secret} from "ReactForgetFeatureFlag"; 

// ... 

function Component_uncompiled(props) { 

if (isInstrumentForgetEnabled_Secret) { 

useRenderCounter(); 

} 

// ... 

} 

function Component_forget(props) { 

if (isInstrumentForgetEnabled_Secret) { 

useRenderCounter(); 

} 

// ... 

} 

```
2023-05-17 14:39:26 -04:00
Sathya Gunasekaran
dc603bb2fa [babel] Add isDev flag and put logging behind it 2023-05-17 18:38:08 +01:00
Ibrahem Mahyob
d7a98a5e97 Fix strict mode badge URL (#26825)
## Summary
Closes https://github.com/facebook/react/issues/26821

[[Fix #26821]](https://github.com/facebook/react/issues/26821) Update
strict mode badge URL


Updated the URL in the strict mode badge to point to the correct React
documentation for StrictMode. The previous URL was outdated. Now, when a
component is not running in StrictMode, the badge links to
https://react.dev/reference/react/StrictMode for more information.


## How did you test this change?

I verified that the strict mode badge now correctly links to the updated
URL. Previously, it pointed to the outdated URL
(https://fb.me/devtools-strict-mode). After the update, it correctly
points to the React Dev documentation for StrictMode
(https://react.dev/reference/react/StrictMode).


_Since its my first contribution here, i have completed the CLA_
2023-05-17 13:34:34 +01:00
Ruslan Lesiutin
2468a87358 React DevTools 4.27.7 -> 4.27.8 (#26823)
Closes https://github.com/facebook/react/issues/26787,
https://github.com/facebook/react/issues/26793

Includes these changes:
* fix[devtools]: fixed duplicated backend activation with multiple
renderers ([hoxyq](https://github.com/hoxyq) in
[#26807](https://github.com/facebook/react/pull/26807))
2023-05-17 11:40:50 +01:00
Andrew Clark
f8de255e94 Lower Suspense throttling heuristic to 300ms (#26803)
Now that the throttling mechanism applies more often, we've decided to
lower this a tad to ensure it's not noticeable. The idea is it should be
just large enough to prevent jank when lots of different parts of the UI
load in rapid succession, but not large enough to make the UI feel
sluggish. There's no perfect number, it's just a heuristic.
2023-05-16 15:59:15 -04:00
Andrew Clark
4bfcd02b2c Fix Suspense throttling mechanism (#26802)
The throttling mechanism for fallbacks should apply to both their
appearance _and_ disappearance.

This was mostly addressed by #26611. See that PR for additional context.

However, a flaw in the implementation is that we only update the the
timestamp used for throttling when the fallback initially appears. We
don't update it when the real content pops in. If lots of content in
separate Suspense trees loads around the same time, you can still get
jank.

The issue is fixed by updating the throttling timestamp whenever the
visibility of a fallback changes. Not just when it appears.
2023-05-16 15:03:30 -04:00
Joe Savona
2a80ba544e Move DisableJsxMemoization-test into main compiler test w pragma
I originally created a separate test for the mode with JSX memoization disabled, 
but we can merge this into the main compiler-test and enable the feature with a 
pragma.
2023-05-15 12:12:53 -07:00
mofeiZ
8bf1ec97a4 Add flag back for inlineUseMemo
Reverts #1502, but flips test flags (e.g. `inlineUseMemo` by default, unless a 
test specifies `@inlineUseMemo false`. I figured this add less thrash for test 
fixtures, but happy to just do a clean revert (or remove the pragma altogether 
and always pass `inlineUseMemo: true`)
2023-05-15 14:27:26 -04:00
Sathya Gunasekaran
f57ed15a33 [Babel] Log errors to stdout, not stderr
Writing to stderr causes buck to fail compilation.. which is not we want. Let's 
log to stdout only for now.
2023-05-15 14:45:26 +01:00
Sathya Gunasekaran
41a897797d [Babel] Format errors for console logging 2023-05-15 14:45:26 +01:00
Sathya Gunasekaran
5c8195aec7 [prettier] Fix linting 2023-05-15 14:43:39 +01:00
Sophie Alpert
4cd7065665 Fix uSES hydration in strict mode (#26791)
Previously, we'd call and use getSnapshot on the second render resulting
in `Warning: Text content did not match. Server: "Nay!" Client: "Yay!"`
and then `Error: Text content does not match server-rendered HTML.`.

Fixes #26095. Closes #26113. Closes #25650.

---------

Co-authored-by: eps1lon <silbermann.sebastian@gmail.com>
2023-05-12 14:18:03 -07:00
Mofei Zhang
dda3e61347 [test cases] Add failing / bug tests for destructuring assignment 2023-05-12 12:48:18 -04:00
Mofei Zhang
fe95b5df90 [hir] add DeclareContext (2/n)
--- 

In `lower`, we now ensure that all context variables are declared by a 
`DeclareContext` instruction. `DeclareContext` always produces a `let` 
declaration, and `StoreContext` is always a reassign. There are a few reasons we 
need `DeclareContext`: 

- DeclareLocal assumes it is storing to a SSA-fied identifier (which always 
stores an immutable primitive). This does not fit context variables. 

- Without DeclareContext, we need custom logic in some passes to initialize 
identifier / context state (e.g. `MutableRange`, ValueKind, etc) for the 
`StoreContext` that declares the context. 

This PR stack models context variables as concrete identifiers (with references 
to context variables modeled by `Place` referencing the context variable 
identifier). @josephsavona pointed out that this is abusing the notion of 
Identifier/Place, as context variables are essentially interior properties of a 
ContextEnvironment. Since we are not modeling `ContextEnvironment` implicitly or 
explicitly, all inference for context variables is essentially pointer analysis.
2023-05-12 12:48:17 -04:00
Mofei Zhang
314a5cfca5 [hir] Add Load/StoreContext (1/n)
--- 

This PR adds LoadContext and StoreContext to handle reading and writing to 
context variables. 

A context variable is any variable that is declared within a Forget-compiled 
function and reassigned within a closure. Conceptually, we want to treat these 
variables as attributes of a `EnvironmentContext` variable (as most javascript 
VMs do). 

- context variables currently do not participate in type inference (i.e. we do 
not produce type equations for loads from context variables). In the future, we 
can try typing this as `Phi(assignment1Type, assignment2Type, ...)`. 

- context variables are always treated as `Effect.Mutable`. 

- context variables do not participate in SSA, or certain optimizing passes 
(e.g. dead code elimination, constant propagation, etc). 

There is some still follow ups: 

- From my understanding, we should introduce a `DeclareContext` instruction. 

- currently, declaring a context variable (without initializing it) is broken. 
This is because the declaration lowers to `DeclareLocal`, which assumes it is 
storing to a SSA-fied identifier. 

```js 

let x; 

x = 4; 

() => { x = {}; }; 

``` 

- DeclareContext will also make some initialization logic easier. In this PR, I 
added some hack-y code to handle initializing effects / mutable ranges / other 
inference state for the first StoreContext. 

- Handle or bail on stores to context variables through destructuring assignment 

- 

~~Next PR:~~ 

- ~~Change closures to track reassigned identifiers (to extend mutable range of 
primitives)~~
2023-05-12 12:17:05 -04:00
Pieter De Baets
a389046a52 [react-native] Always set RN$stopSurface (#26808)
## Summary
To support incremental adoption of bridgeless logic we want to default
to using these globals whenever they're available.

## How did you test this change?
https://github.com/facebook/react-native/pull/37410
2023-05-12 16:14:45 +01:00
Ruslan Lesiutin
67a05d03e3 fix[devtools]: fixed duplicated backend activation with multiple renderers (#26807)
## Summary
Initially reported in https://github.com/facebook/react/issues/26797.
Was not able to reproduce the exact same problem, but found this case:

1. Open corresponding codepen from the issue in debug mode
2. Open components tab of the extension
3. Refresh the page

Received multiple errors:
- Warning in the Console tab: Invalid renderer id "2".
- Error in the Components tab: Uncaught Error: Cannot add node "3"
because a node with that id is already in the Store.

This problem has occurred after landing a fix in
https://github.com/facebook/react/pull/26779. Looks like Chrome is
keeping the injected scripts (the backend in this case) and we start
backend twice.
2023-05-12 14:59:53 +01:00
Joe Savona
f5bdf462b2 Enable hooks validation on playground, make deguggable
Enables hooks validation in playground. Also adds a tab to show the output of 
validation (in case it passes) with the inferred post dominator tree. We can use 
this to debug the dominator in case of false negatives. 

<img width="1724" alt="Screenshot 2023-05-11 at 11 07 08 AM" 
src="https://github.com/facebook/react-forget/assets/6425824/8f7ae472-8415-4899-aedf-c8f26094ebfe">
2023-05-11 13:39:59 -06:00
Joe Savona
e649bf6429 Fixtures from ESLint rule
Incorporates the fixtures from eslint-plugin-react-hooks using a script, so that 
we can easily update them in the future. For each fixture we run the compiler 
with and without hooks validation first so that we know if the fixture is 
expected to pass — we have some false positives and false negatives that i can 
work through. For example we accidentally think that `userFetch()` is a hook, 
oops. Fixtures that should pass but error, or that should error but pass, are 
marked as `todo.<name>` or `todo.error.<name>`. 

While i was here i added the ability to have fixtures in subdirectories for 
grouping purposes.
2023-05-11 13:39:58 -06:00
Mofei Zhang
d1e044b81a [deps] Add DeclareLocal to ReactiveScope decls
--- 

Try to fix bug from #1589: 

> If a declaration for an immutable identifier (i.e. one that is not later 
re-assigned, since undefined is a primitive) is sandwiched between mutations, we 
currently do not record it as an output or hoist it out of the reactive scope. 

One simple fix is to add all declared (and later referenced) identifiers as 
declarations of a reactive scope. This has some undesired effects (e.g. 
additional instructions + memo cache slots), but in practice, this shouldn't be 
happening often. 

Alternatively, we could 1.) add a pass to hoist declarations, 2.) account for 
this in constant propagation, or 3.) add a bailout
2023-05-11 16:24:37 -04:00
Mofei Zhang
a2169d894a [test case] Test for DeclareLocal instruction
--- 

Record incorrect output. 

If a declaration for an immutable identifier (i.e. one that is not later 
re-assigned, since `undefined` is a primitive) is sandwiched between mutations, 
we currently do not record it as an output or hoist it out of the reactive 
scope.
2023-05-11 16:24:36 -04:00
mofeiZ
77c535ce25 [snap] Make watch mode go fast(er)
While optimizing per @josephsavona's suggestions in #1592, I noticed that we 
were clearing quite a few require cache entries. 

As of this PR, `Object.keys(require.cache)` holds 

- 1258 entries total 

- 67 files compiled from Forget source code (this is what 
`ts.createWatchCompilerHost` modifies) 

- 1120 babel source files (from node_modules) 

When working on watch mode, I'm almost always making changes to Forget source or 
test fixture files. It's a bit faster to just clear those entries (assuming that 
babel has no global state we need to invalidate). 

On my computer, re-running tests in watch mode (triggered by source code 
changes) takes: 

|   |  All tests  | One test (filter) | 

|-- |--------|----------| 

| current | 4.7s  | 1.8s  | 

| this PR  |  1.8s  | 0.1s  |
2023-05-11 14:58:51 -04:00
Mofei Zhang
5e80821aa2 [effects] Allow capture-store effects in rvals
--- 

Some typed functions need to annotate callees or arguments as `Effect.Store`. 
This PR modifies alias analysis (`InferAliasForStores`) to account for this
2023-05-10 21:55:56 -04:00
Jan Kassens
df12d7eac4 [www] reduce dynamic SchedulerFeatureFlags (#26617)
For these values we're not using dynamic values. We can statically
compile in the values we're running.
2023-05-10 17:26:05 -04:00
Andrew Clark
7cd98ef2bc Fix nightly job to publish to "canary" channel (#26799)
When I was renaming the next channel to canary, I updated the
`publish_preleases` workflow correctly, but I skipped over
`publish_preleases_nightly`. Oops.
2023-05-09 22:27:35 -04:00
Andrew Clark
b5810163e9 Change yarn test to default to experimental (#26741)
The idea is that the default `yarn test` command should be the one that
includes the most bleeding edge features, because during development you
probably want as many features enabled as possible.

That used to be `www-modern` but nowadays it's `experimental` because
we've landed a bunch of async actions stuff in experimental but it isn't
yet being tested at Meta.

So this switches the default to `experimental`.
2023-05-09 21:50:14 -04:00
Mofei Zhang
f3d4d16918 [lower] Bail out on computed lvalues in destructure
--- 

Currently, we're silently producing incorrect output - 

```js 

// source 

function Component(props) { 

const computedKey = props.key; 

const { [computedKey]: x } = props.val; 

return x; 

} 

// compiles to 

function Component(props) { 

const { computedKey: x } = props.val; 

return x; 

} 

```
2023-05-09 14:38:15 -04:00
mofeiZ
04cee98166 [snap] patch bug in clearing require cache
Snap currently has a bug in which the require cache is not correctly cleared 
when running in filter mode (#tests < 2 * #workers). 

- We're currently clearing all entries in the require cache of worker threads, 
including `jest-worker` and `snap/dist/...` files 

- jest-worker seems to `require` these files on every dispatch (i.e. 
`worker.compile` seems to call `require(`compiler-worker`).compile`)
2023-05-11 13:53:06 -04:00
Joe Savona
5de02b881b Support unused conditional/logical expressions assigned to variable
I noticed some instances of this error when running forget on an internal 
product. I previously fixed the case if a logical/conditional used only for side 
effects (not assigned to a variable) but the new cases were assigned to an 
unused variable. I double-checked and we’ve actually fixed all the steps after 
these invariants so we can just remove them and support these cases.
2023-05-09 10:58:51 -07:00
Joe Savona
50c3bd9d98 Fix capturedRefs collection for lambdas
When we calculate the dependencies of a FunctionExpression we were only adding 
new items if the binding identifier had not been seen yet. That is correct for 
`capturedIds` since its the set of identifiers, but incorrect for `capturedRefs` 
since its an array of all the distinct places. This meant that if a function 
expression referenced multiple properties of the same binding, we'd only record 
the first one. We now correctly record all of them.
2023-05-09 10:38:56 -07:00
Jan Kassens
fda1f0b902 Flow upgrade to 0.205.1 (#26796)
Just a small upgrade to keep us current and remove unused suppressions
(probably fixed by some upgrade since).

- `*` is no longer allowed and has been an alias for `any` for a while
now.
2023-05-09 10:45:50 -04:00
Joe Savona
90109b3572 Clean up dominator/post-dominator impl
Tidies up the implementation a bit, splitting the single function and class into 
distinct computeDominatorTree() and computePostDominatorTree() functions and 
helper classes.
2023-05-08 15:35:48 -07:00
Joe Savona
597e70d69f Improve eslint derived fixtures 2023-05-08 14:10:07 -07:00
Joe Savona
8920fc0b2f Dont count throw as an exit node (React semantics)
React will retry or abort components that throw (depending on a few conditions), 
so from React's perspective a `throw` statement is not a normal exit node. Thus 
the Rules of Hooks really have a caveat: the set of hooks that are called _in an 
execution that returns successfully_ must be consistent. Examples such as the 
following are therefore allowed: 

```javascript 

function Component(props) { 

if (props.cond) { 

throw new Error(...); 

} 

useHook(); 

} 

``` 

By modeling `throw` as an exit node, we rejected cases such as this. This diff 
changes to not model throws as exit nodes. #1584  changes this to make it an 
option, since some cases will want to consider throw as an exit node.
2023-05-08 13:58:46 -07:00
Joe Savona
7dedc6cc72 Fix test for hook name to match lint rule 2023-05-08 12:14:30 -07:00
Joe Savona
fd007be0d0 Fixtures from ESLint rule
Incorporates the fixtures from eslint-plugin-react-hooks using a script, so that 
we can easily update them in the future. For each fixture we run the compiler 
with and without hooks validation first so that we know if the fixture is 
expected to pass — we have some false positives and false negatives that i can 
work through. For example we accidentally think that `userFetch()` is a hook, 
oops. Fixtures that should pass but error, or that should error but pass, are 
marked as `todo.<name>` or `todo.error.<name>`. 

While i was here i added the ability to have fixtures in subdirectories for 
grouping purposes.
2023-05-08 12:10:43 -07:00
Jan Kassens
7ac5e9a602 Small flowconfig fixes (#26784)
- The whole project root is included by default anyway, the include
section should be redundant and just misleading.
- The generated ignore paths ignore more than intended as they didn't
escape the `.` for regex.

Test Plan:
- wait for CI
- tested the ignore pattern change with renaming files and seeing the
expected files ignored for flow
2023-05-08 12:07:48 -04:00
Joe Savona
6bbe3111c0 ValidateUnconditionalHooks pass using dominators
See the code comments for more, but the basic idea here is that we use the post 
dominator tree to find the set of basic blocks which are guaranteed reachable in 
each function. Those are the only blocks where it is safe to call hooks, and we 
error for hook calls in any other blocks.
2023-05-08 08:55:14 -07:00
Joe Savona
2ddd00dbb1 Implement dominator/post-dominator tree calculation
Implements an efficient algorithm for computing the dominator (or post 
dominator) tree of a CFG, following 
https://www.cs.rice.edu/~keith/Embed/dom.pdf. This is used/tested in the next PR 
to validate that hooks are called unconditionally. 

note: I clean up the implementation quite a bit late in the stack in #1584
2023-05-08 08:55:13 -07:00
Joe Savona
5b0f566941 Example of "unnecessary" memoization of lambdas
I noticed this while demoing Forget to React Org alum Christoph Nakazawa — in 
array.map calls (and other APIs that take a lambda as input) we sometimes end up 
memoizing the lambda. It's technically correct since the function _could_ return 
the lambda, and then we'd need it to be memoized. It's tricky because array.map 
is often called on nested objects, where even if we had type inference on the 
outer value we wouldn't know for sure that the inner property is an Array and 
not some other data type with a custom .map. For example in 
`data.feedback.comments.edges.map(edge => ...)`, even if we knew that `data` was 
an Object, we wouldn't know that data.feedback.comments.edges is an Array 
without cross-file type knowledge. 

But it's definitely wasteful to memoize these lambdas, so we should brainstorm 
options. One option that stands out right away: if the lambda has zero 
dependencies, then we could lift it out to module scope and refer to it by name.
2023-05-10 23:09:17 -06:00
Mofei Zhang
11cee99968 [snap runner][easy] reverse diff order 2023-05-08 14:58:32 -04:00
Andrew Clark
16d053d592 Add useFormStatus to server rendering stub (#26788)
This was an oversight when I set up the hook in #26719.
2023-05-06 20:39:08 -04:00
dan
efb381bbf9 [Release Script] Print a hint where to get the token (#26783)
I always forget where to get it.
2023-05-05 20:08:14 +01:00
Samuel Susla
b00e27342d Use native scheduler if defined in global scope (#26554)
Co-authored-by: Dan Abramov <dan.abramov@gmail.com>
2023-05-05 14:01:31 +01:00
Joe Savona
2332155161 ValidateHooksUsage
Adds a validation pass to check that the only thing you can do with hooks is 
call them. A follow-up PR (still early WIP) will check the other aspect of the 
rules of hooks, that they are not called conditionally. That's a more involved 
algorithm.
2023-05-04 13:33:43 -07:00
Joe Savona
f75cf6fe38 Fix fbt (again) 2023-05-04 15:19:41 -07:00
Ruslan Lesiutin
783e7fcfa3 React DevTools 4.27.6 -> 4.27.7 (#26780)
List of changes:
* DevTools: fix backend activation ([hoxyq](https://github.com/hoxyq) in
[#26779](https://github.com/facebook/react/pull/26779))
* fix[dynamic-scripts-injection]: unregister content scripts before
registration ([hoxyq](https://github.com/hoxyq) in
[#26765](https://github.com/facebook/react/pull/26765))
2023-05-04 18:22:47 +01:00
Ruslan Lesiutin
377c5175f7 DevTools: fix backend activation (#26779)
## Summary
We have a case:
1. Open components tab
2. Close Chrome / Firefox devtools window completely
3. Reopen browser devtools panel
4. Open components tab

Currently, in version 4.27.6, we cannot load the components tree.

This PR contains two changes:
- non-functional refactoring in
`react-devtools-shared/src/devtools/store.js`: removed some redundant
type castings.
- fixed backend manager logic (introduced in
https://github.com/facebook/react/pull/26615) to activate already
registered backends. Looks like frontend of devtools also depends on
`renderer-attached` event, without it component tree won't load.

## How did you test this change?
This fixes the case mentioned prior. Currently in 4.27.6 version it is
not working, we need to refresh the page to make it work.

I've tested this in several environments: chrome, firefox, standalone
with RN application.
2023-05-04 17:34:57 +01:00
Sebastian Markbåge
aef7ce5547 [Flight] Progressively Enhanced Server Actions (#26774)
This automatically exposes `$$FORM_ACTIONS` on Server References coming
from Flight. So that when they're used in a form action, we can encode
the ID for the server reference as a hidden field or as part of the name
of a button.

If the Server Action is a bound function it can have complex data
associated with it. In this case this additional data is encoded as
additional form fields.

To process a POST on the server there's now a `decodeAction` helper that
can take one of these progressive posts from FormData and give you a
function that is prebound with the correct closure and FormData so that
you can just invoke it.

I updated the fixture which now has a "Server State" that gets
automatically refreshed. This also lets us visualize form fields.
There's no "Action State" here for showing error messages that are not
thrown, that's still up to user space.
2023-05-03 18:36:57 -04:00
Sebastian Markbåge
c10010a6a0 [Fizz] Gracefully handle suspending in DOM configs (#26768)
E.g. if we suspend (throw a promise) in pushStartInstance today we might
have already pushed some chunks (or even child segments potentially). We
should revert back to where we were.

This doesn't usually happen because when we suspend in a component it
doesn't write anything itself, it'll always defer to som host instance
to do the writing.

There was a todo about this already but I'm not 100% sure it's always
safe when suspending. It should be safe when suspending just regularly
because it's just a noop. We might not even want "throwing a promise" in
this mechanism to be supported longer term but for now that's how a
suspend in internals.
2023-05-03 18:13:47 -04:00
Andrew Clark
f533cee8cb Add useFormStatus to Flight fixture (#26773) 2023-05-03 15:29:32 -04:00
Andrew Gadzik
2c1117a8d0 Reuse request so that a ReabableStream body does not become disturbed (#26771) 2023-05-03 15:06:10 -04:00
Mofei Zhang
407e7b0c62 [snap runner] debug mode 2023-05-03 14:50:27 -04:00
Mofei Zhang
7e990419c1 [snap tester] Handle unexpected errors by failing fixture 2023-05-03 14:50:25 -04:00
Joe Savona
253b05f28d Remove restriction on optional nesting
We previously disallowed OptionalMemberExpression inside a normal 
MemberExpression, eg `(a?.b).c`. The new representation handles this case 
correctly so we can remove the restriction.
2023-05-03 17:10:31 -07:00
Joe Savona
7ecee6a091 Support complex computed properties in OptionalMemberExpression
Our previous lowering for OptionalMemberExpression reordered the evaluation of 
properties, such that we had to restrict the allowed properties to those that 
were safe for reordering. With the new representation we preserve order of 
evaluation, so we can relax the restriction. This unblocks a few cases in an 
internal product.
2023-05-03 17:10:28 -07:00
Joe Savona
e192930cd4 Remove unnecessary optional property on loads
Now that _all_ optional expression types use the new representation, the 
optionality of all PropertyLoad and ComputedLoad is modeled via control flow (in 
HIR) and the structure of OptionalExpression (in ReactiveFunction). Thus we no 
longer need the `optional` properties on these load instructions — they're 
optional if they're part of an OptionalExpression.
2023-05-03 17:10:27 -07:00
Joe Savona
a43fc2bcf3 Consistently use new lowering for OptionalMemberExpression
Earlier PRs in the stack change the way we lower OptionalMemberExpression, but 
only when they ultimately appear inside some OptionalCallExpression. This PR 
ensures that _all_ OptionalMemberExpressions get the new lowering. Note that one 
test case has what is arguably a regression, but the new behavior is also 
reasonable: if we see both `a.b?.c` and `a.b.c.` as dependencies of a scope, we 
previously inferred `a.b.c` as the dependency, but we now infer `a.b` as the 
dependency. This isn't as optimal as what we had before, but it also seems good 
enough for now. Also note that some cases are improved: `foo(a.b?.c)` would 
previously have taken `a.b` as a dependency, we now take the full value of 
`a.b?.c` as a dependency - more precise. 

So overall i'm inclined to land and follow-up on the one regression, since the 
overall model is more cohesive.
2023-05-03 17:10:26 -07:00
Sebastian Markbåge
fa7a447b9c [Fizz] Check for nullish values on ReactCustomFormAction (#26770)
Usually we don't have to do this since we only set these in the loop but
the ReactCustomFormAction props are optional so they might be undefined.

Also moved it to a general type since it's a semi-public API.
2023-05-03 14:35:26 -04:00
Andrew Clark
b7972822b5 useOptimisticState -> useOptimistic (#26772)
Drop the "state". Just "useOptimistic". It's cleaner.

This is still an experimental API. May not be the final name.
2023-05-03 14:26:00 -04:00
Andrew Clark
388686f291 Add "canary" to list of allowed npm dist tags (#26767)
Forgot this allowlist existed. It's an extra safeguard, in case we mess
up the configuration somehow.
2023-05-03 12:36:34 -04:00
Ruslan Lesiutin
8a25302c66 fix[dynamic-scripts-injection]: unregister content scripts before registration (#26765)
## Summary
Fixes #26756.

DevTools is failing to inject `__REACT_DEVTOOLS_GLOBAL_HOOK__` hook in
incognito mode. This is not happening straight-forward, but if extension
is toggled on and off, the next time I try to open it I am receiving an
error that content script was already registered.

<img width="676" alt="Screenshot 2023-05-02 at 14 36 53"
src="https://user-images.githubusercontent.com/28902667/235877692-51c5d284-79d9-4b00-b62e-d25d5bb5e056.png">

- Unregistering content scripts before attempting to register them
again. We need to inject `__REACT_DEVTOOLS_GLOBAL_HOOK__` on each page,
so this should be expected behaviour.
- Fixed error logging
 
## How did you test this change?
Local build of extension for Chrome, trying the same steps, which
resulted in an error.
No regression in performance, tested on react.dev, still the same.
2023-05-03 17:27:39 +01:00
Andrew Clark
2c2476834a Rename "next" prerelease channel to "canary" (#26761)
The "next" prerelease channel represents what will be published the next
time we do a stable release. We publish a new "next" release every day
using a timed CI workflow.

When we introduced this prerelease channel a few years ago, another name
we considered was "canary". But I proposed "next" instead to create a
greater distinction between this channel and the "experimental" channel
(which is published at the same cadence, but includes extra experimental
features), because some other projects use "canary" to refer to releases
that are more unstable than how we would use it.

The main downside of "next" is someone might mistakenly assume the name
refers to Next.js. We were aware of this risk at the time but didn't
think it would be an issue in practice.

However, colloquially, we've ended up referring to this as the "canary"
channel anyway to avoid precisely that confusion.

So after further discussion, we've agreed to rename to "canary".

This affects the label used in the version string (e.g.
`18.3.0-next-a1c2d3e4` becomes `18.3.0-canary-a1c2d3e4`) as well as the
npm dist tags used to publish the releases. For now, I've chosen to
publish the canaries using both `@canary` and `@next` dist tags, so that
downstream consumers who might depend on `@next` have time to adjust. We
can remove that later after the change has been communicated.
2023-05-03 12:10:32 -04:00
Sathya Gunasekaran
e5c07ad3e1 [babel] Skip compilation if there's no function name 2023-05-03 14:32:58 +01:00
Joe Savona
404f627c2c Improve conditional dependency tracking for optional member expr inside optional
call 

When we traverse an OptionalExpression in PropagateScopeDependencies, we 
previously considered the entire value to be optional. With the changes in this 
stack to more accurately model OptionalMemberExpression, the `object` portion of 
an OptionalMemberExpression is now evaluated within the OptionalExpression. This 
PR refines the handling of OptionalExpression accordingly, so that we only treat 
the optional portion as conditional.
2023-05-02 16:49:54 -07:00
Joe Savona
a1902b263d Rename OptionalCall -> Optional for clarity
The previous OptionalCall terminal and reactive value kinds are now used not 
just for optional calls, but for optional member expressions that appear within 
an optional call. This PR renames those data types to OptionalTerminal and 
OptionalExpression for clarity.
2023-05-02 16:31:31 -07:00
Joe Savona
c46157b00b More accurately model OptionalMemberExpression
Extends the new modeling of the previous diff to OptionalMemberExpression. In an 
example such as `a?.b?.c`, we now model that not only is the `.c` conditional, 
but our control flow graph accurately reflects the fact that the `.c` is only 
evaluated if `a.b` exists. Previously we knew it was conditional but the CFG 
allowed a path from a being null through to evaluation of `.c`.
2023-05-02 15:44:06 -07:00
Joe Savona
73a203c199 More accurately model nested OptionalCallExpression
More accurately models nested OptionalCallExpression. Consider: 

```javascript 

a?.(b)?.(c) 

``` 

Our previous representation modeled it such that we treated the second function 
call as if it would be called regardless of whether `a` existed or not. We knew 
that the second call was conditional, so our test output was correct, but the 
control-flow graph didn't faithfully model the semantics. That bothered me. 

The new representation correctly models the control flow, and the fact that if 
`a` is null/undefined execution immediately aborts (not reaching the second call 
at all, nor the evaluation of its args), and evaluates the whole outer 
OptionalCallExpression to `undefined`. 

Note that nested optional member expressions still have the previous model — 
that's next to address.
2023-05-02 15:00:12 -07:00
Joe Savona
9a12e8ba58 Support OptionalCallExpression as LHS of LogicalExpression
A common idiom is to map over some possibly-missing list of items from a data 
payload and fall back to an empty array: 

```javascript 

const renderedItems = data?.items?.map(renderItem) ?? []; 

``` 

The way we were lowering OptionalCallExpression meant that in this case, we'd 
end up with an OptionalCallTerminal as the terminal of the logical expression's 
test block, which violates our internal invariant. Logical test blocks must end 
in a Branch! This PR fixes the immediate issue, which is that the callee - in 
this case `data?.items?.map` — was being lowered prior to the 
OptionalCallTerminal instead of inside its test block. Changing that fixes the 
shape of the IR and makes this example work. 

As part of investigating this I realized that the way I originally handled 
lowering of optional call isn't quite right. The difference isn't observable 
unless we did more sophisticated DCE but we don't correctly model the fact that 
if `data.items` is null that the `map()` call won't occur. That is technically 
fine bc we do model the fact that the `map()` call is conditional, and notably 
its arguments are only conditional dependencies. So it's good enough. But in a 
follow-up I'll change to model the fact that `data.items` is null, that the map 
call isn't reachable at all.
2023-05-02 15:00:11 -07:00
Andrew Clark
fa4314841e Remove deprecated workflow key from Circle config (#26762)
This key was only valid during the 2.0 beta period so we can remove it.
2023-05-02 14:59:36 -04:00
Joe Savona
8292c65d84 Add missing traverseValue()
I don't think this one matters but just in case, we should always call 
traverseValue() when overriding visitValue().
2023-05-02 11:07:12 -07:00
Joe Savona
dd6a9d6a03 Dont memoize hook calls in logical expressions
Fix the previous bug — this was a simple oversight, where FlattenScopesWithHooks 
overrode `visitValue()` but failed to call `traverseValue()`. This meant that 
when we reached compound expressions such as LogicalExpressions that we didn't 
traverse into their nested values, and didn't see the hooks hidden there.
2023-05-02 11:01:37 -07:00
Joe Savona
bfb84eed3b Repro for memoized hook within logical expression
Repro of a bug in which we incorrect memoize hook calls that are inside logical 
expressions (though the bug could occur for ternaries, optional calls, and 
sequence expressions too).
2023-05-02 10:47:48 -07:00
Joe Savona
c0b0119356 Start of architecture doc
This is an attempt to get down some of the principles and goals that we've had 
partially written down, partially just thoroughly discussed amongst the team. 
It's rough draft quality but better than nothing, and gives us someplace to add 
to.
2023-05-02 09:33:19 -07:00
Samuel Susla
5dd90c5623 Use content hash for react-native builds (#26734) 2023-05-02 12:04:02 +01:00
Sebastian Markbåge
559e83aebb [Fizz] Allow an action provide a custom set of props to use for progressive enhancement (#26749)
Stacked on top of #26735.

This allows a framework to add a `$$FORM_ACTION` property to a function.
This lets the framework return a set of props to use in place of the
function but only during SSR. Effectively, this lets you implement
progressive enhancement of form actions using some other way instead of
relying on the replay feature.

This will be used by RSC on Server References automatically by
convention in a follow up, but this mechanism can also be used by other
frameworks/libraries.
2023-05-01 16:01:14 -04:00
Sebastian Markbåge
67f4fb0213 Allow forms to skip hydration of hidden inputs (#26735)
This allows us to emit extra ephemeral data that will only be used on
server rendered forms.

First I refactored the shouldSkip functions to now just do that work
inside the canHydrate methods. This makes the Config bindings a little
less surface area but it also helps us optimize a bit since we now can
look at the code together and find shared paths.

canHydrate returns the instance if it matches, that used to just be
there to refine the type but it can also be used to just return a
different instance later that we find. If we don't find one, we'll bail
out and error regardless so no need to skip past anything.
2023-05-01 15:35:57 -04:00
Josh Story
8ea96ef84d [Fizz] Encode external fizz runtime into chunks eagerly (#26752)
in https://github.com/facebook/react/pull/26738 we added nonce to the
ResponseState. Initially it was used in a variety of places but the
version that got merged only included it with the external fizz runtime.
This PR updates the config for the external fizz runtime so that the
nonce is encoded into the script chunks at request creation time.

The rationale is that for live-requests, streaming is more likely than
not so doing the encoding work at the start is better than during flush.
For cases such as SSG where the runtime is not required the extra
encoding is tolerable (not a live request). Bots are an interesting case
because if you want fastest TTFB you will end up requiring the runtime
but if you are withholding until the stream is done you have already
sacrificed fastest TTFB and the marginal slowdown of the extraneous
encoding is hopefully neglibible

I'm writing this so later if we learn that this tradeoff isn't worth it
we at least understand why I made the change in the first place.
2023-05-01 10:50:36 -07:00
Andrew Clark
491aec5d61 Implement experimental_useOptimisticState (#26740)
This adds an experimental hook tentatively called useOptimisticState.
(The actual name needs some bikeshedding.)

The headline feature is that you can use it to implement optimistic
updates. If you set some optimistic state during a transition/action,
the state will be automatically reverted once the transition completes.

Another feature is that the optimistic updates will be continually
rebased on top of the latest state.

It's easiest to explain with examples; we'll publish documentation as
the API gets closer to stabilizing. See tests for now.

Technically the use cases for this hook are broader than just optimistic
updates; you could use it implement any sort of "pending" state, such as
the ones exposed by useTransition and useFormStatus. But we expect
people will most often reach for this hook to implement the optimistic
update pattern; simpler cases are covered by those other hooks.
2023-05-01 13:19:20 -04:00
Dan Ott
9545e4810c Add nonce support to bootstrap scripts and external runtime (#26738)
Adds support for nonce on `bootstrapScripts`, `bootstrapModules` and the external fizz runtime
2023-05-01 09:19:02 -07:00
Joe Savona
5196fbd92b Visit switch test case as scope dependency
This can't be tested yet - we only support simple, safely re-orderable values as 
case test values - but it will easy to overlook later so i'm adding now.
2023-05-01 08:51:58 -07:00
Andrew Clark
86b0e91998 Gate DevTools test to fix CI (#26742)
This test started failing recently in older versions of React because
the Scheduler priority inside a microtask is Normal instead of
Immediate. This is expected because microtasks are not Scheduler tasks;
it's an implementation detail.

I gated the test to only run in v17 because it's a regression test for
legacy Suspense behavior, and the implementation details of the snapshot
changed in v18.

Test plan
---------

Using latest:

```
yarn test --build --project devtools --release-channel=experimental profilingcache
```

Using v17 (typically runs in a timed CI workflow):

```
/scripts/circleci/download_devtools_regression_build.js 17.0 --replaceBuild
yarn test --build --project devtools --release-channel=experimental --reactVersion 17.0 profilingcache
```
2023-04-29 11:14:16 -04:00
Joe Savona
41d99ffcb9 PropagateScopeDeps uses visitor infra
PropagateScopeDependencies is one of the few places we don't use the new visitor 
infra for traversing ReactiveFunction. Or rather it _was_! 

Note that there's a bit less value here than in other places since we have to 
handle each terminal variant with custom logic, but at least it's more 
consistent with the rest of the codebase now.
2023-04-28 17:14:02 -07:00
Josh Story
b12bea62d9 Preinits should support a nonce option (#26744)
Currently there is no way to provide a nonce when using
`ReactDOM.preinit(..., { as: 'script' })`

This PR adds `nonce?: string` as an option

While implementing this PR I added a test to also show you can pass
`integrity`. This test isn't directly related to the nonce change.
2023-04-28 15:57:39 -07:00
Sebastian Silbermann
efbd68511d Remove unused initialStatus parameter from useHostTransitionStatus (#26743) 2023-04-28 23:18:10 +02:00
Andrew Clark
18282f881d Fix: Update while suspended fails to interrupt (#26739)
This fixes a bug with `use` where if you update a component that's
currently suspended, React will sometimes mistake it for a render phase
update.

This happens because we don't reset `currentlyRenderingFiber` until the
suspended is unwound. And with `use`, that can happen asynchronously,
most commonly when the work loop is suspended during a transition.

The fix is to make sure `currentlyRenderingFiber` is only set when we're
in the middle of rendering, which used to be true until `use` was
introduced.

More specifically this means clearing `currentlyRenderingFiber` when
something throws and setting it again when we resume work.

In many cases, this bug will fail "gracefully" because the update is
still added to the queue; it's not dropped completely. It's also
somewhat rare because it has to be the exact same component that's
currently suspended. But it's still a bug. I wrote a regression test
that shows a sync update failing to interrupt a suspended component.
2023-04-28 15:35:14 -04:00
Joe Savona
1df89e992a Remove unnecessary temporary in tests
We previously didn't support ternaries whose value was unused, so we had an 
extraneous temporary and console.log call to ensure the value counted as used. 
We now special-case ternary/conditional expressions which are in an 
ExpressionStatement to not prune them, so the temporary and log are now 
unnecessary.
2023-04-27 10:43:43 -07:00
Lauren Tan
d2f33dd524 Retain locations when using babel cloneNode in lambdas
It turns out the third parameter to `cloneNode` is ["If the third parameter is 
true, the cloned nodes exclude location 
properties."](c060e5e3d5/packages/babel-types/src/clone/cloneNode.ts (L35-L39)) 
strips away locations if its true, so to fix simply change this to false
2023-04-27 16:25:41 -04:00
Lauren Tan
d5dee80933 Failing test for fbt issue
Specifically, the fbt plugin would error on a `null` loc as it [relies on it in 
one of its 
utils](6a23a5374a/packages/babel-plugin-fbt/src/getNamespacedArgs.js (L82-L84)), 
implying a missing `loc` somewhere in our pipeline after codegen
2023-04-27 16:25:41 -04:00
Lauren Tan
3eed52b49b Only debug with @debug pragma
You don't always want to debug all the passes when you use @only, so split it 
out into its own pragma
2023-04-27 16:16:50 -04:00
Joe Savona
b69d70664c Console methods are readonly
Defines common `console` methods to tell the compiler that they take readonly 
args. This ensures that things like `console.log()` aren't accidentally viewed 
as a mutation. Previously the pattern of "build object, then log it after 
mutation is done" would have grouped the console.log as part of the mutation and 
the log only would fire if the value got reconstructed. Now we know the log 
isn't mutating, and the log will happen regardless of whether the value is 
rebuilt or cached.
2023-04-27 10:34:31 -07:00
Joe Savona
2ddbbd4735 Exhaustive switches for some terminal handling
Updates two points in the compiler that were easy to miss when adding new 
terminals: 

* HIRBuilder's `removeUnreachableFallthroughs()` nulls out unreachable 
fallthroughs, but this had a non-exhaustive `if` statement. It now uses a helper 
function which internally has an exhaustive switch. 

* LeaveSSA needs to schedule block fallthroughs, but had a non-exhaustive `if` 
statement. It also uses a helper function which internally has an exhaustive 
switch. 

cc @poteto since you ran into this (ie the compiler not alerting you to update 
these places) w your diffs.
2023-04-26 16:34:26 -07:00
Joe Savona
afe2f5c810 Support useMemo w named functions
Supports useMemo invocations where the function is not an inline function, such 
as `useMemo(someFunction, [])`.
2023-04-26 18:16:28 -07:00
Sathya Gunasekaran
1cccd6a815 [hir] Clone babel nodes rather than reusing them
There's state such as scope info sticking on to these nodes so reusing them can 
cause issues if a pass later on just uses scopes these directly.
2023-04-27 17:35:30 +01:00
Andrew Clark
540bab085d Implement experimental_useFormStatus (#26722)
This hook reads the status of its ancestor form component, if it exists.

```js
const {pending, data, action, method} = useFormStatus();
```

It can be used to implement a loading indicator, for example. You can
think of it as a shortcut for implementing a loading state with the
useTransition hook.

For now, it's only available in the experimental channel. We'll share
docs once its closer to being stable. There are additional APIs that
will ship alongside it.

Internally it's implemented using startTransition + a context object.
That's a good way to think about its behavior, but the actual
implementation details may change in the future.

Because form elements cannot be nested, the implementation in the
reconciler does not bother to keep track of multiple nested "transition
providers". So although it's implemented using generic Fiber config
methods, it does currently make some assumptions based on React DOM's
requirements.
2023-04-26 18:19:58 -04:00
Lauren Tan
4a8c90a77c [babel] Remove unsafe calls to path.stop()
Discovered this in a recent attempt at syncing Forget to Meta, it seems 

that calling path.stop() is unsafe as it appears to have strange 

behavior in plugins that come after. This resulted in `import type 

{...}` not being compiled away in the post-babel output which isn't 

valid JS syntax. Removing the `stop()` calls fixes it 

Test plan: made these changes locally, synced my local changes to Meta and reran 
- in simulator and observe that it now runs and doesn't throw a syntax error
2023-04-26 17:16:34 -04:00
Lauren Tan
b1eaf88c61 [babel] Ensure only adding import specifier to non-namespace
Missed this in the previous PR 

Test plan: P706162189 (some babel errors) before this PR, P706255523 has no 
errors
2023-04-26 15:16:21 -04:00
Joe Savona
e5f4b3008f Rename things for clarity in PropagateScopeDeps 2023-04-26 11:34:47 -07:00
Joe Savona
2aa3a28481 test case for debugger stmt in reactive scope 2023-04-26 11:34:46 -07:00
Joe Savona
5b9992075c Driveby optimization of DCE
Lift a constant evaluation out of a loop
2023-04-26 11:27:41 -07:00
Joe Savona
d4b8df5441 Address code review 2023-04-26 11:27:40 -07:00
Joe Savona
e98823f933 Generalize #1521 for PropertyLoad
This is a more general version of the change from #1521. That PR ensured that 
LoadLocal temporaries accessed outside the instruction's scope are correctly 
promoted. However, we have a similar pattern with PropertyLoad. 

This PR adds a general mechanism for handling these type of indirections: any 
LoadLocal/PropertyLoad temporary accessed when it's defining scope is not active 
will be promoted to a declaration of the defining scope. Notably, we do this in 
a way that ensures that the dependencies are preserved, ie that we correctly 
view the operand of LoadLocal/PropertyLoad as a dependency of the current scope.
2023-04-26 11:27:39 -07:00
Joe Savona
dd5069162a This page left intentionally blank
Supports EmptyStatement nodes by ignoring them. Note no tests because 
format-on-save clears away any empty statements and there is, rather 
frustratingly, no way to tell VSCode not to format on save for a specific file 
via the file contents itself or project configuration (at least, not that i can 
find).
2023-04-26 11:27:38 -07:00
Joe Savona
8e7b68506f You get a debugger and you get a debugger and you get a
Adds support for DebuggerStatement.
2023-04-26 11:27:37 -07:00
Joe Savona
1f51b10ac9 Fix unused logical/condition via ExpressionStatement instr
Uses the new ExpressionStatement instruction to ensure that logical and 
conditional expressions are never pruned. This addresses an issue where we were 
unable to construct a ReactiveFunction for unused logical/conditional bc there 
wasn't a single Identifier assigned in both branches. The ExpressionStatement 
ensures that the result is used, that we don't prune the phi, and that both 
branches have a single assignment target. 

In theory we could be more sophisticated with DCE and still prune these 
instructions if their operands are also safe to prune, but in practice you're 
only like to have a logical/conditional as an expression statement (in the 
source) if it's for side effects.
2023-04-26 11:27:36 -07:00
Joe Savona
2cb1c72305 Scaffolding for ExpressionStatement instruction kind
Adds an `ExpressionStatement` instruction variant to model values that are 
otherwise "unused" but which we don't want to remove. The next diff changes 
BuildHIR to use this where appropriate.
2023-04-26 11:27:35 -07:00
Joe Savona
894cf6e37b First-class representation of builtin jsx tags
We previously represented JsxExpressions using builtin tags - `<div>`, `<b>` etc 
- by lowering the tag name to a Primitive with the string name of the tag. 
However, by lowering into an independent value, it was possible that the lowered 
tag name could be grouped into a different memo slot, such that we ended up with 
output like: 

```javascript 

let t0; 

if (c_1) { 

... 

t0 = "div" 

... 

} else { ... } 

return <t0>{children}</t0> 

``` 

This is obviously wrong. It's also wrong to rename `t0` -> `T0`, because React 
treats that as a custom component, not a builtin. The right thing is to 
explicitly model builtin components, which this PR does by making 
`JsxExpression.tag` be a union of Place | BuiltinTag.
2023-04-26 11:27:35 -07:00
Joe Savona
9aea37ff5a Promote temporaries used in JSX to uppercase names
Ensures that temporaries used in JsxExpression tags are named with a capital 
letter so that they are treated as custom components rather than builtins.
2023-04-26 11:27:34 -07:00
Lauren Tan
5f2f76cbcd Fix test262
We [renamed the 
export](6f001f54b0/forget/src/Babel/RunReactForgetBabelPlugin.ts (L22)) 
of runReactForgetBabelPlugin so the test262 preprocessor was erroring
2023-04-26 14:12:18 -04:00
Andrew Clark
6eadbe0c4a Fix: Resolve entangled actions independently (#26726)
When there are multiple async actions at the same time, we entangle them
together because we can't be sure which action an update might be
associated with. (For this, we'd need AsyncContext.) However, if one of
the async actions fails with an error, it should only affect that
action, not all the other actions it may be entangled with.

Resolving each action independently also means they can have independent
pending state types, rather than being limited to an `isPending`
boolean. We'll use this to implement an upcoming form API.
2023-04-25 20:43:20 -04:00
Josh Story
ec5e9c2a75 Fix double preload (#26729)
I found a couple scenarios where preloads were issued too aggressively

1. During SSR, if you render a new stylesheet after the preamble flushed
it will flush a preload even if the resource was already preloaded
2. During Client render, if you call `ReactDOM.preload()` it will only
check if a preload exists in the Document before inserting a new one. It
should check for an underlying resource such as a stylesheet link or
script if the preload is for a recognized asset type
2023-04-25 15:10:34 -07:00
Mofei Zhang
5ed297fa74 [snap tester] Support @only / @skip with special file
--- 

Changes: 

- Added `testfilter.txt` 

``` 

// @only 

call 

capture-param-mutate 

jsx-spread 

``` 

or 

``` 

// @skip 

call 

error.todo-kitchensink 

``` 

- grouped all commands under `--mode` 

```js 

// runs all tests 

yarn snap 

// runs all tests and updates fixtures 

yarn snap --mode update 

// runs only tests that pass `testfilter.txt` 

yarn snap --mode filter 

// run in watch mode 

yarn snap --mode watch 

``` 

- in watch mode, toggle between running all tests or filtered tests 

``` 

386 Tests, 386 Passed, 0 Failed 

Completed in 4994 ms 

Current mode = NORMAL, run all test fixtures. 

Waiting for input or file changes... 

u     - update all fixtures 

f     - toggle (turn on) filter mode 

q     - quit 

[any] - rerun tests 

> f 

PASS  call 

PASS  capture_mutate-across-fns 

PASS  timers 

3 Tests, 3 Passed, 0 Failed 

Completed in 39 ms 

Current mode = FILTER, filter test fixtures by "testfilter.txt" 

Waiting for input or file changes... 

u     - update all fixtures 

f     - toggle (turn off) filter mode 

q     - quit 

[any] - rerun tests 

``` 

--- 

- `runner.ts` is pretty large now, happy to split it up into multiple files 

- I'd also like to refactor `watch` to make its shared state and control flow 
explicit
2023-04-25 14:36:06 -04:00
Mofei Zhang
bf518c2b2c [snap tester] watch mode: ignore changes from test updates
A bit of a hack - 

We currently trigger test runs when we detect changes in the test fixtures 
directory. This trigger is also hit when we run `snap` in update mode, since 
updating performs file writes. 

This PR will ignore subscription changes (callbacks) that trigger within 5 
seconds of the last update. 

It seems difficult to be more granular with a timestamp, since `@parcel/watcher` 
doesn't give us the file change timestamp and (from my understanding), other 
promises and tasks can be queued to run between the update and callback.
2023-04-25 14:15:25 -04:00
Rubén Norte
f87e97a0a6 Handle line endings correctly on Windows in build script for RN (#26727)
## Summary

We added some post-processing in the build for RN in #26616 that broke
for users on Windows due to how line endings were handled to the regular
expression to insert some directives in the docblock. This fixes that
problem, reported in #26697 as well.

## How did you test this change?

Verified files are still built correctly on Mac/Linux. Will ask for help
to test on Windows.
2023-04-25 17:26:34 +01:00
lauren
25b99efe0c [DevTools] Add support for useMemoCache (#26696)
useMemoCache wasn't previously supported in the DevTools, so any attempt
to inspect a component using the hook would result in a
`dispatcher.useMemoCache is not a function (it is undefined)` error.
2023-04-25 09:19:25 -07:00
Andrew Clark
ed545ae3d3 Turn off enableFormActions in Meta build (#26721)
This is enabled in the canary channels, but because it's relatively
untested, we'll disable it at Meta until they're ready to start trying
it out. It can change some behavior even if you don't intentionally
start using the API.

The reason it's not a dynamic flag is that it affects the external Fizz
runtime, which currently can't read flags at runtime.
2023-04-25 12:01:34 -04:00
Sebastian Markbåge
bf449ee74e Replay Client Actions After Hydration (#26716)
We used to have Event Replaying for any kind of Discrete event where
we'd track any event after hydrateRoot and before the async code/data
has loaded in to hydrate the target. However, this didn't really work
out because code inside event handlers are expected to be able to
synchronously read the state of the world at the time they're invoked.
If we replay discrete events later, the mutable state around them like
selection or form state etc. may have changed.

This limitation doesn't apply to Client Actions:

- They're expected to be async functions that themselves work
asynchronously. They're conceptually also in the "navigation" events
that happen after the "submit" events so they're already not
synchronously even before the first `await`.
- They're expected to operate mostly on the FormData as input which we
can snapshot at the time of the event.

This PR adds a bit of inline script to the Fizz runtime (or external
runtime) to track any early submit events on the page - but only if the
action URL is our placeholder `javascript:` URL. We track a queue of
these on `document.$$reactFormReplay`. Then we replay them in order as
they get hydrated and we get a handle on the Client Action function.

I add the runtime to the `bootstrapScripts` phase in Fizz which is
really technically a little too late, because on a large page, it might
take a while to get to that script even if you have displayed the form.
However, that's also true for external runtime. So there's a very short
window we might miss an event but it's good enough and better than
risking blocking display on this script.

The main thing that makes the replaying difficult to reason about is
that we can have multiple instance of React using this same queue. This
would be very usual but you could have two different Reacts SSR:ing
different parts of the tree and using around the same version. We don't
have any coordinating ids for this. We could stash something on the form
perhaps but given our current structure it's more difficult to get to
the form instance in the commit phase and a naive solution wouldn't
preserve ordering between forms.

This solution isn't 100% guaranteed to preserve ordering between
different React instances neither but should be in order within one
instance which is the common case.

The hard part is that we don't know what instance something will belong
to until it hydrates. So to solve that I keep everything in the original
queue while we wait, so that ordering is preserved until we know which
instance it'll go into. I ended up doing a bunch of clever tricks to
make this work. These could use a lot more tests than I have right now.

Another thing that's tricky is that you can update the action before
it's replayed but we actually want to invoke the old action if that
happens. So we have to extract it even if we can't invoke it right now
just so we get the one that was there during hydration.
2023-04-25 10:22:20 -04:00
Sebastian Markbåge
64d6be7122 Use require() to implement script src in tests (#26717)
We currently use rollup to make an adhoc bundle from the file system
when we're testing an import of an external file.

This doesn't follow all the interception rules that we use in jest and
in our actual builds.

This switches to just using jest require() to load these. This means
that they effectively have to load into the global document so this only
works with global document tests which is all we have now anyway.
2023-04-25 09:12:16 -04:00
Andrew Clark
919620b293 Add stub for experimental_useFormStatus (#26719)
This wires up, but does not yet implement, an experimental hook called
useFormStatus. The hook is imported from React DOM, not React, because
it represents DOM-specific state — its return type includes FormData as
one of its fields. Other renderers that implement similar methods would
use their own renderer-specific types.

The API is prefixed and only available in the experimental channel.

It can only be used from client (browser, SSR) components, not Server
Components.
2023-04-24 20:18:34 -04:00
Sebastian Markbåge
9ece58ebaa Go through the toString path for booleanish strings and .name property (#26720)
This is consistent with what we used to do but not what we want to do.
2023-04-24 19:26:50 -04:00
Mofei Zhang
a8db941fb7 [snap tester] Handle interrupts by forking runner
Run snap tester on a forked node process so runs can be interrupted. (Currently, 
`Ctrl+C` is not handled until after all test fixtures finish compiling). This 
*feels* a bit heavy-handed, but main.ts is pretty small and doesn't do much 
other than listen for input / signals. Would love feedback here since I haven't 
really worked with nodejs / JS cli tools before 

- main.ts 

new file that spawns forked runner 

- pipe stdin/out/err to and from the child runner process, details described in 
comments. 

- listens for exit event of child 

- runner.ts 

- added logic to listen for interrupts and clean up (not really familiar with 
how file and tsc watchers are implemented, so we try to call 'close' on them 
just in case they need to release locks / do other cleanup)
2023-04-24 19:09:40 -04:00
Mofei Zhang
4cf86028c0 [snap tester] Patch runner for sync mode
--- 

`yarn snap --sync` currently fails on `error.file-has-non-critical-errors`. This 
is because we're relying on a globally overwritten `console.error` function to 
report non-fatal errors. However, executing `Promise.all(...)` on a single 
nodejs thread will interleave calls to `run` (which is an async function).
2023-04-24 15:52:54 -04:00
Mofei Zhang
46752845eb [snap tester] QoL: help messages, cmd line validation, ts errors
--- 

Next PRs: skip / only tests, pretty diffing 

This PR: 

1. Add help messages: 

``` 

$ node packages/snap/dist/runner.js --help 

Options: 

--version         Show version number                                [boolean] 

--sync            Run compiler in main thread (instead of using worker threads 

or subprocesses). Defaults to false. 

[boolean] [default: true] 

--worker-threads  Run compiler in worker threads (instead of subprocesses). 

Defaults to true.                  [boolean] [default: true] 

--watch           Run in watch mode. Defaults to false (single run). 

[boolean] [default: false] 

--update          Run in update mode. Update mode only affects the first run, 

subsequent runs (in watch mode) require typing `u` to 

update. Defaults to false.        [boolean] [default: false] 

--help            Show help                                          [boolean] 

  Done in 0.62s. 

``` 

``` 

... 

386 Tests, 386 Passed, 0 Failed 

Completed in 4434 ms 

Waiting for input or file changes... 

u     - update fixtures 

q     - quit 

[any] - rerun tests 

``` 

2. Surface typescript diagnostics; skip test fixtures if source code has errors 

``` 

$ node packages/snap/dist/runner.js 

src/Optimization/ConstantPropagation.ts:87:3 - error TS1434: Unexpected keyword 
or identifier. 

src/Optimization/ConstantPropagation.ts:87:3 - error TS2304: Cannot find name 
'lt'. 

src/Optimization/ConstantPropagation.ts:87:6 - error TS2552: Cannot find name 
'hasChanges'. Did you mean 'onhashchange'? 

src/Optimization/ConstantPropagation.ts:135:11 - error TS2552: Cannot find name 
'hasChanges'. Did you mean 'onhashchange'? 

src/Optimization/ConstantPropagation.ts:155:10 - error TS2552: Cannot find name 
'hasChanges'. Did you mean 'onhashchange'? 

Compilation failed (5 errors). 

Found errors in Forget source code, skipping test fixtures. 

  Done in 10.73s. 

``` 

``` 

Compiling... 

src/Optimization/ConstantPropagation.ts:86:39 - error TS2552: Cannot find name 
'HIRFunctin'. Did you mean 'HIRFunction'? 

Compilation failed (1 error). 

Test: Found errors in Forget source code, skipping test fixtures. 

Waiting for input or file changes... 

u     - update fixtures 

q     - quit 

[any] - rerun tests 

```
2023-04-24 15:52:52 -04:00
Lauren Tan
a6769df6b1 [babel] Alias unstable_useMemoCache to useMemoCache
DevTools relies on built-in hook names at their call site to be unprefixed in 

order to correctly track them. This PR updates our Babel plugin to: 

- Check if there are any existing import declarations of `import { /* ... /* } 
from 'react';` 

- If true, we add the specifier `unstable_useMemoCache as useMemoCache` 

- Otherwise, we synthesize a new import declaration 

- In Codegen we now emit `useMemoCache(n)` rather than 
`React.unstable_useMemoCache(n)`
2023-04-26 13:40:22 -04:00
Sebastian Markbåge
5e5342b100 Insert temporary input node to polyfill submitter argument in FormData (#26714)
Insert temporary input node to polyfill submitter argument in FormData.
This works for buttons too and fixes a bug where the type attribute
wasn't reset.

I also exclude the submitter if it's a function action. This ensures
that we don't include the generated "name" when the action is a server
action. Conceptually that name doesn't exist.
2023-04-24 14:18:09 -04:00
Sebastian Markbåge
9c58a0b647 Update Flight fixture to use use() instead of Promise as a child (#26715)
The Promise as a child case seems buggy. It ends up throwing the Promise
as fatal when used in Sync rendering.
2023-04-24 14:00:25 -04:00
Sophie Alpert
9ee7964302 Fix escaping in ReactDOMInput code (#26630)
JSON.stringify isn't the right thing here. Luckily this doesn't look to have any security impact.
2023-04-24 10:33:11 -07:00
Sebastian Markbåge
2fa6323818 Restore server controlled form fields to whatever they should be (#26708)
Fizz can emit whatever it wants for the SSR version of these fields when
it's a function action so they might not align with what is in the
previous props. Therefore we need to force them to update if we're
updating to a non-function where they might be relevant again.
2023-04-23 17:44:28 -04:00
Andrew Clark
7ce765ec32 Clean up enableUseHook flag (#26707)
This has been statically enabled everywhere for months.
2023-04-23 14:50:17 -04:00
Sebastian Markbåge
a21d1475ff [Flight] Fix File Upload in Node.js (#26700)
Use the Blob constructor + append with filename instead of File
constructor. Node.js doesn't expose a global File constructor but does
support it in this form.

Queue fields until we get the 'end' event from the previous file. We
rely on previous files being available by the time a field is resolved.
However, since the 'end' event in Readable is fired after two
micro-tasks, these are not resolved in order.

I use a queue of the fields while we're still waiting on files to
finish. This still doesn't resolve files and fields in order relative to
each other but that doesn't matter for our usage.
2023-04-22 01:04:24 -04:00
Josh Story
36e4cbe2e9 [Float][Flight] Flight support for Float (#26502)
Stacked on #26557 

Supporting Float methods such as ReactDOM.preload() are challenging for
flight because it does not have an easy means to convey direct
executions in other environments. Because the flight wire format is a
JSON-like serialization that is expected to be rendered it currently
only describes renderable elements. We need a way to convey a function
invocation that gets run in the context of the client environment
whether that is Fizz or Fiber.

Fiber is somewhat straightforward because the HostDispatcher is always
active and we can just have the FlightClient dispatch the serialized
directive.

Fizz is much more challenging becaue the dispatcher is always scoped but
the specific request the dispatch belongs to is not readily available.
Environments that support AsyncLocalStorage (or in the future
AsyncContext) we will use this to be able to resolve directives in Fizz
to the appropriate Request. For other environments directives will be
elided. Right now this is pragmatic and non-breaking because all
directives are opportunistic and non-critical. If this changes in the
future we will need to reconsider how widespread support for async
context tracking is.

For Flight, if AsyncLocalStorage is available Float methods can be
called before and after await points and be expected to work. If
AsyncLocalStorage is not available float methods called in the sync
phase of a component render will be captured but anything after an await
point will be a noop. If a float call is dropped in this manner a DEV
warning should help you realize your code may need to be modified.

This PR also introduces a way for resources (Fizz) and hints (Flight) to
flush even if there is not active task being worked on. This will help
when Float methods are called in between async points within a function
execution but the task is blocked on the entire function finishing.

This PR also introduces deduping of Hints in Flight using the same
resource keys used in Fizz. This will help shrink payload sizes when the
same hint is attempted to emit over and over again
2023-04-21 20:45:51 -07:00
Andrew Clark
8f42196892 Change DOM HostContext to number instead of string (#26698)
In React DOM, we use HostContext to represent the namespace of whatever
is currently rendering — SVG, Math, or HTML. Because there is a fixed
set of possible values, we can switch this to be a number instead. My
motivation is that I want to start tracking additional information in
this type, and I want to pack all of it into a single number instead of
turning it into an object. For better performance.

(In dev, the host context type is already an object that includes
additional information, but that's dev so who cares.)

Technically, before this change, the host context could be any namespace
URI string, but any value other than SVG or Math was treated the same
way. Only SVG and Math have special behavior. So in the new structure,
there are three enum values: SVG, Math, or None, which represents the
HTML namespace as well as all other possible namespaces.
2023-04-21 21:44:43 -04:00
Joe Savona
32dccd48d2 [hir] Remove flag for inlineUseMemo 2023-04-21 13:43:32 -07:00
Lauren Tan
b40de89805 Run snap in ci 2023-04-21 15:22:56 -04:00
Lauren Tan
2b75c7915b Add @panicOnBailout support to snap
Test plan: tests pass with snap
2023-04-21 15:22:56 -04:00
Lauren Tan
b184d8567c [be] Add snap to yarn commands 2023-04-21 15:22:56 -04:00
Andrew Clark
967d46c76c Add error boundary to Flight fixture (#26695)
Errors in form actions are now rethrown during render (#26689), so we
can handle them using an error boundary.
2023-04-21 14:23:50 -04:00
Jan Kassens
5d7ebb4b78 Allow Node.js 20 to build (#26693)
This is stable and appears to build w/o problem. I don't see why we
should disallow it.
2023-04-21 19:23:27 +01:00
Andrew Clark
fd3fb8e3c5 Rethrow errors from form actions (#26689)
This is the next step toward full support for async form actions.

Errors thrown inside form actions should cause the form to re-render and
throw the error so it can be captured by an error boundary. The behavior
is the same if the `<form />` had an internal useTransition hook, which
is pretty much exactly how we implement it, too.

The first time an action is called, the form's HostComponent is
"upgraded" to become stateful, by lazily mounting a list of hooks. The
rest of the implementation for function components can be shared.

Because the error handling behavior added in this commit is just using
useTransition under-the-hood, it also handles pending states, too.
However, this pending state can't be observed until we add a new hook
for that purpose. I'll add this next.
2023-04-21 13:29:46 -04:00
Jan Kassens
c57a0f68a4 Remove react-is download hack (#26692)
This was added during an upgrade to Jest 24 in
https://github.com/facebook/react/pull/15778

By now we're at Jest 29. I think if CI passes we might not need this
hack anymore.
2023-04-21 13:11:09 -04:00
Joe Savona
aa3edc8130 Cleanup unused wasm-based DOT diagram renderer
I forgot to remove this when we removed the diagram output. This brings test 
time from 6s -> 5s on my machine, still much slower than the new test runner in 
#1486.
2023-04-21 08:03:38 -07:00
Joe Savona
4a67d539dc Prune scopes wo own outputs
#1507 Ensured that declarations of reactive scopes were propagated to parent 
reactive scopes as necessary to ensure that those declarations would be 
available at the appropriate block scope. This meant that some scopes that were 
previously pruned would no longer be pruned. Specifically, an outer scope wo any 
declarations, but which contained a nested scope _with_ a propagated 
declaration, would now end up with non-empty declarations and not be pruned. 

This PR changes to track the declaring scope of each declaration, so we still 
prune scopes that don't have any of their own declarations.
2023-04-21 08:03:37 -07:00
Joe Savona
cb72726e38 Cleanup Stack impl
Originally I defined `Stack` as an interface to ensure both Node and Empty 
variants would have an identical API. But exporting an interface allows a 
developer to define other implementations, when we really want to ensure that a 
Stack is precisely a Node or Empty instance. This PR changes to exporting a 
union of `Stack = Node | Empty`, and makes the interface private to the module.
2023-04-21 08:03:37 -07:00
Joe Savona
f4896b45b2 Fix temporaries accessed outside of their defining scope
Fixed a bug identified in repro cases earlier in the stack. The case is where 
some later value is composed of several values, say A and B, where A is an 
identifier that is reassigned within B. Also, the mutable range of B surrounds 
the evaluation of A. In this case, the reference to A gets lowered to a 
temporary (say a t0 = LoadLocal A), and that temporary is created within the 
reactive scope for B. 

PropagateScopeDependencies bypasses LoadLocal indirections, and considers the 
reference to the temporary (t0) as if it was a reference to the identifier (A). 
That breaks the whole reason we lower Identifiers to temporaries - to preserve 
evaluation order. 

This PR fixes the bug by promoting temporaries to names values if they are 
referenced outside their defining scope. So, the reference to t0 stays a 
reference to t0, which correctly preserves the value of A at the right point in 
time. 

This is all much easier to see in the new test case.
2023-04-20 18:52:39 -07:00
Itai Mizlish
c8369527ef update broken icon link (circleCi status) (#26688)
looks better now 🚀
2023-04-20 18:28:45 -07:00
Joe Savona
e9abc41ea3 Fix evaluation order for JSX element tags
When lowering a JSX element we were correctly lowering to a temporary in all but 
one case: the common case of an identifier. That is fine in practice but breaks 
in the presence of the tag identifier being reassigned in the props/children. 
This PR fixes to always lower the tag to a temporary.
2023-04-20 16:48:34 -07:00
Joe Savona
db378d39f3 Constant propagation for globals
This PR updates ConstantPropagation to support propagating global references: 

```javascript 

// Before 

const x = Math; 

foo(x); 

// After 

foo(Math); 

``` 

This is a generally useful optimization but also helps with a subset of cases 
around JSX element tags, which are frequently globals.
2023-04-20 16:48:30 -07:00
Joe Savona
5c9614785c [codegen] Create new temporary map when entering reactive scopes
During codegen, when we now cache and restore the temporary values map as we 
enter and exit the scope. This ensures that any temporaries within the reactive 
scope are only visible within that scope, and not to subsequent code. In a 
subsequent PR this surfaces a bug with temporaries not correctly exported from a 
reactive scope.
2023-04-20 16:48:26 -07:00
Joe Savona
c72452895a [codegen] validate that temporary values are set
In codegen when we lower an operand we check to see if we have an already 
lowered value for it (stored in `cx.temp`). Currently we silently handle missing 
values by emitting a raw identifier, but this is really an error. This PR adds 
validation, which uncovered a few places where we legitimately won't have a 
value - things like function parameters that got swapped for temporaries bc of 
destructuring. We populate those as `null` values now, and fail if a temporary 
had a truly missing value.
2023-04-20 16:48:22 -07:00
Josh Story
cc93a85332 [Fiber] InvokeGuardedCallback without metaprogramming (#26569)
InvokeGuardedCallback is now implemented with the browser fork done at
error-time rather than module-load-time. Originally it also tried to
freeze the window/document references to avoid mismatches in prototype
chains when testing React in different documents however we have since
updated our tests to not do this and it was a test only feature so I
removed it.
2023-04-20 15:08:51 -07:00
Josh Story
fdad813ac7 [Float][Fiber] Enable Float methods to be called outside of render (#26557)
Stacked on #26570 

Previously we restricted Float methods to only being callable while
rendering. This allowed us to make associations between calls and their
position in the DOM tree, for instance hoisting preinitialized styles
into a ShadowRoot or an iframe Document.

When considering how we are going to support Flight support in Float
however it became clear that this restriction would lead to compromises
on the implementation because the Flight client does not execute within
the context of a client render. We want to be able to disaptch Float
directives coming from Flight as soon as possible and this requires
being able to call them outside of render.

this patch modifies Float so that its methods are callable anywhere. The
main consequence of this change is Float will always use the Document
the renderer script is running within as the HoistableRoot. This means
if you preinit as style inside a component render targeting a ShadowRoot
the style will load in the ownerDocument not the ShadowRoot. Practially
speaking it means that preinit is not useful inside ShadowRoots and
iframes.

This tradeoff was deemed acceptable because these methods are
optimistic, not critical. Additionally, the other methods, preconntect,
prefetchDNS, and preload, are not impacted because they already operated
at the level of the ownerDocument and really only interface with the
Network cache layer.

I added a couple additional fixes that were necessary for getting tests
to pass that are worth considering separately.

The first commit improves the diff for `waitForThrow` so it compares
strings if possible.

The second commit makes invokeGuardedCallback not use metaprogramming
pattern and swallows any novel errors produced from trying to run the
guarded callback. Swallowing may not be the best we can do but it at
least protects React against rapid failure when something causes the
dispatchEvent to throw.
2023-04-20 14:40:25 -07:00
Josh Story
e5708b3ea9 [Tests][Fizz] Better HTML parsing behavior for Fizz tests (#26570)
In anticipation of making Fiber use the document global for dispatching
Float methods that arrive from Flight I needed to update some tests that
commonly recreated the JSDOM instance after importing react.

This change updates a few tests to only create JSDOM once per test,
before importing react-dom/client.

Additionally the current act implementation for server streaming did not
adequately model streaming semantics so I rewrite the act implementation
in a way that better mirrors how a browser would parse incoming HTML.

The new act implementation does the following

1. the first time it processes meaningful streamed content it figures
out whether it is rendering into the existing document container or if
it needs to reset the document. this is based on whether the streamed
content contains tags `<html>` or `<body>` etc...
2. Once the streaming container is set it will typically continue to
stream into that container for future calls to act. The exception is if
the streaming container is the `<head>` in which case it will switch to
streaming into the body once it receives a `<body>` tag.

This means for tests that render something like a `<div>...</div>` it
will naturally stream into the default `<div id="container">...` and for
tests that render a full document the HTML will parse like a real
browser would (with some very minor edge case differences)

I also refactored the way we move nodes from buffered content into the
document and execute any scripts we find. Previously we were using
window.eval and I switched this to just setting the external script
content as script text. Additionally the nonce logic is reworked to be a
bit simpler.
2023-04-20 14:27:02 -07:00
Lauren Tan
8bab0bca3c [babel] Compile individual components
Updates the Babel plugin so that we can individually compile components and skip 
over ones that have non-critical errors
2023-04-20 16:21:40 -04:00
Lauren Tan
c228d63f03 [babel] Add panicOnBailout option
Adds an option to always throw errors regardless of severity (default, ie the 
status quo), or when the flag is disabled, only critical errors will be thrown. 
Any error that isn't considered a critical error (see 
`CompilerError.isCritical()`) since it might indicate that the compiler is 
buggy, while non-critical errors will result in that file being skipped for 
compilation, but otherwise continue compiling other files
2023-04-20 16:21:40 -04:00
Andrew Clark
d73d7d5908 Add alwaysThrottleRetries flag (#26685)
This puts the change introduced by #26611 behind a flag until Meta is
able to roll it out. Disabling the flag reverts back to the old
behavior, where retries are throttled if there's still data remaining in
the tree, but not if all the data has finished loading.

The new behavior is still enabled in the public builds.
2023-04-20 14:23:22 -04:00
Joe Savona
275c755715 Repro for jsx lowering issues
* JSX tag value temporaries getting promoted due to being sandwiched inside the 
mutation of some other item 

* Incorrect order-of-evaluation for jsx tag relative to props/children
2023-04-20 09:29:37 -07:00
Ruslan Lesiutin
7f8c501f68 React DevTools 4.27.5 -> 4.27.6 (#26684)
Full list of changes:
* Use .slice() for all substring-ing
([sophiebits](https://github.com/sophiebits) in
[#26677](https://github.com/facebook/react/pull/26677))
* cleanup[devtools]: remove named hooks & profiler changed hook indices
feature flags ([hoxyq](https://github.com/hoxyq) in
[#26635](https://github.com/facebook/react/pull/26635))
* chore[devtools/release-scripts]: update messages / fixed npm view com…
([hoxyq](https://github.com/hoxyq) in
[#26660](https://github.com/facebook/react/pull/26660))
* (patch)[DevTools] bug fix: backend injection logic not working for
undocked devtools window ([mondaychen](https://github.com/mondaychen) in
[#26665](https://github.com/facebook/react/pull/26665))
* use backend manager to support multiple backends in extension
([mondaychen](https://github.com/mondaychen) in
[#26615](https://github.com/facebook/react/pull/26615))
2023-04-20 13:34:25 +01:00
Sophie Alpert
22d5942675 Add two event system cleanup TODOs (#26678)
There is so much old stuff in these files. I am weeping.
2023-04-19 18:41:46 -07:00
Sophie Alpert
767f52237c Use .slice() for all substring-ing (#26677)
- substr is Annex B
- substring silently flips its arguments if they're in the "wrong order", which is confusing
- slice is better than sliced bread (no pun intended) and also it works the same way on Arrays so there's less to remember

---

> I'd be down to just lint and enforce a single form just for the potential compression savings by using a repeated string.

_Originally posted by @sebmarkbage in https://github.com/facebook/react/pull/26663#discussion_r1170455401_
2023-04-19 14:26:01 -07:00
Joe Savona
3aa6196e30 Starting point for a new, parallel test runner to replace our hacked Jest
snapshotting 

As demo'd on our sync. This is meant as a replacement for `yarn test` just for 
fixtures. On my machine, a test run from a steady state of Jest watch mode takes 
6 seconds. With this script, it takes ~800ms. 

Workflow: make edits in `packages/snap/`, then `yarn build` in that directory to 
build the test runner. 

To run tests, `node packages/snap/dist/runner.js` from the main forget/ 
directory to run tests. Pass `--watch` for watch mode, `--update` to update 
snapshots. Note that this _only_ updates .expect.md files, it does not update 
Jest's `__snapshots__` directory (this is intentional, our use of Jest snapshots 
is a hack that this script is meant to replace). 

When running in watch mode, ctrl-c or q will quit, 'u' will update snapshots, 
and any other key will re-run tests. Tests will re-run on changes to the source 
code (after an incremental TS rebuild) and on changes to the fixtures. 

Main things that are missing: 

* Don't run tests if TS compilation had errors (the errors should be logged to 
console already, but we need to wire that up so that we abort tests if there are 
errors) 

* Actually delete stale files in update mode (there is some commented-out code 
to double-check and then uncomment) 

* Improve diff view: just print the diffed segments, not the whole file diff. 
See the API at https://github.com/facebook/jest/tree/main/packages/jest-diff 
(right now we're using `diff()` but should probably use one of the lower-level 
functions) 

* Properly parse/validate args with `yargs`, add a help option, etc 

* In watch mode, when tests finish print a list of commands so users know what 
they can do (like Jest does) 

* Support skipping tests and selecting a single test to focus. Suggestions: 

* Name files with `skip.` to skip 

* Allow passing a test name to the script to run only tests matching that 
pattern, eg `node runner.js -p <pattern>` 

* In watch mode, support typing 'p' to prompt the user for a pattern. After 
that, support typing 'a' to clear the pattern and run all tests.
2023-04-19 14:07:06 -07:00
Sebastian Markbåge
c826dc50de Add (Client) Functions as Form Actions (#26674)
This lets you pass a function to `<form action={...}>` or `<button
formAction={...}>` or `<input type="submit formAction={...}>`. This will
behave basically like a `javascript:` URL except not quite implemented
that way. This is a convenience for the `onSubmit={e => {
e.preventDefault(); const fromData = new FormData(e.target); ... }`
pattern.

You can still implement a custom `onSubmit` handler and if it calls
`preventDefault`, it won't invoke the action, just like it would if you
used a full page form navigation or javascript urls. It behaves just
like a navigation and we might implement it with the Navigation API in
the future.

Currently this is just a synchronous function but in a follow up this
will accept async functions, handle pending states and handle errors.

This is implemented by setting `javascript:` URLs, but these only exist
to trigger an error message if something goes wrong instead of
navigating away. Like if you called `stopPropagation` to prevent React
from handling it or if you called `form.submit()` instead of
`form.requestSubmit()` which by-passes the `submit` event. If CSP is
used to ban `javascript:` urls, those will trigger errors when these
URLs are invoked which would be a different error message but it's still
there to notify the user that something went wrong in the plumbing.

Next up is improving the SSR state with action replaying and progressive
enhancement.
2023-04-19 16:31:08 -04:00
Andrew Clark
cd2b79dedd Initial (client-only) async actions support (#26621)
Implements initial (client-only) support for async actions behind a
flag. This is an experimental feature and the design isn't completely
finalized but we're getting closer. It will be layered alongside other
features we're working on, so it may not feel complete when considered
in isolation.

The basic description is you can pass an async function to
`startTransition` and all the transition updates that are scheduled
inside that async function will be grouped together. The `isPending`
flag will be set to true immediately, and only set back to false once
the async action has completed (as well as all the updates that it
triggers).

The ideal behavior would be that all updates spawned by the async action
are automatically inferred and grouped together; however, doing this
properly requires the upcoming (stage 2) Async Context API, which is not
yet implemented by browsers. In the meantime, we will fake this by
grouping together all transition updates that occur until the async
function has terminated. This can lead to overgrouping between unrelated
actions, which is not wrong per se, just not ideal.

If the `useTransition` hook is removed from the UI before an async
action has completed — for example, if the user navigates to a new page
— subsequent transitions will no longer be grouped with together with
that action.

Another consequence of the lack of Async Context is that if you call
`setState` inside an action but after an `await`, it must be wrapped in
`startTransition` in order to be grouped properly. If we didn't require
this, then there would be no way to distinguish action updates from
urgent updates caused by user input, too. This is an unfortunate footgun
but we can likely detect the most common mistakes using a lint rule.

Once Async Context lands in browsers, we can start warning in dev if we
detect an update that hasn't been wrapped in `startTransition`. Then,
longer term, once the feature is ubiquitous, we can rely on it for real
and allow you to call `setState` without the additional wrapper.

Things that are _not_ yet implemented in this PR, but will be added as
follow ups:

- Support for non-hook form of `startTransition`
- Canceling the async action scope if the `useTransition` hook is
deleted from the UI
- Anything related to server actions
2023-04-19 13:33:11 -04:00
Jan Kassens
6d394e3d26 [actions] commit from special branches iff they exist (#26673)
This creates 2 special branches. If these special branches exist, we'll
commit build artifacts from these branches, main otherwise.
2023-04-19 12:11:40 -04:00
Sebastian Markbåge
1f248bdd71 Switching checked to null should leave the current value (#26667)
I accidentally made a behavior change in the refactor. It turns out that
when switching off `checked` to an uncontrolled component, we used to
revert to the concept of "initialChecked" which used to be stored on
state.

When there's a diff to this computed prop and the value of props.checked
is null, then we end up in a case where it sets `checked` to
`initialChecked`:


5cbe6258bc/packages/react-dom-bindings/src/client/ReactDOMInput.js (L69)

Since we never changed `initialChecked` and it's not relevant if
non-null `checked` changes value, the only way this "change" could
trigger was if we move from having `checked` to having null.

This wasn't really consistent with how `value` works, where we instead
leave the current value in place regardless. So this is a "bug fix" that
changes `checked` to be consistent with `value` and just leave the
current value in place. This case should already have a warning in it
regardless since it's going from controlled to uncontrolled.

Related to that, there was also another issue observed in
https://github.com/facebook/react/pull/26596#discussion_r1162295872 and
https://github.com/facebook/react/pull/26588

We need to atomically apply mutations on radio buttons. I fixed this by
setting the name to empty before doing mutations to value/checked/type
in updateInput, and then set the name to whatever it should be. Setting
the name is what ends up atomically applying the changes.

---------

Co-authored-by: Sophie Alpert <git@sophiebits.com>
2023-04-19 11:46:29 -04:00
Ruslan Lesiutin
b90e8ebaa5 cleanup[devtools]: remove named hooks & profiler changed hook indices feature flags (#26635)
## Summary

Removing `enableNamedHooksFeature`, `enableProfilerChangedHookIndices`,
`enableProfilerComponentTree` feature flags, they are the same for all
configurations.
2023-04-19 10:05:31 +01:00
Ruslan Lesiutin
a227bcd4f4 chore[devtools/release-scripts]: update messages / fixed npm view com… (#26660)
Some minor changes, observed while working on 24.7.5 release:
- Updated numeration of text instructions
- `reactjs.org` -> `react.dev`
- Fixed using `npm view` command for node 16+, `publish-release` script
currently fails if used with node 16+
2023-04-19 10:05:16 +01:00
Joe Savona
a0777212df Propagate scope declarations to parent scopes
Fix for bug demonstrated in #1506. When we add variables as output of their 
defining scope, we need to propagate this information upwards to all parent 
scopes which are not current active.
2023-04-18 21:27:11 -07:00
Sophie Alpert
c6db19f9cd [Flight] Serialize Date (#26622)
This is kind of annoying because Date implements toJSON so
JSON.stringify turns it into a string before calling our replacer
function.
2023-04-18 20:52:03 -07:00
Mengdi Chen
96fd2fb726 (patch)[DevTools] bug fix: backend injection logic not working for undocked devtools window (#26665)
bugfix for #26492

This bug would cause users unable to use the devtools (component tree
empty).

The else-if logic is broken when user switch to undocked devtools mode
(separate window) because `sender.tab` would exist in that case.
<img width="314" alt="image"
src="https://user-images.githubusercontent.com/1001890/232930094-05a74445-9189-4d50-baf1-a0360b29ef7e.png">

Tested on Chrome with a local build
2023-04-18 20:39:22 -04:00
Joe Savona
fdbfac8f82 Repro for bug with memo vars at wrong block scope
Minimal(ish) repro of a bug we saw internally, where an output of a nested 
reactive scope is defined at the wrong block scope, and so later references to 
that value are invalid. 

The simplified structure is: 

``` 

scope0 inputs=[] outputs=[] { 

scope1 inputs=[] outputs=[t0] { 

t0 = ... 

} 

} 

t0 

``` 

Note that `t0` correctly appears as an output of the inner scope1, but not as an 
output of the outer scope0. We need to propagate outputs upward as necessary to 
ensure they are available at the right block scope: in this case, that would add 
`t0` as an output of scope0. 

An earlier version of PropagateScopeDependencies did this but it looks like it 
got lost along the way (not a big deal)
2023-04-18 16:10:00 -07:00
Joe Savona
746c1dbed5 Add common (Relay) hooks to playground environment
This aligns the playground configuration with our internal compiler 
configuration to make it easier to repro compilation issues on playground. There 
is a bug that doesn't repro right now and i suspect it's because of different 
hooks being configured. 

Test plan: 

Before: playground output has no obvious bugs, but is different than internal 
compilation output where the bug occurs 

After: playground output matches internal compilation output w the bug
2023-04-18 15:29:17 -07:00
Sebastian Markbåge
d8089f2cf2 [Flight Reply] Encode FormData (#26663)
Builds on top of https://github.com/facebook/react/pull/26661

This lets you pass FormData objects through the Flight Reply
serialization. It does that by prefixing each entry with the ID of the
reference and then the decoding side creates a new FormData object
containing only those fields (without the prefix).

Ideally this should be more generic. E.g. you should be able to pass
Blobs, Streams and Typed Arrays by reference inside plain objects too.
You should also be able to send Blobs and FormData in the regular Flight
serialization too so that they can go both directions. They should be
symmetrical. We'll get around to adding more of those features in the
Flight protocol as we go.

---------

Co-authored-by: Sophie Alpert <git@sophiebits.com>
2023-04-18 14:57:33 -04:00
Joe Savona
de89ed32a2 Use implicit return (undefined)
Making ReturnTerminal.value non-nullable broke our optimization to elide final 
value-less return statements. We now check if a return value is explicitly 
`undefined` and elide the value in this case, which then also propagates to 
allow removing the final `return` statement of a function if the value is 
missing.
2023-04-18 11:12:27 -07:00
Joe Savona
b10f60f2b9 Cleanup from non-nullable return value
Now that ReturnTerminal.value is non-nullable we can make 
ReactiveReturnTerminal.value also non-nullable, and remove a bunch of null 
checks.
2023-04-18 11:12:23 -07:00
Sophie Alpert
1b4a0daba8 Add assertions about <input> value dirty state (#26626)
Since this is an observable behavior and is hard to think about, seems
good to have tests for this.

The expected value included in each test is the behavior that existed
prior to #26546.
2023-04-18 11:03:36 -07:00
Sophie Alpert
b433c379d5 Fix input tracking bug (#26627)
In
2019ddc75f,
we changed to set .defaultValue before .value on updates. In some cases,
setting .defaultValue causes .value to change, and since we only set
.value if it has the wrong value, this resulted in us not assigning to
.value, which resulted in inputValueTracking not knowing the right
value. See new test added.

My fix here is to (a) move the value setting back up first and (b)
narrowing the fix in the aforementioned PR to newly remove the value
attribute only if it defaultValue was previously present in props.

The second half is necessary because for types where the value property
and attribute are indelibly linked (hidden checkbox radio submit image
reset button, i.e. spec modes default or default/on from
https://html.spec.whatwg.org/multipage/input.html#dom-input-value-default),
we can't remove the value attribute after setting .value, because that
will undo the assignment we just did! That is, not having (b) makes all
of those types fail to handle updating props.value.

This code is incredibly hard to think about but I think this is right
(or at least, as right as the old code was) because we set .value here
only if the nextProps.value != null, and we now remove defaultValue only
if lastProps.defaultValue != null. These can't happen at the same time
because we have long warned if value and defaultValue are simultaneously
specified, and also if a component switches between controlled and
uncontrolled.

Also, it fixes the test in https://github.com/facebook/react/pull/26626.
2023-04-18 10:49:32 -07:00
Mengdi Chen
d962f35cac [DevTools] use backend manager to support multiple backends in extension (#26615)
In the extension, currently we do the following:
1. check whether there's at least one React renderer on the page
2. if yes, load the backend to the page
3. initialize the backend 

To support multiple versions of backends, we are changing it to:
1. check the versions of React renders on the page
2. load corresponding React DevTools backends that are shipped with the
extension; if they are not contained (usually prod builds of
prereleases), show a UI to allow users to load them from UI
3. initialize each of the backends

To enable this workflow, a backend will ignore React renderers that does
not match its version

This PR adds a new file "backendManager" in the extension for this
purpose.


------
I've tested it on Chrome, Edge and Firefox extensions
2023-04-18 12:02:42 -04:00
Lauren Tan
0ddcaafd7c [babel] Inject React import if Forget compiled the function
Updates our Babel plugin to add an import to React if we succesfully compiled a 
function and cached one or more values. For now this logic is entirely in the 
Babel plugin itself, but long term we should move this into codegen and teach 
Forget to start the pipeline by lowering the whole Program node to an HIR (which 
would also allow us to understand imports and other module scope values being 
used). Right now it's not possible to add in codegen (without some ugly code) as 
a file containing multiple components would result in duplicate imports being 
generated
2023-04-17 17:49:17 -04:00
Sathya Gunasekaran
7c5e5eb30c [hir] Make return.value non nullable 2023-04-17 21:11:44 +01:00
Sathya Gunasekaran
42459f579f [hir] Return undefined explicitly if there's no return value
Future passes like inlineUseMemo assume there's a return value so let's create 
one instead of implicitly returning undefined.
2023-04-17 21:11:43 +01:00
Sathya Gunasekaran
0e34c39c58 [test] Add failing test for empty return in useMemo callback 2023-04-17 21:11:42 +01:00
Sathya Gunasekaran
00d4a69459 [hir] Refactor useMemo inlining
Previously useMemo inlining created a new StoreLocal assignment (not 
reassignment!) instruction for every return value. This breaks when the return 
is inside a block (like an if-block) as the  scope is tied to the block. 

For example: ``` let x = useMemo(() => {   if (...) {     return { ... };   } }) 
``` would become: ``` if (...) {   const temp = { ... }; } const x = temp; ``` 

This PR instead changes the inlining to declare a temporary in the function 
prologue and then reassign values to it when replacing return statements. 

``` let x = useMemo(() => {   if (...) {     return { ... };   } }) ``` 

becomes 

``` let temp; if (...) {   temp = { ... }; } const x = temp; ```
2023-04-17 20:59:35 +01:00
Sathya Gunasekaran
31f6dd8070 [test] Add failing test showing useMemo bug 2023-04-17 20:59:35 +01:00
Ruslan Lesiutin
77d3b02e5c React DevTools 4.27.4 -> 4.27.5 (#26637)
Full list of changes (not everything included in changelog):
* refactor[devtools]: copy to clipboard only on frontend side
([hoxyq](https://github.com/hoxyq) in
[#26604](https://github.com/facebook/react/pull/26604))
* Provide icon to edge devtools.
([harrygz889](https://github.com/harrygz889) in
[#26543](https://github.com/facebook/react/pull/26543))
* [BE] move shared types & constants to consolidated locations
([mondaychen](https://github.com/mondaychen) in
[#26572](https://github.com/facebook/react/pull/26572))
* remove backend dependency from the global hook
([mondaychen](https://github.com/mondaychen) in
[#26563](https://github.com/facebook/react/pull/26563))
* Replace deprecated `new-window` with
`webContents.setWindowOpenHandler()`
([Willie-Boy](https://github.com/Willie-Boy) in
[#26559](https://github.com/facebook/react/pull/26559))
* DevTools: Inline references to fiber flags
([acdlite](https://github.com/acdlite) in
[#26542](https://github.com/facebook/react/pull/26542))
* refactor[devtools]: forbid editing class instances in props
([hoxyq](https://github.com/hoxyq) in
[#26522](https://github.com/facebook/react/pull/26522))
* Move update scheduling to microtask
([acdlite](https://github.com/acdlite) in
[#26512](https://github.com/facebook/react/pull/26512))
* Remove unnecessary CIRCLE_CI_API_TOKEN checks
([mondaychen](https://github.com/mondaychen) in
[#26499](https://github.com/facebook/react/pull/26499))
* browser extension: improve script injection logic
([mondaychen](https://github.com/mondaychen) in
[#26492](https://github.com/facebook/react/pull/26492))
* [flow] make Flow suppressions explicit on the error
([kassens](https://github.com/kassens) in
[#26487](https://github.com/facebook/react/pull/26487))
2023-04-17 17:42:02 +01:00
Sebastian Markbåge
b6006201b5 Add a way to create Server Reference Proxies on the client (#26632)
This lets the client bundle encode Server References without them first
being passed from an RSC payload. Like if you just import `"use server"`
from the client. A bundler could already emit these proxies to be called
on the client but the subtle difference is that those proxies couldn't
be passed back into the server by reference. They have to be registered
with React.

We don't currently implement importing `"use server"` from client
components in the reference implementation. It'd need to expand the
Webpack plugin with a loader that rewrites files with the `"use server"`
in the client bundle.

```
"use server";

export async function action() {
   ...
}
```
->
```
import {createServerReference} from "react-server-dom-webpack/client";
import {callServer} from "some-router/call-server";

export const action = createServerReference('1234#action', callServer);
```

The technique I use here is that the compiled output has to call
`createServerReference(id, callServer)` with the `$$id` and proxy
implementation. We then return a proxy function that is registered with
a WeakMap to the particular instance of the Flight Client.

This might be hard to implement because it requires emitting module
imports to a specific stateful runtime module in the compiler. A benefit
is that this ensures that this particular reference is locked to a
specific client if there are multiple - e.g. talking to different
servers.

It's fairly arbitrary whether we use a WeakMap technique (like we do on
the client) vs an `$$id` (like we do on the server). Not sure what's
best overall. The WeakMap is nice because it doesn't leak implementation
details that might be abused to consumers. We should probably pick one
and unify.
2023-04-14 23:20:35 -04:00
Sebastian Markbåge
da6c23a45c [Flight] Fallback to importing the whole module instead of encoding every name (#26624)
We currently don't just "require" a module by its module id/path. We
encode the pair of module id/path AND its export name. That's because
with module splitting, a single original module can end up in two or
more separate modules by name. Therefore the manifest files need to
encode how to require the whole module as well as how to require each
export name.

In practice, we don't currently use this because we end up forcing
Webpack to deopt and keep it together as a single module, and we don't
even have the code in the Webpack plugin to write separate values for
each export name.

The problem is with CJS we don't statically know what all the export
names will be. Since these cases will never be module split, we don't
really need to know.

This changes the Flight requires to first look for the specific name
we're loading and then if that name doesn't exist in the manifest we
fallback to looking for the `"*"` name containing the entire module and
look for the name in there at runtime.

We could probably optimize this a bit if we assume that CJS modules on
the server never get built with a name. That way we don't have to do the
failed lookup.

Additionally, since we've recently merged filepath + name into a single
string instead of two values, we now have to split those back out by
parsing the string. This is especially unfortunate for server references
since those should really not reveal what they are but be a hash or
something. The solution might just be to split them back out into two
separate fields again.

cc @shuding
2023-04-14 21:09:09 -04:00
Sophie Alpert
2bfe4b246f [Flight] Fix style nit from #26623 (#26629)
Maybe this is faster.
https://github.com/facebook/react/pull/26623#discussion_r1167053174
2023-04-14 09:49:41 -07:00
Sophie Alpert
ab2385fa38 [Flight] Serialize weird numbers (#26623) 2023-04-14 09:28:48 -07:00
Rubén Norte
39a3b72c6d Post-process build files for React Native to add generated signature and @nolint (#26616)
## Summary

We're enabling a new mechanism to synchronize build files from `react`
to `react-native`. That new mechanism doesn't post-process files, so we
need to add that post-processing somewhere. This PR does that when
generating the files in the first place, so the generated files in the
`build` directory are ready to be committed in the `react-native`
repository directly.

This makes use of `signedsource` to avoid direct modifications of these
files in the `react-native` repository, as well as `@noformat` and
`@nolint` to prevent unactionable CI failures in that repository.

## How did you test this change?

Generated build files for `react-native` before and after this change:
```
node ./scripts/rollup/build-all-release-channels.js react-native
```

Checked new contents. Relevant changes:

```diff
diff --color -r build-before/react-native/implementations/ReactFabric-dev.fb.js build-after/react-native/implementations/ReactFabric-dev.fb.js
10c10
<  * @generated
---
>  * @generated SignedSource<<03cef14e77b8250b567dfdf3b066085e>>
diff --color -r build-before/react-native/implementations/ReactFabric-dev.js build-after/react-native/implementations/ReactFabric-dev.js
11c11
<  * @generated
---
>  * @generated SignedSource<<e39eed38a363846ca9ee9b59a225683c>>
diff --color -r build-before/react-native/implementations/ReactFabric-prod.fb.js build-after/react-native/implementations/ReactFabric-prod.fb.js
10c10
<  * @generated
---
>  * @generated SignedSource<<f65efcd6a469d5f6fef1ce647e5ec09a>>
diff --color -r build-before/react-native/implementations/ReactFabric-prod.js build-after/react-native/implementations/ReactFabric-prod.js
11c11
<  * @generated
---
>  * @generated SignedSource<<cdd582aa889b1054b2c5faf412622b18>>
diff --color -r build-before/react-native/implementations/ReactFabric-profiling.fb.js build-after/react-native/implementations/ReactFabric-profiling.fb.js
10c10
<  * @generated
---
>  * @generated SignedSource<<81e74849b24f104882bd298f062be0fa>>
diff --color -r build-before/react-native/implementations/ReactFabric-profiling.js build-after/react-native/implementations/ReactFabric-profiling.js
11c11
<  * @generated
---
>  * @generated SignedSource<<c050b7fa1453dc21ac1c5b98146210a8>>
diff --color -r build-before/react-native/implementations/ReactNativeRenderer-dev.fb.js build-after/react-native/implementations/ReactNativeRenderer-dev.fb.js
10c10
<  * @generated
---
>  * @generated SignedSource<<9c03464b489b41c06a065aeba8619263>>
diff --color -r build-before/react-native/implementations/ReactNativeRenderer-dev.js build-after/react-native/implementations/ReactNativeRenderer-dev.js
11c11
<  * @generated
---
>  * @generated SignedSource<<18b34c037544949dcf9b28f945921ba8>>
diff --color -r build-before/react-native/implementations/ReactNativeRenderer-prod.fb.js build-after/react-native/implementations/ReactNativeRenderer-prod.fb.js
10c10
<  * @generated
---
>  * @generated SignedSource<<592e9654c584d1da523378b119bd8bd7>>
diff --color -r build-before/react-native/implementations/ReactNativeRenderer-prod.js build-after/react-native/implementations/ReactNativeRenderer-prod.js
11c11
<  * @generated
---
>  * @generated SignedSource<<91c894db99e2d76f8a32708ad6ad1bde>>
diff --color -r build-before/react-native/implementations/ReactNativeRenderer-profiling.fb.js build-after/react-native/implementations/ReactNativeRenderer-profiling.fb.js
10c10
<  * @generated
---
>  * @generated SignedSource<<5ce378a9216ea747d91b208b9fd1ebd5>>
diff --color -r build-before/react-native/implementations/ReactNativeRenderer-profiling.js build-after/react-native/implementations/ReactNativeRenderer-profiling.js
11c11
<  * @generated
---
>  * @generated SignedSource<<1c7564f446ee83142976035b2884dcfd>>
diff --color -r build-before/react-native/shims/ReactFabric.js build-after/react-native/shims/ReactFabric.js
7c7
<  * @format
---
>  * @noformat
8a9,10
>  * @nolint
>  * @generated SignedSource<<cece19ddbec9f287c995721f49c68977>>
diff --color -r build-before/react-native/shims/ReactFeatureFlags.js build-after/react-native/shims/ReactFeatureFlags.js
7c7
<  * @format
---
>  * @noformat
8a9,10
>  * @nolint
>  * @generated SignedSource<<2881c8e89ef0f73f4cf6612cb518b197>>
diff --color -r build-before/react-native/shims/ReactNative.js build-after/react-native/shims/ReactNative.js
7c7
<  * @format
---
>  * @noformat
8a9,10
>  * @nolint
>  * @generated SignedSource<<0debd6e5a17dc037cb4661315a886de6>>
diff --color -r build-before/react-native/shims/ReactNativeTypes.js build-after/react-native/shims/ReactNativeTypes.js
7c7
<  * @format
---
>  * @noformat
8a9,10
>  * @nolint
>  * @generated SignedSource<<652b117c94307244bcf5e4af18928903>>
diff --color -r build-before/react-native/shims/ReactNativeViewConfigRegistry.js build-after/react-native/shims/ReactNativeViewConfigRegistry.js
7c7
<  * @format
---
>  * @noformat
8a9,10
>  * @nolint
>  * @generated SignedSource<<ce82e8957367bee7d11379ab88e3f7c5>>
diff --color -r build-before/react-native/shims/createReactNativeComponentClass.js build-after/react-native/shims/createReactNativeComponentClass.js
7c7
<  * @format
---
>  * @noformat
8a9,10
>  * @nolint
>  * @generated SignedSource<<ede54ac2fa1b9a09e234cdf098048989>>
```
2023-04-14 11:42:48 +02:00
Tianyu Yao
d121c67004 Synchronously flush the transition lane scheduled in a popstate event (#26025)
<!--
  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

Browsers restore state like forms and scroll position right after the
popstate event. To make sure the page work as expected on back or
forward button, we need to flush transitions scheduled in a popstate
synchronously, and only yields if it suspends.
This PR adds a new HostConfig method to check if `window.event ===
'popstate'`, and `scheduleMicrotask` if a transition is scheduled in a
`PopStateEvent`.

## How did you test this change?

yarn test
2023-04-13 15:21:19 -04:00
Samuel Susla
7b0642bb98 Remove revertRemovalOfSiblingPrerendering killswitch (#26549)
removal of sibling prerendering has been rolled out at Meta. We can
delete the flag now.
2023-04-12 21:05:17 -04:00
Andrew Clark
8256781fdf Throttle retries even if everything has loaded (#26611)
If a Suspense fallback is shown, and the data finishes loading really
quickly after that, we throttle the content from appearing for 500ms to
reduce thrash.

This already works for successive fallback states (like if one fallback
is nested inside another) but it wasn't being applied to the final step
in the sequence: if there were no more unresolved Suspense boundaries in
the tree, the content would appear immediately.

This fixes the throttling behavior so that it applies to all renders
that are the result of suspended data being loaded. (Our internal jargon
term for this is a "retry".)
2023-04-12 20:25:32 -04:00
Andrew Clark
72c890e312 Convert more Suspense tests to use act (2/n) (#26610)
Many of our Suspense-related tests were written before the `act` API was
introduced, and use the lower level `waitFor` helpers instead. So they
are less resilient to changes in implementation details than they could
be.

This converts some of our test suite to use `act` in more places. I
found these while working on a PR to expand our fallback throttling
mechanism to include all renders that result from a promise resolving,
even if there are no more fallbacks in the tree.

I think this covers all the remaining tests that are affected.
2023-04-12 13:36:13 -04:00
Ruslan Lesiutin
21021fb0f0 refactor[devtools]: copy to clipboard only on frontend side (#26604)
Fixes https://github.com/facebook/react/issues/26500

## Summary
- No more using `clipboard-js` from the backend side, now emitting
custom `saveToClipboard` event, also adding corresponding listener in
`store.js`
- Not migrating to `navigator.clipboard` api yet, there were some issues
with using it on Chrome, will add more details to
https://github.com/facebook/react/pull/26539

## How did you test this change?
- Tested on Chrome, Firefox, Edge
- Tested on standalone electron app: seems like context menu is not
expected to work there (cannot right-click on value, the menu is not
appearing), other logic (pressing on copy icon) was not changed
2023-04-12 16:12:03 +01:00
Harry Zumwalt
5426af3d50 Provide icon to edge devtools. (#26543)
<!--
  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
Addresses #26352.

This PR explicitly passes an icon to `chrome.devtools.panels.create()`,
so that edge devtools will display the icon when in [Focus
Mode](https://learn.microsoft.com/en-us/microsoft-edge/devtools-guide-chromium/experimental-features/focus-mode).

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

## How did you test this change?
Passing test suite (`yarn test` & `yarn test --prod`)  
Passing lint (`yarn linc`)  
Passing type checks (`yarn flow`)  

**Visual Testing**

Before Changes             | After Changes
:-------------------------:|:-------------------------:

![](https://user-images.githubusercontent.com/15645169/229591145-fe99df06-e2e3-4f21-ae31-f770d584ca6c.png)
|
![](https://user-images.githubusercontent.com/15645169/229591594-26c6cbaf-f345-4367-b234-8f3c8ab3ccb1.png)
<!--
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.
-->
2023-04-11 14:42:13 -04:00
Andrew Clark
f9de24a26a Convert more Suspense tests to use act (#26602)
Many of our Suspense-related tests were written before the `act` API was
introduced, and use the lower level `waitFor` helpers instead. So they
are less resilient to changes in implementation details than they could
be.

This converts some of our test suite to use `act` in more places. I
found these while working on a PR to expand our fallback throttling
mechanism to include all renders that result from a promise resolving,
even if there are no more fallbacks in the tree. This isn't all the
affected tests, just some of them — I'll be sharding the changes across
multiple PRs.
2023-04-11 13:47:29 -04:00
Sebastian Markbåge
6b90976bc1 Use already extracted values instead of reading off props for controlled components (#26596)
Since `props.x` is a possibly megamorphic access, it can be slow to
access and trigger recompilation.

When we are looping over the props and pattern matching every key,
anyway, we've already done this work. We can just reuse the same value
by stashing it outside the loop in the stack.

This only makes sense for updates in diffInCommitPhase since otherwise
we don't have the full set of props in that loop.

We also have to be careful not to skip over equal values since we need
to extract them anyway.
2023-04-11 13:32:47 -04:00
Sebastian Markbåge
343a45ffa4 Remove initOption special case (#26595)
This traces back to https://github.com/facebook/react/pull/6449 and then
another before that.

I think that back then we favored the property over the attribute, and
setting the property wouldn't be enough. However, the default path for
these are now using attributes if we don't special case it. So we don't
need it.

The only difference is that we currently have a divergence for
symbol/function behavior between controlled values that use the
getToStringValue helpers which treat them as empty string, where as
everywhere else they're treated as null/missing.

Since this comes with a warning and is a weird error case, it's probably
fine to change.
2023-04-11 12:39:00 -04:00
Sathya Gunasekaran
34bca247d6 [hir] Terminate function within BuildHIR
All the block building logic is encapsulated in BuildHIR.
2023-04-11 15:40:08 +01:00
Sathya Gunasekaran
c42cd3f558 [hir] Refactor HIRBuilder.build to use HIRBuilder.terminate
It's a bit weird  that HIRBuilder is generating terminals, a follow up PR will 
remove this entirely from HIRBuilder. This is a first step towards that.
2023-04-11 15:37:20 +01:00
Sathya Gunasekaran
7678a52c9c [hir] Add invariant to check if useMemo callback is async or a generator 2023-04-11 15:06:53 +01:00
Sathya Gunasekaran
fd252e42ab [hir] Add invariant to check if useMemo callback accepts args 2023-04-11 15:00:30 +01:00
Sathya Gunasekaran
74f5e26e00 [be][test] Remove hir-test 2023-04-11 13:41:33 +01:00
Sathya Gunasekaran
2d8b36467c [hir] Put useMemo inlining behind a flag
It's still a WIP so disable behind a flag for now.
2023-04-11 13:41:33 +01:00
Andrew Clark
58742c21b8 Delete unused eventTimes Fiber field (#26599) 2023-04-11 08:23:04 -04:00
Andrew Clark
0b931f90e8 Remove JND delay for non-transition updates (#26597)
Updates that are marked as part of a transition are allowed to block a
render from committing. Generally, other updates cannot — however,
there's one exception that's leftover from a previous iteration of our
Suspense architecture. If an update is not the result of a known urgent
event type — known as "Default" updates — then we allow it to suspend
briefly, as long as the delay is short enough that the user won't
notice. We refer to this delay as a "Just Noticable Difference" (JND)
delay. To illustrate, if the user has already waited 400ms for an update
to be reflected on the screen, the theory is that they won't notice if
you wait an additional 100ms. So React can suspend for a bit longer in
case more data comes in. The longer the user has already waited, the
longer the JND.

While we still believe this theory is sound from a UX perspective, we no
longer think the implementation complexity is worth it. The main thing
that's changed is how we handle Default updates. We used to render
Default updates concurrently (i.e. they were time sliced, and were
scheduled with postTask), but now they are blocking. Soon, they will
also be scheduled with rAF, too, which means by the end of the next rAF,
they will have either finished rendering or the main thread will be
blocked until they do. There are various motivations for this but part
of the rationale is that anything that can be made non-blocking should
be marked as a Transition, anyway, so it's not worth adding
implementation complexity to Default.

This commit removes the JND delay for Default updates. They will now
commit immediately once the render phase is complete, even if a
component suspends.
2023-04-11 00:19:49 -04:00
Sebastian Markbåge
ac43bf6870 Move validation of text nesting into ReactDOMComponent (#26594)
Extract validateTextNesting from validateDOMNesting. We only need the
parent tag when validating text nodes. Then validate it in setProp.
2023-04-10 21:41:53 -04:00
Sebastian Markbåge
ca41adb8c1 Diff properties in the commit phase instead of generating an update payload (#26583)
This removes the concept of `prepareUpdate()`, behind a flag.

React Native already does everything in the commit phase, but generates
a temporary update payload before applying it.

React Fabric does it both in the render phase. Now it just moves it to a
single host config.

For DOM I forked updateProperties into one that does diffing and
updating in one pass vs just applying a pre-diffed updatePayload.

There are a few downsides of this approach:

- If only "children" has changed, we end up scheduling an update to be
done in the commit phase. Since we traverse through it anyway, it's
probably not much extra.
- It does more work in the commit phase so for a large tree that is
mostly unchanged, it'll stall longer.
- It does some extra work for special cases since that work happens if
anything has changed. We no longer have a deep bailout.
- The special cases now have to each replicate the "clean up old props"
loop, leading to extra code.

The benefit is that this doesn't allocate temporary extra objects
(possibly multiple per element if the array has to resize). It's less
work overall. It also gives us an option to reuse this function for a
sync render optimization.

Another benefit is that if we do the loop in the commit phase I can do
further optimizations by reading all props that I need for special cases
in that loop instead of polymorphic reads from props. This is what I'd
like to do in future refactors that would be stacked on top of this
change.
2023-04-10 19:09:28 -04:00
Josh Story
dd0619b2ee rename $$$hostConfig to $$$config (#26593)
We have moved away from HostConfig since the name does not fully
describe the configs we customize per runtime like FlightClient,
FlightServer, Fizz, and Fiber. This commit generalizes $$$hostconfig to
$$$config
2023-04-10 15:01:04 -07:00
Josh Story
b55d319559 Rename HostConfig files to FiberConfig to clarify they are configs fo… (#26592)
part of https://github.com/facebook/react/pull/26571

merging separately to improve tracking of files renames in git

Rename HostConfig files to FiberConfig to clarify they are configs for
Fiber and not Fizz/Flight. This better conforms to the naming used in
Flight and now Fizz of `ReactFlightServerConfig` and `ReactFizzConfig`
2023-04-10 14:58:44 -07:00
Josh Story
ffb8eaca59 Rename ReactServerFormatConfig to ReactFizzConfig (#26591)
part of https://github.com/facebook/react/pull/26571

merging separately to improve tracking of file renames
2023-04-10 14:54:26 -07:00
Josh Story
f4f873f628 Implements wiring for Flight to have it's own "HostConfig" (#26590)
Part of https://github.com/facebook/react/pull/26571

Implements wiring for Flight to have it's own "HostConfig" from Fizz.

Historically the ServerFormatConfigs were supposed to be generic enough
to be used by Fizz and Flight. However with the addition of features
like Float the configs have evolved to be more specific to the renderer.
We may want to get back to a place where there is a pure FormatConfig
which can be shared but for now we are embracing the fact that these
runtimes need very different things and DCE cannot adequately remove the
unused stuff for Fizz when pulling this dep into Flight so we are going
to fork the configs and just maintain separate ones.

At first the Flight config will be almost empty but once Float support
in Flight lands it will have a more complex implementation

Additionally this commit normalizes the component files which make up
FlightServerConfig and FlightClientConfig. Now each file that
participates starts with ReactFlightServerConfig... and
ReactFlightClientConfig...
2023-04-10 14:51:54 -07:00
Josh Story
44db16afc6 Normalize ReactFlightServerConfig and related files (#26589)
First part of https://github.com/facebook/react/pull/26571

merging separately to help with git history with a lot of file renames
2023-04-10 14:47:23 -07:00
Mengdi Chen
451736b557 [DevTools][BE] move shared types & constants to consolidated locations (#26572)
## Summary

This pull request aims to improve the maintainability of the codebase by
consolidating types and constants that are shared between the backend
and frontend. This consolidation will allow us to maintain backwards
compatibility in the frontend in the future.

To achieve this, we have moved the shared types and constants to the
following blessed files:

- react-devtools-shared/src/constants
- react-devtools-shared/src/types
- react-devtools-shared/src/backend/types
- react-devtools-shared/src/backend/NativeStyleEditor/types

Please note that the inclusion of NativeStyleEditor in this list is
temporary, and we plan to remove it once we have a better plugin system
in place.

## How did you test this change?

I have tested it by running `yarn flow dom-node`, which reports no
errors.
2023-04-10 17:07:05 -04:00
Andrew Clark
fec97ecbc4 act: Move didScheduleLegacyUpdate to ensureRootIsScheduled (#26552)
`act` uses the `didScheduleLegacyUpdate` field to simulate the behavior
of batching in React <17 and below. It's a quirk leftover from a
previous implementation, not intentionally designed.

This sets `didScheduleLegacyUpdate` every time a legacy root receives an
update as opposed to only when the `executionContext` is empty. There's
no real reason to do it this way over some other way except that it's
how it used to work before #26512 and we should try our best to maintain
the existing behavior, quirks and all, since existing tests may have
come to accidentally rely on it.

This should fix some (though not all) of the internal Meta tests that
started failing after #26512 landed.

Will add a regression test before merging.
2023-04-10 14:40:18 -04:00
Joe Savona
67b0cf8a8c Comments from #1484 2023-04-10 11:06:10 -07:00
Sebastian Markbåge
9a9da7721e Don't update textarea defaultValue and input checked unnecessarily (#26580)
In #26573 I changed it so that textareas get their defaultValue reset if
you don't specify one.

However, the way that was implemented, it always set it for any update
even if it hasn't changed.

We have a test for that, but that test only works if no properties
update at all so that no update was scheduled. This fixes the test so
that it updates some unrelated prop.

I also found a test for `checked` that needed a similar fix.

Interestingly, we don't do this deduping for `defaultValue` or
`defaultChecked` on inputs and there's no test for that.
2023-04-09 22:16:38 -04:00
Sebastian Markbåge
e5146cb525 Refactor some controlled component stuff (#26573)
This is mainly renaming some stuff. The behavior change is
hasOwnProperty to nullish check.

I had a bigger refactor that was a dead-end but might as well land this
part and see if I can pick it up later.
2023-04-09 18:06:16 -04:00
Joe Savona
601eb2a23a Inline useMemo callbacks to allow improved memoization
This is a simplified version of #1454. The goal of this PR is to inline the 
contents of `useMemo()` callbacks, rather than just immediately invoke the 
lambda. Turning useMemo() into an IIFE works, but it means that we can't 
optimize within the lambda block. Our investigations showed that there's a lot 
of room to optimize at a finer granularity than manually written useMemo calls. 
For example, one product instance had a useMemo that created a list of child JSX 
elements. Most of those elements only relied on a single variable (`a`), but a 
few relied on a second variable (`b). Thus _all_ elements were invalidated 
whenever `b` changed. If Forget retains the original lambda, we have no choice 
but to keep that (coarse) granularity for memoization. When we inline, we can 
optimize to make e.g. individual JSX elements depend on their precise 
dependencies. 

The rough idea is: 

* Keep track of all function expressions 

* When we find a useMemo, lookup its function expression, and add its CFG to the 
main function (the previous PR ensures that BlockIds won't collide) 

* Replace any return statements with a StoreLocal to save the result and a Goto 
to the code following the useMemo call. 

* Then we run the usual set of passes to patch the HIR back up again. 

Example: 

```javascript 

// Before 

function Component(props) { 

const x = useMemo(() => { 

if (props.cond) { 

return null; 

} 

return foo(props.x); 

}, [props.x]); 

return x + props.y; 

} 

// Intended - **before** memoization 

function Component(props) { 

let x; 

if (props.cond) { 

x = null; 

} else { 

x = foo(props.x); 

} 

return x + props.y; 

} 

```
2023-04-07 16:34:52 -07:00
Joe Savona
f7f7a88e19 Example suboptimal memoization with non-inlined useMemo 2023-04-07 16:34:51 -07:00
Josh Story
657698e48d [Tests] waitForThrow should diff strings (#26568)
Currently, `waitForThrow` tries to diff the expected value against the
thrown value if it doesn't match. However if the expectation is a
string, we are not diffing against the thrown message. This commit makes
it so if we are matching against message we also diff against message.
2023-04-07 14:14:08 -07:00
Mengdi Chen
dd5365878d [DevTools] remove backend dependency from the global hook (#26563)
## Summary

- #26234 is reverted and replaced with a better approach 
- introduce a new global devtools variable to decouple the global hook's
dependency on backend/console.js, and add it to react-devtools-inline
and react-devtools-standalone

With this PR, I want to introduce a new principle to hook.js: we should
always be alert when editing this file and avoid importing from other
files.
In the past, we try to inline a lot of the implementation because we use
`.toString()` to inject this function from the extension (we still have
some old comments left). Although it is no longer inlined that way, it
has became now more important to keep it clean as it is a de facto
global API people are using (9.9K files contains it on Github search as
of today).


**File size change for extension:**
Before:
379K installHook.js

After:
 21K installHook.js
363K renderer.js
2023-04-07 03:35:36 -04:00
Joe Savona
6122f21393 Definition for useContext 2023-04-06 11:46:57 -07:00
Joe Savona
f51e2a6bf4 Enforce terminal has a .loc (and .id)
This PR ensures (via a static assertion function) that all terminal variants 
have a SourceLocation, and adds locations to the variants which didn't have it 
before. This also adds a static assertion that terminals have an InstructionId, 
though we already relied on that so it was checked via usage.
2023-04-06 15:50:43 -07:00
Joe Savona
5622c0ee91 Use single name resolver for nested functions
This is a prerequisite to inlining `useMemo()` lambdas so that we can better 
optimize them. Nested functions are evaluated with a fresh HIRBuilder, which 
means that they currently have their own `bindings` object for mapping 
identifier instances to IdentifierIds. This means that identifier ids in a 
closure are _always_ different that those outside the closure, even when they 
refer to the same identifier: 

``` 

function Component(props) { 

props; // becomes e.g. props$1 

const onClick = () => { 

props // becomes e.g. props$2 

}; 

} 

``` 

For useMemo inlining this is problematic because we've lost the association that 
these identifiers actually refer to the same thing. This PR changes that, 
sharing the name resolution data structure between the top-level function and 
any nested function expressions.
2023-04-06 15:25:30 -07:00
Lauren Tan
fcfb66914a [Babel] Skip files that contain one or more disables of React eslint rules
To unblock internal experimentation, for now let's just skip over compiling any 
file that contains one or more disables of React's eslint rules, and log that. 
This is a little coarse in the sense that we could skip over just functions that 
contain the comments, but Babel doesn't provide an easy way to traverse comments 
afaict so this is the simplest solution. I did check our internal repo and noted 
that there was only one disable of exhaustive-hooks in that entire directory in 
one file, so this should be fine. 

Notably we are not throwing any errors if we detect these violations as we don't 
want to fail the build, we just want to skip them for now.
2023-04-06 19:14:08 -04:00
Lauren Tan
2eae7dc6b9 [be] Simplify yarn test
Updates our scripts to only hash and clean up`dist` when bundling for Meta, 
since we don't need to do that for tests.
2023-04-06 19:10:21 -04:00
Andrew Clark
85bb7b685b Fix: Move destroy field to shared instance object (#26561)
This fixes the "double free" bug illustrated by the regression test
added in the previous commit.

The underlying issue is that `effect.destroy` field is a mutable field
but we read it during render. This is a concurrency bug — if we had a
borrow checker, it would not allow this.

It's rare in practice today because the field is updated during the
commit phase, which takes a lock on the fiber tree until all the effects
have fired. But it's still theoretically wrong because you can have
multiple Fiber copies each with their own reference to a single destroy
function, and indeed we discovered in production a scenario where this
happens via our current APIs.

In the future these types of scenarios will be much more common because
we will introduce features where effects may run concurrently with the
render phase — i.e. an imperative `hide` method that synchronously hides
a React tree and unmounts all its effects without entering the render
phase, and without interrupting a render phase that's already in
progress.

A future version of React may also be able to run the entire commit
phase concurrently with a subsequent render phase. We can't do this now
because our data structures are not fully thread safe (see: the Fiber
alternate model) but we should be able to do this in the future.

The fix I've introduced in this commit is to move the `destroy` field to
a separate object. The effect "instance" is a shared object that remains
the same for the entire lifetime of an effect. In Rust terms, a RefCell.
The field is `undefined` if the effect is unmounted, or if the effect
ran but is not stateful. We don't explicitly track whether the effect is
mounted or unmounted because that can be inferred by the hiddenness of
the fiber in the tree, i.e. whether there is a hidden Offscreen fiber
above it.

It's unfortunate that this is stored on a separate object, because it
adds more memory per effect instance, but it's conceptually sound. I
think there's likely a better data structure we could use for effects;
perhaps just one array of effect instances per fiber. But I think this
is OK for now despite the additional memory and we can follow up with
performance optimizations later.

---------

Co-authored-by: Dan Abramov <dan.abramov@gmail.com>
Co-authored-by: Rick Hanlon <rickhanlonii@gmail.com>
Co-authored-by: Jan Kassens <jan@kassens.net>
2023-04-06 12:08:05 -04:00
Joe Savona
9c1f8a962c Make CompilerError.reason a static string
While running the latest Forget build on www I noticed that a lot of the 
bailouts were special-cases where we used interpolation in the error `reason` 
string to provide more context for debugging. This is a pretty cool result, 
because it means that we actually support nearly all the common syntax (at least 
based on a sample of the codebase). But it makes our tools for aggregating 
errors break down a bit. 

This PR adds a new, nullable `description` property to CompilerErrorDetail, and 
manually updates to ensure that we always pass a static `reason` and only use 
interpolation in the `description`. This will allow our aggregation tools to 
group by the reason.
2023-04-06 08:51:31 -07:00
Willie-Boy
60cfeeebe3 [DevTools] Replace deprecated new-window with webContents.setWindowOpenHandler() (#26559)
## Summary

The electron package was recently upgraded from ^11.1.0 to ^23.1.2
(#26337). However, the WebContents `new-window` event – that is used in
the react-devtools project – was deprecated in
[v12.0.0](https://releases.electronjs.org/release/v12.0.0) and removed
in [v22.2.0](https://releases.electronjs.org/release/v22.2.0). The event
was replaced by `webContents.setWindowOpenHandler()`. This PR replaces
the `new-window` event with `webContents.setWindowOpenHandler()`.

## How did you test this change?

I created a simple electron application with similar functionality:

```
const { app, BrowserWindow, shell } = require('electron')

const createWindow = () => {
  const mainWindow = new BrowserWindow({
    width: 800,
    height: 600
  })

  mainWindow.webContents.setWindowOpenHandler(({ url }) => {
    shell.openExternal(url)
    return { action: 'deny' }
  })

  mainWindow.loadFile('index.html')
}

app.whenReady().then(() => {
  createWindow()
})
```

---------

Co-authored-by: root <root@DESKTOP-KCGHLB8.localdomain>
2023-04-06 10:02:23 -04:00
Sebastian Markbåge
9cfba0f6ec Clean up discrete event replaying (#26558)
We no longer replay and discrete events.

I might re-add a form of this but it'll look a little different.
2023-04-05 19:38:20 -04:00
Joe Savona
702f43eb1e Optimize away extraneous blocks
In codegen we can flatten away extraneous BlockStatements if they turn out not 
to need a label.
2023-04-05 16:37:26 -07:00
Joe Savona
d243e748d0 Build -> Codegen for LabelTerminal
NOTE: See background in #1476. 

Updates BuildHIR to use the new LabelTerminal for LabeledStatements, and adds 
support for HIR->ReactiveFunction transformation and codegen. Note that we 
sometimes produce an extraneous block wrapper if it turns out the label wasn't 
necessary, that seems...fine?
2023-04-05 16:26:40 -07:00
Joe Savona
b087635e5d LabelTerminal scaffolding
Adds a new `LabelTerminal` which will be used to represent LabeledStatements 
that contain a statement other than a loop. What we do for these cases is 
basically break the containing block in two, with a goto after the inner 
statement to the fallthrough. This allows us to model the label, and any `break` 
to it, in the HIR. However this fails in codegen because we can't find the 
fallthrough branch — we need a high level terminal that knows about this 
structure. 

Hence LabelTerminal. Now, instead of just a continuation block and a goto, we 
have a structured terminal. The LabelTerminal expresses the block for the 
labeled statement and the continuation, and we can use this to put it back 
together when constructing a ReactiveFunction. Note that this PR is just the 
scaffolding for LabelTerminal, the next PR is the interesting bits.
2023-04-05 16:26:36 -07:00
Joe Savona
592b911e7f fix main 2023-04-05 15:47:40 -07:00
Joe Savona
1650d8fef2 Ensure blank line after copyright header 2023-04-05 13:42:27 -07:00
Joe Savona
801e4258cf Add missing copyright headers 2023-04-05 12:21:51 -07:00
Joe Savona
fd91191c94 Script to add/fix copyright
Adds a script to automate adding/updating the copyright header to all 
appropriate files. For now i've excluded fixture inputs, just because it would 
impact fixture outputs too, but we can add them in a later PR if we want.
2023-04-05 12:21:47 -07:00
mofeiZ
9d97015236 [globals] Remove global shape for Array.from
Type inference currently assumes that a `FunctionSignature`'s effects have no 
false positives. If a `mutate` effect is observed on a read-only place, Forget 
currently assumes this is an user error and 
[throws](207595e04e/forget/src/Inference/InferReferenceEffects.ts (L275-L281)). 

Array.from is polymorphic -- its effects are dependent on the type of its 
parameters
2023-04-05 12:53:39 -04:00
Joe Savona
4505218911 Ensure unique BlockId for nested functions
This PR ensures that we use a single id space for the `BlockId`s in both 
top-level functions as well as any nested FunctionExpressions (note, we already 
do this for `IdentifierId`). This will make it easier for follow-ups to merge 
the CFG of nested functions (ie useMemo bodies) with the parent without block id 
collisions.
2023-04-05 09:01:08 -07:00
Sophie Alpert
790ebc962d Remove no-fallthrough lint suppressions (#26553)
The lint rule already understands a normal comment. Also a bunch of
these were unnecessary.
2023-04-04 20:08:33 -07:00
Joe Savona
a3dfc7e3a2 Use CompilerError.invariant in BabelPlugin
This means we get more information when we hit these invariants (ie the source 
location)
2023-04-04 17:56:11 -07:00
Sebastian Markbåge
c15579631f Put common aliases in Map/Set instead of switch over strings (#26551)
This is a follow up to https://github.com/facebook/react/pull/26546

This is strictly a perf optimization since we know that switches over
strings aren't optimally implemented in current engines. Basically
they're a sequence of ifs.

As a result, we're better off putting the unusual cases in a Map and the
very common cases in the beginning of the switch. We might be better off
putting very common cases in explicit ifs - just in case the engine does
optimize switches to a hash table which is potentially worse.

---------

Co-authored-by: Sophie Alpert <git@sophiebits.com>
2023-04-04 18:06:09 -04:00
Joe Savona
1e2dbf7fdb Fix JSX form of fbt
Fixes `<fbt>`. This required a bunk of yak shaving to work through several 
issues: 

* First, there was a bug in codegen for JsxNamedspacedName. I added handling for 
it for identifiers, but JsxNamespacedName gets converted to a Primitive. The 
output looked correct because Babel happily creates invalid Jsx identifiers! 

* Next, I needed to add locations to JSX nodes. It took me a while to pinpoint 
which specific node needed the location, so I ended up just adding locations to 
all the parts of a Jsx element. 

* That uncovered the fact that FBT was expecting the `<fbt:param>`'s `name` 
attribute value to be a StringLiteral, not a StringLiteral wrapped in a 
JsxExpressionContainer. So now we special-case JsxAttribute and emit raw 
StringLiteral (either is allowed per the spec) 

And with that, voila, `<fbt>` works.
2023-04-04 14:37:30 -07:00
Joe Savona
3c46984e09 Repro of fbt issues
Adds the two FBT (https://facebook.github.io/fbt/) plugins to our test setup so 
that we can verify Forget plays well with FBT. Unfortunately FBT's plugins are a 
bit finicky, and things that are technically allowed per the JSX spec (such as 
wrapping string attribute values in a JsxExpressionContainer) aren't supported 
by FBT's plugin. This PR is just to add the fbt plugins and highlight some cases 
that fail; these are fixed in later PRs in the stack. 

For example, the `fbt-params.js` fixture fails on this PR: 

Input 

```error.fbt-params.js 

import fbt from "fbt"; 

function Component(props) { 

return ( 

<fbt desc={"Dialog to show to user"}> 

Hello <fbt:param name="user name">{props.name}</fbt:param> 

</fbt> 

); 

} 

``` 

Output 

``` 

React Forget › __tests__/fixtures/compiler › fixtures › fbt-params 

Expected fixture 'fbt-params' to succeed but it failed with error: 

/Users/joesavona/github/react-forget/forget/fbt-params: fbt: unsupported babel 
node: MemberExpression 

--- 

props.name 

--- 

``` 

See fixes later in the stack.
2023-04-04 14:32:21 -07:00
Joe Savona
a97c55dc5d Support for with empty update expression
Adds support for `for` statements with an empty or unreachable update 
expression. In both cases, reversePostorderBlocks() will remove the 
empty/unreachable update block, leaving the ForTerminal.update pointing to a 
non-existent block. We explicitly rewrite this (much like we null out 
unreachable fallthroughs after shrink). When transforming to ReactiveFunction, 
we emit the update block as null if it was the same as the test block.
2023-04-04 13:29:04 -07:00
Joe Savona
1d77016026 Make ReactiveForTerminal.update nullable
Makes ReactiveForTerminal.update nullable, allowing the update clause to be 
omitted. Follow-up diffs null out the update clause in some circumstances.
2023-04-04 13:29:03 -07:00
Joe Savona
d660f37bf2 Validator pass that terminal successors all exist 2023-04-04 13:29:02 -07:00
Joe Savona
6d62d9f505 Infer closures as frozen if they dont capture mutable values
Fix for the previous issue, suggested by @gsathya: when we run 
InferReferenceEffects on the outer function we check each closure to see if it 
actually captured any mutable values. If it didn't, we can mark the closure as 
readonly and memoize it independently.
2023-04-04 12:30:12 -07:00
Joe Savona
939582dae0 Repro for unmemoized readonly callback
Repro of a closure that we currently treat as readonly because it captures a 
possibly-mutable value, but which we later realize is not mutable. Specifically, 
when we check `exit()` we think `dispatch()` is mutable and therefore consider 
it captured, which means we can't independently memoize `exit`.
2023-04-04 12:30:11 -07:00
Joe Savona
2e3aa3954c Memoize hook args (treat as escaping)
Updates `PruneNonEscapingScopes` to consider hook arguments as potentially 
escaping. This is because hook inputs are "owned" by React — for example, 
closures passed to `useEffect`, or a value that is passed to a custom hook and 
which then becomes a memoized input.
2023-04-04 12:30:10 -07:00
Mohammad Ghorbani
d5fd60f7e6 Remove findInstanceBlockingEvent unused parameters (#26534)
## Summary
First three parameters of `findInstanceBlockingEvent` are unused since I
think if we remove the unused parameters it makes it easier to know that
which parameters is need by `findInstanceBlockingEvent`.

## How did you test this change?
Existing tests.
2023-04-04 12:37:14 -04:00
Sebastian Markbåge
eeabb7312f Refactor DOM Bindings Completely Off of DOMProperty Meta Programming (#26546)
There are four places we have special cases based off the DOMProperty
config:

1) DEV-only: ReactDOMUnknownPropertyHook warns for passing booleans to
non-boolean attributes. We just need a simple list of all properties
that are affected by that. We could probably move this in under setProp
instead and have it covered by that list.
2) DEV-only: Hydration. This just needs to read the value from an
attribute and compare it to what we'd expect to see if it was rendered
on the client. This could use some simplification/unification of the
code but I decided to just keep it simple and duplicated since code size
isn't an issue.
3) DOMServerFormatConfig pushAttribute: This just maps the special case
to how to emit it as a HTML attribute.
4) ReactDOMComponent setProp: This just maps the special case to how to
emit it as setAttribute or removeAttribute.

Basically we just have to remember to keep pushAttribute and setProp
aligned. There's only one long switch in prod per environment.

This just turns it all to a giant simple switch statement with string
cases. This is in theory the most optimizable since syntactically all
the information for a hash table is there. However, unfortunately we
know that most VMs don't optimize this very well and instead just turn
them into a bunch of ifs. JSC is best. We can minimize the cost by just
moving common attribute to the beginning of the list.

If we shipped this, maybe VMs will get it together to start optimizing
this case but there's a chicken and egg problem here and the game theory
reality is that we probably don't want to regress. Therefore, I intend
to do a follow up after landing this which reintroduces an object
indirection for simple property aliases. That should be enough to make
the remaining cases palatable. I'll also extract the most common
attributes to the beginning or separate ifs.

Ran attribute-behavior fixture and the table is the same.
2023-04-04 11:05:56 -04:00
Andrew Clark
0ba4d7b0d8 DevTools: Inline references to fiber flags (#26542)
We shouldn't be referencing internal fields like fiber's `flag` directly
of DevTools. It's an implementation detail. However, over the years a
few of these have snuck in. Because of how DevTools is currently
shipped, where it's expected to be backwards compatible with older
versions of React, this prevents us from refactoring those fields inside
the reconciler.

The plan we have to address this is to fix how DevTools is shipped:
DevTools will be released in lockstep with each version of React.

Until then, though, I need a temporary solution because it's blocking a
feature I'm working on. So in meantime, I'm going to have to fork the
DevTool's code based on the React version, like we already do with the
fiber TypeOfWork enum.

As a first step, I've inlined all the references to fiber flags into the
specific call sites where they are used. Eventually we'll import these
functions from the reconciler so they stay in sync, rather than
maintaining duplicate copies of the logic.
2023-04-04 11:05:33 -04:00
Jan Kassens
da94e8b24a Revert "Cleanup enableSyncDefaultUpdate flag (#26236)" (#26528)
This reverts commit b2ae9ddb3b.

While the feature flag is fully rolled out, these tests are also testing
behavior set with an unstable flag on root, which for now we want to
preserve.

Not sure if there's a better way then adding a dynamic feature flag to
the www build?
2023-04-04 10:08:14 -04:00
Rubén Norte
0700dd50bd Implement public instances for text nodes in Fabric (#26516)
## Summary

This adds the ability to create public instances for text nodes in
Fabric. The implementation for the public instances lives in React
Native (as it does for host components after #26437). The logic here
just handles their lazy instantiation when requested via
`getPublicInstanceFromInternalInstanceHandle`, which is called by Fabric
with information coming from the shadow tree.

It's important that the creation of public instances for text nodes is
done lazily to avoid regressing memory usage when unused. Instances for
text nodes are left intact if the public instance is never accessed.

This is necessary to implement access to text nodes in React Native as
explained in
https://github.com/react-native-community/discussions-and-proposals/pull/607

## How did you test this change?

Added unit tests (also fixed a test that was only testing the logic in a
mock :S).
2023-04-04 14:43:35 +01:00
Joe Savona
e32ea49a0e Special-case fbt() function call form
Similar to what we did for `<fbt>` jsx elements, this PR ensures that `fbt()` 
calls have their operands memoized in the same scope to honor the limited 
contract for what's allowed as an argument of an fbt() call expression.
2023-04-03 11:47:45 -07:00
Josh Story
4a1cc2ddd0 Fix logic around attribute seralization (#26526)
There was a bug in the attribute seralization for stylesheet resources
injected by the Fizz runtime. For boolean properties the attribute value
was set to an empty string but later immediately set to a string coerced
value. This PR fixes that bug and refactors the code paths to be clearer
2023-04-03 09:34:53 -07:00
Ruslan Lesiutin
b14f8da155 refactor[devtools]: forbid editing class instances in props (#26522)
## Summary
Fixes https://github.com/facebook/react/issues/24781

Restricting from editing props, which are class instances, because their
internals should be opaque.

Proposed changes:
1. Adding new data type `class_instance`: based on prototype chain of an
object we will check if its plain or not. If not, then will be marked as
`class_instance`. This should not affect `arrays`, ..., because we do
this in the end of an `object` case in `getDataType` function.

Important detail: this approach won't work for objects created with
`Object.create`, because of the custom prototype. This can also be
bypassed by manually deleting a prototype ¯\\\_(ツ)_/¯
I am not sure if there might be a better solution (which will cover all
cases) to detect if object is a class instance. Initially I was trying
to use `Object.getPrototypeOf(object) === Object.prototype`, but this
won't work for cases when we are dealing with `iframe`.


2. Objects with a type `class_instance` will be marked as unserializable
and read-only.

## Demo
`person` is a class instance, `object` is a plain object


https://user-images.githubusercontent.com/28902667/228914791-ebdc8ab0-eb5c-426d-8163-66d56b5e8790.mov
2023-04-03 11:32:17 +01:00
Hans Otto Wirtz
7329ea81c1 Fix suspense replaying forward refs (#26535)
Continuation of https://github.com/facebook/react/issues/26420

Fixes https://github.com/facebook/react/issues/26385 and
https://github.com/facebook/react/issues/26419

---------

Co-authored-by: eps1lon <silbermann.sebastian@gmail.com>
Co-authored-by: Andrew Clark <git@andrewclark.io>
2023-04-02 18:48:28 -04:00
Sathya Gunasekaran
0cb10446b3 [test] Failing test for returning from a for-loop 2023-04-01 09:22:34 +01:00
Lauren Tan
b19555573f [babel] Make gating option a pair of module and project
There are some internal restrictions in Metro that only allow us to specify one 
gating module as an injected dependency. To allow multiple projects, this PR 
updates the Babel plugin to take a gating options config specifiying a project 
name. The project name is used as a suffix for the generated import; for 
example: 

```js 

const options = { 

// ... 

gating: { 

module: "ReactForgetFeatureFlag", 

importSpecifierName: "isForgetEnabled_Secret", 

}; 

// generates 

import {isForgetEnabled_Secret} from "ReactForgetFeatureFlag"; // a module that 
exports multiple flags 

// ... 

```
2023-04-03 12:33:23 -04:00
Andrew Clark
0ae348018d [Float] Suspend unstyled content for up to 1 minute (#26532)
We almost never want to show content before its styles have loaded. But
eventually we will give up and allow unstyled content. So this extends
the timeout to a full minute. This somewhat arbitrary — big enough that
you'd only reach it under extreme circumstances.

Note that, like regular Suspense, the app is still interactive while
we're waiting for content to load. Only the unstyled content is blocked
from appearing, not updates in general. A new update will interrupt it.

We should figure out what the browser engines do during initial page
load and consider aligning our behavior with that. It's supposed to be
render blocking by default but there may be some cases where they, too,
give up and FOUC.
2023-03-31 15:45:45 -04:00
Andrew Clark
888874673f Allow transitions to interrupt Suspensey commits (#26531)
I originally made it so that a Suspensey commit — i.e. a commit that's
waiting for a stylesheet, image, or font to load before proceeding —
could not be interrupted by transitions. My reasoning was that Suspensey
commits always time out after a short interval, anyway, so if the
incoming update isn't urgent, it's better to wait to commit the current
frame instead of throwing it away.

I don't think this rationale was correct, for a few reasons. There are
some cases where we'll suspend for a longer duration, like stylesheets —
it's nearly always a bad idea to show content before its styles have
loaded, so we're going to be extend this timeout to be really long.

But even in the case where the timeout is shorter, like fonts, if you
get a new update, it's possible (even likely) that update will allow us
to avoid showing a fallback, like by navigating to a different page. So
we might as well try.

The behavior now matches our behavior for interrupting a suspended
render phase (i.e. `use`), which makes sense because they're not that
conceptually different.
2023-03-31 15:35:48 -04:00
Andrew Clark
09c8d25633 Move update scheduling to microtask (#26512)
When React receives new input (via `setState`, a Suspense promise
resolution, and so on), it needs to ensure there's a rendering task
associated with the update. Most of this happens
`ensureRootIsScheduled`.

If a single event contains multiple updates, we end up running the
scheduling code once per update. But this is wasteful because we really
only need to run it once, at the end of the event (or in the case of
flushSync, at the end of the scope function's execution).

So this PR moves the scheduling logic to happen in a microtask instead.
In some cases, we will force it run earlier than that, like for
`flushSync`, but since updates are batched by default, it will almost
always happen in the microtask. Even for discrete updates.

In production, this should have no observable behavior difference. In a
testing environment that uses `act`, this should also not have a
behavior difference because React will push these tasks to an internal
`act` queue.

However, tests that do not use `act` and do not simulate an actual
production environment (like an e2e test) may be affected. For example,
before this change, if a test were to call `setState` outside of `act`
and then immediately call `jest.runAllTimers()`, the update would be
synchronously applied. After this change, that will no longer work
because the rendering task (a timer, in this case) isn't scheduled until
after the microtask queue has run.

I don't expect this to be an issue in practice because most people do
not write their tests this way. They either use `act`, or they write
e2e-style tests.

The biggest exception has been... our own internal test suite. Until
recently, many of our tests were written in a way that accidentally
relied on the updates being scheduled synchronously. Over the past few
weeks, @tyao1 and I have gradually converted the test suite to use a new
set of testing helpers that are resilient to this implementation detail.

(There are also some old Relay tests that were written in the style of
React's internal test suite. Those will need to be fixed, too.)

The larger motivation behind this change, aside from a minor performance
improvement, is we intend to use this new microtask to perform
additional logic that doesn't yet exist. Like inferring the priority of
a custom event.
2023-03-31 13:04:08 -04:00
Sathya Gunasekaran
1aec5ef523 [hir] Skip computed part of the captured ref 2023-03-31 17:37:06 +01:00
Lauren Tan
55793bd96f Also visit phis in fallthroughs for DoWhile in LeaveSSA
Oops, forgot about this previously
2023-03-31 17:55:07 -04:00
Lauren Tan
61462a43bc Add support for ForOf statements
Teaches Forget to compile simple ForOf statements, where the init comprises of a 
variable declaration with an identifier or destructure.
2023-03-31 17:55:04 -04:00
Joe Savona
1e2df5bdbb Remove console.log from testing sync script changes
oooooops
2023-03-31 14:43:31 -07:00
Joe Savona
28e6a974fa JSX: children which are jsx elements dont need expr container 2023-03-31 12:32:46 -07:00
Joe Savona
4e2ef92779 Ensure <fbt> children are not independently memod
This is a Meta-ism, but adding it for now to unblock. We special-case the 
`<fbt>` element for translation purposes, and have a transform that requires the 
children of this element to be a limited subset of nodes. Notably, any dynamic 
translation values must appear as `<fbt:param>` children — we disallow 
identifiers as children of `<fbt>` nodes. 

This PR adds a new pass which finds `<fbt>` nodes and ensures their immediate 
operands are not independently memoized. Note that this still allows the values 
of `<fbt:param>` to be independently memoized, as demonstrated in the unit test.
2023-03-31 12:32:45 -07:00
Mofei Zhang
8dfe06ddba [hir] Allow reorderable exprs in optional computed load 2023-03-31 10:58:28 -04:00
Andrew Clark
8310854ceb Clean up enableCapturePhaseSelectiveHydrationWithoutDiscreteEventReplay (#26521)
This flag is already enabled everywhere except for www, which is blocked
by a few tests that assert on the old behavior. Once www is ready, I'll
land this.
2023-03-31 10:25:58 -04:00
Ricky
ca01f359b9 Remove skipUnmountedBoundaries (#26489)
# Overview

Landing this flag internally, will test this PR in React Native before
merging.
2023-03-30 20:58:13 -04:00
Mofei Zhang
c77c1b1644 [hir] Disallow unconditional load from optional memberexpr 2023-03-30 19:23:23 -04:00
Mofei Zhang
c00e7a2af2 [test] Test case for optional chaining in codegen
```js 

// here, `a?.b.c` is a single optional chain 

// (evaluates to undefined if a is nullish) 

a?.b.c; 

// here, 'a?.b` is an optional chain, and `.c` is an unconditional load 

// (nullthrows if a is nullish) 

(a?.b).c; 

``` 

--- 

Next PR in stack will add a bailout for `(a?.b).c`. 

(If we want to properly handle `(a?.b).c`, we might want to model optional 
chains explicitly in the HIR. We currently assume that any `PropertyLoad` whose 
lhs is an optional property load is read conditionally.)
2023-03-30 18:43:55 -04:00
Sathya Gunasekaran
0eeedee95e [hir] Rewrite identifiers to be consistent
If we resolve identifiers to be different from the binding, update the binding 
to the new name.
2023-03-31 12:35:17 +01:00
Sathya Gunasekaran
3b3d15eaeb [hir] Check if callee before pruning member path 2023-03-31 16:36:04 +01:00
Lauren Tan
46a9d40914 [babel] Invoke gating module as a call expression
This is incredibly obvious in hindsight, but for exposure logging to work 
correctly we need to *call* the underlying `MobileConfig.getBool` function at 
the callsite – otherwise the bool is evaluated once (and only once) when the 
module is loaded. 

Tested internally and verified that in dogfooding the exposure logging was 
working correctly
2023-03-31 11:15:51 -04:00
Sebastian Markbåge
43a70a610d Limit the meaning of "custom element" to not include is (#26524)
This PR has a bunch of surrounding refactoring. See individual commits.

The main change is that we no longer special case `typeof is ===
'string'` as a special case according to the
`enableCustomElementPropertySupport` flag.

Effectively this means that you can't use custom properties/events,
other than the ones React knows about on `<input is="my-input">`
extensions.

This is unfortunate but there's too many paths that are forked in
inconsistent ways since we fork based on tag name. I think __the
solution is to let all React elements set unknown properties/events in
the same way as this flag__ but that's a bigger change than this flag
implies.

Since `is` is not universally supported yet anyway, this doesn't seem
like a huge loss. Attributes still work.

We still support passing the `is` prop and turn that into the
appropriate createElement call.

@josepharhar
2023-03-30 18:38:50 -04:00
mofeiZ
5beecef28f [patch] Remove invalid invariant in deriveMinimalDeps
Confirmed that this fixes invariant violation on -
2023-03-30 17:33:37 -04:00
dan
1308e49a69 [Flight Plugin] Scan for "use client" (#26474)
## Summary

Our toy webpack plugin for Server Components is pretty broken right now
because, now that `.client.js` convention is gone, it ends up adding
every single JS file it can find (including `node_modules`) as a
potential async dependency. Instead, it should only look for files with
the `'use client'` directive.

The ideal way is to implement this by bundling the RSC graph first.
Then, we would know which `'use client'` files were actually discovered
— and so there would be no point to scanning the disk for them. That's
how Next.js bundler does it.

We're not doing that here.

This toy plugin is very simple, and I'm not planning to do heavy
lifting. I'm just bringing it up to date with the convention. The change
is that we now read every file we discover (alas), bail if it has no
`'use client'`, and parse it if it does (to verify it's actually used as
a directive). I've changed to use `acorn-loose` because it's forgiving
of JSX (and likely TypeScript/Flow). Otherwise, this wouldn't work on
uncompiled source.

## Test plan

Verified I can get our initial Server Components Demo running after this
change. Previously, it would get stuck compiling and then emit thousands
of errors.

Also confirmed the fixture still works. (It doesn’t work correctly on
the first load after dev server starts, but that’s already the case on
main so seems unrelated.)
2023-03-30 22:05:03 +01:00
Sebastian Markbåge
1a1d61fed9 Warn for ARIA typos on custom elements (#26523)
Normally we allow any attribute/property on custom elements. However
it's a shared namespace. The `aria-` namespace applies to all generic
elements which are shared with custom elements. So arguably adding
custom extensions there is a really bad idea since it can conflict with
future additions.

It's possible there is a new standard one that's polyfilled by a custom
element but the same issue applies to React in general that we might
warn for very new additions so we just have to be quick on that.

cc @josepharhar
2023-03-30 16:31:15 -04:00
Mengdi Chen
5b8cf20b38 Add Circle CI API token to request header if available (#26519)
Follow up of #26499
A Circle CI team member got back to me. It is indeed not necessary, but
they had a regression not long ago on fetching without token.

https://discuss.circleci.com/t/is-api-token-required-when-fetching-artifacts/47606/5

To mitigate the impact of this kind of issues, let's add this token to
requests' header when it's available.
2023-03-30 16:06:56 -04:00
Lauren Tan
d67b3cbdc0 [printer] Add missing terminal printer for do-while 2023-03-30 15:50:08 -04:00
Lauren Tan
89ea2d5f7c [be] Fix missing break and update no-fallthrough eslint rule
- Fixes a missing break in InferTypes - I disabled no-fallthrough previously 
because it would erroneously report that certain cases with non-builtin throws 
(eg `invariant`) would fall through. This brings the rule back but allows 
disabling it with a `// break omitted` comment, since it's still helpful in 
catching some actual missing breaks.
2023-03-30 15:50:07 -04:00
Mofei Zhang
e43f91edc3 [env] Type inference for global object
- Add `DEFAULT_SHAPES` ShapeRegistry, which holds builtins and all 
`ObjectShapes` used in `DEFAULT_GLOBALS`. 

- Add a few typed objects / functions into `DEFAULT_GLOBALS` (used for tests) 

- Add type inference and `infer-global-object` test
2023-03-30 15:03:11 -04:00
Mofei Zhang
25388d3fda [be] Clean up null -> PolyType in ObjectShape
--- 

Question - should the unifier ignore `PolyType` for now? 

```js 

class Unifier { 

// ... 

bindVariableTo(v: TypeVar, type: Type) { 

if (type.kind === "Poly") { 

return; 

} 

// ... 

```
2023-03-30 15:03:11 -04:00
Mofei Zhang
ffc1b5b700 [be] More comments for ObjectShapes; rename BuiltIn shapes 2023-03-30 15:03:10 -04:00
Mofei Zhang
44b2f504ea [rfc][env] Hook, object, and function types for Environment globals
Adds `GlobalRegistry`, which holds the names and types of known global objects, 
i.e. 

```js 

type GlobalRegistry = Map<string, PrimitiveType | ObjectType | FunctionType | 
HookType | PolyType>; 

// ... 

globalRegistry.get("NaN"); // {kind: "Primitive"} 

globalRegistry.get("parseInt"); // {kind: "Function", shapeId: "..."} 

globalRegistry.get("Math"); // {kind: "Object", shapeId: "..."} 

``` 

Since we currently do not track module imports and module-level declarations, 
builtin and custom hooks currently also live in GlobalRegistry. 

```js 

globalRegistry.get("useState"); // {kind: "Hook", definition: {...}} 

globalRegistry.get("useFreeze"); // {kind: Hook, definition: {...}} 

``` 

This PR does not allow Forget users to define their own globals. When we add 
this as a configuration, we should not expose `ShapeRegistry` to the user, as a 
user-provided ShapeRegistry may accidentally be not well formed. (i.e. missing 
(1) required shapes (BuiltInArray for [] and BuiltInObject for {}) or (2) some 
recursive shapeIds) 

```js 

export type UserType = UserObject | UserFunction | "Primitive" | "BuiltinObject" 
| ...; 

export type UserObject = { 

kind: "Object", 

properties: Map<string, UserType> 

} 

export type UserFunction = { 

kind: "Function", 

properties: Map<string, UserType>, 

signature: ... 

} 

export type UserGlobals = Map<string, UserType>; 

class Environment { 

constructor(globals: Map<string, UserType>, ...) { 

// ... 

addUserDefinedGlobals(this.#globals, this.#shapes); 

```
2023-03-30 15:03:10 -04:00
Mofei Zhang
45331ef21b [be][env] Move EnvironmentOptions -> EnvironmentConfig
--- 

Simplify Environment options by: 

- EnvironmentOptions -> EnvironmentConfig 

config is now directly passed around instead of being eagerly merged. 

- Moving merging / initialization logic into `Environment` constructor. From my 
understanding, there is no need to decouple merged options from an environment. 

This prepares Environment for the next PR, which adds non-stateful properties to 
Environment (i.e. a `GlobalRegistry`) that should be converted from config 
values (i.e. not directly exposed to the user due to potentially inconsistent 
inputs)
2023-03-30 15:03:09 -04:00
Mofei Zhang
8e37df6dab [be] Hook type inference should only happen at LoadGlobal
--- 

#1254 added inference for hooks loaded from globals. This is the only time we 
need to generate a type equation assigning `lval` to a resolved`Hook` type. 

@gsathya Would love to get your feedback here on the change. From my 
understanding, this change is technically incorrect, since the type equation we 
generate should be dependent on the `callee` type (i.e. `Hook` if callee is a 
hook, `Function` if callee is a function). 

Would the next step be to consolidate `Hook` and `Function` types? 

```js 

type Function { 

... 

isHook: boolean, // set by inference 

} 

type FunctionSignature { 

isHook: boolean, // set when adding to ShapeRegistry 

} 

```
2023-03-30 15:03:09 -04:00
Sebastian Markbåge
73deff0d51 Refactor DOMProperty and CSSProperty (#26513)
This is a step towards getting rid of the meta programming in
DOMProperty and CSSProperty.

This moves isAttributeNameSafe and isUnitlessNumber to a separate shared
modules.

isUnitlessNumber is now a single switch instead of meta-programming.
There is a slight behavior change here in that I hard code a specific
set of vendor-prefixed attributes instead of prefixing all the unitless
properties. I based this list on what getComputedStyle returns in
current browsers. I removed Opera prefixes because they were [removed in
Opera](https://dev.opera.com/blog/css-vendor-prefixes-in-opera-12-50-snapshots/)
itself. I included the ms ones mentioned [in the original
PR](5abcce5343).
These shouldn't really be used anymore anyway so should be pretty safe.
Worst case, they'll fallback to the other property if you specify both.

Finally I inline the mustUseProperty special cases - which are also the
only thing that uses propertyName. These are really all controlled
components and all booleans.

I'm making a small breaking change here by treating `checked` and
`selected` specially only on the `input` and `option` tags instead of
all tags. That's because those are the only DOM nodes that actually have
those properties but we used to set them as expandos instead of
attributes before. That's why one of the tests is updated to now use
`input` instead of testing an expando on a `div` which isn't a real use
case. Interestingly this also uncovered that we update checked twice for
some reason but keeping that logic for now.

Ideally `multiple` and `muted` should move into `select` and
`audio`/`video` respectively for the same reason.

No change to the attribute-behavior fixture.
2023-03-30 14:30:57 -04:00
Andrew Clark
2d51251e60 Clean up deferRenderPhaseUpdateToNextBatch (#26511)
This is a change to some undefined behavior that we though we would do
at one point but decided not to roll out. It's already disabled
everywhere, so this just deletes the branch from the implementation and
the tests.
2023-03-30 14:10:19 -04:00
Sathya Gunasekaran
e81063e5ef [rfc] Desugar FunctionDeclaration to a FunctionExpression 2023-03-30 15:48:54 +01:00
Sathya Gunasekaran
05f48e2aac [hir] Refactor FunctionExpression lowering into separate function
This will allow us to reuse all the lowering for FunctionDeclaration.
2023-03-30 15:48:53 +01:00
Joseph Savona
0ffc7f632b Update useMemoCache test to confirm that cache persists across errors (#26510)
## Summary

Updates the `useMemoCache()` tests to validate that the memo cache
persists when a component does a setState during render or throws during
render. Forget's compilation output follows the general pattern used in
this test and is resilient to rendering running partway and then again
with different inputs.

## How did you test this change?

`yarn test` (this is a test-only change)
2023-03-30 07:47:22 -07:00
Sebastian Markbåge
29a3be78bd Move ReactDOMFloat to react-dom/src/ (#26514)
This is not really part of the bindings, it's more part of the package
entry points. /shared/ is not really right neither because it's more
like an isomorphic entry point and not some utility.
2023-03-29 23:39:24 -04:00
Sebastian Markbåge
4c2fc01900 Generate safe javascript url instead of throwing with disableJavaScriptURLs is on (#26507)
We currently throw an error when disableJavaScriptURLs is on and trigger
an error boundary. I kind of thought that's what would happen with CSP
or Trusted Types anyway. However, that's not what happens. Instead, in
those environments what happens is that the error is triggered when you
try to actually visit those links. So if you `preventDefault()` or
something it'll never show up and since the error just logs to the
console or to a violation logger, it's effectively a noop to users.

We can simulate the same without CSP by simply generating a different
`javascript:` url that throws instead of executing the potential attack
vector.

This still allows these to be used - at least as long as you
preventDefault before using them in practice. This might be legit for
forms. We still don't recommend using them for links-as-buttons since
it'll be possible to "Open in a New Tab" and other weird artifacts. For
links we still recommend the technique of assigning a button role etc.

It also is a little nicer when an attack actually happens because at
least it doesn't allow an attacker to trigger error boundaries and
effectively deny access to a page.
2023-03-29 23:39:02 -04:00
mofeiZ
c2154b2785 [playground] Only collect first level of function declarations
#1433 means that Forget now will compile nested function declarations, so we no 
longer need to compile these separately
2023-03-29 17:14:58 -04:00
Andrew Clark
f0aafa1a7e Convert a few more tests to waitFor test helpers (#26509)
Continuing my journey to migrate all the Scheduler flush* methods to
async versions of the same helpers.
2023-03-29 17:02:15 -04:00
Andrew Clark
90995ef8b0 Delete "triangle" resuming fuzz tester (#26508)
This deletes the ReactIncrementalTriangle test suite, which I originally
added back in 2017 when I was working on Fiber's "resuming" feature. It
was meant to simulate a similar scenario as Seb's "Sierpinski Triangle"
Fiber demo.

We eventually ended up removing resuming, but we kept this fuzz tester
around since it wasn't really harming anything. However, over the years,
we've had to make many small tweaks to decouple it from implementation
details, to the point that it doesn't test anything useful anymore. And
the thing that it originally tested has long since been removed.

If or when we do add back resuming, we would write a different fuzz
tester from scratch rather than build on this one.

So rather than continue to contrive ways to prevent it from breaking, I
propose we delete it.

We still have other fuzz testers for things like Suspense and context
propagation. Only this particular one has outlived its usefulness.
2023-03-29 16:48:02 -04:00
Sebastian Silbermann
f118b7cebf [Flight] Gated test for dropped transport of undefined object values (#26478)
## Summary

With https://github.com/facebook/react/pull/26349 we now serialize
`undefined`. However, deserializing it on the client is currently
indistinguishable from the value missing entirely due to how
`JSON.parse` treats `undefined` return value of reviver functions.

This leads to inconsistent behavior of the `Object.hasOwn` or `in`
operator (used for narrowing in TypeScript). In TypeScript-speak, `{
prop: T | undefined}` will arrive as `{ prop?: T }`.

## How did you test this change?

- Added test that is expected to fail. Though ideally the implementation
of the component would not care whether it's used on the client or
server.
2023-03-29 18:27:55 +02:00
Sebastian Silbermann
fd0511c728 [Flight] Add support BigInt support (#26479)
## Summary

Adds support for sending `BigInt` to Flight and Flight Reply

## How did you test this change?

- added tests
2023-03-29 18:23:43 +02:00
Sebastian Markbåge
85de6fde51 Refactor DOM special cases per tags including controlled fields (#26501)
I use a shared helper when setting properties into a helper whether it's
initial or update.

I moved the special cases per tag to commit phase so we can check it
only once. This also effectively inlines getHostProps which can be done
in a single check per prop key.

The diffProperties operation is simplified to mostly just generating a
plain diff of all properties, generating an update payload. This might
generate a few more entries that are now ignored in the commit phase.
that previously would've been ignored earlier. We could skip this and
just do the whole diff in the commit phase by always scheduling a commit
phase update.

I tested the attribute table (one change documented below) and a few
select DOM fixtures.
2023-03-28 22:40:03 -04:00
Mengdi Chen
5cbe6258bc Remove unnecessary CIRCLE_CI_API_TOKEN checks (#26499)
Token is not required for GET
2023-03-28 16:31:34 -04:00
Andrew Clark
1f5cdf8c77 Update Suspense fuzz tests to use act (#26498)
This updates the Suspense fuzz tester to use `act` to recursively flush
timers instead of doing it manually.

This still isn't great because ideally the fuzz tester wouldn't fake
timers at all. It should resolve promises using a custom queue instead
of Jest's fake timer queue, like we've started doing in our other
Suspense tests (i.e. the `resolveText` pattern). That's because our
internal `act` API (not the public one, the one we use in our tests)
uses Jest's fake timer queue as a way to force Suspense fallbacks to
appear.

However I'm not interested in upgrading this test suite to a better
strategy right now because if I were writing a Suspense fuzzer today I
would probably use an entirely different approach. So this is just an
incremental improvement to make it slightly less decoupled to React
implementation details.
2023-03-28 14:40:28 -04:00
Ricky
f62cb39ee5 Make disableSchedulerTimeoutInWorkLoop a static ff (#26497)
## Overview

There's a known infinite loop with this but we're not running an
experiment any time soon.
2023-03-28 14:11:52 -04:00
Joe Savona
57bc5fd56e Support AssignmentPattern in params (param default values)
I already taught `lowerAssignment()` to handle assignment patterns for 
destructuring, we just have to call this helper for assignment pattern params 
too.
2023-03-28 09:52:55 -07:00
Sathya Gunasekaran
0999b6b815 [hir] Treat captured refs in throw or return terminals as mutations
In a lambda, a return/throw terminal could return a captured context ref needs 
to be treated as a mutation to correctly alias the returned  context ref and the 
lvalue.
2023-03-29 17:15:00 +01:00
Sathya Gunasekaran
dd0476a1b5 [hir] Infer mutable ranges for terminals
Terminal operands are generally not mutating so this hasn't mattered so far. But 
in a lambda, a return terminal could return a captured context ref which needs 
to be treated as a mutation to correctly alias the returned context ref and the 
lvalue.
2023-03-29 15:48:55 +01:00
Mengdi Chen
f718199313 [DevTools] browser extension: improve script injection logic (#26492)
## Summary

- Drop extension support for Chrome / Edge <v102 since they have less
than 0.1% usage ([see data](https://caniuse.com/usage-table))
- Improve script injection logic when possible so that the scripts
injected by the extension are no longer shown in Network (which caused a
lot of confusion in the past)

## How did you test this change?

Built and tested locally, works as usual on Firefox.

For Chrome/Edge

**Before:**
Scripts shown in Network tab
<img width="1279" alt="Untitled 2"
src="https://user-images.githubusercontent.com/1001890/228074363-1d00d503-d4b5-4339-8dd6-fd0467e36e3e.png">

**After:**
No scripts shown
<img width="1329" alt="image"
src="https://user-images.githubusercontent.com/1001890/228074596-2084722b-bf3c-495e-a852-15f122233155.png">

---------

Co-authored-by: Ruslan Lesiutin <rdlesyutin@gmail.com>
2023-03-28 12:45:53 -04:00
Sathya Gunasekaran
e0180ce86a [lambdas] Track ReactiveScopeDepenency of ComputedLoad
Fixes an issue where we did not track mutations to captured computed loads in 
lambdas.
2023-03-28 16:29:31 +01:00
Ricky
41b4714f19 Remove disableNativeComponentFrames (#26490)
## Overview

I'm landing this flag internally so we can delete this
2023-03-28 09:46:26 -04:00
Andrew Clark
fc90eb6368 Codemod more tests to waitFor pattern (#26494) 2023-03-28 00:03:57 -04:00
Andrew Clark
e0bbc26623 Improve tests that deal with microtasks (#26493)
I rewrote some of our tests that deal with microtasks with the aim of
making them less coupled to implementation details. This is related to
an upcoming change to move update processing into a microtask.
2023-03-27 23:17:55 -04:00
mofeiZ
ec0abcd643 [hir] Strip JSXEmptyExpression syntax
`JSXEmptyExpression` is never added to a React element's children [in 
`react.buildChildren`](https://github.com/babel/babel/blob/main/packages/babel-types/src/builders/react/buildChildren.ts), 
which is [used 
by](https://github.com/babel/babel/blob/main/packages/babel-plugin-transform-react-jsx/src/create-plugin.ts#L649) 
`plugin-transform-react-jsx`]. 

An alternative would be to represent JSX expressions differently in HIR, then 
codegen `JSXEmptyExpression`s back when we encounter an `EmptyExpression` 

```js 

-   children: Array<Place>, 

-   children: Array<Place | "EmptyExpression">, 

``` 

(We could also retain `JSXEmptyExpression` as an `InstructionValue` that 
produces a Primitive. However, this would make babel types in Codegen a bit more 
messy, as `JSXEmptyExpression` does not extend `Expression` (which currently is 
the result of every `InstructionValue`).)
2023-03-27 18:12:18 -04:00
Andrew Clark
8faf751937 Codemod some expiration tests to waitForExpired (#26491)
Continuing my journey to migrate all the Scheduler flush* methods to
async versions of the same helpers.

`unstable_flushExpired` is a rarely used helper that is only meant to be
used to test a very particular implementation detail (update starvation
prevention, or what we sometimes refer to as "expiration").

I've prefixed the new helper with `unstable_`, too, to indicate that our
tests should almost always prefer one of the other patterns instead.
2023-03-27 15:52:25 -04:00
Joe Savona
43176b129e [be] Simplify BuildHIR w lowerValueToTemporary helper
Creates a new helper, `const temp: Place = lowerValueToTemporary(builder, 
value)` which creates a new temporary and an instruction to write that value to 
the temporary. We have this pattern all over BuildHIR, and the new helper makes 
this all a bit tidier.
2023-03-27 11:35:34 -07:00
Joe Savona
445e550e00 Support await expressions
Adds support for `await` expressions. We have primarily seen await used inside 
callbacks, not directly within component render logic, but because we construct 
HIR for lambdas it is helpful to be able to model await rather than require 
everyone to rewrite to use the Promise API. Note a subtlety: awaiting a promise 
is a mutative operation, so we a) model it as a Mutate effect and b) avoid DCE 
of await expressions since they may cause side effects. See the test cases for 
examples.
2023-03-27 10:41:49 -07:00
Joe Savona
4a826985db More tests for AssignmentPattern 2023-03-27 10:34:16 -07:00
Joe Savona
6d434cc777 Generalize helper for reorderable expressions
Adds a new helper method that we can use when processing expressions whose 
evaluation ordering may not be preserved. This was previously the case only for 
switch test case values, but we can use this for AssignmentPattern 
(destructuring default values) as well.
2023-03-27 10:34:11 -07:00
Joe Savona
80bdab7447 Support AssignmentPattern (default values in destructuring)
"Supports" default values in destructuring (AssignmentPattern) by lowering to a 
ternary, even in the output. Examples: 

```javascript 

// Input: 

const [x = 'default'] = y; 

// Output: 

const [t0] = y; 

const x = t0 === undefined ? 'default' : t0; 

``` 

```javascript 

// Input 2 

const [{x} = makeObject()] = y; 

// Output 2 

const [t0] = y; 

const {x} = t0 === undefined ? makeObject() : t0; 

``` 

Note that this is how Babel lowers AssignmentPattern, so it isn't too bad. This 
should help avoid the need to update product code, even if the output isn't 
perfectly ideal.
2023-03-27 10:34:11 -07:00
Joe Savona
61e97dc278 Support RegExp literals
New InstructionValue variant since RegExp literals are valid expressions.
2023-03-27 10:34:10 -07:00
Joe Savona
179b24b56e JSXNamespacedName support
This is kind of a hack, but i think it's worth it given that JSXNamespacedName 
is relatively uncommon. Adding a new InstructionValue variant to represent a 
namespaced name is one option, but then that isn't a valid expression and can't 
appear as an operand anywhere else. Instead, we lower namespaced names as a 
primitive (string) as `${namespace}:${name}` — exploiting the fact the namespace 
and name can't have a colon, and non-namespaced tagnames also can't have colons. 

It's a bit of a hack but it's contained to the JSX processing code. If folks 
have strong opinions on this i'm happy to change but this felt reasonable as a 
quick and reliable way to unblock support. 

NOTE: there is a larger question of what to do about compiling `fbt` tags. 
Before we can do anything with them, though, we need to parse them.
2023-03-27 10:34:09 -07:00
mofeiZ
027f773179 [rhir] Patch for reactive computed loads
We need to check reactivity of both the operand and its resolved source (if 
operand is produced by a LoadLocal / PropertyLoad / ComputedLoad). 

Both the operand and its source can have reactivity. 

e.g. 

```js 

const o = makeObject(); // source has no reactivity 

const x = o[props.x];   // x is reactive 

```
2023-03-27 13:27:58 -04:00
Jan Kassens
8342a09927 Remove unused feature flag disableSchedulerTimeoutBasedOnReactExpirationTime (#26488)
Easy removal as it's completely unused as @rickhanlonii noticed.
2023-03-27 17:52:02 +02:00
Sathya Gunasekaran
bb2325bdce [typer] Track return type in FunctionType
Rather than having a special FunctionCall type that deduces the return type, 
change the FunctionType to include the return type. 

This return type is inferred as part of unification.
2023-03-27 15:58:08 +01:00
Sathya Gunasekaran
a0fa5ede54 [typer] Type Array.at returnType as PolyType 2023-03-27 15:58:07 +01:00
Mofei Zhang
67b2a9f314 [rhir] Represent OptionalMemberExpression as a conditional dependency
--- 

Every `OptionalMemberExpression` rvalue has the form 
`<requiredPath>?.<optionalPath>`. 

``` 

// required = [a], optional: [b, c] 

props.a?.b.c; 

props.a?.b?.c; 

``` 

When calculating reactive dependencies, recall that it is always correct to add 
a subpath of a dependency (e.g. we can always take `props.a` instead of 
`props.a.b` as a dependency). See comments in `DeriveMinimalDependencies` for a 
longer explanation. 

There are two ways we can deal with `OptionalMemberExpression`: 

- We can always truncate a OptionalMemberExpression dependency to its 
`requiredPath`, taking only the required path as a dependency. 

- this is the simpler approach, but it potentially loses granularity. 

e.g. 

``` 

// here, since props.a is already unconditionally accessed, 

// we can safely add props.a.b as a dependency and preserve both 

// nullthrows and the correct dependency set. 

scope @0 { 

let x = []; 

x.push(props.a?.b); 

x.push(props.a.b); 

} 

``` 

(See added test case `reduce-reactive-cond-memberexpr-join` + its comment block 
for a more detailed explanation` 

- (the approach taken by this PR) 

We can add the `requiredPath` as a potentially unconditional access (dependent 
on other control flow) and `requiredPath + optionalPath` as a conditional 
dependency.
2023-03-27 10:41:05 -04:00
Jan Kassens
afea1d0c53 [flow] make Flow suppressions explicit on the error (#26487)
Added an explicit type to all $FlowFixMe suppressions to reduce
over-suppressions of new errors that might be caused on the same lines.

Also removes suppressions that aren't used (e.g. in a `@noflow` file as
they're purely misleading)

Test Plan:
yarn flow-ci
2023-03-27 13:43:04 +02:00
Andrew Clark
768f965de2 Suspensily committing a prerendered tree (#26434)
Prerendering a tree (i.e. with Offscreen) should not suspend the commit
phase, because the content is not yet visible. However, when revealing a
prerendered tree, we should suspend the commit phase if resources in the
prerendered tree haven't finished loading yet.

To do this properly, we need to visit all the visible nodes in the tree
that might possibly suspend. This includes nodes in the current tree,
because even though they were already "mounted", the resources might not
have loaded yet, because we didn't suspend when it was prerendered.

We will need to add this capability to the Offscreen component's
"manual" mode, too. Something like a `ready()` method that returns a
promise that resolves when the tree has fully loaded.

Also includes some fixes to #26450. See PR for details.
2023-03-26 23:48:37 -04:00
Sebastian Silbermann
d12bdcda69 Fix Flow types of useEffectEvent (#26468)
## Summary

Just copied the types over from the internal types. Type error was
hidden by overly broad FlowFixMe. With `$FlowFixMe[not-a-function]` we
would've seen the actual issue:
```
Cannot return `dispatcher.useEffectEvent(...)` because  `T` [1] is incompatible with  undefined [2].Flow(incompatible-return)
```

## How did you test this change?

- [x] yarn flow dom-node
- [x] CI
2023-03-25 20:24:00 +01:00
Josh Story
73b6435ca4 [Float][Fiber] Implement waitForCommitToBeReady for stylesheet resources (#26450)
Before a commit is finished if any new stylesheet resources are going to
mount and we are capable of delaying the commit we will do the following

1. Wait for all preloads for newly created stylesheet resources to load
2. Once all preloads are finished we insert the stylesheet instances for
these resources and wait for them all to load
3. Once all stylesheets have loaded we complete the commit

In this PR I also removed the synchronous loadingstate tracking in the
fizz runtime. It was not necessary to support the implementation on not
used by the fizz runtime itself. It makes the inline script slightly
smaller

In this PR I also integrated ReactDOMFloatClient with
ReactDOMHostConfig. It leads to better code factoring, something I
already did on the server a while back. To make the diff a little easier
to follow i make these changes in a single commit so you can look at the
change after that commit if helpful

There is a 500ms timeout which will finish the commit even if all
suspended host instances have not finished loading yet

At the moment error and load events are treated the same and we're
really tracking whether the host instance is finished attempting to
load.
2023-03-24 19:17:38 -07:00
dan
175962c10c Fix remaining CommonJS imports after Rollup upgrade (#26473)
Follow-up to https://github.com/facebook/react/pull/26442.

It looks like we missed a few cases where we default import a CommonJS
module, which leads to Rollup adding `.default` access, e.g.
`require('webpack/lib/Template').default` in the output.

To fix, add the remaining cases to the list of exceptions. Verified by
going through all `externals` in the bundle list, and manually checking
the webpack plugin.
2023-03-25 00:05:23 +00:00
Mofei Zhang
4aef9dac49 [be] Make ReactiveScopeDependency.path nonnullable
--- 

Previously, both `path=null` and `path=[]` could represent a dependency with no 
property path (i.e. the result of a LoadLocal with no PropertyLoad). 

Make path non-nullable so we don't have to add null checks everywhere.
2023-03-24 17:53:06 -04:00
Mofei Zhang
b07bbc36ae [buildhir] Patch: lower nested OptionalMemberExpr 2023-03-24 17:53:04 -04:00
Mofei Zhang
5e95967c7c [be][dependencies] Remove control flow info from PropertyLoad sidemap
--- 

We don't need to store whether a `PropertyLoad` happens within a conditional 
(within its reactive scope). In fact, the PropertyLoad producing a rval often is 
in a different ReactiveScope from where the rval is used. 

We only need to add `#inConditionalWithinScope` when we actually visit a 
reactive dependency.
2023-03-24 17:53:03 -04:00
Joe Savona
9ff82c3c10 Support for (Optional)MemberExpression callee in OptionalCall
Earlier PRs bailed out when the callee of an OptionalCallExpression was a 
MemberExpression or OptionalMemberExpression (ie for optional method calls). 
This PRs expands support for optional method calls, including when the receiver, 
method, or both are optional. Even better, we don't need to add any additional 
terminals or instruction variants for this case - the one new OptionalCall 
terminal from earlier in the stack works for all these cases.
2023-03-24 14:22:16 -07:00
Joe Savona
326ee664dc Test cases for optional call
Tests, focusing on two key behaviors: 

* Dependencies of the args are treated as conditional, since the call may not 
happen 

* Args cannot be memoized independently, even when that would be valid for a 
non-optional call.
2023-03-24 14:22:15 -07:00
Joe Savona
77bb9ff765 ReactiveFunction and codegen for optional calls
Implements HIR->ReactiveFunction conversion and Codegen for optional calls. We 
add a new OptionalCall variant of ReactiveValue, which is a SequenceExpression 
that describes the evaluation of the args and the call itself. This is then 
straightforward to codgen.
2023-03-24 14:22:14 -07:00
Joe Savona
feb8e924e4 BuildHIR for OptionalCallExpression
Implements lowering for a subset of optional calls - specifically, we don't 
(yet) support when the callee is a member expression or an optional member 
expression. So `foo?.()` works but we bailout on `object?.foo()` and 
`object.foo?.()`. 

For `<calleee>?.(<args>)` we lower as roughly: 

``` 

bb0: 

t0 = <callee> 

OptionalCall test=bb1 fallthrough= 

bb1 (value): 

Branch t0 consequent=bb2 alternate=bb3 

bb2 (value): 

...lower <args> here... 

t1 = Call t0, args 

StoreLocal res, t1 

Goto bb4 

bb3 (value): 

t2 = undefined 

StoreLocal res, t2 

Goto bb4 

bb4: 

// result in `res` here 

```
2023-03-24 14:22:13 -07:00
Joe Savona
40bd9b060c Scaffolding for OptionalCall
Adds a new `optional-call` terminal and sets up the appropriate handling in the 
visitors, with lowering/reactivefunction/codegen as todos for now and 
implemented in follow-ups.
2023-03-24 14:22:13 -07:00
Mengdi Chen
3fcf209ea4 React DevTools 4.27.3 -> 4.27.4 (#26470) 2023-03-24 15:45:26 -04:00
mofeiZ
568048af0f [tests] failing tests for dependencies and codegen (#1414) 2023-03-24 15:23:42 -04:00
Mengdi Chen
bde974ae40 [DevTools] missing file name in package.json (#26469)
resolves
https://github.com/facebook/react/pull/26337#issuecomment-1483004732
2023-03-24 14:45:27 -04:00
Mark Erikson
909c6dacfd Update Rollup to 3.x (#26442)
<!--
  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

This PR:

- Updates Rollup from 2.x to latest 3.x, and updates associated plugins
- Updates deprecated / altered config settings in the Rollup plugin
pipeline
- Fixes some file extension and import issues related to use of ESM in
`react-dom-webpack-server`
- Removes a now-obsolete `strip-unused-imports` Rollup plugin
- <s>Fixes an _existing_ bug with the Rollup 2.x plugin pipeline on
`main` that was causing parts of `DOMProperty.js` to get left out of the
`react-dom-webpack-server` JS bundles, by adding a new plugin to tell
Rollup to treat that file as if it as side effects</s>

This PR should be functionally identical to the other existing "Rollup 3
upgrade" PR at #26078 . I'm filing this as a near-duplicate because I'm
ready to push this change through ASAP so that I can follow it up with a
PR that adds sourcemap support, that PR's artifact diffing seems like
it's possibly stuck and I want to compare the build results, and I've
got this set up against latest `main`.

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

This gets React's build setup updated to the latest Rollup version,
which is generally a good practice, but also ensures that any further
Rollup config tweaks can be done using the current Rollup docs as a
reference.

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

- Made builds from the latest `main`
- Updated Rollup package versions and cross-compared the changes I
needed to make locally to get successful builds vs #26078
- Diffed the output folders between `main` and this PR, and confirmed
that the bundle contents are identical (with the exception of version
strings and the `react-dom-webpack-server` bundle fix re-adding missing
`DOMProperty.js` content)
2023-03-24 18:08:41 +00:00
Joe Savona
0ee5e482a2 Optional computed member expressions are not supported (add validation)
We don't propagate the `optional` flag through to codegen, so let's error on 
this for now
2023-03-23 09:01:21 -07:00
Mofei Zhang
ef83c02d3c [hir][typer] infer polymorphic types from PropertyLoad and PropertyCall
--- 

Expand Hindley Milner type inference to infer dependent types. 

Say `t` is a typevar and `t'` is some type (a built-in type, phi node, or 
another typevar). 

Our type equations are as follows (please edit/correct notation 😅) 

- type substitution: `t = t'`, 

- ~~dependent~~ polymorphic property load: `t = t'.prop` 

- polymorphic function call `t = fnCall{returnType}` 

- ~~dependent property call: `t = t'.prop` (only if t'.prop is a function 
type)~~ 

- ~~dependent return type: `t = t'.[[returntype]]`~~
2023-03-23 15:08:19 -04:00
Mofei Zhang
447f401f32 [be][tests] Remove all hir-tests (cleanup for ObjectShape stack)
--- 

+10 −1,698 lines [[insert impacc macro]] 

The ObjectShape stacks (#1350, #1358) used these tests to record changes in 
inferred types (and associated ObjectShapes), reference effects, and mutable 
ranges. 

Now that those PRs have landed, we can delete these tests. They are somewhat 
fragile (changing anytime HIR / printHIR is changed) and easily cause 
rebase/merge conflicts.
2023-03-23 15:08:18 -04:00
Mofei Zhang
c3589a9565 [hir] infer reference effects for property call
--- 

This PR does not add inference for normal `CallExpression`s, since built-in 
functions for `Array` and `Object` are usually only valid if called with a 
correctly-typed `this`. If we want codegen to preserve source code semantics, 
Forget should only add inferred types it is confident about. 

This PR also adds `returnEffect` to FunctionSignature. `returnEffect = Store` if 
this function is known to always return a captured value from `receiver` or 
`args`.
2023-03-23 15:08:18 -04:00
Mofei Zhang
76e6eff110 [hir][typer] infer polymorphic types from PropertyLoad and PropertyCall
--- 

Expand Hindley Milner type inference to infer dependent types. 

Say `t` is a typevar and `t'` is some type (a built-in type, phi node, or 
another typevar). 

Our type equations are as follows (please edit/correct notation 😅) 

- type substitution: `t = t'`, 

- ~~dependent~~ polymorphic property load: `t = t'.prop` 

- polymorphic function call `t = fnCall{returnType}` 

- ~~dependent property call: `t = t'.prop` (only if t'.prop is a function 
type)~~ 

- ~~dependent return type: `t = t'.[[returntype]]`~~
2023-03-23 15:08:17 -04:00
Joe Savona
9507493ee9 Allow accessing properties of globals in switch test values
We limit the types of expressions allowed as switch case test values because we 
our HIR doesn't yet preserve order-of-evaluation for switch test values (we 
model them as being evaluated prior to entering the switch, as opposed to 
lazily, when the case is reached). One common pattern internally is test case 
values that are properties of a global, eg you have some bag of enum values and 
are comparing against that: 

```javascript 

// at module scope, or imported from another module: 

const OPTIONS = {FOO: 'foo'}; 

// in a component 

switch (value) { 

case OPTIONS.FOO: { ... } 

} 

``` 

This PR allows this specific case, ie member expressions where the innermost 
object is a global identifier.
2023-03-22 14:36:50 -07:00
Joe Savona
7d43730319 [be] Remove stale global handling code
I forgot to remove this when i made globals explicit.
2023-03-22 14:36:49 -07:00
Joe Savona
14c03b897f Consolidate {Property,Computed}Call into MethodCall
Now that we model the method resolution via a PropertyLoad or ComputedLoad, we 
don't need to distinguish between PropertyCall and ComputedCall. These two call 
variants are now combined into a single MethodCall variant.
2023-03-22 14:36:48 -07:00
Joe Savona
5f1bebbeae ComputedCall modeled as ComputedLoad + Call for order-of-evaluation semantics
This is the version of @mofeiZ's change for PropertyLoad, but made to work on 
ComputedCall. We force the method to be evaluated in the same scope as the call 
in InferReactiveScopeVariables.
2023-03-22 14:36:48 -07:00
Mofei Zhang
8ef22a2a90 [hir] todo tests for lambda capture
--- 

(I'm not sure if these are already known issues. I found them while playing 
around with lambda captures. They are also reproducible on main / stable) 

I have some limited understanding of lambda captures after reading Sathya's 
posts -- please correct if/where this is incorrect 

``` 

function Component() { 

// instr1 

// instr2 

const func3 = function(...) { 

// func3instr1 

} 

} 

``` 

We currently determine effects of captured references in `AnalyzeFunctions`, 
before InferReferenceEffects. 

- i.e. for some function 

1. dependencies of all functions (func3.deps) 

2. prefix traversal of all instructions (e.g. instr1, instr2, func3.deps, 
func3instr1, ...) 

- is this just an implementation decision? i.e. what is stopping us from postfix 
traversal in InferReferenceEffects (e.g. instr1, instr2, func3instr1, 
func3.deps) 

As such, for each captured reference, `AnalyzeFunctions` needs to assign a 
reference effect. We currently check `MutableRange`, which seems to miss a few 
cases 

- We do not model assignments to primitives correctly, since primitives do not 
have a mutable range. 

- We're not able to model captured (but not mutated) values correctly. 

Would it be possible to consolidate `AnalyzeFunctions` into 
InferReferenceEffects, using some post-order traversal (iterating over a 
function's instructions to collect its dependencies + associated capture 
effects)? I definitely don't understand lambdas completely, so please tell me 
what I'm missing
2023-03-22 15:58:07 -04:00
Mofei Zhang
501fbd8ed8 [hir] infer reference effects for property call
--- 

This PR does not add inference for normal `CallExpression`s, since built-in 
functions for `Array` and `Object` are usually only valid if called with a 
correctly-typed `this`. If we want codegen to preserve source code semantics, 
Forget should only add inferred types it is confident about. 

This PR also adds `returnEffect` to FunctionSignature. `returnEffect = Store` if 
this function is known to always return a captured value from `receiver` or 
`args`.
2023-03-22 15:58:06 -04:00
Mofei Zhang
241101c08a [builtins] Fix effects: capture -> read, store -> mutate
--- 

I didn't properly understand Capture and Store effects previously, just 
correcting those mistakes! 

These functions are all synchronously mutative, so they should use Read / 
Mutate, not Capture + Store
2023-03-22 15:50:40 -04:00
Mofei Zhang
a7191d4e3b [hir][typer] infer polymorphic types from PropertyLoad and PropertyCall
--- 

Expand Hindley Milner type inference to infer dependent types. 

Say `t` is a typevar and `t'` is some type (a built-in type, phi node, or 
another typevar). 

Our type equations are as follows (please edit/correct notation 😅) 

- type substitution: `t = t'`, 

- ~~dependent~~ polymorphic property load: `t = t'.prop` 

- polymorphic function call `t = fnCall{returnType}` 

- ~~dependent property call: `t = t'.prop` (only if t'.prop is a function 
type)~~ 

- ~~dependent return type: `t = t'.[[returntype]]`~~
2023-03-22 15:50:40 -04:00
Rubén Norte
9c54b29b44 Remove ReactFabricPublicInstance and used definition from ReactNativePrivateInterface (#26437)
## Summary

Now that React Native owns the definition for public instances in Fabric
and ReactNativePrivateInterface provides the methods to create instances
and access private fields (see
https://github.com/facebook/react-native/pull/36570), we can remove the
definitions from React.

After this PR, React Native public instances will be opaque types for
React and it will only handle their creation but not their definition.
This will make RN similar to DOM in how public instances are handled.

This is a new version of #26418 which was closed without merging.

## How did you test this change?

* Existing tests.
* Manually synced the changes in this PR to React Native and tested it
end to end in Meta's infra.
2023-03-22 17:54:36 +00:00
Ricky
f77099b6f1 Remove layout effect warning on the server (#26395)
## Overview

This PR unfortunately removes the warning emitted when using layout
effects on the server:

> useLayoutEffect does nothing on the server, because its effect cannot
be encoded into the server renderer's output format. This will lead to a
mismatch between the initial, non-hydrated UI and the intended UI. To
avoid this, useLayoutEffect should only be used in components that
render exclusively on the client. See
https://reactjs.org/link/uselayouteffect-ssr for common fixes.

## Why this warning exists
The new docs explain this really well. Adding a screenshot because as
part of this change, we'll be removing these docs.

<img width="1562" alt="Screenshot 2023-03-15 at 10 56 17 AM"
src="https://user-images.githubusercontent.com/2440089/225349148-f0e57c3f-95f5-4f2e-9178-d9b9b221c28d.png">

## Why are we changing it

In practice, users are not just ignoring this warning, but creating
hooks to bypass this warning by switching the useLayoutEffect hook on
the server instead of fixing it. This battle seems to be lost, so let's
remove the warning so at least users don't need to use the indirection
hook any more. In practice, if it's an issue, you should see the
problems like flashing the wrong content on first load in development.
2023-03-22 13:33:48 -04:00
Andrew Clark
51a7c45f87 Bugfix: SuspenseList incorrectly forces a fallback (#26453)
Fixes a bug in SuspenseList that @kassens found when deploying React to
Meta. In some scenarios, SuspenseList would force the fallback of a
deeply nested Suspense boundary into fallback mode, which should never
happen under any circumstances — SuspenseList should only affect the
nearest descendent Suspense boundaries, without going deeper.

The cause was that the internal ForceSuspenseFallback context flag was
not being properly reset when it reached the nearest Suspense boundary.
It should only be propagated shallowly.

We didn't discover this earlier because the scenario where it happens is
not that common. To trigger the bug, you need to insert a new Suspense
boundary into an already-mounted row of the list. But often when a new
Suspense boundary is rendered, it suspends and shows a fallback, anyway,
because its content hasn't loaded yet.

Another reason we didn't discover this earlier is because there was
another bug that was accidentally masking it, which was fixed by #25922.
When that fix landed, it revealed this bug.

The SuspenseList implementation is complicated but I'm not too concerned
with the current messiness. It's an experimental API, and we intend to
release it soon, but there are some known flaws and missing features
that we need to address first regardless. We'll likely end up rewriting
most of it.

Co-authored-by: Jan Kassens <jkassens@meta.com>
2023-03-22 13:33:02 -04:00
Sebastian Markbåge
afb3d51dc6 Fix enableClientRenderFallbackOnTextMismatch flag (#26457)
With this flag off, we don't throw and therefore don't patch up the tree
when suppression is off.

Haven't tested.

---------

Co-authored-by: Rick Hanlon <rickhanlonii@fb.com>
2023-03-22 13:12:41 -04:00
Rubén Norte
8e17bfd144 Make InternalInstanceHandle type opaque in ReactNativeTypes (#26461)
## Summary

This type was defined as `mixed` to avoid bringing the whole definition
from React to React Native, but its definition is visible to RN. This
type should be opaque to RN, so this makes it explicit.

## How did you test this change?

Applied the same changes in the React Native repository and could use
the type without issues.
2023-03-22 15:39:52 +00:00
Mengdi Chen
8bdf162bcc React DevTools 4.27.2 -> 4.27.3 (#26459)
bump version
2023-03-22 11:20:10 -04:00
Sebastian Markbåge
b93b4f0745 Should not throw for children of iframe or object (#26458)
Still needs a regression test to test this for the future.
2023-03-22 13:56:20 +01:00
Leedom
c0b34bc5fb chore: update links of docs and api (#26455)
Update new links of docs and api  for react package.
> [Documentation](https://react.dev/)
> [API](https://react.dev/reference/react)
2023-03-22 12:56:18 +01:00
Leedom
56f7a90e68 chore: update new docs links for react-dom (#26456)
Update new documentation links in react-dom's readme.
> [react-dom](https://react.dev/reference/react-dom)
> [react-dom/client](https://react.dev/reference/react-dom/client)
> [react-dom/server](https://react.dev/reference/react-dom/server)
2023-03-22 12:55:06 +01:00
Jan Kassens
bd5e32309d Small Flow upgrade to 0.202.0 (#26435)
Easy upgrade.

`exact_by_default=true` is now the default, so we can remove it.
2023-03-22 12:52:13 +01:00
Valor(华洛)
ffb6733eef fix docs link for useSyncExternalStore (#26452)
## Summary

Update readme to new documentation links to
[`React.useSyncExternalStore`](https://react.dev/reference/react/useSyncExternalStore

## How did you test this change?

This is just a documentation change, so we don't need to test it

Co-authored-by: 田源 <tianyuan@eol.cn>
2023-03-22 01:39:05 +00:00
Mofei Zhang
01a6502baa [hir] represent PropertyCall as receiver + PropertyLoad
How Forget currently lowers PropertyCall: 

```js 

// source: [[ calleeExpr ]].propertyName( [[ argExpr0 ]]) 

$0 = [[ calleeExpr ]] 

$1 = [[ argExpr0 ]] 

$2 = PropertyCall callee=$0 property="propertyName" args=[$1] 

``` 

This PR changes the lowering: 

```js 

// source: [[ calleeExpr ]].propertyName( [[ argExpr0 ]]) 

$0 = [[ calleeExpr ]] 

$1 = PropertyLoad $0 "propertyName" 

$2 = [[ argExpr0 ]] 

$3 = PropertyCall callee=$0 fn=$1 args=[$2] 

``` 

From my understanding, `PropertyCall` needs the receiver to properly model JS 
semantics which is something like `resolvedFn.apply(resolvedCallee, arg0, arg1, 
...)`. This is additionally useful for: 

- Fine-grained mutability / alias analysis. The property call is technically a 
read of the resolved function, and a mutate of the callee. 

- Dependency tracking. While we could special case PropertyCall, this 
representation would correctly add both callee and callee.propertyName as 
dependencies for PropertyCall. 

e.g. 

```js 

let x = []; 

mutate(x); 

useFreeze(x); 

let y = {}; 

y.a = x.bar(); 

return y; 

```
2023-03-21 14:57:12 -04:00
Mofei Zhang
6ce4cd0898 [rhir] Revert logic that dedupes inlined temporaries
Reverts #1199, which was added before we properly supported destructuring 
assignment. 

Next PR (changes to PropertyCall in #1384) will lower two references to the same 
named identifier (the property call receiver)
2023-03-21 14:57:12 -04:00
Mofei Zhang
ab1d11a446 [hir] remove constant propagation for ComputedCall 2023-03-21 14:57:11 -04:00
Mofei Zhang
ec345ca538 [wip][typer] Infer Array instance properties
--- 

TODO: add inference for TypedFunction to `InferReferenceEffects`
2023-03-21 14:57:11 -04:00
Joe Savona
ef34ca6cb0 Model other assignment variants as values
The previous PR only updated simple assignment expressions (where the lvalue is 
an identifier), this PR extends the same idea to all assignment variants. Note 
that there is one case that doesn't work yet, which is complex destructuring 
assignment as a value: 

```javascript 

let x = makeObject(); 

x.foo(([[x]] = makeObject())); 

``` 

What happens here is that we lower the destructuring to a series of steps: 

``` 

tmp1: Destructure Const [ tmp0 ]  = makeObject(); 

tmp2: Destructure Reassign [ x ] = tmp0; 

PropertyCall x, 'foo', [ tmp1 ] 

``` 

Thankfully we can detect this case: if we have a const/let declaration with an 
lvalue, that's invalid. See the new error test case which shows we correctly 
detect & reject this case for now.
2023-03-21 10:01:09 -07:00
Joe Savona
bf1db812a8 Model assignment as value
This PR subtly changes how we represent assignment expressions in order to 
accurately model them _as expressions_. Specifically, the result of lowering an 
assignment is now the temporary created for the assignment's lvalue. This allows 
us to restore the assignment as a value (expression) during codegen. Note how 
this fixes a bug and cleans up some output.
2023-03-21 10:01:08 -07:00
Joe Savona
f4c4dcb1b3 Instruction-specific propagation to account for assignment-as-value
Updates ConstantPropagation so that each instruction is responsible for whether 
to replace its `.value` with the resolved constant value (if found). 
Specifically, for `StoreLocal` we don't want to replace the value — we want to 
keep the assignment — but we do want to propagate the _result_ of the assignment 
downstream. This more accurately models the semantics of assignment expressions, 
and helps with subsequent PRs.
2023-03-21 10:01:07 -07:00
Samuel Susla
0018cf2246 Add REVISION file to react-fbsource-import (#26448)
For DiffTrain to fbsource, we need REVISION file in compiled-rn folder
2023-03-21 16:18:20 +00:00
Andrew Clark
12a1d140e3 Don't prerender siblings of suspended component (#26380)
Today if something suspends, React will continue rendering the siblings
of that component.

Our original rationale for prerendering the siblings of a suspended
component was to initiate any lazy fetches that they might contain. This
was when we were more bullish about lazy fetching being a good idea some
of the time (when combined with prefetching), as opposed to our latest
thinking, which is that it's almost always a bad idea.

Another rationale for the original behavior was that the render was I/O
bound, anyway, so we might as do some extra work in the meantime. But
this was before we had the concept of instant loading states: when
navigating to a new screen, it's better to show a loading state as soon
as you can (often a skeleton UI), rather than delay the transition.
(There are still cases where we block the render, when a suitable
loading state is not available; it's just not _all_ cases where
something suspends.) So the biggest issue with our existing
implementation is that the prerendering of the siblings happens within
the same render pass as the one that suspended — _before_ the loading
state appears.

What we should do instead is immediately unwind the stack as soon as
something suspends, to unblock the loading state.

If we want to preserve the ability to prerender the siblings, what we
could do is schedule special render pass immediately after the fallback
is displayed. This is likely what we'll do in the future. However, in
the new implementation of `use`, there's another reason we don't
prerender siblings: so we can preserve the state of the stack when
something suspends, and resume where we left of when the promise
resolves without replaying the parents. The only way to do this
currently is to suspend the entire work loop. Fiber does not currently
support rendering multiple siblings in "parallel". Once you move onto
the next sibling, the stack of the previous sibling is discarded and
cannot be restored. We do plan to implement this feature, but it will
require a not-insignificant refactor.

Given that lazy data fetching is already bad for performance, the best
trade off for now seems to be to disable prerendering of siblings. This
gives us the best performance characteristics when you're following best
practices (i.e. hoist data fetches to Server Components or route
loaders), at the expense of making an already bad pattern a bit worse.

Later, when we implement resumable context stacks, we can reenable
sibling prerendering. Though even then the use case will mostly be to
prerender the CPU-bound work, not lazy fetches.
2023-03-21 10:24:56 -04:00
Sathya Gunasekaran
63450d5768 [test] Update test snapshot 2023-03-21 14:15:01 +00:00
Andrew Clark
77ba1618a5 Bugfix: Remove extra render pass when reverting to client render (#26445)
(This was reviewed and approved as part of #26380; I'm extracting it
into its own PR so that it can bisected later if it causes an issue.)

I noticed while working on a PR that when an error happens during
hydration, and we revert to client rendering, React actually does _two_
additional render passes instead of just one. We didn't notice it
earlier because none of our tests happened to assert on how many renders
it took to recover, only on the final output.

It's possible this extra render pass had other consequences that I'm not
aware of, like messing with some assumption in the recoverable errors
logic.

This adds a test to demonstrate the issue. (One problem is that we don't
have much test coverage of this scenario in the first place, which
likely would have caught this earlier.)
2023-03-20 22:07:53 -04:00
Sebastian Markbåge
520f7f3ed4 Refactor ReactDOMComponent to use flatter property operations (#26433)
This is in line with the refactor I already did on Fizz earlier and
brings Fiber up to a similar structure.

We end up with a lot of extra checks due the extra abstractions we use
to check the various properties. This uses a flatter and more inline
model which makes it easier to see what each property does. The tradeoff
is that a change might need changes in more places.

The general structure is that there's a switch for tag first, then a
switch for each attribute special case, then a switch for the value. So
it's easy to follow where each scenario will end up and there shouldn't
be any unnecessary code executed along the way.

My goal is to eventually get rid of the meta-programming in DOMProperty
and CSSProperty but I'm leaving that in for now - in line with Fizz.

My next step is moving around things a bit in the diff/commit phases.
This is the first step to more refactors for perf and size, but also
because I'm adding more special cases so I need to have a flatter
structure that I can reason about for those special cases.
2023-03-20 20:56:14 -04:00
Sathya Gunasekaran
9b5ff25b3b [Babel] Desugar ArrowFunctionExpression
Rewrite ArrowFunctionExpression to FunctionDeclaration and compile it. This lets 
us reuse all the export gating logic, rather than writing separate, specific 
logic for ArrowFunctionExpression.
2023-03-20 17:42:58 +00:00
Sathya Gunasekaran
ff571d8d85 [Babel] Refactor compilation checks into a separate function 2023-03-20 17:42:57 +00:00
Sathya Gunasekaran
93b79e4aa0 [Babel] Refactor visitor to separate function
This lets us extend to ArrowFunctionExpression
2023-03-20 17:42:56 +00:00
Sathya Gunasekaran
3605199646 [Babel] Refactor gating test
Move to separate function
2023-03-20 17:42:56 +00:00
Joe Savona
3e84c870f6 Helper for lowering args
Cleans up duplicated code for processing call/constructor arguments. As a side 
benefit, we now support spread elements for constructor arguments (and if we 
want to change how we represent that, we can do it in one place).
2023-03-20 12:55:14 -07:00
Andrew Clark
0131d0cff4 Check if suspensey instance resolves in immediate task (#26427)
When rendering a suspensey resource that we haven't seen before, it may
have loaded in the background while we were rendering. We should yield
to the main thread to see if the load event fires in an immediate task.

For example, if the resource for a link element has already loaded, its
load event will fire in a task right after React yields to the main
thread. Because the continuation task is not scheduled until right
before React yields, the load event will ping React before it resumes.

If this happens, we can resume rendering without showing a fallback.

I don't think this matters much for images, because the `completed`
property tells us whether the image has loaded, and during a non-urgent
render, we never block the main thread for more than 5ms at a time (for
now — we might increase this in the future). It matters more for
stylesheets because the only way to check if it has loaded is by
listening for the load event.

This is essentially the same trick that `use` does for userspace
promises, but a bit simpler because we don't need to replay the host
component's begin phase; the work-in-progress fiber already completed,
so we can just continue onto the next sibling without any additional
work.

As part of this change, I split the `shouldSuspendCommit` host config
method into separate `maySuspendCommit` and `preloadInstance` methods.
Previously `shouldSuspendCommit` was used for both.

This raised a question of whether we should preload resources during a
synchronous render. My initial instinct was that we shouldn't, because
we're going to synchronously block the main thread until the resource is
inserted into the DOM, anyway. But I wonder if the browser is able to
initiate the preload even while the main thread is blocked. It's
probably a micro-optimization either way because most resources will be
loaded during transitions, not urgent renders.
2023-03-20 12:35:10 -04:00
Rubén Norte
3554c8852f Clean interface for public instances between React and React Native (#26416)
## Summary

We are going to move the definition of public instances from React to
React Native to have them together with the native methods in Fabric
that they invoke. This will allow us to have a better type safety
between them and iterate faster on the implementation of this proposal:
https://github.com/react-native-community/discussions-and-proposals/pull/607

The interface between React and React Native would look like this after
this change and a following PR (#26418):

React → React Native:
```javascript
ReactNativePrivateInterface.createPublicInstance // to provide via refs
ReactNativePrivateInterface.getNodeFromPublicInstance // for DevTools, commands, etc.
ReactNativePrivateInterface.getNativeTagFromPublicInstance // to implement `findNodeHandle`
```

React Native → React (ReactFabric):
```javascript
ReactFabric.getNodeFromInternalInstanceHandle // to get most recent node to call into native
ReactFabric.getPublicInstanceFromInternalInstanceHandle // to get public instances from results from native
```

## How did you test this change?

Flow
Existing unit tests
2023-03-20 13:35:18 +00:00
Samuel Susla
c57b90f50d [DiffTrain] Add artifacts for React Native to compiled (#26204) 2023-03-20 11:23:55 +00:00
Andrew Clark
842bd787a5 Fix sizebot not working due to missing auth token (#26423)
Sizebot works by fetching the base artifacts from CI. CircleCI recently
updated this endpoint to require an auth token. This is a problem for PR
branches, where sizebot runs, because we don't want to leak the token to
arbitrary code written by an outside contributor.

This only affects PR branches. CI workflows that run on the main branch
are allowed to access environment variables, because only those with
push access can land code in main.

As a temporary workaround, we'll fetch the assets from a mirror,
react-builds.vercel.app. This is the same app that hosts the sizebot
diff previews.

Need to figure out a longer term solution. Perhaps by converting sizebot
into a proper GitHub app.
2023-03-18 16:22:20 -04:00
Joe Savona
ff8868e8d1 Fix self-closing jsx element codegen
We were never emitting self-closing jsx elements because children were never 
null, we now set children to null if they were empty in the AST.
2023-03-17 16:18:11 -07:00
Joe Savona
a7ac20973f Support JsxMemberExpression 2023-03-17 16:18:07 -07:00
mofeiZ
0c8f11e13f [test][ssa] Add todo test for reassigning in rval
From my understanding, `LeaveSSA` is not currently handling reassignment in 
rvals. 

Source code 

```js 

let x = foo(); 

x(x = bar()); 

``` 

Simplified HIR (from EnterSSA) 

``` 

[1]  $1 = StoreLocal Let x$0 = [[ foo() ]]       // x$1 = foo() 

[2] $2 = LoadLocal x$1                           // t0 = x$1 

[3] $4 = StoreLocal Reassign x$3 = [[ bar() ]]   // t1 = x$3 = bar() 

[4] $5 = CallExpression $2 ($4)                   // t0(t1) 

``` 

codegen: 

```js 

let x; 

x = foo(); 

x = bar(); 

x(x); 

```
2023-03-17 20:08:20 -04:00
Joe Savona
f838ebb34e Simpler fix for missed reactivity bug
Fixes the issue @mofeiZ identified, where mutations of an object via a 
propertyload were not tracking reactivity.
2023-03-17 15:07:14 -07:00
Andrew Clark
db281b3d9c Feature: Suspend commit without blocking render (#26398)
This adds a new capability for renderers (React DOM, React Native):
prevent a tree from being displayed until it is ready, showing a
fallback if necessary, but without blocking the React components from
being evaluated in the meantime.

A concrete example is CSS loading: React DOM can block a commit from
being applied until the stylesheet has loaded. This allows us to load
the CSS asynchronously, while also preventing a flash of unstyled
content. Images and fonts are some of the other use cases.

You can think of this as "Suspense for the commit phase". Traditional
Suspense, i.e. with `use`, blocking during the render phase: React
cannot proceed with rendering until the data is available. But in the
case of things like stylesheets, you don't need the CSS in order to
evaluate the component. It just needs to be loaded before the tree is
committed. Because React buffers its side effects and mutations, it can
do work in parallel while the stylesheets load in the background.

Like regular Suspense, a "suspensey" stylesheet or image will trigger
the nearest Suspense fallback if it hasn't loaded yet. For now, though,
we only do this for non-urgent updates, like with startTransition. If
you render a suspensey resource during an urgent update, it will revert
to today's behavior. (We may or may not add a way to suspend the commit
during an urgent update in the future.)

In this PR, I have implemented this capability in the reconciler via new
methods added to the host config. I've used our internal React "no-op"
renderer to write tests that demonstrate the feature. I have not yet
implemented Suspensey CSS, images, etc in React DOM. @gnoff and I will
work on that in subsequent PRs.
2023-03-17 18:05:11 -04:00
lauren
6310087f09 [ci] Fix download_base_build_for_sizebot (#26422)
CircleCI now enforces passing a token when fetching artifacts. I'm also
deleting the old request-promise-json dependency because AFAIK we were
only using it to fetch json from circleci about the list of available
artifacts – which we can just do using node-fetch. Plus, the underlying
request package it uses has been deprecated since 2019.
2023-03-17 13:04:20 -07:00
lauren
6854a3cf6d [difftrain] Fix broken workflow (#26421)
Seems like CircleCI now enforces passing a token when fetching
artifacts. I provisioned a new read-only CircleCI token just for
difftrain.

test plan: see https://github.com/facebook/react/actions/runs/4450679268
2023-03-17 12:16:55 -07:00
Jan Kassens
55308554ed [www] enable enableFilterEmptyStringAttributesDOM flag (#26410) 2023-03-17 12:09:36 -04:00
Ibrahim Amin
163d86e195 Updated comment message (#26158)
a simple grammar fix.
2023-03-17 14:48:44 +00:00
Rubén Norte
108aed083e Fix use of stale props in Fabric events (#26408)
## Summary

We had to revert the last React sync to React Native because we saw
issues with Responder events using stale event handlers instead of
recent versions.

I reviewed the merged PRs and realized the problem was in the refactor I
did in #26321. In that PR, we moved `currentProps` from `canonical`,
which is a singleton referenced by all versions of the same fiber, to
the fiber itself. This is causing the staleness we observed in events.

This PR does a partial revert of the refactor in #26321, bringing back
the `canonical` object but moving `publicInstance` to one of its fields,
instead of being the `canonical` object itself.

## How did you test this change?

Existing unit tests continue working (I didn't manage to get a repro
using the test renderer).
I manually tested this change in Meta infra and saw the problem was
fixed.
2023-03-17 11:27:49 +00:00
Sebastian Markbåge
8fa41ffa27 Don't "fix up" mismatched text content with suppressedHydrationWarning (#26391)
In concurrent mode we error if child nodes mismatches which triggers a
recreation of the whole hydration boundary. This ensures that we don't
replay the wrong thing, transform state or other security issues.

For text content, we respect `suppressedHydrationWarning` to allow for
things like `<div suppressedHydrationWarning>{timestamp}</div>` to
ignore the timestamp. This mode actually still patches up the text
content to be the client rendered content.

In principle we shouldn't have to do that because either value should be
ok, and arguably it's better not to trigger layout thrash after the
fact.

We do have a lot of code still to deal with patching up the tree because
that's what legacy mode does which is still in the code base. When we
delete legacy mode we would still be stuck with a lot of it just to deal
with this case.

Therefore I propose that we change the semantics to not patch up
hydration errors for text nodes. We already don't for attributes.
2023-03-16 22:39:17 -04:00
mofeiZ
2148b4e8ca [test][hir-lower] todo: lower property calls in evaluation order
We currently are not lowering property calls in evaluation order. 

I wonder if the following lowering for a PropertyCall (with static or computed 
property) is semantically equivalent to source: 

1. eval + resolve receiver (store in t0) 

2. eval computed property (if present) 

3. resolve t0.property (binding the call to receiver and storing in t1) 

4. eval args 

5. eval t1(args) 

Although codegen might then generate something like this (if args are named 
temporaries) 

```js 

const tmp = receiver.property.bind(receiver); 

// lower args to temporaries 

tmp(arg1, arg2); 

```
2023-03-16 15:48:54 -04:00
Tianyu Yao
87c803d1da Fix a test case in ReactUpdates-test (#26399)
Just noticed the test isn't testing what it is meant to test properly.
The error `Warning: ReactDOM.render is no longer supported in React 18.
Use createRoot instead. Until you switch to the new API, your app will
behave as if it's running React 17. Learn more:
https://reactjs.org/link/switch-to-createroot` is thrown, the inner
`expect(error).toContain('Warning: Maximum update depth exceeded.');`
failed and threw jest error, and the outer `.toThrow('Maximum update
depth exceeded.')` happens to catch it and makes the test pass.
2023-03-16 12:27:15 -07:00
Jan Kassens
eaccf27c2e Revert "Remove hydrate entry point from www builds" (#26413)
Reverts facebook/react#26400.

Will take a look at the test failures before re-merging.
2023-03-16 14:01:20 -04:00
Sebastian Markbåge
480aa7785f Remove hydrate entry point from www builds (#26400)
As I understand it this isn't used at Meta and it would let us get rid
of at least legacy mode hydration code when we remove legacy mode from
OSS builds.
2023-03-16 11:39:34 -04:00
Ricky
9941cbacac Fix devtools tests after internal test changes (#26405) 2023-03-16 08:14:23 -04:00
Jarred Sumner
e4606c1e0e Add missing "react-dom/server.bun" entry in package.json "exports" (#26402)
<!--
  Thanks for submitting a pull request!
We appreciate you spending the time to work on these changes. Please
provide enough information so that others can review your pull request.
The three fields below are mandatory.

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

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

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

## Summary

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

`react-dom/server` in Bun (correctly) chooses `react-dom/server.bun`,
but `react-dom/server.bun` currently can't be imported because it is not
included in package.json `"exports"` (`react-dom/server` works,
`react-dom/server.bun` doesn't). Previously, I didn't think it was
necessary to do that, but it is too easy to accidentally run the browser
build in unit tests when importing `react-dom/server`

This also aligns behavior of package.json `"exports"` of
`react-dom/server.bun` with `react-dom/server.browser`,
`react-dom/server.node`, and the rest.

## How did you test this change?

Manually edited package.json in node_modules in a separate folder and
ran tests in Bun with `react-dom/server.bun` as the import specifier

<!--
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.
-->
2023-03-15 22:09:49 -04:00
Sophie Alpert
05777ffb01 Setting transition pending flag shouldn't be part of a surrounding transition (#26243)
Fixes #26226. (Is this the right fix?)
2023-03-15 18:10:53 -07:00
Ricky
21f6dba6a7 Sync from oss-experimental, not oss-stable (#26401)
## Overview

To test useEffectEvent, we need the experimental build of the lint
plugin.
2023-03-15 21:01:07 -04:00
Joe Savona
c6d1181ba3 Refactor DCE internal state into a class
Tidying up the implementation to make the next PR's changes easier to follow.
2023-03-15 13:20:26 -07:00
Jan Kassens
99aa082be0 Remove unstable_flushControlled (#26397)
This API has been fully replaced by `flushSync`.
2023-03-15 16:13:54 -04:00
Joe Savona
f54f653277 DeclareLocal instruction
Adds a `DeclareLocal` instruction which represents declaring a named variable 
without initializing it. Currently declarations without an initializer (`let x`) 
are transformed into a declaration to undefined (`let x = undefined`) which 
changes the semantics due to hoisting and TDZ (temporary dead zone). The correct 
thing is to represent declaration without initialization.
2023-03-15 13:12:07 -07:00
Joe Savona
f88713bba5 Support spread elements in CallExpression args 2023-03-15 17:13:50 -07:00
Joe Savona
957d8f1d44 Remove incomplete try/catch support 2023-03-15 15:36:17 -07:00
Joe Savona
5bc2c807c3 Support array pattern params 2023-03-15 15:33:14 -07:00
Joe Savona
b69afe0506 More precise error for canonical reassignment in a value block
These examples previously errored all the way in codegen, when we detected that 
a value block (eg a `while` test expression) was declaring a new variable. We 
now detect this in LeaveSSA and error. The actual fix is a bit tricky, we'd need 
to add a new declaration in the nearest block scope (or selectively not DCE the 
declaration if its reassigned in just this way).
2023-03-15 09:39:23 -07:00
Joe Savona
9200ad027d Throw CompilerError (todo) for unused conditional/logical
If a logical or conditional expression is unused, then a phi node isn't created 
for the identifier it assigns to. Then when we leave SSA form the two branches 
will assign to separate values, and we aren't sure which identifier to use as 
the lvalue of the resulting ReactiveInstruction (remember that 
logicals/conditionals decompose into control flow in HIR, but are a single 
compound instruction in ReactiveFunction). If the two sides don't assign to the 
same location, it could be because of a bug in the compiler or because the value 
wasn't used. Ideally we'd represent this explicitly, but for now i'm just making 
this a TODO since most logicals/conditionals should have their value used.
2023-03-15 09:39:23 -07:00
Rubén Norte
47cf4e578c Restore some guards in ReactFabricGlobalResponderHandler after refactor (#26394)
## Summary

I refactored this code in #26290 but forgot to add guards when the fiber
or the state node where null, and this is typed as `any` so Flow didn't
catch it.

This restores the same logic to guard against null.

## How did you test this change?

Existing tests.
2023-03-15 10:30:40 +00:00
Sebastian Markbåge
cfc1274e3b Disable IE innerHTML workaround behind a flag (#26390)
We don't need this workaround for SVG anymore and we don't need to
workaround MSApp's security model since Windows 10.
2023-03-14 23:27:04 -04:00
Joe Savona
7537df3d4e Support assignment expressions in value blocks
Enables support for assignment expressions in value blocks (which includes in 
loop init/test/update blocks). This was pretty straightforward, the main changes 
are: 

* During PropagateScopeDependencies, we currently record scope reassignments 
based on `Identifier` object identity. In the case where a variable is 
reassigned in multiple control-flow paths of a value block, however, there can 
be multiple object identities. So we now de-dupe reassignments based on 
identifier id. 

* MergeOverlappingScopes now treats value blocks as regular blocks, allowing it 
to correctly merge scopes from the value with other scopes from the outer block. 

Otherwise this is mostly just lots of tests. Note that there is an outstanding 
todo, which is that we currently error for ternaries and logicals whose value is 
unused (eg `cond ? (x = 1) : null`). I'll address that in a follow-up.
2023-03-14 20:02:05 -07:00
Sebastian Markbåge
a57f40d839 Undo dependency injection of batching (#26389)
There's currently a giant cycle between the event system, through
react-dom-bindings, reconciler and then react-dom. We resolve this cycle
using dependency injection. However, this all ends up in the same
bundle. It can be reordered to resolve the cycles. If we avoid
side-effects and avoid reading from module exports during
initialization, this should be resolvable in a more optimal way by the
compiler.
2023-03-14 21:40:43 -04:00
Sebastian Markbåge
d310d654a7 Avoid meta programming to initialize functions in module scope (#26388)
I'm trying to get rid of all meta programming in the module scope so
that closure can do a better job figuring out cyclic dependencies and
ability to reorder.

This is converting a lot of the patterns that assign functions
conditionally to using function declarations instead.

```
let fn;
if (__DEV__) {
  fn = function() {
    ...
  };
}
```
->
```
function fn() {
  if (__DEV__) {
    ...
  }
}
```
2023-03-14 21:00:22 -04:00
Sebastian Markbåge
21aee59e45 Delete unused DOM files (#26387)
These used to be used by partial render.

ReactDOMDispatcher ended up not being used in this way.

Move shared DOM files to client. These are only used by client
abstractions now. They're inlined in the Fizz code so they're no longer
shared.
2023-03-14 19:52:57 -04:00
Joe Savona
59cd1ca569 LeaveSSA: consistently rename identifiers even for value block phis
This PR clarifies the logic for adjust mutable ranges of phis and their operands 
during LeaveSSA. Previously we had logic in several places to determine 
whether/how to extend the ranges of each phi and its operands: this occurred 
while traversing reassignmentPhis (in 2+ places) and rewritePhis, as well as in 
rewritePlace(). 

This was kind of a band-aid to make things work, but the logic was imprecise. 
The actual rules are as follows: 

If there is a back-edge, or the phi id is unnamed, then were extend the ranges 
of the phi and its operands to min(starts) and max(ends). This ensures that the 
operands are computed as one unit, ie put into a single reactive scope. For 
loops this is necessary because...looping! For unnamed values this is necessary 
because of the way we collapse logical and ternary expressions back to a 
hierarchical ReactiveFunction — we need to make sure the final mutable range 
extends from the start of the final instruction up to the end of the 
logical/ternaries value blocks. 

Otherwise this is a phi where operands come from predecessors and are named. If 
the phi is mutated later, then we have to extend the end of each operand's range 
to account for the fact that they can be mutated later. Else, we leave the 
operands alone. 

Behavior doesn't change, but we consolidate all of the mutable range logic in 
one place.
2023-03-14 15:24:38 -07:00
Andrew Clark
56a3c18e56 [Flight fixture] Remove redundant use (#26373)
Now that promises are renderable nodes, we can remove the `use` call
from the root of the Flight fixture.

Uncached promises will likely be accompanied by a warning when they are
rendered outside a transition. But this promise is the result of a
Flight response, so it's cached. And it's also a rendered as part of a
transition. So it's fine. Indeed, this is the canonical way to use this
feature.
2023-03-14 11:14:53 -04:00
Sebastian Markbåge
6bd53a5bdf Remove FeatureFlags fork for react-dom/unstable_testing (#26383)
This doesn't need its own set of flags. We use things like `__PROFILE__`
in the regular feature flags file to fork for the `react-dom/profiling`
build so we can do the same here if needed but I don't think we actually
need to fork this anywhere as far as I can tell.
2023-03-13 18:43:37 -04:00
Joe Savona
23e0ce02a6 Make JSX memoization optional (on by default)
Makes JSX memoized by default again, but adds an option to disable memoization 
of JSX. Also adds a new test and fixtures directory to test the opt-in 
no-jsx-memoization behavior.
2023-03-13 13:25:09 -07:00
Mofei Zhang
9465cb2100 [hir] Move Types to a separate file
--- 

Move types around in preparation for next PR #1335. No changes in impl, types, 
or functions.
2023-03-13 14:52:15 -04:00
Mofei Zhang
b3086817d7 [tests][hir-typer] Add hir-tests fixture
--- 

Currently, we run type inference passes early in the pipeline and do not check 
inference output in any tests, test fixtures, or verifier passes. In fact, the 
only ways to view inferred types are (1) locally add a test fixture with`@only` 
and inspect console logs or (2) scroll to the relevant section on a playground 
example. 

However, inferred types and effects significantly affect the output of later 
passes (Alias / MutableRange analysis, InferReactiveIdentifiers, etc), and we 
have already found some bugs due to incorrect inference (e.g. #1274). 

This PR add the `typer-tests` fixture with the following goals 

1. Record relevant current compiler type + effect inference output. 

2. Have relatively stable output (with respect to changes in HIR and PrintHIR). 

- we try to achieve this by annotating the source code.
2023-03-13 14:52:15 -04:00
Mofei Zhang
03f3e541ce [tests][hir-typer] Add hir-tests fixture
--- 

Currently, we run type inference passes early in the pipeline and do not check 
inference output in any tests, test fixtures, or verifier passes. In fact, the 
only ways to view inferred types are (1) locally add a test fixture with`@only` 
and inspect console logs or (2) scroll to the relevant section on a playground 
example. 

However, inferred types and effects significantly affect the output of later 
passes (Alias / MutableRange analysis, InferReactiveIdentifiers, etc), and we 
have already found some bugs due to incorrect inference (e.g. #1274). 

This PR add the `typer-tests` fixture with the following goals 

1. Record relevant current compiler type + effect inference output. 

2. Have relatively stable output (with respect to changes in HIR and PrintHIR). 

- we try to achieve this by annotating the source code.
2023-03-13 14:49:53 -04:00
Mofei Zhang
814a21c97b [prettier] Ignore flow files in incremental formatting 2023-03-13 14:49:52 -04:00
Lauren Tan
e90d058bee [babel] Remove prettier from plugin
I think we added this for easier debugging but isn't strictly needed. Remove 
since this was causing some issues internally.
2023-03-13 14:32:32 -04:00
Sebastian Markbåge
2788d0d8dd Allow empty string to be passed to formAction (#26379)
We disallow empty strings for `href` and `src` since they're common
mistakes that end up loading the current page as a preload, image or
link. We also disallow it for `action`. You have to pass `null` which is
the same.

However, for `formAction` passing `null` is not the same as passing
empty string. Passing empty string overrides the form's action to be the
current page even if the form's action was set to something else.
There's no easy way to express the same thing `#` show up in the user
visible URLs and `?` clears the search params.

Since this is also not a common mistake, we can just allow this.
2023-03-13 14:28:17 -04:00
Rubén Norte
f828bad387 Extracted definition and access to public instances to a separate module in Fabric (#26321)
## Summary

The current definition of `Instance` in Fabric has 2 fields:
- `node`: reference to the native node in the shadow tree.
- `canonical`: public instance provided to users via refs + some
internal fields needed by Fabric.

We're currently using `canonical` not only as the public instance, but
also to store internal properties that Fabric needs to access in
different parts of the codebase. Those properties are, in fact,
available through refs as well, which breaks encapsulation.

This PR splits that into 2 separate fields, leaving the definition of
instance as:
- `node`: reference to the native node in the shadow tree.
- `publicInstance`: public instance provided to users via refs.
- Rest of internal fields needed by Fabric at the instance level.

This also migrates all the current usages of `canonical` to use the
right property depending on the use case.

To improve encapsulation (and in preparation for the implementation of
this [proposal to bring some DOM APIs to public instances in React
Native](https://github.com/react-native-community/discussions-and-proposals/pull/607)),
this also **moves the creation of and the access to the public instance
to separate modules** (`ReactFabricPublicInstance` and
`ReactFabricPublicInstanceUtils`). In a following diff, that module will
be moved into the `react-native` repository and we'll access it through
`ReactNativePrivateInterface`.

## How did you test this change?

Existing unit tests.
Manually synced the PR in Meta infra and tested in Catalyst + the
integration with DevTools. Everything is working normally.
2023-03-13 13:25:42 +00:00
Andrew Clark
cd20376f03 Remove internal act from DevTools e2e test (#26376)
For various reasons some of the DevTools e2e tests uses our repo's
private internal version of `act`. It should really just be using the
public one.

This converts one of the usages, because it was causing CI to fail.
2023-03-12 12:58:58 -04:00
Andrew Clark
131768166b Support Context as renderable node (#25641)
## Based on #25634

Like promises, this adds support for Context as a React node.

In this initial implementation, the context dependency is added to the
parent of child node. This allows the parent to re-reconcile its
children when the context updates, so that it can delete the old node if
the identity of the child has changed (i.e. if the key or type of an
element has changed). But it also means that the parent will replay its
entire begin phase. Ideally React would delete the old node and mount
the new node without reconciling all the children. I'll leave this for a
future optimization.
2023-03-11 17:34:31 -05:00
Andrew Clark
d4f58c3b81 Support Promise as a renderable node (#25634)
Implements Promise as a valid React node types. The idea is that any
type that can be unwrapped with `use` should also be renderable.

When the reconciler encounters a Usable in a child position, it will
transparently unwrap the value before reconciling it. The value of the
inner value will determine the identity of the child during
reconciliation, not the Usable object that wraps around it.

Unlike `use`, the reconciler will recursively unwrap the value until it
reaches a non-Usable type, e.g. `Usable<Usable<Usable<T>>>` will resolve
to T.

In this initial commit, I've added support for Promises. I will do
Context in the [next
step](https://github.com/facebook/react/pull/25641).

Being able to render a promise as a child has several interesting
implications. The Server Components response format can use this feature
in its implementation — instead of wrapping references to client
components in `React.lazy`, it can just use a promise.

This also fulfills one of the requirements for async components on the
client, because an async component always returns a promise for a React
node. However, we will likely warn and/or lint against this for the time
being because there are major caveats if you re-render an async
component in response to user input. (Note: async components already
work in a Server Components environment — the caveats only apply to
running them in the browser.)

To suspend, React uses the same algorithm as `use`: by throwing an
exception to unwind the stack, then replaying the begin phase once the
promise resolves. It's a little weird to suspend during reconciliation,
however, `lazy` already does this so if there were any obvious bugs
related to that we likely would have already found them.

Still, the structure is a bit unfortunate. Ideally, we shouldn't need to
replay the entire begin phase of the parent fiber in order to reconcile
the children again. This would require a somewhat significant refactor,
because reconciliation happens deep within the begin phase, and
depending on the type of work, not always at the end. We should consider
as a future improvement.
2023-03-11 17:11:27 -05:00
Andrew Clark
f411e8990f Remote .internal override from untrusted URL tests (#26372)
Adding `.internal` to a test file prevents it from being tested in build
mode. The best practice is to instead gate the test based on whether the
feature is enabled.

Ideally we'd use the `@gate` pragma in these tests, but the `itRenders`
test helpers don't support that.
2023-03-11 15:46:16 -05:00
Andrew Clark
6334614860 Add disableLegacyContext test gates where needed (#26371)
The www builds include disableLegacyContext as a dynamic flag, so we
should be running the tests in that mode, too. Previously we were
overriding the flag during the test run. This strategy usually doesn't
work because the flags get compiled out in the final build, but we
happen to not test www in build mode, only source.

To get of this hacky override, I added a test gate to every test that
uses legacy context. When we eventually remove legacy context from the
codebase, this should make it slightly easier to find which tests are
affected. And removes one more hack from our hack-ridden test config.

Given that sometimes www has features enabled that aren't on in other
builds, we might want to consider testing its build artifacts in CI,
rather than just source. That would have forced this cleanup to happen
sooner. Currently we only test the public builds in CI.
2023-03-11 15:32:02 -05:00
Tianyu Yao
432ffc9d0f Convert more Scheduler.unstable_flushAll in tests to new test utils (#26369)
`Scheduler.unstable_flushAll` in existing tests doesn't work with
microtask. This PR converts most of the remaining
`Scheduler.unstable_flushAll()` calls to using internal test utilities
to unblock refactoring `ensureRootIsScheduled` with scheduling a
microtask.
2023-03-10 20:56:13 -05:00
Sebastian Markbåge
774111855d [Flight Fixture] Fix proxying with compression (#26368)
We're decompressing and then writing and recompressing in the proxy.
This causes it to stall if buffered because `.pipe()` doesn't force
flush automatically.
2023-03-10 19:48:46 -05:00
Andrew Clark
69fd78fe37 Update Float tests to check for specific errors (#26367)
I updated some of the Float tests that intentionally trigger an error to
assert on the specific error message, rather than swallow any errors
that may or may not happen.
2023-03-10 18:37:32 -05:00
Andrew Clark
93c10dfa6b flushSync: Exhaust queue even if something throws (#26366)
If something throws as a result of `flushSync`, and there's remaining
work left in the queue, React should keep working until all the work is
complete.

If multiple errors are thrown, React will combine them into an
AggregateError object and throw that. In environments where
AggregateError is not available, React will rethrow in an async task.
(All the evergreen runtimes support AggregateError.)

The scenario where this happens is relatively rare, because `flushSync`
will only throw if there's no error boundary to capture the error.
2023-03-10 17:21:34 -05:00
Mengdi Chen
a22bd995c5 [DevTools] prevent StyleX plugin from throwing when inspecting CSS (#26364)
## Summary

An error might happen when we try to read the CSS rules, but the
stylesheet does not allow so (often happens on production).

Before:
<img width="713" alt="image"
src="https://user-images.githubusercontent.com/1001890/224376546-024f7a32-d314-4dd1-9333-7e47d96a2b7c.png">

After:

<img width="504" alt="image"
src="https://user-images.githubusercontent.com/1001890/224376426-964a33c4-0677-4a51-91c2-74074e4dde63.png">


## How did you test this change?

Built a fb version and tested locally (see above screenshot)

---------

Co-authored-by: Hendrik Liebau <mail@hendrik-liebau.de>
2023-03-10 15:43:05 -05:00
Sebastian Markbåge
be353d2515 [Flight Reply] Add undefined and Iterable Support (#26365)
These were recently added to ReactClientValue and so needs to be
reflected in ReactServerValue too.
2023-03-10 12:47:43 -05:00
Sebastian Markbåge
ef8bdbecb6 [Flight Reply] Add Reply Encoding (#26360)
This adds `encodeReply` to the Flight Client and `decodeReply` to the
Flight Server.

Basically, it's a reverse Flight. It serializes values passed from the
client to the server. I call this a "Reply". The tradeoffs and
implementation details are a bit different so it requires its own
implementation but is basically a clone of the Flight Server/Client but
in reverse. Either through callServer or ServerContext.

The goal of this project is to provide the equivalent serialization as
passing props through RSC to client. Except React Elements and
Components and such. So that you can pass a value to the client and back
and it should have the same serialization constraints so when we add
features in one direction we should mostly add it in the other.

Browser support for streaming request bodies are currently very limited
in that only Chrome supports it. So this doesn't produce a
ReadableStream. Instead `encodeReply` produces either a JSON string or
FormData. It uses a JSON string if it's a simple enough payload. For
advanced features it uses FormData. This will also let the browser
stream things like File objects (even though they're not yet supported
since it follows the same rules as the other Flight).

On the server side, you can either consume this by blocking on
generating a FormData object or you can stream in the
`multipart/form-data`. Even if the client isn't streaming data, the
network does. On Node.js busboy seems to be the canonical library for
this, so I exposed a `decodeReplyFromBusboy` in the Node build. However,
if there's ever a web-standard way to stream form data, or if a library
wins in that space we can support it. We can also just build a multipart
parser that takes a ReadableStream built-in.

On the server, server references passed as arguments are loaded from
Node or Webpack just like the client or SSR does. This means that you
can create higher order functions on the client or server. This can be
tokenized when done from a server components but this is a security
implication as it might be tempting to think that these are not fungible
but you can swap one function for another on the client. So you have to
basically treat an incoming argument as insecure, even if it's a
function.

I'm not too happy with the naming parity:

Encode `server.renderToReadableStream` Decode: `client.createFromFetch`

Decode `client.encodeReply` Decode: `server.decodeReply`

This is mainly an implementation details of frameworks but it's annoying
nonetheless. This comes from that `renderToReadableStream` does do some
"rendering" by unwrapping server components etc. The `create` part comes
from the parity with Fizz/Fiber where you `render` on the server and
`create` a root on the client.

Open to bike-shedding this some more.

---------

Co-authored-by: Josh Story <josh.c.story@gmail.com>
2023-03-10 11:36:15 -05:00
Andrew Clark
a8875eab7f Update more tests to not rely on sync queuing (#26358)
This fixes a handful of tests that were accidentally relying on React
synchronously queuing work in the Scheduler after a setState.

Usually this is because they use a lower level SchedulerMock method
instead of either `act` or one of the `waitFor` helpers. In some cases,
the solution is to switch to those APIs. In other cases, if we're
intentionally testing some lower level behavior, we might have to be a
bit more clever.

Co-authored-by: Tianyu Yao <skyyao@fb.com>
2023-03-10 11:06:28 -05:00
Sebastian Silbermann
d1ad984db1 [Flight] Add support for returning undefined from render (#26349)
## Summary

Adds support for returning `undefined` from Server Components.
Also fixes a bug where rendering an empty fragment would throw the same
error as returning undefined.

## How did you test this change?

- [x] test failed with same error message I got when returning undefined
from Server Components in a Next.js app
- [x] test passes after adding encoding for `undefined`
2023-03-09 22:18:52 +01:00
Joe Savona
d376cf1e37 Memoize arrays/objects created with destructuring spread
We were treating Destructuring as if it could never allocate and therefore 
didn't have to be memoized. That's only true if there are no rest spreads 
though. This PR teaches the compiler to treat rest spreads differently for 
scoping and memoization 

purposes, fixing the newly added test case and some existing bugs.
2023-03-09 12:44:30 -08:00
Joe Savona
fcbfca69c9 More tests
More tests, in particular demonstrating that we don't memoize destructured rest 
elements propery — yet! Follow-up fixes.
2023-03-09 12:44:26 -08:00
Joe Savona
58a1cd872e Be explicit about lvalues (to distinguish their memo level later)
This is prep for #1345, which distinguishes different memoization levels per 
lvalue
2023-03-09 12:44:22 -08:00
Joe Savona
9048f59237 Prune scopes whose values dont escape
Adds a new pass that uses escape analysis and React-specific heuristics to tune 
the amount of memoization applied. Specifically, the pass ensures that we only 
memoize: 

* Values which escape (are directly returned or transitively aliased by a 
returned value) 

* ...and that are not JSX elements 

* OR values which are _dependencies_ of scopes that produce an escaping value. 

The latter case is necessary to avoid breaking memoization of an escaping value 
bc a scope happened to have a non-escaping dependency. 

## Algorithm 

1. First we build up a graph, a mapping of IdentifierId to a node describing all 
the scopes and inputs involved in creating that identifier. Individual nodes are 
marked as definitely aliased, conditionally aliased, or unaliased: 

a. Arrays, objects, function calls all produce a new value and are always marked 
as aliased 

b. Conditional and logical expressions (and a few others) are conditinally 
aliased, depending on whether their result value is aliased. 

c. JSX is always unaliased (though its props children may be) 

2. The same pass which builds the graph also stores the set of returned 
identifiers 

3. We traverse the graph starting from the returned identifiers and mark 
reachable dependencies as escaping, based on the combination of the parent 
node's type and its children (eg a conditional node with an aliased dep promotes 
to aliased). 

4. Finally we prune scopes whose outputs weren't marked.
2023-03-09 09:51:43 -08:00
Lauren Tan
faa8eef0a8 [be] Fix remaining lints and enable lint in CI 2023-03-10 16:21:01 -05:00
Andrew Clark
39d4b93657 [Internal tests] Close MessageChannel port to prevent leak (#26357)
Node's MessageChannel implementation will leak if you don't explicitly
close the port. This updates the enqueueTask function we use in our
internal testing helpers to close the port once it's no longer needed.
2023-03-09 11:20:07 -05:00
Josh Story
3706edb81c [Float][Fizz]: Don't preload nomodule scripts (#26353)
We attempt to preload scripts that we detect during Fizz rendering
however when `noModule={true}` we should not because it will force
modern browser to fetch scripts they will never execute

Hoisted script resources already don't preload because we just emit the
resource immediately. This change currently on affects the preloads for
scripts that aren't hoistable
2023-03-08 21:59:43 -08:00
Joe Savona
7813cfa52c Fix EliminateRedundantPhi for cascading eliminated phis
This was the actual bug. When EliminateRedundantPhis eliminates a phi, it has to 
rewrite downstream usages of the phi id to the single operand id. We were 
correctly doing that in all but one place. When we iterate _downstream phis_, we 
were looking up the operands against the rewrite table, but not updating the phi 
operands themselves to the rewritten value. 

This fixes the bug, and incidentally fixes a test that has been broken for a 
while and nagging at me.
2023-03-08 21:10:07 -08:00
Joe Savona
1fb0aed668 Fix mapInstructionOperands() visitor
Found while debugging the previous issue: `mapInstructionOperands()` should not 
look at lvalues. The previous version was causing us to create extra phi nodes, 
which interestingly weren't the actual problem behind the "SSA" bug, but sure 
looked like it at first.
2023-03-08 20:49:32 -08:00
Joe Savona
ff855b1d34 Repro case for product bug
Simplified version of the example. As I eventually uncovered in #1342, the issue 
is cascading redundant phis not getting rewritten.
2023-03-08 20:49:28 -08:00
Sebastian Markbåge
2b003a5cc6 Split out ServerReferenceMetadata into Id and Bound Arguments (#26351)
This is just moving some stuff around and renaming things.

This tuple is opaque to the Flight implementation and we should probably
encode it separately as a single string instead of a model object.

The term "Metadata" isn't the same as when used for ClientReferences so
it's not really the right term anyway.

I also made it optional since a bound function with no arguments bound
is technically different than a raw instance of that function (it's a
clone).

I also renamed the type ReactModel to ReactClientValue. This is the
generic serializable type for something that can pass through the
serializable boundary from server to client. There will be another one
for client to server.

I also filled in missing classes and ensure the serializable sub-types
are explicit. E.g. Array and Thenable.
2023-03-08 23:45:55 -05:00
Joe Savona
6d4b0c61b3 Export ValueKind and Effect
We need to be able to reference these to teach the compiler about custom hooks 
like Relay.
2023-03-08 15:56:25 -08:00
Andrew Clark
62cd5af08e Codemod redundant async act scopes (#26350)
Prior to #26347, our internal `act` API (not the public API) behaved
differently depending on whether the scope function returned a promise
(i.e. was an async function), for historical reasons that no longer
apply. Now that this is fixed, I've codemodded all async act scopes that
don't contain an await to be sync.

No pressing motivation other than it looks nicer and the codemod was
easy. Might help avoid confusion for new contributors who see async act
scopes with nothing async inside and infer it must be like that for a
reason.
2023-03-08 16:40:23 -05:00
Andrew Clark
037378202f Internal act: Call scope function after an async gap (#26347)
This adds an async gap to our internal implementation of `act` (the one
used by our repo, not the public API). Rather than call the provided
scope function synchronously when `act` is called, we call it in a
separate async task. This is an extra precaution to ensure that our
tests do not accidentally rely on work being queued synchronously,
because that is an implementation detail that we should be allowed to
change. We don't do this in the public version of `act`, though we maybe
should in the future, for the same rationale. That might be tricky,
though, because it could break existing tests.

This also fixes the issue where our internal `act` requires an async
function. You can pass it a regular function, too.
2023-03-08 16:25:12 -05:00
Sebastian Markbåge
d8e49f2af8 Use setTimeout to schedule work on the server in Edge environments (#26348)
We rely heavily on being able to batch rendering after multiple fetches
etc. have completed on the server. However, we only do this in the
Node.js build. Node.js `setImmediate` has the exact semantics we need.
To be after the current cycle of I/O so that we can collect after all
those I/O events already in the queue has been processed.

This doesn't exist in standard browsers, so we ended up not using it
there. We could've used `setTimeout` but that risks being throttled
which would severely negatively affect the performance so we just did it
synchronously there. We probably could just use the `scheduler` there.

Now we have a separate build for Edge where `setTimeout(..., 0)`
actually behaves like `setImmediate` which is what we want. So we can
just use that in that build.

@Jarred-Sumner not sure what you want for Bun.
2023-03-08 15:34:29 -05:00
Andrew Clark
83643778bd Internal test helpers: Use Node's MessageChannel to queue task (#26345)
To wait for the microtask queue to empty, our internal test helpers
schedule an arbitrary task using `setImmediate`. It doesn't matter what
kind of task it is, only that it's a separate task from the current one,
because by the time it fires, the microtasks for the current event will
have already been processed.

The issue with `setImmediate` is that Jest mocks it. Which can lead to
weird behavior.

I've changed it to instead use a message event, via the MessageChannel
implementation exposed by the `node:worker_threads` module.

We should consider doing this in the public implementation of `act`,
too.
2023-03-08 15:04:38 -05:00
Joe Savona
f985d6cdba PropertyDelete/ComputedDelete instructions 2023-03-08 12:04:27 -08:00
Andrew Clark
f36ab0e375 Remove timers from ReactDOMSuspensePlaceholder tests (#26346)
Our internal `act` implementation flushes Jest's fake timer queue as a
way to force Suspense fallbacks to appear. So we should avoid using
timers in our internal tests.
2023-03-08 14:45:35 -05:00
Andrew Clark
44d3807945 Move internalAct to internal-test-utils package (#26344)
This is not a public API. We only use it for our internal tests, the
ones in this repo. Let's move it to this private package. Practically
speaking this will also let us use async/await in the implementation.
2023-03-08 12:58:31 -05:00
Jan Kassens
8c100620ca Build: specify Node.js 16 as minimum for dev (#26343)
- Specifies Node 16 as the minimum supported version.
- Remove no longer supported 17.x version (per
https://nodejs.dev/en/about/releases/)
- Add 19.x

Test Plan:
(using node 19) as that's what I'm adding)
- yarn build
- yarn test
2023-03-08 12:14:36 -05:00
Andrew Clark
d814473047 [Internal API only] Delete non-awaited form of act (#26339)
**This commit only affects the internal version of `act` that we use in
this repo. The public `act` API is unaffected, for now.**

We should always await the result of an `act` call so that any work
queued in a microtask has a chance to flush. Neglecting to do this can
cause us to miss bugs when testing React behavior.

I codemodded all the existing `act` callers in previous PRs.
2023-03-08 11:46:10 -05:00
Lauren Tan
0363648178 [babel] Fix export ordering
Turns out hoisting doesn't work with export declarations, so fix ordering such 
that the export always comes after the synthesized test declaration.
2023-03-08 11:42:57 -05:00
Andrew Clark
702fc984e6 Codemod act -> await act (4/?) (#26338)
Similar to the rationale for `waitFor` (see #26285), we should always
await the result of an `act` call so that microtasks have a chance to
fire.

This only affects the internal `act` that we use in our repo, for now.
In the public `act` API, we don't yet require this; however, we
effectively will for any update that triggers suspense once `use` lands.
So we likely will start warning in an upcoming minor.
2023-03-08 11:36:05 -05:00
Rubén Norte
9fb2469a63 Restore definition of NativeMethods as an object for React Native (#26341)
## Summary

In #26283, I changed definition of `NativeMethods` from an object to an
interface. This is correct but introduces a lot of errors in React
Native, so this restores the original definition and exports the fixed
type as a separate type so we can gradually migrate in React Native.

## How did you test this change?

Manually applied this change in React Native and validated the errors
are gone.
2023-03-08 14:37:37 +00:00
Mengdi Chen
aef930314f [DevTools] upgrade electron to latest version & security improvements (#26337)
## Summary

resolves #25667
This PR also resolves several security issues in the standalone app

## How did you test this change?

Tested locally `yarn start` in react-devtools package. Everything works
normal

---
- To see the specific tasks where the Asana app for GitHub is being
used, see below:
  - https://app.asana.com/0/0/1204123419819195
2023-03-07 22:31:54 -05:00
Sathya Gunasekaran
42c04fdcc7 [test] Add test to show Forget's inference is run inside lambda
JSX reads the value of `z` and does not mutate it so `z` can be independently 
memoized.
2023-03-08 00:16:00 +00:00
Sathya Gunasekaran
8695ea05c3 [test] Add test for capturing a ref before renaming
The renaming does not affect the lambda correctly.
2023-03-08 00:15:57 +00:00
Sathya Gunasekaran
80ab2f25a6 [test] Add test for capturing a renamed ref
The ref isn't renamed inside the lambda, needs to be fixed.
2023-03-08 00:15:54 +00:00
Sathya Gunasekaran
d155d2dd81 [test] Add test for lambda that conditionally captures ref
Conditionally captured refs are correctly added to dependency list of the 
lambda.
2023-03-08 00:15:51 +00:00
Sathya Gunasekaran
1e8b6b51d3 [test] Add test for lambda that shadows ref
There is no ref captured as it is shadowed and the lambda does not depend on the 
ref.
2023-03-08 00:15:48 +00:00
Andrew Clark
161f6ae42c Codemod act -> await act (3/?) (#26336)
Similar to the rationale for `waitFor` (see #26285), we should always
await the result of an `act` call so that microtasks have a chance to
fire.

This only affects the internal `act` that we use in our repo, for now.
In the public `act` API, we don't yet require this; however, we
effectively will for any update that triggers suspense once `use` lands.
So we likely will start warning in an upcoming minor.
2023-03-07 14:39:30 -05:00
Andrew Clark
58605f7988 Codemod act -> await act (2/?) (#26335)
Similar to the rationale for `waitFor` (see #26285), we should always
await the result of an `act` call so that microtasks have a chance to
fire.

This only affects the internal `act` that we use in our repo, for now.
In the public `act` API, we don't yet require this; however, we
effectively will for any update that triggers suspense once `use` lands.
So we likely will start warning in an upcoming minor.
2023-03-07 12:07:30 -05:00
Andrew Clark
703c67560d Codemod act -> await act (1/?) (#26334)
Similar to the rationale for `waitFor` (see
https://github.com/facebook/react/pull/26285), we should always await
the result of an `act` call so that microtasks have a chance to fire.

This only affects the internal `act` that we use in our repo, for now.
In the public `act` API, we don't yet require this; however, we
effectively will for any update that triggers suspense once `use` lands.
So we likely will start warning in an upcoming minor.
2023-03-07 10:15:34 -05:00
Andrew Clark
b380c24852 Convert class equivlance tests to flushSync (#26333)
There's an old collection of test suites that test class component
behavior across ES6 (regular JavaScript classes), CoffeeScript classes,
and TypeScript classes. They work by running the same tests in all
environments and comparing the results.

Rather than use `act` or `waitFor` in these, I've changed them to use
`flushSync` instead so that they can flush synchronously. The reason is
that CoffeeScript doesn't have async/await, so we'd have to write those
tests differently than how they are written in the corresponding
modules. Since none of these tests cover any concurrent behavior, I
believe it's fine in this case to do everything synchronously; they
don't use any concurrent features, anyway, so effectively it's just
skipping a microtask.
2023-03-07 10:14:41 -05:00
Rubén Norte
8f812e75d6 Refactor ReactFabricHostComponent (#26323)
## Summary

This is a small refactor of `ReactFabricHostComponent` to remove
unnecessary dependencies, unused methods and type definitions to
simplify a larger refactor of the class in a following PR
(https://github.com/facebook/react/pull/26321).

## How did you test this change?

Existing unit tests.
2023-03-07 14:33:55 +00:00
Josh Story
978fae4b4f [Float][Fiber] implement a faster hydration match for hoistable elements (#26154)
This PR is now based on #26256 

The original matching function for `hydrateHoistable` some challenging
time complexity since we built up the list of matchable nodes for each
link of that type and then had to check to exclusion. This new
implementation aims to improve the complexity

For hoisted title tags we match the first title if it is valid (not in
SVG context and does not have `itemprop`, the two ways you opt out of
hoisting when rendering titles). This path is much faster than others
and we use it because valid Documents only have 1 title anyway and if we
did have a mismatch the rendered title still ends up as the
Document.title so there is no functional degradation for misses.

For hoisted link and meta tags we track all potentially hydratable
Elements of this type in a cache per Document. The cache is refreshed
once each commit if and only if there is a title or meta hoistable
hydrating. The caches are partitioned by a natural key for each type
(href for link and content for meta). Then secondary attributes are
checked to see if the potential match is matchable.

For link we check `rel`, `title`, and `crossorigin`. These should
provide enough entropy that we never have collisions except is contrived
cases and even then it should not affect functionality of the page. This
should also be tolerant of links being injected in arbitrary places in
the Document by 3rd party scripts and browser extensions

For meta we check `name`, `property`, `http-equiv`, and `charset`. These
should provide enough entropy that we don't have meaningful collisions.
It is concievable with og tags that there may be true duplciates `<meta
property="og:image:size:height" content="100" />` but even if we did
bind to the wrong instance meta tags are typically only read from SSR by
bots and rarely inserted by 3rd parties so an adverse functional outcome
is not expected.
2023-03-06 19:52:35 -08:00
Joe Savona
1c023263a3 Use shorthand where possible for ObjectExpression properties
During codegen, emit object properties as shorthand where possible (`{x}` 
instead of `{x: x}`)
2023-03-06 16:35:52 -08:00
Joe Savona
e381aa042f Support spread elements in ArrayExpression
Similar to the previous, but for array expression: `const x = [...y]`
2023-03-06 15:32:43 -08:00
Joe Savona
93cca54aba Support spread patterns in object literals
Support ObjectExpression with spread items, eg `const x = {...y}`.
2023-03-06 15:24:43 -08:00
Joe Savona
7893a6c403 Represent ObjectExpression properties as Array<ObjectProperty>
Refactors the representation of ObjectExpression properties from a Map to an 
`Array<ObjectProperty>` to prepare for the next diff which adds spread element 
support.
2023-03-06 15:19:34 -08:00
Josh Story
8a9f82ed58 [Float][Fizz][Fiber] - Do not hoist elements with itemProp & hydrate more tolerantly in hoist contexts (#26256)
## Do not hoist elements with `itemProp`
In HTML `itemprop` signifies a property of an `itemscope` with respect
to the Microdata spec
(https://html.spec.whatwg.org/multipage/microdata.html#microdata)

additionally `itemprop` is valid on any tag and can even make some tags
that are otherwise invalid in the `<body>` valid there (`<meta>` for
instance).

Originally I tried an approach where if you rendered something otherwise
hoistable inside an `itemscope` it would not hoist if it had an
`itemprop`. This meant that some components with `itemprop` could hoist
(if they were not scoped, which is generally invalid microdata
implementation). However the problem is things that do hoist, hoist into
the head and body and these tags can have an `itemscope`. This creates a
ton of ambiguity when trying to hydrate in these hoist scopes because we
can't know for certain whether a DOM node we find there was hoisted or
not even if it has an `itemprop` attribute. There are other scenarios
too that have abiguous semantics like rendering a hoistable with
`itemProp` outside of `<html itemScope={true>`. Is it fair to embed that
hoistable inside that itemScope even though it was defined outside?

To simplify the situation and disambiguate I dropped the `itemscope`
portion from the implementation and now any host component that could
normally be hoisted will not hoist if it has an `itemProp` prop.

In addition to the changes made for `itemProp` this PR also modifies
part of the hydration implementation to be more tolerant of tags
injected by 3rd parties. This was opportunistically done when we needed
to have context information like `inItemScope` but with the most recent
implementation that has been removed. I have however left the hydration
changes in place as it is a goal to make React handle hydrating the
entire Document even when we cannot control whether 3rd parties are
going to inject tags that React will not render but are also not
hoistables

-------

##### Original Description when we considered tracking itemScope
>One recent decision was to make elements using the `itemProp` prop not
hoistable if they were inside and itemScope. This better fits with
Microdata spec which allows for meta tags and other tag types usually
reserved for the `<head>` to be used in the `<body>` when using
itemScope.
>
>To implement this a number of small changes were necessary
>
>1. HostContext in prod needed to expand beyond just tracking the
element namespace for new element creation. It now tracks whether we are
in an itemScope. To keep this efficient it is modeled as a bitmask.
>2. To disambiguate what is and is not a potential instance in the DOM
for hoistables the hydration algo was updated to skip past non-matching
instances while attempting to claim the instance rather than ahead of
time (getNextHydratable).
>3. React will not consider an itemScope on `<html>`, `<head>`, or
`<body>` as a valid scope for the hoisting opt-out. This is important as
an invariant so we can make assumptions about certain tags in these
scopes. This should not be a functional breaking change because if any
of these tags have an `itemScope` then it can just be moved into the
first node inside the `<body>`
>
>Since we were already updating the logic for hydration to better
support `itemScope` opt-out I also changed the hydration behavior for
suspected 3rd party nodes in `<head>` and `<body>`. Now if you are
hydrating in either of those contexts hydration will skip past any
non-matching nodes until it finds a match. This allows 3rd party scripts
and extensions to inject nodes in either context that React does not
expect and still avoid a hydration mismatch.
>
>This new algorithm isn't perfect and it is possible for a mismatch to
occur. The most glaring case may be if a 3rd party script prepends a
`<div>` into `<body>` and you render a `<div>` in `<body>` in your app.
there is nothing to signal to React that this div was 3rd party so it
will claim is as the hydrated instance and hydration will almost
certainly fail immediately afterwards.
>
>The expectation is that this is rare and that if falling back to client
rendering is transparent to the user then there is not problem here. We
will continue to evaluate this and may change the hydration matching
algorithm further to match user and developer expectations
2023-03-06 15:00:54 -08:00
Joe Savona
f3c662845b Support string literal keys for object expressions
For ObjectExpression, we now support computed keys where the key is a string 
literal.
2023-03-06 14:51:18 -08:00
Joe Savona
a9d6d2d95a [rfc] always create collections even if elements have errors
BuildHIR currently propagates UnsupportedNodes for collection types where the 
element itself can fail (for example object expressions where the key may not be 
valid). However, given that we currently abort compilation after the first 
failing pass (and will probably do so for quite a while) I think we can simplify 
and just always return the collection. Note that I already did this for 
destructuring. I'm open to leaving the code as-is if you prefer, though.
2023-03-06 14:43:58 -08:00
Joe Savona
b793fe424d Separate eachLValue/eachOperand visitors
This PR starts to clean up our handling of lvalues and rvalues by adding new 
`eachInstructionLValues()` and `mapInstructionLValues()` helpers. Now, 
`eachInstructionOperand()` and `mapInstructionOperands()` only visit true 
rvalues, and the new passes must be used to visit lvalues. This allows us to 
remove the special-casing for StoreLocal and Destructure in most of the passes.
2023-03-06 14:33:52 -08:00
Sathya Gunasekaran
cf03bac12a [be] Move skipped test to kitchensink 2023-03-07 16:21:34 +00:00
Sathya Gunasekaran
8477195c74 [babel] Re-export compiled functions 2023-03-07 16:08:16 +00:00
Jan Kassens
3cad3a54ed Use content hash for facebook-www builds (#26331)
Currently, any commit to React causes an internal sync since the Git
commit hash is part of the build. This creates a lot more sync commits
and noise than necessary, see:
https://github.com/facebook/react/commits/builds/facebook-www

This PR changes the version string to be a hash of the target build
files instead. This way we get a new version with any change that
actually impacts the generated files and still have a matching version
across the files.
2023-03-06 17:13:17 -05:00
Jan Kassens
ba353a50a6 Build: make version in build artifacts match (#26329)
Some build artifacts contain multiple version strings. It seems like an
oversight to me that this `.replace` call just replaces the one that
happens to be first.
2023-03-06 15:38:43 -05:00
Jan Kassens
88313ffd57 Codesandbox: upgrade to Node.js 18 (#26330)
Turns out Codesandbox didn't support `String.prototype.replaceAll` in
#26329.

This updates the config to use Node.js 18 for Codesandbox builds.
2023-03-06 15:38:03 -05:00
Sathya Gunasekaran
39898c1858 [babel] Add gating module support
Instead of replacing original function with compiled code, this adds an option 
to append the code and switch between the two based on an `isForgetEnabled` test 
condition that's imported from the specified gatingModule.
2023-03-06 19:54:00 +00:00
Sathya Gunasekaran
2ede182f5e [test] Enable gatingModule in tests 2023-03-06 19:53:57 +00:00
Sathya Gunasekaran
c642de322c [test] Enable "use forget" directive in tests 2023-03-06 19:53:54 +00:00
Sathya Gunasekaran
8c24fc2be2 [pipeline] Type the result as t.FunctionDeclaration
A more narrower type as we only accept FunctionDeclaration as inputs
2023-03-06 19:53:52 +00:00
Sathya Gunasekaran
3cd31a11fb [babel] Add option to specify a gatingModule 2023-03-06 19:53:49 +00:00
Sathya Gunasekaran
637c2e68f1 [be][babel] Move directive checking to separate function 2023-03-06 19:53:46 +00:00
mofeiZ
0e1bba87ea [be][cleanup] Split primitive tests to individual fixtures
Followup to #1273 

No changes, just moving test functions to their own fixture files.
2023-03-06 18:25:53 -05:00
Mofei Zhang
8be45e7d4a [rhir][optim] Preserve conditional deps when propagating reactive scopes
--- 

**This PR slightly changes the semantics of ReactiveScopeDependencies**. 
Previously, reading a ReactiveScopeDependency is guaranteed to preserve the 
`nullthrows` semantics of its own declarations (not that of its inner scopes). 
This does not affect the overall correctness properties, since we already hoist 
reading of conditional dependencies (and thus may throw earlier than the 
original source). 

E.g. we already do not preserve *where* the nullthrows occurs. 

```javascript 

function Component(props) { 

// throws here, before print(x) 

const c_0 = props.a.b !== $[0]; 

let x; 

if (c_0) { 

x = {}; 

print(x); 

if (...) mutate1(x, props.a.b); 

mutate2(x, props.a.b); 

// ... 

``` 

### Summary 

This is an optimization, not a correctness property. 

When propagating reactive dependencies of an inner scope up to its parent, we 
want to *retain information about conditional dependencies* -- not the derived 
unconditional dependencies. This helps us produce more granular dependencies in 
the parent scope. 

Current implementation: 

```javascript 

const innerScopeDeps = innerScope.depTree.deriveMinimalUnconditionalDeps(); 

for (const dep of innerScopeDeps) { 

currentScope.depTree.addDep(dep); 

} 

``` 

New implementation: 

```javascript 

// union of a tree takes union of each node 

currentScope.depTree = currentScope.depTree.union(innerScope.depTree); 

``` 

### Example 

In the below example: 

- `scope @1` has a conditional dependency of `props.a.b`, but that reduces to 
the unconditional dependency `props` 

- `scope @0` itself has a unconditional dependency of `props.a.b` 

- Currently, Forget joins the derived / reduced dependencies of inner scopes, 
which adds `props` as unconditional dependency of `scope @0` 

- With this change, Forget joins the property trees and retains info about 
conditional deps, which adds `props.a.b` as a conditional dep of `scope @0`. 

```javascript 

// scope @0 (deps=[???] decls=[x, y]) 

let y = {}; 

// scope @1 (deps=[props] decls=[x]) 

let x = {}; 

if (foo) mutate1(x, props.a.b); 

mutate2(y, props.a.b); 

``` 

### Followup 

We currently keep track of properties unconditionally accessed per 
ReactiveBlock. Eventually we want to keep track of properties unconditionally 
accessed across blocks (as according to control flow). 

Consider the following code, in which sibling scopes 0 and 1 are sequentially 
executed. In this case, we can safely add props.a.b as a dependency of scope 1. 

```javascript 

// scope@0 (deps=[props.a.b], decls=[x]) 

let x = { a: foo(props.a.b) }; 

// scope@1 (deps=[???], decls=[y]) 

let y = {}; 

if (...) { 

mutate(y, props.a.b); 

} 

```
2023-03-06 16:33:08 -05:00
Mofei Zhang
e2698a3124 [rhir] Add printDeps for debugging reactive dependency trees 2023-03-06 16:33:07 -05:00
Mofei Zhang
e68ea941e6 [rhir] Promote conditional dependencies accessed by every cfg path
--- 

Implementation details summarized in comments. 

Overall, we want to calculate a `ReactiveDependencyTree` for every conditional 
block. If we know that conditional blocks are exhaustive (e.g. all CFG paths 
calculates a tree), we can take `intersection(depsFromEachBlock)` and add this 
to the parent Reactive + conditional scope `parentDeps = union(parentDeps, 
intersection(...))`. 

We use trees instead of individual deps here because we can still derive 
unconditional accesses. 

e.g. 

``` 

let x = {}; 

// props.a is an unconditional access here 

if (foo(other)) { 

x.a = props.a.b; 

} else { 

x.b = props.a.c; 

} 

```
2023-03-06 16:33:07 -05:00
Mofei Zhang
25bfe728aa [rhir] move DeriveMinimalDependencies to its own file
--- 

Small refactor of reactive dependency logic, no behavioral change. 

- Moves ReactiveDependencyTree logic into `DeriveMinimalDependencies`. 

- this moves hides most helper functions + types 🥳 

- made `ReactiveDependencyTree` a class 

- Changes `#dependencies` type: `Set<ReactiveScopeDep>` -> 
`ReactiveDependencyTree` 

- instead of collecting all dependencies into a tree in the end, we now eagerly 
join dependencies into the tree on `visitDep` 

- this is needed for the next PR in the stack, which relies on incremental 
merging
2023-03-06 16:33:06 -05:00
Andrew Clark
6e1756a5a9 Move suspended render logic to ensureRootIsScheduled (#26328)
When the work loop is suspended, we shouldn't schedule a new render task
until the promise has resolved. When I originally implemented this, I
wasn't sure where to put this logic — `ensureRootIsScheduled` is the
more natural place for it, but that's also a really hot path, so I chose
to do it elsewhere, and left a TODO to reconsider later.

Now it's later. I'm working on a refactor to move the
`ensureRootIsScheduled` call to always happen in a microtask, so that if
there are multiple updates/pings in a single event, they get batched
into a single operation. Which means I can put the logic in that
function where it belongs.
2023-03-06 12:27:48 -05:00
Andrew Clark
1528c5ccdf SchedulerMock.unstable_yieldValue -> SchedulerMock.log (#26312)
(This only affects our own internal repo; it's not a public API.)

I think most of us agree this is a less confusing name. It's possible
someone will confuse it with `console.log`. If that becomes a problem we
can warn in dev or something.
2023-03-06 11:09:07 -05:00
Jan Kassens
4bbac04cd3 Upgrade Flow to 0.201 (#26326)
Small Flow upgrade to keep us current.
2023-03-06 10:33:22 -05:00
Rubén Norte
eb616a12f1 Extract duplicated methods in Fabric and the legacy renderer to a shared module (#26319)
## Summary

The following methods have exactly the same implementation on Fabric and
the legacy renderer:
* `findHostInstance_DEPRECATED`
* `findNodeHandle`
* `dispatchCommand`
* `sendAccessibilityEvent`

This just extracts those functions to a common module so they're easier
to change (no need to sync changes in 2 files).

## How did you test this change?

Existing tests (this is a refactor).
2023-03-06 10:51:59 +00:00
Andrew Clark
49f7410467 Fix: Infinite act loop caused by wrong shouldYield (#26317)
Based on a bug report from @bvaughn.

`act` should not consult `shouldYield` when it's performing work,
because in a unit testing environment, I/O (such as `setTimeout`) is
likely mocked. So the result of `shouldYield` can't be trusted.

In the regression test, I simulate the bug by mocking `shouldYield` to
always return `true`. This causes an infinite loop in `act`, because it
will keep trying to render and React will keep yielding.
2023-03-05 20:24:39 -05:00
Sebastian Markbåge
106ea1c584 Support Iterables in Flight (#26313)
We support any super type of anything that we can serialize. Meaning
that as long as the Type that's passed through is less precise, it means
that we can encoded it as any subtype and therefore the incoming type
doesn't have to be the subtype in that case. Basically, as long as
you're only passing through an `Iterable<T>` in TypeScript, then you can
pass any `Iterable<T>` and we'll treat it as an array.

For example we support Promises *and* Thenables but both are encoded as
Promises.

We support Arrays and since Arrays are also Iterables, we can support
Iterables.

For @wongmjane
2023-03-05 13:18:54 -05:00
Hendrik Liebau
f905da2276 [Flight] Send server reference error chunks to the client (#26293)
Previously when a called server reference function was rejected, the
emitted error chunk was not flushed, and the request was not properly
closed.

Co-authored-by: Sebastian Markbage <sebastian@calyptus.eu>
2023-03-04 22:56:19 -05:00
Sebastian Markbåge
e0241b6600 Simplify Webpack References by encoding file path + export name as single id (#26300)
We always look up these references in a map so it doesn't matter what
their value is. It could be a hash for example.

The loaders now encode a single $$id instead of filepath + name.

This changes the react-client-manifest to have a single level. The value
inside the map is still split into module id + export name because
that's what gets looked up in webpack.

The react-ssr-manifest is still two levels because that's a reverse
lookup.
2023-03-04 19:51:34 -05:00
Andrew Clark
25685d8a90 Codemod tests to waitFor pattern (9/?) (#26309)
This converts some of our test suite to use the `waitFor` test pattern,
instead of the `expect(Scheduler).toFlushAndYield` pattern. Most of
these changes are automated with jscodeshift, with some slight manual
cleanup in certain cases.

See #26285 for full context.
2023-03-04 18:06:20 -05:00
Andrew Clark
64dde70827 Codemod tests to waitFor pattern (8/?) (#26308)
This converts some of our test suite to use the `waitFor` test pattern,
instead of the `expect(Scheduler).toFlushAndYield` pattern. Most of
these changes are automated with jscodeshift, with some slight manual
cleanup in certain cases.

See #26285 for full context.
2023-03-04 18:04:43 -05:00
Andrew Clark
3cb5afb82e Codemod tests to waitFor pattern (7/?) (#26307)
This converts some of our test suite to use the `waitFor` test pattern,
instead of the `expect(Scheduler).toFlushAndYield` pattern. Most of
these changes are automated with jscodeshift, with some slight manual
cleanup in certain cases.

See #26285 for full context.
2023-03-04 18:03:24 -05:00
Andrew Clark
e98695db91 Codemod tests to waitFor pattern (6/?) (#26305)
This converts some of our test suite to use the `waitFor` test pattern,
instead of the `expect(Scheduler).toFlushAndYield` pattern. Most of
these changes are automated with jscodeshift, with some slight manual
cleanup in certain cases.

See #26285 for full context.
2023-03-04 11:45:26 -05:00
Andrew Clark
9a52cc8bcd Convert ReactLazy-test to waitFor pattern (#26304)
I'm in the process of codemodding our test suite to the waitFor pattern.
See #26285 for full context.

This module required a lot of manual changes so I'm doing it as its own
PR. The reason is that most of the tests involved simulating an async
import by wrapping them in `Promise.resolve()`, which means they would
immediately resolve the next time the microtask queue was flushed. I
rewrote the tests to resolve the simulated import explicitly.

While converting these tests, I also realized that the `waitFor` helpers
weren't properly waiting for the entire microtask queue to recursively
finish — if a microtask schedules another microtask, the subsequent one
wouldn't fire until after `waitFor` had resolved. To fix this, I used
the same strategy as `act` — wait for a real task to finish before
proceeding, such as a message event.
2023-03-04 11:44:41 -05:00
mofeiZ
03462cfc7a [Fizz] External runtime: fix bug in processing existing elements (#26303)
## Summary
Fix bug in how the Fizz external runtime processes existing template
elements.

Bug:
- getElementsByTagName returns a HTMLCollection, which is live.
- while iterating over an HTMLCollection, we call handleNode which
removes nodes

Fix:
- Call Array.from to copy children of `document.body` before processing.
- We could use `querySelectorAll` instead, but that is likely slower due
to reading more nodes.

## How did you test this change?

Did ad-hoc testing on Facebook home page by commenting out the mutation
observer and adding the following.
```javascript
  window.addEventListener('DOMContentLoaded', function () {
    handleExistingNodes(document.body);
  });
```
2023-03-04 11:26:59 -05:00
Andrew Clark
faacefb4d0 Codemod tests to waitFor pattern (4/?) (#26302)
This converts some of our test suite to use the `waitFor` test pattern,
instead of the `expect(Scheduler).toFlushAndYield` pattern. Most of
these changes are automated with jscodeshift, with some slight manual
cleanup in certain cases.

See #26285 for full context.
2023-03-03 21:24:22 -05:00
Joe Savona
5b11372901 Optimize DCE for destructuring
In #1287 i implemented basic handling for destructuring in DCE: if any of the 
pattern values are used, we retained the whole instruction as-is. However, 
ideally we could prune out unused elements from the pattern. There are pretty 
simple rules: 

* ArrayPattern we can eliminate unused elements from the end. 

* ObjectPattern we can eliminate any unused element, but only if there is no 
rest element.
2023-03-03 17:16:39 -08:00
Joe Savona
8233e8f95a All calls to lowerExpression lower to a unique temporary
This is more followup toward deleting Instruction.lvalue. The previous PR 
ensured that all Instruction.lvalue identifiers are only ever assigned to once. 
Now we ensure that `lowerExpression()` is _only_ called via 
`lowerExpressionToTemporary()`, ie we now always lower every single expression 
to a temporary. 

This will make it easier to make lvalue a part of the InstructionValue instead 
of the instruction itself, in follow-up PRs.
2023-03-03 17:09:27 -08:00
Joe Savona
fe2d179a61 Value block reassignment uses StoreLocal
As part of removing Instruction.lvalue we need to ensure that it is only used to 
represent that instruction's value — the InstructionKind should always be Const. 
The one place where we violated this was for value blocks, specifically 
ConditionalExpression and LogicalExpression. For both of those, we generate a 
single temporary place to represent the expression result. Then the consequent 
and alternate branch ended in a `LoadLocal` that reassigned that temporary (in 
the lvalue) to the result of that branch. 

This PR changes to use StoreLocal instead, and updates the recently added 
validation pass to ensure that all identifiers that appear in an 
Instruction.lvalue are only ever assigned once.
2023-03-03 17:09:26 -08:00
Joe Savona
ca9d49090a New destructuring representation modeled on StoreLocal
Changes to explicitly model destructuring (array and object patterns), expanding 
support to include rest elements and preserving destructuring through the 
output. The new "Destructure" instruction is similar to "StoreLocal" but has a 
pattern instead of a place. For now each level of nested array/object patterns 
creates a separate destructure instruction, which ensures we have a temporary 
Place to talk about the intermediate array/object and its type/effects etc. 
Example: 

``` 

// INPUT 

const [x, {y}, ...z] = a; // yay rest elements work now! 

// HIR 

[1] <unknown> $2 = LoadLocal a$1 

[2] <unknown> $6 = Destructure Const [ <unknown> x$3, <unknown> $4, ...<unknown> 
z$5 ] = <unknown> $2 

[3] <unknown> $8 = Destructure Const { y: <unknown> y$8 } = <unknown> $4 

// OUTPUT 

const [x, t0, ...z] = a; 

const {y} = t0; 

``` 

Note that we can still collapse to a single destructure statement during 
codegen, independently of whether we have separate instructions internally. For 
now i'm going w the simple approach of emitting multiple statements in codegen 
(the code will very likely get further rewritten by downstream babel passes 
anyway). 

Also, I don't love the "if StoreLocal/Destructure else ..." pattern that the 
StoreLocal created and that this PR entrenches. As discussed w @gsathya offline, 
the long-term direction will be to add a separate visitor, roughly 
`eachLValue()` and `eachOperand()` so that we can treat all instructions the 
same. Existing Instruction.lvalue will go away and become a property of the 
other types of instructions.
2023-03-03 17:09:25 -08:00
Rubén Norte
06460b6fb5 Remove unnecessary (and incorrect) code for compatibility with Paper in the Fabric version of GlobalResponderHandler (#26290)
## Summary

I'm working on a refactor of the definition of `Instance` in Fabric and
I came across this code that seemed to be for compatibility with Paper,
but that it would actually throw an error in that case.

In Paper, `stateNode` is an instance of `ReactNativeFiberHostComponent`,
which doesn't have a `canonical` field. We try to access nested
properties in that field in a couple of places here, which would throw a
type error (cannot read property `_nativeTag` of `undefined`) if we
actually happened to pass a reference to a Paper state node.

In this line:

```javascript
const isFabric = !!(
      fromOrToStateNode && fromOrToStateNode.canonical._internalInstanceHandle
    );
```

If it wasn't Fabric, `fromOrToStateNode.canonical` would be undefined,
and we don't check for that before accessing
`fromOrToStateNode.canonical._internalInstanceHandle`. This means that
we actually never use this logic in Paper or we would've seen the error.

## How did you test this change?

Existing tests.
2023-03-03 23:39:04 +00:00
Andrew Clark
e64a8f4035 Codemod tests to waitFor pattern (3/?) (#26299)
This converts some of our test suite to use the `waitFor` test pattern,
instead of the `expect(Scheduler).toFlushAndYield` pattern. Most of
these changes are automated with jscodeshift, with some slight manual
cleanup in certain cases.

See #26285 for full context.
2023-03-03 17:02:12 -05:00
Andrew Clark
ce8a72fd4e Codemod tests to waitFor pattern (2/?) (#26296)
This converts some of our test suite to use the `waitFor` test pattern,
instead of the `expect(Scheduler).toFlushAndYield` pattern. Most of
these changes are automated with jscodeshift, with some slight manual
cleanup in certain cases.

See #26285 for full context.
2023-03-03 17:01:57 -05:00
Josh Story
1f1f8eb559 [Float][Fizz][Fiber]: Refactor <style> Resource implementation to group on flush (#26280)
There is a problem with <style> as resource. For css-in-js libs there
may be an very large number of these hoistables being created. The
number of style tags can grow quickly and to help reduce the prevalence
of this FIzz now aggregates all style tags for a given precedence into a
single tag. The client can 'hydrate' against these compound tags but
currently on the client insertions are done individually.

additionally drops the implementation where style tags are embedding in
a template for one where `media="not all"` is set. The idea is to have
the browser construct the underlying stylesheet eagerly which does not
happen if the tag is embedded in a template

Key Decision:
One choice made in this PR is that we flush style tags eagerly even if a
boundary is blocked that is the only thing that depends on that style
rule. The reason we are starting with this implementation is that it
allows a very condensed representation of the style resources. If we
tracked which rules were used in which boundaries we would need a style
resource for every rendered <style> tag. This could be problematic for
css-in-js libs that might render hundreds or thousands of style tags.
The tradeoff here is we slightly delay content reveal in some cases (we
send extra bytes) but we have fewer DOM tags and faster SSR runtime
2023-03-03 12:50:35 -08:00
Andrew Clark
5c633a48f9 Add back accidentally deleted test comments (#26294)
The codemod I used in #26288 accidentally caused some comments to be
deleted. Because not all affected lines included comments, I didn't
notice until after landing.

This adds the comments back.
2023-03-03 14:34:41 -05:00
Mengdi Chen
b073104c26 [DevTools] improve troubleshooting in README (#26235)
## Summary

Improve the README when the elements are not loaded due to Chrome
service worker malfunction
2023-03-03 14:02:21 -05:00
Mengdi Chen
fcf2187919 [DevTools] Remove renderer.js from extension build (#26234)
## Summary

When looking into the compiled code of `installHook.js` of the extension
build, I noticed that it actually includes the large `attach` function
(from renderer.js). I don't think it was expected.
This is because `hook.js` imports from `backend/console.js` which
imports from `backend/renderer.js` for `getInternalReactConstants`
A straightforward way is to extract function
`getInternalReactConstants`. However, I think it's more simplified to
just merge these two files and save the 361K renderer.js from the
extension build since we have always been loading this code anyways.
I changed the execution check from `__REACT_DEVTOOLS_ATTACH__ ` to the
session storage.

## How did you test this change?

Everything works normal in my local build.
2023-03-03 14:01:58 -05:00
Sathya Gunasekaran
d24f3fdad9 [test] Add failing test of incorrect typing of captured ref
The typer doesn't understand that it needs to ignore captured references ("read" 
refs are ok, but not "mutated" refs) to be conservative.
2023-03-03 17:33:44 +00:00
Sathya Gunasekaran
ec2a179572 [be] Move phi aliasing to InferAliasForPhis
InferMutableRangesForAlias is about extending the mutable ranges, not for 
updating the alias sets. Let's refactor this into a separate pass. 

InferMutableRangesForAlias was iterating over alias sets and not the HIR so this 
refactor isn't costing us any additional perf cost (in terms of an extra 
iteration over the HIR).
2023-03-03 13:54:52 +00:00
Sathya Gunasekaran
1fffc842bc [hir] Don't redefine context refs in EnterSSA
Context references are special since reassignments need to update the original 
reference, not define a new place.
2023-03-03 13:35:04 +00:00
Sathya Gunasekaran
1e5e75746d [hir] Handle LHS of AssignmentExpression specially
Babel has a bug where it doesn't visit the LHS of an AssignmentExpression if 
it's an Identifier. Work around it by explicitly visiting it.
2023-03-03 13:35:04 +00:00
Sathya Gunasekaran
482ae7aa7c [hir] Refactor Babel expression visitor to separate function
We'll need to recursively call it in the future.
2023-03-03 13:35:03 +00:00
Sathya Gunasekaran
99eb48db07 [hir] Skip only MemberExpressions
Identifiers don't need skipping anyways, so this doesn't affect the existing 
behavior. 

In the future, we will special case handling of LHS of AssignmentExpression 
which will require us to not skip the RHS.
2023-03-03 13:35:03 +00:00
Sathya Gunasekaran
f17f4dcf0b [hir] Treat values escaping into a contextref as Mutate 2023-03-03 13:35:02 +00:00
Sathya Gunasekaran
f002682322 [hir] Treat reassignment as mutation for context refs
The mutable range difference for assignment is just 1 which is something we 
usually don't track as we care about mutation and not assignment. 

But this isn't true for context refs whose (re) assignment is actually a 
mutation.
2023-03-03 13:35:02 +00:00
Sathya Gunasekaran
24fbeddcea [test] Fix test to have initial value
Having undefined as the initial value makes this a primitive. There's a separate 
bug where we need to remove type inference for captured refs that get mutated 
but that's secondary -- we're currently not even marking the Identifier LHS as a 
captured ref. Fix the test to repro this bug for now.
2023-03-03 13:35:01 +00:00
Rubén Norte
b72ed698fb Fixed incorrect value returned as public instance from reconciler (#26283)
## Summary

A few methods in `ReactFiberReconciler` are supposed to return
`PublicInstance` values, but they return the `stateNode` from the fiber
directly. This assumes that the `stateNode` always matches the public
instance (which it does on Web) but that's not the case in React Native,
where the public instance is a field in that object.

This hasn't caused issues because everywhere where we use that method in
React Native we actually extract the real public instance from this
"fake" public instance.

This PR fixes the inconsistency and cleans up some code.

## How did you test this change?

Existing tests.
2023-03-03 09:38:08 +00:00
Andrew Clark
25a8b9735c Codemod tests to waitFor pattern (1/?) (#26288)
This converts some of our test suite to use the `waitFor` test pattern,
instead of the `expect(Scheduler).toFlushAndYield` pattern. Most of
these changes are automated with jscodeshift, with some slight manual
cleanup in certain cases.

See #26285 for full context.
2023-03-02 22:34:58 -05:00
Andrew Clark
e524467338 New internal testing helpers: waitFor, waitForAll, waitForPaint (#26285)
Over the years, we've gradually aligned on a set of best practices for
for testing concurrent React features in this repo. The default in most
cases is to use `act`, the same as you would do when testing a real
React app. However, because we're testing React itself, as opposed to an
app that uses React, our internal tests sometimes need to make
assertions on intermediate states that `act` intentionally disallows.

For those cases, we built a custom set of Jest assertion matchers that
provide greater control over the concurrent work queue. It works by
mocking the Scheduler package. (When we eventually migrate to using
native postTask, it would probably work by stubbing that instead.)

A problem with these helpers that we recently discovered is, because
they are synchronous function calls, they aren't sufficient if the work
you need to flush is scheduled in a microtask — we don't control the
microtask queue, and can't mock it.

`act` addresses this problem by encouraging you to await the result of
the `act` call. (It's not currently required to await, but in future
versions of React it likely will be.) It will then continue flushing
work until both the microtask queue and the Scheduler queue is
exhausted.

We can follow a similar strategy for our custom test helpers, by
replacing the current set of synchronous helpers with a corresponding
set of async ones:

- `expect(Scheduler).toFlushAndYield(log)` -> `await waitForAll(log)`
- `expect(Scheduler).toFlushAndYieldThrough(log)` -> `await
waitFor(log)`
- `expect(Scheduler).toFlushUntilNextPaint(log)` -> `await
waitForPaint(log)`

These APIs are inspired by the existing best practice for writing e2e
React tests. Rather than mock all task queues, in an e2e test you set up
a timer loop and wait for the UI to match an expecte condition. Although
we are mocking _some_ of the task queues in our tests, the general
principle still holds: it makes it less likely that our tests will
diverge from real world behavior in an actual browser.

In this commit, I've implemented the new testing helpers and converted
one of the Suspense tests to use them. In subsequent steps, I'll codemod
the rest of our test suite.
2023-03-02 21:58:11 -05:00
Rubén Norte
d49e0e0be0 Removed unused imperative events implementation from React Native renderer (#26282)
## Summary

I'm going to start implementing parts of this proposal
https://github.com/react-native-community/discussions-and-proposals/pull/607

As part of that implementation I'm going to refactor a few parts of the
interface between React and React Native. One of the main problems we
have right now is that we have private parts used by React and React
Native in the public instance exported by refs. I want to properly
separate that.

I saw that a few methods to attach event handlers imperatively on refs
were also exposing some things in the public instance (the
`_eventListeners`). I checked and these methods are unused, so we can
just clean them up instead of having to refactor them too. Adding
support for imperative event listeners is in the roadmap after this
proposal, and its implementation might differ after this refactor.

This is essentially a manual revert of #23386.

I'll submit more PRs after this for the rest of the refactor.

## How did you test this change?

Existing jest tests. Will test a React sync internally at Meta.
2023-03-02 15:54:51 +00:00
Sathya Gunasekaran
9683771861 [packages] Add Forget version of benchmark 2023-03-02 11:06:00 +00:00
Sathya Gunasekaran
63fd00ab27 [hir] Remove unreachable fallthroughs after merging blocks
Fixes https://github.com/facebook/react-forget/issues/1141
2023-03-03 14:08:52 +00:00
Lauren Tan
0ad0f8cf43 [rhir] Visit DoWhile's test as a conditional dependency
Missed this in the prior PR!
2023-03-03 00:31:37 -05:00
Tianyu Yao
de6444b4f5 Add a logger option for logging compiler errors from Babel
Add a `logger` option so compiler errors are surfaced  in our metrics collection 
pipeline. 

We can probably later merge the global `log` function with it.
2023-03-02 16:59:09 -08:00
Joe Savona
36d1fa2569 [storelocal] Instruction lvalue is just a Place 2023-03-02 14:19:18 -08:00
Joe Savona
f4abf0a9ee [storelocal] lvalues are always const 2023-03-02 14:19:17 -08:00
Joe Savona
487786f7d4 StoreLocal instruction
Adds a new `StoreLocal <kind> <place> = <value>` instruction which stores 
<value> into <place>. With this change, Instruction.lvalue is _always_ a `const` 
temporary, and never a named identifier (there's a new validation pass to assert 
this). StoreLocal is the only way to declare or update a named identifier: the 
instructionKind property says whether it's a const/let declaration or a 
reassignment. Naturally a _lot_ of passes had to be updated to make this work, 
but the existing Effect.Store variant that @gsathya added made this overall 
straightforward. 

Note that as of this PR several passes still have code to handle the possibility 
of an instruction lvalue being something other than a temporary. When we clean 
that up in a follow-up, there will be a lot less of the duplication that appears 
here. For example, CodegenReactiveFunction has two places to handle variable 
declarations in this PR. However, one of them is to handle lvalues, which should 
now _always_ be temporaries and never emit a regular variable declaration. 
Similarly, several passes have to build up a table of identifier -> identifier 
(because of LoadLocal). Longer-term, we should update the Place abstraction so 
that it directly specifies the instruction which created that temporary, so we 
can look it up on demand instead of needing an extra mapping.
2023-03-02 14:19:17 -08:00
Lauren Tan
440fd1f24a Add support for DoWhile statements
Adds support for DoWhileStatements. It's pretty similar to how we handle While, 
except in the case where a test block is unreachable (for example, an early 
unconditional `break` within the loop body). In this scenario we eliminate the 
terminal altogether and replace it with a goto to the loop block.
2023-03-01 19:45:02 -05:00
Joe Savona
71db40c6ff LoadLocal instruction
Changes InstructionValue::Place to InstructionValue::LoadLocal for clarity, this 
is intended as the only instruction where a variable can appear as an operand. 
All other instructions operands will be temporaries.
2023-03-01 16:27:34 -08:00
Sathya Gunasekaran
08c1eda7ff [hir] Simplify depRoot map
Use Identifier as a key, which lets us simplify lookup to no longer require an 
index access.
2023-03-01 16:48:54 +00:00
Andrew Clark
41110021f2 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.
2023-03-01 11:38:48 -05:00
Sebastian Markbåge
67a61d5bd7 [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.
2023-02-28 19:44:37 -05:00
Sebastian Markbåge
40755c01a6 [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.
2023-02-28 19:24:16 -05:00
Lauren Tan
7a6a0e5f72 [be] Fix various eslints 2023-02-28 19:19:38 -05:00
Lauren Tan
f28eef3dca [eslint] Disable no-constant-condition and no-fallthrough 2023-02-28 19:19:37 -05:00
Lauren Tan
323a70d181 [playground] Fix compiler errors being cut off 2023-02-28 19:19:36 -05:00
Jiachi Liu
38509cce9b 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.
-->
2023-02-28 17:27:16 -05:00
Mofei Zhang
1fdbcfe162 [rhir] Add dependencies produced by active (incomplete) scopes
--- 

> If this operand is used in a scope, has a dynamic value, and was defined 
before this scope, then its a dependency of the scope. 

> (from current comments in PropagateScopeDependencies::visitDependency) 

A reactive scope can take a dependency from a definition produced by an 
incomplete parent scope. Our tests previously did not cover this, since most 
object types aliased together and remained mutable throughout a ReactiveScope. 

e.g. our tests did not have 

``` 

scope @0 (deps=...,  declarations=[x, y]) { 

x = {}; 

// define a reactive, immutable value that is not aliased to become mutable 

const immutableVal = ...; 

scope @1 (deps=immutableVal, declarations=[y]) { 

y = read(immutableVal) 

} 

mutateX(x, ...); 

} 

``` 

We should not add a dependency if it is produced in exactly the same scope as 
the one it is used. It is safe (and correct) to depend on values produced by a 
parent scope. 

--- 

Note that we still should check for whether a defining scope is active to 
determine whether it should be added as a output of that scope 
([src](b608ab20d5/forget/src/ReactiveScopes/PropagateScopeDependencies.ts (L469-L478))). 

Access of an identifier produced by a parent scope (i.e. adding a variable 
defined by a scope's parent as its own dependency) does not require adding that 
identifier to the parent's `declarations`, since that identifier is already 
valid to access via identifier binding rules.
2023-02-28 16:36:01 -05:00
Mofei Zhang
b532465ce2 [inference] Capturing an immutable value should be a read
--- 

Following #1216: 

If a value is known to be immutable, then it doesn't need to be considered 
'captured' since no mutation should occur. 

Couldn't figure out a unit test in which this specific fix matters, but we need 
this to fix test output of #1273 

cc. @gsathya, would love some feedback / eyes on this. This makes sense for 
Primitives in particular (which are always read / copied in rval position), but 
I'm not as familiar with edge cases for other immutable values especially around 
lambdas.
2023-02-28 16:36:00 -05:00
Mofei Zhang
474c38c573 [rhir][tests] Added tests for primitives as dependencies
--- 

Our current compiler has specific logic for determining what can be a reactive 
value / reactive dependency. 

Currently, all of the following affect whether an identifier is a reactive: 

- **alias analysis** (applicable to objects) 

- **data + control flow** (whether any other reactive identifiers is used in 
determining it) 

- **reactive scopes** (we generalize and say anything produced by a block with 
reactive dependencies must be non-stable and reactive) 

- this is not true in the case of const primitives, but an overestimate is safe 

- whether the **scope that declares this identifier** is ~~currently active~~ 
the same scope in which it is used (fixed by #1275) 

(since a scope cannot be dependent on itself) 

These conditions are complex. We end up inferring most identifiers as `mutable` 
and `object` types, which have different stability and aliasing properties from 
primitives. As a result, we're missing some cases in our existing test coverage. 

Test case output is fixed by #1274 and #1275 

--- 

(This can be separated from the stack below, which implements conditional 
dependencies. Happy to merge that first and open this as a new stack if that 
produces a significantly better Git PR history.)
2023-02-28 16:35:59 -05:00
Mofei Zhang
6b129b59ed [rhir] Refactor ReactiveScopeDependency, conditional dependencies (2/2)
--- 

See comment block in `PropagateScopeDependencies` and added test case 
`reduce-reactive-conditional-dependencies` for correctness properties / 
dependency merging logic.
2023-02-28 16:35:59 -05:00
Jan Kassens
b2ae9ddb3b Cleanup enableSyncDefaultUpdate flag (#26236)
This feature flag is enabled everywhere.
2023-02-27 14:04:02 -05:00
Mofei Zhang
4005f862bd [rhir] Refactor ReactiveScopeDependency, unconditional dependencies (1/2)
--- 

See comment block in `PropagateScopeDependencies` and added test case 
`reduce-reactive-unconditional-dependencies` for correctness properties / 
dependency merging logic.
2023-02-27 13:38:23 -05:00
Mofei Zhang
9ca41f8a2e [rhir] small: ReactiveDependency uses Identifier instead of Place
--- 

We never use the `Place` of a ReactiveScopeDependency, except for when we want 
to access its identifier. Later PRs in this stack will convert 
`ReactiveScopeDependency` to property access trees (and traverse over the tree). 
This usually involves merging multiple Dependencies into trees (where each root 
is a unique identifier). We then traverse over each tree to extract its 
dependencies (e.g. unconditional leaves). 

``` 

{place: {loc: 1, identifier: 'props'}, path: ['a', 'b']} 

{place: {loc: 2, identifier: 'props'}, path: ['a']} 

// merges into a single tree root, which should represent a single identifier 

``` 

The `place` of each individual `ReactiveScopeDependency` will be lost during the 
tree traversal, and it doesn't really make sense to recreate them using the 
`Place` attached to the tree root.
2023-02-27 13:38:02 -05:00
Mofei Zhang
f335e7d4d9 [rhir] Patch: ordering of overlapping input dependencies does not matter
--- 

Patch and simplify logic around merging overlapping reactive dependencies. 

Added `reduce-reactive-unconditional-deps` test fixtures, which tries to cover 
all cases of merging unconditional dependencies (to a minimal dependencies set). 
Please let me know if I missed any
2023-02-27 13:38:02 -05:00
Lauren Tan
8bc8d67aee [be] Fix unused vars in BuildHIR 2023-02-27 17:12:41 -05:00
Lauren Tan
e4e1af7236 [eslint] Ignore _ prefixed unused variables 2023-02-27 17:12:38 -05:00
mofeiZ
60137a8b64 [rhir][cleanup] remove DeclKind (replaced by pruneNonReactiveDependencies)
DeclKind is no longer read / needed due to pruneNonReactiveDependencies pass.
2023-02-27 11:04:38 -05:00
Josh Story
6ff1733e63 [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.
2023-02-25 11:06:09 -08:00
Josh Story
1173a17e6e [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.
2023-02-25 11:04:51 -08:00
Sebastian Markbåge
e7d7d4cb4b 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".
2023-02-25 12:10:39 -05:00
Mengdi Chen
564166099b [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.
2023-02-24 15:13:05 -05:00
Sophie Alpert
a8f971b7a6 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.
2023-02-24 12:06:27 -08:00
Sophie Alpert
96cdeaf89b [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).
2023-02-24 11:33:54 -08:00
Mengdi Chen
ca2cf319fd [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.
2023-02-23 16:53:11 -05:00
lauren
bfb9cbd8ca [difftrain] Make github sha clickable for easier debugging (#26225) 2023-02-23 07:59:22 -08:00
Joe Savona
1dfaf8a94b Lower all operands to temporaries
This PR changes BuildHIR to lower all operands to temporaries. Example: 

```javascript 

// Input 

a + b; 

// Previous Lowering 

Const t0 = BinaryOperation Place(a) "+" Place(b) 

// New Lowering 

Const t0 = Place(a); 

Const t1 = Place(b); 

BinaryOperation Place(t0) "+" Place(t1) 

``` 

This is necessary to ensure we're always referring to the correct version of a 
variable, even in the case of reassignment mid-expression. For example, we 
previously evaluated `let x=1; x + (x = 2) + x` incorrectly to 6 because we 
lowered the `x = 2` prior to the binary operators. We now lowers each instance 
of x to a temporary, ensuring they refer to the correct SSA version of the 
variable, and produce the correct result (5). 

Note that with this change, the _only_ place a variable can appear as an 
operator is when the InstructionValue is a raw identifier. This was already the 
case for globals (as of the LoadGlobal instruction). All other instruction value 
variants will only ever receive temporaries as arguments. 

This necessitated a few changes to our inference: 

* The logic to extend the range of phi operands (if the phi is mutated) was 
previously in LeaveSSA, but that was actually too late. The introduction of 
lowering to temporaries help discover failing cases, which I fixed earlier in 
the stack by moving the logic to extend the range of phi operands into the 
InferMutableRanges fixpoint loop. 

* PropagateScopeDependencies now has to track variable reassignments in addition 
to tracking property accesses 

* AnalyzeFunctions now has to track variable reassignments in addition to 
tracking property accesses 

* InferReactiveIdentifiers now needs a fixpoint iteration, because identifiers 
don't directly appear together in the same instruction anymore (such that we can 
directly propagate the reactivity between them). Instead, we'll first see that 
the temporaries are reactive, and have to propagate that back to the identifiers 
the temporaries were loaded from. 

Overall while this does introduce a bit more complexity, it also makes the 
compiler more robust. As with the phi example illustrates, there are legitimate 
inputs that can create similar indirections to that introduced by lowering 
identifiers to temporaries. 

Note that there’s a theme to the changes here: several analysis passes need to 
map an operand back to its identifier value. Ideally our HIR structure would 
directly support looking up the value for a temporary. For example, if operands 
were references to eg the index of the instruction that produced them. Because 
we don’t have such a representation yet (it would fall out naturally if we were 
writing in Rust), we have to do some bookkeeping. The key takeaway here is that 
this bookkeeping is incidental complexity given our current representation, not 
fundamental complexity of the algorithm.
2023-02-22 15:53:23 -08:00
Andrew Clark
c04b180701 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.
2023-02-22 15:32:09 -05:00
Abhiram Satpute
212b89fa25 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>
2023-02-21 21:30:34 +01:00
Sebastian Markbåge
0a76fb9ec4 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.
2023-02-21 14:48:37 -05:00
Sebastian Markbåge
c8d4eeda5f 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>
2023-02-21 14:18:21 -05:00
Sebastian Markbåge
60144a04da 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.
2023-02-21 13:18:24 -05:00
mofeiZ
70b0bbda76 [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).
2023-02-21 09:10:23 -08:00
Sebastian Silbermann
c7967b194b 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
2023-02-20 22:16:23 +01:00
Sebastian Silbermann
bb1e3d0e19 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`
2023-02-20 21:59:21 +01:00
Sebastian Markbåge
62e6c4612e 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.
2023-02-20 15:03:22 -05:00
Sebastian Markbåge
80cf4a099e 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.
2023-02-20 13:27:13 -05:00
Samuel Susla
2cc54b57ed 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.
2023-02-20 15:17:44 +00:00
chenpeng
8a82207286 add test case for semver major comparisons 2023-02-20 15:36:48 +01:00
Glenn 'devalias' Grant
6b6d0617ef 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>
2023-02-20 01:35:56 -05:00
Ming Ye
bc38a3dfa7 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
2023-02-20 00:04:26 -05:00
Joe Savona
256071460d [destructuring] Cleanup InstructionValue type definition 2023-02-17 15:30:42 -08:00
Joe Savona
1d0aa64b24 Make it easier to debug lambdas 2023-02-22 14:07:33 -08:00
Joe Savona
8da443b673 Print HIR of function expressions for debugging
Example output: 

``` 

bb0 (block): 

[1] Const mutate $9$ = read a$8 

[2] Const store x$10:TObject$ = Object { a: read $9 } 

[3] Const mutate $11:TObject$ = capture x$10:TObject 

[4] Const store $12[4:6]:TFunction$ = Function @deps[read $11:TObject]: 

bb0 (block): 

[1] Const mutate q$7$ = capture x$6 

[2] Const mutate $8$ = capture q$7 

[3] Const mutate $9$ = PropertyLoad read $8.b 

[4] Const store $10[4:6]:TFunction$ = Function @deps[read $9]: 

bb0 (block): 

[1] Const mutate $7:TPrimitive$ = 1 

[2] Const mutate $8[2:4]$ = capture q$6[0:4] 

[3] Const store $9$ = PropertyStore mutate $8[2:4].b = read $7:TPrimitive 

[4] Return 

[5] Const mutate $11$ = Call mutate $10[4:6]:TFunction() 

[6] Return 

[5] Const mutate $13$ = Call mutate $12[4:6]:TFunction() 

[6] Const mutate $14:TObject$ = capture x$10:TObject 

[7] Return freeze $14:TObject 

```
2023-02-22 13:03:00 -08:00
Joe Savona
bae2cb5f89 Remove now-unnecessary mutable range extension in LeaveSSA
This is no longer necessary now that we extend phi operands' ranges in 
InferMutableRanges
2023-02-21 15:29:30 -08:00
Joe Savona
9a25b5a12a Fix previous examples, alias across phis
Within the InferMutableRanges fixpoint iteration, we need to alias phi operands 
with the phi id if the phi id is later mutated.
2023-02-21 15:29:30 -08:00
Joe Savona
79eb250187 Bug repro for unobserved aliased mutation w phi
I found this while working to ensure that we always lower all operands to 
temporaries. This works: 

```javascript 

// the whole computation of x is memoized in one block, bc of the mutation after 
the phi 

let x; 

if (cond) { 

x = someObj(); 

} else { 

x = someObj(); 

} 

mutate(x); 

``` 

However, if you alias either of the operands, we lose the mutation: 

```javascript 

let x; 

if (cond) { 

const y = someObj(); // OOPS this gets independently memoized 

x = y; 

} else { 

x = someObj(); 

} 

mutate(x); 

``` 

The core issue is that InferMutableRanges does not take into account mutation of 
phis. ~~My first thought is that we need an additional, outer fixpoint iteration 
loop to flow mutation back "up" to phi operands~~ 

edit: there was a much easier fix, we need to alias phi operands and phi id 
within the existing fixpoint iteration. See follow-up PR which fixes.
2023-02-21 08:29:37 -08:00
Sebastian Markbåge
db5e6250d4 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.
2023-02-17 16:00:18 -05:00
Andrew Clark
c9d9f524d7 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.
2023-02-17 15:45:03 -05:00
Joe Savona
fcdcd6038f Constant propagation converts computed access to static property where possible 2023-02-17 12:32:30 -08:00
Joe Savona
2b3902f043 Bailout on assigning to module-scope variables 2023-02-17 12:18:17 -08:00
Joe Savona
a2ebea4cde Bailout on assigning to globals 2023-02-17 10:02:56 -08:00
Joe Savona
ac9212f24e Make globals configurable; populate a reasonable default list
This is a precursor to validating that all identifiers are defined - we need to 
know about gobals and module declarations, so this PR adds the ability to 
configure a Set<string> of defined globals. The default list is inspired by the 
globals that prepack defines, which just comes from the spec definition.
2023-02-17 09:47:59 -08:00
Joe Savona
6b654f306c Construct LoadGlobal; consume hook info from types
Updates BuildHIR to produce LoadGlobal instructions for references to globals. 
Note that this breaks our previous strategy of finding hook calls: that relied 
on looking at the callee of a CallExpression and checking its name, which relied 
on the callee not being lowered to a temporary. By lowering the name (eg 
`useState`) to a temporary first, we now no longer see the name at the callsite. 

Thankfully @gsathya solved this for us already by teaching type inference about 
hooks, and more generally implementing type inference. I updated this so that we 
infer the type of a LoadGlobal if the name is a hook: the type inference picks 
this up and propagates the type forward correctly. So now, all places that 
needed to check for a hook can just look at the type and everything works. 

This is much more robust than before - you can now reassign a hook to a local 
variable and we'll still detect that when you call it, you're calling a hook.
2023-02-17 09:47:58 -08:00
Mengdi Chen
1a49e2d833 remove flow check in electron app.js (#26184)
When we were upgrading flow in
6ddcbd4f96
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
2023-02-17 11:54:43 -05:00
BIKI DAS
4fcc9184ac 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)
2023-02-17 12:23:10 +01:00
Joe Savona
326e8c13f7 Scaffolding for LoadGlobal instruction
Adds a new `LoadGlobal` InstructionValue variant which will be used to represent 
identifiers that refer to globals. We don't construct this value type yet.
2023-02-16 15:17:30 -08:00
Joe Savona
0c72eed413 Pass environment options through babel plugin
Updates the babel plugin so that environment options — including custom hook 
definitions — can be passed in through the plugin: 

* Renames `CompilerFlags` => `PluginOptions` since they are specific to the 
babel plugin, and are no longer just flags. 

* Moves the definition of `useFreeze()` out of the builtin hook list and instead 
passes it when our unit tests configure the plugin.
2023-02-16 14:24:15 -08:00
Joe Savona
8810076bc6 Lookup hook declarations on environment
Changes from calling the global parseHookCall() function to looking up the hook 
declaration on the environment.
2023-02-16 14:06:17 -08:00
Joe Savona
cee25928bf Rename Environment => State for infer reference effects for clarity
InferReferenceEffects needs to be able to pass around the function's 
Environment, but there is already a local class with that name. It's confusing 
to have two "environment" concepts in one file, so this PR renames that local 
class to the more appropriate `InferenceState` and renames local variables and 
updates comments accordingly.
2023-02-16 14:06:16 -08:00
Joe Savona
eece73262e Start of making globals and hook declarations configurable
Some refactoring to allow the environment options to be passed in from the 
outside.
2023-02-16 14:06:15 -08:00
Mengdi Chen
42106558ed React DevTools 4.27.1 -> 4.27.2 (#26185) 2023-02-16 16:46:23 -05:00
lauren
21b49103d6 [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.
2023-02-16 12:47:12 -08:00
Joe Savona
158c9e4fc1 [be] Extract Environment to a separate file
Precursor to making the environment configurable
2023-02-16 10:47:27 -08:00
Joe Savona
530231712f [be] Extract hooks helpers to separate file
This is a precursor to allowing the set of custom hooks (and their behavior) to 
be configurable.
2023-02-16 10:38:06 -08:00
Joe Savona
b05fc6a945 Repro of tagged template as hook arg 2023-02-16 10:21:53 -08:00
Joe Savona
26e9e14d85 Fix typo 2023-02-16 09:04:45 -08:00
Joe Savona
849198da9d Pass cache size to useMemoCache() 2023-02-16 08:57:42 -08:00
Joe Savona
93775440a6 Minimal repros of product patterns 2023-02-16 08:57:38 -08:00
Joe Savona
fe5ca23384 Fix PrintHIR for TaggedTemplateExpression 2023-02-16 08:57:34 -08:00
Joe Savona
e45f69154f Fix dropped temporary in value block 2023-02-16 08:57:30 -08:00
Joe Savona
e504e1212a [be] Import from index instead of direct path 2023-02-16 08:57:26 -08:00
mofeiZ
55ca5fc26c [playground] add flow parsing
I don't think there is a monaco config to parse flow (for IDE integration), but 
now we should be able to parse flow for the Forget compiler. 

Since typescript and flow has different parsing rules, playground will only use 
flow parser if `// @flow` is at the top of the file. 

Test: 
[link](https://react-forget-playground-j7nd7j8cv-fbopensource.vercel.app/#eyJzb3VyY2UiOiIvLyBAZmxvd1xuZnVuY3Rpb24gQ29tcG9uZW50KHByb3BzKSB7XG4gIGxldCB4ID0gKHByb3BzOiBudW1iZXIpO1xuICByZXR1cm4geDtcbn1cbiJ9)
2023-02-16 11:54:27 -05:00
Sebastian Markbåge
189f70e17b Create a bunch of custom webpack vs unbundled node bundles (#26172)
We currently have an awkward set up because the server can be used in
two ways. Either you can have the server code prebundled using Webpack
(what Next.js does in practice) or you can use an unbundled Node.js
server (what the reference implementation does).

The `/client` part of RSC is actually also available on the server when
it's used as a consumer for SSR. This should also be specialized
depending on if that server is Node or Edge and if it's bundled or
unbundled.

Currently we still assume Edge will always be bundled since we don't
have an interceptor for modules there.

I don't think we'll want to support this many combinations of setups for
every bundler but this might be ok for the reference implementation.

This PR doesn't actually change anything yet. It just updates the
plumbing and the entry points that are built and exposed. In follow ups
I'll fork the implementation and add more features.

---------

Co-authored-by: dan <dan.abramov@me.com>
2023-02-16 11:01:52 -05:00
Jonny Burger
fbf3bc3158 Add scale as a unitless property (#25601)
## Summary

CSS has a new property called `scale` (`scale: 2` is a shorthand for
`transform: scale(2)`).

In vanilla JavaScript, we can do the following:

```js
document.querySelector('div').scale = 2;
```

which will make the `<div>` twice as big. So in JavaScript, it is
possible to pass a plain number.
However, in React, the following does not work currently:


```js
<div style={{scale: 2}}>
```

because `scale` is not in the list of unitless properties. This PR adds
`scale` to the list.


## How did you test this change?

I built `react` and `react-dom` from source and copied it into the
node_modules of my project and verified that now `<div style={{scale:
2}}>` does indeed work whereas before it did not.
2023-02-16 11:12:32 +01:00
BIKI DAS
2f40170192 Don't recommend deprecated debugger script (#26171)
yarn debug-test is now deprecated in React package.json. It has been
replaced by yarn test --debug.



https://user-images.githubusercontent.com/72331432/219268188-8ff5dd42-da2b-434c-83be-72a9d258ee98.mp4
2023-02-16 11:11:12 +01:00
Lauren Tan
0d0d3a4038 Ensure stable variable names after leaving SSA
With this PR we now no longer emit copy instructions during LeaveSSA, and 
restore the original identifier name.
2023-02-15 15:22:03 -05:00
Lauren Tan
d1fd0449ee [be] Linter fixes for LeaveSSA 2023-02-15 15:22:01 -05:00
Sathya Gunasekaran
06e5681198 [hir] Use receiver of CallExpression as dep 2023-02-15 15:03:29 +00:00
Joe Savona
008cebd633 [facepalm] Fix bug w missing deps
While reviewing @poteto's PR I noticed that there were some cases of missing 
dependencies. I tracked it down to a bug I introduced 
[here](5b827eb85c (r100646304)). 
Decl.id is meant to be the id of the instruction that declares the variable. We 
then test to see if a dependency is later than that. If the Decl.id is 
incorrectly too high, then we miss some dependencies thinking they aren't 
defined yet.
2023-02-14 16:22:58 -08:00
Joe Savona
b7b0118afa InferReactiveIdentifiers handles Capture effect 2023-02-14 15:48:52 -08:00
Joe Savona
9493e13709 [be] Use switch for exhaustiveness 2023-02-14 15:48:49 -08:00
Joe Savona
eda7788c48 InferReactiveIdentifiers uses IdentifierId
This is to help prep for @poteto's renaming PR. To make that PR work we 
generally need to use IdentifierId to distinguish "the same identifier" rather 
than Identifier object identity.
2023-02-14 15:44:46 -08:00
Joe Savona
490c204dcf Move logic for making reactive scope decls all reactive
InferReactiveIdentifiers has some extra logic to find identifiers declared in 
the same scope, and promote non-reactive identifiers to reactive if they appear 
inside a reactive scope (reactive scope == scope with one or more (reactive) 
dependencies). Even though the identifier alone might not be technically 
reactive (have no reactive inputs), it can get re-recreated if the scope 
re-evaluates. 

We can now do this during PruneNonReactiveDependencies as we exit out of each 
scope.
2023-02-14 15:27:52 -08:00
Joe Savona
b1ee356805 InferReactiveIdentifiers: fixpoint iteration is now unnecessary
I removed fixpoint iteration and all tests pass, which matches my intuition that 
it's really that we need strictly two passes. Removing to simplify and for 
performance (avoid unnecessary extra visits of the ast)
2023-02-14 15:24:01 -08:00
Joe Savona
2b47cac5fd Create a separate pass to prune non-reactive dependencies
The fact that InferReactiveIdentifiers is integrated directly into 
PropagateScopeDependencies has made the latter pretty tricky to debug at times. 
If a dependency is missing, we have to introspect and figure out if that's 
because it was somehow inferred as non-reactive. This PR creates a new 
PruneNonReactiveDependencies pass to separate out these phases.
2023-02-14 14:09:53 -08:00
Sathya Gunasekaran
fb8f293c32 [hir] Add a DropMemoCall pass
This drops the memo hook calls from the IR
2023-02-14 23:07:19 +00:00
Sathya Gunasekaran
e0562bbd51 [typer] Type hook callee as Hook type 2023-02-14 23:07:18 +00:00
Sathya Gunasekaran
d0f1a98144 [typer] Introduce a Hook type 2023-02-14 23:07:17 +00:00
Sathya Gunasekaran
1dfd51cdb0 [hir] Add name field to Hook 2023-02-14 23:07:17 +00:00
Sathya Gunasekaran
a65bf197d7 [hir] Add Memo hooks 2023-02-14 23:07:16 +00:00
Sathya Gunasekaran
12ca0ba61b [hir] Simplify HookKind 2023-02-14 23:07:16 +00:00
Sathya Gunasekaran
81b23f9242 [typer][be] Add helper for checking type.kind 2023-02-14 19:10:37 +00:00
Joe Savona
5673588be4 [be] Tidy up some mutableRange logic 2023-02-13 15:26:07 -08:00
Joe Savona
225fe0835c Optimize DCE to visit CFG only once when there are no loops
Optimizes dead code elimination. Currently it keeps iterating the control flow 
graph until no new usages have been discovered, which accounts for usages across 
loops. However, when there are no loops it's sufficient to iterate the CFG 
exactly once.
2023-02-13 13:59:44 -08:00
Joe Savona
6b67f597a6 Capturing a frozen value is a Read
If a value is known to be frozen (or potentially frozen), then it doesn't need 
to be considered 'captured' since no mutation can occur via aliasing.
2023-02-14 09:33:23 -08:00
Lauren Tan
759a7e027b Fix incorrectly recording declarations in reassignments in
PropagateScopeDependencies 

This was incorrectly added in #1190, oops!
2023-02-13 16:52:08 -05:00
Lauren Tan
b5a0739e8c Scopes with reassignments should still emit memo block 2023-02-13 16:52:07 -05:00
Lauren Tan
a76627c972 Use IdentifierIds to when comparing Identifier
With the upcoming changes to SSA renaming in #1194, we rewrite phi operand 
identifiers to have the same IdentifierId as the declaration the identifier 
originated from: so downstream checks need to compare ids instead of the 
identifier instance.
2023-02-13 16:52:05 -05:00
Lauren Tan
985a289a4c [BE] Various linter fixes 2023-02-13 16:52:04 -05:00
Mateus Toledo
fccf3a9fba 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.
-->
2023-02-13 21:47:42 +01:00
Sebastian Silbermann
86c8c8db79 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.
2023-02-13 21:45:59 +01:00
Sathya Gunasekaran
31d8aad40e [hir] Check if defined before looking up ValueKind
This handles globals now without throwing
2023-02-13 16:32:50 +00:00
Ming Ye
4a4ef2706c 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
2023-02-12 16:03:32 -05:00
Josh Story
64acd3918a 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
2023-02-10 13:35:50 -08:00
Jan Kassens
2de85d7c71 Minor Jest upgrade (#26150)
Minor version bump to get the fix for `numPassingAsserts`:
https://github.com/facebook/jest/pull/13795

Test Plan:
CI
2023-02-10 14:06:14 -05:00
Ming Ye
71cace4d32 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
2023-02-10 13:39:14 -05:00
Sebastian Silbermann
b8ae89f382 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`
2023-02-10 19:19:26 +01:00
Sathya Gunasekaran
7277897405 [test] Add test for broken lambda capturing
SSA redefines context refs which breaks our inference. The correct fix here is 
to not overwrite context refs in EnterSSA.
2023-02-10 17:59:59 +00:00
Sathya Gunasekaran
b56f413e99 [hir] Mark ArrayExpression capturing a context ref as a context ref
A context ref capture is transitive.
2023-02-10 17:59:58 +00:00
Sathya Gunasekaran
343ebb47bd [hir] Mark ObjectExpression capturing a context ref as a context ref
A context ref capture is transitive.
2023-02-10 17:59:57 +00:00
Sathya Gunasekaran
fa57551dd5 [hir] Introduce ValueKind.Context
This tracks whether a value is a context ref or generated from a context ref. 

This lets us track mutations to context refs and treat it separately as we want 
this to be more conservative than our existing inference. 

ValueKind.Context is exactly like ValueKind.Mutable but is more conservative.
2023-02-10 17:59:56 +00:00
Sathya Gunasekaran
2a9fab001a [be] Fix test
'e' does not exist, use 'd' instead
2023-02-10 17:26:25 +00:00
Sathya Gunasekaran
199e284eda [hir] Mark Identifiers aliased as Effect.Capture 2023-02-10 17:26:21 +00:00
Sathya Gunasekaran
40a85432ed [hir] Move inference logic to Env.reference 2023-02-10 17:26:17 +00:00
Joe Savona
6877ac6500 Fix update assignment on computed memberexpression 2023-02-10 08:59:15 -08:00
Xin Chen
d9e0485c84 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: ******
```
2023-02-10 11:28:31 -05:00
Sebastian Markbåge
c8510227c1 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.
2023-02-10 11:23:48 -05:00
Ming Ye
55542bc73d Update jest printBasicPrototype config (#26142) 2023-02-10 09:58:57 +01:00
Josh Story
6396b66411 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
2023-02-09 22:59:29 -08:00
Joe Savona
5746d5b07f Temporary workaround for emitting temporaries multiple times
This is a temporary fix for the issue we discovered on our first integration, 
where destructuring of a function return value is emitting the function call 
multiple times: 

```javascript 

// Input 

const [x, setX] = useState(null); 

// Output 

const x = useState(null)[0]; 

const setX = useState(null)[1]; 

``` 

The reason this happens is that we lower `useState(null)` to a temporary, and 
then generate a ComputedLoad for each of x and setX. Codegen doesn't emit 
temporaries eagerly - it assumes they are going to be used exactly once and it 
re-emits the value each time the temporary is used. Hence why the 
`useState(null)` part gets duplicated in the output. 

Right now destructuring is the only place i'm aware of where we reuse 
temporaries this way. And we do want to change codegen to preserve destructuring 
in the output to correctly handle array patterns. However, that's a more 
involved change. For now, this PR is a stopgap. During the pass where we promote 
temporaries used in scopes to named variables, we now check to see if those 
temporaries are used multiple times and promote them. 

The above example would then generate something like 

```javascript 

const t0 = useState(null); 

const x = t0[0]; 

const setX = t0[1]; 

``` 

This is still incorrect (it assumes t0 is an array), but it's more likely to 
work in practice. I'll revert this change once we correctly handle 
destructuring.
2023-02-09 17:22:54 -08:00
Sebastian Markbåge
ef9f6e77b8 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.
2023-02-09 19:45:05 -05:00
Sebastian Markbåge
6c75d4e009 Delete blocks fixture (#26143)
It's not really up-to-date and it's not really show casing anything we
don't have elsewhere.
2023-02-09 18:44:37 -05:00
Ming Ye
35698311de 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
2023-02-10 00:08:37 +01:00
Jan Kassens
6ddcbd4f96 [flow] enable LTI inference mode (#26104)
This is the next generation inference mode for Flow.
2023-02-09 17:07:39 -05:00
Joe Savona
dd228c9ed0 [be] non-blocking ESLint config, fixes
Configures typescript-eslint for the project with an initial configuration that 
starts with their recommended rules, and adds/disables a few (generally either 
disabling warnings or promoting them to errors). The new `yarn lint` command is 
not hooked up to CI yet, so for now this is something we can opt-in to running 
locally. If you have some free time, help get us down to zero errors! 

My general philosophy for linting, which I propose we follow, is that lints 
should be very high-signal: 

* Error, don't warn. If it's worth mentioning it's worth fixing. 

* Enable rules that consistently identify real problems. If we frequently would 
have to disable the rule due to false positives, it isn't high-signal. 

* Enable rules that help improve consistent style (to avoid code review about 
style rather than substance).
2023-02-09 11:58:06 -08:00
Joe Savona
8eb5feb847 [be] Cleanup BuildHIR 2023-02-09 11:41:04 -08:00
Rubén Norte
53b1f69ba6 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
afec07aca2).
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
673c7617bc
.

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.
2023-02-09 18:51:47 +00:00
Sebastian Silbermann
c0b0b3a9f8 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
2023-02-09 18:00:11 +01:00
Ming Ye
5940934967 Update to Jest 29 (#26088)
## Summary

- yarn.lock diff +-6249, **small pr**
- use jest-environment-jsdom by default
- uncaught error from jsdom is an error object instead of strings
- abortSignal.reason is read-only in jsdom and node,
https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/reason

## How did you test this change?

ci green

---------

Co-authored-by: Sebastian Silbermann <silbermann.sebastian@gmail.com>
2023-02-09 17:07:49 +01:00
Aravind D
28fcae062b Add support for SVG transformOrigin prop (#26130)
Co-authored-by: eps1lon <silbermann.sebastian@gmail.com>
2023-02-09 13:47:50 +01:00
Sebastian Silbermann
3ff1540e9b 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
2023-02-09 10:54:35 +00:00
Mark Erikson
78d2e9e2a8 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!
2023-02-08 20:00:22 -05:00
Joe Savona
41f52b73c2 Change reference effects for hooks
I realized we hadn't updated InferReferenceEffects to match our latest thinking 
on hooks. Specifically, we will default to assuming that hooks can mutate their 
arguments and return mutable values — this works with our model since we don't 
treat hooks specially for reactive scope construction. Ie, first we figure out 
what variables construct together, then we create scopes, then we prune scopes 
that contain hooks. So changing the reference effects for hooks "just works". 

Note that it is helpful for our unit tests to have an example hook that we know 
_does_ freeze its input and return a frozen value, so i've temporarily added 
`useFreeze()` to the list of defined hooks. That is meant as a stopgap: the 
right solution is to allow some way to tell the compiler about specific custom 
hooks and their semantics.
2023-02-08 14:24:14 -08:00
Joe Savona
7f60f32118 Dont memoize scopes with hook calls 2023-02-08 14:07:01 -08:00
Joe Savona
c7e3bc4d41 Visitor extension for transforming ReactiveFunction
Adds a subclass of ReactiveFunctionVisitor, ReactiveFunctionTransform, which 
makes it easier to write passes that change the shape of a ReactiveFunction. The 
two use-cases converted so far are both flattening away certain categories of 
reactive scopes — this will make it easier to add a similar pass to prune scopes 
that contain hook calls.
2023-02-08 14:07:00 -08:00
Josh Story
a3152eda5f 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
2023-02-08 11:32:38 -08:00
Sathya Gunasekaran
394666118d [hir] Lower function expressions into HIR 2023-02-08 17:45:33 +00:00
Sathya Gunasekaran
662b8d2ff3 [hir] Add lvalue effect for PropertyLoad and ComputedLoad 2023-02-08 16:01:36 +00:00
Lauren Tan
d47f608c61 Record reassignments
Record a variable that is declared in some other scope and that is being 
reassigned in the current one as a reassignment
2023-02-08 10:26:33 -05:00
Lauren Tan
e7f4eae619 Reset canonicalId mutable range if not mutated after creation 2023-02-08 10:26:31 -05:00
Lauren Tan
6f661f3b79 Extend mutable ranges if a phi is mutated after creation 2023-02-08 10:26:29 -05:00
Lauren Tan
d43a5014f4 Rename ReactiveScope.outputs to ReactiveScope.declarations 2023-02-08 10:26:27 -05:00
Lauren Tan
1809ffd06d Add new test cases for SSA
Add these as a separate commit so we can see how later PRs in the stack change 
them
2023-02-08 10:26:26 -05:00
Lauren Tan
5888cbdd9b Don't throw on invalid compiler flags 2023-02-08 10:26:24 -05:00
Xin Chen
758fc7fde1 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.
2023-02-07 14:47:05 -08:00
Sebastian Markbåge
01a0c4e12c 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.
2023-02-07 15:10:01 -05:00
Sathya Gunasekaran
24b28ae257 [λ] Remove broken support for identifiers defined after use
This also adds some book keeping to throw if ever define identifiers after use 
to make sure we don't generate incorrect code.
2023-02-07 18:25:55 +00:00
Sebastian Markbåge
f0cf832e1d Update Flight Fixture to "use client" instead of .client.js (#26118)
This updates the Flight fixture to support the new ESM loaders in newer
versions of Node.js.

It also uses native fetch since react-fetch is gone now. (This part
requires Node 18 to run the fixture.)

I also updated everything to use the `"use client"` convention instead
of file name based convention.

The biggest hack here is that the Webpack plugin now just writes every
`.js` file in the manifest. This needs to be more scoped. In practice,
this new convention effectively requires you to traverse the server
graph first to find the actual used files. This is enough to at least
run our own fixture though.

I didn't update the "blocks" fixture.

More details in each commit message.
2023-02-07 12:09:29 -05:00
Sathya Gunasekaran
d1dbb00790 [hir] Throw if Effect.Store is not handled 2023-02-07 16:59:37 +00:00
Sathya Gunasekaran
3df1ae66c0 [λ] Use Effect.Capture for mutating deps
Leverage Effect.Capture to differentiate between mutating and non mutating deps.
2023-02-07 16:59:36 +00:00
Sathya Gunasekaran
85c92bcfbe [aliasing] Introduce Effect.Capture
Effect.Capture is very similar to Effect.Read, but the only difference is that 
this reference is stored somewhere via a Effect.Store. 

Previously, any operand associated with a Effect.Store in the same instruction 
would get aliased -- so there was no need to explicitly differentiate between a 
"normal read" and "read that gets stored". 

This difference is now explicit with FunctionExpression where every dependency 
is "read" but only a few are "captured" for store (and mutation). In a follow up 
PR, the mutating deps will have an Effect.Capture to differentiate from the 
other non mutating deps (Effect.Read).
2023-02-07 16:59:35 +00:00
Sathya Gunasekaran
4e07b8a869 [hir] Do not alias Identifier as Store
Identifiers are never stored (Effect.Store), they are always mutated 
(Effect.Mutate) and aliased in the InferAlias pass.
2023-02-07 16:59:35 +00:00
Sebastian Silbermann
13f4ccfdba 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`
2023-02-07 17:57:43 +01:00
Lauren Tan
195f473cb4 s/useMemoCache/unstable_useMemoCache
uMC is still prefixed with unstable in React 
(653dd2348c/packages/react/src/React.js (L143))
2023-02-07 11:40:06 -05:00
Sathya Gunasekaran
1f7cd2ff21 [hir] Remove unnecessary null check 2023-02-07 15:08:38 +00:00
Lauren Tan
9cac0b0068 Ensure Forget runs first if specified in a Babel config
This commit adds a new Program visitor to our Babel plugin which then calls our 
FunctionDeclaration visitor. Babel does some "smart" merging of plugin passes so 
so even if plugin A is inserted prior to plugin B, if A does not have a Program 
visitor and B does, B will run first. 

Note that we also can't use Forget inside of a Babel preset as plugins run 
_before_ presets (https://babeljs.io/docs/en/plugins/#plugin-ordering).
2023-02-07 11:11:58 -05:00
Mengdi Chen
c12194f748 [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.
2023-02-07 07:59:44 -05:00
Lauren Tan
e159844b0d Add generated code to errors thrown by BabelPlugin
If we've generated an erroneous AST (eg duplicate declarations), this lets us 
observe what the code looked like to aid debugging
2023-02-06 19:03:54 -05:00
Lauren Tan
0d2653dbd4 Use parent of AssigmentExpressions when bailing out
For some reason the expression itself wont print the codeframe, but its parent 
will, so print that instead
2023-02-06 17:32:30 -05:00
Joe Savona
382226ab31 Add missing return statements to fixtures 2023-02-06 14:09:15 -08:00
Jan Kassens
1445acf777 [CI] cache yarn instead of node_modules (#25834)
The current caching of steps of `node_modules` doesn't work reliable as
is because it includes `arch` in the cache key. `arch` might be
different across workers in the same commit.

I couldn't find a way to optionally restore caches, so what this PR does
is:
- remove the setup step that ran before all other steps and essentially
just populates a circle CI cache key
- all other steps now do: restore yarn cache, `yarn install`, save yarn
cache (fast if already exists)

With this change the initial batch of jobs all race to populate the
cache, but any subsequent jobs should find the existing cache. The
expected downside would be slightly more worker CPU time with all the
parallel jobs, but wall time might be shorter (1 step less in the
critical path) and we should be more reliable as we no longer have the
failure with multiple archs.


## Alternative 1
Remove the `{arch}` from the cache key.

Downside: this might run into weird issues with native dependencies.

## Alternative 2
Somehow check if the cache was restored and only then run a yarn
install.

Downside: couldn't figure out if it's possible to only restore the yarn
cache if restoring the node_modules cache failed. Without that we'd
either always restore both the yarn and node_modules cache or do yarn
installs w/o cache which are prone to failure in the past.
2023-02-06 16:11:17 -05:00
Sebastian Markbåge
03a216070d 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.
2023-02-06 15:54:14 -05:00
Sebastian Markbåge
4bf2113a15 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.
2023-02-06 10:50:52 -05:00
Sathya Gunasekaran
500cfddc3a [λ] Remove unused params in FunctionExpression 2023-02-06 14:03:13 +00:00
Lauren Tan
cd108cd430 Add enableOnlyOnUseForgetDirective flag
When this flag is enabled, Forget will only compile function declarations opted 
in via the `'use forget'` directive. By default this is false. 

Tested internally, see related diffs
2023-02-06 16:47:35 -05:00
Joe Savona
b009626431 Improve DCE to handle unused loop phis
Improves DCE, using fixpoint iteration to detect values that are updated across 
loops but otherwise never read. There is still some further optimization we can 
do (the dce-loop case could optimize out `y`), but this seems like plenty for 
now. 

Actually, we probably have to add some return statements to our fixtures before 
landing this, because otherwise most of the code goes away.
2023-02-03 15:46:00 -08:00
Joe Savona
19e21b73a7 Initial pass at dead code elimination
This is a first pass at DCE without having read any literate on the subject, so 
lemme know if there's a better approach. That said the algorithm is: 

* Keep a `Set<Identifier>` of identifiers that are used (and whose constructing 
logic cannot be removed). 

* Do a first RPO iteration of all block's phis. Any phi operand that 
participates in a loop is preemptively marked as "used" even if it isn't 
strictly used somewhere. This step is necessary bc these operands may otherwise 
not be used. 

* Do a second post-order iteration of all blocks, including iterating first 
their terminals, then reverse iteration of instructions, then their phis. Mark 
the operands of each as used as we encounter them, and prune instructions whose 
lvalue is never used. 

For now I was conservative about which types of instructions can be pruned. For 
example, call instructions are never pruned, even if the result of the call is 
never used. 

However one catch is that we currently prune instructions that cause values to 
become frozen. We had planned to add runtime calls (in dev) to freeze values for 
runtime enforcement, and if we want to do that we can always add these 
instructions back (or replace them with explicit freeze calls). 

There are a few potential next steps but we should discuss whether they're worth 
it: 

* Use fixpoint iteration to find exactly which operands are actually used. This 
would allow us to to prune cases such as `let x = 0; while (...) { x += 1 }` eg 
where there's a phi but the result is never used. Such cases should be rare in 
practice though. 

* Eliminate more types of instructions, eg eliminate function calls that don't 
have any mutable arguments.
2023-02-03 14:55:49 -08:00
Joe Savona
812e0ce701 [valueblocks] Join blocks instead of replacing operands (fix edge case)
There's a bug in the HIR->ReactiveFunction conversion for certain categories of 
compound value blocks where we replace operands (which must be a Place) with a 
ReactiveValue. This approach worked in practice for lots of cases so I thought a 
type coercion was safe, but then I found a case where this assumption breaks 
(see new test). 

The updated logic fixes the bug and is simpler. When a value block gets split up 
(because there was a nested value block), instead of replacing the earlier value 
in the later instructions, we append the instructions together. This can result 
in some extra nesting (which if we wanted we could flatten away) but ensures 
that we maintain type-safety.
2023-02-03 14:16:17 -08:00
Joe Savona
cc33497c44 [valueblocks] Add InstrId to SeqExperession value
A SequenceExpression currently doesn't store the InstructionId that produced its 
final `.value`. This PR adds that instruction id, which is then used in the next 
PR as we compose SequenceExpressions.
2023-02-03 14:16:17 -08:00
Joe Savona
29a95d2dea [be] Use generator in InferTypes, extract helper
Just small things I noticed when looking at InferTypes. I was thinking about how 
we'd adjust this pass to account for hooks, i'll probably pause that for now but 
putting this up in case you like the changes. If not no big deal!
2023-02-03 12:59:13 -08:00
Mofei Zhang
e30a9e9258 [hir syntax] Handle TemplateLiteral syntax 2023-02-03 15:44:37 -05:00
Mofei Zhang
34595b84c8 [syntax] Followup: clean up InferReactiveIdentifiers 2023-02-03 15:44:36 -05:00
Sathya Gunasekaran
4b55399fb8 [λ] Use context identifiers in inner functions
This threads through context identifiers to inner functions and also uses them 
as dependencies if they are mutated in the inner function.
2023-02-03 17:42:07 +00:00
mofeiZ
ecb084c4b8 [ReactiveHIR] Infer reactive identifiers and promote temporaries
Messed up ghstack, this is a duplicate of #1093
2023-02-03 14:52:46 -05:00
Andrew Clark
855b77c9bb 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.
2023-02-02 19:20:34 -05:00
Jan Kassens
2ef24145e4 [flow] upgrade to 0.199.0 (#26096)
`flow-remove-types` was also upgraded to the latest version.
2023-02-02 16:19:05 -05:00
Sebastian Markbåge
922dd7ba50 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.
2023-02-02 15:30:59 -05:00
Joe Savona
34a7b58334 Restrict switch case test values until they use value blocks
We currently lower switch case test values within the wrong scope: the test 
value really should be a value block rather than a `Place`. Until then, this PR 
adds a bailout for complex test values: we allow primitives and identifiers 
which should cover most real-world use-cases.
2023-02-02 09:09:25 -08:00
Sathya Gunasekaran
dc65e7c5a9 [aliasing] Make InferAliasForStores use the visitor infra
No need for InferAliasForStores to know about the semantics of each instruction 
anymore. It's just a simple pass that iterates over every operand and lvalue. 

The FunctionExpression is special cased because it's slightly different but I 
have a follow up that removes this special casing.
2023-02-02 17:41:35 +00:00
Sathya Gunasekaran
40f304392e [aliasing] Alias object loads to it's lvalue as well
This doesn't change codegen as the lvalue is unused but it lets us make this 
pass be semantically the same across all instructions -- "alias lvalue and 
operands of an instr".
2023-02-02 17:41:31 +00:00
Sathya Gunasekaran
018899d778 [aliasing] Make aliasing account for MutableRange.end being exclusive 2023-02-02 17:41:27 +00:00
Sathya Gunasekaran
98f67c407b [aliasing] Alias ComputedLoad operands 2023-02-02 15:45:16 +00:00
Sathya Gunasekaran
5e1929c002 [aliasing] Alias ComputedStore operands 2023-02-02 15:45:12 +00:00
Joe Savona
de929fcc40 Partial support for update expressions
Adds limited support for UpdateExpressions (`x++`). We now support the postfix 
form (`x++` ok, `++x` is a todo) and only when the argument is an identifier. We 
can relax these restrictions with more work, but this PR should be sufficient 
for the examples we've seen so far.
2023-02-02 07:53:24 -08:00
Sathya Gunasekaran
7a92b2fe5d [be] Cleanup logic that matches mutatedId and mutatedDep 2023-02-02 14:05:37 +00:00
Sathya Gunasekaran
12274f30b9 [be] Inline buildMutatedDeps 2023-02-02 14:05:36 +00:00
Sathya Gunasekaran
aa2403e068 [λ] Run analyseFunctions on inner func exprs
Previously we would skip out on calling analyseFunctions on inner function  
exprs so we missed out on catching aliased mutation in a different scope.
2023-02-02 14:05:35 +00:00
Sathya Gunasekaran
0522d5233b [λ] Store and define captured bindings as context
This lets us treat global references differently from captured references.
2023-02-02 14:05:34 +00:00
Lauren Tan
8a0d3169fd Record todo bailouts in CodegenReactiveFunction
Went over this pass and converted any todos to bailouts, otherwise we continue 
to throw an invariant if there's an internal error
2023-02-01 14:49:47 -05:00
Lauren Tan
1baf22a421 [playground] Fix error wrapping for realsies
CSS is hard (jk i'm just terrible at it now)
2023-02-01 14:14:45 -05:00
Lauren Tan
8c9d1b85be Failing test from - - 2023-02-01 13:46:20 -05:00
Lauren Tan
f53318d0ba [playground] Fix errors not wrapping 2023-02-01 13:17:04 -05:00
Sebastian Markbåge
9d111ffdfb 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.
2023-02-01 12:56:53 -05:00
Joe Savona
c2dda028fd Improve debugging for - errors 2023-02-01 09:42:46 -08:00
Joe Savona
2069269903 Support TypeCastExpression
Support TypeCastExpressions — `(x: TypeAnnotation)`. This is pretty 
straightforward, it's semantically identical to a raw identifier. 

One catch is that our prettier config is hard-coded to use the babel-ts parser, 
i wasn't sure how to make that dynamic based on the file extension so for now i 
just ignored .flow.js files in our pretter config.
2023-02-01 08:42:33 -08:00
Ming Ye
0ba4698c7b Fix async test in React reconciler (#26087) 2023-02-01 09:59:41 +01:00
Sebastian Markbåge
8c234c0de9 Move the Webpack manifest config to one level deeper (#26083)
This frees up the Webpack manifest to contain a `serverManifest` part
too.

@shuding
2023-01-31 23:33:31 -05:00
Joe Savona
47074a2def Support JsxSpreadAttribute
Changes the representation of JsxElement props to be an array of attributes, 
each of which can be a named attribute or spread attribute.
2023-01-31 16:43:46 -08:00
Joe Savona
df07522b89 [be] Move Result into Utils/
The `Utils/` folder is meant to be a catch-all for code that doesn't have an 
obvious home in other directories.
2023-01-31 16:14:23 -08:00
Lauren Tan
e8650951ea [playground] Add diff view toggle
Quick hack to show a diff view comparing previous pass to current. Default is 
the output view 

![Screenshot 2023-01-31 at 5 37 09 
PM](https://user-images.githubusercontent.com/1390709/215899637-672d578a-6fb9-4580-ae87-ae0be0878a59.png) 

![Screenshot 2023-01-31 at 5 37 12 
PM](https://user-images.githubusercontent.com/1390709/215899640-7aff3c06-fc67-476a-82f9-59d65b4f9ac4.png)
2023-01-31 17:37:22 -05:00
mofeiZ
5fbfce6d3b [test case] Failing assignment inside of nested if statement
``` 

function useBar(props) { 

let z; 

if (props.a) { 

if (props.b) { 

z = baz(); 

} 

} 

return z; 

} 

``` 

Currently fails with 

``` 

InvariantViolation: A phi cannot have two operands initialized before its 
declaration 

```
2023-01-31 16:53:06 -05:00
Joe Savona
0c5176c618 [valueblocks] Cleanup
Removes dead code related the now-unused old representation for value blocks.
2023-01-31 13:39:41 -08:00
Joe Savona
fa525e0b6f [valueblocks] For.init is a value block 2023-01-31 13:39:40 -08:00
Joe Savona
894eadfa67 [valueblocks] For.update is a proper value block 2023-01-31 13:39:39 -08:00
Joe Savona
6930b5f77e [valueblocks] For.test is a proper value block 2023-01-31 13:39:39 -08:00
Joe Savona
90e1265442 [valueblocks] While.test is a proper value block
Changes ReactiveWhileTerminal’s test to use the new value block representation. 
This means logical and condition expressions will work as while test values now.
2023-01-31 13:39:38 -08:00
Joe Savona
50f300bc92 [valueblocks] Update some passes to use the new visitor
Updates some passes from ReactiveScopes/ to use the visitor added in the 
previous PR. The +124/-354 line count on this diff tells the story  — the new 
visitor avoids a lot of boilerplate and helps focus on the logic not the 
traversal. 

Note that there are a few passes which transform the function such as 
adding/removing scopes. A follow-up will extend the visitor to support that and 
convert the remaining passes.
2023-01-31 13:39:38 -08:00
Joe Savona
400bf4588c [valueblocks] More general visitor for ReactiveFunctions
This adds a truly general-purpose visitor pattern for ReactiveFunction, modeled 
on what's worked well in Relay Compiler. All types of node that have children 
get a visitFoo/traverseFoo pair of functions. By default the visitFoo() function 
delegates to the traverseFoo() function, but the visit variant is meant to be 
overridden and can delegate to the traverseFoo() variant — this gives you 
precise control so that you can save/restore state before/after traversing 
children. 

Probably the only interesting thing is that visitLValue() does not call 
visitPlace() by default though it technically could. So far that is making sense 
in the passes i converted. 

Note that once all passes are updated to use this, i'll delete the other visitor 
helpers for ReactiveFunction.
2023-01-31 13:39:37 -08:00
Joe Savona
149353badb [valueblocks] Support sequence expressions (comma operator) 2023-01-31 13:39:37 -08:00
Joe Savona
d6505572cb [valueblocks] Disallow AssignmentExpression in value blocks (temporarily)
There's a bug with assignment expression in normal value blocks due to LeaveSSA. 
Until that's resolved i'm temporarily distinguishing "loop" blocks and "value" 
blocks, and disallowing assignment expressions in value blocks specifically.
2023-01-31 13:39:36 -08:00
Joe Savona
8c13c91f27 [valueblocks] ternary tests showing assignment bug
A ternary that reassigns the same variable in both branches causes some 
weirdness with LeaveSSA, this PR just adds the failing case.
2023-01-31 13:39:36 -08:00
Joe Savona
acd227440e [valueblocks] Support conditional expressions (ternary)
Support conditional expressions from AST -> HIR -> ReactiveFunction -> AST. This 
also helps make the patterns for value block handling more clear, so i was able 
to extract some reusable logic in the HIR -> ReactiveFunction conversion phase.
2023-01-31 13:39:35 -08:00
Joe Savona
dc7ac6fea4 [valueblocks] Scaffolding for ternary terminals
Core representation for terminals, without the lowering and conversion logic.
2023-01-31 13:39:34 -08:00
Joe Savona
aca0e27012 [valueblocks] split working test and aliasing bug case 2023-01-31 13:39:34 -08:00
Joe Savona
096482e5cb print mutable ranges on every place
useful for debugging
2023-01-31 13:39:33 -08:00
Joe Savona
95642c4421 [valueblocks] Printing for LogicalValue/SequenceValue 2023-01-31 13:39:33 -08:00
Joe Savona
86ffcde8ed [valueblocks] Handle compound RHS for logicals
The previous PR handled the case where the LHS of a logical was compound, but 
didn't handle compound RHS values. This is fixed now.
2023-01-31 13:39:32 -08:00
Joe Savona
d4acc7efa6 [valueblocks] Convert logical terminal to ReactiveValue
Implements the conversion from LogicalTerminal into a ReactiveLogicalValue (and 
ReactiveSequenveValue if necessary). The implementation is a bit rough, i clean 
it up in subsequent PRs which revealed parts of the logic that could be shared w 
ternaries.
2023-01-31 13:39:32 -08:00
Joe Savona
bb8ae86c24 [valueblocks] ReactiveFunction repr for logical expressions
Extends ReactiveInstruction's value type to be a regular InstructionValue *or* a 
LogicalValue. LogicalValue is operator, left, and right. It's really convenient 
that we've already distinguished Instruction/ReactiveInstruction now — while the 
_helpers_ here are updated to handle this new value type, the types ensure that 
HIR can never encounter a LogicalValue. 

The actual conversion of logical terminals into this value is complex and is 
later in the stack.
2023-01-31 13:39:31 -08:00
Joe Savona
c6a066af83 [valueblocks] Lower logical expressions into logical terminals
Changes the lowering for LogicalExpression to use the new 'logical' terminal. 
Whereas before we tried to more directly model the semantics of `??` by 
generating an `if (<lhs> != null)`, we now generate a branch terminal that looks 
at the lhs. 

The HIR -> ReactiveFunction construction for logical and branch terminals are 
placeholders while I refactor the ReactiveFunction representation to support 
value blocks.
2023-01-31 13:39:31 -08:00
Joe Savona
b1548100d1 [be] Clarify type of value block final value before change
Makes the type of the final value of a ValueBlock more precise, prior to 
changing it
2023-01-31 13:39:30 -08:00
Sebastian Markbåge
977bccd24d Refactor Flight Encoding (#26082)
This is just shifting around some encoding strategies for Flight in
preparation for more types.

```
S1:"react.suspense"
J2:["$", "$1", {children: "@3"}]
J3:"Hello"
```

```
1:"$Sreact.suspense"
2:["$", "$1", {children: "$L3"}]
3:"Hello"
```
2023-01-31 12:41:36 -05:00
Ming Ye
8b9ac8175f 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
2023-01-31 10:47:14 -05:00
Lauren Tan
e48b615598 [playground] Fix header when horizontal scrolling
Fixes a minor annoyance 

Before 

![Screenshot 2023-01-31 at 10 39 06 
AM](https://user-images.githubusercontent.com/1390709/215806108-f3b084d3-c693-404b-a9b3-785d0f15c332.png) 

After 

![Screenshot 2023-01-31 at 10 33 15 
AM](https://user-images.githubusercontent.com/1390709/215804818-c94a5905-e278-4380-af44-6ab34ac95ff3.png)
2023-01-31 10:36:31 -05:00
Ming Ye
d7bb524ade [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
2023-01-31 10:23:31 -05:00
Jan Kassens
6b30832666 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.
2023-01-31 08:25:05 -05:00
Lauren Tan
3b4f41b58d [ez] Make dev mode more obvious in playground
It's easy to confuse your local browser tab with main, this modifies a 

few colors and labels to make it more obvious 

![Screenshot 2023-01-30 at 5 05 18 
PM](https://user-images.githubusercontent.com/1390709/215606089-78e5c874-263e-46e9-a99d-3d863bdc4432.png)
2023-01-30 17:03:59 -05:00
Jan Kassens
1f5ce59dd7 [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.
2023-01-30 15:25:24 -05:00
an onion
48b687fc95 [trusted types][www] Add enableTrustedTypesIntegration flag back in (#26016)
## Summary

The flag was first added in #16157 and was rolled out to employees in
D17430095. #25997 removed this flag because it wasn't dynamically set to
a value in www. The www side was mistakenly removed in D41851685 due to
deprecation of a TypedJSModule but we still want to keep this flag, so
let's add it back in + add a GK on the www side to match the previous
rollout.

See D42574435 for the dynamic value change in www

## How did you test this change?

```
yarn test
yarn test --prod
```
2023-01-30 13:26:04 -05:00
Lauren Tan
213ed2d6d0 [ez] Wrap output cols to prevent nested h-scroll
![Screenshot 2023-01-30 at 1 03 46 
PM](https://user-images.githubusercontent.com/1390709/215558010-49d3ddf4-3dee-418e-9595-790e720bad22.png)
2023-01-30 13:04:39 -05:00
Sathya Gunasekaran
04fb507876 [hir] Remove broken support for ForOf, ForIn, DoWhile 2023-01-30 19:12:43 +00:00
Samuel Susla
9b1423cc09 Revert "Hold host functions in var" (#26079)
Revert https://github.com/facebook/react/commit/353c30252. The commit
breaks old React Native where `nativeFabricUIManager` is undefined. I
need to add unit test for this to make sure it doesn't happen in the
future and create a mechanism to deal with undefined
`nativeFabricUIManager`.
This is to unblock React sync to React Native.
2023-01-30 17:23:02 +00:00
Lauren Tan
019f069778 Fix not being able to scroll horizontally 2023-01-30 11:37:28 -05:00
Lauren Tan
f0d64064a9 Support partial compilation in playground
This adds support in the playground for best effort compilation: if any 

passes have errors, we'll try to render as many successful tabs leading 

up to the pass with an error. 

Also contains some styling updates 

![Screenshot 2023-01-27 at 2 18 06 
PM](https://user-images.githubusercontent.com/1390709/215222635-59b42555-f1f3-4fc0-b1cd-3959946df6da.png) 

![Screenshot 2023-01-27 at 2 18 54 
PM](https://user-images.githubusercontent.com/1390709/215222636-4c0275fd-a95b-4f0f-946a-258ad8b27722.png) 

![Screenshot 2023-01-27 at 5 03 02 
PM](https://user-images.githubusercontent.com/1390709/215222637-92a8e459-173a-41ae-be9f-0cc0d54479d0.png)
2023-01-30 10:36:35 -05:00
Lauren Tan
be4058057c Bailout TaggedTemplateExpressions instead of invariant 2023-01-30 10:36:34 -05:00
Lauren Tan
545e53c428 Use CompilerErrors to record errors
This moves the bailout recording mechanism into a separate CompilerErrors class 
instead of repurposing HIRBuilder. This is to allow other passes to also record 
errors instead of immediately throwing.
2023-01-30 10:29:14 -05:00
Sebastian Silbermann
b0671f9ea0 Include removal of scheduler/tracing in changelog (#26063) 2023-01-30 08:12:48 +01:00
Sebastian Markbåge
ce09ace9a2 Improve Error Messages when Access Client References (#26059)
This renames Module References to Client References, since they are in
the server->client direction.

I also changed the Proxies exposed from the `node-register` loader to
provide better error messages. Ideally, some of this should be
replicated in the ESM loader too but neither are the source of truth.
We'll replicate this in the static form in the Next.js loaders. cc
@huozhi @shuding

- All references are now functions so that when you call them on the
server, we can yield a better error message.
- References that are themselves already referring to an export name are
now proxies that error when you dot into them.
- `use(...)` can now be used on a client reference to unwrap it server
side and then pass a reference to the awaited value.
2023-01-27 20:08:26 -05:00
Mengdi Chen
78c4bec207 [DevTools] fix local build for extension (#26067)
## Summary

resolves #26051

After we upgrade to Manifest V3, the browser no longer allow us to run
`eval` within the extension. It's not a problem for prod build, but for
dev build, webpack has been using eval to inject the source map for
devtool. This PR changes it to an alternative method.
2023-01-27 15:35:07 -05:00
Jan Kassens
cb16201180 Update danger.js token (#26066)
The old token was revoked, this updates the token by reading from CI
secrets instead, I'm not sure there's benefit in making it publicly
visible.
2023-01-27 14:05:08 -05:00
Samuel Susla
0652bdbd10 Add flow types to Maps in ReactNativeViewConfigRegistry.js (#26064)
Need to add types to these two maps to unblock React Native sync.
2023-01-27 16:55:38 +00:00
Sathya Gunasekaran
c803558b2a [hir] Parse object pattern params 2023-01-26 16:40:08 -05:00
Sathya Gunasekaran
41e8088e8c [hir] Try to resolve a dep into a property load only if it's a temporary. 2023-01-26 16:40:07 -05:00
Sathya Gunasekaran
978215eae6 [test] Add test that resolves property loads to expanded places incorrectly
Ideally this should happen only for temporary places containing property loads.
2023-01-26 13:38:55 -05:00
Lauren Tan
98cb9eff92 Fix playground tabs always showing the same HIR or reactive function
Previously we were storing a pointer to the HIR or ReactiveFunction 

prior to printing, so when we printed them it would always print the 

results of the last pass. This commit changes it so we print them to 

strings when iterating through the compiler pipeline so each snapshot is 

correctly preserved 

![Screenshot 2023-01-26 at 4 34 23 
PM](https://user-images.githubusercontent.com/1390709/214955701-67f4da1e-b12c-432a-ba47-1a29afd91312.png)
2023-01-26 16:33:56 -05:00
Lauren Tan
d44538ad96 Stop passing NodePaths to CompilerError
This was causing issues in various places where errors would be stringified. 
Because the inner detail objects would contain a NodePath with circular 
structures this would cause a JSON.stringify error in code outside of our 
control. This change makes it so we always print the codeframe from the NodePath 
and then passing the string.
2023-01-26 13:58:56 -05:00
Joe Savona
4ab8cc6ae9 [valueblocks] Use branch terminal for if/for test blocks
Updates `while` and `for` to use the new branch terminal as their test block 
terminal (IfTerminal is now only meant for if statements).
2023-01-25 17:05:23 -05:00
Joe Savona
f88fa006e7 [valueblocks] Scaffolding for branch terminal
Scaffolding for a new 'branch' terminal, which is the lower-level form of 'if' 
meant for use in value blocks. See design at 
https://fb.quip.com/b7N6AjkDcl2a#temp:C:bAO904b0cf06f154de4a7287af6d
2023-01-25 17:05:22 -05:00
Joe Savona
1014727d41 [valueblocks] Specify block type at creation
We need to know the kind of each block (regular or value). Rather than specify 
the kind when closing the block — when we've lost context about why the block 
was created — it's simpler and more accurate to specify the kind when 
creating/reserving the block.
2023-01-25 17:05:22 -05:00
Lauren Tan
840bb6fec2 Add colors to debug logging 2023-01-25 16:15:12 -05:00
Sathya Gunasekaran
e6b4988b1e [hir] Infer UnaryExpression as non allocating 2023-01-25 11:11:16 -05:00
Sathya Gunasekaran
9eb9071aed [typer] Add type inference for unary expr 2023-01-25 11:11:16 -05:00
mofeiZ
9bd67099d7 [prettier] detect changed files from relative dir
Previously, `yarn prettier` didn't write changed files since `glob` produced 
paths relative to cwd and `git diff --name-only` produced paths relative to git 
root directory. 

This changes `git diff --name-only` to `git diff --name-only --relative`
2023-01-25 15:16:39 -05:00
Sathya Gunasekaran
f83ff2feda [hir] Parse UnaryExpression 2023-01-25 11:11:16 -05:00
mofeiZ
b00963ffde [playground] Handle invariant violation errors
playground currently hard crashes when we hit an invariant violation 

<img width="1104" alt="image" 
src="https://user-images.githubusercontent.com/34200447/214615036-dbe307d8-132d-4186-a8ab-6fcaf69801d1.png"> 

[playground 
link](https://0xeac7-forget.vercel.app/#eyJzb3VyY2UiOiJcbmZ1bmN0aW9uIHVzZUJhcihwcm9wcykge1xuICBwcm9wcyA9IG51bGw7XG4gIGxldCB5LCB6O1xuXG4gIGlmIChwcm9wcy54KSB7XG4gICAgbGV0IHkgPSB1c2VGb28ocHJvcHMuYS5iKTtcbiAgICB3aGlsZSAoYmFyKCkpIHtcbiAgICAgIGlmIChwcm9wcy55KSB7XG4gICAgICAgIHogPSBiYXooKTtcbiAgICAgIH1cbiAgICB9XG4gIH1cblxuICByZXR1cm4gW3ksIHpdXG59In0=) 

This should fix that
2023-01-25 11:23:09 -05:00
Lauren Tan
47da50dfe8 [ez] Fix typo 2023-01-25 10:20:53 -05:00
mofeiZ
62b7526929 [hir] Handle OptionalMemberExpression syntax
(Implemented as per discussions with @gsathya ) 

Handle OptionalMemberExpression by adding an 'optional' flag to `PropertyLoad` 
instruction, which is set during `BuildHIR` and read during 
`CodegenReactiveFunction`.
2023-01-25 10:16:21 -05:00
Sathya Gunasekaran
79d53f9117 [hir] Parse and codegen TaggedTemplateExpression
Basic support to parse relay fragments
2023-01-24 16:41:00 -05:00
Lauren Tan
cd45341920 yarn install 2023-01-24 14:05:14 -05:00
Lauren Tan
9d935db383 Render error markers in playground
Additionally with this commit we now support multiple top level 

functions 

![Screenshot 2023-01-24 at 12 01 34 
PM](https://user-images.githubusercontent.com/1390709/214359278-7160b612-094d-4498-918d-944d30d61366.png) 

![Screenshot 2023-01-24 at 12 01 21 
PM](https://user-images.githubusercontent.com/1390709/214359275-d776c416-badb-4989-8952-dec1b1f3f7ed.png)
2023-01-24 12:44:51 -05:00
Lauren Tan
109d7ba980 Refactor CompilerError
This commit repurposes CompilerError to represent an aggregate of error details 
accumulated during HIR lowering. It also fixes the playground to correctly 
render errors again.
2023-01-24 12:44:51 -05:00
Lauren Tan
3da8d52a0f Consistency pass for error messages in BuildHIR 2023-01-24 12:44:51 -05:00
Sathya Gunasekaran
8f169574c7 [test262] Set language as typescript 2023-01-24 11:02:54 -05:00
Sathya Gunasekaran
8041b0b0d5 [λ] Parse and codegen concise arrow expressions 2023-01-24 10:47:49 -05:00
Sathya Gunasekaran
9aed0fc6b1 [babel] Add flow support
Check if there's a pragma to toggle flow parsing
2023-01-24 10:21:25 -05:00
Sathya Gunasekaran
19dd29707b [λ] Fix mutatedDep collection in AnalyseFunctions
Make sure to check free variables as well for mutations. Not just object 
properties.
2023-01-23 15:46:35 -05:00
Sathya Gunasekaran
ee3a88f20f [λ] Parse and codegen arrow function exprs 2023-01-23 17:39:37 -05:00
mofeiZ
3ba90a7f9c Inline hasNode check (hack)
www currently on an older version of babel
2023-01-23 16:08:01 -05:00
mofeiZ
16169bec07 Redo patch prettier
reverts / redos #1055 

(accidentally merged changes from another PR in #1055)
2023-01-23 16:03:49 -05:00
mofeiZ
07cda62430 [prettier] Patch prettier to write modified TS files (#1055) 2023-01-23 15:57:11 -05:00
Sathya Gunasekaran
3927281fe4 [λ] Re run SSA on function expr
Functions can capture variables declared after the definition of the function. 
This re runs SSA to map the captured identifiers to the new SSA identifiers if 
available.
2023-01-23 13:20:33 -05:00
Sathya Gunasekaran
123d024af7 [λ] Add test for function expr passed to jsx
Function exprs become frozen when captured by jsx.
2023-01-20 19:44:32 +00:00
Sathya Gunasekaran
294b6c752d [plugin] Add default export to forget 2023-01-23 14:36:54 -05:00
Lauren Tan
8e08334a42 Specify sourceType "module" in hir-test and playground
This was preventing the playground and fixture tests from being able to compile 
an ExportDefaultDeclaration
2023-01-23 13:11:35 -05:00
Lauren Tan
b44f507c92 [test262] Strip codeframes from Forget errors so results are grouped
correctly
2023-01-20 11:47:11 -05:00
Lauren Tan
44beb3c023 Collect bailouts in BuildHIR::lowerAssignment 2023-01-20 11:47:11 -05:00
Lauren Tan
9ed6977c48 Collect bailouts in BuildHIR::lowerJsxElement 2023-01-20 11:47:10 -05:00
Lauren Tan
4b3b498e37 Collect bailouts in BuildHIR::lowerJsxElementName 2023-01-20 11:47:10 -05:00
Lauren Tan
9697e15bd5 Collect bailouts in BuildHIR::lowerMemberExpression 2023-01-20 11:47:09 -05:00
Lauren Tan
b2983571f2 Collect bailouts in BuildHIR::lowerExpression
Mostly mechanical changes to lowerExpression to push an error to HIRBuilder 
rather than invariant.
2023-01-20 11:47:09 -05:00
Lauren Tan
1a3e269274 Rename InstructionValue.OtherStatement to UnsupportedNode
As discussed, this repurposes OtherStatement as a catch all variant for 
unsupported syntax or errors in the source. This also renames the previously 
added ErrorTerminal to UnsupportedTerminal for consistency (plus makes it a 
little bit less confusing that it's not an actual terminal representing an 
Error). 

Not loving the name but couldn't think of anything better, open to suggestions!
2023-01-20 11:47:08 -05:00
Sathya Gunasekaran
c1c30889cc [hir] Lower function expressions into HIR 2023-01-20 14:01:51 +00:00
Lauren Tan
b3fedd3273 Fix import path to ReactForgetBabelPlugin
This broke jest in watch mode
2023-01-19 13:33:32 -05:00
Sathya Gunasekaran
7c73f51139 [hir] Define function name only if it exists 2023-01-19 18:39:23 +00:00
Sathya Gunasekaran
da6d372c3a [hir] Store env in HIRFunction
The env is specific to the HIR function anwyays. It's not very useful outside 
the HIRFunction.
2023-01-19 18:39:19 +00:00
Sathya Gunasekaran
0a60bf2071 [ts] Make ts emit source maps 2023-01-19 18:39:14 +00:00
Sathya Gunasekaran
a5b245b17d [hir] Fix typescript warnings 2023-01-19 12:07:05 +00:00
Joe Savona
d295bb4516 Fix scope merging in MergeOverlappingReactiveScopes
When `MergeOverlappingReactiveScopes` identified scopes to be merged, it was 
currently (oops, my bad) updating the _existing_ scope's id and range. Later, 
PropagateScopeDependencies marks outputs of a scope by updating that 
identifier's scope instance — so if that scope instance isn't shared, then the 
output is lost. This PR fixes MergeOverlappingReactiveScopes to correctly update 
all operands for a scope to have the same scope instance.
2023-01-19 10:10:21 -08:00
Joe Savona
7f7727d7e5 Consolidate logic in MergeOverlappingScopes prior to fix
Small refactor to consolidate visiting operands and their scopes, used in the 
follow-up PR.
2023-01-19 10:10:20 -08:00
Lauren Tan
6174c85ee9 [oops] Use correct import path in test262-preprocessor 2023-01-19 12:29:49 -05:00
Lauren Tan
40df4a8a86 [ez] Update test262-preprocessor to use the same config as hir-test 2023-01-19 11:37:50 -05:00
Lauren Tan
32a83374be Format CompilerErrors with Babel codeframes 2023-01-19 11:37:49 -05:00
Lauren Tan
60698e63c6 Re-emit unexpected hir-test error rather than a new one
Makes debugging a little easier as the previous console.error would be logged 
out of band with the jest error message. And the jest error would be missing the 
error stack.
2023-01-19 11:37:49 -05:00
Lauren Tan
b98e87aa63 Use BabelPlugin in hir-test 2023-01-19 11:37:48 -05:00
Lauren Tan
717719b8ea Fix infinite loop in BabelPlugin
After some painful debugging I isolated the infinite loop when attempting to use 
the BabelPlugin in hir-test rather than manually parsing and traversing it. The 
issue is that in the BabelPlugin we were replacing the original 
FunctionDeclaration with a new one, which would add it to Babel's traversal 
queue. This would effectively create an infinite loop where we would try to 
optimize a function that was already compiled by Forget (aside: _should_ running 
the compiler multiple times on code work?). 

To get around this we can just call the handy `skip` method on the new 
FunctionDeclaration to tell Babel to stop traversing it. I'm also moving the 
scope check here because I'll remove it from hir-test in a later commit.
2023-01-19 10:10:56 -05:00
Sathya Gunasekaran
f42c51b971 [λ] Support member expressions in lambdas
Lower member expression if the receiver is in scope. Skip the remaining path 
before capturing so we don't recurse down the identifiers in the member 
expression.
2023-01-19 12:13:35 +00:00
Sathya Gunasekaran
ef5636c25d [λ] Use lowerExpression to create captured identifier 2023-01-19 12:13:34 +00:00
Lauren Tan
50d27c325a Allow tests to be skipped with @skip
Also remove old filename based test directive, since the comment based one is 
much easier to use
2023-01-18 10:58:50 -05:00
Lauren Tan
23a044e406 Record more errors in BuildHIR::lowerStatement
Captures other kinds of statements that we're lowering to OtherStatements as 
TODO errors
2023-01-18 10:58:50 -05:00
Joe Savona
de83adc739 [be] Skip debug logging if content has not changed
Avoids printing debug information if it exactly matches what was last printed. 
This means when debug printing (eg with `@only`) you'll see things like: 

``` 

BuildReactiveFunctions: 

...debug view... 

FlattenReactiveLoops: (no change) 

PropagateScopeDependencies: 

...debug view... 

``` 

Which saves time figuring out if something changed in a given pass.
2023-01-17 16:00:42 -08:00
Joe Savona
8a15b65e1a [be] Reorder PruneUnusedLabels pass
This pass can run later, rather than right in between two passes that affect 
scope creation.
2023-01-17 16:00:39 -08:00
Joe Savona
0391405530 [be] Print implicit break/continue
When debug printing `ReactiveFunction`, clarifies which break/continue are 
implicit.
2023-01-17 16:00:36 -08:00
Joe Savona
2e501b0f01 Rename variables during BuildHIR
Per design discussion, this PR changes BuildHIR to maintain the invariant that, 
for each distinct variable in the input, that all references to that variable in 
the HIR will have the same unique `name` _and_ same unique `id`. Phrased 
differently: Identifiers with the same id will have the same name and 
vice-versa. 

This isn't an invariant we maintain throughout compilation — SSA form changes 
the `id`s — but crucially, ensuring that the `name` is also unique allows us to 
understand later which identifiers referred to the same original variable and 
which were different. 

Follow-up PRs will ensure that we maintain variable identifiers in the output as 
well, in all cases except shadowing (and for shadowing, we'll rewrite 
identifiers inside lambdas).
2023-01-17 09:40:50 -08:00
Joe Savona
edeaaaf38a Add PropertyCall/ComputedCall instructions
Adds `PropertyCall` and `ComputedCall`, which are a combination of 
CallExpression and PropertyLoad/ComputedLoad, respectively. The goal is to 
ensure that we correctly model the receiver of a call where the callee is a 
member expression, and also accurately record scope dependencies in for both the 
computed and non-computed (property) cases. 

An alternative that I tried first was to add a `receiver: Place | null` to 
CallExpression. That works well for HIR construction, but it's then very 
difficult at codegen time to correctly reconstruct the original call: if the 
receiver and callee share part of their structure then we can transform back to 
a non-computed member expression, otherwise it has to be computed. Eg we have to 
distinguish `a.b.c[d.foo]()` from `a.b.c[a.b.c.foo]()`. Given that our target is 
high-level code, it seems reasonable to have a higher-level representation for 
these cases. 

I'm open to feedback but this feels pretty reasonable in terms of complexity / 
precision of modeling.
2023-01-17 09:40:49 -08:00
Joe Savona
4a70aa7faf Make implicit break/continue explicit in ReactiveFunction
Previously when converting from HIR -> ReactiveFunction we elided break/continue 
terminals in places where control would implicitly transfer to the 
break/continue target and therefore nothing has to be emitted. The one downside 
of this approach is that it makes scope analysis a bit trickier. We want to 
close scopes once we see an instruction id past the end of the scope's range, 
but these implicit breaks were causing us to miss some instruction ids. We 
compensated for this, but it's helpful to keep the representation explicit and 
discard these terminals later in codegen.
2023-01-17 09:40:48 -08:00
Joe Savona
2c95cdb431 Collapse BuildReactiveFunction/TreeVisitor
Collapses HIRTReeVisitor into BuildReactiveFunction, allowing us to remove the 
generic interface and simplify the code. Note that because the visitor was 
already not attempting to group instructions by scope anymore, the visitor code 
was very straightforward. This is mostly replacing calls to `appendBlock(block, 
instr)` with `block.push(instr)`.
2023-01-17 09:40:47 -08:00
Jan Kassens
ee85098019 [cleanup] remove deletedTreeCleanUpLevel feature flag (#25529)
I noticed this was an experiment concluded 16 months ago (#21679) that
this extra work is beneficial
to break up cycles leaking memory in product code.
2023-01-17 11:03:29 -05:00
Sathya Gunasekaran
39eb89f65e [hir] Use types to infer constant declarations 2023-01-16 15:34:24 +00:00
Sathya Gunasekaran
6ea0b6a42e [alias] Don't alias primitives 2023-01-16 15:34:21 +00:00
Sebastian Silbermann
4f8ffec453 Rejct toWarnDev if given callback throws (#26003)
## Summary

Should unblock https://github.com/facebook/react/pull/25970
If the callback for `toWarnDev` was `async` and threw, we didn't
ultimately reject the await Promise from the matcher. This resulted in
tests failing even though the failure was expected due to a test gate.

## How did you test this change?

- [x] tested in https://github.com/facebook/react/pull/25970 with `yarn
test --r=stable --env=development
packages/react-dom/src/__tests__/ReactDOMFizzServer-test.js --watch`
- [x] `yarn test`
- [x] CI
2023-01-15 18:57:59 +01:00
Sathya Gunasekaran
ab6a1dbbd4 [λ] Add test for nested function declaration that captures a var 2023-01-14 10:19:40 +00:00
Sathya Gunasekaran
6af9c25300 [test] Run Forget only on top level functions 2023-01-14 10:19:40 +00:00
Sathya Gunasekaran
5fa3d41b22 [λ] Make function expr tests be reactive to input
This lets us memoize more and test function expressions better
2023-01-14 10:19:39 +00:00
Sathya Gunasekaran
e8cad1584c [be] Refactor capturePureScopes to be more generic 2023-01-14 10:19:39 +00:00
Jan Kassens
0e31dd028e Remove findDOMNode www shim (#25998)
This shim is no longer needed on www, in fact I had already deleted it
there and it's currently not on www. See D42503692 which is trying to
add it back as I didn't realize this file was synced from GitHub.
2023-01-13 16:27:03 -05:00
Jan Kassens
379dd741e9 [www] set enableTrustedTypesIntegration to false (#25997)
This isn't configured to a dynamic value on www, so hardcode here to
false.
2023-01-13 16:02:24 -05:00
Sathya Gunasekaran
b1eb22d941 [be] Don't show duplicate codegen tab
The JS tab and the codegen tab are the same.
2023-01-13 16:33:04 +00:00
Sathya Gunasekaran
ddc135cf40 [be] Type CompilerPipeline as Generator 2023-01-13 16:26:09 +00:00
Sathya Gunasekaran
d25c2d0d58 [be] Make ts emit ES2015
This gives allows us to use generators without failing type checking.
2023-01-13 16:26:04 +00:00
Lauren Tan
7c65f62c27 Collect bailouts in BuildHIR::lowerStatement
Remove invariants and collect all errors
2023-01-13 16:14:07 -05:00
Lauren Tan
73f09248fb Add Result
Adds a direct translation of Rust's Result type, for later use in BuildHIR and 
possibly other passes
2023-01-12 19:35:20 -05:00
Lauren Tan
325987d744 Delete old CompilerError module
This was a carryover from the old architecture; we can remove it now to get rid 
of the indirection.
2023-01-12 19:35:19 -05:00
Andrey Lunyov
489d00fa61 [cleanup] Remove warnAboutDeprecatedLifecycles feature flag (#25992)
This `warnAboutDeprecatedLifecycles` is always true, and should be safe
to remove.
2023-01-12 16:57:14 -05:00
Joe Savona
321d7b7d00 [be] Clean up public exports
Cleans up the public exports for the package itself: 

* `parseFunctions()` was only used in playground, so this moves the definition 
there. I had to update playground's dependencies to ensure the babel version 
matched. 

* Flattens away the `HIR` const in the export, and exports just 4 functions all 
at the top-level: `run()`, `compile()`, `printHIR()`, and 
`printReactiveFunction()`. 

This will make it very easy to split the core compiler into a separate package 
from the babel plugin, though i'm not sure it's worth doing that (yet).
2023-01-12 12:16:07 -08:00
Joe Savona
bd7e19b85f Codegen is from ReactiveFunction->AST only
Other than BuildReactiveFunction (HIR -> ReactiveFunction), Codegen.ts was the 
only other remaining place that we use HIRTreeVisitor. However, we've already 
switched the compiler to use the new form of codegen, 
CodegenReactiveFunction.ts. This PR extracts the shared code from Codegen.ts 
into the latter, and deletes the unused bits of Codegen.ts which relied on the 
visitor API. 

This now frees us up to merge BuildReactiveFunction and HIRTreeVisitor, removing 
all the complexity of the visitor trait and type params. 

Note that the `ReactiveFunction` data type can represent non-reactive functions. 
So we can still compile non-React code after this change, the pipeline is `AST` 
-> (BuildHIR) -> `HIR` -> (BuildReactiveFunction) -> `ReactiveFunction` -> 
(CodegenReactiveFunction) -> `AST`. Which is the exact sequence I mapped out at 
the start of this project ;-) (happy that worked out!)
2023-01-12 11:49:47 -08:00
Joe Savona
da21e9c525 Switch to new BuildReactiveFunction passes 2023-01-12 11:06:40 -08:00
Joe Savona
a40ade1e61 Fixes, identical output in new version 2023-01-12 09:43:17 -08:00
Joe Savona
919f193934 MergeOverlappingScopes visits value block final values 2023-01-12 09:12:11 -08:00
Joe Savona
99dcf03852 AlignBlockScopes visits value block final values 2023-01-12 09:12:08 -08:00
Joe Savona
09246207c7 Value block final value has an InstrId 2023-01-12 09:12:01 -08:00
Joe Savona
df8945b684 Visit terminal operands during alignment 2023-01-12 09:11:58 -08:00
Joe Savona
9e549e9417 Fork HIRTreeVisitor to specialize it for ReactiveFunction conversion 2023-01-12 09:11:54 -08:00
Sebastian Silbermann
555ece0cd1 Don't warn about concurrently rendering contexts if we finished rendering (#22797)
Closes https://github.com/facebook/react/issues/22796
2023-01-12 13:17:15 +01:00
Joe Savona
46024acb82 MergeOverlappingReactiveScopes (rewritten against ReactiveFunction)
See the background in #982. This PR reimplements part of InferReactiveScopes, 
merging overlapping reactive scopes, but against ReactiveFunction instead of the 
HIR.
2023-01-11 14:04:51 -08:00
Joe Savona
2358d9f01f AlignReactiveScopesToBlockScopes (rewritten against ReactiveFunction)
See the background in #982. This PR reimplements part of InferReactiveScopes, 
aligning reactive scopes to block boundaries, but against ReactiveFunction 
instead of the HIR.
2023-01-11 14:04:48 -08:00
Joe Savona
87d70b9129 BuildReactiveBlocks to construct scopes in ReactiveFunction
The primary goal of this stack is to change HIRTreeVisitor to make it easier to 
handle value blocks. That's complicated by the fact that the visitor is a 
general-purpose visitor, used in several analysis passes including 
BuildReactiveFunction (which translates HIR->ReactiveFunction while also 
grouping instructions into scopes) and InferReactiveScopes (which is actually 
two passes, one to align scopes to block boundaries, one to merge overlapping 
scopes). The long-term goal then is as follows: 

1. Make BuildReactiveFunction transform HIR->ReactiveFunction but _without_ 
reactive scopes. 

2. Align scopes to block boundaries, but rewritten to operate on 
ReactiveFunction 

3. Merge overlapping scopes, again rewritten to operate on ReactiveFunction 

4. Group statements within ReactiveFunction into ReactiveScopeBlocks (today this 
occurs when constructing the ReactiveFunction). 

This PR implements 1 and 4. Because the implementation is incomplete this would 
break the whole compiler, so for now both versions are still around. By default 
compilation uses the old pipeline, but if a feature flag is enabled we use the 
new version. The plan is to incrementally fix up the new version of the passes 
in this stack, and then cutover: removing the flag and the old version of the 
passes.
2023-01-11 14:04:45 -08:00
Jan Kassens
0fce6bb498 [cleanup] remove feature flags warnAboutDefaultPropsOnFunctionComponents and warnAboutStringRefs (#25980)
These feature flags are fully rolled out and easy to clean up. Let's
remove them!
2023-01-11 12:19:46 -05:00
Jan Kassens
7002a6743e [cleanup] remove unused values from ReactFeatureFlags.www-dynamic (#25575)
These values are never imported into `ReactFeatureFlags.www.js`, so
they're unused:
- `allowConcurrentByDefault`
- `consoleManagedByDevToolsDuringStrictMode`

These values are never set in the WWW module
(https://fburl.com/code/dsb2ohv8), so they're always `undefined` on www:
- `createRootStrictEffectsByDefault`
- `enableClientRenderFallbackOnTextMismatch`
2023-01-10 23:26:01 -05:00
Tianyu Yao
fb324faf8a Test case for stack overflow in ReactFizzServer (#25971)
SSR currently stack overflows when the component tree is extremely large
2023-01-10 16:53:16 -08:00
Joe Savona
a4fc975340 Scaffolding for LogicalTerminal 2023-01-10 13:49:57 -08:00
Sathya Gunasekaran
f9ecc96bf3 [hir] Update mutable range of operands during LeaveSSA
It's not enough to only update the mutable range of the canonical id created 
instead of the phi but we need to update the mutable range of each of the 
operands of the phi as well to account for the fact that the phi could've been 
mutated later. 

The operands are updated only if the phi is mutated later. Otherwise these 
operands can be cached in their blocks. 

Fixes https://github.com/facebook/react-forget/issues/978
2023-01-11 15:17:14 +00:00
Sathya Gunasekaran
986c95bc09 [hir] Add test case for incorrect memoisation of mutated objects
In this case, x should not be cached within the if or else blocks as it is 
mutated later.
2023-01-11 15:17:13 +00:00
Sathya Gunasekaran
ed63dba739 [hir] Print MutableRange in lvalue
This is admittedly a little noisy but super valuable when debugging.
2023-01-11 15:08:37 +00:00
Sathya Gunasekaran
bbba752e98 [typer] Add type inference for Phis 2023-01-11 11:30:58 +00:00
Sathya Gunasekaran
1910ede500 [typer] Add PhiType to represent Phis 2023-01-11 11:30:58 +00:00
Sathya Gunasekaran
0c3cfbdd36 [typer] Add type to Phi 2023-01-11 11:30:57 +00:00
Jan Kassens
a48e54f2b7 [cleanup] remove old feature flag warnAboutDeprecatedLifecycles (#25978)
This feature flag was always set to true, we can easily clean it up.
2023-01-10 15:30:42 -05:00
Joe Savona
27b37341e5 Playground uses run() to automatically sync w compiler passes
Changes playground to use the modified `run()` function of the compiler, polling 
the generator and building up a Map of tabs automatically based on the passes 
that the compiler runs. This means tabs are always derived from the current 
state of the compiler and we can never forget to add a pass. 

<img width="1497" alt="Screen Shot 2023-01-10 at 11 06 03 AM" 
src="https://user-images.githubusercontent.com/6425824/211639442-da421f73-e19e-4b63-9f33-0ce5a68cceb7.png"> 

Note the inclusion of some recently added passes that weren't added to the 
playground — which was my fault but only bc i intended to ship this PR soon :-)
2023-01-10 11:05:32 -08:00
Joe Savona
7751202433 Make CompilerPipeline a generator
Turns CompilerPipeline into two functions: 

* `run()` is a generator and yields values that are a disjoint union of either 
AST/HIR/ReactiveFunction along with a name for that step. The idea is to use 
this in the playground so that it always matches the exact steps for 
compilation. I'll update playground in a follow-up. 

* `compile()` is ast in, ast out, and uses `run()` under the hood.
2023-01-10 10:15:45 -08:00
Joe Savona
f3168d020f Distinguish regular/value blocks 2023-01-10 09:37:33 -08:00
Jan Kassens
0f4a835966 Remove duplicate JSResourceReferenceImpl mock (#25976)
This mock exists in 2 directories (with identical implementation) and
Jest just picks one at random. This removes one which makes it at least
deterministic and fixes a Jest warning on startup.

It existed in these 2 places:
-
`packages/react-server-dom-relay/src/__mocks__/JSResourceReferenceImpl.js`
-
`packages/react-server-native-relay/src/__mocks__/JSResourceReferenceImpl.js`
(removed)
2023-01-10 10:32:59 -05:00
Jan Kassens
c49131669b Remove unused Flow suppressions (#25977)
These suppressions are no longer required.

Generated using:
```sh
flow/tool update-suppressions .
```
followed by adding back 1 or 2 suppressions that were only triggered in
some configurations.
2023-01-10 10:32:42 -05:00
Chris
afe6521e13 Refactor: remove useless parameter (#25923)
## Summary

I was reading the source code of `ReactFiberLane.js` and I found the
third parameter of the function markRootPinged was not used. So I think
we can remove it.

## How did you test this change?

There is no logic changed, so I think there is no need to add unit
tests. So I run `yarn test` and `yarn test --prod` locally and all tests
are passed.

Co-authored-by: Jan Kassens <jkassens@meta.com>
2023-01-09 23:25:02 -05:00
Hoikan
1253462ea4 Refactor: Reuse variable "remoteRepoDir" (#25740)
Reuse variable `remoteRepoDir` , same with `join(__dirname, 'remote-repo')`.
2023-01-09 22:59:38 -05:00
Joe Savona
dce5371763 Constant propagation/folding
Implements constant propagation/constant folding for a conservative subset of 
the language. The approach is described in detail in the comments in the file 
itself, a key note here is that this pass currently emits what looks like 
garbage: 

``` 

// input 

const x = 1; 

const y = x + 1; 

// output 

const x = 1; 

2; // <---- you'll see a bunch of lines like this 

const y = 2; 

``` 

These useless lines occur where previously there was a temporary getting 
calculated that was used later (so we saved it until it was used), but now it 
isn't used later so we just emit it in-place. Dead code elimination (DCE) can 
eliminate these and other useless statements later. 

Note that a key motivation for implementing this pass is to reduce memoization 
blocks to what is strictly required for dynamic computations. Why memoize at 
runtime when we compute at build time?
2023-01-09 15:30:20 -08:00
Sathya Gunasekaran
6f9c9cf9ea [hir] Make lambdas dependencies be a list of Places
This lets HIR understand and rename dependencies correctly.
2023-01-10 16:06:55 +00:00
Jan Kassens
34464fb16c Upgrade to Flow 0.196.3 (#25974)
After the previous changes these upgrade are easy.

- removes config options that were removed
- object index access now requires an indexer key in the type, this
cause a handful of errors that were fixed
- undefined keys error in all places, this needed a few extra
suppressions for repeated undefined identifiers.

Flow's
[CHANGELOG.md](https://github.com/facebook/flow/blob/main/Changelog.md).
2023-01-09 17:52:42 -05:00
Jan Kassens
e2424f33b3 [flow] enable exact_empty_objects (#25973)
This enables the "exact_empty_objects" setting for Flow which makes
empty objects exact instead of building up the type as properties are
added in code below. This is in preparation to Flow 191 which makes this
the default and removes the config.

More about the change in the Flow blog
[here](https://medium.com/flow-type/improved-handling-of-the-empty-object-in-flow-ead91887e40c).
2023-01-09 17:00:36 -05:00
Jan Kassens
0b4f443020 [flow] enable enforce_local_inference_annotations (#25921)
This setting is an incremental path to the next Flow version enforcing
type annotations on most functions (except some inline callbacks).

Used
```
node_modules/.bin/flow codemod annotate-functions-and-classes --write .
```
to add a majority of the types with some hand cleanup when for large
inferred objects that should just be `Fiber` or weird constructs
including `any`.

Suppressed the remaining issues.

Builds on #25918
2023-01-09 15:46:48 -05:00
Sathya Gunasekaran
346ecb27fe [hir] Gather dependencies for lambdas 2023-01-09 18:22:35 +00:00
Sathya Gunasekaran
ce7cab4eee [hir] Parse and codegen FunctionExpression 2023-01-09 18:22:32 +00:00
Joe Savona
57ea3b7e8a Merge consecutive blocks
See the previous PR for context, this PR adds a new pass to merge consecutive 
blocks.
2023-01-09 13:04:33 -08:00
Joe Savona
7a7538920e Broken test for labeled statements
When we convert a LabeledStatement to HIR we can end up emitting "consecutive" 
blocks, ie where there are two blocks such that control flow will always go from 
from one block to the other, with no other way to reach the second block but 
through the first. Example: 

```javascript 

label: { 

foo(); 

break label; 

} 

bar(); 

``` 

Converts to 

``` 

bb0: 

foo() 

goto bb1: 

bb1: 

bar(); 

... 

``` 

Ideally in this case we would merge these into a single block: 

* When debugging, the extra goto makes it look like there is conditional control 
flow when there isn't. If the code is consecutive it's easier to understand that 
if it's a single block. 

* Conversion from HIR -> AST relies on consecutive code all being in a single 
block, so this breaks codegen (we never visit the goto target since all gotos 
are assumed to be safe to convert to a break or continue). 

This PR adds a failing test case, the next PR fixes it.
2023-01-09 13:04:30 -08:00
Joe Savona
d8d5fe989c [be] Improvements to shrink/markInstructionIds 2023-01-09 10:06:03 -08:00
Joe Savona
0abc420c78 [be] Preds/phis use BlockId since blocks may change
Phi operands and Block predecessors currently use a `BasicBlock` reference 
rather than the BlockId. This diverges from other places (like terminals) where 
we use an id and not a direct object reference. Especially since blocks may get 
rewritten or pruned, it's a bit cleaner to use the block id in these places.
2023-01-09 09:22:43 -08:00
Joe Savona
3765219933 [be] Mutate HIR in-place (shrink/rpo)
Changes `shrink()` and `reversePostorderBlocks()` to modify the HIR in-place 
rather than return a new function, for consistency with all our other passes 
which mutate in-place (for performance reasons).
2023-01-09 09:13:31 -08:00
mofeiZ
0b974418c9 [Fizz] Fork Fizz instruction set for inline script and external runtime (#25862)
~~[Fizz] Duplicate completeBoundaryWithStyles to not reference globals~~

## Summary

Follow-up / cleanup PR to #25437 

- `completeBoundaryWithStylesInlineLocals` is used by the Fizz external
runtime, which bundles together all Fizz instruction functions (and is
able to reference / rename `completeBoundary` and `resourceMap` as
locals).
- `completeBoundaryWithStylesInlineGlobals` is used by the Fizz inline
script writer, which sends Fizz instruction functions on an as-needed
basis. This version needs to reference `completeBoundary($RC)` and
`resourceMap($RM)` as globals.

Ideally, Closure would take care of inlining a shared implementation,
but I couldn't figure out a zero-overhead inline due to lack of an
`@inline` compiler directive. It seems that Closure thinks that a shared
`completeBoundaryWithStyles` is too large and will always keep it as a
separate function. I've also tried currying / writing a higher order
function (`getCompleteBoundaryWithStyles`) with no luck



## How did you test this change?
- generated Fizz inline instructions should be unchanged
- bundle size for unstable_external_runtime should be slightly smaller
(due to lack of globals)
- `ReactDOMFizzServer-test.js` and `ReactDOMFloat-test.js` should be
unaffected
2023-01-06 14:28:55 -05:00
Tianyu Yao
5379b6123f Batch sync, default and continuous lanes (#25700)
<!--
  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 is the other approach for unifying default and sync lane
https://github.com/facebook/react/pull/25524.
The approach in that PR is to merge default and continuous lane into the
sync lane, and use a new field to track the priority. But there are a
couple places that field will be needed, and it is difficult to
correctly reset the field when there is no sync lane.

In this PR we take the other approach that doesn't remove any lane, but
batch them to get the behavior we want.


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

Co-authored-by: Andrew Clark <hi@andrewclark.io>
2023-01-05 15:21:35 -08:00
Ming Ye
bbf4d22113 Update import for babel-code-frame in build script (#25963)
## Summary

Updating import for babel-code-frame to use the official @babel package,
as babel-code-frame is a ghost dependency. This change is necessary to
avoid potential issues and stay up-to-date with the latest version of
@babel/code-frame, which is already declared in our project's
package.json.

## How did you test this change?
yarn test
2023-01-05 15:56:31 -05:00
Jan Kassens
b83baf63f7 Transform updates to support Flow this annotation syntax (#25918)
Flow introduced a new syntax to annotated the context type of a
function, this tries to update the rest and add 1 example usage.

- 2b1fb91a55 already added the changes
required for eslint.
- Jest transform is updated to use the recommended `hermes-parser` which
can parse current and Flow syntax and will be updated in the future.
- Rollup uses a new plugin to strip the flow types. This isn't ideal as
the npm module is deprecated in favor of using `hermes-parser`, but I
couldn't figure out how to integrate that with Rollup.
2023-01-05 15:41:49 -05:00
Mengdi Chen
2619886ac0 fix function type for flow (#25965)
These files fail CI `yarn_flow`.
2023-01-05 15:27:51 -05:00
Sathya Gunasekaran
159a3f64d0 [typer] Remove unnecessary unifier parameter 2023-01-05 13:46:55 +00:00
Sathya Gunasekaran
db3839e716 [typer] Cleanup lvalue null checking 2023-01-05 13:46:51 +00:00
Mengdi Chen
ff9f943741 [DevTools] add perf regression test page in shell (#25078)
## Summary

This PR adds a "perf regression tests" page to react-devtools-shell.
This page is meant to be used as a performance sanity check we will run
whenever we release a new version or finish a major refactor.
Similar to other pages in the shell, this page can load the inline
version of devtools and a test react app on the same page. But this page
does not load devtools automatically like other pages. Instead, it
provides a button that allows us to load devtools on-demand, so that we
can easily compare perf numbers without devtools against the numbers
with devtools.

<img width="561" alt="image"
src="https://user-images.githubusercontent.com/1001890/184059633-e4f0852c-8464-4d94-8064-1684eee626f4.png">

As a first step, this page currently only contain one test:
mount/unmount a large subtree. This is to catch perf issues that
devtools can cause on the react applications it's running on, which was
once a bug fixed in #24863.
In the future, we plan to add:
- more test apps covering different scenarios 
- perf numbers within devtools (e.g. initial load) 

## How did you test this change?

In order to show this test app can actually catch the perf regression
it's aiming at, I reverted #24863 locally. Here is the result:


https://user-images.githubusercontent.com/1001890/184059214-9c9b308c-173b-4dd7-b815-46fbd7067073.mov

As shown in the video, the time it takes to unmount the large subtree
significantly increased after DevTools is loaded.

For comparison, here is how it looks like before the fix was reverted:
<img width="452" alt="image"
src="https://user-images.githubusercontent.com/1001890/184059743-0968bc7d-4ce4-42cd-b04a-f6cbc078d4f4.png">

## about the `requestAnimationFrame` method

For this test, I used `requestAnimationFrame` to catch the time when
render and commit are done. It aligns very well with the numbers
reported by Chrome DevTools performance profiling. For example, in one
run, the numbers reported by my method are
<img width="464" alt="image"
src="https://user-images.githubusercontent.com/1001890/184060228-990a4c75-f594-411a-9f85-fa5532ec8c37.png">
They are very close to the numbers reported by Chrome profiling:
<img width="456" alt="image"
src="https://user-images.githubusercontent.com/1001890/184060355-a15d1ec5-c296-4016-9c83-03e761f387e3.png">

<img width="354" alt="image"
src="https://user-images.githubusercontent.com/1001890/184060375-19029010-3aed-4a23-890e-397cdba86d9e.png">

`<Profiler>` is not able to catch this issue here.

If you are aware of a better way to do this, please kindly share with
me.
2023-01-04 17:31:13 -05:00
Sathya Gunasekaran
cccec0e5b2 [be] Don't use nested imports 2023-01-04 21:11:40 +00:00
Sathya Gunasekaran
b8fd4680b1 [hir] Move inference passes to separate folder 2023-01-04 21:11:37 +00:00
Sathya Gunasekaran
d187fff414 [typer] Move type inference to a separate folder 2023-01-04 21:11:33 +00:00
Andrew Clark
c2d6552079 Unify use and renderDidSuspendDelayIfPossible implementations (#25922)
When unwrapping a promise with `use`, we sometimes suspend the work loop
from rendering anything else until the data has resolved. This is
different from how Suspense works in the old throw-a-promise world,
where rather than suspend rendering midway through the render phase, we
prepare a fallback and block the commit at the end, if necessary;
however, the logic for determining whether it's OK to block is the same.
The implementation is only incidentally different because it happens in
two different parts of the code. This means for `use`, we end up doing
the same checks twice, which is wasteful in terms of computation, but
also introduces a risk that the logic will accidentally diverge.

This unifies the implementation by moving it into the SuspenseContext
module. Most of the logic for deciding whether to suspend is already
performed in the begin phase of SuspenseComponent, so it makes sense to
store that information on the stack rather than recompute it on demand.

The way I've chosen to model this is to track whether the work loop is
rendering inside the "shell" of the tree. The shell is defined as the
part of the tree that's visible in the current UI. Once we enter a new
Suspense boundary (or a hidden Offscreen boundary, which acts a Suspense
boundary), we're no longer in the shell. This is already how Suspense
behavior was modeled in terms of UX, so using this concept directly in
the implementation turns out to result in less code than before.

For the most part, this is purely an internal refactor, though it does
fix a bug in the `use` implementation related to nested Suspense
boundaries. I wouldn't be surprised if it happens to fix other bugs that
we haven't yet discovered, especially around Offscreen. I'll add more
tests as I think of them.
2023-01-04 15:11:56 -05:00
Andrew Clark
48274a43aa Remove vestigial Suspense batching logic (#25861)
This code was originally added in the old ExpirationTime implementation
of Suspense. The idea is that if multiple updates suspend inside the
same Suspense boundary, and both of them resolve, we should render both
results in the same batch, to reduce jank.

This was an incomplete idea, though. We later discovered a stronger
requirement — once we show a fallback, we cannot fill in that fallback
without completing _all_ the updates that were previously skipped over.
Otherwise you get tearing. This was fixed by #18411, then we discovered
additional related flaws that were addressed in #24685. See those PR
descriptions for additional context.

So I believe this older code is no longer necessary.
2023-01-04 14:50:00 -05:00
Sathya Gunasekaran
efac190973 [typer] Make type inference more conservative
It's not entirely correct to infer arguments to (not) equals operator as 
primitives.
2023-01-04 18:09:25 +00:00
Sathya Gunasekaran
09bdf3553f [hir] Remove unreachable fallthroughs separately from shrink
shrink visits all the fallthroughs even if they are unreachable so this isn't 
the right place to prune unreachable blocks. 

This PR moves pruning into a separate pass.
2023-01-04 18:09:24 +00:00
Joe Savona
e4642326d3 Make LValue non-nullable in HIR 2023-01-04 09:51:17 -08:00
Joe Savona
29bb3f55a3 Rename IndexLoad/Store to ComputedLoad/Store
Hopefully a more clear name, these values correspond to computed properties.
2023-01-03 17:03:45 -08:00
Joe Savona
bd99d06a5f Support computed property access/assignment
Supports computed properties (as LHS and RHS) correctly. Previously we only 
handled member expressions where the property was an identifier, and would 
incorrect treat `a[b]` the same as `a.b`. Now we correctly distinguish these and 
convert `a[b]` as an IndexLoad and `a.b` as a PropertyLoad. Similar for 
assignment, `a[b] = c` is an IndexStore. For both IndexLoad and IndexStore we 
lower the property to a Place first.
2023-01-03 16:59:41 -08:00
Joe Savona
ab150bd9d1 Object and array destructuring support in declaration/assignment
Implements support for array and object de-structuring in variable declarations 
and assignment expressions. Note that the code currently makes the overly 
optimistic assumption that the RHS is an array or object that can be safely 
indexed into. The correct representation would instead treat the RHS as possibly 
iterable, but we need to consider the appropriate representation. I think it's 
worth landing a first optimistic pass and we can iterate forward, this helps 
make it more clear what the ideal representation would have to be and should 
make a bunch of examples work. It also allows us to experiment with 
representations of, and handling for, scope dependencies that involve computed 
property access.
2023-01-03 16:59:38 -08:00
Joe Savona
45b3bd4899 Foundation for IndexStore/IndexLoad (no lowering)
Adds new types for IndexLoad/IndexStore (renamed later in the stack to 
ComputedLoad/ComputedStore) which will be used to represent computed property 
access/update. The actual lowering to use these is later in the stack.
2023-01-03 16:59:35 -08:00
Joe Savona
c2b2df0d17 Remove unused Place.memberPath
After the previous PR to change the scope dependency representation, 
`Place.memberPath` is now completely unused, this PR deletes that field and all 
references. Rejoice!
2023-01-03 15:34:42 -08:00
Joe Savona
c69cba357f Use distinct type for scope dependencies
This is a pre-req to deleting the `Place.memberPath` field. We no longer need 
memberPath in the HIR now that we have PropertyStore and PropertyLoad. However, 
scope dependencies use memberPath to track the precise fields that a computation 
depends upon. This PR changes scopes dependencies to use a new 
`ReactiveScopeDependency` type (Place + optional path), which allows the next PR 
to remove `Place.memberPath`.
2023-01-03 15:34:39 -08:00
Joe Savona
26cd435c7d Support chained assignment expressions
Fixes codegen for chained assignment expressions. Previously each intermediate 
assignment would be generated independently _in addition_ to the final chained 
expression being emitted. We now emit a single chained expression, almost 
exactly matching the input except for expanding from `x += 1` into `x = x + 1`. 

There are two key changes: 

* Ensuring that assignment expressions always generate an lvalue, which is 
necessary for alias analysis to kick in, since it relies on the effect of the 
lvalue to know where to look for aliasing. 

* The above makes codegen think the entire assignment expression value is a 
temporary that can be emitted later, but that isn't true. The new 
PruneTemporaryLValue pass nulls out lvalues that are never read later, ensuring 
that codegen can eagerly emit the value instead of saving it as a temporary.
2023-01-03 14:11:04 -08:00
Steven
de7d1c9071 Add fetchPriority to <img> and <link> (#25927)
<!--
  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

- Fixes https://github.com/facebook/react/issues/25682

## How did you test this change?

I tried this but it didn't work
```
yarn build --type=UMD_DEV react/index,react-dom && cd fixtures/attribute-behavior && yarn install && yarn start
```

Co-authored-by: eps1lon <silbermann.sebastian@gmail.com>
2022-12-23 14:31:27 -05:00
satelllte
81d4ee9ca5 reconciler docs: fix small typo - "mode" (instead of "node") (#25863) 2022-12-23 13:22:55 +01:00
KZ-Lucas
726a40eded CHANGELOG.md Change parentheses position (#25762) 2022-12-23 12:43:06 +01:00
Joe Savona
0a6af823b3 Lowering for PropertyStore
Converts assignment expressions where the lvalue is a MemberExpression to use 
PropertyStore, rather than creating an lvalue with a member path. The net effect 
is that lvalue will always have a null member path. 

There are two main cases: 

* `x.y = <value>`. We lower <value> to a Place, lower the object of the member 
expression to a place (`object)` create a temporary Place for the result of the 
assignment, and then create a `PropertyStore <object>, "<property>", <value>`. 

* `x.y += <value>` (and similar update-in-place operands). We extract the object 
of the member expression, read the current value via a PropertyLoad, compute the 
updated value, and store it back with a PropertyStore (each of these goes into 
its own temporary).
2022-12-22 15:04:57 -08:00
Joe Savona
c7a84fc033 Foundation for PropertyStore (no lowering yet)
Adds a `InstructionValue::PropertyStore` variant and the minimal necessary 
handling across the passes to get things to compile. Lowering is in the next PR.
2022-12-22 14:51:27 -08:00
lauren
7ee40764e6 Revert "[nocommit] Run test262 on this PR to verify it works for real…
…-realsies" 

This reverts commit 3c8700cbc7502e56cca8d4bb77a08e1ee747c166. 

I'm not sure how this happened but I accidentally hit up + enter on a previous 
`ghstack land` command for a different stack and it landed this one. 
Infuriating.
2022-12-22 17:53:59 -05:00
Lauren Tan
2d4c2094d8 [@nocommit] Run test262 on this PR to verify it works for real-realsies
final v2
2022-12-22 17:40:20 -05:00
Lauren Tan
5e0dba9012 [test262] Always return a pseudo Error object
For unknown reasons I didn't have the energy to dig into, some Babel Error 
objects can't be written to so despite formatting the error message, the 
original one would still be used. To get around this I'm just constructing a 
fake object with a `name` and `message` so the correctly formatted messages are 
used.
2022-12-22 17:40:18 -05:00
Joe Savona
74a0d54db2 Account for stores that can occur in object/array literals 2022-12-22 14:00:49 -08:00
Joe Savona
1fd4bad525 RHS member expression converts to PropertyLoad
This is an incremental step to removing `Place.memberPath`. This PR changes how 
we handle MemberExpressions in rvalue position, converting to a new 
`PropertyLoad` InstructionValue variant. Example: 

``` 

let x = a.b; 

x.y = b.c; 

=> 

Const tmp1 = PropertyLoad a, 'b'; 

Const x = Place tmp1; 

Const tmp2 = PropertyLoad b, 'c'; 

Reassign x.y = tmp2 

``` 

That we already recently made a chance to ensure that _if_ the lvalue is a 
member expression, that we convert the RHS to a Place. So although `x.y = b.c` 
could technically be lowered to a single instruction (with the`b.c` as a 
PropertyLoad), we force this to a temporary to ensure that we can independently 
memoize the RHS value. 

The net result is that the following combinations are possible: 

* `x = y`, lvalue identifier, rvalue identifier 

* `x.y = y` lvalue member path, rvalue identifier 

* `x = y.z` lvalue identifier, rvalue property load 

As noted above, `x.y = a.b` no longer occurs (and there's an invariant for this 
in one of the passes). 

A follow-up PR will add a PropertyStore instruction so that we can remove member 
paths in lvalue position too.
2022-12-22 14:00:48 -08:00
Lauren Tan
8246956331 Force DisjointSet.union to always pick a root
@josephsavona had the intuition that we were picking the wrong root in the 
previous infinite loop test case, so the fix for this is to force a root to 
always be picked. This works because `find` implements path compression (if a <- 
b and b <- c, then we can just point a <- c to "flatten" the tree which makes 
subsequent `find` operations more efficient since we don't have to follow the 
ancestor chain each time), so we're forcing all those unions to pick one parent. 

From some googling it looks like the traditional way to implement union is to 
call `find` so this should be the "right" way to fix it (?). 

I'm also adding a basic unit test for DisjointSet, I think we could revisit 
later and see if property testing is worth it but for now I mainly wanted to 
capture the regression test as a unit test.
2022-12-22 16:16:16 -05:00
Lauren Tan
311e5fdf69 Add infinite loop test case
Discovered this by accident modifying Joe's playground example. This seemed to 
be triggered in inferReactiveScopeVariables when iterating over the DisjointSet 
of scopeIdentifiers. In particular this test case contains a cycle and 
DisjointSet.find would never terminate.
2022-12-22 16:16:16 -05:00
Lauren Tan
75fc20981a Fix test262 for realsies
The github action was exceeding maximum allowed memory size because we were no 
longer grouping messages correctly prior to formatting them in the script. I 
think these were introduced when we integrated the Babel plugin into the 
preprocessor. This PR strips out filenames from the message so they can be 
grouped together again. Also added some light comments 

Test plan: manually ran `scripts/test262.sh` and verified that the JSON was 
grouped together correctly
2022-12-22 13:12:08 -05:00
Joe Savona
47e20c3f66 Expect files are input/ouput code only (no HIR/scopes) 2022-12-22 10:23:14 -08:00
Joe Savona
4385a283e4 Ensure non-conflicting names in output, wo suffixes by default 2022-12-22 10:23:11 -08:00
Andrew Clark
5fcf1a4b4c Bugfix: Synchronous ping during render phase sometimes unwinds the stack, leading to crash (#25851)
I found this bug when working on a different task.

`pingSuspendedRoot` sometimes calls `prepareFreshStack` to interupt the
work-in-progress tree and force a restart from the root. The idea is
that if the current render is already in a state where it be blocked
from committing, and there's new data that could unblock it, we might as
well restart from the beginning.

The problem is that this is only safe to do if `pingSuspendedRoot` is
called from a non-React task, like an event handler or a microtask.
While this is usually the case, it's entirely possible for a thenable to
resolve (i.e. to call `pingSuspendedRoot`) synchronously while the
render phase is already executing. If that happens, and work loop
attempts to unwind the stack, it causes the render phase to crash.
2022-12-21 23:55:49 -05:00
Lauren Tan
b5623abf74 [ez] Update test262 submodule
`git submodule update --remote`
2022-12-21 16:07:11 -05:00
Lauren Tan
003a1772ab Fix broken import path in test262-preprocessor
Previously we weren't ever clearing the `dist` directory so there were likely 
some vestigial files left over from previous builds that might have confused the 
import path. This commit fixes the import path and also deletes the `dist` 
directory on every build to ensure a clean slate.
2022-12-21 16:04:29 -05:00
Sathya Gunasekaran
f72397b5c1 [typer] Infer JSXText as a Primitive 2022-12-21 21:13:58 +00:00
Sathya Gunasekaran
6ba2117227 [hir] Use type inference for Effect.Store refinement
Only identifiers of type object can be safely refined to Effect.Store, default 
unknown identifiers to Effect.Mutate.
2022-12-21 21:13:58 +00:00
Sathya Gunasekaran
ff29264050 [typer] Remove type inference of fields
Given that our type inference needs to be very conservative, there's not a lot 
of benefit to having such fine grained type inference. 

In the future, we can use type information from flow/ts for inference.
2022-12-21 21:13:57 +00:00
Sathya Gunasekaran
b59f9dd561 [hir] Remove unused code from InferAlias
For now, we've decided to punt on super fine grained aliasing of fields (ie, 
mutating x.y shouldn't mutate x.z or it's aliases). 

This PR removes the code that tracks the aliases of each field. We can re-add 
this when we revisit this functionality. 

For the rest of the field aliasing, most of it has been replaced by 
InferAliasForStores.
2022-12-21 21:13:57 +00:00
Joe Savona
8c920cfa90 Factor out assignment expression cases
Splits handling of simple assignment updates (`=`) from update-assignments (`+=` 
etc). This unblocks starting to support destructuring for the simple case in the 
subsequent PR.
2022-12-21 10:02:06 -08:00
Joe Savona
69e34270a2 Factor out assignment lowering to allow generating multiple instructions 2022-12-21 10:02:06 -08:00
Joe Savona
836211a549 Prep for destructuring, factor out lowerIdentifier() 2022-12-20 16:57:13 -08:00
Joe Savona
079cfe68bf Fix test262 preprocessor
The test262 preprocessor was correctly running forget against all the functions 
in each test file, but it was incorrectly transforming the file contents 
overall. Previously we swapped the contents of the file for the transformed 
output of the last function, now we use the babel plugin to rewrite functions in 
place and keep the rest of the file intact. 

Of course, the tests that failed before still fail. But when we fix them the 
tests will work now.
2022-12-20 16:27:11 -08:00
Joe Savona
bc0787fefb More precise handling of const/reassign in ssa form
Addressed a TODO from the previous PR. When we enter SSA form, when we rewrite 
variable reassignments we currently change the identifier but leave the kind of 
the lvalue alone; technically we should convert from Reassign to Const. After 
doing that, it's easier to correctly update when we leave SSA form, we can 
convert just a subset back into let/reassign (but leave most things alone as 
const).
2022-12-20 16:09:59 -08:00
Joe Savona
178bde3495 Run LeaveSSA prior to analyzing reactive scopes
Reorders LeaveSSA so that it runs before we begin evaluating reactive scopes. 
Note that reactive scopes must span the full construction of each variable — for 
variables with a phi, this must span the declaration and all assignments of the 
phi operands. And that's exactly what the new LeaveSSA does! LeaveSSA removes 
phi nodes and ensure that all versions of a variable which flow into a phi have 
been assigned a single canonical identifier (with an appropriate mutable range). 

This PR includes this and some related changes: 

* Reorders the pass 

* Changes hir-test to print the final HIR, eg just prior to codegen 

* Teaches LeaveSSA to update the mutable range of the canonical identifiers it 
assigns, based on the min/max of the variables assigned.
2022-12-20 15:58:03 -08:00
Sathya Gunasekaran
5388839357 [hir] Generalize alias analysis for Effect.Store
Rather than special casing for field stores, look for Effect.Store to alias 
fields. 

In the future, this will be extended to other constructs like Array#push.
2022-12-21 12:04:02 +00:00
Sathya Gunasekaran
afdd2cb910 [hir] Add Effect.Store
Effect.Store is exactly like Effect.Mutate, the only difference is that Store 
aliases one into a another value. 

There is no practical difference between Effect.Mutate and Effect.Store 
currently.
2022-12-21 12:04:01 +00:00
Jan Kassens
2b1fb91a55 ESLint upgrade to use hermes-eslint (#25915)
Hermes parser is the preferred parser for Flow code going forward. We
need to upgrade to this parser to support new Flow syntax like function
`this` context type annotations or `ObjectType['prop']` syntax.

Unfortunately, there's quite a few upgrades here to make it work somehow
(dependencies between the changes)

- ~Upgrade `eslint` to `8.*`~ reverted this as the React eslint plugin
tests depend on the older version and there's a [yarn
bug](https://github.com/yarnpkg/yarn/issues/6285) that prevents
`devDependencies` and `peerDependencies` to different versions.
- Remove `eslint-config-fbjs` preset dependency and inline the rules,
imho this makes it a lot clearer what the rules are.
- Remove the turned off `jsx-a11y/*` rules and it's dependency instead
of inlining those from the `fbjs` config.
- Update parser and dependency from `babel-eslint` to `hermes-eslint`.
- `ft-flow/no-unused-expressions` rule replaces `no-unused-expressions`
which now allows standalone type asserts, e.g. `(foo: number);`
- Bunch of globals added to the eslint config
- Disabled `no-redeclare`, seems like the eslint upgrade started making
this more precise and warn against re-defined globals like
`__EXPERIMENTAL__` (in rollup scripts) or `fetch` (when importing fetch
from node-fetch).
- Minor lint fixes like duplicate keys in objects.
2022-12-20 14:27:01 -05:00
Sathya Gunasekaran
69fbdfc7cd [typer] Add inferTypes pass to playground 2022-12-20 14:55:56 +00:00
Sathya Gunasekaran
c130bcc9c2 [typer] Use opaque TypeId to number types 2022-12-20 14:55:52 +00:00
Sathya Gunasekaran
549f5a4af6 [typer] Return a narrow-er type from makeType 2022-12-20 14:55:48 +00:00
Joe Savona
828fd81be3 Add new pass to playground 2022-12-20 12:16:34 -08:00
Joe Savona
af91a7ab86 Ensure member path assignments memoize independently
Assignment expressions to a member path are a special case because they're the 
only place where a value isn't assigned to a (possibly temporary) variable, 
which is our unit of memoization. #901 demonstrated how this can lead to values 
that can't be independently memoized: 

```javascript 

const x = {a: a} 

x.y = [b, c]; // array recomputed w `x`, even if only `a` changed 

``` 

This PR ensures that assignment expressions where the LHS is a member path lower 
the RHS to a Place. That means the above example is handled as if you wrote: 

```javascript 

const x = {a: a}; 

const tmp1 = [b, c]; 

x.y = tmp1; 

``` 

And we independently memoize the temporary.
2022-12-20 11:06:08 -08:00
Joe Savona
cedaee5b03 Codegen for scopes without dependencies
Completes a todo for the `if` condition of scopes without any inputs. In this 
case since there are no inputs we can check for changes, we check if the first 
_output_ cache slot is set to the sentinel. 

For this to work we need to ensure that all scopes have at least one output, 
which isn't currently the case. Dead code can produce output-less sentinels. So 
this PR also adds a pass to find scopes w/o any outputs and convert them to 
regular blocks. We could in theory also just delete them, but for now let's be 
more conservative. This is something we'd want to highlight as a diagnostic in 
an IDE, though existing dead code linters would almost certainly find this case 
too.
2022-12-20 11:06:07 -08:00
Lauren Tan
ae8f9066dd Fix invalid import path in test262-preprocessor 2022-12-20 11:42:51 -05:00
Lauren Tan
2721d2a0d9 Remove compiler flags
Remove our existing compiler flags since they were only being used for 
enabling/disabling passes to aid debugging and to simplify in preparation for 
the upcoming work on diagnostics and bailouts. Additionally with the new 
playground tabs disabling passes has become less necessary. In the future when 
we have actual compiler flags (eg tweaking optimization levels) we can add this 
back. 

I opted to keep the existing `CompilerResult` return value instead of just 
returning the optimized AST as we're still using `scopes` in our test fixtures.
2022-12-20 11:42:51 -05:00
Lauren Tan
7cf8e9ac42 [ez] Fixup missing passes in test262-preprocessor 2022-12-20 11:13:05 -05:00
Lauren Tan
9390e969e2 mv src/HIR/Pipeline src/CompilerPipeline
Small reorganization to move Pipeline out of HIR since it's a compiler module. 
It used to make sense before to be in HIR since the old architecture was the 
still the primary, but no longer!
2022-12-20 11:13:05 -05:00
Sathya Gunasekaran
f1af022be1 [typer] Fix objectTypeEquals 2022-12-20 13:38:09 +00:00
Sathya Gunasekaran
6f06b0e08a [typer] Reuse PolyType objects 2022-12-20 13:38:08 +00:00
Sathya Gunasekaran
2c3e572566 [typer] Be more conservative with function type inference
It's not safe to infer types of arguments and return values because Javascript 
is so polymorphic. Instead just infer the type of the callee for non methods. 

Interestingly, even this is not conservative enough for JavaScript because Proxy 
can also be callable. But I think for our use cases we will treat Proxy and 
Functions similarly (they're all just objects) so it's ok.
2022-12-20 13:38:07 +00:00
Joe Savona
9207607d37 Delete old architecture
Thanks old architecture! We learned a lot about what does and doesn't work via 
this POC, but it's time to move forward w the ~~new~~ current architecture.
2022-12-19 10:04:54 -08:00
Joe Savona
d9b9554948 Remove old architecture from playground
Removes the old architecture from the playground. Next step deletion.
2022-12-19 10:00:16 -08:00
Joe Savona
5db523a98a Fix bug with scope output analysis for nested scopes
When collecting the output of each scope I was checking to see whether each 
operand was being used after the end of the _current_ scope. What we really want 
to be checking is whether the operand is used after _the scope in which it's 
defined_. Those are the same thing when there is no nesting, involved, so the 
previous logic worked for most examples. 

It isn't super easy to tell when if the operand's scope has ended, because we 
don't always know what the "current" InstructionId is inside a ReactiveFunction. 
And that in turn isn't quite so easy to change, because of some edge cases like 
break statements that we synthesize. The solution here is to track the set of 
active scopes, and if an operand is used and its scope is not active then voila, 
it's scope must have completed and its an output.
2022-12-18 12:14:41 -08:00
Joe Savona
d649940c27 Test case showing lack of independent memoization of object properties 2022-12-18 12:14:38 -08:00
Joe Savona
05d1fe94f9 [be] Split files into directories
Moves _some_ files from HIR into new top-level directories. To not make 
@gsathya's life a pain I left the files he's touching alone, but I moved some 
others. My intent is to have something like this: 

* Babel/ - code for the Babel plugin, though ideally this actually gets split 
into a separate package and the compiler itself is AST in, AST out w no Babel 
dep. 

* HIR/ - the core HIRFunction, HIR and related data types, plus the HIR 
construction and printing, HIR visitors. 

* Inference/ - the core inference passes that operate on the HIR, including type 
inference, reference effects, alias analysis, mutable range analysis, etc. I'll 
let @gsathya  move these files when at a good stopping point. 

* ReactiveScopes/ - inference relating to reactive scopes, 
constructing/printing/codegenning ReactiveFunction 

* SSA/ - enter/leave SSA and eliminate redundant phis 

* Utils/ - every project needs a place to put stuff that doesn't fit into the 
other categories, this is ours. 

This leaves just index.ts at the top level, and overall feels pretty tidy. Not 
too tedious to figure out where anything goes, hopefully.
2022-12-16 17:25:11 -08:00
Joe Savona
6053703dbb add missing pass to playground
It's pretty tedious to keep the playground in sync w `Pipeline` — we need some 
abstraction so we can write the sequence of passes once and reuse it (while 
inspecting intermediate states).
2022-12-16 09:41:47 -08:00
Joe Savona
075cdcec9e [be] Move old compiler to separate package 2022-12-16 09:33:07 -08:00
Joe Savona
7a29405d68 [be] Rename some types for ReactiveFunction 2022-12-16 08:45:46 -08:00
Tianyu Yao
fabef7a6b7 Resubmit Add HydrationSyncLane (#25878)
Depends on #25876

Resubmit #25711 again(previously reverted in #25812), and added the fix
for unwinding in selective hydration during a hydration on the sync
lane.
2022-12-15 12:23:53 -08:00
Tianyu Yao
7efa9e5970 Fix unwinding context during selective hydration (#25876)
This PR includes the previously reverted #25695 and #25754, and the fix
for the regression test added in #25867.


Tested internally with a previous failed test,  and it's passing now.

Co-authored-by: Andrew Clark <git@andrewclark.io>
2022-12-15 11:47:07 -08:00
Sathya Gunasekaran
7ab0303822 [playground] Increase min width of output tabs 2022-12-15 18:38:06 +00:00
Sathya Gunasekaran
25fb36c966 [playground] Make gutter smaller in the output tabs 2022-12-15 18:38:05 +00:00
Sathya Gunasekaran
9e9dba90eb [playground] Make input tab smaller 2022-12-15 18:38:05 +00:00
Sathya Gunasekaran
78d976302f [playground] Remove mobile support
This is mostly unused and there's just not enough benefit for now. We can re-add 
this if folks start using this site on mobile. Removing now to simplify the 
codebase.
2022-12-15 18:38:04 +00:00
Sathya Gunasekaran
c4f16fce5c [playground] Remove handlebar to resize input
The only use of this is to resize the input tab immediately to be smaller. 
Instead, a follow on PR will just make the input tab smaller by default.
2022-12-15 18:38:03 +00:00
Joe Savona
6efac28677 Prune unnecessary labels in output 2022-12-14 16:42:54 -08:00
Joe Savona
de3952352b Use new codegen in playground
Switches to the new codegen with memoization applied, and puts the JS tab first 
to make it easier to look at the input/output 

side by side.
2022-12-14 16:23:41 -08:00
Joe Savona
575db2b4ea [wip] Codegen with memoization applied
Updates the ReactiveFunction-based codegen from the previous PR to emit 
memoization code for each scope. This is currently naive and has some bugs, but 
it gets the idea across. The core logic is straightforward at this point, all 
the hard work is in earlier passes: 

* Compute one change variable per scope dependency, eg `const c_0 = $[0] === 
maxItems` 

* Generate one `let` binding for each scope output 

* Generate an if block where the test is if any of the change variables are true 
(`||` them together) 

* Generate the consequent block with the original code block, plus statements to 
save dependencies and outputs to their cache slots 

* Generate the alternate block to populate the scope outputs from their cached 
values 

## Todos 

A few things don't quite work yet: 

* Codegen is designed to avoid emitting variables for temporary values, but 
that's causing a few values to sort of disappear n the examples, or get emitted 
twice. There are a variety of ways to achieve this but we'll need to ensure that 
this category of values gets assigned to a variable and then reference the 
variable. This is more involved. 

* Scopes can end up with zero dependencies, in which case we should check that 
the first output cache is initialized. This one is more straightforward. 

* If there are early returns, we don't record that they occurred and replay them 
in the `else` branch for each scope. We know the algorithm though so i'm okay 
delaying that for now.
2022-12-14 16:12:36 -08:00
Joe Savona
70a7d5f41e Codegen from ReactiveFunction (no memoization yet)
Currently codegen operates from HIR using a tree visitor, but for scope 
construction we're converting the HIR (CFG) into a ReactiveFunction (AST-like). 
Our original idea for codegen was that we would convert the ReactiveFunction 
back to HIR, and then codegen from there. However, the ReactiveFunction is 
already in tree form...which makes it very straightforward to generate code 
from. 

So this PR implements codegen from ReactiveFunction. The output is _identical_ 
thanks in large part to reusing as much logic from Codegen.ts as possible. The 
next PR will add memoization logic.
2022-12-14 14:54:37 -08:00
Joe Savona
7199229cb4 Record scope outputs
While we're collecting scope dependencies, we have the exact right information 
to record scope outputs. These are variables that need to be defined outside of 
the scope and populated by recomputing (on change) or via the cached value (if 
no change).
2022-12-14 13:27:20 -08:00
Sebastian Markbåge
84a0a171ea Rename experimental useEvent to useEffectEvent (#25881)
We originally had grand plans for using this Event concept for more but
now it's only meant to be used in combination with effects.

It's an Event in the FRP terms, that is triggered from an Effect.
Technically it can also be from another function that itself is
triggered from an existing side-effect but that's kind of an advanced
case.

The canonical case is an effect that triggers an event:

```js
const onHappened = useEffectEvent(() => ...);
useEffect(() => {
  onHappened();
}, []);
```
2022-12-14 15:08:29 -05:00
Joe Savona
459263b763 Refactor reactive scope representation 2022-12-14 12:07:50 -08:00
Joe Savona
552fe1878b Cleanup previous dep collection 2022-12-14 08:42:39 -08:00
Joe Savona
dd1ff4dc30 Combine dependency collection and propagation, more precise collection
I realized that properly propagating scope dependencies requires reusing the 
same logic as dependency collection itself: a dependency of an inner scope 
should only be propagated upward if the dependency was declared before the outer 
scope, for example. So this PR reimplements dependency collection in the 
propagation pass. 

At the same time I made a few other improvements: 

* Don't report dependencies that are "constant". This is a bit simplistic for 
now, we can use a more advanced analysis later. 

* Try to avoid creating duplicate dependencies. 

This addresses the todo from the previous PR (flattening scopes in loops) since 
now we don't need to compute deps until after that runs. As a follow-up i'll 
remove the existing dependency collection.
2022-12-14 08:42:39 -08:00
Joe Savona
d909ae0434 Fix scope dependency collection ordering bug
Dependency collection has to visit the instruction id first before evaluating 
the instruction, in order to completely any scopes that would end at that 
instruction. Note the removed dependencies that don't appear within the scopes.
2022-12-14 08:42:38 -08:00
Joe Savona
972caf5bf1 Propagate scope dependencies upwards
Initial, partial implementation of dependency propagation. This lays the 
groundwork, #876 completes it after some other fixes this uncovered.
2022-12-14 08:42:37 -08:00
Joe Savona
5f3dc0b6c7 Flatten scopes within loops
We can't independently memoize values created within a loop, so this pass 
flattens scopes within loops. Right now this just flattens the scope away 
without propagating any dependency (or output) information, follow-ups will 
extend it to do that.
2022-12-14 08:42:37 -08:00
Joe Savona
be9b6356df cleanup unnecessary code from BuildReactiveFunction 2022-12-14 08:42:36 -08:00
Joe Savona
189f48ee0a Dont create scopes for consts w primitive values
We don't need to create scopes for primitive values that are never reassigned. 
The actual rules are more complex — we could choose to skip creating scopes for 
values that don't allocate — but this simple heuristic is good for now.
2022-12-14 08:42:36 -08:00
Joe Savona
73ad571c6b Add invariant for problematic LeaveSSA case
The new LeaveSSA looks ahead to the phis of fallback blocks. However, HIR can 
sometimes have multiple blocks with the same fallthrough (totally fine), so this 
diff clears the phis of fallbacks as they are reached to avoid reprocessing 
them. This caused a previously incorrect case to now fail, yay.
2022-12-14 08:42:35 -08:00
Sathya Gunasekaran
4b66531237 [test] Remove mermaid diagrams from test output 2022-12-14 15:47:13 +00:00
Sathya Gunasekaran
9bfad00410 [type-infer] Implement Hindley Milner type inference
Based on the lambda calculus of ForgetScript, this infers the types of 
primitives, objects and functions.
2022-12-14 15:36:32 +00:00
Joseph Savona
6e52cc3f38 Construct nested reactive scopes
There are a bunch of ways we can go about converting from the input HIR into a 
final form that has the preamble inserted and memoized blocks of code wrapped 
with change detection and caching. This is just one way, it might not be the 
ideal way. In any case, this pass converts HIRFunction -> ReactiveFunction. The 
latter is a recursive (tree-shaped) data structure that attempts to represent 
blocks each of composed of scopes or instructions, where scopes are themselves 
composed of blocks etc. The idea is a) this makes it easy to visualize the 
structure and check that the scopes and their dependencies are correct and b) 
this is a really nice form for adding the memoization code. We can convert from 
a ReactiveFunction back to an HIRFunction, wrapping each scope in the 
appropriate if checks and caching. 

## Example 

Consider the following example, which has 2 main scopes: an outer one for `x` 
and an inner one in the consequent for `y`: 

```javascript 

function foo(a, b, c) { 

const x = []; 

if (a) { 

const y = []; 

y.push(b); 

x.push(<div>{y}</div>); 

} else { 

x.push(c); 

} 

return x; 

} 

``` 

## Output 

The new builder constructs a ReactiveFunction for this example along the lines 
of the following (note that inputs are always empty bc we don't collect those 
yet): 

``` 

{ 

scope @0 [1:11] inputs=[]  { 

[1] Const mutate x$11_@0[1:11] = Array [] 

[2] if (read a$8) { 

scope @1 [3:5] inputs=[] { 

[3] Const mutate y$12_@1[3:5] = Array [] 

[4] Call mutate y$12_@1.push(read b$9) 

} 

scope @2 [5:6] inputs=[] { 

[5] Const mutate $13_@2 = "div" 

} 

scope @3 [6:7] inputs=[] { 

[6] Const mutate $14_@3 = JSX <read $13_@2>{freeze y$12_@1}</read $13_@2> 

} 

[7] Call mutate x$11_@0.push(read $14_@3) 

} else { 

[9] Call mutate x$11_@0.push(read c$10) 

} 

} 

[10] return x$11; 

} 

``` 

This shows the hierarchy: there's an outer scope, `@0` to compute `x` (the first 
scope), then within the if consequent there's another scope, `@1`, to compute 
`y`. We have some technically extraneous scopes to compute the JSX element; that 
can be cleaned up with a bit more refinement. 

With this structure — and the inputs and outputs of each scope filled in — we 
can convert to code in a straightforward manner. Each scope turns into a block 
along the lines of the following: 

(note here we use strings to index the cache, in reality these would be ints) 

```javascript 

// one change variable pet input: 

let c_a = a !== $['a']; 

... 

// one variable for each output: 

let x; 

... 

// if (changed) { recompute } else { use-cache } 

if (c_a || ... ) { 

x = ...; 

// one assignment per output 

$['x'] = x; 

// update cache per input 

$['a'] = a; 

... 

} else { 

// one assignment per output 

x = $['x']; 

... 

} 

```
2022-12-13 11:53:42 -08:00
Jan Kassens
4dda96a407 [react-www] remove forked bundle (#25866)
*NOTE:* re-apply of 645ae2686b now that
www is updated.

The `enableNewReconciler` was gone with
420f0b7fa1, this removes the bundle
config.
2022-12-13 10:44:48 -05:00
Sathya Gunasekaran
2df0c832f5 [be] Remove stale TODO
Fixed in fa1ae5de5be84dd25263845fb43157d77c0826aa
2022-12-13 09:28:00 +00:00
Sathya Gunasekaran
74599a92a2 [hir] Update Place.type based on value inference 2022-12-13 09:17:19 +00:00
Sathya Gunasekaran
7f8ad49165 [hir] Split value tracking into a separate pass 2022-12-13 09:17:19 +00:00
Joe Savona
5aa4143e24 TreeVisitor distinguish blocks from statements
TreeVisitor didn't distinguish between the type of a block and the type of an 
item that can occur within a block - this was fine for Codegen which can use 
`t.Statement` for both of those values. However, the upcoming scope construction 
needs to distinguish instructions in a block from a block itself, so this PR 
adds a new type parameter.
2022-12-12 16:46:55 -08:00
Joseph Savona
35ba4149ec Support assignment in for statement's update clause
Per the title, this PR adds support for assignment expressions in update 
clauses. This was mostly fixed by the previous diff to improve value block 
handling, and there's only a bit more to do here to allow a "value block" that 
doesn't produce a value (we need a better name).
2022-12-12 15:40:46 -08:00
Sathya Gunasekaran
b8cf85d77d [hir] Add Type to Place 2022-12-12 21:10:50 +00:00
Sathya Gunasekaran
e2e5e389af [be] Move buildAliasSets to DisjointSet 2022-12-12 20:35:23 +00:00
Sathya Gunasekaran
3c976a24b3 [hir] Run mutable range analysis for aliases to fix point 2022-12-12 20:35:23 +00:00
Joseph Savona
b8d78a94a8 Improve "value block" handling
This is a pre-req to construct reactive scopes in #857. "Value blocks" such as 
`for` init/test/update and `while` test need to be consistently wrapped in 
enter/leave calls so that we can extend the range of values properly. We also 
need to handle `for` init blocks a bit differently, since they allow variable 
declarations but not other types of statements. 

This PR ensures that we use consistent methods for handling value blocks (`for` 
test/update and `while` test) and treats `for` init as a new type with its own 
enter/append/leave visitor functions.
2022-12-12 11:20:10 -08:00
lauren
9c09c1cd62 Revert "Fork ReactDOMSharedInternals for www (#25791)" (#25864)
We did some cleanup internally of our ReactDOM module, so this fork
should be safe to remove now. Will land this only after our internal
diff lands.
2022-12-12 09:39:57 -08:00
Samuel Susla
996e4c0d56 Offscreen add attach (#25603)
`Offscreen.attach` is imperative API to signal to Offscreen that its
updates should be high priority and effects should be mounted. Coupled
with `Offscreen.detach` it gives ability to manually control Offscreen.
Unlike with mode `visible` and `hidden`, it is developers job to make
sure contents of Offscreen are not visible to users.
`Offscreen.attach` only works if mode is `manual`.

Example uses:
```jsx
let offscreenRef = useRef(null);
<Offscreen mode={'manual'} ref={offscreenRef)}>
  <Child />
</Offscreen>

// ------

// Offscreen is attached by default. 
// For example user scrolls away and Offscreen subtree is not visible anymore.
offscreenRef.current.detach();


// User scrolls back and Offscreen subtree is visible again.
offscreenRef.current.attach();
```

Co-authored-by: Andrew Clark <git@andrewclark.io>
2022-12-12 14:00:16 +00:00
Lauren Tan
c8bb9ea0af Move pretty printing Scopes into PrintHIR 2022-12-09 17:12:45 -05:00
Jan Kassens
255700e2cd Increase precision in InferMutableRangesForAlias
Previously, this step just set the mutable range of any alias set including any 

mutation to the end of the last mutable range of any of the containing 
identifiers. 

This change makes it so that the ends are only updated of the ranges that end 

before the last mutation. 

Fixes #852
2022-12-09 13:10:01 -05:00
Joseph Savona
748992d508 LeaveSSA: handle phi as operand to subsequent phi
Fixes https://github.com/facebook/react-forget/pull/858#discussion_r1044626137. 
The case is 

```javascript 

function foo() { 

let x$1 = 1; 

let y = 2; 

if (y === 2) { 

x$2 = 3; 

} 

x$3 = phi(x$1, x$2) 

if (y === 3) { 

x4 = 5; 

} 

x$5 = phi(x$3, x$4); 

y = x$5; 

} 

``` 

What happens here is that there are two _sequential_ phis for `x`. Previously 
when we encountered the second phi we would find that there is no `let` 
declaration for the phi or any of its operands, and create a new one before the 
second `if`. That's incorrect, these should all merge into a single `x` 
declaration. We now look up the phi operands to see if they are part of a 
previous phi, and merge them correctly.
2022-12-09 09:47:47 -08:00
Joseph Savona
d03c5bc0a0 Run LeaveSSA prior to analyzing reactive scopes
Reorders LeaveSSA so that it runs before we begin evaluating reactive scopes. 
Note that reactive scopes must span the full construction of each variable — for 
variables with a phi, this must span the declaration and all assignments of the 
phi operands. And that's exactly what the new LeaveSSA does! LeaveSSA removes 
phi nodes and ensure that all versions of a variable which flow into a phi have 
been assigned a single canonical identifier (with an appropriate mutable range). 

This PR includes this and some related changes: 

* Reorders the pass 

* Changes hir-test to print the final HIR, eg just prior to codegen 

* Teaches LeaveSSA to update the mutable range of the canonical identifiers it 
assigns, based on the min/max of the variables assigned.
2022-12-09 07:39:28 -08:00
Samuel Susla
b14d7fa4b8 Add support for setNativeProps to Fabric (#25737)
Add support for `setNativeProps` in Fabric to make migration to the new
architecture easier. The React Native part of this has already landed in
the core and iOS in
1d3fa40c59.

It is still recommended to move away from `setNativeProps` because the
API will not work with future features.
2022-12-09 14:43:52 +00:00
Sathya Gunasekaran
daaf95854c [hir] Don't alias fields unless a mutation occurs after aliasing
A wise Joe once said, "We only care about observed aliasing". 

Instead of performing aliasing for fields and non fields together, split the 
analysis to happen over separate passes. Similarly split inferring mutable 
lifetimes pass for fields and non fields. 

Now, we can identify the aliases of fields that are *not* mutated and only alias 
the ones that do mutate. 

The algorithm is roughly as follows: 

1. Build the set of aliases for non fields 

2. Infer mutable ranges for all instructions except aliasing fields 

3. Infer mutable ranges for all aliased instructions based on the alias set 
calculated in step 1 (this doesn't include aliasing fields) 

4. Extend the set of aliases (calculated in step 1)  to include fields only if 
the field or the receiver is mutated after the aliasing, ie, if _mutability is 
observed_. 

5. Run infer mutable ranges again for all instructions including the fields that 
were aliased in the previous step. 

6. Run infer mutable ranges for all aliased instructions including the fields 
that were aliased.
2022-12-08 23:29:41 +00:00
lauren
1c7055ddbb [DiffTrain] Add github url for the commit to the commit message (#25845)
Currently we just append the ref for the commit, let's make it clickable
for easier debugging in syncs.
2022-12-08 11:22:35 -08:00
Joseph Savona
21652a135b Improved LeaveSSA pass
## Problem 

The previous version of LeaveSSA used a very simple approach in which 
identifiers stored their pre-ssa id, and LeaveSSA restored this id back. The 
upside of this approach is that it's very simple and trivially correct (assuming 
no reordering of code). The downside is that after running LeaveSSA we lose all 
information about which versions of variable declarations are distinct, and 
which might merge together in a phi. That information is really useful for scope 
analysis! Consider this input (variables are numbered as they would be in SSA 
form): 

```javascript 

function foo(a, b, c) { 

let x$1 = null; 

if (a) { 

x$2 = b; 

} else { 

x$3 = c; 

} 

x$4 = phi(x$2, x$3); 

return x$4; 

``` 

The current LeaveSSA assigns all 4 variables back to `x$1`, with a single let 
declaration at `let x$1 = null`. However, from a reactive scopes perspective, 
there are really just 2 versions of x: the initial x$1 (defined and never used) 
and then x$2, x$3, and x$4, which have to be merged into a single scope because 
they are part of a phi. In other words, we can't independently compute x$2, x$3, 
or x$4 - if any of their inputs changes, we have to redo all the computation. 
However, the existing structure makes it difficult to figure out the correct 
starting point for this scope — there is no initial `let` declaration that we 
can refer to. 

Instead, we can represent the program as follows after LeaveSSA, and then use 
this form for scope analysis: 

```javascript 

function foo(a, b, c) { 

const x$1 = null; // NOTE: rewritten to const 

let x$2; // synthesized declaration to allow later reassignment 

if (a) { 

x$2 = b; 

} else { 

x$2 = c; 

} 

return x$2; 

``` 

Note that there are only 2 versions of x, and we have synthesized a variable 
declaration for x$2 at the appropriate scope. Our scope analysis can then 
determine that the range of x$2 is from the declaration to the end of the if. 

## Approach 

This pass does two main rewrites: 

* For variables that do *not* appear as a phi id or operand, it rewrites the 
declaration to be `const`. You can see this above for x$1. 

* For variables that *do* appear as a phi or operand, it synthesizes a new `let` 
binding at the appropriate scope (ie, in the appropriate block), and updates all 
other operands from the phi to use the same id for the variable.  You can see 
this above for x$2, x$3, and x$4. 

Note that the let binding is generated at the narrowest scope possible. In this 
example, we generate distinct let bindings for the other if and else branches: 

```javascript 

function foo(a, b, c) { 

let x = null; 

if (a) { 

// we generate a `let x$2` here 

if (b) { 

x = 0; // becomes x$2 

} else { 

x = 1;  // becomes x$2 

} 

x // becomes x$2 

} else { 

// we generate a `let x$3` here 

if (c) { 

x = 2; // becomes x$3 

} else { 

x = 3; // becomes x$3 

} 

x; // becomes x$3 

} 

} 

``` 

Because the different x values from the outer if/else can never join in a phi, 
we can treat them as independent variables and (re)compute them independently. 

The algorithm works by iterating in reverse-postorder, and looking ahead at 
fallthrough blocks to find phi nodes that may need a let declaration (see above 
example of where these are generated). It also tracks variables which _don't_ 
participate in a phi so that it can rewrite their declarations to `const`. 

## TODO 

This PR does *not* yet work for cases where there is unconditional assignment 
within a `while` test condition. That would technically create a distinct 
version of the variable that shadows the value for the loop, and you can't have 
variable declarations in a while test condition. 

That case already doesn't work, though, so i'm punting on it for now until we 
figure out a bit more around 

"value" blocks. We have some good options, like desugaring to a `for(;;)` and 
manually implementing the while semantics in that case.
2022-12-08 07:35:14 -08:00
Ikko Ashimine
8196872798 [Float] Fix typo in ReactDOMResourceValidation.js (#25798)
Co-authored-by: Sebastian Silbermann <silbermann.sebastian@gmail.com>
2022-12-08 06:09:05 +01:00
Josh Story
5dfc485f69 fix tests for when float is off (#25839)
Some tests fail when float is off but when singletons are on. This PR
makes some adjustments

1. 2 singleton tests assert float semantics so will fail.
2. the float dispatcher was being set on the server even when float was
off. while the float calls didn't do anything warnings were still
generated. Instead we provide an empty object for the dispatcher if
float is off. Longer term the dispatcher should move to formatconfig and
just reference the float methods if the flag is on
3. some external fizz runtime tests did not gate against float but
should have
2022-12-07 12:51:46 -08:00
Mengdi Chen
827cbdbcc6 React DevTools 4.27.0 -> 4.27.1 (#25835)
patch for devtools bug
2022-12-07 12:23:52 -05:00
dependabot[bot]
c600339200 Bump qs from 6.5.2 to 6.5.3 in /fixtures/concurrent/time-slicing (#25846) 2022-12-07 16:10:33 +00:00
dependabot[bot]
a0619e26ca Bump qs from 6.4.0 to 6.4.1 in /fixtures/packaging/webpack-alias/prod (#25823) 2022-12-07 15:58:42 +00:00
dependabot[bot]
8e24b04687 Bump qs from 6.4.0 to 6.4.1 in /fixtures/packaging/brunch/dev (#25822) 2022-12-07 15:50:36 +00:00
dependabot[bot]
b94275150a Bump qs from 6.4.0 to 6.4.1 in /fixtures/packaging/webpack/dev (#25824) 2022-12-07 15:50:16 +00:00
Sebastian Markbåge
bfcbf33067 toString children of title (#25838)
children of title can either behave like children or like an attribute.
We're kind of treating it more like an attribute now so we should
support toString/valueOf like we do on attributes.
2022-12-07 09:41:50 -05:00
Ricky
d4bc16a7d6 Revert "[react-www] remove forked bundle" (#25837)
Reverts facebook/react#25831
2022-12-06 19:14:31 -05:00
Mengdi Chen
d69b2cf820 [bug fix] revert values in ReactFiberFlags to keep consistency for devtools (#25832)
## Summary

We see recent bug reports like #25755 and #25769 for devtools. Whenever
a component uses hook `useEffect`, it triggers an error.
This was introduced in #25663 when we try to keep the `ReactFiberFlags`
numbers consistent with reconciler, in order to fix an issue with server
components.
However, the values of `ReactFiberFlags` in reconciler were actually
changed a while ago in
b4204ede66
We made this mistake because, although it's not mentioned in the
comment, `DidCapture` and `Hydrating` are actually used by DevTools

This caused
- the latest (not stable) react version is broken on devtools before
4.27.0 (but only in uncommon cases such server components)
- all earlier react versions are broken on latest devtools (4.27.0)

To keep most versions work, we need to revert the commit that changed
the `ReactFiberFlags` values

## How did you test this change?

1. add a `useEffect` in a component in the TodoList of the shell,
trigger the error in devtools
2. after change, the error is gone
2022-12-06 17:25:30 -05:00
Jan Kassens
645ae2686b [react-www] remove forked bundle (#25831)
The `enableNewReconciler` was gone with
420f0b7fa1, this removes the bundle
config.
2022-12-06 16:12:20 -05:00
lushevol
7db45b9a38 fix invalid link to react-devtools-extensions/src/__tests__ (#25816) 2022-12-06 21:21:01 +01:00
lauren
c961f2f476 [DiffTrain] Add REVISION and REVISION_TRANSFORM to output (#25830)
We use these for the sync script, so to preserve option value let's
continue adding these files so the script can still be used for
arbitrary commits.
2022-12-06 09:55:37 -08:00
Jan Kassens
4837e21de3 [HIR] add for terminal
The changes here are pretty significant and there's a bunch more left: 

- support for with any of `<init>`, `<test>` or `<update>` empty. - support for 
with `<init>` as `Expression` instead of VariableDeclaration` node - support 
assignment expressions in `<update>`, this seems like it might require further 
new abstractions to allow something like a block to codegen into a single 
expression.
2022-12-06 12:01:32 -05:00
lauren
7c39922891 [DiffTrain] Strip @license from files (#25821)
We need to remove this for some internal tests. This was previously in
our upgrade script so adding it back here for parity.

Test plan: files were updated correctly
[[1]](1704bbb826 (diff-80b968e05ce2ceeff6e17c938dc722aff2c1c660f8ef402e6664bc5b2cafa5fbL2))
[[2]](1704bbb826 (diff-6ecd07a61c8e0e28793dace3f9f62751e4808de9c2965aa1ddeb0157f3c9b4ecL2))

Co-authored-by: Jan Kassens <jkassens@meta.com>
2022-12-06 09:01:24 -08:00
dependabot[bot]
2f16409f3a Bump qs from 6.4.0 to 6.4.1 in /fixtures/attribute-behavior (#25820)
Bumps [qs](https://github.com/ljharb/qs) from 6.4.0 to 6.4.1.
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a
href="https://github.com/ljharb/qs/blob/main/CHANGELOG.md">qs's
changelog</a>.</em></p>
<blockquote>
<h2><strong>6.4.1</strong></h2>
<ul>
<li>[Fix] <code>parse</code>: ignore <code>__proto__</code> keys (<a
href="https://github-redirect.dependabot.com/ljharb/qs/issues/428">#428</a>)</li>
<li>[Fix] fix for an impossible situation: when the formatter is called
with a non-string value</li>
<li>[Fix] use <code>safer-buffer</code> instead of <code>Buffer</code>
constructor</li>
<li>[Fix] <code>utils.merge</code>: avoid a crash with a null target and
an array source</li>
<li>[Fix]<code> </code>utils.merge`: avoid a crash with a null target
and a truthy non-array source</li>
<li>[Fix] <code>stringify</code>: fix a crash with
<code>strictNullHandling</code> and a custom
<code>filter</code>/<code>serializeDate</code> (<a
href="https://github-redirect.dependabot.com/ljharb/qs/issues/279">#279</a>)</li>
<li>[Fix] <code>utils</code>: <code>merge</code>: fix crash when
<code>source</code> is a truthy primitive &amp; no options are
provided</li>
<li>[Fix] when <code>parseArrays</code> is false, properly handle keys
ending in <code>[]</code></li>
<li>[Robustness] <code>stringify</code>: avoid relying on a global
<code>undefined</code> (<a
href="https://github-redirect.dependabot.com/ljharb/qs/issues/427">#427</a>)</li>
<li>[Refactor] use cached <code>Array.isArray</code></li>
<li>[Refactor] <code>stringify</code>: Avoid arr = arr.concat(...), push
to the existing instance (<a
href="https://github-redirect.dependabot.com/ljharb/qs/issues/269">#269</a>)</li>
<li>[readme] remove travis badge; add github actions/codecov badges;
update URLs</li>
<li>[Docs] Clarify the need for &quot;arrayLimit&quot; option</li>
<li>[meta] fix README.md (<a
href="https://github-redirect.dependabot.com/ljharb/qs/issues/399">#399</a>)</li>
<li>[meta] Clean up license text so it’s properly detected as
BSD-3-Clause</li>
<li>[meta] add FUNDING.yml</li>
<li>[actions] backport actions from main</li>
<li>[Tests] remove nonexistent tape option</li>
<li>[Dev Deps] backport from main</li>
</ul>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="486aa46547"><code>486aa46</code></a>
v6.4.1</li>
<li><a
href="727ef5d346"><code>727ef5d</code></a>
[Fix] <code>parse</code>: ignore <code>__proto__</code> keys (<a
href="https://github-redirect.dependabot.com/ljharb/qs/issues/428">#428</a>)</li>
<li><a
href="cd1874eb17"><code>cd1874e</code></a>
[Robustness] <code>stringify</code>: avoid relying on a global
<code>undefined</code> (<a
href="https://github-redirect.dependabot.com/ljharb/qs/issues/427">#427</a>)</li>
<li><a
href="45e987c603"><code>45e987c</code></a>
[readme] remove travis badge; add github actions/codecov badges; update
URLs</li>
<li><a
href="90a3bced51"><code>90a3bce</code></a>
[meta] fix README.md (<a
href="https://github-redirect.dependabot.com/ljharb/qs/issues/399">#399</a>)</li>
<li><a
href="9566d25019"><code>9566d25</code></a>
[Fix] fix for an impossible situation: when the formatter is called with
a no...</li>
<li><a
href="74227ef022"><code>74227ef</code></a>
Clean up license text so it’s properly detected as BSD-3-Clause</li>
<li><a
href="35dfb227e2"><code>35dfb22</code></a>
[actions] backport actions from main</li>
<li><a
href="7d4670fca6"><code>7d4670f</code></a>
[Dev Deps] backport from main</li>
<li><a
href="0485440902"><code>0485440</code></a>
[Fix] use <code>safer-buffer</code> instead of <code>Buffer</code>
constructor</li>
<li>Additional commits viewable in <a
href="https://github.com/ljharb/qs/compare/v6.4.0...v6.4.1">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=qs&package-manager=npm_and_yarn&previous-version=6.4.0&new-version=6.4.1)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)
- `@dependabot use these labels` will set the current labels as the
default for future PRs for this repo and language
- `@dependabot use these reviewers` will set the current reviewers as
the default for future PRs for this repo and language
- `@dependabot use these assignees` will set the current assignees as
the default for future PRs for this repo and language
- `@dependabot use this milestone` will set the current milestone as the
default for future PRs for this repo and language

You can disable automated security fix PRs for this repo from the
[Security Alerts
page](https://github.com/facebook/react/network/alerts).

</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-12-06 11:51:09 -05:00
Jan Kassens
db740366f8 "ValueBlock" for while test node
The instructions of a while test node cannot just be pushed to the previous 
block. This creates a new block for the test node and then during code gen 
converts the statements pushed to the "value block" into expressions.
2022-12-06 11:28:15 -05:00
Sathya Gunasekaran
3a1124fe14 [hir] Add alias analysis for lvalue aggregates
This adds a field sensitive, flow-insensitive, context-insensitive alias 
analysis for lvalue aggregates. 

In the future, InferMutableLifetimes can refine it's analysis using these field 
sensitive alias sets.
2022-12-05 22:27:01 +00:00
Sathya Gunasekaran
a855e76494 [hir] Introduce AliasSet type
Starting to get wonky typing out the entire type. This typedef is better for 
typing and readability.
2022-12-05 22:27:01 +00:00
Sathya Gunasekaran
2dab6f6c4d [hir] Store Primitives in AbstractState 2022-12-05 22:27:00 +00:00
Sathya Gunasekaran
9da7ad557d [hir] Introduce AbstractState.store
Currently AbstractState.alias performs three operations: - Reading a value - 
Storing the value - Updating aliasing (in the DisjointSet) 

This commit makes AbstractState.alias only responsible for updating the alias 
information. The rest of the operations are split into separate functions.
2022-12-05 22:27:00 +00:00
Sathya Gunasekaran
1c6e39a1d6 [hir] Introduce AbstractState.read to lookup value
Split AbstractState.alias into two separate operations for better readability.
2022-12-05 22:26:59 +00:00
Andrew Clark
d807eb52cf Revert recent hydration changes (#25812)
We're reverting the stack of changes that this code belongs to in order
to unblock the sync to Meta's internal codebase. We will attempt to
re-land once the sync is unblocked.

I have not yet verified that this fixes the error that were reported
internally. I will do that before landing.
2022-12-05 16:10:03 -05:00
lauren
2ccfa657d9 Fork ReactDOMSharedInternals for www (#25791)
This isn't the right way to do this, but internally we have some
restrictions so we need to add an indirection. Let's land this now so we
can catch up our sync and then fix forward from there.

Co-authored-by: Jan Kassens <jkassens@meta.com>
2022-12-05 15:08:28 -05:00
lauren
cd23e40c73 [DiffTrain] Use original commit message (#25809)
Instead of the current commit message (which just shows "Build for
<sha>", re-use the commit message from the origin commit instead.
2022-12-05 10:56:57 -08:00
Tianyu Yao
f0534ae94a Avoid replaying SelectiveHydrationException in dev (#25754)
<!--
  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 is discovered by @acdlite.
In dev we replay errors so debugger will treat them as uncaught errors,
but we need to ignore internal exceptions.
<!--
Explain the **motivation** for making this change. What existing problem
does the pull request solve?
-->

## How did you test this change?
manually console.log in some tests, and noticed replay didn't happen.
<!--
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.
-->
2022-12-02 11:48:58 -08:00
Dmitry
7fab379d8e fix link to ReactDOMHostconfig in reconciler docs (#25788)
## Summary

Reference to #25716, changed old link to a new, now page exist, instead
of 404.

## How did you test this change?

yarn test
and by clicking on the link of host config in
https://github.com/facebook/react/blob/main/packages/react-reconciler/README.md#practical-examples
2022-12-02 17:40:50 +00:00
Samuel Susla
500c8aa082 Add component name to StrictMode error message (#25718)
The error message to warn user about state update coming from inside an
update function does not contain name of the offending component. Other
warnings StrictMode has, always have offending component mentioned in
top level error message.


Previous error message:
```
An update (setState, replaceState, or forceUpdate) was scheduled 
from inside an update function. Update functions should be pure
with zero side-effects. Consider using componentDidUpdate or a
callback.
```

New error message:
```
An update (setState, replaceState, or forceUpdate) was scheduled 
from inside an update function. Update functions should be pure
with zero side-effects. Consider using componentDidUpdate or a
callback.

Please update the following component: Foo
```
2022-12-02 17:14:12 +00:00
Samuel Susla
353c30252f Hold host functions in var (#25741)
Calling any function on `nativeFabricUIManager`, for example
`nativeFabricUIManager.measure`, results in a round trip to the host
platform through jsi layer. It is the same for repeated calls to same
host function. This is unnecessary overload which can be avoided by
retaining host function in a variable.
2022-12-02 15:53:55 +00:00
Samuel Susla
17f6912a44 Add flow types to ReactFiberHooks (#25752)
Increase type coverage in ReactFiberHooks file.
2022-12-02 15:31:53 +00:00
dependabot[bot]
f0bba2d4f5 Bump decode-uri-component from 0.2.0 to 0.2.2 in /fixtures/concurrent/time-slicing (#25781)
Bumps
[decode-uri-component](https://github.com/SamVerschueren/decode-uri-component)
from 0.2.0 to 0.2.2.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a
href="https://github.com/SamVerschueren/decode-uri-component/releases">decode-uri-component's
releases</a>.</em></p>
<blockquote>
<h2>v0.2.2</h2>
<ul>
<li>Prevent overwriting previously decoded tokens  980e0bf</li>
</ul>
<p><a
href="https://github.com/SamVerschueren/decode-uri-component/compare/v0.2.1...v0.2.2">https://github.com/SamVerschueren/decode-uri-component/compare/v0.2.1...v0.2.2</a></p>
<h2>v0.2.1</h2>
<ul>
<li>Switch to GitHub workflows  76abc93</li>
<li>Fix issue where decode throws - fixes <a
href="https://github-redirect.dependabot.com/SamVerschueren/decode-uri-component/issues/6">#6</a>
746ca5d</li>
<li>Update license (<a
href="https://github-redirect.dependabot.com/SamVerschueren/decode-uri-component/issues/1">#1</a>)
486d7e2</li>
<li>Tidelift tasks  a650457</li>
<li>Meta tweaks  66e1c28</li>
</ul>
<p><a
href="https://github.com/SamVerschueren/decode-uri-component/compare/v0.2.0...v0.2.1">https://github.com/SamVerschueren/decode-uri-component/compare/v0.2.0...v0.2.1</a></p>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="a0eea469d2"><code>a0eea46</code></a>
0.2.2</li>
<li><a
href="980e0bf09b"><code>980e0bf</code></a>
Prevent overwriting previously decoded tokens</li>
<li><a
href="3c8a373dd4"><code>3c8a373</code></a>
0.2.1</li>
<li><a
href="76abc93978"><code>76abc93</code></a>
Switch to GitHub workflows</li>
<li><a
href="746ca5dcb6"><code>746ca5d</code></a>
Fix issue where decode throws - fixes <a
href="https://github-redirect.dependabot.com/SamVerschueren/decode-uri-component/issues/6">#6</a></li>
<li><a
href="486d7e26d3"><code>486d7e2</code></a>
Update license (<a
href="https://github-redirect.dependabot.com/SamVerschueren/decode-uri-component/issues/1">#1</a>)</li>
<li><a
href="a65045724e"><code>a650457</code></a>
Tidelift tasks</li>
<li><a
href="66e1c2834c"><code>66e1c28</code></a>
Meta tweaks</li>
<li>See full diff in <a
href="https://github.com/SamVerschueren/decode-uri-component/compare/v0.2.0...v0.2.2">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=decode-uri-component&package-manager=npm_and_yarn&previous-version=0.2.0&new-version=0.2.2)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)
- `@dependabot use these labels` will set the current labels as the
default for future PRs for this repo and language
- `@dependabot use these reviewers` will set the current reviewers as
the default for future PRs for this repo and language
- `@dependabot use these assignees` will set the current assignees as
the default for future PRs for this repo and language
- `@dependabot use this milestone` will set the current milestone as the
default for future PRs for this repo and language

You can disable automated security fix PRs for this repo from the
[Security Alerts
page](https://github.com/facebook/react/network/alerts).

</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-12-02 00:06:21 -05:00
dependabot[bot]
44a3d6e148 Bump decode-uri-component from 0.2.0 to 0.2.2 in /fixtures/ssr (#25782) 2022-12-02 04:52:41 +00:00
dependabot[bot]
000c5cb28f Bump decode-uri-component from 0.2.0 to 0.2.2 in /fixtures/blocks (#25777) 2022-12-02 04:45:15 +00:00
dependabot[bot]
38208fc5ad Bump decode-uri-component from 0.2.0 to 0.2.2 in /fixtures/dom (#25783) 2022-12-02 04:44:52 +00:00
dependabot[bot]
eb1024fd99 Bump decode-uri-component from 0.2.0 to 0.2.2 (#25778) 2022-12-02 04:36:19 +00:00
dependabot[bot]
06fff18d2a Bump decode-uri-component from 0.2.0 to 0.2.2 in /fixtures/legacy-jsx-runtimes (#25779) 2022-12-02 04:29:39 +00:00
dependabot[bot]
3e151c7d21 Bump decode-uri-component from 0.2.0 to 0.2.2 in /fixtures/fizz (#25780)
Bumps
[decode-uri-component](https://github.com/SamVerschueren/decode-uri-component)
from 0.2.0 to 0.2.2.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a
href="https://github.com/SamVerschueren/decode-uri-component/releases">decode-uri-component's
releases</a>.</em></p>
<blockquote>
<h2>v0.2.2</h2>
<ul>
<li>Prevent overwriting previously decoded tokens  980e0bf</li>
</ul>
<p><a
href="https://github.com/SamVerschueren/decode-uri-component/compare/v0.2.1...v0.2.2">https://github.com/SamVerschueren/decode-uri-component/compare/v0.2.1...v0.2.2</a></p>
<h2>v0.2.1</h2>
<ul>
<li>Switch to GitHub workflows  76abc93</li>
<li>Fix issue where decode throws - fixes <a
href="https://github-redirect.dependabot.com/SamVerschueren/decode-uri-component/issues/6">#6</a>
746ca5d</li>
<li>Update license (<a
href="https://github-redirect.dependabot.com/SamVerschueren/decode-uri-component/issues/1">#1</a>)
486d7e2</li>
<li>Tidelift tasks  a650457</li>
<li>Meta tweaks  66e1c28</li>
</ul>
<p><a
href="https://github.com/SamVerschueren/decode-uri-component/compare/v0.2.0...v0.2.1">https://github.com/SamVerschueren/decode-uri-component/compare/v0.2.0...v0.2.1</a></p>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="a0eea469d2"><code>a0eea46</code></a>
0.2.2</li>
<li><a
href="980e0bf09b"><code>980e0bf</code></a>
Prevent overwriting previously decoded tokens</li>
<li><a
href="3c8a373dd4"><code>3c8a373</code></a>
0.2.1</li>
<li><a
href="76abc93978"><code>76abc93</code></a>
Switch to GitHub workflows</li>
<li><a
href="746ca5dcb6"><code>746ca5d</code></a>
Fix issue where decode throws - fixes <a
href="https://github-redirect.dependabot.com/SamVerschueren/decode-uri-component/issues/6">#6</a></li>
<li><a
href="486d7e26d3"><code>486d7e2</code></a>
Update license (<a
href="https://github-redirect.dependabot.com/SamVerschueren/decode-uri-component/issues/1">#1</a>)</li>
<li><a
href="a65045724e"><code>a650457</code></a>
Tidelift tasks</li>
<li><a
href="66e1c2834c"><code>66e1c28</code></a>
Meta tweaks</li>
<li>See full diff in <a
href="https://github.com/SamVerschueren/decode-uri-component/compare/v0.2.0...v0.2.2">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=decode-uri-component&package-manager=npm_and_yarn&previous-version=0.2.0&new-version=0.2.2)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)
- `@dependabot use these labels` will set the current labels as the
default for future PRs for this repo and language
- `@dependabot use these reviewers` will set the current reviewers as
the default for future PRs for this repo and language
- `@dependabot use these assignees` will set the current assignees as
the default for future PRs for this repo and language
- `@dependabot use this milestone` will set the current milestone as the
default for future PRs for this repo and language

You can disable automated security fix PRs for this repo from the
[Security Alerts
page](https://github.com/facebook/react/network/alerts).

</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-12-01 23:22:51 -05:00
Jan Kassens
f101c2d0d3 Remove Reconciler fork (2/2) (#25775)
We've heard from multiple contributors that the Reconciler forking
mechanism was confusing and/or annoying to deal with. Since it's
currently unused and there's no immediate plans to start using it again,
this removes the forking.

Fully removing the fork is split into 2 steps to preserve file history:

**#25774 previous PR that did the bulk of the work:**
- remove `enableNewReconciler` feature flag.
- remove `unstable_isNewReconciler` export
- remove eslint rules for cross fork imports
- remove `*.new.js` files and update imports
- merge non-suffixed files into `*.old` files where both exist
(sometimes types were defined there)

**This PR**
- rename `*.old` files
2022-12-01 23:19:13 -05:00
Jan Kassens
420f0b7fa1 Remove Reconciler fork (1/2) (#25774)
We've heard from multiple contributors that the Reconciler forking
mechanism was confusing and/or annoying to deal with. Since it's
currently unused and there's no immediate plans to start using it again,
this removes the forking.

Fully removing the fork is split into 2 steps to preserve file history:

**This PR**
- remove `enableNewReconciler` feature flag.
- remove `unstable_isNewReconciler` export
- remove eslint rules for cross fork imports
- remove `*.new.js` files and update imports
- merge non-suffixed files into `*.old` files where both exist
(sometimes types were defined there)

**#25775**
- rename `*.old` files
2022-12-01 23:06:25 -05:00
lauren
030dae2f4c [DiffTrain] Fix null artifactsUrl and add more logging (#25768)
Log more info on the status of the process_artifacts_combined job to
help with debugging, and exit with exitcode 1 if anything goes wrong

Test plan: Ran the workflow
[successfully](https://github.com/facebook/react/actions/runs/3595185062)
2022-12-01 11:08:29 -08:00
Sathya Gunasekaran
7bdd0f03cb [hir] Perform alias analysis for aggregate rvalues
Maintain and use abstract memory to peform more refined aliasing of member 
expressions.
2022-12-01 19:03:50 +00:00
Sathya Gunasekaran
00f74d4e70 [hir] Correctly identify mutated identifiers
mutableRange.end is exclusive so account for this extra 1 instruction.
2022-12-01 19:03:47 +00:00
Sathya Gunasekaran
c96c9b458f [hir] Add a buildAliasSets pass
Moves the existing alias set building logic from inferMutableLifetimes to a 
separate pass. 

Additionally maintain abstract state to refine aliasing to not include 
primitives.
2022-12-01 19:03:44 +00:00
Joseph Savona
4b9c2f36fe add missing reactive scope passes to playground
I forget to add these passes to the playground, oops.
2022-12-01 11:02:27 -08:00
Jan Kassens
df58546f4e Codegen TValue are just Expressions (#839) 2022-12-01 12:56:45 -05:00
Sebastian Silbermann
3ba7add608 Allow async blocks in to(Error|Warn)Dev (#25338) 2022-12-01 11:26:43 +01:00
Mengdi Chen
f197ca997b React DevTools 4.26.1 -> 4.27.0 (#25753) 2022-11-30 19:14:11 -05:00
Joe Savona
509aa9f0e5 HIRVisitor - change labels to block ids
HIRTreeVisitor previously passed a string label (for certain blocks). This 
changes to pass the raw BlockId, and have codegen convert that to a string. I'm 
not sure if we'll need this but it would be helpful for eg visiting the IR and 
emitting a new IR, while mapping block ids forward. Even if we don't need that 
it makes sense for Codegen to decide how to convert a block id into a label 
(which has to obey the rules of an identifier, not the visitor's concern).
2022-11-30 10:24:51 -08:00
mofeiZ
fa11bd6ecc [ServerRenderer] Add option to send instructions as data attributes (#25437)
### Changes made:
- Running with enableFizzExternalRuntime (feature flag) and
unstable_externalRuntimeSrc (param) will generate html nodes with data
attributes that encode Fizz instructions.
```
<div 
  hidden data-rxi=""
  data-bid="param0"
  data-dgst="param1"
></div>
```
- Added an external runtime browser script
`ReactDOMServerExternalRuntime`, which processes and removes these nodes
- This runtime should be passed as to renderInto[...] via
`unstable_externalRuntimeSrc`
- Since this runtime is render blocking (for all streamed suspense
boundaries and segments), we want this to reach the client as early as
possible. By default, Fizz will send this script at the end of the shell
when it detects dynamic content (e.g. suspenseful pending tasks), but it
can be sent even earlier by calling `preinit(...)` inside a component.
- The current implementation relies on Float to dedupe sending
`unstable_externalRuntimeSrc`, so `enableFizzExternalRuntime` is only
valid when `enableFloat` is also set.
2022-11-30 13:22:08 -05:00
Jan Kassens
aa2b152ea8 Fixture tests for 2 cases of expressions that produce incorrect output
They're fairly related, but I figured it's worth keeping more examples. 

- For the `while` example we need to codegen into a single expression. - For the 
expression with contained assignment we need to either keep the SSA ids around 
or re-create a similar expression during codegen.
2022-11-29 18:33:00 -05:00
Lauren Tan
b3a26f1de2 Infer reactive scope dependencies
This builds upon @josephsavona's prior PR #817 to add support for inferring 
reactive scope dependencies for all instructions and terminals. 

Still TODO (probably in follow up PRs): 

- [ ] fix duplicate/different identity scope issue (see this [test 
fixture](5f3b260aaa/forget/src/__tests__/fixtures/hir/overlapping-scopes-while.expect.md)) 
- [ ] also collect outputs of each scope - [ ] add new tree visitor that only 
visits, consider renaming the current `visitTree` to `mapTree` or similar 

Co-authored-by: Joe Savona <joesavonafb.com>
2022-11-29 17:07:55 -05:00
Lauren Tan
ccca2d38cf [ez] Delete some old files 2022-11-29 15:23:56 -05:00
Samuel Susla
e98225485a Add ref cleanup function (#25686)
Add option for ref function to return a clean up function.

```jsx
<div ref={(_ref) => {
  // Use `_ref`
  return () => {
    // Clean up _ref
  };
}} />
```

If clean up function is not provided. Ref function is called with null
like it has been before.

```jsx
<div ref={(_ref) => {
  if (_ref) {
    // Use _ref
  } else {
    // Clean up _ref
  }
}} />
```
2022-11-29 16:41:02 +00:00
Lauren Tan
179a7f9605 Fix output tabs growing infinitely in height
The `automaticLayout` config option for Monaco causes it to remeasure itself, 
and the parent container's height being longer than the screen causes it to 
constantly grow infinitely. You can observe this bug by going to the playground, 
expanding any tab, and watch the scrollbar grow as the editor quickly grows to 
ridiculous heights and your laptop starts glowing red hot and̶͙̕ H̴͉͘e comes 
t̵͙́o ̴̜̿de̷̼̚s̷̻̍ec̶̮͒rate all knowled̵̥̆ge
2022-11-29 11:07:03 -05:00
Tianyu Yao
edbfc6399f Fix Jest cache for transform-react-version-pragma (#25712)
<!--
  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
Jest caching wasn't working correctly for
`transform-react-version-pragma`. One condition for including
`transform-react-version-pragma` is that `process.env.REACT_VERSION` is
set, but it wasn't included in the cache key computation. Thus local
test runs would only run without `transform-react-version-pragma`, if
jest runs weren't using the `-reactVersion` flag and then added it.

Inlined the `scripts/jest/devtools/preprocessor.js` file, because it
makes it more obvious that `process.env.REACT_VERSION` is used in
`scripts/jest/preprocessor.js`

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

Repro step:
- Clear jest cache
- node ./scripts/jest/jest-cli.js --build --project devtools
--release-channel=experimental --reactVersion 18.0
- node ./scripts/jest/jest-cli.js --build --project devtools
--release-channel=experimental

Before:
Jest cached the first run with `REACT_VERSION` set, so in the second run
`transform-react-version-pragma` is still there and runs only the
regression tests on old react versions.

After:
- The second run runs all tests and ignore `// @reactVersion` as
expected.
2022-11-28 15:14:34 -08:00
Jan Kassens
9f7878c7c0 [easy] remove isFallthrough arg from mapTerminalSuccessors
The argument was unused and a confusing boolean argument that's easy to mix up. 
Suggesting to remove it until we see a need for it at which point we might want 
to introduce an enum to make the argument more obvious.
2022-11-28 17:48:59 -05:00
Jan Kassens
0bbb36e1a4 [codegen] more locations: binary, return, call (#820) 2022-11-28 16:54:46 -05:00
Josh Story
15557fa67f [Fix] properly track useId use in StrictMode in development (#25713)
In `<StrictMode>` in dev hooks are run twice on each render.

For `useId` the re-render pass uses the `updateId` implementation rather
than `mountId`. In the update path we don't increment the local id
counter. This causes the render to look like no id was used which
changes the tree context and leads to a different set of IDs being
generated for subsequent calls to `useId` in the subtree.

This was discovered here: https://github.com/vercel/next.js/issues/43033

It was causing a hydration error because the ID generation no longer
matched between server and client. When strict mode is off this does not
happen because the hooks are only run once during hydration and it
properly sees that the component did generate an ID.

The fix is to not reset the localIdCounter in `renderWithHooksAgain`. It
gets reset anyway once the `renderWithHooks` is complete and since we do
not re-mount the ID in the `...Again` pass we should retain the state
from the initial pass.
2022-11-28 09:42:57 -08:00
Tianyu Yao
8a23def32f Resubmit Add HydrationSyncLane (#25711)
<!--
  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
Submit https://github.com/facebook/react/pull/25698 again after fixing
the devtools regression tests in CI.
The PR changed lanes representation and some snapshot tests of devtools
captures lanes. In devtools tests for older versions, the updated lanes
representation no longer matched. The fix is to disable regression tests
for those tests.

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

```
./scripts/circleci/download_devtools_regression_build.js 18.0 --replaceBuild
node ./scripts/jest/jest-cli.js --build --project devtools --release-channel=experimental --reactVersion 18.0
```

Unrelated to this PR. There was some issue with jest caching when I
locally ran that command. it didn't seem to include the @reactVersion
transform, but if I manually modified `scripts/jest/preprocessor.js` or
ran ` yarn test --clearCache`, the jest test runs correctly.
2022-11-28 09:13:06 -08:00
jacdebug
b932ce19a7 [playground] TabbedWindowItem lifting tabs state up
- List local state in TabbedWindowItem to Editor/index
2022-11-25 09:00:30 +00:00
Sathya Gunasekaran
9ae698c734 [playground] Add tab to display output from old architecture 2022-11-24 18:04:16 +00:00
Sathya Gunasekaran
76a4bd67f4 [playground] Remove unused kind parameter 2022-11-24 17:56:49 +00:00
jacdebug
c203d07d8c [Playground] vertical tabs to see multiple stages same time
# Add vertical tabs to see multiple stages same time 

<img width="781" alt="image" 
src="https://user-images.githubusercontent.com/430289/203837762-ccf37491-2006-4512-8014-0b7893f3396f.png">
2022-11-24 17:25:13 +00:00
Sathya Gunasekaran
d958d4b73e [playground] Remove line number from output
We already have instruction numbers as part of the output so line numbers just add extra visual noise.
2022-11-24 16:04:27 +00:00
Sathya Gunasekaran
06ca8b1026 [playground] Refactor compilation of HIR
Stack created with [Sapling](https://sapling-scm.com). Best reviewed with 
[ReviewStack](https://reviewstack.dev/facebook/react-forget/pull/825). * __->__ 
#825 

[playground] Refactor compilation of HIR
2022-11-24 15:28:38 +00:00
Sathya Gunasekaran
e2cfbeb3d3 [playground] Display only new HIR
Stack created with [Sapling](https://sapling-scm.com). Best reviewed with 
[ReviewStack](https://reviewstack.dev/facebook/react-forget/pull/824). * #825 * 
__->__ #824 

[playground] Display only new HIR
2022-11-24 15:24:40 +00:00
Jan Kassens
da6d84049e easy: name InstructionKind enum values (#818) 2022-11-23 10:48:53 -05:00
Joe Savona
e51553f5da InferReactiveScopes considers all operands, incl terminals 2022-11-22 14:10:06 -08:00
Joe Savona
a0054a1837 Visit terminal ids before terminal branches
This is a follow-up to merging ranges. I realized that we need to mark terminal 
ids as visited _before_ processing the branches of that terminal (whereas before 
we were marking terminal ids only _after_ processing the branches). That exposed 
another bug where interleaving could fail to be detected (with an error, 
thankfully) if one of the branches had completed already. 

Our small test suite is already really good!
2022-11-22 12:10:26 -08:00
Joe Savona
d2e5c31fc6 Test case showing reassignment block scoping problem
This demonstrates a situation we don't handle well today. The basic structure is 
that you have some variable defined at the top level, then some control flow 
like if/switch where _all_ branches reassign the variable, then some code after 
that references the resulting phi node: 

```javascript 

let x1; 

// ... mutate/read x1 

if (cond) { 

x2 = {}; 

} else { 

x3 = {}; 

} 

x4 = phi(x2, x3); 

``` 

We currently group x3, x3, and x4 into a scope together, but note that...there's 
no `let` declaration for any of those! This means that it looks like the scope 
for x2 and x3 start in the consequent/alternate, but the true scope spans from 
before-after the if. I'm inclined to say that LeaveSSA should run _before_ scope 
analysis, and produce something like the following in this case: 

```javascript 

let x1; 

// ...mutate/read x1 

let x2; // new variable declaration for the new version of x 

if (cond) { 

x2 = {}; 

} else { 

x2 = {}; 

} 

x2; 

``` 

This then allows us to construct a correct range for x2, which starts in the 
other block.
2022-11-22 10:42:36 -08:00
Joe Savona
4a3640f25c Merge scopes that interleave or cross control-flow boundaries together
- [x] Merge scopes that are interleaved 

- [x] Merge scopes if they both cross control-flow boundaries together 

- [x] Don't merge scopes that strictly shadow 

Still WIP because I want to double-check and see if i can find a simpler 
algorithm for this. But it works.
2022-11-22 10:42:33 -08:00
Sathya Gunasekaran
d9c6d61192 [test] Print HIR before leaving SSA
Stack created with [Sapling](https://sapling-scm.com). Best reviewed with 
[ReviewStack](https://reviewstack.dev/facebook/react-forget/pull/812). * __->__ 
#812 

[test] Print HIR before leaving SSA Looking at the HIR before it leaves SSA 
helps debugging better.
2022-11-22 17:59:42 +00:00
Lauren Tan
1f4705bbab [ez] Update test262 2022-11-22 11:39:42 -05:00
Joe Savona
6bf5a1b396 [codegen] Elide final return stmt if no value
This is a random driveby improvement. I realized that we can eliminate `return` 
statements if a) they have no value and b) they are in the top-level block. 
Functions implicitly return at that point — there can't be any succeeding 
instructions anyway — so we can save bytes in the output.
2022-11-22 08:03:40 -08:00
Joe Savona
1976fd03b4 Adjust scope ranges to block boundaries
Visits the HIR as a tree and updates mutable ranges to ensure their range end is 
aligned with the block in which the scope is declared: 

```javascript 

function foo(cond, a) { 

⌵ original scope 

⌵ expanded scope 

const x = [];    ⌝    ⌝ 

if (cond) {      ⎮    ⎮ 

...            ⎮    ⎮ 

x.push(a);     ⌟    ⎮ 

...                 ⎮ 

}                     ⎮ 

...                   ⌟ 

} 

``` 

The implementation tracks the block in which each scope "starts" (first 
instruction with an operand in that scope), and then finds the first instruction 
at that block (or a parent) which is after the scope's end.
2022-11-22 08:03:39 -08:00
Joe Savona
796e14f38e Identifier.scope includes scope id and range
Refactors `Identifier.scope` to be a `ReactiveScope` object with an id and 
range. This gives us a place to later add a list of dependencies for the scope.
2022-11-22 08:03:38 -08:00
Jimmy Lai
2655c9354d Fizz Browser: fix precomputed chunk being cleared on Node 18 (#25645)
## Edit

Went for another approach after talking with @gnoff. The approach is
now:
- add a dev-only error when a precomputed chunk is too big to be written
- suggest to copy it before passing it to `writeChunk`

This PR also includes porting the React Float tests to use the browser
build of Fizz so that we can test it out on that environment (which is
the one used by next).

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

Someone reported [a bug](https://github.com/vercel/next.js/issues/42466)
in Next.js that pointed to an issue with Node 18 in the streaming
renderer when using importing a CSS module where it only returned a
malformed bootstraping script only after loading the page once.

After investigating a bit, here's what I found:

- when using a CSS module in Next, we go into this code path, which
writes the aforementioned bootstrapping script


5f7ef8c4cb/packages/react-dom-bindings/src/server/ReactDOMServerFormatConfig.js (L2443-L2447)

- the reason for the malformed script is that
`completeBoundaryWithStylesScript1FullBoth` is emptied after the call to
`writeChunk`
- it gets emptied in `writeChunk` because we stream the chunk directly
without copying it in this codepath

a438590144/packages/react-server/src/ReactServerStreamConfigBrowser.js (L63)
- the reason why it only happens from Node 18 is because the Webstreams
APIs are available natively from that version and in their
implementation, [`enqueue` transfers the array buffer
ownership](9454ba6138/lib/internal/webstreams/readablestream.js (L2641)),
thus making it unavailable/empty for subsequent calls. In older Node
versions, we don't encounter the bug because we are using a polyfill in
Next.js, [which does not implement properly the array buffer transfer
behaviour](d354a7457c/src/lib/abstract-ops/ecmascript.ts (L16)).

I think the proper fix for this is to clone the array buffer before
enqueuing it. (we do this in the other code paths in the function later
on, see ```((currentView: any): Uint8Array).set(bytesToWrite,
writtenBytes);```





## How did you test this change?

Manually tested by applying the change in the compiled Next.js version.

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

Co-authored-by: Sebastian Markbage <sebastian@calyptus.eu>
2022-11-21 19:33:41 -05:00
lauren
799ee65343 [DiffTrain] Tweak folder structure (#25724)
Should hopefully be final tweaks! Sorry about all the noise.

Test plan: temporarily ran the workflow on this branch, verified output
in the builds/facebook-www branch is correct:
bfc0eb6cd4
2022-11-21 14:35:52 -08:00
lauren
62e2b1374b [DiffTrain] Fix incorrect build path (#25723) 2022-11-21 13:00:50 -08:00
lauren
e58b6c158b Reorganize build folders for DiffTrain (#25722)
Reorganize some files to make the DiffTrain config easier to setup. Also
add unstable_server-external-runtime to sync.
2022-11-21 12:42:49 -08:00
Jan Kassens
d44082d63c [codegen] location refinements
- Add a `loc` to the `while` terminal node. 

- Move location data for assignments 1 level higher as that seems to work better 
in the generated code (not tested with actual debugger yet though, we'll 
probably want to look at this more closely.
2022-11-21 15:35:39 -05:00
Jan Kassens
1228bc8ce5 [codegen] assign some locations in generated code (#802) 2022-11-21 15:14:20 -05:00
Joseph Savona
855d13f4b2 Add instruction ids to terminals
[ghstack-poisoned] 

closes #799
2022-11-21 11:51:19 -08:00
Joseph Savona
9948e389f1 Opaque InstructionId type
[ghstack-poisoned] 

closes #797
2022-11-21 11:47:14 -08:00
Joseph Savona
391aeab5aa MutableRange is start(inclusive) to end(exclusive)
closes #796
2022-11-21 11:44:02 -08:00
Jan Kassens
e59c17ad85 [playground] upgrade to Next 13'
- update dependencies - migrate to app directory
2022-11-21 14:03:30 -05:00
lauren
13681aaf9c Add github action to commit build artifacts for Facebook (#25721)
This PR adds a new GitHub action to commit build artifacts for Facebook
into a new protected branch. This will later be used to setup an
automatic sync to www.

The hacky spinloop is meant to be a temporary implementation until we
can support running a script internally on top of the synced diff
(coming soon). A GitHub token is otherwise required if we want to setup
a pub/sub between cirleci and github but it's not straightforward to
provision one for our org. So this workaround should do for now since we
won't keep it around for too long.

Example of it running and creating a commit on the `builds/facebook-www`
branch:
https://github.com/facebook/react/actions/runs/3516958576/jobs/5894251359
2022-11-21 11:03:23 -08:00
Joe Savona
5f2833bd5c Add HIR "tree" visitor and use it for codegen, alternate printer
Refactors Codegen to extract the core "visit IR as a tree" logic separately from 
the code to emit JS: 

* `HIRTreeVisitor` is a new helper that visits the HIR as a tree. You call 
`visitTree(ir, yourVisitor)` and it drives visiting of the IR, tracking blocks 
and scopes and calling methods as appropriate. 

* `Codegen` is now implemented as a Visitor implementation. For example 
`enterBlock()` creates an empty `Array<t.Statement>`, `leaveBlock()` wraps that 
in a `t.BlockStatement`, etc. 

* `printHIRTree()` is a new IR printer (implemented as a visitor) that prints 
the HIR in tree form, so it retains the original shape of the code but with each 
block replaced with its IR equivalent.
2022-11-18 17:15:16 -08:00
Sathya Gunasekaran
0c1f88db6c [test262] Use compiler pipeline in test262 runner (#800) 2022-11-21 18:55:57 +00:00
Sathya Gunasekaran
61e0186950 Add compiler pipeline (#795) 2022-11-21 18:42:58 +00:00
Sathya Gunasekaran
584eff2d38 [hir] Handle simple aliases when inferring mutable lifetimes (#794) 2022-11-21 18:35:14 +00:00
Jan Kassens
43686787a0 [playground] add link to view sourcemap (#798) 2022-11-21 13:19:36 -05:00
Tianyu Yao
c08d8b8041 Revert "Add SyncHydrationLane" (#25708)
Reverts facebook/react#25698
DevTools CI for older version are failing
2022-11-18 15:00:35 -08:00
Joe Savona
92afc1a50b Stub for final phase of reactive scope construction w docs 2022-11-18 14:59:33 -08:00
Lauren Tan
71a7f0d6b2 Wrap mermaid labels as strings
The new pretty printed scopes "syntax" breaks mermaid labels because the `@` 
character seems to be reserved. This wraps them all as a string so they work 
again.
2022-11-18 11:09:21 -05:00
Joe Savona
70e7a632bb Annotate mutable range for each scope
Expands InferReactiveScopeVariables to update the mutableRange of all 
identifiers to be the range of its scope. The result is that all identifiers in 
a given scope will have the same range, whose start is the minimum of the 
identifiers range starts, and end is the maximum.
2022-11-17 15:13:35 -08:00
Colin McDonnell
56ffca8b9e Add Bun streaming server renderer (#25597)
Add support for Bun server renderer
2022-11-17 13:15:56 -08:00
Tianyu Yao
f31005d6ad Add SyncHydrationLane (#25698)
<!--
  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?
-->
For more context: https://github.com/facebook/react/pull/25692

Based on https://github.com/facebook/react/pull/25695. This PR adds the
`SyncHydrationLane` so we rewind on sync updates during selective
hydration. Also added tests for ContinuouseHydration and
DefaultHydration lanes.


## 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.
-->
yarn test
2022-11-17 12:14:49 -08:00
Andrew Clark
f284d9fafa Track ThenableState alongside other hooks
Now that hook state is preserved while the work loop is suspended, we
don't need to track the thenable state in the work loop. We can track
it alongside the rest of the hook state.

This is a nice simplification and also aligns better with how it works
in Fizz and Flight.

The promises will still be cleared when the component finishes rendering
(either complete or unwind). In the future, we could stash the promises
on the fiber and reuse them during an update. However, this would only
work for `use` calls that occur before an prop/state/context is
processed, because `use` calls can only be assumed to execute in the
same order if no other props/state/context have changed. So it might not
be worth doing until we have finer grained memoization.
2022-11-17 14:48:42 -05:00
Andrew Clark
6b4c0314e8 Check thenable instead of thenableState
Now that hook state is preserved while the work loop is suspended, we
don't need to track the thenable state in the work loop. We can track
it alongside the rest of the hook state.

Before deleting the thenable state variable from the work loop, I need
to remove the other places where it's referenced.

One of them is `isThenableStateResolved`. This grabs the last thenable
from the array and checks if it has resolved.

This was a pointless indirection anyway. The thenable is already stored
as `workInProgressThrownValue`. So we can check that directly.
2022-11-17 14:48:42 -05:00
Andrew Clark
33e3d2878e Reuse hooks when replaying a suspended component
When a component suspends, under some conditions, we can wait for the
data to resolve and replay the component without unwinding the stack or
showing a fallback in the interim. When we do this, we reuse the
promises that were unwrapped during the previous attempts, so that if
they aren't memoized, the result can still be used.

We should do the same for all hooks. That way, if you _do_ memoize an
async function call with useMemo, it won't be called again during the
replay. This effectively gives you a local version of the functionality
provided by `cache`, using the normal memoization patterns that have
long existed in React.
2022-11-17 14:48:42 -05:00
Andrew Clark
4387d752da Allow more hooks to be added when replaying mount
Currently, if you call setState in render, you must render the exact
same hooks as during the first render pass.

I'm about to add a behavior where if something suspends, we can reuse
the hooks from the previous attempt. That means during initial render,
if something suspends, we should be able to reuse the hooks that were
already created and continue adding more after that. This will error
in the current implementation because of the expectation that every
render produces the same list of hooks.

In this commit, I've changed the logic to allow more hooks to be added
when replaying. But only during a mount — if there's already a current
fiber, then the logic is unchanged, because we shouldn't add any
additional hooks that aren't in the current fiber's list. Mounts are
special because there's no current fiber to compare to.

I haven't change any other behavior yet. The reason I've put this into
its own step is there are a couple tests that intentionally break the
Hook rule, to assert that React errors in these cases, and those happen
to be coupled to the behavior. This is undefined behavior that is always
accompanied by a warning and/or error. So the change should be safe.
2022-11-17 14:48:42 -05:00
Andrew Clark
5eb78d0a04 Pass ThenableState to replaySuspendedUnitOfWork
Tiny refactor to refine the work loop variable so Flow knows it's not
null when we access it in replaySuspendedUnitOfWork.
2022-11-17 14:48:42 -05:00
Andrew Clark
4a2d86bddb Don't reset work loop until stack is unwound
When replaying a suspended function components, we want to reuse the
hooks that were computed during the original render.

Currently we reset the state of the hooks right after the component 
suspends (or throws an error). This is too early because it doesn't 
give us an opportunity to wait for the promise to resolve.

This refactors the work loop to reset the hooks right before unwinding
instead of right after throwing. It doesn't include any other changes
yet, so there should be no observable behavioral change.
2022-11-17 14:48:42 -05:00
Andrew Clark
9dfbd9fa90 use: Don't suspend if there are pending updates
Before suspending, check if there are other pending updates that might
possibly unblock the suspended component. If so, interrupt the current
render and switch to working on that.

This logic was already implemented for the old "throw a Promise"
Suspense but has to be replicated for `use` because it suspends the
work loop much earlier.

I'm getting a little anxious about the divergence between the two
Suspense patterns. I'm going to look into enabling the new behavior for
the old pattern so that we can unify the implementations.
2022-11-17 14:48:42 -05:00
Andrew Clark
44c4e6f4dd Force unwind work loop during selective hydration (#25695)
When an update flows into a dehydrated boundary, React cannot apply the
update until the boundary has finished hydrating. The way this currently
works is by scheduling a slightly higher priority task on the boundary,
using a special lane that's reserved only for this purpose. Because the
task is slightly higher priority, on the next turn of the work loop, the
Scheduler will force the work loop to yield (i.e. shouldYield starts
returning `true` because there's a higher priority task).

The downside of this approach is that it only works when time slicing is
enabled. It doesn't work for synchronous updates, because the
synchronous work loop does not consult the Scheduler on each iteration.

We plan to add support for selective hydration during synchronous
updates, too, so we need to model this some other way.

I've added a special internal exception that can be thrown to force the
work loop to interrupt the work-in-progress tree. Because it's thrown
from a React-only execution stack, throwing isn't strictly necessary —
we could instead modify some internal work loop state. But using an
exception means we don't need to check for this case on every iteration
of the work loop. So doing it this way moves the check out of the fast
path.

The ideal implementation wouldn't need to unwind the stack at all — we
should be able to hydrate the subtree and then apply the update all
within a single render phase. This is how we intend to implement it in
the future, but this requires a refactor to how we handle "stack"
variables, which are currently pushed to a per-render array. We need to
make this stack resumable, like how context works in Flight and Fizz.
2022-11-17 13:51:33 -05:00
Joe Savona
2d8dc3ec4f Phi operands belong in the same reactive scope
This completes the implementation of InferReactiveScopeVariables, adding support 
for phi nodes. Example: 

```javascript 

let x$0 = null; 

mutate(x$0); 

if (cond) { 

x$1 = a; 

mutate(x$1) 

} else { 

x$2 = b; 

} 

x$3 = phi(x$1, x$2); 

mutate(x$3); 

``` 

We now add x$1, x$2, and x$3 to the same reactive scope. This reflects the fact 
that x$3 cannot be computed without also computing both x$1 and x$2. Note that 
x$3 can never be x$0, so x$0 is _not_ added to the same scope. This allows us to 
take advantage of SSA form to note that _some_ instances of an identifier really 
are distinct.
2022-11-17 09:35:00 -08:00
Sebastian Markbåge
7b17f7bbf3 Enable warning for defaultProps on function components for everyone (#25699)
This also fixes a gap where were weren't warning on memo components.
2022-11-17 12:22:23 -05:00
Lauren Tan
cf7176d3f2 Add prettier script
Copies over the prettier script from the React repo with a few tiny tweaks for a 
nicer experience running prettier on changed files
2022-11-17 10:31:34 -05:00
Sebastian Silbermann
6fb8133ed3 Turn on string ref deprecation warning for everybody (not codemoddable) (#25383)
## Summary
 
Alternate to https://github.com/facebook/react/pull/25334 without any
prod runtime changes i.e. the proposed codemod in
https://github.com/reactjs/rfcs/blob/createlement-rfc/text/0000-create-element-changes.md#deprecate-string-refs-and-remove-production-mode-_owner-field
would not work.

## How did you test this change?

- [x] CI
- [x] `yarn test` with and without `warnAboutStringRefs`
2022-11-16 19:15:57 -05:00
Sebastian Markbåge
07f46ecf2e Turn on key spread warning in jsx-runtime for everyone (#25697)
This improves the error message a bit and ensures that we recommend
putting the key first, not last, which ensures that the faster
`jsx-runtime` is used.

This only affects the modern "automatic" JSX transform.
2022-11-16 18:57:50 -05:00
Lauren Tan
188c1501be Condense test262 output in ci
There's no option to output the results of the test262 harness in silent mode so 
every pass and failure outputs multiple lines to stdout. Since there are many 
thousands of tests this results in unusable log files that are over 200k lines 
long. This PR redirects stdout to a tmp file and then we reformat the result 
into a small JSON object, grouped by the failure message with count. 

Example: 

```json [   {     "pass": false,     "data": {       "message": "Expected no 
error, got Error: TODO: Support complex object assignment",       "count": 66    
 }   },   {     "pass": false,     "data": {       "message": "Expected no 
error, got Error: TODO: lowerExpression(FunctionExpression)",       "count": 4   
  }   },   {     "pass": false,     "data": {       "message": "Expected no 
error, got Error: TODO: lowerExpression(UnaryExpression)",       "count": 6     
}   },   {     "pass": false,     "data": {       "message": "Expected no error, 
got Error: todo: lower initializer in ForStatement",       "count": 28     }   
},   {     "pass": false,     "data": {       "message": "Expected no error, got 
Invariant Violation: Expected value for identifier `15` to be initialized.",     
  "count": 14     }   },   {     "pass": false,     "data": {       "message": 
"Expected no error, got Invariant Violation: `var` declarations are not 
supported, use let or const",       "count": 76     }   },   {     "pass": true, 
    "data": {       "message": null,       "count": 1     }   } ] ```
2022-11-16 18:24:07 -05:00
Sebastian Markbåge
d65b88d031 Eagerly initialize an mutable object for instance.refs (#25696)
This micro-optimization never made sense and less so now that they're
rare.

This still initializes the class with a shared immutable object in the
constructor - which is also what createClass() does.

Then we override it during mount. This is done in case someone messes up
the initialization of the super() constructor for example, which was
more common in polyfills.

This change means that if a ref is initialized during the constructor
itself it wouldn't be lazily initialized but that's not user code that
does it, it's React so that shouldn't happen.

This makes string refs codemoddable as described in.
https://github.com/facebook/react/pull/25334
2022-11-16 15:16:54 -05:00
dependabot[bot]
db8a3fcc31 Bump loader-utils from 1.4.0 to 1.4.2 in /fixtures/fizz (#25680)
[//]: # (dependabot-start)
⚠️  **Dependabot is rebasing this PR** ⚠️ 

Rebasing might not happen immediately, so don't worry if this takes some
time.

Note: if you make any changes to this PR yourself, they will take
precedence over the rebase.

---

[//]: # (dependabot-end)

Bumps [loader-utils](https://github.com/webpack/loader-utils) from 1.4.0
to 1.4.2.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a
href="https://github.com/webpack/loader-utils/releases">loader-utils's
releases</a>.</em></p>
<blockquote>
<h2>v1.4.2</h2>
<h3><a
href="https://github.com/webpack/loader-utils/compare/v1.4.1...v1.4.2">1.4.2</a>
(2022-11-11)</h3>
<h3>Bug Fixes</h3>
<ul>
<li>ReDoS problem (<a
href="https://github-redirect.dependabot.com/webpack/loader-utils/issues/226">#226</a>)
(<a
href="17cbf8fa89">17cbf8f</a>)</li>
</ul>
<h2>v1.4.1</h2>
<h3><a
href="https://github.com/webpack/loader-utils/compare/v1.4.0...v1.4.1">1.4.1</a>
(2022-11-07)</h3>
<h3>Bug Fixes</h3>
<ul>
<li>security problem (<a
href="https://github-redirect.dependabot.com/webpack/loader-utils/issues/220">#220</a>)
(<a
href="4504e34c47">4504e34</a>)</li>
</ul>
</blockquote>
</details>
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a
href="https://github.com/webpack/loader-utils/blob/v1.4.2/CHANGELOG.md">loader-utils's
changelog</a>.</em></p>
<blockquote>
<h3><a
href="https://github.com/webpack/loader-utils/compare/v1.4.1...v1.4.2">1.4.2</a>
(2022-11-11)</h3>
<h3>Bug Fixes</h3>
<ul>
<li>ReDoS problem (<a
href="https://github-redirect.dependabot.com/webpack/loader-utils/issues/226">#226</a>)
(<a
href="17cbf8fa89">17cbf8f</a>)</li>
</ul>
<h3><a
href="https://github.com/webpack/loader-utils/compare/v1.4.0...v1.4.1">1.4.1</a>
(2022-11-07)</h3>
<h3>Bug Fixes</h3>
<ul>
<li>security problem (<a
href="https://github-redirect.dependabot.com/webpack/loader-utils/issues/220">#220</a>)
(<a
href="4504e34c47">4504e34</a>)</li>
</ul>
<p><!-- raw HTML omitted --><!-- raw HTML omitted --></p>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="331ad5067d"><code>331ad50</code></a>
chore(release): 1.4.2</li>
<li><a
href="17cbf8fa89"><code>17cbf8f</code></a>
fix: ReDoS problem (<a
href="https://github-redirect.dependabot.com/webpack/loader-utils/issues/226">#226</a>)</li>
<li><a
href="8f082b39f6"><code>8f082b3</code></a>
chore(release): 1.4.1</li>
<li><a
href="4504e34c47"><code>4504e34</code></a>
fix: security problem (<a
href="https://github-redirect.dependabot.com/webpack/loader-utils/issues/220">#220</a>)</li>
<li>See full diff in <a
href="https://github.com/webpack/loader-utils/compare/v1.4.0...v1.4.2">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=loader-utils&package-manager=npm_and_yarn&previous-version=1.4.0&new-version=1.4.2)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)
- `@dependabot use these labels` will set the current labels as the
default for future PRs for this repo and language
- `@dependabot use these reviewers` will set the current reviewers as
the default for future PRs for this repo and language
- `@dependabot use these assignees` will set the current assignees as
the default for future PRs for this repo and language
- `@dependabot use this milestone` will set the current milestone as the
default for future PRs for this repo and language

You can disable automated security fix PRs for this repo from the
[Security Alerts
page](https://github.com/facebook/react/network/alerts).

</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-11-16 13:19:42 -05:00
dependabot[bot]
355dd7d9dc Bump loader-utils from 2.0.0 to 2.0.4 in /fixtures/flight (#25694)
Bumps [loader-utils](https://github.com/webpack/loader-utils) from 2.0.0
to 2.0.4.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a
href="https://github.com/webpack/loader-utils/releases">loader-utils's
releases</a>.</em></p>
<blockquote>
<h2>v2.0.4</h2>
<h3><a
href="https://github.com/webpack/loader-utils/compare/v2.0.3...v2.0.4">2.0.4</a>
(2022-11-11)</h3>
<h3>Bug Fixes</h3>
<ul>
<li>ReDoS problem (<a
href="https://github-redirect.dependabot.com/webpack/loader-utils/issues/225">#225</a>)
(<a
href="ac09944dfa">ac09944</a>)</li>
</ul>
<h2>v2.0.3</h2>
<h3><a
href="https://github.com/webpack/loader-utils/compare/v2.0.1...v2.0.3">2.0.3</a>
(2022-10-20)</h3>
<h3>Bug Fixes</h3>
<ul>
<li><strong>security:</strong> prototype pollution exploit (<a
href="https://github-redirect.dependabot.com/webpack/loader-utils/issues/217">#217</a>)
(<a
href="a93cf6f470">a93cf6f</a>)</li>
</ul>
<h2>v2.0.2</h2>
<h3><a
href="https://github.com/webpack/loader-utils/compare/v2.0.1...v2.0.2">2.0.2</a>
(2021-11-04)</h3>
<h3>Bug Fixes</h3>
<ul>
<li>base64 generation and unicode characters (<a
href="https://github-redirect.dependabot.com/webpack/loader-utils/issues/197">#197</a>)
(<a
href="8c2d24ee40">8c2d24e</a>)</li>
</ul>
<h2>v2.0.1</h2>
<h3><a
href="https://github.com/webpack/loader-utils/compare/v2.0.0...v2.0.1">2.0.1</a>
(2021-10-29)</h3>
<h3>Bug Fixes</h3>
<ul>
<li>md4 support on Node.js v17 (<a
href="https://github-redirect.dependabot.com/webpack/loader-utils/issues/193">#193</a>)
(<a
href="1069f61284">1069f61</a>)</li>
</ul>
</blockquote>
</details>
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a
href="https://github.com/webpack/loader-utils/blob/v2.0.4/CHANGELOG.md">loader-utils's
changelog</a>.</em></p>
<blockquote>
<h3><a
href="https://github.com/webpack/loader-utils/compare/v2.0.3...v2.0.4">2.0.4</a>
(2022-11-11)</h3>
<h3>Bug Fixes</h3>
<ul>
<li>ReDoS problem (<a
href="https://github-redirect.dependabot.com/webpack/loader-utils/issues/225">#225</a>)
(<a
href="ac09944dfa">ac09944</a>)</li>
</ul>
<h3><a
href="https://github.com/webpack/loader-utils/compare/v2.0.1...v2.0.3">2.0.3</a>
(2022-10-20)</h3>
<h3>Bug Fixes</h3>
<ul>
<li><strong>security:</strong> prototype pollution exploit (<a
href="https://github-redirect.dependabot.com/webpack/loader-utils/issues/217">#217</a>)
(<a
href="a93cf6f470">a93cf6f</a>)</li>
</ul>
<h3><a
href="https://github.com/webpack/loader-utils/compare/v2.0.1...v2.0.2">2.0.2</a>
(2021-11-04)</h3>
<h3>Bug Fixes</h3>
<ul>
<li>base64 generation and unicode characters (<a
href="https://github-redirect.dependabot.com/webpack/loader-utils/issues/197">#197</a>)
(<a
href="8c2d24ee40">8c2d24e</a>)</li>
</ul>
<h3><a
href="https://github.com/webpack/loader-utils/compare/v2.0.0...v2.0.1">2.0.1</a>
(2021-10-29)</h3>
<h3>Bug Fixes</h3>
<ul>
<li>md4 support on Node.js v17 (<a
href="https://github-redirect.dependabot.com/webpack/loader-utils/issues/193">#193</a>)
(<a
href="1069f61284">1069f61</a>)</li>
</ul>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="6688b50281"><code>6688b50</code></a>
chore(release): 2.0.4</li>
<li><a
href="ac09944dfa"><code>ac09944</code></a>
fix: ReDoS problem (<a
href="https://github-redirect.dependabot.com/webpack/loader-utils/issues/225">#225</a>)</li>
<li><a
href="7162619fb9"><code>7162619</code></a>
chore(release): 2.0.3</li>
<li><a
href="a93cf6f470"><code>a93cf6f</code></a>
fix(security): prototype polution exploit (<a
href="https://github-redirect.dependabot.com/webpack/loader-utils/issues/217">#217</a>)</li>
<li><a
href="90c7c4be17"><code>90c7c4b</code></a>
chore(release): 2.0.2</li>
<li><a
href="8c2d24ee40"><code>8c2d24e</code></a>
fix: base64 generation and unicode characters (<a
href="https://github-redirect.dependabot.com/webpack/loader-utils/issues/197">#197</a>)</li>
<li><a
href="5fb5562084"><code>5fb5562</code></a>
chore(release): 2.0.1</li>
<li><a
href="1069f61284"><code>1069f61</code></a>
fix: md4 support on Node.js v17 (<a
href="https://github-redirect.dependabot.com/webpack/loader-utils/issues/193">#193</a>)</li>
<li>See full diff in <a
href="https://github.com/webpack/loader-utils/compare/v2.0.0...v2.0.4">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=loader-utils&package-manager=npm_and_yarn&previous-version=2.0.0&new-version=2.0.4)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)
- `@dependabot use these labels` will set the current labels as the
default for future PRs for this repo and language
- `@dependabot use these reviewers` will set the current reviewers as
the default for future PRs for this repo and language
- `@dependabot use these assignees` will set the current assignees as
the default for future PRs for this repo and language
- `@dependabot use this milestone` will set the current milestone as the
default for future PRs for this repo and language

You can disable automated security fix PRs for this repo from the
[Security Alerts
page](https://github.com/facebook/react/network/alerts).

</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-11-16 13:16:39 -05:00
Jan Kassens
c343f80254 [react-float] feature detect getRootNode (#25689)
Some old environments like IE11 or very old versions of jsdom are
missing `getRootNode()`. Use feature detection to fall back to
`ownerDocuments` in these environments that also won't be supporting
shadow DOM anyway.
2022-11-16 13:12:04 -05:00
Lauren Tan
9058797e6a Add test262 github action
Add a new workflow to run the test262 tests on commits to main but not in pull 
requests. This is to keep this test non-blocking on PRs but lets us track pass 
rates over time
2022-11-16 10:45:36 -05:00
Sebastian Markbåge
e1dd0a2f54 Remove recoverable error when a sync update flows into a dehydrated boundary (#25692)
This just removes the error but the underlying issue is still there, and
it's likely that the best course of action is to not update in effects
and to wrap most updates in startTransition. However, that's more of a
performance concern which is not something we generally do even in
recoverable errors since they're less actionable and likely belong in
another channel. It is also likely that in many cases this happens so
rarely because you have to interact quickly enough that it can often be
ignored.

After changes to other parts of the model, this only happens for
sync/discrete updates. There are three scenarios that can happen:
- We replace a server rendered fallback with a client rendered fallback.
Other than this potentially causing some flickering in the loading
state, it's not a big deal.
- We replace the server rendered content with a client side fallback if
this suspends on the client. This is in line with what would happen
anyway. We will loose state of forms which is not intended semantics.
State and animations etc would've been lost anyway if it was client-side
so that's not a concern.
- We replace the server rendered content with a client side rendered
tree and lose selection/state and form state. While the content looks
the same, which is unfortunate.

In most scenarios it's a bad loading state but it's the same scenario as
flushing sync client-side. So it's not so bad.

The big change here is that we consider this a bug of React that we
should fix. Therefore it's not actionable to users today because it
should just get fixed. So we're removing the error early. Although
anyone that has fixed these issues already are probably better off for
it.

To fix this while still hydrating we need to be able to rewind a sync
tree and then replay it.

@tyao1 is going to add a Sync hydration lane. This is will allow us to
rewind the tree when we hit this state, and replay it given the previous
Context, hydrate and then reapply the update. The reason we didn't do
this originally is because it causes sync mode to unwind where as for
backwards compatibility we didn't want to cause that breaking semantic -
outside Suspense boundaries - and we don't want that semantic longer
term. We're only do this as a short term fix.

We should also have a way to leave a partial tree in place. If the sync
hydration lane suspends, we should be able to switch to a client side
fallback without throwing away the state of the DOM and then hydrate
later.

We now know how we want to fix this longer term. We're going to move all
Contexts into resumable trees like what Fizz/Flight does. That way we
can leave the original Context at the hydration boundaries and then
resume from there. That way the rewinding would never happen even in the
existence of a sync hydration lane which would only apply locally to the
dehydrated tree.

So the steps are 1) remove the error 2) add the sync hydration lane with
rewinding 3) Allow hiding server-rendered content while still not
hydrated 4) add resumable contexts at these boundaries.

Fixes #25625 and #24959.
2022-11-15 22:10:54 -05:00
Joe Savona
4a21bb8856 Infer sets of variables in each reactive scope
Adds a new pass `InferReactiveScopeVariables` which determines the sets of 
variables (by Identifier) which "construct together" and belong in the same 
reactive scope. Concretely, `Identifier` gets a new property `scope: ScopeId`, 
and this pass assigns each identifier a ScopeId value. The algorithm iterates 
over all instructions in all blocks (in a single pass) and builds up disjoint 
sets of identifiers that appear as mutable operands in the same instruction. 

The algorithm is relatively simple (especially since I had already implemented a 
union-find data structure): however looking at some examples reinforced that 
other planned todos around alias analysis are really important. We also have to 
think more about what "mutable lifetime" means in the context of SSA: currently 
variables that are reassigned (but never "mutated", eg bc they're assigned a 
value type) never appear as mutable.
2022-11-15 14:26:18 -08:00
Lauren Tan
e6956bd4d8 [ez] Remove test262-all script
Just realized we can run all tests without encountering the arg limit if a 
string is passed in. 

This is much better because the test runner will count all tests in the parent 
test directory rather than run the tests in each subdirectory
2022-11-15 17:01:28 -05:00
Lauren Tan
dff31d80eb [ez] Don't output the command when running test262
Currently yarn prints out the command prior to executing it which makes test 
output for test262 very verbose
2022-11-15 14:06:49 -05:00
Lauren Tan
ec64edae21 Create identifier for any global or unscoped variable
Noticed this while running test262 tests that many variables were throwing an 
invariant for being undefined. This includes things like the special `arguments` 
object, a global `assert` function used by test262, etc.
2022-11-15 13:32:53 -05:00
Lauren Tan
9027117c4f Scaffolding for test262
- Adds a shallow git submodule for test262 as the tests aren't available   as an 
npm module - To run all tests: `yarn test262:all`. Note that this chunks up the  
 tests by test262 folder as there are over 50k+ tests and the test harness only 
accepts arrays of filepaths which exceeds arg limits - To run a specific test: 
`yarn test262 test262/test/folder/file.js`.   You can also pass globs which 
expand into an array of filepaths: `yarn test262 test262/test/folder/**/*.js` - 
More instructions for the test-harness can be found here: 
https://github.com/bterlson/test262-harness
2022-11-15 13:24:14 -05:00
Joseph Savona
e149413057 Distinguish identifier id and ssa id
I noticed on @kassens's #771 that despite running LeaveSSA there are still cases 
where we still reassign to a unique identifier: functions that have reassignment 
but no phi nodes, such as: 

```javascript 

function foo() { 

let x$1 = 0; 

x$2 = x$1 + 1; 

} 

``` 

Here SSA form rewrote the second statement's LHS, but bc there's no phi node we 
can't recover what the original was supposed to be (`x = x + 1`). This was my 
oversight when suggesting the simpler LeaveSSA algorithm, it works for 
eliminating phis but not other reassignments. The only alternative to removing 
SSA form is to add assignment statements, which we obviously don't want to do 
since that generates bloat. 

This PR addresses the issue by adding an additional, optional property to 
`Identifier` called `preSsaId` that starts off null. When entering SSA we save 
the original id in this property and update id to a new SSA value. LeaveSSA does 
the inverse, setting id = preSsaId and nulling out the latter. This means that 
an identifier can always be uniquely identified by its `id` value at any point 
in the compiler, while it's trivial to correctly undo SSA form. 

```typescript 

type Identifier = { 

// Unique value for each original identifier 

id: IdentifierId; 

// The original, un-mangled variable name if this was a variable present in the 
source (null if it's generated) 

name: string | null; 

// When in SSA mode, this is set to the original, pre-SSA `id` value 

preSsaId: IdentifierId | null; 

} 

```
2022-11-15 10:36:54 -08:00
Jan Kassens
5f40a1bf75 [bug] fix codegen for LVals with memberPath (#772) 2022-11-14 11:35:47 -05:00
Jan Kassens
99181160d5 [hir] implement assignment expressions
Implements assignment expressions with operators other than `=` (such as `+=`) 
by lowering to an assignment. 

I think this isn't fully correct for something like `a.b.c += 1`, but it seems 
like there's more gaps in object accesses.
2022-11-14 10:58:55 -05:00
Lauren Tan
0c5fc52c47 Refactor VisualizeHIRMermaid
- Get rid of `indent` as it was making the code hard to read - Remove 
unnecessary 2nd iteration over blocks - Remove extra newline between the bb 
subgraphs and the jumps section - Remove trailing spaces - Remove newlines 
between each subgraph and jump
2022-11-13 16:07:53 -05:00
Jan Kassens
d9724c7e00 [playground] option to codegen output in HIR tab
We might need to revisit the tabs vs. options split, but for now this just adds 
a checkbox toggle that outputs codegenned JS instead of HIR in the HIR tab. Open 
to ideas to organize this in the future...
2022-11-13 11:00:29 -05:00
Mengdi Chen
c54e3541b2 [DevTools] bug fix for Hydrating fibers (#25663)
## Summary

This PR is to fix a bug: an "element cannot be found" error when
hydrating Server Components

### The problem
<img width="1061" alt="image"
src="https://user-images.githubusercontent.com/1001890/201206046-ac32a5e3-b08a-4dc2-99f4-221dad504b28.png">

To reproduce:
1. setting up a vercel next.js 13 playground locally
https://github.com/vercel/app-playground
2. visit http://localhost:3000/loading
3. click "electronics" button to navigate to
http://localhost:3000/loading/electronics to trigger hydrating
4. inspect one of the skeleton card UI from React DevTools extension

### The root cause & fix
This bug was introduced in #22527. When syncing reconciler changes, the
value of `Hydrating` was copied from another variable `Visibility` (one
more zero in the binary number).
To avoid this kind of issue in the future, a new file `ReactFiberFlags`
is created following the same format of the one in reconciler, so that
it's easier to sync the number without making mistakes.
The reconciler fiber flag file is also updated to reflect which of the
flags are used in devtools

## How did you test this change?

I build it locally and the bug no longer exist on
http://localhost:3000/loading
2022-11-11 15:18:06 -05:00
Jan Kassens
16430247a4 [playground] remove unused dependency next-transpile-modules (#768) 2022-11-11 12:27:28 -05:00
Jan Kassens
3fd88b7f6f [playground] fixup for TS error 2022-11-11 12:18:18 -05:00
Jan Kassens
b9ffb59478 [playground] remove multi-file support and preview (#767) 2022-11-11 12:11:08 -05:00
Lauren Tan
3b3107fb3e Add Mermaid visualizations for CFG into fixtures
This PR adds a new section to fixture tests, which renders the HIR into 

a visualization using mermaid.js syntax which can then be embedded 

directly into markdown. 

The nice thing about the mermaid syntax is that it's quite readable, so 

if desired we could replace the current basic block textual output with 

the mermaid block. I'm opting to append it for now and wait for feedback 

if we want to keep both or replace. 

To view the graphs in your editor, download an extension that 

adds mermaid.js support: 
https://mermaid-js.github.io/mermaid/#/integrations?id=editor-plugins. In vscode 
you can use this plugin by right clicking on "Open Preview" on any expect.md 
file. No extra dependencies are required for GitHub which should have builtin 
support for mermaid in markdown
2022-11-10 17:09:28 -05:00
Jan Kassens
779947520d [playground] new HIR tab
Instead of hacking into the babel plugin passes, this now takes a new approach 
for the HIR tab: 

- The different passes are exported from the babel plugin (for simplicity) 

- The tab actually runs the compiler steps based on local config in the tab. 

- Re-purposed the CompilerFlags component to configure what passes to run. This 
is currently mostly causing different errors, but could be useful going forward 
as a direction.
2022-11-10 15:45:51 -05:00
Jan Kassens
5e86e6a9c8 [playground] refactor output tabs
Removes a bit of indirection and opens the way to more easily customize specific 
tabs.
2022-11-10 14:32:40 -05:00
Jan Kassens
21b6112238 Fix yarn dev to run tsc watch mode
The `--watch` argument forwarding wasn't working anymore because `yarn build` 
doesn't have the `tsc` command at the end anymore. There's maybe something that 
can be done to forward the watch argument, just call `tsc --watch` directly.
2022-11-10 11:30:45 -05:00
Samuel Susla
d1e35c7039 Don't disappear layout effects unnecessarily (#25660)
Nested Offscreens can run into a case where outer Offscreen is revealed
while inner one is hidden in a single commit. This is an edge case that
was previously missed. We need to prevent call to disappear layout
effects.

When we go from state:
```jsx
<Offscreen mode={'hidden'}> // outer offscreen
  <Offscreen mode={'visible'}> // inner offscreen
    {children}
  </Offscreen>
</Offscreen>
```

To following. Notice that visibility of each offscreen flips.

```jsx
<Offscreen mode={'visible'}> // outer offscreen
  <Offscreen mode={'hidden'}> // inner offscreen
    {children}
  </Offscreen>
</Offscreen>
```

Inner offscreen must not call
`recursivelyTraverseDisappearLayoutEffects`.
Check unit tests for an example of this.
2022-11-10 14:49:30 +00:00
Joe Savona
f57bcacced fix for while (...) { break } edge case
Small adjustment to the previous PR for a special case: 

```javascript 

while (cond) { 

break; 

} 

``` 

The loop body is an indirection to the fallthrough, so shrink() collapses that 
and makes the while.loop === while.fallthrough. We now detect that this is the 
case in codegen and correctly emit a `break` rather than trying to write the 
fallthrough block inside the loop.
2022-11-09 20:52:08 -08:00
Joe Savona
656b8c9a0e While terminal and codegen
Adds a new 'while' terminal variant, which will be a model for other loop 
terminals, and adds support for the entire compilation pipeline through codegen. 
To understand the structure of the terminal consider this input: 

```javascript 

let x = 0; 

while (x) { 

x = foo(x); 

} 

return x; 

``` 

We currently lower this to ifs and gotos: 

``` 

bb0: precursor to loop 

let x = 0; 

goto(break) bb1; // <-- **The new terminal replaces this** 

bb1: test block, whether to (re-)enter the loop 

if (x) consequent=bb2 alternate=bb3; 

bb2: loop body 

x = foo(x); 

goto(continue) bb1; 

bb3: fallthrough after the loop 

return x 

``` 

This representation correctly models the semantics of while statements, but 
loses the high-level information that there was a loop. The new 'while' terminal 
replaces the first 'goto(break) bb1'. Conceptually, the 'while' terminal means 
"enter the starting point of a while loop". In this example the terminal would 
look like this: 

``` 

{ 

kind: 'while', 

testBlock: 'bb1', // the basic block that checks whether to enter the loop or 
not 

loop: 'bb2', // the block containing the loop body 

fallthrough: 'bb3' // the block that goes after the loop 

} 

``` 

Most passes will only look at 'testBlock', ie they will treat this terminal as a 
simple goto:testBlock. However, codegen uses the full information in the 
terminal to reconstruct the loop. My previous PR, #755, added a mechanism to be 
smart about when to emit or not emit `break` statements; this PR improves upon 
that to accurately emit the minimal break and continue statements: ie omitting 
entirely where they are extraneous, emitting unlabeled break/continue when 
sufficient, and falling back to labeled break/continue only where strictly 
necessary. The logic is very much analogous to IR construction.
2022-11-09 16:39:50 -08:00
Lauren Tan
90aa627c6b Add LeaveSSA pass to DumpHIRPass 2022-11-09 17:31:00 -05:00
Lauren Tan
e64ef9e1e0 Extract eachBlockOperand to its own visitor
Follow up for #757: 

- Adds a new visitor which iterates over every Place within a BasicBlock - 
Remove unused entryBlock binding - Comments
2022-11-09 16:37:14 -05:00
Lauren Tan
74e6ffc4a2 Leave SSA form
Alternative approach to #750. We now store the original identifier on the Phi 
node, then rewrite every BasicBlock's identifiers to reference the original id 
instead of the SSA'd id. 

This solves the shadowing problem and also lets us omit adding copies of 
instructions.
2022-11-09 15:12:04 -05:00
Joe Savona
ea1a18ec16 Emit labeled ifs/switch/break; gen each block exactly once
The approach is very similar to what BuildHIR does to resolve break and continue 
targets during IR construction: 

* We annotate goto targets as either a break or a continue (during HIR 
construction). This is necessary to reconstruct the right kind in codegen. 

* Codegen continues to work by traversing the IR as if it were a tree, relying 
on the `fallthrough` branches of if/switch to be able to visit the 
consequent/alternate recursively and then emit the fallthrough branch. 

* We track a Set of blocks that are scheduled to be emitted by some parent in 
the tree. Nested ifs may all have the same fallthrough branch, which we only 
want to emit once. This set helps us to know that a parent is already going to 
emit some block, such that children can skip it. 

* We also keep a stack of break targets that are in scope, and use this to 
convert gotos appropriately, as either a break, continue, or nothing at all (for 
example a switch case that falls through has no explicit syntax to model this 
fall-through, the only option is to emit nothing for the goto). 

* Then, if/switch have to carefully check whether each branch should be emitted 
or not. For example, if the alternate is already scheduled to be emitted (by a 
parent), then we emit a block with a break statement instead. 

* Switch in particular is tricky, because we need to know that subsequent cases 
are scheduled, but only for preceding blocks. So we visit the cases in reverse 
order (not surprisingly, we do the same thing during IR construction for similar 
reasons!). 

The bookkeeping is a bit finicky but this works reliably. There are some cases 
where we could try to emit an unlabeled break instead of a labeled break, or 
avoid emitting a label at all (if nothing will explicitly break to that label), 
but overall the generated code is readable enough that i'm inclined to ship and 
iterate. I'm open to feedback though, as always!
2022-11-08 21:14:10 -08:00
Joe Savona
22d1481125 Add and use mapInstructionOperands() 2022-11-08 14:46:03 -08:00
Joe Savona
afabaa0af3 Add and use mapTerminalOperands() 2022-11-08 14:45:59 -08:00
Joe Savona
2a049044bb Add and use eachTerminalSuccessor() 2022-11-08 14:45:56 -08:00
Joe Savona
e665f6b877 Cleanup in advance of reworking codegen 2022-11-08 14:45:53 -08:00
Jan Kassens
e336ea44ed [playground] include HIR output (#756) 2022-11-09 13:39:50 -05:00
Aurélien Chivot-Buhler
1e3e30dae2 Fix useSyncExternalStore dropped update when state is dispatched in render phase (#25578)
Fix https://github.com/facebook/react/issues/25565
2022-11-08 11:25:42 +01:00
Lauren Tan
f8f4dc4b8b s/SSAify/Enter SSA/
Rename this existing pass to make more sense with the next PR
2022-11-07 18:34:45 -05:00
Jan Kassens
5bd3a39d86 Implement HIR visitors (#747) 2022-11-08 09:55:35 -05:00
Jan Kassens
7c094af34e [HIR] fix missing read reference to switch test value
Unless I'm mistaken, the switch operand is missing here.
2022-11-07 16:38:58 -05:00
Mengdi Chen
18dff7990a [DevTools] add support for HostSingleton & HostResource (#25616)
## Summary

This is to support two new reconciler work tags `HostSingleton` and
`HostResource` introduced in PRs #25243 #25426. The behavior is
described below.
I also renamed an option in components settings from an internal concept
"host" to more understood "dom nodes"

## How did you test this change?

Tested on the latest Vercel playground app
https://github.com/vercel/app-playground/

Before the change, devtools cannot show correct display name for these
new elements. Also, some unnecessary internal details are exposed to
users.
<img width="1395" alt="image"
src="https://user-images.githubusercontent.com/1001890/199578181-c4e4ea74-baa1-4507-83d0-91a62ad7de5f.png">

After the change, the display names are correctly shown and the "state"
would always be hidden in the detail view.
<img width="1417" alt="image"
src="https://user-images.githubusercontent.com/1001890/199578442-adc1951d-7d5b-4b84-ad64-85bcf7a8ebcc.png">

These elements will also be hidden just like other native dom elements
(e.g. `<div>`)
<img width="836" alt="image"
src="https://user-images.githubusercontent.com/1001890/199578598-2dfacf64-ddc9-42b5-a246-dd0b09f629af.png">
2022-11-07 15:23:17 -05:00
Jan Kassens
5d81fdeb5f [easy] use yield* in eachInstructionOperand
Noticed we could simplify this code a bit using `yield*`.
2022-11-07 15:10:49 -05:00
Sathya Gunasekaran
69cce3d51f [hir][be] Move collectInputs to HIRBuilder
This seems like a better place to put helper methods.
2022-11-07 18:45:29 +00:00
Lauren Tan
4d9022a17c Remove early SSA phi optimzation
Reverts #726 which added an early optimization to the SSAify pass in skipping 
over phi creation if only one unique operand. This is no longer necessary with 
the addition of a phi elimination pass added in #739.
2022-11-07 12:25:50 -05:00
Joseph Savona
3a200fa4a1 Pass to eliminate redundant phis
This is an alternate take on phi elimination to the one we pursued over VC w 
@poteto driving. This version exploits the RPO ordering of blocks to do phi 
elimination in a single pass when there are no loops, and to minimize repeated 
visits when there are loops. The main difference is when redundant phis are 
removed. Rather than eagerly walking through the CFG for each pruned phi to 
rewrite its uses, we build up a mapping of rewritten identifiers. As we walk 
through subsequent instructions, we rewrite each place based on that mapping. We 
continue cycling through the blocks so long as a given iteration *both* added 
new rewrites (meaning there may be subsequent uses to rewrite) *and* there are 
back-edges. With no loops this results in a single visit of each block and of 
each instruction, but even with loops this is bounded.
2022-11-07 08:37:19 -08:00
Samuel Susla
4bd245e9ee Do not unmount layout effects if ancestor Offscreen is hidden (#25628)
This is a follow up on https://github.com/facebook/react/pull/25592

There is another condition Offscreen calls
`recursivelyTraverseDisappearLayoutEffects` when it shouldn't. Offscreen
may be nested. When nested Offscreen is hidden, it should only unmount
layout effects if it meets following conditions:
1. This is an update, not first mount.
2. This Offscreen was hidden before.
3. No ancestor Offscreen is hidden.

Previously, we were not accounting for the third condition.
2022-11-04 13:31:07 +00:00
Andrew Clark
df61e708c8 Remove check in renderDidSuspendDelayIfPossible (#25630)
I don't think we need this anymore. It was added originally because
RootSuspended would take priority over RootSuspendedWithDelay. But we've
since changed it: any "bad" fallback state is permitted to block a
"good" fallback state.

The other status flags that this check used to account for are
RootDidNotComplete and RootFatalErrored:

- RootFatalErrored is like an invariant violation, it means something
went really wrong already and we can't recover from it
- RootCompleted and RootDidNotComplete are only set at the very end of
the work loop, there's no way for renderDidSuspendDelayIfPossible to
sneak in after that (at least none that I can think of — it's only
called from the render phase)

So I think we can just delete this.

It's entirely possible there's some scenario I haven't considered,
though, which is why I'm submitting this change as its own PR. To
preserve the ability to bisect to it later.
2022-11-03 16:15:55 -04:00
mofeiZ
1a08f1478d [ServerRenderer] Move fizz external runtime implementation to react-dom-bindings (#25617)
<!--
  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
-->

Following
[comment](https://github.com/facebook/react/pull/25437#discussion_r1010944983)
in #25437 , the external runtime implementation should be moved from
`react-dom` to `react-dom-bindings`.

I did have a question here:
I set the entrypoint to `react-dom/unstable_server-external-runtime.js`,
since a.) I was following #25436 as an example and b.)
`react-dom-bindings` was missing a `README.md` and `npm/`. This also
involved adding the external runtime to `package.json`.
However, the external runtime isn't really a `react-dom` entrypoint. Is
this change alright, or should I change the bundling code instead?
## 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.
-->
2022-11-03 11:15:29 -04:00
Andrew Clark
1a902623a8 Unwrap sync resolved thenables without suspending (#25615)
If a thenable resolves synchronously, `use` should unwrap its result
without suspending or interrupting the component's execution.
2022-11-02 13:53:23 -04:00
Josh Story
4ea063b56f refactor isHostResourceType to not receive the context from reconciler and not leak types (#25610)
type validateDOMNesting
move `isHostResourceType` to ReactDOMHostConfig
type `AncestorInfo`
refactor `resourceFormOnly` into `ancestorInfo.containerTagInScope`
provide hostContext from reconciler
2022-11-01 17:14:46 -07:00
Sebastian Markbåge
8e69bc45aa Make host context use null as empty and only error in dev (#25609)
Makes it slightly more blazing.

No host config actually uses null as any useful and we use this as a
placeholder value anyway. It's also better for perf since it doesn't let
two different hidden classes pass around. It's also a magic place holder
that triggers error if we do try to access anything from it.
2022-11-01 19:02:37 -04:00
Josh Story
5f7ef8c4cb [Float] handle resource Resource creation inside svg context (#25599)
`title` is a valid element descendent of `svg`. this PR adds a
prohibition on turning titles in svg into Resources.

This PR also adds additional warnings if you render something that is
almost a Resource inside an svg.
2022-11-01 14:57:45 -07:00
Andrew Clark
36426e6cb6 Allow uncached IO to stablize (#25561)
Initial draft. I need to test this more.

If a promise is passed to `use`, but the I/O isn't cached, we should
still be able to unwrap it.

This already worked in Server Components, and during SSR.

For Fiber (in the browser), before this fix the state would get lost
between attempts unless the promise resolved immediately in a microtask,
which requires IO to be cached. This was due to an implementation quirk
of Fiber where the state is reset as soon as the stack unwinds. The
workaround is to suspend the entire Fiber work loop until the promise
resolves.

The Server Components and SSR runtimes don't require a workaround: they
can maintain multiple parallel child tasks and reuse the state
indefinitely across attempts. That's ideally how Fiber should work, too,
but it will require larger refactor.

The downside of our approach in Fiber is that it won't "warm up" the
siblings while you're suspended, but to avoid waterfalls you're supposed
to hoist data fetches higher in the tree regardless. But we have other
ideas for how we can add this back in the future. (Though again, this
doesn't affect Server Components, which already have the ideal
behavior.)
2022-11-01 15:00:34 -04:00
mofeiZ
6883d79445 [ServerRenderer] Setup for adding data attributes streaming format (#25567) 2022-11-01 12:04:50 -04:00
Samuel Susla
ab075a2324 Do not unmount layout effects on initial Offscreen mount (#25592)
`wasHidden` is evaluted to false if `current` is null. This means
Offscreen has never been shown but this code assumes it is going from
'visible' to 'hidden' and unmounts layout effects.
To fix this, only unmount layout effects if `current` is not null.

I'm not able to repro this problem or write unit test for it. I see this
crash bug in production test.
The problem with repro is that if Offscreen starts as hidden, it's
render is deferred and current is no longer null.
2022-11-01 15:11:28 +00:00
Sebastian Markbåge
765805bf88 Fix type check for null (#25595) 2022-10-31 17:29:01 -04:00
Andrew Clark
2ac77aab94 Clean up vestige of useOpaqueIdentifier (#25587)
Found some code that was left over from the experimental
useOpaqueIdentifier hook, which we eventually replaced with useId.

This deletes it.
2022-10-29 20:46:54 -04:00
Andrew Clark
bdd3d0807c Extract logic for detecting bad fallback to helper
Pure refactor, no change in behavior.

Extracts the logic for detecting whether a suspended component will
result in a "bad" Suspense fallback into a helper function. An example
of a bad Suspense fallback is one that causes already-visible content
to disappear.

I want to reuse this same logic in the work loop, too.
2022-10-28 17:19:45 -07:00
Andrew Clark
952dfff3f1 Split suspended work loop logic into separate functions
Refactors the logic for handling when the work loop is suspended into
separate functions for replaying versus unwinding. This allows us to
hoist certain checks into the caller.

For example, when rendering due to flushSync, we will always unwind the
stack without yielding the microtasks.

No intentional behavior change in this commit.
2022-10-28 17:19:45 -07:00
Andrew Clark
d2c0ab10de In work loop, add enum of reasons for suspending
This is a pure refactor, no change to behavior.

When a component throws, the work loop can handle that in one of several
ways — unwind immediately, wait for microtasks, and so on. I'm about
to add another one, too. So I've changed the variable that tracks
whether the work loop is suspended from a boolean
(workInProgressIsSuspended) to an enum (workInProgressSuspendedReason).
2022-10-28 17:19:45 -07:00
Andrew Clark
5450dd4098 Strict Mode: Reuse memoized result from first pass (#25583)
In Strict Mode, during development, user functions are double invoked to
help detect side effects. Currently, the way we implement this is to
completely discard the first pass and start over. Theoretically this
should be fine because components are idempotent. However, it's a bit
tricky to get right because our implementation (i.e. `renderWithHooks`)
is not completely idempotent with respect to internal data structures,
like the work-in-progress fiber. In the past we've had to be really
careful to avoid subtle bugs — for example, during the initial mount,
`setState` functions are bound to the particular hook instances that
were created during that render. If we compute new hook instances, we
must also compute new children, and they must correspond to each other.

This commit addresses a similar issue that came up related to `use`:
when something suspends, `use` reuses the promise that was passed during
the first attempt. This is itself a form of memoization. We need to be
able to memoize the reactive inputs to the `use` call using a hook (i.e.
`useMemo`), which means, the reactive inputs to `use` must come from the
same component invocation as the output.

The solution I've chosen is, rather than double invoke the entire
`renderWithHook` function, we should double invoke each individual user
function. It's a bit confusing but here's how it works:

We will invoke the entire component function twice. However, during the
second invocation of the component, the hook state from the first
invocation will be reused. That means things like `useMemo` functions
won't run again, because the deps will match and the memoized result
will be reused.

We want memoized functions to run twice, too, so account for this, user
functions are double invoked during the *first* invocation of the
component function, and are *not* double invoked during the second
incovation:

- First execution of component function: user functions are double
invoked
- Second execution of component function (in Strict Mode, during
development): user functions are not double invoked.

It's hard to explain verbally but much clearer when you run the test
cases I've added.
2022-10-28 17:46:20 -04:00
Andrew Clark
d2a0176a13 Detect and warn if use(promise) is wrapped with try/catch block (#25543)
The old (unstable) mechanism for suspending was to throw a promise. The
purpose of throwing is to interrupt the component's execution, and also
to signal to React that the interruption was caused by Suspense as
opposed to some other error.

A flaw is that throwing is meant to be an implementation detail — if
code in userspace catches the promise, it can lead to unexpected
behavior.

With `use`, userspace code does not throw promises directly, but `use`
itself still needs to throw something to interrupt the component and
unwind the stack.

The solution is to throw an internal error. In development, we can
detect whether the error was caught by a userspace try/catch block and
log a warning — though it's not foolproof, since a clever user could
catch the object and rethrow it later.

The error message includes advice to move `use` outside of the try/catch
block.

I did not yet implement the warning in Flight.
2022-10-28 17:46:03 -04:00
Sebastian Markbåge
cf3932be5c Remove old react-fetch, react-fs and react-pg libraries (#25577)
To avoid confusion. We are patching `fetch`, and only `fetch`, for a
small fix scoped to react renders elsewhere, but this code is not it.

This code was for the strategy used in the original [React Server
Components demo](https://github.com/reactjs/server-components-demo).
Which [we
announced](https://reactjs.org/blog/2022/06/15/react-labs-what-we-have-been-working-on-june-2022.html)
that we're moving away from in favor of [First class support for
promises and async/await](https://github.com/reactjs/rfcs/pull/229).

We might explore using these package for other instrumentation in the
future but not now and not like this.
2022-10-27 17:52:53 -04:00
Sebastian Markbåge
28a574ea8f Try assigning fetch to globalThis if global assignment fails (#25571)
In case it's a more modern yet rigid environment.
2022-10-27 02:43:17 -04:00
Josh Story
09def5990b [Float] handle noscript context for Resources (#25559)
stacked on https://github.com/facebook/react/pull/25569

On the client noscript already never renders children so no resources
will be extracted from this context. On the server we now track if we
are in a noscript context and turn off Resource semantics in this scope
2022-10-26 23:11:31 -07:00
Josh Story
17204056d5 [Float] fix coordination of resource identity and hydration (#25569)
there are a few bugs where dom representations from SSR aren't
identified as Resources when they should be.

There are 3 semantics

Resource -> hoist to head, deduping, etc...
hydratable Component -> SSR'd and hydrated in place
non-hydratable Component -> never SSR'd, never hydrated, always inserted
on the client

this last category is small
(non stylesheet) links with onLoad and/or onError
async scripts with onLoad and/or onError

The reason we have this distinction for now is we need every SSR'd async
script to be assumable to be a Resource. we don't currently encode
onLoad on the server and so we couldn't otherwise tell if an async
script is a Resource or is an async script with an onLoad which would
not be a resource. To avoid this ambiguity we never emit the scripts in
SSR and assume they need to be inserted on the client.

We can explore changes to these semantics in the future or possibly
encode some identifier when we want to opt out of resource semantics but
still SSR the link or script.
2022-10-26 19:53:29 -07:00
Robert Balicki
fecc288b7d [react devtools] Device storage support (#25452)
# Summary
* This PR adds support for persisting certain settings to device
storage, allowing e.g. RN apps to properly patch the console when
restarted.
* The device storage APIs have signature `getConsolePatchSettings()` and
`setConsolePatchSettings(string)`, in iOS, are thin wrappers around the
`Library/Settings` turbomodule, and wrap a new TM that uses the `SharedPreferences` class in Android.
* Pass device storage getters/setters from RN to DevTools'
`connectToDevtools`. The setters are then used to populate values on
`window`. Later, the console is patched using these values.
* If we receive a notification from DevTools that the console patching
fields have been updated, we write values back to local storage.
* See https://github.com/facebook/react-native/pull/34903

# How did you test this change?
Manual testing, `yarn run test-build-devtools`, `yarn run prettier`,
`yarn run flow dom`

## Manual testing setup:

### React DevTools Frontend
* Get the DevTools frontend in flipper:
* `nvm install -g react-devtools-core`, then replace that package with a
symlink to the local package
  * enable "use globally installed devtools" in flipper
* yarn run start in react-devtools, etc. as well

### React DevTools Backend
* `yarn run build:backend` in react-devtools-core, then copy-paste that
file to the expo app's node_modules directory

### React Native
* A local version of React Native can be patched in by modifying an expo
app's package.json, as in `"react-native":
"rbalicki2/react-native#branch-name"`

# Versioning safety
* There are three versioned modules to worry about: react native, the
devtools frontend and the devtools backend.
* The react devtools backend checks for whether a `cachedSettingsStore`
is passed from react native. If not (e.g. if React Native is outdated),
then no behavior changes.
* The devtools backend reads the patched console values from the cached
settings store. However, if nothing has been stored, for example because
the frontend is outdated or has never synced its settings, then behavior
doesn't change.
* The devtools frontend sends no new messages. However, if it did send a
new message (e.g. "store this value at this key"), and the backend was
outdated, that message would be silently ignored.
2022-10-25 13:25:33 +11:00
Josh Story
d925a8d0be Flight client error stack (#25560)
restore error message into stack for flight prod errors
2022-10-24 16:32:33 -07:00
Leo Lamprecht
996b00b787 [Tiny] Fixed incorrect import in react-server-dom-webpack (#25554)
<!--
  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

In https://github.com/facebook/react/pull/25504,
`react-server-dom-webpack/` was deprecated in favor of
`react-server-dom-webpack/client`, but a remaining import wasn't
adjusted accordingly.

As a result, the remaining conditions within the file are no longer
firing appropriately, which I ran into while playing around with a fork
of
[server-components-demo](https://github.com/reactjs/server-components-demo).

The `index.js` file now contains a
[placeholder](https://github.com/facebook/react/blob/main/packages/react-server-dom-webpack/index.js)
and the actual logic of the client now sits in `/client`.

## How did you test this change?

I replaced `require.resolve('../')` with `require.resolve('../client')`
in the `react-server-dom-webpack` package in `node_modules` and
confirmed that the output of the build looked good again.
2022-10-24 10:40:18 -07:00
Sebastian Markbåge
e7c5af45ce Update cache() and use() to the canary aka next channel (#25502)
Testing what it would look like to move this to the `next` channel.
2022-10-23 23:20:52 -04:00
Andrew Clark
fa77f52e74 Unify promise switch statements
There are two different switch statements that we use to unwrap a
`use`-ed promise, but there really only needs to be one. This was a
factoring artifact that arose because I implemented the yieldy `status`
instrumentation thing before I implemented `use` (for promises that are
thrown directly during render, which is the old Suspense pattern that
will be superseded by `use`).
2022-10-23 18:43:30 -04:00
Andrew Clark
7572e4931f Track thenable state in work loop
This is a refactor to track the array of thenables that is preserved
across replays in the work loop instead of the Thenable module.

The reason is that I'm about to add additional state to the Thenable
module that is specific to a particular attempt — like the current
index — and is reset between replays. So it's helpful to keep the two
kinds of state separate so it's clearer which state gets reset when.

The array of thenables is not reset until the work-in-progress either
completes or unwinds.

This also makes the structure more similar to Fizz and Flight.
2022-10-23 18:43:30 -04:00
Andrew Clark
7fc3eefd85 Revert yieldy behavior for non-use Suspense (in Flight, too)
Same as #25537 but for Flight.

I was going to wait to do this later because the temporary
implementation of async components uses some of the same code that
non-used wakables do, but it's not so bad. I just had to inline one bit
of code, which we'll remove when we unify the implementation with `use`.
2022-10-23 18:43:30 -04:00
Robert Zhang
2c37aa78d3 [Playground] Style compiler options editor
This diff adds styling to the compiler options editor. The floating input/output 
toggle button on small screens now spans the bottom of the screen, so that it 
doesn't block the compiler options. 

Height overflows when adjusting screen size are complicated by Monaco Editor and 
will be addressed in a later diff. 

Test plan: 

Start Playground and see the latest look of the compiler options editor beneath 
the output section.
2022-10-23 18:33:39 -04:00
Lauren Tan
22cbd97fe5 Update outdated package.json repo url 2022-11-04 18:13:47 -04:00
Lauren Tan
285b7e7acb Update outdated fixture snapshots 2022-11-04 17:59:04 -04:00
Joseph Savona
24ea3fa4bc Support JSX fragments (#736)
* handle jsx fragments

* update effects for jsx fragments
2022-11-04 11:16:50 -07:00
Sathya Gunasekaran
871a171a1f [hir] Add InferMutableRange pass 2022-11-04 16:39:45 +00:00
Sathya Gunasekaran
c75a1fe6bb [hir] Add MutableRange to Identifier 2022-11-04 16:39:45 +00:00
Sathya Gunasekaran
e69888054c [hir] Add id to number Instruction 2022-11-04 16:39:44 +00:00
Sathya Gunasekaran
e015bf6a7b [test] Add pragma parsing to test runner 2022-11-04 16:39:43 +00:00
Joseph Savona
5f81b7bc30 Replace NodePath with SourceLocation
Removes all the `path: NodePath` values from various IR node types, replacing 
them with `loc: SourceLocation`. This type is an alias for babel's source 
location type plus a "generated" variant. The "OtherStatement" kind also used 
the `path` to print back the original AST (since we don't look into these); 
instead, we now capture the underlying `node` and emit that as-is during 
codegen. 

While I was doing this, i also fixed up the places where we had passed a null 
path; the vast majority have a clear place we can pull a location from. For 
example, `a ?? b` syntax creates some places/instructions for the `a != null`, 
but those can all point back to the `a` location.
2022-11-04 08:55:18 -07:00
Lauren Tan
a9419099b4 Allow fixture tests to be only or skip
This commit introduces a small update to our fixture tests to allow certain jest 
`test` modifiers to be added to fixture tests via a leading prefix in the 
fixture name. 

For example, `only.my-fixture.js` is the equivalent of writing 
`test.only("my-fixture")`.
2022-11-03 18:47:02 -04:00
Lauren Tan
acb4999049 Import invariant from CompilerError 2022-11-03 18:47:00 -04:00
Jan Kassens
189b22171f [hir] implement nullish coalescing operator
This currently basically lowers the code into the equivalent of 

``` 

const vLeft = <left>; 

const vNull = null; 

const vCond = vLeft != vNull; 

vCond ? vLeft : <right> 

``` 

I created a temporary `Place` to hold the `null` constant value because the 
binary operator in HIR accepts only `Place`s. Not sure if this is the preferred 
approach. Alternatives I could think of: 

-  Allow constants as an alternative to Place? 

- A `NotNull` operator for `<x> != null` 

- Some other extension to the HIR?
2022-11-03 10:28:26 -04:00
Joseph Savona
515c33d2a6 Custom version of no-use-before-define rule
## Proper Detection of Out-of-order Functions 

The no-use-before-define rule from ESLint has a strange behavior in which it 
treats variables differently than functions: 

```javascript 

function foo() { 

return bar(X); 

} 

const X = null; 

function bar(x) {} 

``` 

By default, `bar(x)` has two errors: one because X is used before defined, and 
once because `bar` is used before defined. The rule has an option `{variables: 
false}` which only enables validation when the variable is from the same "scope" 
as the reference, the net result of which is it means it doesn't report spurious 
errors such as X being undefined. There is _also_ a `{functions: false}` option, 
but for some reason that doesn't work the same way, it just turns off all 
validation of references that came from functions. So enabling that option would 
suppress the (spurious) error on invoking `bar()` above, but causes the rule to 
miss invalid code such as: 

``` 

function foo() { 

return bar(); 

function bar() {} 

} 

``` 

This PR adds a fork of the rule that makes `{functions: false}` behave similarly 
to `{variables: false}`, which should help avoid some of the spurious errors i 
saw internally. The rule is exported from Forget itself, which will make it 
easier to consume internally, in tests, and in the playground. 

## Targeting the validation to Forget functions 

Even with the above, there are still some false positives coming from code such 
as: 

```javascript 

const x = foo(); 

function foo() {} 

``` 

This PR changes codegen to ensure that the output of a function _always_ has the 
body starting with 'use forget'. The ESLint rule then only looks at function 
declarations/expressions whose body starts with that expression. The new unit 
test confirms that the validation finds invalid reorderings even on functions 
that weren't explicitly tagged as 'use forget'.
2022-10-27 16:29:09 -07:00
Joseph Savona
fc1320552b [ssa] Potential improvements to ssa construction
Redo of #711 

Note that one test (switch.js) is failing, i'm working on a fix.
2022-10-27 13:20:10 -07:00
Sathya Gunasekaran
89151eb487 [ssa][be] Refactor visitedBlocks out of SSABuilder 2022-10-27 16:43:41 +01:00
Sathya Gunasekaran
2329326552 [hir] Run SSA pass on all tests 2022-10-27 16:43:38 +01:00
Sathya Gunasekaran
a5fb869640 [hir] Skip backedges when handling phis
These will be handled later during Environment.merge, no need to set an empty 
Set as value.
2022-10-27 16:43:34 +01:00
Sathya Gunasekaran
d9c61bac70 [hir][be] Improve debug printing of invariant 2022-10-27 16:43:31 +01:00
Sathya Gunasekaran
fd6cb34843 [ssa] Run SSA in RPO traversal
This prevents us from looking up state in blocks that have not been visited.
2022-10-27 16:43:28 +01:00
Sathya Gunasekaran
15104ab21b [ssa] Infer arguments of a function 2022-10-27 15:16:56 +01:00
Sathya Gunasekaran
fed106a8eb [ssa][be] Fix printing of SSA blocks 2022-10-27 15:16:52 +01:00
Sathya Gunasekaran
97757ea988 [hir] Run SSA pass before InferReferenceEffects pass 2022-10-27 15:16:49 +01:00
Sathya Gunasekaran
6b9f07624f [hir] Add support for handling phis in InferReferenceEffects
This just piggybacks on the infrastructure for handling Env.#variables. 

In the future, a better approach would be to simplify the environment creation 
and merging by leveraging the SSA property of the new IR -- 1) We don't need to 
track IdentifierId per environment as they are all    unique 2) Rather than 
tracking values, we can just track Identifiers because    Identifiers can never 
be reassigned.
2022-10-27 15:16:46 +01:00
Sathya Gunasekaran
de6afc2c52 [ssa] Update lvalue based on whether it has a memberPath or not
The semantics of lvalue changes based on whether lvalue.place.memberPath is null 
or not. If it's null, then lvalue.place acts as the lvalue for the instruction, 
otherwise it's just a reference to the memberPath specified location. 

Ideally we'd have an MemberExpression IR that lowers this complex lvalue into a 
temporary Place, uses this temporary place and stores back to the 
MemberExpression. 

Working around for now, will refactor to create a MemberExpression in the future 
if necessary for other analysis.
2022-10-27 14:11:23 +01:00
Sathya Gunasekaran
c8aaa7f172 [ssa] Use Identifier for updating SSA
Instead of using Place, use Identifier as the unit of comparison in SSA. 

Place is too high level and can not be substituted for other Places (even those 
with the same Identifier) as Place contain higher level metadata such as 
memberPath.
2022-10-27 14:11:19 +01:00
Sathya Gunasekaran
588a098149 [hir][be] Remove unused param 2022-10-27 14:11:16 +01:00
Sathya Gunasekaran
1396ee28a4 [ssa][be] Refactor to be more idiomatic typescript 2022-10-27 14:11:12 +01:00
Joseph Savona
e262d9e5ba only run validation if code is actually transformed
Disables post-codegen validation if there were no React functions in the input.
2022-10-25 08:33:20 -07:00
Jan Kassens
eb13f84b2d [fix] consistently import from react
Instead of a combination of `react` and `React`, consistently use `react` which 
is the preferred name to import.
2022-10-25 11:00:27 -04:00
Sathya Gunasekaran
34e02dab32 [ssa] Fix lookup of global values
Currently, HIR doesn't load global idenfifiers into a temporary Place which 
means our SSA transform breaks when it tries to lookup this global identifier. 

Instead of throwing, let's log and return the old place. This works for now but 
will probably break when we start mutating globals, but at that point our HIR 
builder will need fixes.
2022-10-24 16:04:20 +01:00
Sathya Gunasekaran
75871d7de7 [ssa] Add support for other kinds of Instructions 2022-10-24 16:04:19 +01:00
Sathya Gunasekaran
bb91cbbf62 [hir][be] Use a Map to store ObjectExpression.properties
Semantically this seems like a better fit as we're using Map like methods to 
iterate and update values anyway.
2022-10-24 16:04:18 +01:00
Sathya Gunasekaran
f54d121d71 [hir][be] Use a Map to store JsxExpression.props
Semantically this seems like a better fit as we're using Map like methods to 
iterate and update values anyway.
2022-10-24 16:04:18 +01:00
Sathya Gunasekaran
c347e8b6d2 [ssa][be] Delete dead code
Leftover from 4eba7a87ec6b27d1e8bad697ff6c0ac5db1ae7ad
2022-10-24 15:49:49 +01:00
Sathya Gunasekaran
152c3e81d3 [hir][be] Use .kind() to update and find ValueKind 2022-10-24 15:49:45 +01:00
Josh Story
61f9b5e97b [Float] support <base> as Resource (#25546)
keys off `target` and `href`.
prepends on insertion similar to title.
only flushes on the server in the shell (should probably add a warning
if there are any to flush in a boundary)
2022-10-23 15:03:52 -07:00
Sebastian Markbåge
1d3fc9c9c4 Bug fix when resolving cache (#25545)
We must use the asynclocalstorage one if it's available.
2022-10-23 14:12:47 -04:00
Sebastian Markbåge
cce18e3504 [Flight] Use AsyncLocalStorage to extend the scope of the cache to micro tasks (#25542)
This extends the scope of the cache and fetch instrumentation using
AsyncLocalStorage for microtasks. This is an intermediate step. It sets
up the dispatcher only once. This is unique to RSC because it uses the
react.shared-subset module for its shared state.

Ideally we should support multiple renderers. We should also have this
take over from an outer SSR's instrumented fetch. We should also be able
to have a fallback to global state per request where AsyncLocalStorage
doesn't exist and then the whole client-side solutions. I'm still
figuring out the right wiring for that so this is a temporary hack.
2022-10-23 01:06:58 -04:00
Sebastian Markbåge
caa84c8da0 Revert fetch instrumentation to only RSC (#25540)
Revert fetch instrumentation so that it only affects RSC by applying it
only in the react-server condition of "react".

This helps make the rollout a little smoother because these affects
existing libraries that fetch during client components, and then gets
forever cached. We need to implement the GC first.

I haven't fully implemented the SSR part anyway.

The main problem that we discovered is that `"react"` and
`"react/react.shared-subset"` have separate dispatchers in an
environment that runs both Fizz and Flight. That's intentional and
sometimes a feature. However, in this case it means that we instrument
fetch twice and when you run Flight inside Fizz, that fetch goes into
both caches when it's supposed to only see the inner one. I'm not sure
how to solve that atm.
2022-10-22 22:58:30 -04:00
Josh Story
0c11baa6ab add warnings for non-resources rendered outside body or head (#25532)
Adds some clarifying warnings when you render a component that is almost
a resource but isn't and the element was rendered outside the main
document tree (outside of `<body>` or `<head>`
2022-10-22 15:19:42 -07:00
Josh Story
9236abdb5a when float is enabled only push title and script as a single unit (#25536)
replaces: https://github.com/facebook/react/pull/25535

This takes a more huerstic based approach with no new conditionals on
the hot path of fizz rendering.

If float is enabled
* title and script can only have simple children
* if non-simple children are found they will be ignored
* title and script are pushed in a single unit during pushStartInstance
including their children and closing tags

If float is not enabled
* the original pushing behaviors are in place and you can have complex
children but you will get warnings
2022-10-22 15:11:26 -07:00
Andrew Clark
dd5c208257 Revert yieldy behavior for non-use Suspense (#25537)
To derisk the rollout of `use`, and simplify the implementation, this
reverts the yield-to-microtasks behavior for promises that are thrown
directly (as opposed to being unwrapped by `use`).

We may add this back later. However, the plan is to deprecate throwing a
promise directly and migrate all existing Suspense code to `use`, so the
extra code probably isn't worth it.
2022-10-22 17:52:20 -04:00
Josh Story
934177598e fix transposed escape functions (#25534)
escapeTextForBrowser accepts any type so flow did not identify that we
were escaping a Chunk rather than a string. It's tricky because we
sometimes want to be able to escape non strings.

I've also updated the types for `Chunk` and `escapeTextForBrowser`
so that we should be able to catch this statically in the future.

The reason this did not show up in tests is almost all of our tests of
float (the areas affected by transpositions) are tested using the Node
runtime where a chunk type is a string. It may be wise to run these
tests in every runtime in the future or at least make sure there is
broad representation of resources in each specific runtime test suite.
2022-10-22 09:56:40 -07:00
Josh Story
d1ced9fd58 [Float] support all links as Resources (#25515)
stacked on https://github.com/facebook/react/pull/25514

This PR adds support for any type of Link as long as it has a string rel
and href and does not include an onLoad or onError property.

The semantics for generic link resources matches other head resources,
they will be inserted and removed as their ref counts go positive and
back to zero.

Keys are based on rel, href, sizes, and media.

on the server preconnect and prefetch-dns are privileged and will emit
near the start of the stream.
2022-10-21 22:38:24 -07:00
Mengdi Chen
6dbccb9249 [DevTools] upgrade to Manifest V3 (#25145)
## Summary

resolves #24522

To upgrade to Manifest V3, one of the biggest issue is that we are no
longer allowed to add a script element with code in textContent so that
it would run synchronously. It's necessary for us because we need to
inject a global hook for react reconciler to detect whether devtools
exist.
To do that, we'll leverage a new API
`chrome.scripting.registerContentScripts` in V3. Particularly, we rely
on the "world" option (added in Chrome v102
[commit](e5ad3451c1))
to run it in the "main world" on the page.

This PR also renames a few content script files so that it's easier to
tell them apart from other extension scripts and understand the purpose
of each of them.

Manifest V3 is not yet ready for Firefox, so we need to keep some code
for compatibility.

## How did you test this change?

`yarn build:chrome && yarn test:chrome`
`yarn build:edge && yarn test:edge`
`yarn build:firefox && yarn test:firefox`
2022-10-21 22:52:18 -04:00
Josh Story
973b90bdf6 [Float] support meta tags as Resources (#25514)
Stacked on #25508

This PR adds meta tags as a resource type.

metas are classified in the following priority

1. charset
2. http-equiv
3. property
4. name
5. itemprop

when using property, there is special logic for og type properties where
a `property="og:image:height"` following a `property="og:image"` will
inherit the key of the previous tag. this relies on timing effects to
stay consistent so when mounting new metas it is important that if
structured properties are being used all members of a structure mount
together. This is similarly true for arrays where the implicit
sequential order defines the array structure. if you need an array you
need to mount all array members in the same pass.
2022-10-21 15:21:29 -07:00
Joseph Savona
f4df345420 Improve playground validation, workaround lack of JSX support
ESLint's default parser doesn't support any non-standard syntax, which includes 
JSX. So when I added the ESLint validation step to the playground, it meant that 
valid examples containing JSX still reported "invalid output". I tried to use an 
alternative parser, but I couldn't figure out the right webpack incantations to 
make `@babel/eslint-parser` or `hermes-eslint` work. I even tried recreating 
some of their code to avoid problematic imports, no dice. 

Instead this PR: 

* No longer uses the `postCodegenValidator` step, and runs the validation on the 
output after compilation completes. This is better anyway since we can see the 
output *and* the error messages 

* Shows rule violations as an "Invalid output" comment 

* Shows parser errors as a note (mostly to indicate that the validation step 
couldn't run, there could still be no-use-before-define violations that weren't 
found) 

Invalid example: 

<img width="1502" alt="Screen Shot 2022-10-21 at 9 50 23 AM" 
src="https://user-images.githubusercontent.com/6425824/197249007-1ec244a0-6dfe-4ec6-a0d0-60302efd86bd.png"> 

Sample example but with some JSX: 

<img width="1500" alt="Screen Shot 2022-10-21 at 9 50 39 AM" 
src="https://user-images.githubusercontent.com/6425824/197249030-e68ba968-4101-47c7-a148-f548f84f375c.png">
2022-10-21 11:00:39 -07:00
Joseph Savona
a7450572fa import runtime from "React.unstable_ForgetRuntime"
Imports the runtime from `React.unstable_ForgetRuntime` rather than from a 
separate module. The hope is that any code that gets transformed already has a 
dependency on React anyway, so we can avoid adding a new dependency that other 
systems don't know about. 

While here, i also cleaned up the `guardThrows` flag (we still parse it if 
present and warn, rather than throwing, to make it easier to adopt the latest 
version in various places).
2022-10-21 09:13:37 -07:00
Joseph Savona
2f34f85011 Enable no-use-before-define validation in playground
#686 added an option to validate generated code after transformation and adds an 
ESLint-based validator function to transform-test. Unfortunately it isn't super 
easy to wire up ESLint for use in a browser: traditionally the ESLint project 
specifically did _not_ support browser builds, but they recently have relaxed 
this because they added a browser playground on their website. There isn't 
official support, but the [playground 
repo](f3b1f78cc1/webpack.config.js) 
has a webpack config that, when combined with requiring a specific file, allows 
making things work in a browser. 

I tried using this directly in our playground app but Next's default webpack 
config doesn't work. So I created a separate package, playground-validator, 
which exports a webpack-built version of `eslint.Linter`. Then the playground 
can consume that, and everything works: 

## Test Plan 👀 

Confirmed that a known problematic example displays the validation message in 
playground (both locally and on the preview deployment): 

<img width="1500" alt="Screen Shot 2022-10-20 at 12 22 59 PM" 
src="https://user-images.githubusercontent.com/6425824/197041265-966ffda2-a3d0-450e-8fc4-fd1a7ca06e1a.png">
2022-10-21 08:37:18 -07:00
Sebastian Markbåge
79c5829813 Let ReactDOM initialize in RSC (#25503)
With the `react-dom/server-rendering-stub` you can import `react-dom` in
RSC so that you can call `preload` and `preinit` but if you don't alias
it, then requiring it breaks because we React.Component which doesn't
exist in the react subset.
2022-10-21 10:41:14 -04:00
Josh Story
1f7a2f577b [Float] support title tags as Resources (#25508)
Adds a category of Resources of type `head` which will be used to track
the tags that go into the <head>

Currently only implements for `<title>`.

titles are keyed off their textContent so each time the title changes a
new resource will be created. Currently insertion is done by prepending
in the <head>. The argument here is that the newest title should "win"
if there are multiple rendered. This also helps when a navigation or
update causes a server rendered title to hang around but it is not the
most recent one.
2022-10-20 23:13:32 -07:00
Andrew Clark
c635807875 Support use in act testing API (#25523)
`use` can avoid suspending on already resolved data by yielding to
microtasks. In a real, browser environment, we do this by scheduling a
platform task (i.e. postTask).

In a test environment, tasks are scheduled on a special internal queue
so that they can be flushed by the `act` testing API. So we need to add
support for this in `act`.

This behavior only works if you `await` the thenable returned by the
`act` call. We currently do not require that users do this. So I added a
warning, but it only fires if `use` was called. The old Suspense pattern
will not trigger a warning. This is to avoid breaking existing tests
that use Suspense.

The implementation of `act` has gotten extremely complicated because of
the subtle changes in behavior over the years, and our commitment to
maintaining backwards compatibility. We really should consider being
more restrictive in a future major release.

The changes are a bit confusing so I did my best to add inline comments
explaining how it works.

## Test plan

I ran this against Facebook's internal Jest test suite to confirm
nothing broke
2022-10-20 22:08:23 -04:00
Sebastian Markbåge
65e32e58b6 Add fetch Instrumentation to Dedupe Fetches (#25516)
* Add fetch instrumentation in cached contexts

* Avoid unhandled rejection errors for Promises that we intentionally ignore

In the final passes, we ignore the newly generated Promises and use
the previous ones. This ensures that if those generate errors, that we
intentionally ignore those.

* Add extra fetch properties if there were any
2022-10-19 18:37:00 -04:00
Joseph Savona
00a58cdab1 Option to validate output with ESLint
Adds a new compiler option `validateNoUseBeforeDefine`, which enables a 
post-codegen pass to validate that there are no usages of values before they are 
defined (which causes a ReferenceError at runtime). This can occur when a value 
is accessed when its in the TDZ (temporary dead zone), after the hoisted 
_declaration_ but before the variable is defined: 

```javascript 

function foo() { 

x; // x is in the TDX here: the binding from the subsequent statement is 
hoisted, but x is not yet defined. 

let x; 

} 

``` 

* The validation is off by default, but enabled in transform-test 

* The validation crashes compilation, rather than bailout, because the code has 
already been mangled and we can't roll back at the point the validation runs. 

* The validator uses ESLint's no-use-before-define rule by printing the program 
to source and then configuring ESLint to use Hermes parser. 

* transform-test now supports tests prefixed with "error." to indicate tests for 
which compilation is expected to crash (not just bailout), and the expect file 
includes the error message.
2022-10-19 13:00:47 -07:00
lauren
9336e29d91 [useEvent] Lint for presence of useEvent functions in dependency lists (#25512)
* [useEvent] Lint for presence of useEvent functions in dependency lists

With #25473, the identity of useEvent's return value is no longer stable
across renders. Previously, the ExhaustiveDeps lint rule would only
allow the omission of the useEvent function, but you could still add it
as a dependency.

This PR updates the ExhaustiveDeps rule to explicitly check for the
presence of useEvent functions in dependency lists, and emits a warning
and suggestion/autofixer for removing the dependency.
2022-10-19 12:03:46 -07:00
lauren
3cc792bfb5 [useEvent] Non-stable function identity (#25473)
* [useEvent] Non-stable function identity

Since useEvent shouldn't go in the dependency list of whatever is
consuming it (which is enforced by the fact that useEvent functions are
always locally created and never passed by reference), its identity
doesn't matter. Effectively, this PR is a runtime assertion
that you can't rely on the return value of useEvent to be stable.

* Test: Events should see latest bindings

The key feature of useEvent that makes it different from useCallback
is that events always see the latest committed values. There's no such
thing as a "stale" event handler.

* Don't queue a commit effect on mount

* Inline event function wrapping

- Inlines wrapping of the callback
- Use a mutable ref-style object instead of a callable object
- Fix types

Co-authored-by: Andrew Clark <git@andrewclark.io>
2022-10-19 11:59:27 -07:00
Jan Kassens
94f1e6f27c Add runtime dependencies to the dependencies
These are used somewhere in the `dist/` directory after building and as such 
should be included in the dependencies of the package.json.
2022-10-19 13:09:03 -04:00
Samuel Susla
987292815c Remove feature flag enableStrictEffects (#25387) 2022-10-19 10:57:09 +01:00
Sebastian Markbåge
8e2bde6f27 Add cache() API (#25506)
Like memo() but longer lived.
2022-10-18 16:55:06 -04:00
Sathya Gunasekaran
eeb01b17e6 [ssa] Remove lambdas for update functions
Rather than passing lambdas above to the builder, pass the builder down and 
update places.
2022-10-18 19:30:53 +01:00
Sathya Gunasekaran
b9ce8bdcfd [SSA] Fix identifierID hack
Rather than starting from 1000, start from the last used identifier id.
2022-10-18 18:57:34 +01:00
Sathya Gunasekaran
379251c65f Add SSA-ify pass
The algorithm is described in detail here: 

https://pp.info.uni-karlsruhe.de/uploads/publikationen/braun13cc.pdf 

Note that the SSA form generated is not minimal. A follow on 
RedundantPhiElimination pass 

is required to prune the graph.
2022-10-18 18:45:01 +01:00
Jan Kassens
9524c58486 Replace import from '.' with path name
Somehow these imports aren't compatible with builds inside buck.
2022-10-18 13:14:27 -04:00
Andrew Clark
9cdf8a99ed [Codemod] Update copyright header to Meta (#25315)
* Facebook -> Meta in copyright

rg --files | xargs sed -i 's#Copyright (c) Facebook, Inc. and its affiliates.#Copyright (c) Meta Platforms, Inc. and affiliates.#g'

* Manual tweaks
2022-10-18 11:19:24 -04:00
c0dedance
e54015e267 Refactor: fill in the flow missing type (#25496) 2022-10-18 11:06:35 -04:00
bubucuo
3b1fd5767a refactor: Flow: typing of Scheduler (#25485)
Flow: typing of Scheduler.
2022-10-18 11:05:38 -04:00
Samuel Susla
14072ce648 Add detach to Offscreen component (#25265) 2022-10-18 15:56:41 +01:00
Sebastian Markbåge
3bb71dfd4b Rename react-server-dom-webpack entry points to /client and /server (#25504) 2022-10-18 10:15:52 -04:00
Tianyu Yao
95fe4ed0ed Include Utils.Component() in BailOnCapitalizedFunctionCalls
`Utils.Component()` wasn't caught by the bailout, and there are such usage on 
WWW 

Fixes #671
2022-10-17 22:44:03 -07:00
Joseph Savona
704d936009 [easy] rename InferReference{Capability=>Effects}
Forgot to rename the function/file when changing from capability to effect. 

#accept2ship
2022-10-18 08:49:31 -07:00
Josh Story
71f2c8cf15 move resource acquisition to mutation phase (#25500) 2022-10-17 15:21:06 -07:00
Andrew Clark
500bea532d Add option to load Fizz runtime from external file (#25499)
* Add feature flag for external Fizz runtime

Only enabled for www for now

* Add option to load Fizz runtime from external file

When unstable_externalRuntimeSrc is provided, React will inject a script
tag that points to the provided URL.

Then, instead of emitting inline scripts, the Fizz stream will emit
HTML nodes with data attributes that encode the instructions. The
external runtime will detect these with a mutation observer and
translate them into runtime commands. This part isn't implemented in 
this PR, though — all this does is set up the option to use 
an external runtime, and inject the script tag.

The external runtime is injected at the same time as bootstrap scripts.
2022-10-17 17:57:59 -04:00
Tianyu Yao
4712017744 Include Utils.Component() in BailOnCapitalizedFunctionCalls
`Utils.Component()` wasn't caught by the bailout, and there are such usage on 
WWW 

Fixes #671
2022-10-17 14:41:26 -07:00
Josh Story
4494f2a86f [Float] add support for scripts and other enhancements (#25480)
* float enhance!!!

Support preinit as script
Support resources from async scripts
Support saving the precedence place when rendering the shell

There was a significant change to the flushing order of resources which follows the general principal of...
1. stuff that blocks display
2. stuff that we know will be used
3. stuff that was explicitly preloaded

As a consequence if you preinit a style now it won't automatically flush in the shell unless you actually depend on it in your tree. To avoid races with precedence order we now emit a tag that saves the place amongst the precedence hierarchy so late insertions still end up where they were intended

There is also a novel hydration pathway for certain tags. If you render an async script with an onLoad or onError it will always treat it like an insertion rather than a hydration.

* restore preinit style flushing behavior and nits
2022-10-17 14:00:20 -07:00
Lauren Tan
46d7f4f8af Synchronize symbol names with React
In the upstream useMemoCache PR this symbol got renamed and unexpectedly caused 
a RN crash. Synchronize it so the comparison works.
2022-10-17 16:07:50 -04:00
Lauren Tan
b03752cbe0 Use for loop instead of Array.prototype.fill
Some prior [microbenchmarking](https://jsbench.me/7ol98ws520/1) showed that a 
for loop outperformed `fill` (which is about ~60% slower). This is the same 
approach we use in the latest useMemoCache PR
2022-10-17 16:07:50 -04:00
Andrew Clark
9ecf84ed7f Bugfix: Suspending in shell during discrete update (#25495)
Fixes a bug that happens when you suspend in the shell (the part of the
tree that is not wrapped in a Suspense boundary) during a
discrete update.

There were two underyling issues. One was just a mistake:
RootDidNotComplete needs to be handled in both renderRootConcurrent and
renderRootSync, but it was only handled in renderRootConcurrent. I did
it this way because I thought this path was unreachable during a sync
update, but I neglected to consider that renderRootSync is sometimes
called for non-concurrent lanes, like when recovering from an error, or
patching up a mutation to an external store.

After I fixed that oversight, the other issue is that we intentionally
error if the shell suspends during a sync update. The idea was that you
should either wrap the tree in a Suspense boundary, or you should mark
the update as a transition to allow React to suspend.

However, this did not take into account selective hydration, which can
force a sync render before anything has even committed. There's no way
in that case to wrap the update in startTransition.

Our solution for now is to remove the error that happens when you
suspend in the shell during a sync update — even for discrete updates.

We will likely revisit this in the future. One appealing possibility is
to commit the whole root in an inert state, as if it were a hidden
Offscreen tree.

Co-authored-by: Sebastian Markbåge <sebastian@calyptus.eu>

Co-authored-by: Sebastian Markbåge <sebastian@calyptus.eu>
2022-10-17 14:17:17 -04:00
Jan Kassens
90e189ae82 Add react-forget-runtime
This is a new module that holds: 

- the `useMemoCache` stub (hopefully to be deleted next week) 

- various helpers that can be imported by the compiler, e.g. the dispatcher 
guard `$startLazy` 

- skipped the implementation of `makeReadOnly` for now as there's already 
multiple copies and I wanted to avoid typescript in this file for now to make 
the build easier (i.e. no build)
2022-10-17 13:08:34 -04:00
Lauren Tan
8f42eda432 Provide full path to tsc
I think my previous stack got mangled somehow
2022-10-17 11:33:24 -04:00
Jan Kassens
54f297a60c Enable useMemoCacheHook for ReactNative-fb build (#25498) 2022-10-17 10:40:59 -04:00
c0dedance
9fb581c7cc Refactor: merge duplicate imports (#25489)
Co-authored-by: Jan Kassens <jan@kassens.net>
2022-10-16 21:58:58 -04:00
Sebastian Markbåge
bc358362a6 [Flight] Improve Error Messages when Invalid Object is Passed to Client/Host Components (#25492)
* Print built-in specific error message for toJSON

This is a better message for Date.

Also, format the message to highlight the affected prop.

* Describe error messages using JSX elements in DEV

We don't have access to the grand parent objects on the stack so we stash
them on weakmaps so we can access them while printing error messages.

Might be a bit slow.

* Capitalize Server/Client Component

* Special case errror messages for children of host components

These are likely meant to be text content if they're not a supported object.

* Update error messages
2022-10-16 21:49:17 -04:00
Andrew Clark
3ba788ff34 Fix download-build script (#25493)
The download-build script works by scraping the CircleCI job number from
the GitHub status API. Yes, I know this is super hacky but last I
checked this was the least bad of not a lot of options. Because the
response is paginated, sometimes the status for the build job exceeds
the page size.

This increases the page size to 100 so this is less likely to happen.

It'd be great to find a better way to download the artifacts. I don't
love how brittle this solution is. I think switching to the GitHub
Checks API might be worth trying, but last I looked into it, it has
other flaws.
2022-10-16 19:17:07 -04:00
Jan Kassens
780eacd408 Flow upgrade to 0.190 (#25483) 2022-10-15 17:33:51 -04:00
Andrew Clark
4e27881cfe Add Jest entry file for external-server-runtime (#25484)
Follow-up to #25482.

This file is created during build, but we need an entry point for local
development, too.
2022-10-15 15:33:33 -04:00
Andrew Clark
54f0e0f730 Scaffolding for react-dom/unstable_external-server-runtime (#25482)
* Scaffolding for react-dom/unstable_external-server-runtime

Implements a new bundle type for in our build config called
BROWSER_SCRIPT. This is intended for scripts that get delivered straight
to the browser without needing to be processed by a bundler. (And also
doesn't include any extra UMD crap.)

Right now there's only a single use case so I didn't stress about making
it general purpose.

The use case is: a script that loads the Fizz browser runtime, and sets
up a MutationObserver to receive instructions as HTML streams in. This
will be an alternative option to the default Fizz behavior of sending
the runtime down as inline script tags, to accommodate environments
where inline script tags are not allowed.

There's no development version of this bundle because it doesn't contain
any warnings or run any user code.

None of the actual implementation is in this PR; it just sets up the
build infra.

Co-authored-by: Mofei Zhang <feifei0@fb.com>

* Set BUNDLE_SCRIPT's GCC output format to ES5

This removes the automatic 'use strict' directive, which we don't need.

Co-authored-by: Mofei Zhang <feifei0@fb.com>
2022-10-14 23:29:17 -04:00
Andrew Clark
0eaca37565 Add script to generate inline Fizz runtime (#25481)
* Move Fizz inline instructions to unified module

Instead of a separate module per instruction, this exports all of them
from a unified module.

In the next step, I'll add a script to generate this new module.

* Add script to generate inline Fizz runtime

This adds a script to generate the inline Fizz runtime. Previously, the
runtime source was in an inline comment, and a compiled version of the
instructions were hardcoded as strings into the Fizz implementation,
where they are injected into the HTML stream.

I've moved the source for the instructions to a regular JavaScript
module. A script compiles the instructions with Closure, then generates
another module that exports the compiled instructions as strings.

Then the Fizz runtime imports the instructions from the
generated module.

To build the instructions, run:
  yarn generate-inline-fizz-runtime

In the next step, I'll add a CI check to verify that the generated files
are up to date.

* Check in CI if generated Fizz runtime is in sync

The generated Fizz runtime is checked into source. In CI, we'll ensure
it stays in sync by running the script and confirming nothing changed.
2022-10-14 21:00:14 -04:00
Joseph Savona
69c7246d9d Initialize useMemoCache with sentinel values (#25465)
* Flush out useMemoCache API

* rename symbol

* rename symbol.for string name

* workaround symbol export not working in unit tests
2022-10-14 15:00:31 -07:00
Lauren Tan
9e8224cc59 Pass init to E0007 diagnostic
I'm not sure why exactly but previously this diagnostic message was 

unusually slow to typecheck. Lifting the getter for init outside of the 

diagnostic to the callsite seems to fix the hotspot. Probably some 

interaction with string interpolation, or something else. 

Test case: ran `yarn ts:analyze-trace`, hotspot for Diagnostic.ts no 

longer present
2022-10-14 17:36:20 -04:00
Lauren Tan
33735b90fe Add a ts:analyze-trace command
I think all of us have noticed TS slowing to a crawl in the past couple of weeks 
and I was curious what exactly was causing it. This adds a yarn command to 
generate a TS trace and then runs a script on it to identify any hot spots 
during compilation. 

Example trace and hot spot analysis: 

``` yarn run v1.22.19 $ scripts/ts-analyze-trace.sh Hot Spots ├─ Check file 
[35m/users/laurentan/code/react-forget/forget/src/ir/[36mbabel-utils.ts[39m[35m[39m 
(2326ms) │  └─ Check expression from (line 141, char 5) to (line 141, char 19) 
(1760ms) │     └─ Check expression from (line 141, char 14) to (line 141, char 
18) (1760ms) │        └─ Compare types 658 and 607 (1759ms) │           ├─ 
{"id":658,"kind":"GenericInstantiation","name":"NodePath","instantiatedType":350,"typeArguments":[657],"location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@types/babel__traverse[39m[35m/index.d.ts[39m","line":237,"char":1}} 
│           │  ├─ 
{"id":350,"kind":"GenericType","name":"NodePath","typeArguments":[351],"location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@types/babel__traverse[39m[35m/index.d.ts[39m","line":237,"char":1}} 
│           │  │  └─ 
{"id":351,"kind":"TypeParameter","name":"T","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@types/babel__traverse[39m[35m/index.d.ts[39m","line":237,"char":23}} 
│           │  └─ {"id":657,"kind":"Union","count":2,"types":[430,452]} │        
   │     ├─ 
{"id":430,"kind":"Object","name":"Identifier","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":156,"char":1}} 
│           │     └─ 
{"id":452,"kind":"Object","name":"JSXIdentifier","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":982,"char":1}} 
│           └─ 
{"id":607,"kind":"GenericInstantiation","name":"NodePath","instantiatedType":350,"typeArguments":[606],"location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@types/babel__traverse[39m[35m/index.d.ts[39m","line":237,"char":1}} 
│              ├─ 
{"id":350,"kind":"GenericType","name":"NodePath","typeArguments":[351],"location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@types/babel__traverse[39m[35m/index.d.ts[39m","line":237,"char":1}} 
│              │  └─ 
{"id":351,"kind":"TypeParameter","name":"T","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@types/babel__traverse[39m[35m/index.d.ts[39m","line":237,"char":23}} 
│              └─ 
{"id":606,"kind":"AliasedUnion","name":"Node","count":252,"types":[353,355,356,357,358,359,360,361,362,363,364,365,366,367,368,369,370,371,372,373,374,375,376,377,378,379,380,381,382,383,384,385,386,387,388,389,390,391,392,393,394,395,396,397,398,399,400,401,402,403,404,405,406,407,408,409,410,411,412,413,414,415,416,417,418,419,420,421,422,423,424,425,426,427,428,429,430,431,432,433,434,435,436,437,438,439,440,441,442,443,444,445,446,447,448,449,450,451,452,453,454,455,456,457,458,459,460,461,462,463,464,465,466,467,468,469,470,471,472,473,474,475,476,477,478,479,480,481,482,483,484,485,486,487,488,489,490,491,492,493,494,495,496,497,498,499,500,501,502,503,504,505,506,507,508,509,510,511,512,513,514,515,516,517,518,519,520,521,522,523,524,525,526,527,528,529,530,531,532,533,534,535,536,537,538,539,540,541,542,543,544,545,546,547,548,549,550,551,552,553,554,555,556,557,558,559,560,561,562,563,564,565,566,567,568,569,570,571,572,573,574,575,576,577,578,579,580,581,582,583,584,585,586,587,588,589,590,591,592,593,594,595,596,597,598,599,600,601,602,603,604,605],"location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":38,"char":1}} 
│                 ├─ 
{"id":353,"kind":"Object","name":"AnyTypeAnnotation","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":625,"char":1}} 
│                 ├─ 
{"id":355,"kind":"Object","name":"ArgumentPlaceholder","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":1035,"char":1}} 
│                 ├─ 
{"id":356,"kind":"Object","name":"ArrayExpression","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":39,"char":1}} 
│                 ├─ 
{"id":357,"kind":"Object","name":"ArrayPattern","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":356,"char":1}} 
│                 ├─ 
{"id":358,"kind":"Object","name":"ArrayTypeAnnotation","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":628,"char":1}} 
│                 ├─ 
{"id":359,"kind":"Object","name":"ArrowFunctionExpression","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":363,"char":1}} 
│                 ├─ 
{"id":360,"kind":"Object","name":"AssignmentExpression","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":43,"char":1}} 
│                 ├─ 
{"id":361,"kind":"Object","name":"AssignmentPattern","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":349,"char":1}} 
│                 ├─ 
{"id":362,"kind":"Object","name":"AwaitExpression","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":523,"char":1}} 
│                 ├─ 
{"id":363,"kind":"Object","name":"BigIntLiteral","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":530,"char":1}} 
│                 ├─ 
{"id":364,"kind":"Object","name":"BinaryExpression","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":49,"char":1}} 
│                 ├─ 
{"id":365,"kind":"Object","name":"BindExpression","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":1038,"char":1}} 
│                 ├─ 
{"id":366,"kind":"Object","name":"BlockStatement","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":67,"char":1}} 
│                 ├─ 
{"id":367,"kind":"Object","name":"BooleanLiteral","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":192,"char":1}} 
│                 ├─ 
{"id":368,"kind":"Object","name":"BooleanLiteralTypeAnnotation","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":635,"char":1}} 
│                 ├─ 
{"id":369,"kind":"Object","name":"BooleanTypeAnnotation","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":632,"char":1}} 
│                 ├─ 
{"id":370,"kind":"Object","name":"BreakStatement","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":72,"char":1}} 
│                 ├─ 
{"id":371,"kind":"Object","name":"CallExpression","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":76,"char":1}} 
│                 ├─ 
{"id":372,"kind":"Object","name":"CatchClause","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":84,"char":1}} 
│                 ├─ 
{"id":373,"kind":"Object","name":"ClassAccessorProperty","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":570,"char":1}} 
│                 ├─ 
{"id":374,"kind":"Object","name":"ClassBody","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":374,"char":1}} 
│                 ├─ 
{"id":375,"kind":"Object","name":"ClassDeclaration","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":389,"char":1}} 
│                 ├─ 
{"id":376,"kind":"Object","name":"ClassExpression","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":378,"char":1}} 
│                 ├─ 
{"id":377,"kind":"Object","name":"ClassImplements","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":642,"char":1}} 
│                 ├─ 
{"id":378,"kind":"Object","name":"ClassMethod","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":460,"char":1}} 
│                 ├─ 
{"id":379,"kind":"Object","name":"ClassPrivateMethod","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":598,"char":1}} 
│                 ├─ 
{"id":380,"kind":"Object","name":"ClassPrivateProperty","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":587,"char":1}} 
│                 ├─ 
{"id":381,"kind":"Object","name":"ClassProperty","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":553,"char":1}} 
│                 ├─ 
{"id":382,"kind":"Object","name":"ConditionalExpression","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":89,"char":1}} 
│                 ├─ 
{"id":383,"kind":"Object","name":"ContinueStatement","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":95,"char":1}} 
│                 ├─ 
{"id":384,"kind":"Object","name":"DebuggerStatement","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":99,"char":1}} 
│                 ├─ 
{"id":385,"kind":"Object","name":"DecimalLiteral","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":1069,"char":1}} 
│                 ├─ 
{"id":386,"kind":"Object","name":"DeclareClass","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":647,"char":1}} 
│                 ├─ 
{"id":387,"kind":"Object","name":"DeclareExportAllDeclaration","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":704,"char":1}} 
│                 ├─ 
{"id":388,"kind":"Object","name":"DeclareExportDeclaration","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":697,"char":1}} 
│                 ├─ 
{"id":389,"kind":"Object","name":"DeclareFunction","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":656,"char":1}} 
│                 ├─ 
{"id":390,"kind":"Object","name":"DeclareInterface","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":661,"char":1}} 
│                 ├─ 
{"id":391,"kind":"Object","name":"DeclareModule","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":670,"char":1}} 
│                 ├─ 
{"id":392,"kind":"Object","name":"DeclareModuleExports","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":676,"char":1}} 
│                 ├─ 
{"id":393,"kind":"Object","name":"DeclareOpaqueType","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":686,"char":1}} 
│                 ├─ 
{"id":394,"kind":"Object","name":"DeclareTypeAlias","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":680,"char":1}} 
│                 ├─ 
{"id":395,"kind":"Object","name":"DeclareVariable","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":693,"char":1}} 
│                 ├─ 
{"id":396,"kind":"Object","name":"DeclaredPredicate","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":709,"char":1}} 
│                 ├─ 
{"id":397,"kind":"Object","name":"Decorator","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":1048,"char":1}} 
│                 ├─ 
{"id":398,"kind":"Object","name":"Directive","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":59,"char":1}} 
│                 ├─ 
{"id":399,"kind":"Object","name":"DirectiveLiteral","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":63,"char":1}} 
│                 ├─ 
{"id":400,"kind":"Object","name":"DoExpression","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":1052,"char":1}} 
│                 ├─ 
{"id":401,"kind":"Object","name":"DoWhileStatement","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":102,"char":1}} 
│                 ├─ 
{"id":402,"kind":"Object","name":"EmptyStatement","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":107,"char":1}} 
│                 ├─ 
{"id":403,"kind":"Object","name":"EmptyTypeAnnotation","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":764,"char":1}} 
│                 ├─ 
{"id":404,"kind":"Object","name":"EnumBooleanBody","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":902,"char":1}} 
│                 ├─ 
{"id":405,"kind":"Object","name":"EnumBooleanMember","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":925,"char":1}} 
│                 ├─ 
{"id":406,"kind":"Object","name":"EnumDeclaration","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":897,"char":1}} 
│                 ├─ 
{"id":407,"kind":"Object","name":"EnumDefaultedMember","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":940,"char":1}} 
│                 ├─ 
{"id":408,"kind":"Object","name":"EnumNumberBody","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":908,"char":1}} 
│                 ├─ 
{"id":409,"kind":"Object","name":"EnumNumberMember","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":930,"char":1}} 
│                 ├─ 
{"id":410,"kind":"Object","name":"EnumStringBody","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":914,"char":1}} 
│                 ├─ 
{"id":411,"kind":"Object","name":"EnumStringMember","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":935,"char":1}} 
│                 ├─ 
{"id":412,"kind":"Object","name":"EnumSymbolBody","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":920,"char":1}} 
│                 ├─ 
{"id":413,"kind":"Object","name":"ExistsTypeAnnotation","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":713,"char":1}} 
│                 ├─ 
{"id":414,"kind":"Object","name":"ExportAllDeclaration","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":402,"char":1}} 
│                 ├─ 
{"id":415,"kind":"Object","name":"ExportDefaultDeclaration","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":408,"char":1}} 
│                 ├─ 
{"id":416,"kind":"Object","name":"ExportDefaultSpecifier","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":1057,"char":1}} 
│                 ├─ 
{"id":417,"kind":"Object","name":"ExportNamedDeclaration","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":413,"char":1}} 
│                 ├─ 
{"id":418,"kind":"Object","name":"ExportNamespaceSpecifier","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":534,"char":1}} 
│                 ├─ 
{"id":419,"kind":"Object","name":"ExportSpecifier","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":421,"char":1}} 
│                 ├─ 
{"id":420,"kind":"Object","name":"ExpressionStatement","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":110,"char":1}} 
│                 ├─ 
{"id":421,"kind":"Object","name":"File","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":114,"char":1}} 
│                 ├─ 
{"id":422,"kind":"Object","name":"ForInStatement","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":120,"char":1}} 
│                 ├─ 
{"id":423,"kind":"Object","name":"ForOfStatement","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":427,"char":1}} 
│                 ├─ 
{"id":424,"kind":"Object","name":"ForStatement","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":126,"char":1}} 
│                 ├─ 
{"id":425,"kind":"Object","name":"FunctionDeclaration","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":133,"char":1}} 
│                 ├─ 
{"id":426,"kind":"Object","name":"FunctionExpression","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":145,"char":1}} 
│                 ├─ 
{"id":427,"kind":"Object","name":"FunctionTypeAnnotation","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":716,"char":1}} 
│                 ├─ 
{"id":428,"kind":"Object","name":"FunctionTypeParam","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":724,"char":1}} 
│                 ├─ 
{"id":429,"kind":"Object","name":"GenericTypeAnnotation","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":730,"char":1}} 
│                 ├─ 
{"id":430,"kind":"Object","name":"Identifier","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":156,"char":1}} 
│                 ├─ 
{"id":431,"kind":"Object","name":"IfStatement","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":163,"char":1}} 
│                 ├─ 
{"id":432,"kind":"Object","name":"Import","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":527,"char":1}} 
│                 ├─ 
{"id":433,"kind":"Object","name":"ImportAttribute","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":1043,"char":1}} 
│                 ├─ 
{"id":434,"kind":"Object","name":"ImportDeclaration","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":434,"char":1}} 
│                 ├─ 
{"id":435,"kind":"Object","name":"ImportDefaultSpecifier","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":441,"char":1}} 
│                 ├─ 
{"id":436,"kind":"Object","name":"ImportNamespaceSpecifier","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":445,"char":1}} 
│                 ├─ 
{"id":437,"kind":"Object","name":"ImportSpecifier","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":449,"char":1}} 
│                 ├─ 
{"id":438,"kind":"Object","name":"IndexedAccessType","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":944,"char":1}} 
│                 ├─ 
{"id":439,"kind":"Object","name":"InferredPredicate","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":735,"char":1}} 
│                 ├─ 
{"id":440,"kind":"Object","name":"InterfaceDeclaration","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":743,"char":1}} 
│                 ├─ 
{"id":441,"kind":"Object","name":"InterfaceExtends","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":738,"char":1}} 
│                 ├─ 
{"id":442,"kind":"Object","name":"InterfaceTypeAnnotation","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":752,"char":1}} 
│                 ├─ 
{"id":443,"kind":"Object","name":"InterpreterDirective","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":55,"char":1}} 
│                 ├─ 
{"id":444,"kind":"Object","name":"IntersectionTypeAnnotation","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":757,"char":1}} 
│                 ├─ 
{"id":445,"kind":"Object","name":"JSXAttribute","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":955,"char":1}} 
│                 ├─ 
{"id":446,"kind":"Object","name":"JSXClosingElement","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":960,"char":1}} 
│                 ├─ 
{"id":447,"kind":"Object","name":"JSXClosingFragment","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":1020,"char":1}} 
│                 ├─ 
{"id":448,"kind":"Object","name":"JSXElement","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":964,"char":1}} 
│                 ├─ 
{"id":449,"kind":"Object","name":"JSXEmptyExpression","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":971,"char":1}} 
│                 ├─ 
{"id":450,"kind":"Object","name":"JSXExpressionContainer","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":974,"char":1}} 
│                 ├─ 
{"id":451,"kind":"Object","name":"JSXFragment","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":1011,"char":1}} 
│                 ├─ 
{"id":452,"kind":"Object","name":"JSXIdentifier","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":982,"char":1}} 
│                 ├─ 
{"id":453,"kind":"Object","name":"JSXMemberExpression","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":986,"char":1}} 
│                 ├─ 
{"id":454,"kind":"Object","name":"JSXNamespacedName","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":991,"char":1}} 
│                 ├─ 
{"id":455,"kind":"Object","name":"JSXOpeningElement","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":996,"char":1}} 
│                 ├─ 
{"id":456,"kind":"Object","name":"JSXOpeningFragment","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":1017,"char":1}} 
│                 ├─ 
{"id":457,"kind":"Object","name":"JSXSpreadAttribute","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":1003,"char":1}} 
│                 ├─ 
{"id":458,"kind":"Object","name":"JSXSpreadChild","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":978,"char":1}} 
│                 ├─ 
{"id":459,"kind":"Object","name":"JSXText","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":1007,"char":1}} 
│                 ├─ 
{"id":460,"kind":"Object","name":"LabeledStatement","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":169,"char":1}} 
│                 ├─ 
{"id":461,"kind":"Object","name":"LogicalExpression","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":209,"char":1}} 
│                 ├─ 
{"id":462,"kind":"Object","name":"MemberExpression","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":215,"char":1}} 
│                 ├─ 
{"id":463,"kind":"Object","name":"MetaProperty","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":455,"char":1}} 
│                 ├─ 
{"id":464,"kind":"Object","name":"MixedTypeAnnotation","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":761,"char":1}} 
│                 ├─ 
{"id":465,"kind":"Object","name":"ModuleExpression","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":1073,"char":1}} 
│                 ├─ 
{"id":466,"kind":"Object","name":"NewExpression","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":222,"char":1}} 
│                 ├─ 
{"id":467,"kind":"Object","name":"Noop","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":1023,"char":1}} 
│                 ├─ 
{"id":468,"kind":"Object","name":"NullLiteral","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":189,"char":1}} 
│                 ├─ 
{"id":469,"kind":"Object","name":"NullLiteralTypeAnnotation","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":639,"char":1}} 
│                 ├─ 
{"id":470,"kind":"Object","name":"NullableTypeAnnotation","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":767,"char":1}} 
│                 ├─ 
{"id":471,"kind":"Object","name":"NumberLiteral$1","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":185,"char":1}} 
│                 ├─ 
{"id":472,"kind":"Object","name":"NumberLiteralTypeAnnotation","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":771,"char":1}} 
│                 ├─ 
{"id":473,"kind":"Object","name":"NumberTypeAnnotation","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":775,"char":1}} 
│                 ├─ 
{"id":474,"kind":"Object","name":"NumericLiteral","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":178,"char":1}} 
│                 ├─ 
{"id":475,"kind":"Object","name":"ObjectExpression","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":238,"char":1}} 
│                 ├─ 
{"id":476,"kind":"Object","name":"ObjectMethod","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":242,"char":1}} 
│                 ├─ 
{"id":477,"kind":"Object","name":"ObjectPattern","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":479,"char":1}} 
│                 ├─ 
{"id":478,"kind":"Object","name":"ObjectProperty","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":255,"char":1}} 
│                 ├─ 
{"id":479,"kind":"Object","name":"ObjectTypeAnnotation","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":778,"char":1}} 
│                 ├─ 
{"id":480,"kind":"Object","name":"ObjectTypeCallProperty","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":795,"char":1}} 
│                 ├─ 
{"id":481,"kind":"Object","name":"ObjectTypeIndexer","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":800,"char":1}} 
│                 ├─ 
{"id":482,"kind":"Object","name":"ObjectTypeInternalSlot","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":787,"char":1}} 
│                 ├─ 
{"id":483,"kind":"Object","name":"ObjectTypeProperty","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":808,"char":1}} 
│                 ├─ 
{"id":484,"kind":"Object","name":"ObjectTypeSpreadProperty","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":819,"char":1}} 
│                 ├─ 
{"id":485,"kind":"Object","name":"OpaqueType","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":823,"char":1}} 
│                 ├─ 
{"id":486,"kind":"Object","name":"OptionalCallExpression","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":545,"char":1}} 
│                 ├─ 
{"id":487,"kind":"Object","name":"OptionalIndexedAccessType","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":949,"char":1}} 
│                 ├─ 
{"id":488,"kind":"Object","name":"OptionalMemberExpression","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":538,"char":1}} 
│                 ├─ 
{"id":489,"kind":"Object","name":"ParenthesizedExpression","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":288,"char":1}} 
│                 ├─ 
{"id":490,"kind":"Object","name":"PipelineBareFunction","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":1084,"char":1}} 
│                 ├─ 
{"id":491,"kind":"Object","name":"PipelinePrimaryTopicReference","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":1088,"char":1}} 
│                 ├─ 
{"id":492,"kind":"Object","name":"PipelineTopicExpression","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":1080,"char":1}} 
│                 ├─ 
{"id":493,"kind":"Object","name":"Placeholder","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":1026,"char":1}} 
│                 ├─ 
{"id":494,"kind":"Object","name":"PrivateName","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":617,"char":1}} 
│                 ├─ 
{"id":495,"kind":"Object","name":"Program","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":230,"char":1}} 
│                 ├─ 
{"id":496,"kind":"Object","name":"QualifiedTypeIdentifier","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":830,"char":1}} 
│                 ├─ 
{"id":497,"kind":"Object","name":"RecordExpression","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":1061,"char":1}} 
│                 ├─ 
{"id":498,"kind":"Object","name":"RegExpLiteral","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":196,"char":1}} 
│                 ├─ 
{"id":499,"kind":"Object","name":"RegexLiteral$1","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":204,"char":1}} 
│                 ├─ 
{"id":500,"kind":"Object","name":"RestElement","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":263,"char":1}} 
│                 ├─ 
{"id":501,"kind":"Object","name":"RestProperty$1","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":273,"char":1}} 
│                 ├─ 
{"id":502,"kind":"Object","name":"ReturnStatement","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":280,"char":1}} 
│                 ├─ 
{"id":503,"kind":"Object","name":"SequenceExpression","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":284,"char":1}} 
│                 ├─ 
{"id":504,"kind":"Object","name":"SpreadElement","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":485,"char":1}} 
│                 ├─ 
{"id":505,"kind":"Object","name":"SpreadProperty$1","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":492,"char":1}} 
│                 ├─ 
{"id":506,"kind":"Object","name":"StaticBlock","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":621,"char":1}} 
│                 ├─ 
{"id":507,"kind":"Object","name":"StringLiteral","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":174,"char":1}} 
│                 ├─ 
{"id":508,"kind":"Object","name":"StringLiteralTypeAnnotation","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":835,"char":1}} 
│                 ├─ 
{"id":509,"kind":"Object","name":"StringTypeAnnotation","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":839,"char":1}} 
│                 ├─ 
{"id":510,"kind":"Object","name":"Super","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":496,"char":1}} 
│                 ├─ 
{"id":511,"kind":"Object","name":"SwitchCase","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":292,"char":1}} 
│                 ├─ 
{"id":512,"kind":"Object","name":"SwitchStatement","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":297,"char":1}} 
│                 ├─ 
{"id":513,"kind":"Object","name":"SymbolTypeAnnotation","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":842,"char":1}} 
│                 ├─ 
{"id":514,"kind":"Object","name":"TSAnyKeyword","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":1171,"char":1}} 
│                 ├─ 
{"id":515,"kind":"Object","name":"TSArrayType","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":1246,"char":1}} 
│                 ├─ 
{"id":516,"kind":"Object","name":"TSAsExpression","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":1342,"char":1}} 
│                 ├─ 
{"id":517,"kind":"Object","name":"TSBigIntKeyword","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":1177,"char":1}} 
│                 ├─ 
{"id":518,"kind":"Object","name":"TSBooleanKeyword","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":1174,"char":1}} 
│                 ├─ 
{"id":519,"kind":"Object","name":"TSCallSignatureDeclaration","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":1132,"char":1}} 
│                 ├─ 
{"id":520,"kind":"Object","name":"TSConditionalType","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":1276,"char":1}} 
│                 ├─ 
{"id":521,"kind":"Object","name":"TSConstructSignatureDeclaration","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":1138,"char":1}} 
│                 ├─ 
{"id":522,"kind":"Object","name":"TSConstructorType","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":1219,"char":1}} 
│                 ├─ 
{"id":523,"kind":"Object","name":"TSDeclareFunction","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":1099,"char":1}} 
│                 ├─ 
{"id":524,"kind":"Object","name":"TSDeclareMethod","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":1109,"char":1}} 
│                 ├─ 
{"id":525,"kind":"Object","name":"TSEnumDeclaration","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":1352,"char":1}} 
│                 ├─ 
{"id":526,"kind":"Object","name":"TSEnumMember","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":1360,"char":1}} 
│                 ├─ 
{"id":527,"kind":"Object","name":"TSExportAssignment","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":1397,"char":1}} 
│                 ├─ 
{"id":528,"kind":"Object","name":"TSExpressionWithTypeArguments","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":1313,"char":1}} 
│                 ├─ 
{"id":529,"kind":"Object","name":"TSExternalModuleReference","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":1389,"char":1}} 
│                 ├─ 
{"id":530,"kind":"Object","name":"TSFunctionType","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":1213,"char":1}} 
│                 ├─ 
{"id":531,"kind":"Object","name":"TSImportEqualsDeclaration","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":1382,"char":1}} 
│                 ├─ 
{"id":532,"kind":"Object","name":"TSImportType","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":1376,"char":1}} 
│                 ├─ 
{"id":533,"kind":"Object","name":"TSIndexSignature","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":1164,"char":1}} 
│                 ├─ 
{"id":534,"kind":"Object","name":"TSIndexedAccessType","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":1296,"char":1}} 
│                 ├─ 
{"id":535,"kind":"Object","name":"TSInferType","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":1283,"char":1}} 
│                 ├─ 
{"id":536,"kind":"Object","name":"TSInstantiationExpression","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":1337,"char":1}} 
│                 ├─ 
{"id":537,"kind":"Object","name":"TSInterfaceBody","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":1326,"char":1}} 
│                 ├─ 
{"id":538,"kind":"Object","name":"TSInterfaceDeclaration","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":1318,"char":1}} 
│                 ├─ 
{"id":539,"kind":"Object","name":"TSIntersectionType","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":1272,"char":1}} 
│                 ├─ 
{"id":540,"kind":"Object","name":"TSIntrinsicKeyword","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":1180,"char":1}} 
│                 ├─ 
{"id":541,"kind":"Object","name":"TSLiteralType","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":1309,"char":1}} 
│                 ├─ 
{"id":542,"kind":"Object","name":"TSMappedType","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":1301,"char":1}} 
│                 ├─ 
{"id":543,"kind":"Object","name":"TSMethodSignature","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":1154,"char":1}} 
│                 ├─ 
{"id":544,"kind":"Object","name":"TSModuleBlock","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":1372,"char":1}} 
│                 ├─ 
{"id":545,"kind":"Object","name":"TSModuleDeclaration","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":1365,"char":1}} 
│                 ├─ 
{"id":546,"kind":"Object","name":"TSNamedTupleMember","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":1262,"char":1}} 
│                 ├─ 
{"id":547,"kind":"Object","name":"TSNamespaceExportDeclaration","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":1401,"char":1}} 
│                 ├─ 
{"id":548,"kind":"Object","name":"TSNeverKeyword","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":1183,"char":1}} 
│                 ├─ 
{"id":549,"kind":"Object","name":"TSNonNullExpression","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":1393,"char":1}} 
│                 ├─ 
{"id":550,"kind":"Object","name":"TSNullKeyword","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":1186,"char":1}} 
│                 ├─ 
{"id":551,"kind":"Object","name":"TSNumberKeyword","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":1189,"char":1}} 
│                 ├─ 
{"id":552,"kind":"Object","name":"TSObjectKeyword","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":1192,"char":1}} 
│                 ├─ 
{"id":553,"kind":"Object","name":"TSOptionalType","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":1254,"char":1}} 
│                 ├─ 
{"id":554,"kind":"Object","name":"TSParameterProperty","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":1091,"char":1}} 
│                 ├─ 
{"id":555,"kind":"Object","name":"TSParenthesizedType","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":1287,"char":1}} 
│                 ├─ 
{"id":556,"kind":"Object","name":"TSPropertySignature","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":1144,"char":1}} 
│                 ├─ 
{"id":557,"kind":"Object","name":"TSQualifiedName","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":1127,"char":1}} 
│                 ├─ 
{"id":558,"kind":"Object","name":"TSRestType","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":1258,"char":1}} 
│                 ├─ 
{"id":559,"kind":"Object","name":"TSStringKeyword","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":1195,"char":1}} 
│                 ├─ 
{"id":560,"kind":"Object","name":"TSSymbolKeyword","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":1198,"char":1}} 
│                 ├─ 
{"id":561,"kind":"Object","name":"TSThisType","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":1210,"char":1}} 
│                 ├─ 
{"id":562,"kind":"Object","name":"TSTupleType","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":1250,"char":1}} 
│                 ├─ 
{"id":563,"kind":"Object","name":"TSTypeAliasDeclaration","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":1330,"char":1}} 
│                 ├─ 
{"id":564,"kind":"Object","name":"TSTypeAnnotation","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":1405,"char":1}} 
│                 ├─ 
{"id":565,"kind":"Object","name":"TSTypeAssertion","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":1347,"char":1}} 
│                 ├─ 
{"id":566,"kind":"Object","name":"TSTypeLiteral","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":1242,"char":1}} 
│                 ├─ 
{"id":567,"kind":"Object","name":"TSTypeOperator","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":1291,"char":1}} 
│                 ├─ 
{"id":568,"kind":"Object","name":"TSTypeParameter","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":1417,"char":1}} 
│                 ├─ 
{"id":569,"kind":"Object","name":"TSTypeParameterDeclaration","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":1413,"char":1}} 
│                 ├─ 
{"id":570,"kind":"Object","name":"TSTypeParameterInstantiation","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":1409,"char":1}} 
│                 ├─ 
{"id":571,"kind":"Object","name":"TSTypePredicate","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":1231,"char":1}} 
│                 ├─ 
{"id":572,"kind":"Object","name":"TSTypeQuery","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":1237,"char":1}} 
│                 ├─ 
{"id":573,"kind":"Object","name":"TSTypeReference","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":1226,"char":1}} 
│                 ├─ 
{"id":574,"kind":"Object","name":"TSUndefinedKeyword","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":1201,"char":1}} 
│                 ├─ 
{"id":575,"kind":"Object","name":"TSUnionType","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":1268,"char":1}} 
│                 ├─ 
{"id":576,"kind":"Object","name":"TSUnknownKeyword","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":1204,"char":1}} 
│                 ├─ 
{"id":577,"kind":"Object","name":"TSVoidKeyword","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":1207,"char":1}} 
│                 ├─ 
{"id":578,"kind":"Object","name":"TaggedTemplateExpression","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":499,"char":1}} 
│                 ├─ 
{"id":579,"kind":"Object","name":"TemplateElement","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":505,"char":1}} 
│                 ├─ 
{"id":580,"kind":"Object","name":"TemplateLiteral","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":513,"char":1}} 
│                 ├─ 
{"id":581,"kind":"Object","name":"ThisExpression","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":302,"char":1}} 
│                 ├─ 
{"id":582,"kind":"Object","name":"ThisTypeAnnotation","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":845,"char":1}} 
│                 ├─ 
{"id":583,"kind":"Object","name":"ThrowStatement","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":305,"char":1}} 
│                 ├─ 
{"id":584,"kind":"Object","name":"TopicReference","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":1077,"char":1}} 
│                 ├─ 
{"id":585,"kind":"Object","name":"TryStatement","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":309,"char":1}} 
│                 ├─ 
{"id":586,"kind":"Object","name":"TupleExpression","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":1065,"char":1}} 
│                 ├─ 
{"id":587,"kind":"Object","name":"TupleTypeAnnotation","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":848,"char":1}} 
│                 ├─ 
{"id":588,"kind":"Object","name":"TypeAlias","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":856,"char":1}} 
│                 ├─ 
{"id":589,"kind":"Object","name":"TypeAnnotation","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":862,"char":1}} 
│                 ├─ 
{"id":590,"kind":"Object","name":"TypeCastExpression","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":866,"char":1}} 
│                 ├─ 
{"id":591,"kind":"Object","name":"TypeParameter","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":871,"char":1}} 
│                 ├─ 
{"id":592,"kind":"Object","name":"TypeParameterDeclaration","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":878,"char":1}} 
│                 ├─ 
{"id":593,"kind":"Object","name":"TypeParameterInstantiation","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":882,"char":1}} 
│                 ├─ 
{"id":594,"kind":"Object","name":"TypeofTypeAnnotation","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":852,"char":1}} 
│                 ├─ 
{"id":595,"kind":"Object","name":"UnaryExpression","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":315,"char":1}} 
│                 ├─ 
{"id":596,"kind":"Object","name":"UnionTypeAnnotation","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":886,"char":1}} 
│                 ├─ 
{"id":597,"kind":"Object","name":"UpdateExpression","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":321,"char":1}} 
│                 ├─ 
{"id":598,"kind":"Object","name":"V8IntrinsicIdentifier","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":1031,"char":1}} 
│                 ├─ 
{"id":599,"kind":"Object","name":"VariableDeclaration","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":327,"char":1}} 
│                 ├─ 
{"id":600,"kind":"Object","name":"VariableDeclarator","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":333,"char":1}} 
│                 ├─ 
{"id":601,"kind":"Object","name":"Variance","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":890,"char":1}} 
│                 ├─ 
{"id":602,"kind":"Object","name":"VoidTypeAnnotation","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":894,"char":1}} 
│                 ├─ 
{"id":603,"kind":"Object","name":"WhileStatement","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":339,"char":1}} 
│                 ├─ 
{"id":604,"kind":"Object","name":"WithStatement","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":344,"char":1}} 
│                 └─ 
{"id":605,"kind":"Object","name":"YieldExpression","location":{"path":"[35m/users/laurentan/code/react-forget/forget/node_modules/[36m@babel/types[39m[35m/lib/index.d.ts[39m","line":518,"char":1}} 
└─ Check file 
[35m/users/laurentan/code/react-forget/forget/src/[36mdiagnostic.ts[39m[35m[39m 
(809ms)    └─ Check expression from (line 222, char 14) to (line 228, char 8) 
(698ms)       └─ Check expression from (line 227, char 21) to (line 227, char 
74) (697ms)          └─ Check expression from (line 227, char 29) to (line 227, 
char 61) (697ms)             └─ Check expression from (line 227, char 39) to 
(line 227, char 60) (697ms) 

No duplicate packages found Done in 16.27s. ```
2022-10-14 17:36:19 -04:00
Sebastian Markbåge
3b814327e2 Allow Async Functions to be used in Server Components (#25479)
This is a temporary step until we allow Promises everywhere.

Currently this serializes to a Lazy which can then be consumed in this same
slot by the client.
2022-10-14 15:09:33 -04:00
Tianyu Yao
44e2ca393e React DevTools 4.26.0 -> 4.26.1 (#25478) 2022-10-14 10:36:52 -07:00
Lauren Tan
e939cacf97 Don't console.error in dev
Previously the PassManager would console.error if an unexpected error was 
thrown, to help with debugging jest. However because we now capture all 
invariants in compiler passes as bailouts, these are already captured in fixture 
tests. 

Additionally, we also already console.error if we find an unexpected bailout in 
a fixture test. So this is purely redundant and removing reduces some noise when 
running tests.
2022-10-14 12:10:58 -04:00
Lauren Tan
101ee3a440 Allow capitalized function identifiers to be allowlisted
The current allowlist for capitalized function identifiers only allows stdlib JS 
modules. This PR introduces a new compiler option to allow passing in a set of 
allowed capitalized user function identifiers. It's a hack (in the absence of a 
type system) to let us check that capitalized function calls are only possible 
for identifiers that aren't bound to a React component. 

I considered adding a mechanism in fixtures to configure compiler options 
per-fixture, but opted to keep it simple for now and special case a 
`ReactForgetSecretInternals` identifier as one allowed user function in 
transform tests.
2022-10-14 12:10:55 -04:00
Lauren Tan
58100e3d60 Use CompilerError invariant
The CompilerError module's `invariant` is wired up to our bailout system so in 
compiler passes should be preferred to the raw `invariant` module. 

We should probably add an internal eslint rule to suggest using CompilerError if 
the file is in one of the compiler pass directories.
2022-10-14 12:10:53 -04:00
Andrew Clark
a6bf466892 Extract Fizz instruction set to build macro (#25457)
We're adding an option to Fizz to support an alternate output format
that doesn't rely on inline script tags (see #25437). The two outputs
will share the same "instruction set" of functions. These functions are
currently inlined into the source file; to make this a bit more maintainable,
and eventually have a single source of truth, in preparation for the new option,
this commit moves the instruction set to a separate files that are imported.

In the future, we could improve this further by running Closure on the
instruction set and generating it at build time. This isn't an urgent
improvement, though, because we rarely modify the instruction set.

Co-authored-by: Mofei Zhang <feifei0@fb.com>

Co-authored-by: Mofei Zhang <feifei0@fb.com>
2022-10-14 11:00:35 -04:00
Jan Kassens
ea5bc6bac1 [React Native FB] dynamic feature flag for ref access warning (#25471) 2022-10-14 10:11:42 -04:00
Tianyu Yao
fd31724d5d Stop spamming highlight events when a component is selected (#25448) 2022-10-13 17:38:05 -07:00
Sebastian Markbåge
08d035bc8f Remove Shallow Renderer Tests (#25475) 2022-10-13 19:02:03 -04:00
Jan Kassens
b1006e12cd Invariant for use before definition of reactive values (#662) 2022-10-13 16:17:39 -04:00
Joseph Savona
0000ab6ca4 [new-arch] HIR cleanup per discussion
* Renames `Capability` to `Effect` and clarifies the kinds as Freeze, Read, and 
Mutate. The real intent of what we're inferring/representing is "what effect 
does this reference to the value have on its value". Ie freeze freezes the 
value, mutate mutates it. 

* Consolidates Capability and EffectKind into Effect 

* Renames some properties on Place for clarity 

* Adds `value: ValueKind` to Place, which indicates the (merged) kind of the 
value at that place at that point in the program. 

* Changes HIR printing to show the effect and the value kind 

* Simplifies some inference logic
2022-10-13 11:23:14 -07:00
mofeiZ
73059d9a4f [Playground][Nit] Add delete + overtype for autoclosing brackets
Fix for papercut: playground should now be smart about autoclosing brackets. 

Before: 


https://user-images.githubusercontent.com/34200447/195653419-0eb529e4-0aed-4894-9db6-bfe1554aaded.mov 

Now: 


https://user-images.githubusercontent.com/34200447/195653738-07abed36-d9e8-4842-bac5-9e84b72c0704.mov
2022-10-13 13:16:56 -04:00
Joseph Savona
144e856264 Cleanup reverse postordering
Splits out the reverse postorder logic from `shrink` into a separate method.
2022-10-13 07:58:06 -07:00
Sathya Gunasekaran
b01fbfa7fb Change function parameters to type Place
So that we can infer a Capability of Freeze for components
2022-10-13 11:29:58 +01:00
Sebastian Markbåge
a8c16a0040 Split Cache into its own Dispatcher (#25474)
* Missing Hooks

* Remove www forks. These can use __SECRET... instead.

* Move cache to separate dispatcher

These will be available in more contexts than just render.
2022-10-12 23:13:39 -04:00
Joseph Savona
5149ce0fbb [new-arch] Store HIR blocks in reverse postorder
* Changes HIR to store blocks in reverse postorder, which allows forward data 
flow analysis to iterate the blocks in order and (in the absence of loops) see 
all predecessors before visiting a successor. 

* Updates reference kind inference to exploit this ordering 

Note that the approach of modifying the ordering in `mapTerminalSuccessors()` 
feels gross, i'd like to split this up a bit.
2022-10-12 16:11:15 -07:00
Joseph Savona
3d4130140a [new-arch] Scaffolding and fixtures for mutability lifetime inference
Scaffolds out mutable lifetime inference and the potential two-pass approach, 
with motivating examples. Also adds some fixtures that collectively demonstrate 
a bunch of cases of aliasing: 

* direct assignment `a = b` 

* property assignment `a.b = b` 

* array literals `a = [b]` 

* object literals `a = {b}` 

* mutable arguments to the same call `foo(mut a, mut b)` 

* return values aliasing arguments `a = foo(mut b)` 

* aliasing that occurs only after multiple loop iterations 

All of these fixtures use an empty `if (varName) {}` as a way to check that an 
otherwise readonly usage of a variable is correctly inferred as mutable.
2022-10-12 10:54:09 -07:00
Joseph Savona
94adcf91b1 [new-arch] Cleanup unused analysis (#651) 2022-10-11 12:00:45 -07:00
Joseph Savona
beb6e1431c [new-arch] Improve reference-kind analysis
This implements an alternative approach to reference kind inference in the new 
architecture based on feedback. Here, we track an environment that maps 
top-level identifiers (IdentifierId) to the "kind" of value stored: immutable, 
mutable, frozen, or maybe-frozen. We then do a forward data flow analysis 
updating this environment based on the semantics of each instruction combined 
with the types of values present. For example a reference of a value in a 
"mutable" position is inferred as readonly if the value is known to be frozen or 
immutable. Similarly, a usage of a reference in a "freeze" position is inferred 
as a freeze if the value is not yet definitively frozen, and inferred as 
readonly if the value is already frozen. 

When multiple control paths converge we merge the previous and new incoming 
environments, and only reprocess the block if the environment changed relative 
to the previous value. This has some noticeable benefits over the previous 
version: 

* We now infer precisely where `makeReadOnly()` calls need to be inserted, aka 
points where a value needs to be frozen may not yet be frozen. 

* We track immutable values and can infer their usage as readonly rather than 
mutable. 

* The system handles aliasing by representing values as distinct from variables, 
so that we can handle situations such as: 

```javascript 

const a = [];  // env: {a: value0; value0: mutable} 

const b = a;   // env: {a: value0, b: value0; value0: mutable} 

freeze(a);     // env: {a: value0, b: value0; value0: frozen} 

mayMutate(b);  // ordinarily inferred as a mutable reference, but we know its 
readonly 

```
2022-10-11 11:32:49 -07:00
Jan Kassens
7f17dd84d1 Import useMemoCache from unstable name
I didn't make this an option as it's unclear we'll really need this. We can 
always add an option later, I think. 

This is the name that's available on facebook.com at the moment.
2022-10-11 13:16:01 -04:00
Josh Story
2cf4352e1c Implement HostSingleton Fiber type (#25426) 2022-10-11 08:42:42 -07:00
Josh Story
aa9988e5e6 Server render fork for react-dom (#25436)
Publish an aliasable entry for `react-dom` top level package exports for use in server environments. This is a stub containing only the exports that we expect to retain in the top level once 19 is released
2022-10-10 11:06:22 -07:00
Tianyu Yao
513417d695 Return lastNonHostInstance in getInspectorDataForInstance for devtools (#25441) 2022-10-07 15:43:02 -07:00
Andrew Clark
5d60a0b840 Bugfix: LegacyHidden shouldn't defer effects (#25442)
In #24967, I changed the behavior of Offscreen so that passive effects
are not fired when the tree is hidden. I accidentally applied this
behavior to the old LegacyHidden API, too, which is a deprecated
internal-only type that www has been using while they wait for Offscreen
to be ready.

This fixes LegacyHidden so that the effects do not get deferred, like
before. The new behavior still remains in the Offscreen API, which is
experimental and not currently in use in www.
2022-10-06 17:23:27 -04:00
Jan Kassens
e575e22925 Add hash of Babel plugin to Jest transform
Jest caches based on the hash of the babel config. This caused us to not break 
that cache when the we made changes to the plugin. 

Fixes #643
2022-10-06 16:59:12 -04:00
Xuan Huang (黄玄)
b605fc1ab3 [BE] Even more permissive ref annotation comment
Allow `readOnly` and `writable` or even `WriTaBlE`. 

commit-id:f6f77fd8
2022-10-05 18:42:16 -04:00
Xuan Huang (黄玄)
a574d15985 [Fix] Control Dep Should Only Add To Defs
Control dep should only affect how things are invalidated, which are modeled as 
defs including declarations, writable uses to variables and expressions. 

Closes #633 

commit-id:41bd6fe5
2022-10-05 18:42:11 -04:00
Xuan Huang (黄玄)
19b08e67ad [Bailout] When Inputs Detected In DepGraph Cycle
Inputs occured in depGraph cycle is dangenrous and should be treated as an 
invariant since Forget _may_ generate broken code in this case, despite that 
technically this is a stricter then what we needed for the particular case of 
#633 and #634 and there   could be case that this is safe (like many `cfg-`   
tests that I have to mark as `bailout.`) 

I expect the next diff will fix them though. 

commit-id:0b13ed02
2022-10-05 18:42:10 -04:00
Joseph Savona
cbbfba27b4 [new-arch][easy] Handle declarations (let/const) through codegen
Distinguishes between `LValue` and `Place`. For the most part this is the same 
data structure (LValue composes Place), but it's helpful to distinguish them 
since LValue has other properties such as the kind of declaration. The 
representations may diverge more in the future. 

This change lets us correctly emit code for variable declarations: previously we 
didn't emit `let` or `const`.
2022-10-06 08:56:20 -07:00
Joseph Savona
90ab346505 [new-arch][easy] Codegen for switch statements
Flushes out basic codegen for switch statements. This is more indication that we 
can recover nearly the original source even for complex control-flow, given the 
right IR design.
2022-10-05 19:45:05 -07:00
Joseph Savona
f5f9143381 [new-architecture] Reassignment-safe frozenness inference
NOTE: this improves the equivalent of "ref kind inference" in the new 
architecture. I'd appreciate review here on the algorithm in particular, but in 
general my plan is to try to implement this on the current architecture. 

The previous InferMutability reference kind inference didn't properly handle 
capturing or reassignment combined with control flow. This is a new version 
(i'll clean up to delete InferMutability entirely) that is less ambitious but 
fully accurate (i hope, hence WIP): 

* Annotates all references of frozen variables as frozen. This includes 
following reassignment, so if you do `const x = props.x; foo(x);` we know that 
`x` is frozen because it derived from a frozen value. This even works 
conditionally, so if `x` is conditionally assigned to some value derived from eg 
props, and you later use `x`, that will be marked as frozen even if it could 
have other values at runtime (since it must conservatively assume a frozen value 
flowed in at runtime). 

* Annotates references that may mutate as mutable. 

* Annotates references that are not frozen, but not mutated _at this reference 
site_, as readonly. It's possible that a readonly usage is followed by a mutable 
usage, since we don't yet know the "lifetime" of the mutability. 

The notable difference from the previous attempt is that we do not attempt to 
find the point at which a formerly-mutable values becomes readonly (and 
therefore eligible for caching). That requires pointer analysis, let's discuss 
offline.
2022-10-05 13:56:13 -07:00
Xuan Huang (黄玄)
e877f89dda Allow comment annotation to be spaced
I.e. `/* readonly */` is fine too 

commit-id:1437395a
2022-10-05 13:30:25 -04:00
Xuan Huang (黄玄)
83f3999a2e Support var declaration hoisting
Var declarations were treated identical as other declarations which cause code 
relying on them getting hoisted now triggers runtime exception on TDZ. 

This diff fixed that by generating `var` for `var` so they can be hoisted as 
usual. 

commit-id:00ab02f6
2022-10-05 13:23:37 -04:00
Josh Story
e40893d097 add tests for resource emission when rendering no head or just a head (#25433) 2022-10-05 10:14:40 -07:00
dependabot[bot]
792343dd86 Bump css-what from 2.1.0 to 2.1.3 in /fixtures/flight (#25434) 2022-10-05 17:00:21 +00:00
dependabot[bot]
aea1e6fb37 Bump css-what from 2.1.0 to 2.1.3 in /fixtures/expiration (#25431)
Bumps [css-what](https://github.com/fb55/css-what) from 2.1.0 to 2.1.3.
- [Release notes](https://github.com/fb55/css-what/releases)
- [Commits](https://github.com/fb55/css-what/compare/v2.1.0...v2.1.3)

---
updated-dependencies:
- dependency-name: css-what
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-10-05 12:54:19 -04:00
dependabot[bot]
5aec50533c Bump css-what from 2.1.0 to 2.1.3 in /fixtures/attribute-behavior (#25429)
Bumps [css-what](https://github.com/fb55/css-what) from 2.1.0 to 2.1.3.
- [Release notes](https://github.com/fb55/css-what/releases)
- [Commits](https://github.com/fb55/css-what/compare/v2.1.0...v2.1.3)

---
updated-dependencies:
- dependency-name: css-what
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-10-05 12:53:42 -04:00
dependabot[bot]
da876b9809 Bump css-what from 2.1.0 to 2.1.3 in /fixtures/fiber-debugger (#25430)
Bumps [css-what](https://github.com/fb55/css-what) from 2.1.0 to 2.1.3.
- [Release notes](https://github.com/fb55/css-what/releases)
- [Commits](https://github.com/fb55/css-what/compare/v2.1.0...v2.1.3)

---
updated-dependencies:
- dependency-name: css-what
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-10-05 12:53:32 -04:00
Josh Story
618388bc32 [Float] Support script preloads (#25432)
* support script preloads

* gates
2022-10-05 09:47:35 -07:00
Sebastian Silbermann
65b3449c89 Include install command for devtools-extension build instructions (#25053)
Include install command for devtools-extension build instructions
2022-10-05 11:27:09 -04:00
Josh Story
2872a26e14 track resources in different roots separately (#25388)
* track resources in different roots separately

* flow types

* add test demonstrating portals deep into shadowRoots

* revert hostcontext changes

* lints

* funge style cache key a la ReactDOMComponentTree

* hide hacks in componentTree
2022-10-04 16:11:15 -07:00
Jan Kassens
ea04a486a7 Flow: remove unused suppressions (#25424)
Removes $FlowFixMe's that are no longer needed.

Used flow/tool from the Flow repo:

```
 ~/Developer/flow/tool update-suppressions .
```
2022-10-04 16:18:12 -04:00
Jan Kassens
9813edef29 Flow upgrade to 0.188
ghstack-source-id: 5c359b97cc
Pull Request resolved: https://github.com/facebook/react/pull/25423
2022-10-04 15:49:48 -04:00
Jan Kassens
3b6826ed9e Flow: inference_mode=constrain_writes
This mode is going to be the new default in Flow going forward.
There was an unfortuante large number of suppressions in this update.

More on the changes can be found in this [Flow blog post](https://medium.com/flow-type/new-flow-language-rule-constrained-writes-4c70e375d190).

Added some of the required annotations using the provided codemod:

```sh
node_modules/.bin/flow codemod annotate-declarations --write .
```

ghstack-source-id: 0b168e1b23
Pull Request resolved: https://github.com/facebook/react/pull/25422
2022-10-04 15:49:48 -04:00
lauren
af9afe9b3f Update safe-string-coercion to handle additions of string literals (#25286)
* Update safe-string-coercion to handle additions of string literals

Adding strings shouldn't trigger a lint violation of this rule, since
adding strings are always safe.
2022-10-04 12:29:36 -07:00
Jan Kassens
aed33a49cc Flow upgrade to 0.185
ghstack-source-id: 8104710c96
Pull Request resolved: https://github.com/facebook/react/pull/25420
2022-10-04 13:50:59 -04:00
Jan Kassens
f02a5f5c79 Flow upgrade to 0.182
ghstack-source-id: b9bb8c1560
Pull Request resolved: https://github.com/facebook/react/pull/25419
2022-10-04 13:37:58 -04:00
Jan Kassens
72593f008e Flow upgrade to 0.176
This upgrade deprecated calling `new` on functions which introduced
the majority of breakages and I suppressed those.

ghstack-source-id: 545363f3c5
Pull Request resolved: https://github.com/facebook/react/pull/25418
2022-10-04 13:37:58 -04:00
Jan Kassens
46d40f306a Flow upgrade to 0.175
ghstack-source-id: 99008118ef
Pull Request resolved: https://github.com/facebook/react/pull/25417
2022-10-04 13:37:58 -04:00
Jan Kassens
1089faf0d8 Flow: run codemod to remove existential type
The existential type `*` was deprecated and a codemod provided to replace it. Ran that and did some manual fixups:

```sh
node_modules/.bin/flow codemod replace-existentials --write .
```

ghstack-source-id: 4c98b8db6a
Pull Request resolved: https://github.com/facebook/react/pull/25416
2022-10-04 13:37:58 -04:00
Lauren Tan
3fd9bd8e74 Add RulesOfHooks support for use
Usage of the new `use` hook needs to conform to the rules of hooks, with
the one exception that it can be called conditionally.

ghstack-source-id: 7ea5beceaf
Pull Request resolved: https://github.com/facebook/react/pull/25370
2022-10-04 12:41:29 -04:00
Jan Kassens
338e6a967c Flow upgrade to 0.155
This version banned use of this in object functions.

ghstack-source-id: f49fd5e1b7
Pull Request resolved: https://github.com/facebook/react/pull/25414
2022-10-04 11:49:15 -04:00
Jan Kassens
8bc95bb3c8 Flow upgrade to 0.154
ghstack-source-id: d84024950a
Pull Request resolved: https://github.com/facebook/react/pull/25413
2022-10-04 11:49:14 -04:00
Jan Kassens
9f8a98a390 Flow upgrade to 0.153
- method unbinding is no longer supported in Flow for soundness, this added a bunch of suppressions
- Flow now prevents objects to be supertypes of interfaces/classes

ghstack-source-id: d7749cbad8
Pull Request resolved: https://github.com/facebook/react/pull/25412
2022-10-04 11:30:06 -04:00
Jan Kassens
adb58f529d Flow upgrade to 0.152
- 0.147 removes access to Object.prototype via the global object.
- 0.149 removed deprecated config options

ghstack-source-id: c77f9b3739
Pull Request resolved: https://github.com/facebook/react/pull/25411
2022-10-04 11:30:06 -04:00
Jan Kassens
64fe791be8 Flow upgrade to 0.146
This upgrade made more expressions invalidate refinements. In some
places this lead to a large number of suppressions that I automatically
suppressed and should be followed up on when the code is touched.
I think most of them might require either manual annotations or moving
a value into a const to allow refinement.

ghstack-source-id: a45b40abf0
Pull Request resolved: https://github.com/facebook/react/pull/25410
2022-10-04 11:01:50 -04:00
Jan Kassens
d3c6c16a03 Flow upgrade to 0.145
Fixed a RN library definition that defined `CustomEvent` as a reference to itself.

ghstack-source-id: 90da2e316f
Pull Request resolved: https://github.com/facebook/react/pull/25409
2022-10-04 11:01:50 -04:00
Jan Kassens
00a2f81508 Flow upgrade to 0.143
This was a large upgrade that removed "classic mode" and made "types first" the only option.
Most of the needed changes have been done in previous PRs, this just fixes up the last few instances.

ghstack-source-id: 9612d95ba4
Pull Request resolved: https://github.com/facebook/react/pull/25408
2022-10-04 11:01:50 -04:00
Jan Kassens
0a3072278e Flow: complete types first migration (#25389)
This complete the "types first" migration and enables the config everywhere.
2022-10-03 21:59:33 -04:00
Jan Kassens
bcc05671fc Flow: types first in shared (#25343) 2022-10-03 20:57:34 -04:00
Jan Kassens
dc52b6739e Add NodeJS 18.x as devEngine (#25348) 2022-10-03 20:57:06 -04:00
Jan Kassens
b1f34aa307 Flow: types first in react-native-renderer (#25363) 2022-10-03 17:03:33 -04:00
Jan Kassens
9143864ae1 Flow: well formed exports for smaller packages (#25361)
Enforces well formed exports for packages where the fixes are small.
2022-10-03 16:52:41 -04:00
Jan Kassens
94ac306688 CI: update CircleCI docker image (#25374)
This updates to an image that's using node 16.16.0 and java 18.0.2.

| Package | Old    | New
| ------ | ------- | ---
| git    | 2.32.0  | 2.37.1
| gradle | 7.2     | 7.5.1
| java   | 17      | 18.0.2
| maven  | 3.8.2   | 3.8.6
| node   | 14.17.6 | 16.16.0
| ubuntu | 20.04.2 LTS |  20.04.4 LTS
| yarn   | 1.22.5 |  1.22.5
2022-10-03 16:52:14 -04:00
Mofei Zhang
896ef251b4 patch makeReadOnly into playground 2022-10-03 14:37:24 -04:00
Mofei Zhang
4e0639c2dc Add makeReadOnly codegen into the compiler 2022-10-03 14:37:23 -04:00
Kirankumar Ambati
2d80a0cd69 Fix: Updated link in CONTRIBUTING (#25381) 2022-10-03 10:29:57 -04:00
dependabot[bot]
041dbe2e1f Bump eventsource from 1.0.7 to 1.1.2 (#25386)
Bumps [eventsource](https://github.com/EventSource/eventsource) from 1.0.7 to 1.1.2.
- [Release notes](https://github.com/EventSource/eventsource/releases)
- [Changelog](https://github.com/EventSource/eventsource/blob/master/HISTORY.md)
- [Commits](https://github.com/EventSource/eventsource/compare/v1.0.7...v1.1.2)

---
updated-dependencies:
- dependency-name: eventsource
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-10-03 10:28:38 -04:00
dependabot[bot]
55811834b0 Bump eventsource from 1.0.7 to 1.1.2 in /fixtures/blocks (#25385)
Bumps [eventsource](https://github.com/EventSource/eventsource) from 1.0.7 to 1.1.2.
- [Release notes](https://github.com/EventSource/eventsource/releases)
- [Changelog](https://github.com/EventSource/eventsource/blob/master/HISTORY.md)
- [Commits](https://github.com/EventSource/eventsource/compare/v1.0.7...v1.1.2)

---
updated-dependencies:
- dependency-name: eventsource
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-10-03 10:16:08 -04:00
Alexandru Tasica
21a851e035 Fix devtools typos and grammar (#24587)
Closes #24587
2022-10-03 10:11:40 -04:00
Kerim Büyükakyüz
cfafeb6858 Remove extra space in Wedge.js (#24611) 2022-10-03 10:03:56 -04:00
Jan Kassens
9c3de25e1c Flow: types first in reconciler (#25362)
This contains one code change, renaming the local function `ChildReconciler` to `createChildReconciler` as it's called as a function, not a constructor and to free up the name for the return value.
2022-10-01 18:47:32 -04:00
Sebastian Silbermann
0033d1a98c Fix failing tests in latest 16.x and 18.x Node versions (#25378) 2022-10-01 17:12:28 -04:00
Josh Story
7b25b961df [Fizz/Float] Float for stylesheet resources (#25243)
* [Fizz/Float] Float for stylesheet resources

This commit implements Float in Fizz and on the Client. The initial set of supported APIs is roughly

1. Convert certain stylesheets into style Resources when opting in with precedence prop
2. Emit preloads for stylesheets and explicit preload tags
3. Dedupe all Resources by href
4. Implement ReactDOM.preload() to allow for imperative preloading
5. Implement ReactDOM.preinit() to allow for imperative preinitialization

Currently supports
1. style Resources (link rel "stylesheet")
2. font Resources (preload as "font")

later updates will include support for scripts and modules
2022-09-30 16:14:04 -07:00
Jan Kassens
d061e6e7d4 CI: delete old AppVeyor config (#25373)
I noticed this file as #24892 is updating the NodeJS version in it.

I don't think this is used for anything as the config just runs a handful
of yarn commands and I assume that's all covered by CircleCI.
2022-09-30 19:02:25 -04:00
zhangrenyang
4c016e7aaf Refactor: use property shorthand (#25366) 2022-09-30 17:50:08 -04:00
Lauren Tan
06066c1a5a Make RulesOfHooks-test more consistent with ExhaustiveDeps-test
Small formatting changes to make the tests consistent.

ghstack-source-id: 7013a37f1f
Pull Request resolved: https://github.com/facebook/react/pull/25369
2022-09-30 15:16:22 -04:00
Lauren Tan
49ae0fad84 Fix RulesOfHooks test case indentation
Just a small formatting fix.

ghstack-source-id: c71ff02ed9
Pull Request resolved: https://github.com/facebook/react/pull/25368
2022-09-30 15:16:22 -04:00
Samuel Susla
abbbdf4cec Put modern StrictMode behind a feature flag (#25365)
* Put modern StrictMode behind a feature flag

* Remove unneeded flag
2022-09-30 17:06:11 +01:00
Igor Berlenko
434110390a ReactHooks.js - delete emptyObject (#25031)
It's not mentioned in docs and never used by projects.. should be removed..
2022-09-30 11:29:51 -04:00
jerry-lllman
31400ce293 Refactor: merge duplicate imports (#25364) 2022-09-30 09:57:50 -04:00
Lauren Tan
3517bd9f77 Refactor useEvent (#25336)
* Refactor useEvent

Previously, the useEvent implementation made use of effect infra under
the hood. This was a lot of extra overhead for functionality we didn't
use (events have no deps, and no clean up functions). This PR refactors
the implementation to instead use a queue to ensure that the callback is
stable across renders.

Additionally, the function signature was updated to infer the callback's argument types and return value. While this doesn't affect anything internal it more accurately describes what's being passed.
2022-09-29 13:45:27 -07:00
Jan Kassens
abd7bcd8b2 Flow: remove max_workers setting (#25349)
This was added back in #17880 to make CI pass for an unrelated change.

This limits the max worker setting to CI environments as removing the setting completely still seems to break on CircleCI.
2022-09-29 14:49:41 -04:00
Mofei Zhang
72775fba10 makeReadOnly implementation
Added utility package to track mutations to objects marked as "read-only".
2022-09-29 14:17:38 -04:00
Joseph Savona
3158146989 POC of new expression-oriented inference model for memoization within control-flow (#589)
* [hir] Core data types and lowering for new model

* Handle more expressions, including using babel for binding resolution

* test setup with pretty printing of ir

* Basic codegen and improved pretty printing

* avoid else block when if has no fallthrough

* emit function declarations with mapped name/params

* start of scope analysis

* saving state pre-run

* add slightly more complex example and flush out lowering/printing (jsx, new, variables)

* Various improvements:
* Convert logical expressions (|| and &&) to control flow, accounting
  for lazy evaluation semantics.
* Handle expression statements
* Improve printing of HIR for unsupported node kinds
* Handle more cases of JSX by falling by to OtherStatement to wrap
  subtrees at coarse granularity.

* improve HIR printing, lowering of expression statements

* handle object expression printing

* improve IR model for values/places along w codegen

* more test cases

* start of mutability inference

* passable but still incorrect mutability inference

* improved mutability inference, should cover most cases now

* visualization of reference graph

* correctly flow mutability backwards (have to actually set the capability)

* separate visualization in output

* consolidate on frozen/readonly/mutable capabilities

* cleanup

* conditional reassignment test (not quite working)

* hack to output svg files for debugging

* handle conditional reassignment

* improve capture analysis

* treat jsx as (interior) mutable; handle memberexpression lvalues

* lots of comments; hook return is frozen

* update main comment

* inference for switch, which reveals a bug

* fix yarn.lock
2024-03-25 10:39:47 +00:00
Xuan Huang (黄玄)
a33c0b897c Initial commit 2024-03-25 10:39:47 +00:00
Sreecharan
8ee4f52989 Fix: Documentation typos (#24471)
* fix: typo

Co-authored-by: Jan Kassens <jkassens@meta.com>
2022-09-29 12:46:53 -04:00
zhangenming
6cf06a9297 Remove outdated comments. (#24464)
fixed by https://github.com/facebook/react/pull/20894
2022-09-29 12:40:42 -04:00
Vic Graf
20a257c259 Refactor: more word doubles removed (#25352) 2022-09-29 09:57:49 -04:00
zhangrenyang
8cadcffd5d Fix typo: reconcilation -> reconciliation (#25355) 2022-09-29 09:34:30 -04:00
Sebastian Markbåge
ebbe599a25 Fix EventListener fork (#25347) 2022-09-28 19:45:59 -04:00
dependabot[bot]
904555eb64 Bump mout from 1.1.0 to 1.2.4 in /fixtures/packaging/brunch/dev (#25346)
Bumps [mout](https://github.com/mout/mout) from 1.1.0 to 1.2.4.
- [Release notes](https://github.com/mout/mout/releases)
- [Changelog](https://github.com/mout/mout/blob/master/CHANGELOG.md)
- [Commits](https://github.com/mout/mout/compare/v1.1.0...v1.2.4)

---
updated-dependencies:
- dependency-name: mout
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-09-28 19:44:04 -04:00
Sebastian Markbåge
97d75c9c8b Move react-dom implementation files to react-dom-bindings (#25345)
This lets us share it with react-server-dom-webpack while still having a
dependency on react-dom. It also makes somewhat sense from a bundling
perspective since react-dom is an external to itself.
2022-09-28 19:05:50 -04:00
dan
3de9264496 [Fizz] experimental_useEvent (#25325)
* [Fizz] useEvent

* Use same message on client and server
2022-09-27 20:42:16 +01:00
Vic Graf
ae7ad8b4c2 refactor: removed duplicated words in comments (#25332) 2022-09-27 10:07:46 -04:00
Vic Graf
5b59dd6400 Fix duplicate words tests (#25333)
* refactor: removed duplicated words in comments
* refactor: removed duplicate words in tests
2022-09-27 10:07:06 -04:00
Lauren Tan
cb5084d1c4 [ESLint] Check useEvent references instead (#25319)
* [ESLint] Check useEvent references instead

Previously the useEvent check in RulesOfHooks would collect all
definitions of useEvent functions at the top level, record them as
violations, then clear those violations if the useEvent function was
later called or referened inside of an effect or another event.

The flaw with this approach was in the special case where useEvent
functions could be passed by reference inside of effects or events. The
violation would be cleared here (since it was called at least once)
and subsequent usages of the useEvent function would not be properly
checked.

This PR changes it so we check all identifiers that resolve to a
useEvent function, and if they are not in an effect or event must be
called or a lint error is emitted.

Co-authored-by: Dan Abramov <dan.abramov@gmail.com>

* Add comment

Co-authored-by: Dan Abramov <dan.abramov@gmail.com>
2022-09-24 01:34:17 +01:00
Lauren Tan
c89a83695c Update RulesOfHooks with useEvent rules (#25285)
This update to the RulesOfHooks rule checks that functions created with
`useEvent` can only be invoked in a `useEffect` callback, in another
event function, or a closure.
They can't be passed down directly as a reference to child components.

This PR also updates the ExhaustiveDeps lint rule to treat useEvent's 
return value as stable, so it can be omitted from dependency lists.

Currently this all gated behind an experimental flag.

Co-authored-by: Dan Abramov <dan.abramov@gmail.com>
2022-09-23 14:55:12 -07:00
Josh Story
efc6a08e98 [Flight] Implement error digests for Flight runtime and expose errorInfo in getDerivedStateFromError (#25302)
Similar to Fizz, Flight now supports a return value from the user provided onError option. If a value is returned from onError it will be serialized and provided to the client.

The digest is stashed on the constructed Error on the client as .digest
2022-09-23 13:19:29 -07:00
Samuel Susla
c1d414d758 Add ref to Offscreen component (#25254)
* Expose ref to Offscreen if mode is manual

* Prepend private fields on OffscreenInstance with underscore

* Schedule Ref effect unconditionally on Offscreen

* Make sure Offscreen's ref is detached when unmounted

* Make sure ref is mounted/unmounted in all scenarious

* Nit: pendingProps -> memoizedProps

Co-authored-by: Andrew Clark <git@andrewclark.io>
2022-09-23 11:31:34 -04:00
Jan Kassens
135e33c954 Flow: typing of Scheduler (#25317)
Enables well formed exports for /scheduler. Some of the modules there were missing `@flow` and were therefore completely unchecked (despite some spurious types sprinkled around).
2022-09-23 10:28:34 -04:00
Jan Kassens
cc8cb145f0 Flow: add some missing types in react-reconciler (#25316)
To enable the next Flow version, we need to annotate exported values. This adds a few automatically inferred types that didn't look huge or just `any`.
2022-09-23 10:28:00 -04:00
Josh Story
112d0498c8 [Fizz] Move digest from errorInfo to Error instance (#25313)
* suspense boundary error digest to Error instance and deprecate digest from errorInfo for onRecoverableError

* fix closure escape
2022-09-22 12:40:30 -07:00
Andrew Clark
d1bb1c5861 Fix memory leak after repeated setState bailouts (#25309)
There's a global queue (`concurrentQueues` in the
ReactFiberConcurrentUpdates module) that is cleared at the beginning of
each render phase.

However, in the case of an eager `setState` bailout where the state is
updated to same value as the current one, we add the update to the queue
without scheduling a render. So the render phase never removes it from
the queue. This can lead to a memory leak if it happens repeatedly
without any other updates.

There's only one place where this ever happens, so the fix was pretty
straightforward.

Currently there's no great way to test this from a Jest test, so I
confirmed locally by checking in an existing test whether the array gets
reset. @sompylasar had an interesting suggestion for how to catch these
in the future: in the development build (perhaps behind a flag), use a
Babel plugin to instrument all module-level variables. Then periodically
sweep to confirm if something has leaked. The logic is that if there's
no React work scheduled, and a module-level variable points to an
object, it very likely indicates a memory leak.
2022-09-22 11:19:54 -04:00
Samuel Susla
0cac4d54c3 Double invoked effects on suspended children (#25307)
Co-authored-by: Robert Balicki <robertbalicki@fb.com>
2022-09-21 16:58:04 +01:00
Brandon Chan
b2748907c3 Updated the URL link for serve (#25296) 2022-09-19 13:13:38 -04:00
Victoria Graf
3d615fc14a Grammar. Removed doubles of the word "the". (#25295) 2022-09-19 10:04:03 -04:00
Tianyu Yao
e099e1dc0e React DevTools 4.25.0 -> 4.26.0 (#25283) 2022-09-16 12:35:00 -07:00
Tianyu Yao
6e3bc8a2e8 [DevTools] Check if Proxy exists before creating DispatcherProxy (#25278) 2022-09-16 11:24:03 -07:00
Tianyu Yao
8951c5fc9d [DevTools][BE] Read username using gh in release script (#25270)
* [DevTools][BE] Read username using gh in release script

* better regex & fix lint
2022-09-15 18:12:46 -07:00
Josh Story
e7fc04b297 [react-dom] Reorganize react-dom internals to match react (#25277)
* reorganize react-dom internals to match react

* refactor and make forks work for flow and internal imports

* flew too close to the sun

* typo
2022-09-15 15:31:31 -07:00
Jan Kassens
fc16293f3f Flow: well_formed_exports for devtools (#25266) 2022-09-15 16:45:29 -04:00
Sebastian Markbåge
0b54e00475 Handle rejections to avoid uncaught rejections (#25272) 2022-09-14 23:22:27 -04:00
Sebastian Markbåge
c5d06fdc5d [Flight] Fix Webpack Chunk Loading (#25271)
* Fix acorn import

I'm not sure how this ever worked.

* Fix cache to wait for entries already added to the chunk cache

* Modernize API
2022-09-14 22:57:35 -04:00
Sebastian Markbåge
975b644643 [Flight] response.readRoot() -> use(response) (#25267)
* [Flight] Move from suspensey readRoot() to use(thenable)

* Update noop tests

These are no longer sync so they need some more significant updating.

Some of these tests are written in a non-idiomatic form too which is not
great.

* Update Relay tests

I kept these as sync for now and just assume a sync Promise.

* Updated the main tests

* Gate tests

* We need to cast through any because Thenable doesn't support unknown strings
2022-09-14 20:20:33 -04:00
Sebastian Markbåge
60fbb7b143 [Flight] Implement FlightClient in terms of Thenable/Promises instead of throwing Promises (#25260)
* [Flight] Align Chunks with Thenable used with experimental_use

Use the field names used by the Thenable data structure passed to use().
These are considered public in this model.

This adds another field since we use a separate field name for "reason".

* Implement Thenable Protocol on Chunks

This doesn't just ping but resolves/rejects with the value.

* Subclass Promises

* Pass key through JSON parsing

* Wait for preloadModules before resolving module chunks

* Initialize lazy resolved values before reading the result

* Block a model from initializing if its direct dependencies are pending

If a module is blocked, then we can't complete initializing a model.
However, we can still let it parse, and then fill in the missing pieces
later.

We need to block it from resolving until all dependencies have filled in
which we can do with a ref count.

* Treat blocked modules or models as a special status

We currently loop over all chunks at the end to error them if they're
still pending. We shouldn't do this if they're pending because they're
blocked on an external resource like a module because the module might not
resolve before the Flight connection closes and that's not an error.

In an alternative solution I had a set that tracked pending chunks and
removed one at a time. While the loop at the end is faster it's more
work as we go.

I figured the extra status might also help debugging.

For modules we can probably assume no forward references, and the first
async module we can just use the promise as the chunk.

So we could probably get away with this only on models that are blocked by
modules.
2022-09-14 20:13:33 -04:00
Lauren Tan
c91a1e03be experimental_useEvent (#25229)
This commit adds a new hook `useEvent` per the RFC [here](https://github.com/reactjs/rfcs/pull/220), gated as experimental. 

Co-authored-by: Rick Hanlon <rickhanlonii@gmail.com>
Co-authored-by: Rick Hanlon <rickhanlonii@fb.com>
Co-authored-by: Lauren Tan <poteto@users.noreply.github.com>
2022-09-14 11:39:06 -07:00
Srikanth Kolli
2248dccfb3 [DevTools] Show DevTools icons in Edge browser panel (#25257)
Show DevTools icons in Edge browser panel
2022-09-14 13:50:57 -04:00
Jan Kassens
c327b91d22 CI: try to make caching more reliable (#25259)
- `~/.yarn/cache` is now restored from an hierarchical cache key, if no precise match is found, we fallback to less precise ones. 
- The yarn install in `fixtures/dom` is also cached. Notably, is utilizes the cache from root, but stores into its more precise key.
- Steps running in root no longer have a `yarn install` and rely on the cache from the setup step.
- Retry `yarn install` once on failure.
2022-09-14 13:22:20 -04:00
Jan Kassens
afe664d9d7 Flow: upgrade to 0.142 (#25255) 2022-09-13 18:39:26 -04:00
Jan Kassens
346c7d4c43 straightford explicit types (#25253) 2022-09-13 17:57:38 -04:00
Jan Kassens
aca7f30c95 CI: extract node_modules cache key computation (#25258) 2022-09-13 17:54:00 -04:00
Joseph Savona
3401e9200e useMemoCache implementation (#25143)
* useMemoCache impl
* test for multiple calls in a component (from custom hook)
* Use array of arrays for multiple calls; use alternate/local as the backup
* code cleanup
* fix internal test
* oops we do not support nullable property access
* Simplify implementation, still have questions on some of the PR feedback though
* Gate all code based on the feature flag
* refactor to use updateQueue
* address feedback
* Try to eliminate size increase in prod bundle
* update to retrigger ci
2022-09-13 14:44:32 -07:00
Luna Ruan
0556bab32c [Transition Tracing] More Accurate End Time (#25105)
add more accurate end time for transitions and update host configs with `requestPostPaintCallback` function and move post paint logic to another module and use it in the work loop
2022-09-13 10:55:56 -07:00
Jan Kassens
5fdcd23aaa Flow: upgrade to 0.140 (#25252)
This update range includes:

- `types_first` ([blog](https://flow.org/en/docs/lang/types-first/), all exports need annotated types) is default. I disabled this for now to make that change incremental.
- Generics that escape the scope they are defined in are an error. I fixed some with explicit type annotations and some are suppressed that I didn't easily figure out.
2022-09-13 13:33:43 -04:00
Jan Kassens
e6a062bd2a Flow: add simple explicit export types to Devtools (#25251) 2022-09-13 12:03:20 -04:00
Robert Balicki
271bf90a94 [react devtools][easy] Centralize calls to patchConsoleUsingWindowValues (#25222)
* Instead of reading from window in two separate places, do this in a single function
* Add some type safety
2022-09-13 11:24:10 -04:00
Sebastian Markbåge
5c43c6f026 Unwind the current workInProgress if it's suspended (#25247)
Usually we complete workInProgress before yielding but if that's the
currently suspended one, we don't yet complete it in case we can
immediately unblock it.

If we get interrupted, however, we must unwind it. Where as we usually
assume that we've already completed it.

This shows up when the current work in progress was a Context that pushed
and then it suspends in its immediate children. If we don't unwind,
it won't pop and so we get an imbalance.
2022-09-13 11:18:57 -04:00
Samuel Susla
e52fa4c575 Add early exit to strict mode (#25235) 2022-09-13 12:08:51 +01:00
Akul Srivastava
f2e4ff082d fix: prettier ignore removed and fixed (#24811) 2022-09-12 21:16:29 -04:00
Jan Kassens
6aa38e74c7 Flow: enable unsafe-addition error (#25242) 2022-09-12 16:22:50 -04:00
Jan Kassens
ba7b6f4183 Flow: upgrade to 0.132 (#25244) 2022-09-12 14:36:02 -04:00
Jan Kassens
9328988c02 Flow: fix Fiber typed as any (#25241) 2022-09-12 13:44:58 -04:00
Jan Kassens
c739cef2fc Flow: ReactFiberHotReloading recursive type (#25225) 2022-09-12 10:25:01 -04:00
Sebastian Markbåge
c156ecd483 Add some test coverage for some error cases (#25240) 2022-09-11 21:53:00 -04:00
mofeiZ
3613284dce experimental_use(context) for server components and ssr (#25226)
implements the experimental use(context) API for the server components (Flight) and SSR (Fizz) runtimes
2022-09-09 21:19:28 -04:00
Jan Kassens
d5ddc6543e Flow: upgrade to 0.131 (#25224)
This also downgrades the new lint warning to avoid new suppressions with this upgrade.
2022-09-09 16:21:32 -04:00
Samuel Susla
269c4e975f Prevent infinite re-renders in StrictMode + Offscreen (#25203)
* Prevent infinite re-render in StrictMode + Offscreen

* Only fire effects for Offscreen when it is revealed

* Move setting debug fiber into if branch

* Move settings of debug fiber out of if branch
2022-09-09 21:10:26 +01:00
Jan Kassens
8003ab9cf5 Flow: remove explicit object syntax (#25223) 2022-09-09 16:03:48 -04:00
Jan Kassens
492c6e29e7 Flow: upgrade to 0.127 (#25221)
A smaller incremental update as some next version was changing more.
2022-09-09 12:21:44 -04:00
Jan Kassens
bbd56b278c Flow: enable exact_by_default (#25220)
With this change, a simple object type `{ }` means an exact object `{| |}` which most people assume.
Opting for inexact requires the extra `{ a: number, ... }` syntax at the end.

A followup, someone could replace all the `{| |}` with `{ }`.
2022-09-09 12:16:40 -04:00
Robert Balicki
425f9fbba0 [react devtools] Don't check for NODE_ENV==='test' because it never is (#25186)
* remove useless condition
2022-09-09 11:31:32 -04:00
Robert Balicki
540ba5b403 [react devtools][easy] Change variable names, etc. (#25211)
* Change variable names, put stuff in constants, etc. in preparation for next diff
2022-09-09 11:09:30 -04:00
dependabot[bot]
b0593dd964 Bump async from 2.6.3 to 2.6.4 in /fixtures/concurrent/time-slicing (#24443)
Bumps [async](https://github.com/caolan/async) from 2.6.3 to 2.6.4.
- [Release notes](https://github.com/caolan/async/releases)
- [Changelog](https://github.com/caolan/async/blob/v2.6.4/CHANGELOG.md)
- [Commits](https://github.com/caolan/async/compare/v2.6.3...v2.6.4)

---
updated-dependencies:
- dependency-name: async
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-09-09 10:56:21 -04:00
Jan Kassens
8a9e7b6cef Flow: implicit-inexact-object=error (#25210)
* implicit-inexact-object=error
* default everything ambiguous to exact object
* inexact where exact causes errors
2022-09-09 10:13:58 -04:00
Sebastian Markbåge
37cc6bf124 Remove useDeferredValue and useTransition from Flight subset (#25215) 2022-09-09 09:32:40 -04:00
Andrew Clark
c28f313e6d experimental_use(promise) for SSR (#25214)
Follow up to #25084 and #25207. Implements experimental_use(promise) API
in the SSR runtime (Fizz).

This is largely a copy-paste of the Flight implementation. I have
intentionally tried to keep both as close as possible.
2022-09-08 21:47:33 -04:00
Sebastian Markbåge
d6f9628a8c Remove some RSC subset entry points that were removed in the main entry point (#25209) 2022-09-08 13:25:10 -04:00
Jan Kassens
a473d08fce Update to Flow from 0.97 to 0.122 (#25204)
* flow 0.122
* update ReactModel type
2022-09-08 11:46:07 -04:00
dependabot[bot]
fe55c0ea09 Bump jsdom from 16.4.0 to 16.7.0 in /fixtures/legacy-jsx-runtimes (#24924)
Bumps [jsdom](https://github.com/jsdom/jsdom) from 16.4.0 to 16.7.0.
- [Release notes](https://github.com/jsdom/jsdom/releases)
- [Changelog](https://github.com/jsdom/jsdom/blob/master/Changelog.md)
- [Commits](https://github.com/jsdom/jsdom/compare/16.4.0...16.7.0)

---
updated-dependencies:
- dependency-name: jsdom
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-09-08 11:02:18 -04:00
dependabot[bot]
f094ee56d1 Bump terser from 4.6.13 to 4.8.1 (#24971)
Bumps [terser](https://github.com/terser/terser) from 4.6.13 to 4.8.1.
- [Release notes](https://github.com/terser/terser/releases)
- [Changelog](https://github.com/terser/terser/blob/master/CHANGELOG.md)
- [Commits](https://github.com/terser/terser/commits)

---
updated-dependencies:
- dependency-name: terser
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-09-08 10:57:43 -04:00
dependabot[bot]
0d095a3d96 Bump cross-fetch from 3.1.4 to 3.1.5 (#24462) 2022-09-08 14:55:35 +00:00
dependabot[bot]
eaf8a138a9 Bump terser from 4.6.7 to 4.8.1 in /fixtures/blocks (#24970)
Bumps [terser](https://github.com/terser/terser) from 4.6.7 to 4.8.1.
- [Release notes](https://github.com/terser/terser/releases)
- [Changelog](https://github.com/terser/terser/blob/master/CHANGELOG.md)
- [Commits](https://github.com/terser/terser/commits)

---
updated-dependencies:
- dependency-name: terser
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-09-08 10:49:16 -04:00
dependabot[bot]
15d6bd79b5 Bump terser from 4.8.0 to 4.8.1 in /fixtures/fizz (#24974)
Bumps [terser](https://github.com/terser/terser) from 4.8.0 to 4.8.1.
- [Release notes](https://github.com/terser/terser/releases)
- [Changelog](https://github.com/terser/terser/blob/master/CHANGELOG.md)
- [Commits](https://github.com/terser/terser/commits)

---
updated-dependencies:
- dependency-name: terser
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-09-08 10:27:54 -04:00
dependabot[bot]
84d7e3720d Bump shell-quote in /fixtures/packaging/browserify/dev (#24773) 2022-09-08 14:26:04 +00:00
dependabot[bot]
e1020aa52a Bump moment from 2.24.0 to 2.29.4 (#24875) 2022-09-08 14:24:56 +00:00
dependabot[bot]
43aa6f4c88 Bump jpeg-js from 0.4.3 to 0.4.4 (#24747) 2022-09-08 14:23:31 +00:00
dependabot[bot]
126d3bf749 Bump shell-quote in /fixtures/packaging/browserify/prod (#24772) 2022-09-08 14:14:50 +00:00
dependabot[bot]
5ecc6568a1 Bump async from 2.6.3 to 2.6.4 in /fixtures/dom (#24664) 2022-09-08 14:03:21 +00:00
dependabot[bot]
a2331343ba Bump async from 2.6.3 to 2.6.4 in /fixtures/blocks (#24668) 2022-09-08 13:56:07 +00:00
dependabot[bot]
b3ebca7329 Bump moment from 2.29.1 to 2.29.4 in /fixtures/ssr (#24879) 2022-09-08 13:53:25 +00:00
dependabot[bot]
79e2671168 Bump jszip from 2.6.1 to 2.7.0 (#25208)
Bumps [jszip](https://github.com/Stuk/jszip) from 2.6.1 to 2.7.0.
- [Release notes](https://github.com/Stuk/jszip/releases)
- [Changelog](https://github.com/Stuk/jszip/blob/main/CHANGES.md)
- [Commits](https://github.com/Stuk/jszip/commits)

---
updated-dependencies:
- dependency-name: jszip
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-09-08 09:39:33 -04:00
Andrew Clark
7028ce7456 experimental_use(promise) for Server Components (#25207)
Follow up to #25084. Implements experimental_use(promise) API in 
the Server Components runtime (Flight).

The implementation is much simpler than in Fiber because there is no
state. Even the "state" added in this PR — to track the result of each
promise across attempts — is reset as soon as a component 
successfully renders without suspending.

There are also fewer caveats around neglecting to cache a promise
because the state of the promises is preserved even if we switch to a
different task.

Server Components is the primary runtime where this API is intended to
be used.

The last runtime where we need to implement this is the server renderer
(Fizz).
2022-09-07 22:27:04 -04:00
Luna Ruan
c80e54116e [DevTools][Bugfix] Don't hide fragment if it has a key (#25197)
resolves #25187

---

We shouldn't hide fragments that have a key because this is important information that the user might want in the future.
2022-09-07 10:21:30 -07:00
mofeiZ
bfb65681e7 experimental_use(context)(#25202) 2022-09-07 13:09:42 -04:00
Tim Neutkens
a9dc73cfd4 Handle info, group, and groupCollapsed in Strict Mode logging (#25172)
* Handle info, group, and groupCollapsed in Strict Mode logging

While working on the new Next.js router which heavily relies on useReducer I noticed that `group` and `groupCollapsed` which both take labels were showing as-is in the console for the second render/dispatch in Strict Mode logs. While looking at the code I found that `info` was also not instrumented.

I've added additional handling for:
- `info`
- `group`
- `groupCollapsed`

* Remove console.log

* Fix tests
2022-09-06 10:03:27 -07:00
Brandon Chan
81b79c7c29 Added the word 'own' to the README file for design consistency (#25185) 2022-09-06 11:06:18 -04:00
Jan Kassens
f0efa1164b [flow] remove custom suppress comment config (#25170) 2022-09-01 12:55:59 -04:00
bubucuo
2e7f422fea Refactor: its type is Container (#25153) 2022-09-01 10:43:40 -04:00
Jan Kassens
2c2d9a1df0 [eslint-plugin-react-hooks] only allow capitalized component names (#25162)
- update naming rules to disallow _component
- update eslint-plugin-react-hooks version
2022-09-01 10:07:31 -04:00
Sebastian Markbåge
36c908a6c8 Don't use the Flight terminology in public error messages (#25166) 2022-08-31 23:07:56 -04:00
Sebastian Markbåge
8d1b057ec1 [Flight] Minor error handling fixes (#25151)
* Fix error handling when the Flight client itself errors

* Serialize references to errors in the error priority queue

It doesn't make sense to emit references to future values at higher pri
than the value that they're referencing.

This ensures that we don't emit hard forward references to values that
don't yet exist.
2022-08-31 18:40:17 -04:00
Robert Balicki
7e5322ccf2 run prettier (#25164) 2022-08-31 14:20:01 -04:00
Robert Balicki
47867a772e [react devtools][easy] Fix code highlighting in VSCode (#25155)
* Minor change that fixes code highlighting in VSCode in a particular file
2022-08-31 14:07:37 -04:00
Jan Kassens
a40ddf3124 Fix CI: run yarn prettier-all (#25163) 2022-08-31 18:50:04 +01:00
Robert Balicki
aa80a309b1 [react devtools][easy] Rename LOCAL_STORAGE_SHOULD_PATCH_CONSOLE_KEY to LOCAL_STORAGE_SHOULD_APPEND_COMPONENT_STACK_KEY (#25154)
* This more accurately describes what this constant does
2022-08-30 13:32:52 -04:00
Tianyu Yao
9ff738f53f [devtools][easy] Fix flow type (#25147) 2022-08-26 18:47:39 -07:00
Ricky
0de3ddf56e Remove Symbol Polyfill (again) (#25144) 2022-08-25 17:01:30 -04:00
Samuel Susla
b36f722357 Remove ReactFiberFlags MountLayoutDev and MountPassiveDev (#25091) 2022-08-25 20:23:10 +01:00
Andrew Clark
b6978bc38f experimental_use(promise) (#25084)
* Internal `act`: Unwrapping resolved promises

This update our internal implementation of `act` to support React's new
behavior for unwrapping promises. Like we did with Scheduler, when 
something suspends, it will yield to the main thread so the microtasks
can run, then continue in a new task.

I need to implement the same behavior in the public version of `act`,
but there are some additional considerations so I'll do that in a
separate commit.

* Move throwException to after work loop resumes

throwException is the function that finds the nearest boundary and
schedules it for a second render pass. We should only call it right 
before we unwind the stack — not if we receive an immediate ping and
render the fiber again.

This was an oversight in 8ef3a7c that I didn't notice because it happens
to mostly work, anyway. What made me notice the mistake is that
throwException also marks the entire render phase as suspended
(RootDidSuspend or RootDidSuspendWithDelay), which is only supposed to
be happen if we show a fallback. One consequence was that, in the 
RootDidSuspendWithDelay case, the entire commit phase was blocked,
because that's the exit status we use to block a bad fallback
from appearing.

* Use expando to check whether promise has resolved

Add a `status` expando to a thrown thenable to track when its value has
resolved.

In a later step, we'll also use `value` and `reason` expandos to track
the resolved value.

This is not part of the official JavaScript spec — think of
it as an extension of the Promise API, or a custom interface that is a
superset of Thenable. However, it's inspired by the terminology used
by `Promise.allSettled`.

The intent is that this will be a public API — Suspense implementations
can set these expandos to allow React to unwrap the value synchronously
without waiting a microtask.

* Scaffolding for `experimental_use` hook

Sets up a new experimental hook behind a feature flag, but does not
implement it yet.

* use(promise)

Adds experimental support to Fiber for unwrapping the value of a promise
inside a component. It is not yet implemented for Server Components, 
but that is planned.

If promise has already resolved, the value can be unwrapped
"immediately" without showing a fallback. The trick we use to implement
this is to yield to the main thread (literally suspending the work
loop), wait for the microtask queue to drain, then check if the promise
resolved in the meantime. If so, we can resume the last attempted fiber
without unwinding the stack. This functionality was implemented in 
previous commits.

Another feature is that the promises do not need to be cached between
attempts. Because we assume idempotent execution of components, React
will track the promises that were used during the previous attempt and
reuse the result. You shouldn't rely on this property, but during
initial render it mostly just works. Updates are trickier, though,
because if you used an uncached promise, we have no way of knowing 
whether the underlying data has changed, so we have to unwrap the
promise every time. It will still work, but it's inefficient and can
lead to unnecessary fallbacks if it happens during a discrete update.

When we implement this for Server Components, this will be less of an
issue because there are no updates in that environment. However, it's
still better for performance to cache data requests, so the same
principles largely apply.

The intention is that this will eventually be the only supported way to
suspend on arbitrary promises. Throwing a promise directly will
be deprecated.
2022-08-25 14:12:07 -04:00
Luna Ruan
11ed7010c6 [Transition Tracing] onMarkerIncomplete - Tracing Marker/Suspense Boundary Deletions (#24885)
This PR adds the `onMarkerIncomplete` callback for tracing marker name changes. Specifically, this PR:
* Adds the `onMarkerIncomplete` callback
* When a tracing marker is deleted, call `onMarkerIncomplete` with the `name` of the tracing marker for the tracing marker. 
* When a tracing marker/suspense boundary is deleted, call `onMarkerIncomplete` for every parent tracing marker with the `name` of the tracing marker that caused the transition to be incomplete. 
* Don't call `onTransitionComplete` or `onMarkerComplete` when `onMarkerIncomplete` is called for all tracing markers with the same transitions, but continue to call `onTransitionProgress`
2022-08-25 11:03:03 -07:00
Sebastian Markbåge
b79894259a [Flight] Add support for Webpack Async Modules (#25138)
This lets you await the result of require(...) which will then
mark the result as async which will then let the client unwrap the Promise
before handing it over in the same way.
2022-08-25 12:27:30 -04:00
kwzr
c8b778b7f4 Fix typo: supportsMicrotask -> supportsMicrotasks (#25142) 2022-08-25 16:56:24 +01:00
Sebastian Markbåge
d0f396651b Allow functions to be used as module references (#25137) 2022-08-25 07:47:38 -04:00
Sebastian Markbåge
38c5d8a035 Test the node-register hooks in unit tests (#25132) 2022-08-24 19:05:39 -04:00
Tianyu Yao
3f70e68cea Return closestInstance in getInspectorDataForViewAtPoint (#25118) 2022-08-24 11:26:08 -07:00
Tianyu Yao
181525338e [DevTools] Highlight RN elements on hover (#25106)
* [DevTools] Highlight RN elements on hover

* Remove unused TODO
2022-08-24 11:25:22 -07:00
Tim Neutkens
3d443cad74 Update fixtures/flight to webpack 5 (#25115)
* Add new flight fixture

* Move flight dir files

* Enable writeToDisk and distDir

* Move flight2 -> flight

* flight2 -> flight

* Remove unused files

* Remove unused files

* Run prettier

* Ignore eslint cache

Co-authored-by: Sebastian Markbage <sebastian@calyptus.eu>
2022-08-23 21:18:05 -04:00
Samuel Susla
5d1ce65139 Align StrictMode behaviour with production (#25049)
* Skip double invoking effects in Offscreen

* Run yarn replace-fork

* Use executionContext to disable profiler timer

* Restructure recursion into two functions

* Fix ReactStrictMode test

* Use gate pragma in ReacetOffscreenStrictMode test

* Set and reset current debug fiber in dev

* Skip over paths that don't include any insertions

* Extract common logic to check for profiling to a helper function

* Remove hasPassiveEffects flag from StrictMode

* Fix flow issues

* Revert "Skip over paths that don't include any insertions"
2022-08-23 18:19:07 +01:00
Joseph Savona
9e67e7a315 Scaffolding for useMemoCache hook (#25123)
* Scaffolding for useMemoCache hook
* cleanup leftovers from copy/paste of use() diff

Co-authored-by: Andrew Clark <git@andrewclark.io>
2022-08-23 09:36:02 +01:00
taiga
e25648b0a8 devtools: Fix typo from directores to directories (#25124) 2022-08-22 18:40:26 +02:00
Evren
1b69a8bb73 fixture: Fix typo from perfomrance to performance (#25100) 2022-08-21 21:16:01 +02:00
Tianyu Yao
26ba5fb2e0 [DevTools] Add events necessary for click to inspect on RN (#25111)
* Add inspectingNative events for RN

* Enable inspection toggle UI for RN

* Add a stopInspectingNative method for agent
2022-08-19 16:18:14 -07:00
Jiachi Liu
19e9a4c68e Add missing createServerContext for experimental shared subset (#25114) 2022-08-18 09:33:36 -04:00
Josh Story
1e5245df89 support subresource integrity for bootstrapScripts and bootstrapModules (#25104) 2022-08-17 08:31:05 +01:00
Josh Story
6ef466c681 make preamble and postamble types explicit and fix typo (#25102) 2022-08-16 12:17:49 +01:00
Josh Story
796d31809b Implement basic stylesheet Resources for react-dom (#25060)
Implement basic support for "Resources". In the context of this commit, the only thing that is currently a Resource are

<link rel="stylesheet" precedence="some-value" ...>

Resources can be rendered anywhere in the react tree, even outside of normal parenting rules, for instance you can render a resource before you have rendered the <html><head> tags for your application. In the stream we reorder this so the browser always receives valid HTML and resources are emitted either in place (normal circumstances) or at the top of the <head> (when you render them above or before the <head> in your react tree)

On the client, resources opt into an entirely different hydration path. Instead of matching the location within the Document these resources are queried for in the entire document. It is an error to have more than one resource with the same href attribute.

The use of precedence here as an opt-in signal for resourcifying the link is in preparation for a more complete Resource implementation which will dedupe resource references (multiple will be valid), hoist to the appropriate container (body, head, or elsewhere), order (according to precedence) and Suspend boundaries that depend on them. More details will come in the coming weeks on this plan.

This feature is gated by an experimental flag and will only be made available in experimental builds until some future time.
2022-08-12 13:27:53 -07:00
Luna Ruan
32baab38f8 [Transition Tracing] Add Tag Field to Marker Instance (#25085)
We were previously using `markerInstance.name` to figure out whether the marker instance was on the tracing marker or the root, but this is unsustainable. This adds a tag field so we can explicitly check this.
2022-08-11 23:04:45 -04:00
Andrew Clark
8ef3a7c08c Resume immediately pinged fiber without unwinding (#25074)
* Yield to main thread if continuation is returned

Instead of using an imperative method `requestYield` to ask Scheduler to
yield to the main thread, we can assume that any time a Scheduler task
returns a continuation callback, it's because it wants to yield to the
main thread. We can assume the task already checked some condition that
caused it to return a continuation, so we don't need to do any
additional checks — we can immediately yield and schedule a new task
for the continuation.

The replaces the `requestYield` API that I added in ca990e9.

* Move unwind after error into main work loop

I need to be able to yield to the main thread in between when an error
is thrown and when the stack is unwound. (This is the motivation behind
the refactor, but it isn't implemented in this commit.) Currently the
unwind is inlined directly into `handleError`.

Instead, I've moved the unwind logic into the main work loop. At the
very beginning of the function, we check to see if the work-in-progress
is in a "suspended" state — that is, whether it needs to be unwound. If
it is, we will enter the unwind phase instead of the begin phase.

We only need to perform this check when we first enter the work loop:
at the beginning of a Scheduler chunk, or after something throws. We
don't need to perform it after every unit of work.

* Yield to main thread whenever a fiber suspends

When a fiber suspends, we should yield to the main thread in case the
data is already cached, to unblock a potential ping event.

By itself, this commit isn't useful because we don't do anything special
in the case where to do receive an immediate ping event. I've split this
out only to demonstrate that it doesn't break any existing behavior.

See the next commit for full context and motivation.

* Resume immediately pinged fiber without unwinding

If a fiber suspends, and is pinged immediately in a microtask (or a
regular task that fires before React resumes rendering), try rendering
the same fiber again without unwinding the stack. This can be super
helpful when working with promises and async-await, because even if the
outermost promise hasn't been cached before, the underlying data may
have been preloaded. In many cases, we can continue rendering
immediately without having to show a fallback.

This optimization should work during any concurrent (time-sliced)
render. It doesn't work during discrete updates because those are
semantically required to finish synchronously — those get the current
behavior.
2022-08-11 22:01:56 -04:00
Robert Balicki
4e60dbd905 [easy] Clarify folders in react devtools readme #25077
Clarify the folder from which we run various commands in the react-devtools readme
2022-08-11 19:47:02 -04:00
Samuel Susla
7bcc687720 Remove argument committedLanes from reappearLayoutEffects and recursivelyTraverseReappearLayoutEffects (#25080) 2022-08-11 14:24:56 +01:00
ZA Syed
7a227276e6 revert last grammatical edit (#25067)
on line 29, #24798 edited (others') to (other's); however, the subject here is plural (e.g. "others in the community"), thus (others') is grammatically correct
2022-08-10 20:14:31 +01:00
Krishnamohan Yerrabilli
17e2a15bea Added a comma to understand better the Readme file for the contributor and the viewer. (#24798)
* Small change for Readme file

Added a comma, for better understanding for the contributor and the viewer.

* Update CODE_OF_CONDUCT.md

* Updated, requested changes are done!
2022-08-08 07:31:34 -04:00
Andrew Clark
ca990e9a75 Add API to force Scheduler to yield for macrotask (#25044)
We need a way to yield control of the main thread and schedule a
continuation in a separate macrotask. (This is related to some Suspense
optimizations we have planned.)

Our solution needs account for how Scheduler is implemented. Scheduler
tasks are not 1:1 with real browser macrotasks — many Scheduler "tasks"
can be executed within a single browser task. If a Scheduler task yields
control and posts a continuation, but there's still time left in the
frame, Scheduler will execute the continuation immediately
(synchronously) without yielding control back to the main thread. That's
not what we want — we want to schedule a new macrotask regardless of
where we are in the browser's render cycle.

There are several ways we could approach this. What I ended up doing was
adding a new Scheduler method `unstable_requestYield`. (It's similar to
the existing `unstable_requestPaint` that we use to yield at the end of
the frame.)

It works by setting the internal start time of the current work loop to
a large negative number, so that when the `shouldYield` call computes
how much time has elapsed, it's guaranteed to exceed the deadline. The
advantage of doing it this way is that there are no additional checks in
the normal hot path of the work loop.

The existing layering between Scheduler and React DOM is not ideal. None
of the APIs are public, so despite the fact that Scheduler is a separate
package, I consider that a private implementation detail, and think of
them as part of the same unit.

So for now, though, I think it makes sense to implement this macrotask
logic directly inside of Scheduler instead of layering it on top.

The rough eventual plan for Scheduler is turn it into a `postTask`
prollyfill. Because `postTask` does not yet have an equivalent for
`shouldYield`, we would split that out into its own layer, perhaps
directly inside the reconciler. In that world, the macrotask logic I've
added in this commit would likely live in that same layer. When the
native `postTask` is available, we may not even need any additional
logic because it uses actual browser tasks.
2022-08-04 21:20:15 -04:00
Andrew Clark
b4204ede66 Clean up unused Deletion flag (#24992)
This was replaced by the ChildDeletion flag when we refactored the 
commit phase.
2022-08-03 17:03:53 -04:00
Luna Ruan
e193be87e6 [Transition Tracing] Add Offscreen Test (#25035)
Add a test to make sure offscreen trees don't stop transitions from completing.
2022-08-03 13:24:41 -04:00
Sebastian Markbåge
9fcaf88d58 Remove rootContainerInstance from unnecessary places (#25024)
We only really use this for the create APIs since the DOM requires it.

We could probably use the Host Context for this instead since they're
updated at the same time and the namespace is related to this concept.
2022-08-01 23:30:04 -04:00
Konpaku Youmu
3f3b46c845 docs(react-devtools-inline): react-dom@experimental instead of react-dom@experimenal (#25001) 2022-07-30 10:57:13 +02:00
Andrew Clark
80f3d88190 Mount/unmount passive effects when Offscreen visibility changes (#24977)
* Remove unnecessary try-catch from passive deletion

The individual unmount calls are already wrapped in a catch block, so
this outer one serves no purpose.

* Extract passive unmount effects to separate functions
    
I'm about to add a "disconnect passive effects" function that will share
much of the same code as commitPassiveUnmountOnFiber. To minimize the
duplicated code, I've extracted the shared parts into separate
functions, similar to what I did for commitLayoutEffectOnFiber and
reappearLayoutEffects.

This may not save much on code size because Closure will likely inline
some of it, anyway, but it makes it harder for the two paths to
accidentally diverge.

* Mount/unmount passive effects on hide/show

This changes the behavior of Offscreen so that passive effects are
unmounted when the tree is hidden, and re-mounted when the tree is
revealed again. This is already how layout effects worked.

In the future we will likely add an option or heuristic to only unmount
the effects of a hidden tree after a delay. That way if the tree quickly
switches back to visible, we can skip toggling the effects entirely.

This change does not apply to suspended trees, which happen to use
the Offscreen fiber type as an implementation detail. Passive effects
remain mounted while the tree is suspended, for the reason described
above — it's likely that the suspended tree will resolve and switch
back to visible within a short time span.

At a high level, what this capability enables is a feature we refer to
as "resuable state". The real value proposition here isn't so much the
behavior of effects — it's that you can switch back to a previously
rendered tree without losing the state of the UI.

* Add more coverage for nested Offscreen cases
2022-07-29 19:34:28 -04:00
Andrew Clark
4ea064eb09 Don't fire passive effects during initial mount of a hidden Offscreen tree (#24967)
* Change OffscreenInstance isHidden to bitmask

The isHidden field of OffscreenInstance is a boolean that represents
whether the tree is currently hidden. To implement resuable effects, we
need to also track whether the passive effects are currently connected.
So I've changed this field to a bitmask.

No other behavior has changed in this commit. I'll update the effects
behavior in the following steps.

* Extract passive mount effects to separate functions

I'm about to add a "reappear passive effects" function that will share
much of the same code as commitPassiveMountEffectOnFiber. To minimize
the duplicated code, I've extracted the shared parts into separate
functions, similar to what I did for commitLayoutEffectOnFiber and
reappearLayoutEffects.

This may not save much on code size because Closure will likely inline
some of it, anyway, but it makes it harder for the two paths to
accidentally diverge.

* Don't mount passive effects in a new hidden tree

This changes the behavior of Offscreen so that passive effects do not
fire when prerendering a brand new tree. Previously, Offscreen did not
affect passive effects at all — only layout effects, which mount or
unmount whenever the visibility of the tree changes.

When hiding an already visible tree, the behavior of passive effects is
unchanged, for now; unlike layout effects, the passive effects will not
get unmounted. Pre-rendered updates to a hidden tree in this state will
also fire normally. This is only temporary, though — the plan is for
passive effects to act more like layout effects, and unmount them when
the tree is hidden. Perhaps after a delay so that if the visibility
toggles quickly back and forth, the effects don't need to remount. I'll
implement this separately.

* "Atomic" passive commit effects must always fire

There are a few cases where commit phase logic always needs to fire even
inside a hidden tree. In general, we should try to design algorithms
that don't depend on a commit effect running during prerendering, but
there's at least one case where I think it makes sense.

The experimental Cache component uses reference counting to keep track
of the lifetime of a cache instance. This allows us to expose an
AbortSignal object that data frameworks can use to cancel aborted
requests. These cache objects are considered alive even inside a
prerendered tree.

To implement this I added an "atomic" passive effect traversal that runs
even when a tree is hidden. (As a follow up, we should add a special
subtree flag so that we can skip over nodes that don't have them. There
are a number of similar subtree flag optimizations that we have planned,
so I'll leave them for a later refactor.)

The only other feature that currently depends on this behavior is
Transition Tracing. I did not add a test for this because Transition
Tracing is still in development and doesn't yet work with Offscreen.
2022-07-29 19:22:57 -04:00
Andrew Clark
2c7dea7365 Implement Offscreen in Fizz (#24988)
During server rendering, a visible Offscreen subtree acts exactly like a
fragment: a pure indirection.

A hidden Offscreen subtree is not server rendered at all. It's ignored
during hydration, too. Prerendering happens only on the client. We
considered prerendering hidden trees on the server, too, but our
conclusion is that it's a waste of bytes and server computation. We
can't think of any compelling cases where it's the right trade off. (If
we ever change our mind, though, the way we'll likely model it is to
treat it as if it's a Suspense boundary with an empty fallback.)
2022-07-26 00:35:51 -04:00
Mengdi Chen
5f34b051df [Devtools] add logs for profiler tab switch & settings change (#24966)
* [devtools] add logs for profiler tab switch & settings change

* prettier

* remove unnecessary console.log

* better naming: logEvent -> loggerEvent

* use same object for event and metadata
2022-07-25 11:53:38 -04:00
Sebastian Silbermann
b66936ece7 devtools: Remove ForwardRef/Memo from display name if displayName is set (#21952)
* feat(devtools): Remove ForwardRef/Memo from display name if `displayName` is set

* Avoid potentially wasting work by inlining `functionName`
2022-07-25 09:02:12 +02:00
davidrenne
49f8254d6d Bug fix for <App /> vs. <Counter /> (#24972) 2022-07-22 11:24:49 -04:00
Sebastian Silbermann
6b28bc9c5a test: Throw custom error instead of relying on runtime error (#24946) 2022-07-21 15:46:57 -04:00
Sebastian Silbermann
9bd0dd4c18 test(react-debug-tools): Improve coverage of currentDispatcher.current setter (#24945) 2022-07-21 15:46:43 -04:00
Sebastian Silbermann
59bc52a16c Add 4.5.0 release to eslint rules CHANGELOG (#24853)
Eye-balled from https://app.renovatebot.com/package-diff?name=eslint-plugin-react-hooks&from=4.4.0&to=4.5.0#d2h-042857 which changes were included.
2022-07-21 15:46:10 -04:00
Mengdi Chen
3ddbedd052 [devtools] log more events + metadata (#24951)
* [devtools] log more events + metadata

* better typing

* consistent string type
2022-07-19 15:22:09 -04:00
Andrew Clark
cfb6cfa250 Reused components commit with timing as new ones
When an Offscreen tree goes from hidden -> visible, the tree may include
both reused components that were unmounted when the tree was hidden, and
also brand new components that didn't exist in the hidden tree.

Currently when this happens, we commit all the reused components'
effects first, before committing the new ones, using two separate
traversals of the tree.

Instead, we should fire all the effects with the same timing as if it
were a completely new tree. See the test I wrote for an example.

This is also more efficient because we only need to traverse the
tree once.
2022-07-19 14:11:33 -04:00
Andrew Clark
679eea3282 Extract layout effects to separate functions
There's a lot of duplicated code between commitLayoutEffectOnFiber and the
"reappear layout effects" path that happens when an Offscreen tree goes from
hidden back to visible. I'm going to refactor these to share more of the same
code. As a first step, this extracts the shared parts into separate functions.

This may not save much on code size because Closure will likely inline some of
it, anyway, but it makes it harder for the two paths to accidentally diverge.
2022-07-19 14:11:32 -04:00
Andrew Clark
41287d4475 Use recursion to traverse during "reappear layout" phase
This converts the "reappear layout" phase to iterate over its effects
recursively instead of iteratively. This makes it easier to track
contextual information, like whether a fiber is inside a hidden tree.

We already made this change for several other phases, like mutation and
layout mount. See 481dece for more context.
2022-07-19 14:11:32 -04:00
Andrew Clark
697702bf34 Use recursion to traverse during "disappear layout" phase
This converts the "disappear layout" phase to iterate over its effects
recursively instead of iteratively. This makes it easier to track
contextual information, like whether a fiber is inside a hidden tree.

We already made this change for several other phases, like mutation and
layout mount. See 481dece for more context.
2022-07-19 14:11:32 -04:00
Mengdi Chen
992911981b [DevTools] add simple usage events for internal logging (#24888)
* [DevTools] add simple events for internal logging

* fix lint

* fix lint

* better event name

* fix flow

* better way to fix flow

* combine 'select-element'

* use same event name for selecting element by inspecting
2022-07-18 15:52:53 -04:00
Luna Ruan
6daf600609 add transistion callbacks to hydrateRoot (#24937)
This PR adds transition callbacks to hydrateRoot.
2022-07-18 10:22:47 -07:00
Andrew Clark
02206099af Use recursion to traverse during passive unmount phase (#24918)
This converts the layout phase to iterate over its effects recursively
instead of iteratively. This makes it easier to track contextual
information, like whether a fiber is inside a hidden tree.

We already made this change for several other phases, like mutation and
layout mount. See 481dece for more context.
2022-07-14 11:08:08 -04:00
Mengdi Chen
d54880d424 React DevTools 4.24.7 -> 4.25.0 (#24919) 2022-07-13 15:57:50 -04:00
Luna Ruan
f629495199 [Transition Tracing] Rename transitionCallbacks to unstable_transitionCallbacks (#24920)
Renaming transitionCallbacks to unstable_transitionCallbacks as per convention
2022-07-13 15:27:12 -04:00
Mengdi Chen
4bc83e6821 [DevTools] enable enableProfilerComponentTree flag for all builds (#24921) 2022-07-13 15:21:32 -04:00
Andrew Clark
7a4336c404 Use recursion to traverse during passive mount phase
This converts the layout phase to iterate over its effects
recursively instead of iteratively. This makes it easier to track 
contextual information, like whether a fiber is inside a hidden tree.

We already made this change for the mutation phase. See 481dece for
more context.
2022-07-12 16:06:53 -04:00
Andrew Clark
bb1357b381 Wrap try-catch directly around each user function
(This is the same as f9e6aef, but for the passive mount phase rather than the
mutation phase.)

This moves the try-catch from around each fiber's passive mount phase to
direclty around each user function (effect function, callback, etc).

We already do this when unmounting because if one unmount function
errors, we still need to call all the others so they can clean up
their resources.

Previously we didn't bother to do this for anything but unmount,
because if a mount effect throws, we're going to delete that whole
tree anyway.

But now that we're switching from an iterative loop to a recursive one,
we don't want every call frame on the stack to have a try-catch, since
the error handling requires additional memory.

Wrapping every user function is a bit tedious, but it's better
for performance. Many of them already had try blocks around
them already.
2022-07-12 16:06:53 -04:00
Andrew Clark
de3c069843 Move flag check into each switch case
The fiber tag is more specific than the effect flag, so we should always
refine the type of work first, to minimize redundant checks.
2022-07-12 16:06:53 -04:00
Luna Ruan
f5916d15b6 [Transition Tracing][Code Cleanup] Delete Marker Name Change Tests (#24908)
We decided that changing the Tracing Marker name wasn't allowed and we would error, so this PR deletes all the tests that tested name change behavior
2022-07-12 12:59:58 -07:00
Luna Ruan
fa20b319fc [Transition Tracing] Code Cleanup (#24880)
This PR cleans up some of the transition tracing code by:
* Looping through marker transitions only when we process the markerComplete callback (rather than in the commit phase) so we block for less time during commit.
* Renaming `PendingSuspenseBoundaries` to `pendingBoundaries`
* Cleaning up the callback functions
2022-07-12 12:48:04 -07:00
Luna Ruan
5e8c1961c0 [Transition Tracing] onMarkerProgress (#24861)
This PR adds support for `onMarkerProgress` (`onTransitionProgress(transitionName: string, markerName: string, startTime: number, currentTime: number, pending: Array<{name: null | string}>)`)

We call this callback when:
    * When **a child suspense boundary of the marker commits in a fallback state**. Only the suspense boundaries that are triggered and commit in a fallback state when the transition first occurs (and all subsequent suspense boundaries in the initial suspense boundary's subtree) are considered a part of the transition
    * **A child suspense boundary of the marker resolves**
   
When we call `onMarkerProgress`, we call the function with a `pending` array. This array contains the names of the transition's suspense boundaries that are still in a fallback state
2022-07-12 11:59:54 -07:00
Andrew Clark
b641d02097 Use recursion to traverse during layout phase
This converts the layout phase to iterate over its effects
recursively instead of iteratively. This makes it easier to track 
contextual information, like whether a fiber is inside a hidden tree.

We already made this change for the mutation phase. See 481dece for
more context.
2022-07-12 13:27:22 -04:00
Andrew Clark
a1b1e391e1 Wrap try-catch directly around each user function
(This is the same as f9e6aef, but for the layout phase rather than the
mutation phase.)

This moves the try-catch from around each fiber's layout phase to
direclty around each user function (effect function, callback, etc).

We already do this when unmounting because if one unmount function
errors, we still need to call all the others so they can clean up
their resources.

Previously we didn't bother to do this for anything but unmount,
because if a mount effect throws, we're going to delete that whole
tree anyway.

But now that we're switching from an iterative loop to a recursive one,
we don't want every call frame on the stack to have a try-catch, since
the error handling requires additional memory.

Wrapping every user function is a bit tedious, but it's better
for performance. Many of them already had try blocks around
them already.
2022-07-12 13:27:22 -04:00
Andrew Clark
3df7e8f5dc Move flag check into each switch case
The fiber tag is more specific than the effect flag, so we should always
refine the type of work first, to minimize redundant checks.
2022-07-12 13:27:22 -04:00
Andrew Clark
b8c96b136d Move ref commit effects inside switch statement
Only certain fiber types can have refs attached to them, so this moves the
Ref effect logic out of the common path and into the corresponding branch
of the layout phase's switch statement.

The types of fibers this affects are host components and class components.
Function components are not affected because they can only have a ref via
useImperativeHandle, which has a different implementation. The experimental
Scope type attaches its refs in the mutation phase, not the layout phase.
2022-07-12 13:27:22 -04:00
Luna Ruan
e225fa43ad [Transition Tracing] Don't call transition callbacks if no transition name specified (#24887)
This PR checks to see if `transition.name` is defined before adding the transition so we avoid doing unnecessary work for transitions without a transition name
2022-07-11 18:00:49 -04:00
Luna Ruan
dd2d652275 [Transition Tracing] Tracing Marker Name Change in Update Warning (#24873)
We should only support Tracing Marker's name field during component mount. This PR adds a warning if the Tracing Marker's name changes during an update.
2022-07-08 12:31:44 -04:00
Luna Ruan
80208e7696 [Transition Tracing] Add onTransitionProgress Callback (#24833)
This PR adds support for `onTransitionProgress` (`onTransitionProgress(transitionName: string, startTime: number, currentTime: number, pending: Array<{name: null | string}>)`)

We call this callback when:
    * When **a child suspense boundary of the transition commits in a fallback state**. Only the suspense boundaries that are triggered and commit in a fallback state when the transition first occurs (and all subsequent suspense boundaries in the initial suspense boundary's subtree) are considered a part of the transition
    * **A child suspense boundary of the transition resolves**
   
When we call `onTransitionProgress`, we call the function with a `pending` array. This array contains the names of the transition's suspense boundaries that are still in a fallback state
2022-07-08 12:13:29 -04:00
Andrew Clark
30eb267abd Land forked reconciler changes (#24878)
This applies forked changes from the "new" reconciler to the "old" one.

Includes:

- 67de5e3 [FORKED] Hidden trees should capture Suspense
- 6ab05ee [FORKED] Track nearest Suspense handler on stack
- 051ac55 [FORKED] Add HiddenContext to track if subtree is hidden
2022-07-08 11:55:53 -04:00
Andrew Clark
5e4e2dae0b Defer setState callbacks until component is visible (#24872)
A class component `setState` callback should not fire if a component is inside a
hidden Offscreen tree. Instead, it should wait until the next time the component
is made visible.
2022-07-08 11:51:40 -04:00
Andrew Clark
95e22ff528 Delete Partial Renderer SSR implementation (#24868)
This removes the old server rendering implementation (the "Partial Renderer").
It was replaced in React 18 with a new streaming implementation (Fizz).

We hadn't removed it from the codebase yet because Facebook hadn't finished
rolling out Fizz in production; it's been behind a feature flag while we run
performance tests and migrate our internal infrastructure.

The diff to land Fizz will land imminently, and once it does, we can merge
this commit.
2022-07-07 16:57:42 -04:00
Luna Ruan
c3b18571db [DevTools][Bugfix] Fix DevTools Perf Issue When Unmounting Large React Subtrees (#24863)
We've recently had multiple reports where, if React DevTools was installed, unmounting large React subtrees would take a huge performance hit (ex. from 50ms to 7 seconds). 

Digging in more, we realized for every fiber that unmounts, we called `untrackFibers`, which calls `clearTimeout` (and does some work manipulating a set, but this wasn't the bulk of the time). We ten call `recordUnmount`, which adds the timer back. Adding and removing the timer so many times was taking upwards of 50ms per timer add/remove call, which was resulting in exorbitant amounts of time spent in DevTools deleting subtrees.

It looks like we are calling `untrackFibers` so many times to avoid a race condition with Suspense children where we unmount them twice (first a "virtual" unmount when the suspense boundary is toggled from visible to invisible, and then an actual unmount when the new children are rendered) without modifying `fiberIDMap`. We can fix this race condition by using the `untrackFibersSet` as a lock and not calling `recordUnmount` if the fiber is in the set and hasn't been processed yet. This works because the only way fibers are added in the set is via `recordUnmount` anyway.

This PR also adds a test to make sure this change doesn't regress the previous behavior.

**Before**
![image](https://user-images.githubusercontent.com/2735514/177655428-774ee306-0568-49ce-987e-b5213b613265.png)

**After**
![image](https://user-images.githubusercontent.com/2735514/177655604-a217583f-787e-438e-b6f9-18953fe32444.png)
2022-07-07 10:43:25 -04:00
Luna Ruan
8e35b50608 [Transition Tracing] Refactor Code to Remove OffscreeInstance TODOs (#24855)
Refactored code to pass flow and remove TODOs introduced in #24846
2022-07-06 09:38:28 -04:00
Luna Ruan
deab1263a8 [Transition Tracing] Change Transition Type Passed Pending Transitions (#24856)
This PR changes the type of the object we store in the pending transitions callbacks map. Previously, we were recreating the transition object that we initially created during `startTransition`. However, we can actually reuse the object instead (and it also gives us a stable way to identify a transition). This PR changes the implementation to reuse the transition object instead of creating a new one
2022-07-06 09:37:46 -04:00
Andrew Clark
82e9e99098 Suspending inside a hidden tree should not cause fallbacks to appear (#24699)
* [FORKED] Hidden trees should capture Suspense

If something suspends inside a hidden tree, it should not affect
anything in the visible part of the UI. This means that Offscreen acts
like a Suspense boundary whenever it's in its hidden state.

* Add previous commit to forked revisions
2022-07-05 17:51:27 -04:00
Andrew Clark
c1f5884ffe Add missing null checks to OffscreenInstance code (#24846)
`stateNode` is any-typed, so when reading from `stateNode` we should always cast
it to the specific type for that type of work. I noticed a place in the commit
phase where OffscreenInstance wasn't being cast. When I added the type
assertion, it exposed some type errors where nullable values were being accessed
without first being refined.

I added the required null checks without verifying the logic of the existing
code. If the existing logic was correct, then the extra null checks won't have
any affect on the behavior, because all they do is refine from a nullable type
to a non-nullable type in places where the type was assumed to already be
non-nullable. But the result looks a bit fishy to me, so I also left behind some
TODOs to follow up and verify it's correct.
2022-07-05 11:40:44 -04:00
Luna Ruan
4cd788aef0 Revert "Revert [Transition Tracing] Refactor Transition Tracing Root Code" (#24830)
* refactor root

* old

* Add comments and push actual marker instance in pushMarkerInstance

* old

* refactor pushRootMarkerInstance

* old

* fix test
2022-06-30 13:16:08 -04:00
Andrew Clark
e61fd91f5c Revert "[Transition Tracing] Refactor Transition Tracing Root Code (#24766)" (#24829)
This reverts commit 401296310f because it's
failing on main, likely due to conflict with something that landed before the
PR was merged. Need to rebase and fix.
2022-06-30 11:48:25 -04:00
Luna Ruan
401296310f [Transition Tracing] Refactor Transition Tracing Root Code (#24766)
This PR refactors the transition tracing root code by reusing the tracing marker code. Namely it:
* Refactors the tracing marker code so that it takes a tracing marker instance instead of a tracing marker fiber and rename the stack to `markerInstance` instead of `tracingMarker`
* Pushes the root code onto the stack
* Moves the instantiation of `root.incompleteTransitions` to the begin phase when we are pushing the root to the stack rather than in the commit phase
2022-06-30 08:16:32 -07:00
Andrew Clark
1859329021 Track nearest Suspense handler on stack (#24585)
* [FORKED] Add HiddenContext to track if subtree is hidden

This adds a new stack cursor for tracking whether we're rendering inside
a subtree that's currently hidden.

This corresponds to the same place where we're already tracking the
"base lanes" needed to reveal a hidden subtree — that is, when going
from hidden -> visible, the base lanes are the ones that we skipped
over when we deferred the subtree. We must includes all the base lanes
and their updates in order to avoid an inconsistency with the
surrounding content that already committed.

I consolidated the base lanes logic and the hidden logic into the same
set of push/pop calls.

This is intended to replace the InvisibleParentContext that is currently
part of SuspenseContext, but I haven't done that part yet.

* Add previous commit to forked revisions

* [FORKED] Track nearest Suspense handler on stack

Instead of traversing the return path whenever something suspends to
find the nearest Suspense boundary, we can push the Suspense boundary
onto the stack before entering its subtree. This doesn't affect the
overall algorithm that much, but because we already do all the same
logic in the begin phase, we can save some redundant work by tracking
that information on the stack instead of recomputing it every time.

* Add previous commit to forked revisions
2022-06-30 10:03:29 -04:00
Andrew Clark
a7b192e0f1 Add test gate alias for Offscreen (#24749)
Offscreen is only enabled in the www and experimental channels. Instead
of listing these on every Offscreen test, I added a test gate alias
called `enableOffscreen`. Makes it easier to grep for these, and edit or
remove the channels later.
2022-06-30 09:44:54 -04:00
Andrew Clark
6b6cf8311c Land forked reconciler changes (#24817)
This applies forked changes from the "new" reconciler to the "old" one.

Includes:

- d410f0a [FORKED] Bugfix: Offscreen instance is null during setState
- 58bb117 [FORKED] Check for infinite update loops even if unmounted
- 31882b5 [FORKED] Bugfix: Revealing a hidden update
- 17691ac [FORKED] Don't update childLanes until after current render
2022-06-29 23:31:42 -04:00
Luna Ruan
4e1fcfa771 [DevTools] Resign Timeline Profiler Sidebar (#24816)
This PR:
* Redesigned the sidebar to resemble the flamegraph profiler sidebar and added title and timestamp to the sidebar
* Added ability to copy the component stack (for places where you're unable to link to source)

https://user-images.githubusercontent.com/2735514/176564897-5301d6d4-429a-4ea3-86cd-74427cff4ce6.mov
2022-06-29 17:54:06 -07:00
Luna Ruan
1974d08c93 [DevTools] Fix Bugs With Component Stacks (#24815)
This PR:
* Simplifies the code in `SidebarEventInfo` by passing it the actual clicked event rather than an index.
* Lightly refactored the `SidebarEventInfo` code so that it can be used for more than just `schedulingEvents`
* Fixes bug. Previously, whenever a state update event was clicked, we updated the `selectedCommitIndex` in the `ProfilerContext`. However, this index is used for the selected commit in the Flamegraph profiler, which caused a bug where if you would change the contents of the event sidebar, the commit sidebar in the Flamegraph profiler would change too. This PR replaces this with the actual event info instead
2022-06-29 16:00:48 -07:00
Luna Ruan
cd80d3274d [DevTools] Add column number to viewSourceLineFunction (#24814)
Add column number for `viewSourceLineFunction` and renamed the function to `viewUrlSourceFunction` to match the other source function naming conventions
2022-06-29 10:38:27 -07:00
Mengdi Chen
f01e119b7d [DevTools] Log page URL in internal build (#24799)
* test log

* fix attribute name

* fix lint

* tabs can be empty

* improve coding style per comments
2022-06-29 13:02:53 -04:00
Luna Ruan
d1432ba93e [Transition Tracing] Fix excess calls to the transition start callback (#24806)
This PR fixes a bug where we would add a transition to the lanes map every time an update occurs. However, we didn't factor in that there might be multiple updates in a transition, which would cause the transition to be added multiple times to the transitionLanes map.

This changes the transitionLanes object from an Array of Arrays to an Array of Sets so that we only add a transition if it hasn't been added before, avoiding duplicates
2022-06-28 21:17:14 -04:00
Blake Friedman
2e1c8841e9 [DevTools] front-end for profiling event stack (#24805)
* [DevTools] front-end for profiling event stack

Adds a side-bar to the profiling tab. Users can now select an update event, and are
shown the callstack from the originating component. When a source path is available
there is now UI to jump to source.

Add FB enabled feature flag: enableProfilerComponentTree for the side-bar.

resolves #24170
2022-06-28 22:15:24 +01:00
Luna Ruan
88574c1b8b Fix enableTransitionTracing flag (#24801)
Move `enableTransitionTracing` to `dynamicFeatureFlags` so it runs when you run `yarn test`
2022-06-28 13:09:59 -04:00
Luna Ruan
a4bed46969 [Transition Tracing] Add Tracing Markers (#24686)
This PR adds support for Tracing Markers as well as onTracingMarkerComplete
2022-06-27 09:46:43 -07:00
Josh Story
167853026c fix hydration warning suppression in text comparisons (#24784)
* fix hydration warning suppression in text comparisons

* lint

* lowercase test
2022-06-26 12:22:10 -07:00
Andrew Clark
652e6c5a1b [sizebot] Add link to diff view (#24790)
Updates the sizebot output so that the file names link to a diff view of
the corresponding build artifact.

Example diff view: https://react-builds.vercel.app/commits/955cad9bcc6d755b2a672f8038fe9754e0fe5108/files/oss-stable-semver/react-dom/cjs/react-dom.production.min.js?compare=c3d7a7e3d72937443ef75b7e29335c98ad0f1424

The diff view itself is rendered by a Next.js app that I built as a side
project and is hosted at https://react-builds.vercel.app. If we find
this useful enough I could move the app to a React-owned repo but since
this isn't a critical feature it might be OK to leave it separate for
now, so we don't need to commit to supporting it indefinitely.
2022-06-25 19:13:41 -04:00
Luna Ruan
955cad9bcc [DevTools] Clean Up DevTools Code (#24782)
This PR cleans up the DevTools codebase by:
* Consolidating `normalizeCodeLocInfo` into one place
* Remove unused source argument in the DevTools component stacks code
2022-06-23 15:47:47 -07:00
Luna Ruan
9abe745aa7 [DevTools][Timeline Profiler] Component Stacks Backend (#24776)
This PR adds a component stack field to the `schedule-state-update` event. The algorithm is as follows:
* During profiling, whenever a state update happens collect the parents of the fiber that caused the state update and store it in a map
* After profiling finishes, post process the `schedule-state-update` event and using the parent fibers, generate the component stack by using`describeFiber`, a function that uses error throwing to get the location of the component by calling the component without props.

---

Co-authored-by: Blake Friedman <blake.friedman@gmail.com>
2022-06-23 11:19:23 -07:00
Luna Ruan
cf665c4b73 [DevTools] Refactor incompleteTransitions field from Root Fiber memoized state to FiberRoot (#24765)
`incompleteTransitions` persists across renders, so it should be part of the `fiber.stateNode` (ie FiberRoot) rather than `fiber.memoizedState`
2022-06-20 17:08:54 -07:00
Mengdi Chen
d6255f0ac4 [DevTool] fix build-for-devtools script (#24764) 2022-06-20 15:06:40 -04:00
Sebastian Markbåge
56389e81ff Abort Flight (#24754)
Add aborting to the Flight Server. This encodes the reason as an "error"
row that gets thrown client side. These are still exposed in prod which
is a follow up we'll still have to do to encode them as digests instead.

The error is encoded once and then referenced by each row that needs to
be updated.
2022-06-19 11:05:41 -04:00
Sebastian Markbåge
0f216ae31d Add entry points for "static" server rendering passes (#24752)
This will be used to add optimizations for static server rendering.
2022-06-18 22:34:31 -04:00
Sebastian Markbåge
f796fa13ad Rename Segment to Task in Flight (#24753)
In Fizz this got split into Task and Segment. We don't have a concept of
Segment in Flight yet because we don't inline multiple segments into one
"Row". We just emit one "Row" for each Segment if something suspends.

This makes Flight non-deterministic atm but that's something we'll want to
address.

Regardless, right now, this is more like a Task than a Segment.
2022-06-18 15:02:11 -04:00
Sebastian Markbåge
0f0aca3ab3 Aborting early should not infinitely suspend (#24751)
Before this change we weren't calling onError nor onFatalError if you abort
before completing the shell.

This means that the render never completes and hangs.

Aborting early can happen before even creating the stream for AbortSignal,
before rendering starts in Node since there's an setImmediate atm, or
during rendering.
2022-06-18 11:01:58 -04:00
Luna Ruan
12a738f1a8 [Transition Tracing] Add Support for Multiple Transitions on Root (#24732)
We can think of transitions on the root as a bunch of tracing markers. Therefore, we can map each transition to a map of pending suspense boundaries. When a transition's pending suspense boundary map is empty, we know that it's complete. This PR:
* Combines the `pendingSuspenseBoundaries` and `transitions` into one `incompleteTransitions` object. This object is a map from a `transition` to a map of `pendingSuspenseBoundaries`
* Refactored code to make it so that every transition has its own `pendingSuspenseBoundaries` map rather than sharing just one.
* Moves the transition complete callback to the root. Alternatively, we can also keep a map of pendingSuspenseBoundaries to transitions on the Offscreen marker, but it's simpler to just call the transition complete callback on the root instead. We also only do this if there are transitions pending, so it shouldn't make too big of a difference
2022-06-17 13:43:46 -07:00
Mengdi Chen
72ebc703ac [DevTools] fix useDeferredValue to match reconciler change (#24742)
* [DevTools] fix useDeferredValue to match reconciler change

* fixup

* update test to catch original issue

* fix lint

* add safer tests for other composite hooks
2022-06-17 14:43:10 -04:00
Siyabend Ürün
a7c322c6f5 Fix typo in dangerfile.js (insiginificant -> insignificant) (#24393) 2022-06-17 10:43:52 -07:00
Kerim Büyükakyüz
7cf9f5e03a Extra space (#24612) 2022-06-17 10:43:17 -07:00
Andrew Clark
229c86af07 Revert "Land enableClientRenderFallbackOnTextMismatch" (#24738)
This reverts commit 327e4a1f96.

Turns out we hadn't rolled this out internally yet — I mistook
enableClientRenderFallbackOnHydrationMismatch for
said enableClientRenderFallbackOnTextMismatch. Need to revert
until we finish rolling out the change.
2022-06-16 11:38:37 -04:00
Andrew Clark
c3d7a7e3d7 Bugfix: Offscreen instance is null during setState (#24734)
* [FORKED] Bugfix: Offscreen instance is null during setState

During a setState, we traverse up the return path and check if any
parent Offscreen components are currently hidden. To do that, we must
access the Offscreen fiber's `stateNode` field.

On a mounted Offscreen fiber, the `stateNode` is never null, so usually
we don't need to refine the type. When a fiber is unmounted, though,
we null out its `stateNode` field to prevent memory cycles. However,
we also null out its `return` field, so I had assumed that an unmounted
Offscreen fiber would never be reachable.

What I didn't consider is that it's possible to call `setState` on a
fiber that never finished mounting. Because it never mounted, it was
never deleted. Because it was never deleted, its `return` field was
never disconnected.

This pattern is always accompanied by a warning but we still need to
account for it. There may also be other patterns where an unmounted
Offscreen instance is reachable, too.

The discovery also suggests it may be better for memory
usage if we don't attach the `return` pointer until the commit phase,
though in order to do that we'd need some other way to track the return
pointer during initial render, like on the stack.

The fix is to add a null check before reading the instance
during setState.

* Add previous commit to list of forked revisions
2022-06-15 22:13:22 -04:00
Luna Ruan
fcd720d363 [Transition Tracing] Push Transition When Offscreen Becomes Visible (#24718)
This PR pushes all of a suspense boundary's transitions onto the transition stack when it goes from hidden to visible so we can pass it to any child suspense boundaries or tracing markers.
2022-06-15 11:51:51 -07:00
Sebastian Markbåge
522f47345f Move the Error creation to be lazy (#24728)
Creating an Error captures a stack trace which can be somewhat expensive.
We shouldn't do tthat always for every render.

This also ensures that the stack trace is more useful because you can
follow through the Node.js code to see the cause.
2022-06-14 20:16:42 -04:00
dan
256aefbea1 Typo 2022-06-14 22:34:30 +01:00
Sebastian Markbåge
6522179f43 Enable no-longer experimental (#24727) 2022-06-14 17:11:01 -04:00
Sebastian Markbåge
567500d710 Move renderToString tests out of the streamable API tests (#24724)
ReactDOMFizzServer(Browser/Node)-test file is really meant to just be a
very shallow tests of the Browser/Node specific streaming APIs.

Most of the general streaming tests are in ReactDOMFizzServer-test instead
of testing all streaming related things in each environment.

The legacy renderToString APIs are mostly covered by ReactServerRendering-test
et al for historical reasons.
2022-06-14 16:48:33 -04:00
Josh Story
5cc2487e08 bump versions for next release (#24725) 2022-06-14 13:24:00 -07:00
Josh Story
89bae8f371 Update Changelog release date for 18.2.0 2022-06-14 12:49:54 -07:00
Luna Ruan
54f17e490f [Transition Tracing] Fix Cache and Transitions Pop Order (#24719)
We push the Cache before the transition so we should pop the transition before the cache. This PR fixes this issue.
2022-06-14 11:48:01 -07:00
Josh Story
be229c5655 Changelog for 18.2 (#24717)
* 1820-changelog

* generalize date and fix version typo

* reword, edit, and condense

* punctuation

* Nits

Co-authored-by: dan <dan.abramov@gmail.com>
2022-06-13 12:36:49 -07:00
Luna Ruan
7cf8dfd94f [Transition Tracing] Create/Process Marker Complete Callback (#24700)
This PR adds code to add a marker complete callback to the queue. It also adds code to process marker complete callback.

Marker complete callbacks, in addition to the fields that transition complete callbacks need, also have a `markerName` field
2022-06-13 10:56:21 -07:00
Andrew Clark
327e4a1f96 [Follow-up] Land enableClientRenderFallbackOnTextMismatch
This was meant to land in the previous commit; forgot to stage the
changes when I was rebasing.
2022-06-13 12:01:44 -04:00
Andrew Clark
29c2c63315 Land enableClientRenderFallbackOnTextMismatch (#24714)
This was released to open source in 18.0 and is already hardcoded to
true in www.
2022-06-13 11:58:03 -04:00
Andrew Clark
a8c9cb18b7 Land enableSuspenseLayoutEffectSemantics flag (#24713)
This was released to open source in 18.0 and is already hardcoded to
true in www.
2022-06-13 11:27:40 -04:00
Mengdi Chen
f7b44539ca [DevTools] enable "reload & profile" button for timeline view (#24702) 2022-06-10 10:38:33 -04:00
Luna Ruan
a8555c308e [Transition Tracing] Add Tracing Marker Stack (#24661)
When a suspense boundary suspends or commits, we need to notify the corresponding tracing markers so that they know when to log that they've completed. To do this, we add a stack of tracing markers. In the begin phase, we will push the tracing markers onto the stack, and during the complete/unwind phase we will pop the tracing markers off the stack

In a later PR, we will store the active tracing markers on the suspense boundary, and during the commit phase we will process the active tracing markers by adding/removing the boundary as appropriate.
2022-06-09 17:10:42 -07:00
Andrew Clark
8186b19378 Check for infinite update loops even if unmounted (#24697)
* [FORKED] Check for infinite update loops even if unmounted

The infinite update loop check doesn't need to run if the component
already unmounted, because an update to an unmounted component can't
cause a re-render. But because we used to run the check in this case,
anyway, I found one test in www that happens to "rely on" this behavior
(accidentally). The test is a pretty messy snapshot thing that I have no
interest fixing so to unblock the sync I'm just going to switch this
back to how it was.

* Add previous commit to forked revisions
2022-06-08 22:29:10 -04:00
Josh Story
9e3b772b8c Update error transform to allow excluding errors inside subexpressions like ternaries (#24693)
* Update error transform to allow excluding errors inside subexpressions like ternaries

* make leadingcomments aggregation walk the expression stack
2022-06-08 16:59:49 -07:00
Mengdi Chen
3e92eb0fce [DevTools] find best renderer when inspecting (#24665)
* [DevTools] find best renderer when inspecting

* fix lint

* fix test

* fix lint

* move logic to agent

* fix lint

* style improvements per review comments

* fix lint & flow

* re-add try catch for safety
2022-06-08 16:01:06 -04:00
Andrew Clark
42b330c1c9 Fix check_error_codes CI job (#24692)
The diff command was missing a --quiet argument, causing the job not to
fail when unminified messages were found.
2022-06-08 13:07:05 -04:00
Josh Story
060505e9dc Fix misapplying prod error opt-out (#24688)
The eslint-disable-next-line opt out for prod error minification was not properly working. In the build a replacable error was output even though it was not failing the build. This change refactors the code to avoid the erroneous behavior but a fix for the lint may be better
2022-06-08 09:49:31 -07:00
Mathieu Dutour
47944142f5 now isn't part of the react-reconciler config anymore (#24689) 2022-06-08 17:00:10 +01:00
Josh Story
b345523528 [Fizz] Support abort reasons (#24680)
* [Fizz] Support abort reasons

Fizz supports aborting the render but does not currently accept a reason. The various render functions that use Fizz have some automatic and some user-controlled abort semantics that can be useful to communicate with the running program and users about why an Abort happened.

This change implements abort reasons for renderToReadableStream and renderToPipeable stream as well as legacy renderers such as renderToString and related implementations.

For AbortController implementations the reason passed to the abort method is forwarded to Fizz and sent to the onError handler. If no reason is provided the AbortController should construct an AbortError DOMException and as a fallback Fizz will generate a similar error in the absence of a reason

For pipeable  streams, an abort function is returned alongside pipe which already accepted a reason. That reason is now forwarded to Fizz and the implementation described above.

For legacy renderers there is no exposed abort functionality but it is used internally and the reasons provided give useful context to, for instance to the fact that Suspense is not supported in renderToString-like renderers
2022-06-07 22:36:09 -07:00
Andrew Clark
79f54c16dc Bugfix: Revealing a hidden update (#24685)
* Add `isHidden` to OffscreenInstance

We need to be able to read whether an offscreen tree is hidden from
an imperative event. We can store this on its OffscreenInstance.

We were already scheduling a commit effect whenever the visibility
changes, in order to toggle the inner effects. So we can reuse that.

* [FORKED] Bugfix: Revealing a hidden update

This fixes a bug I discovered related to revealing a hidden Offscreen
tree. When this happens, we include in that render all the updates that
had previously been deferred — that is, all the updates that would have
already committed if the tree weren't hidden. This is necessary to avoid
tearing with the surrounding contents. (This was the "flickering"
Suspense bug we found a few years ago: #18411.)

The way we do this is by tracking the lanes of the updates that were
deferred by a hidden tree. These are the "base" lanes. Then, in order
to reveal the hidden tree, we process any update that matches one of
those base lanes.

The bug I discovered is that some of these base lanes may include
updates that were not present at the time the tree was hidden. We cannot
flush those updates earlier that the surrounding contents — that, too,
could cause tearing.

The crux of the problem is that we sometimes reuse the same lane for
base updates and for non-base updates. So the lane alone isn't
sufficient to distinguish between these cases. We must track this in
some other way.

The solution I landed upon was to add an extra OffscreenLane bit to any
update that is made to a hidden tree. Then later when we reveal the
tree, we'll know not to treat them as base updates.

The extra OffscreenLane bit is removed as soon as that lane is committed
by the root (markRootFinished) — at that point, it gets
"upgraded" to a base update.

The trickiest part of this algorithm is reliably detecting when an
update is made to a hidden tree. What makes this challenging is when the
update is received during a concurrent event, while a render is already
in progress — it's possible the work-in-progress render is about to
flip the visibility of the tree that's being updated, leading to a race
condition.

To avoid a race condition, we will wait to read the visibility of the
tree until the current render has finished. In other words, this makes
it an atomic operation. Most of this logic was already implemented
in #24663.

Because this bugfix depends on a moderately risky refactor to the update
queue (#24663), it only works in the "new" reconciler fork. We will roll
it out gradually to www before landing in the main fork.

* Add previous commit to list of forked revisions
2022-06-07 20:04:02 -04:00
Sebastian Markbåge
7e8a020a4a Remove extra Server Context argument (#24683)
This was left over from a refactor.
2022-06-07 15:12:51 -04:00
Luna Ruan
3bb154bbab [DevTools] Run Devtools Regression Tests Once a Day (#24678)
We don't need to run DevTools regression tests once an hour, and also it makes getting the most recent react build or react devtools build really annoying, so run them once a day instead
2022-06-07 11:05:04 -07:00
Josh Story
bcbeb52bf3 [Fizz] Disallow complex children in <title> elements (#24679)
* [Fizz] Disallow complex children in <title> elements

<title> Elements in the DOM can only have Text content. In Fizz if more than one text node is emitted an HTML comment node is used as a text separator. Unfortunately because of the content restriction of the DOM representation of the title element this separator is displayed as escaped text which is not what the component author intended.

This commit special cases title handling, primarily to issue warnings if you pass complex children to <title>. At the moment title expects to receive a single child or an array of length 1. In both cases the type of that child must be string or number. If anything more complex is provided a warning will be logged to the console explaining why this is problematic.

There is no runtime behavior change so broken things are still broken (e.g. returning two text nodes which will cause a separator or using Suspense inside title children) but they should at least be accompanied by warnings that are useful.

One edge case that will now warn but won't technically break an application is if you use a Component that returns a single string as a child of title. This is a form of indirection that works but becasue we cannot discriminate between a Component that will follow the rules and one that violates them the warning is issued regardless.

* fixup dev warning conditional logic

* lints

* fix bugs
2022-06-07 00:33:36 -07:00
Josh Story
4f29ba1cc5 support errorInfo in onRecoverableError (#24591)
* extend onRecoverableError API to support errorInfo

errorInfo has been used in Error Boundaries wiht componentDidCatch for a while now. To date this metadata only contained a componentStack. onRecoverableError only receives an error (type mixed) argument and thus providing additional error metadata was not possible without mutating user created mixed objects.

This change modifies rootConcurrentErrors rootRecoverableErrors, and hydrationErrors so all expect CapturedValue types. additionally a new factory function allows the creation of CapturedValues from a value plus a hash and stack.

In general, client derived CapturedValues will be created using the original function which derives a componentStack from a fiber and server originated CapturedValues will be created using with a passed in hash and optional componentStack.
2022-06-06 14:23:32 -07:00
Luna Ruan
254b49e589 Add snapshot testing on e2e test failure (#24672)
We have a currently unreproducible flaky e2e test. This PR captures snapshots on e2e test failures so we can better debug flaky e2e tests that don't fail locally.
2022-06-06 10:36:58 -07:00
Andrew Clark
1cd90d2ccc Refactor of interleaved ("concurrent") update queue (#24663)
* Always push updates to interleaved queue first

Interleaves updates (updates that are scheduled while another render
is already is progress) go into a special queue that isn't applied until
the end of the current render. They are transferred to the "real" queue
at the beginning of the next render.

Currently we check during `setState` whether an update should go
directly onto the real queue or onto the special interleaved queue. The
logic is subtle and it can lead to bugs if you mess it up, as in #24400.

Instead, this changes it to always go onto the interleaved queue. The
behavior is the same but the logic is simpler.

As a further step, we can also wait to update the `childLanes` until
the end of the current render. I'll do this in the next step.

* Move setState return path traversal to own call

A lot of the logic around scheduling an update needs access to the
fiber root. To obtain this reference, we must walk up the fiber return
path. We also do this to update `childLanes` on all the parent
nodes, so we can use the same traversal for both purposes.

The traversal currently happens inside `scheduleUpdateOnFiber`, but
sometimes we need to access it beyond that function, too.

So I've hoisted the traversal out of `scheduleUpdateOnFiber` into its
own function call that happens at the beginning of the
`setState` algorithm.

* Rename ReactInterleavedUpdates -> ReactFiberConcurrentUpdates

The scope of this module is expanding so I've renamed accordingly. No
behavioral changes.

* Enqueue and update childLanes in same function

During a setState, the childLanes are updated immediately, even if a
render is already in progress. This can lead to subtle concurrency bugs,
so the plan is to wait until the in-progress render has finished before
updating the childLanes, to prevent subtle concurrency bugs.

As a step toward that change, when scheduling an update, we should not
update the childLanes directly, but instead defer to the
ReactConcurrentUpdates module to do it at the appropriate time.

This makes markUpdateLaneFromFiberToRoot a private function that is
only called from the ReactConcurrentUpdates module.

* [FORKED] Don't update childLanes until after current render

(This is the riskiest commit in the stack. Only affects the "new"
reconciler fork.)

Updates that occur in a concurrent event while a render is already in
progress can't be processed during that render. This is tricky to get
right. Previously we solved this by adding concurrent updates to a
special `interleaved` queue, then transferring the `interleaved` queue
to the `pending` queue after the render phase had completed.

However, we would still mutate the `childLanes` along the parent path
immediately, which can lead to its own subtle data races.

Instead, we can queue the entire operation until after the render phase
has completed. This replaces the need for an `interleaved` field on
every fiber/hook queue.

The main motivation for this change, aside from simplifying the logic a
bit, is so we can read information about the current fiber while we're
walking up its return path, like whether it's inside a hidden tree.
(I haven't done anything like that in this commit, though.)

* Add 17691ac to forked revisions
2022-06-06 12:15:59 -04:00
Andrew Clark
4ddd8b455c Track revs that intentionally fork the reconciler (#24671)
* Track revs that intentionaly fork the reconciler

When we fork the the "old" and "new" reconciler implementations, it can
be difficult to keep track of which commits introduced the delta
in behavior. This makes bisecting difficult if one of the changes
introduces a bug.

I've added a new file called `forked-revisions` that contains the list
of commits that intentionally forked the reconcilers.

In CI, we'll confirm that the reconcilers are identical except for the
changes in the listed revisions. This also ensures that the revisions
can be cleanly reverted.

* [TEST] Add trivial divergence between forks

This should fail CI. We'll see if the next commit fixes it.

* [TEST] Update list of forked revisions

This should fix CI

* Revert temporary fork

This reverts the temporary fork added in the previous commits that was
used to test CI.

* Update error message when CI fails
2022-06-06 11:53:11 -04:00
Andrew Clark
652dcf6550 Fix CI: Persist build artifacts to workspace
The download_build job needs to persist its artifacts to the workspace
so downstream jobs can access them.

Persist the same directories as the normal build job.
2022-06-06 11:33:32 -04:00
Andrew Clark
dfd6f96f76 Fix CI: Remove copypasta from sizebot download job
This was copy pasted from the similar job that exists to download
base artifacts for sizebot.
2022-06-06 11:30:07 -04:00
Andrew Clark
a621cb099d Fix CI: Download to build instead of base-build (#24677)
Fixes a mistake in #24676. The get_base_build job downloads artifacts to
`base-build` instead of `build`, so that sizebot can compare the two
directories. For most other jobs, though, we want it to produce the
same output as the normal build job.
2022-06-06 10:38:02 -04:00
Andrew Clark
a97a0810ea DevTools e2e workflow: Download build artifacts (#24676)
When running the hourly DevTools testing workflow, we don't need to
build React from scratch each time; we can download its build artifacts,
like we do for sizebot and the release workflow.
2022-06-06 09:57:35 -04:00
Andrew Clark
7a5b8227c7 Allow aritfacts download even if CI is broken (#24666)
* Allow aritfacts download even if CI is broken

Adds an option to the download script to disable the CI check and
continue downloading the artifacts even if CI is broken.

I often rely on this to debug broken build artifacts. I was thinking
the sizebot should also use this when downloading the base artifacts
from main, since for the purposes of size tracking, it really doesn't
matter whether the base commit is broken.

* Sizebot should work even if base rev is broken

Sizebot works by downloading the build artifacts for the base revision
and comparing the fize sizes, but the download script will fail if
the base revision has a failing CI job. This happens more often than it
should because of flaky cron jobs, but even when it does, we shouldn't
let it affect the sizebot — for the purposes of tracking sizes, it
doesn't really matter whether the base revision is broken.
2022-06-02 21:55:35 -04:00
Mengdi Chen
d300cebde2 [DevTools] only polyfill requestAnimationFrame when necessary (#24651) 2022-06-01 13:04:09 -04:00
Luna Ruan
d2c9e834ae [DevTools] Run e2e Regression Tests Hourly on Circle CI (#24648)
Modifies Circle CI so we run e2e regression tests hourly on Circle CI
2022-06-01 10:55:26 -04:00
Luna Ruan
b1858b110d [DevTools] devtools-test-shell Regression App fixes (#24644)
Made a couple of fixes to the `devtools-test-shell`
* test selectors aren't available in > React v18.0 either, so we'll need to mock the test selector functions there as well
* `react-dom/client` should map to `react-dom/client` and not `react-dom`
2022-05-31 16:13:41 -07:00
Josh Story
dd4950c90e [Flight] Implement useId hook (#24172)
* Implements useId hook for Flight server.

The approach for ids for Flight is different from Fizz/Client where there is a need for determinancy. Flight rendered elements will not be rendered on the client and as such the ids generated in a request only need to be unique. However since FLight does support refetching subtrees it is possible a client will need to patch up a part of the tree rather than replacing the entire thing so it is not safe to use a simple incrementing counter. To solve for this we allow the caller to specify a prefix. On an initial fetch it is likely this will be empty but on refetches or subtrees we expect to have a client `useId` provide the prefix since it will guaranteed be unique for that subtree and thus for the entire tree. It is also possible that we will automatically provide prefixes based on a client/Fizz useId on refetches

in addition to the core change I also modified the structure of options for renderToReadableStream where `onError`, `context`, and the new `identifierPrefix` are properties of an Options object argument to avoid the clumsiness of a growing list of optional function arguments.

* defend against useId call outside of rendering

* switch to S from F for Server Component ids

* default to empty string identifier prefix

* Add a test demonstrating that there is no warning when double rendering on the client a server component that used useId

* lints and gates
2022-05-31 14:53:32 -07:00
Josh Larson
26a5b3c7f7 Explicitly set highWaterMark to 0 for ReadableStream (#24641)
* Explicitly set highWaterMark to 0 for ReadableStreams

This is because not all streaming implementations respect the
default behavior of settings highWaterMark to 0 for byte streams.
Being explicit guarantees the intended behavior across runtimes.

* Remove size methods and add FlowFixMe instead
2022-05-31 16:20:36 -04:00
Luna Ruan
25837acfee React DevTools 4.24.6 -> 4.24.7 (#24646) 2022-05-31 16:16:07 -04:00
Mengdi Chen
be1fd48e96 [DevTools] mock requestAnimationFrame with setTimeout as a temporary fix for #24626 (#24633)
* mock requestAnimationFrame as a temp workaround for #24626

* give name to constant variable
2022-05-31 15:32:21 -04:00
Luna Ruan
0b545551e6 [DevTools] Modify DevTools e2e test script for regression tests (#24642)
Modified the `run_devtools_e2e_tests` script so that you can pass in a React version. If you pass in a version, it will build the DevTools shell and run the e2e tests with that version.
2022-05-31 14:39:30 -04:00
Luna Ruan
f534cc6ea4 [DevTools] Add --replaceBuild option to Older React Builds Download Script (#24621)
This PR adds a `--replaceBuild` option to the script that downloads older React version builds. If this flag is true, we will replace the contents of the `build` folder with the contents of the `build-regression` folder and remove the `build-regression` folder after, which was the original behavior.

However, for e2e tests, we need both the original build (for DevTools) and the new build (for the React Apps), so we need both the `build` and the `build-regression` folders. Not adding the `--replaceBuild` option will do this.

This PR also modifies the circle CI config to reflect this change.
2022-05-31 12:23:44 -04:00
Josh Story
aec575914a [Fizz] Send errors down to client (#24551)
* use return from onError

* export getSuspenseInstanceFallbackError

* stringToChunk

* return string from onError in downstream type signatures

* 1 more type

* support encoding errors in html stream and escape user input

This commit adds another way to get errors to the suspense instance by encoding them as dataset properties of a template element at the head of the boundary. Previously if there was an error before the boundary flushed there was no way to stream the error to the client because there would never be a client render instruction.

Additionally the error is sent in 3 parts

1) error hash - this is always sent (dev or prod) if one is provided
2) error message - Dev only
3) error component stack - Dev only, this now captures the stack at the point of error

Another item addressed in this commit is the escaping of potentially unsafe data. all error components are escaped as test for browers when written into the html and as javascript strings when written into a client render instruction.

* nits

Co-authored-by: Marco Salazar <salazarm@fb.com>
2022-05-29 23:07:10 -07:00
Josh Story
a2766387ef [Fizz] Improve text separator byte efficiency (#24630)
* [Fizz] Improve text separator byte efficiency

Previously text separators were inserted following any Text node in Fizz. This increases bytes sent when streaming and in some cases such as title elements these separators are not interpreted as comment nodes and leak into the visual aspects of a page as escaped text.

The reason simple tracking on the last pushed type doesn't work is that Segments can be filled in asynchronously later and so you cannot know in a single pass whether the preceding content was a text node or not. This commit adds a concept of TextEmbedding which provides a best effort signal to Segments on whether they are embedded within text. This allows the later resolution of that Segment to add text separators when possibly necessary but avoid them when they are surely not.

The current implementation can only "peek" head if the segment is a the Root Segment or a Suspense Boundary Segment. In these cases we know there is no trailing text embedding and we can eliminate the separator at the end of the segment if the last emitted element was Text. In normal Segments we cannot peek and thus have to assume there might be a trailing text embedding and we issue a separator defensively. This should be rare in practice as it is assumed most components that will cause segment creation will also emit some markup at the edges.

* [Fizz] Improve separator efficiency when flushing delayed segments

The method by which we get segment markup into the DOM differs depending on when the Segment resolves.

If a Segment resolves before flushing begins for it's parent it will be emitted inline with the parent markup. In these cases separators may be necessary because they are how we clue the browser into breakup up text into distinct nodes that will later match up with what will be hydrated on the client.

If a Segment resolves after flushing has happened a script will be used to patch up the DOM in the client. when this happens if there are any text nodes on the boundary of the patch they won't be "merged" and thus will continue to have distinct representation as Nodes in the DOM. Thus we can avoid doing any separators at the boundaries in these cases.

After applying these changes the only time you will get text separators as follows

* in between serial text nodes that emit at the same time - these are necessary and cannot be eliminated unless we stop relying on the browser to automatically parse the correct text nodes when processing this HTML
* after a final text node in a non-boundary segment that resolves before it's parent has flushed - these are sometimes extraneous, like when the next emitted thing is a non-Text node.

In all other cases text separators should be omitted which means the general byte efficiency of this approach should be pretty good
2022-05-28 08:30:38 -07:00
François Chalifour
f7860538a6 Fix typo in useSyncExternalStore main entry point error (#24631) 2022-05-27 22:16:51 +01:00
Sebastian Markbåge
1bed20731f Add a module map option to the Webpack Flight Client (#24629)
On the server we have a similar translation map from the file path that the
loader uses to the refer to the original module and to the bundled module ID.

The Flight server is optimized to emit the smallest format for the client.
However during SSR, the same client component might go by a different
module ID since it's a different bundle than the client bundle.

This provides an option to add a translation map from client ID to SSR ID
when reading the Flight stream.

Ideally we should have a special SSR Flight Client that takes this option
but for now we only have one Client for both.
2022-05-27 16:16:24 -04:00
Luna Ruan
3133dfa6ee DevTools] e2e Regression Testing App (#24619)
This PR adds an e2e regression app to the react-devtools-shell package. This app:

* Has an app.js and an appLegacy.js entrypoint because apps prior to React 18 need to use ReactDOM.render. These files will create and render multiple test apps (though they currently only render the List)
* Moved the ListApp out of the e2e folder and into an e2e-apps folder so that both e2e and e2e-regression can use the same test apps
* Creates a ListAppLegacy app because prior to React 16.8 hooks didn't exist.
* Added a devtools file for the e2e-regression
* Modifies the webpack config so that the e2e-regression React app can use different a different React version than DevTools
2022-05-26 11:36:00 -04:00
Luna Ruan
1328ff70cd [DevTools] Regression-proof e2e Tests (#24620)
This PR:

* Increases test retry count to 2 so that flaky tests have more of a chance to pass
* Ideally most e2e tests will run for all React versions (and ensure DevTools elegantly fails if React doesn't support its features). However, some features aren't supported in older React versions at all (ex. Profiling) Add runOnlyForReactRange function in these cases to skip tests that don't satisfy the correct React semver range
* Fix should allow searching for component by name test, which was flaky because sometimes the Searchbox would be unfocused the second time we try to type in it
* Edited test Should allow elements to be inspected to check that element inspect gracefully fails in older React versions
* Updated config to add a config.use.url field and a config.use.react_version field, which change depending on the React Version (and whether it's specified)
2022-05-25 20:53:44 -04:00
Josh Story
05c34dea91 [Test] Outer boundary should not report errors from an inner boundary (#24618)
* Test to assert that hydration errors of an inner suspended boundary are not retained by an unsuspended outer boundary

* lints
2022-05-25 14:10:50 -07:00
Andrew Clark
b2763d3eaa Move hydration code out of normal Suspense path (#24532)
* Move hydration code out of normal Suspense path

Shuffling some code around to make it easier to follow. The logic for
updating a dehydrated Suspense boundary is significantly different
from the logic for a client-rendered Suspense boundary. Most of it was
already lifted out into a separate function; this moves the remaining
hydration-specific logic out of updateSuspenseComponent and into
updateDehydratedSuspenseComponent instead.

No expected changes to program behavior.

* Extract hydration logic in complete phase, too

Same as previous step but for the complete phase. This is a separate
commit to make bisecting easier in case something breaks. The logic
is very subtle but mostly all I've done is extract it to
another function.
2022-05-25 15:42:02 -04:00
Alexandru Tasica
2c68776abe fix scripts folder text (#24609) 2022-05-25 09:56:35 -04:00
Luna Ruan
a2505792ed [DevTools] Add CircleCI Chron Job For DevTools Regression Tests (#24601)
This PR adds an hourly chron job on Circle CI that runs regression tests on the most recent DevTools build for React v16.0, v16.5, v16.8 v17.0 and v18.0.
2022-05-24 09:46:22 -04:00
Luna Ruan
1e98682dd3 [DevTools] Fix moduleNameMapper Order in DevTools Config #24602)
We need the regression config moduleNameMapper to come before the current moduleNameMapper so when it tries to map "/^react-dom\/([^/]+)$/ it doesn't get confused. The reason is because order in which the mappings are defined matters. Patterns are checked one by one until one fits, and the most specific rule should be listed first.
2022-05-23 14:18:17 -07:00
Luna Ruan
210fee474d [DevTools] Make Devtools Regression Build (#24599)
This PR adds a script that downloads the specified react version from NPM (ie. react-dom, react, and react-test-renderer) and replaces the corresponding files in the build folder with the downloaded react files.

The scheduler package, unlike react-dom, react, and react-test-renderer, is versioned differently, so we also need to specifically account for that in the script.
2022-05-23 14:33:04 -04:00
Luna Ruan
5a1e558df2 [DevTools] Regression Test Jest Config (#24598)
Some older React versions have different module import names and are missing certain features. This PR mocks modules that don't exist and maps modules in older versions to the ones that are required in tests. Specifically:

* In React v16.5, scheduler is named schedule
* In pre concurrent React, there is no act
* Prior to React v18.0, react-dom/client doesn't exist
* In DevTools, we expect to use scheduler/tracing-profiling instead of scheduler/tracing
2022-05-23 13:50:53 -04:00
Sebastian Silbermann
82c64e1a49 Match Preact behavior for boolean props on custom elements (#24541)
* Log unexpected warnings when testing with ReactDOMServerIntegrationTestUtils

* Add test

Following https://github.com/facebook/react/issues/9230#issuecomment-322007671 except that `foo={true}` renders an empty string.
See https://github.com/facebook/react/issues/9230#issuecomment-1123464720 for rationale.

* Match Preact behavior for boolean props on custom elements

* Poke CircleCI
2022-05-20 18:10:43 +01:00
Luna Ruan
6e2f38f3a4 [DevTools] Remove string.replaceAll Call in @reactVersion Pragma Functions (#24584)
`string.replaceAll` doesn't exist in our CircleCI Docker environment. We also don't need it in this case because `semver.satisfies` allows for whitespace when specifying a range. This PR removes the unnecessary call.
2022-05-19 09:59:36 -07:00
Luna Ruan
d89657bc8f [DevTools] Use Inline Snapshots for storeStressTestSync (#24583)
Change storeStressTestSync to use inline snapshots instead of a snapshot file. We want to do this because some tests are gated and not called in regression tests, and if snapshot tests are not called when there is a corresponding .snap file, that test will fail.

Arguably inline snapshots are a better pattern anyway, so enforcing this in DevTools tests IMO makes sense
2022-05-19 07:52:30 -07:00
Blake Friedman
835d9c9f47 Handle github rate limiting response (#24573)
Make the error messages clearer when the API doesn't respond with 200.
2022-05-18 15:14:27 -04:00
Andrew Clark
769875806c Add option for source maps when running tests (#24577)
I added a `--sourceMaps` option to our test command that enables inline
source maps. I've kept it disabled by default, since it makes the tests
run slower. But it's super useful when attaching to a debugger.
2022-05-18 13:48:21 -04:00
Luna Ruan
b77c12576d [DevTools] Add React Version Pragma to Tests (#24576)
This PR adds the reactVersion pragma to tests.

Tests without the reactVersion pragma won't be run if the reactVersion pragma isn't specified.

Tested each React version manually with the pragma to make sure the tests pass
2022-05-18 12:37:17 -04:00
Andrew Clark
a412d787e9 Remove dependency on build artifacts mirror (#24575)
This reverts #24106.

There was a regression in CircleCI's artifacts API recently where you
could no longer access artifacts without an authorization token. This
broke our size reporting CI job because we can't use an authorization
token on external PRs without potentially leaking it. As a temporary
workaround, I changed the size reporting job to use a public mirror of
our build artifacts.

The CircleCI API has since been fixed to no longer require
authorization, so we can revert the workaround.
2022-05-18 11:13:19 -04:00
Luna Ruan
357a61324f [DevTools][Transition Tracing] Added support for Suspense Boundaries (#23365)
This PR:

* During the passive effect complete phase for Offscreen, we add all the transitions that were added to the update queue in the render phase to the transitions set on the memoziedState. We also add the stateNode for the Offscreen component to the root pendingSuspenseBoundaries map if the suspense boundary has gone from shown to fallback. We remove the stateNode if the boundary goes from fallback to shown.
* During the passive effect complete phase for the HostRoot, for each transition that was initiated during this commit, we add a pending transitionStart callback. We also add them to the transition set on the memoizedState for the HostRoot. If the root pendingSuspenseBoundaries is empty, we add a pending transitionComplete callback.
2022-05-16 13:23:46 -04:00
Luna Ruan
c5e039d9b0 [DevTools] Add jest-cli --reactVersion argument (#24556)
Add `--reactVersion` argument. This argument is only used in DevTools. When this is specified, run only the tests that have the `// @reactVersion` pragma that satisfies the semver version range. Otherwise, run tests as normal
2022-05-16 08:30:43 -07:00
Luna Ruan
4c03bb6ed0 [DevTools] ignore tests without reactVersion pragma if REACT_VERSION specified (#24555)
In DevTools tests, if the REACT_VERSION specified, we know this is a regression test (testing older React Versions). Because a lot of tests test the DevTools front end and we don't want to run them in the regression test scenario, we decided to only run tests that have the // @reactVersion pragma defined.

Because if there are no tests specified, jest will fail, we also opt to use jest.skip to skip all the tests that we don't want to run for a specific React version istead.

This PR makes this change.
2022-05-14 00:54:50 -04:00
Luna Ruan
0ecb77d4c5 [DevTools] Fix formatWithStyles not styling the results if the first argument is an object + Added unit tests (#24554)
formatWithStyles currently doesn't style the array argument if the first argument is an object. This PR fixes this and also adds unit tests.
2022-05-13 15:34:33 -07:00
dan
2c8a1452b8 Fix ignored setState in Safari when iframe is touched (#24459) 2022-05-12 17:58:18 +01:00
Ricky
62662633d1 Remove enableFlipOffscreenUnhideOrder (#24545) 2022-05-12 12:40:17 -04:00
Mengdi "Monday" Chen
52c434be1d React DevTools 4.24.5 -> 4.24.6 (#24547) 2022-05-12 10:52:55 -04:00
Mengdi "Monday" Chen
852f10b5cf fix a bug in console.log with non-string args (#24546) 2022-05-12 10:29:36 -04:00
Ricky
34da5aa69b Only treat updates to lazy as a new mount in legacy mode (#24530)
* Only treat updates to lazy as a new mount in legacy mode

* Update name and swap current check

* Flip order back
2022-05-12 08:51:32 -04:00
Luna Ruan
7d9e17a982 [DevTools] Add Pragma to Only Run Tests if Version Requirement Satisfied (#24533)
This PR:

Adds a transform-react-version-pragma that transforms // @reactVersion SEMVER_VERSION into _test_react_version(...) and _test_react_version_focus(...) that lets us only run a test if it satisfies the right react version.
Adds _test_react_version and _test_react_version_focus to the devtools setupEnv file
Add a devtools preprocessor file for devtools specific plugins
2022-05-11 12:01:05 -04:00
Josh Story
8197c73ec3 Support document rendering (#24523)
* Support Document as a container for hydration and rendering

Previously Document was not handled effectively as a container. in particual when hydrating if there was a fallback to client rendering React would attempt to append a new <html> element into the document before clearing out the existing one which errored leaving the application in brokent state.

The initial approach I took was to recycle the documentElement and never remove or append it, always just moving it to the right fiber and appending the right children (heady/body) as needed. However in testing a simple approach in modern browsers it seems like treating the documentElement like any other element works fine. This change modifies the clearContainer method to remove the documentElement if the container is a DOCUMENT_NODE. Once the container is cleared React can append a new documentElement via normal means.

* Allow Document as container for createRoot

previously rendering into Document was broken and only hydration worked because React did not properly deal with the documentElement and would error in a broken state if used that way. With the previous commit addressing this limitation this change re-adds Document as a valid container for createRoot.

It should be noted that if you use document with createRoot it will drop anything a 3rd party scripts adds the page before rendering for the first time.
2022-05-10 10:17:36 -07:00
Luna Ruan
d20c3af9d1 [DevTools][Bug] Fix Race Condition When Unmounting Fibers (#24510)
When we delete fibers, we will call onCommitFiberUnmount on every deleted fiber to also remove them from the element tree. However, there are some cases where fibers aren't deleted but we still want to remove them from the element tree (ex. offscreen). In the second case, we recursively remove these children during handleCommitFiberRoot.

When we remove an element, we will untrack its corresponding fiber ID. However, because of fast refresh, we don't do this immediately, opting to instead add the value to a set to process later. However, before the set has been processed, we unmount that fiber again, we will get duplicate unmounts.

To fix this, handleCommitFiberRoot explicitly flushes all the fibers in the set before starting the deletion process. We also need to do this in handleCommitFiberUnmount in case handleCommitFiberRoot gets called first.
2022-05-06 15:36:03 -04:00
Timothy Yung
46a6d77e32 Unify JSResourceReference Interfaces (#24507) 2022-05-06 11:24:04 -07:00
Mengdi "Monday" Chen
e531a4a62d [React DevTools] Improve DevTools UI when Inspecting a user Component that Throws an Error (#24248)
* [ReactDevTools] custom view for errors occur in user's code

* [ReactDevTools] show message for unsupported feature

* fix bad import

* fix typo

* fix issues from rebasing

* prettier

* sync error names

* sync error name with upstream

* fix lint & better comment

* fix error message for test

* better error message per review

* add missing file

* remove dead enum & provide component name in error message

* better error message

* better user facing error message
2022-05-05 20:17:23 -04:00
Brian Vaughn
547b707493 React DevTools 4.24.4 -> 4.24.5 (#24503) 2022-05-05 10:19:08 -07:00
Brian Vaughn
d4acbe85d5 Fixed possible undefined error in TreeContext reducer (#24501) 2022-05-05 08:46:57 -07:00
Sebastian Markbåge
024a7274fb Constrain the container type of createPortal (#24496)
We already constrained the type of createRoot (can't take document) and hydrateRoot (can't take fragments).
2022-05-04 23:05:37 -04:00
Luna Ruan
3dc9a8af05 fix forward ref (#24494)
Resolves #24428

---

For fiber types that render user code, we check the PerformedWork flag rather than the props, ref, and state to see if the fiber rendered (rather than bailing out/etc.) so we know whether we need to do things like record profile durations. ForwardRef wasn't added to this list, which caused #24428.
2022-05-04 13:25:27 -07:00
Luna Ruan
c7e494b553 [React DevTools] Fix regex for formateWithStyles function (#24486)
The previous regex to detect string substitutions is not quite right, this PR fixes it by:

Check to make sure we are starting either at the beginning of the line or we match a character that's not % to make sure we capture all the % in a row.
Make sure there are an odd number of % (the first X pairs are escaped % characters. The odd % followed by a letter is the string substitution)
2022-05-03 15:52:56 -07:00
Ricky
6cbf0f7fac Fork ReactSymbols (#24484)
* Fork ReactSymbols

* Fix tests

* Update jest config
2022-05-03 17:12:23 -04:00
Ricky
a10a9a6b5b Add test for hiding children after layout destroy (#24483) 2022-05-03 14:24:23 -04:00
Josh Story
b4eb0ad71f Do not replay erroring beginWork with invokeGuardedCallback when suspended or previously errored (#24480)
When hydrating a suspense boundary an error or a suspending fiber can often lead to a cascade of hydration errors. While in many cases these errors are simply discarded (e.g. when teh root does not commit and we fall back to client rendering) the use of invokeGuardedCallback can lead to many of these errors appearing as uncaught in the browser console. This change avoids error replaying using invokeGuardedCallback when we are hydrating a suspense boundary and have either already suspended or we have one previous error which was replayed.
2022-05-03 11:07:47 -07:00
Ricky
99eef9e2df Hide children of Offscreen after destroy effects (#24446) 2022-05-03 10:16:53 -04:00
Brian Vaughn
6c36aee944 Fixed wrong method call for LRU cache (#24477) 2022-05-02 21:17:01 -04:00
Andrew Clark
ce13860281 Remove enablePersistentOffscreenHostContainer flag (#24460)
This was a Fabric-related experiment that we ended up not shipping.
2022-04-28 15:05:41 -04:00
dan
340060cccd Add @Andarist to changelog credits 2022-04-28 16:03:34 +01:00
dan
9f80a48ad4 Add missing item to the changelog 2022-04-27 02:03:08 +01:00
Andrew Clark
53b95e5511 Fill in date in changelog for 18.1 (#24449) 2022-04-26 17:09:08 -04:00
dan
d78460490b Add date to changelog 2022-04-26 22:07:33 +01:00
dan
9c25728d10 Changelog for 18.1 (#24411)
* 1810-changelog

* Update CHANGELOG.md

Co-authored-by: Strek <ssharishkumar@gmail.com>

* Update CHANGELOG.md

Co-authored-by: Strek <ssharishkumar@gmail.com>
2022-04-26 22:05:29 +01:00
Andrew Clark
2633a6efc4 Bump @next versions (#24448)
18.2 will be the next release
2022-04-26 16:58:53 -04:00
Andrew Clark
72b7462fe7 Bump local package.json versions for 18.1 release (#24447) 2022-04-26 16:58:44 -04:00
Andrew Clark
22edb9f777 React version field should match package.json (#24445)
The `version` field exported by the React package currently corresponds
to the `@next` release for that build. This updates the build script
to output the same version that is used in the package.json file.

It works by doing a find-and-replace of the React version after the
build has completed. This is a bit weird but it saves us from having
to build the `@next` and `@latest` releases separately; they are
identical except for the version numbers.
2022-04-26 16:28:48 -04:00
Michael サイトー 中村 Bashurov
6bf3deef59 Upgrade react-shallow-renderer to support react 18 (#24442)
To a minimum version that support react 18
2022-04-26 19:45:04 +01:00
dan
bd4784c8f8 Revert #24236 (Don't recreate the same fallback on the client if hydrating suspends) (#24434)
* Revert #24236 (Don't recreate the same fallback on the client if hydrating suspends)

* Use @gate FIXME
2022-04-25 16:16:32 +01:00
Andrew Clark
6d3b6d0f40 forwardRef et al shouldn't affect if props reused (#24421)
We don't have strong guarantees that the props object is referentially
equal during updates where we can't bail out anyway — like if the props
are shallowly equal, but there's a local state or context update in the
same batch.

However, as a principle, we should aim to make the behavior consistent
across different ways of memoizing a component. For example, React.memo
has a different internal Fiber layout if you pass a normal function
component (SimpleMemoComponent) versus if you pass a different type like
forwardRef (MemoComponent). But this is an implementation detail.
Wrapping a component in forwardRef (or React.lazy, etc) shouldn't affect
whether the props object is reused during a bailout.

Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com>
2022-04-22 14:23:26 -04:00
Andrew Clark
bd08137666 Fix: useDeferredValue should reuse previous value (#24413)
During an urgent update, useDeferredValue should reuse the previous
value. The regression test I added shows that it was reverting to
the initial value instead.

The cause of the bug was trivial: the update path doesn't update the
hook's `memoizedState` field. Only the mount path.

None of the existing tests happened to catch this because to trigger the
bug, you have to do an urgent update that isn't the first update after
initial render. In all of the existing tests that included an urgent
update, it was the first update, so the "previous" value and the initial
value happened to be the same thing.
2022-04-20 23:30:46 -04:00
Josh Story
9ae80d6a2b Suppress hydration warnings when a preceding sibling suspends (#24404)
* Add failing test case for #24384

If a components suspends during hydration we expect there to be mismatches with server rendered HTML but we were not always supressing warning messages related to these expected mismatches

* Mark hydration as suspending on every thrownException

previously hydration would only be marked as supsending when a genuine error was thrown. This created an opportunity for a hydration mismatch that would warn after which later hydration mismatches would not lead to warnings. By moving the marker check earlier in the thrownException function we get the hydration context to enter the didSuspend state on both error and thrown promise cases which eliminates this gap.

* Fix failing test related to client render fallbacks

This test was actually subject to the project identified in the issue fixed in this branch. After fixing the underlying issue the assertion logic needed to change to pick the right warning which now emits after hydration successfully completes on promise resolution. I changed the container type to 'section' to make the error message slightly easier to read/understand (for me)

* Only mark didSuspend on suspense path

For unknown reasons the didSuspend was being set only on the error path and nto the suspense path. The original change hoisted this to happen on both paths. This change moves the didSuspend call to the suspense path only. This appears to be a noop because if the error path marked didSuspend it would suppress later warnings but if it does not the warning functions themsevles do that suppression (after the first one which necessarily already happened)

* gate test on hydration fallback flags

* refactor didSuspend to didSuspendOrError

the orignial behavior applied the hydration warning bailout to error paths only. originally I moved it to Suspense paths only but this commit restores it to both paths and renames the marker function as didThrow rather than didSuspend

The logic here is that for either case if we get a mismatch in hydration we want to warm up components but effectively consider the hydration for this boundary halted

* factor tests to assert different behavior between prod and dev

* add DEV suffix to didSuspendOrError to better indicate this feature should only affect dev behavior

* move tests back to ReactDOMFizzServer-test

* fix comment casing

* drop extra flag gates in tests

* add test for user error case

* remove unnecessary gate

* Make test better

it now has an intentional client mismatch that would error if there wasn't suppression brought about by the earlier error. when it client renders it has the updated value not found in the server response but we do not see a hydration warning because it was superseded by the thrown error in that render
2022-04-20 14:52:54 -07:00
Andrew Clark
0dc4e6663d Land enableClientRenderFallbackOnHydrationMismatch (#24410)
This flag is already enabled on all relevant surfaces. We can remove it.
2022-04-20 14:09:11 -04:00
Andrew Clark
354772952a Land enableSelectiveHydration flag (#24406)
This flag is already enabled on all relevant surfaces. We can remove it.
2022-04-20 10:26:25 -04:00
Andrew Clark
392808a1f7 Land enableClientRenderFallbackOnTextMismatch flag (#24405)
This flag is already enabled on all relevant surfaces. We can remove it.
2022-04-20 10:21:36 -04:00
Andrew Clark
1e748b4528 Land enableLazyElements flag (#24407)
This flag is already enabled on all relevant surfaces. We can remove it.
2022-04-20 10:17:52 -04:00
Ricky
4175f05934 Temporarily feature flag numeric fallback for symbols (#24401) 2022-04-19 17:34:49 -04:00
Ricky
a6d53f3468 Revert "Clean up Selective Hydration / Event Replay flag (#24156)" (#24402)
This reverts commit b5cca182ffd5500b83f20f215d0e16d6dbae0efb.
2022-04-19 17:34:30 -04:00
Andrew Clark
ab9cdd34fb Bugfix: In legacy mode, call suspended tree's unmount effects when it is deleted (#24400)
* Bug: Missing unmount when suspended tree deleted

When a suspended tree switches to a fallback, we unmount the effects.
If the suspended tree is then deleted, there's a guard to prevent us
from unmounting the effects again.

However, in legacy mode, we don't unmount effects when a tree suspends.
So if the suspended tree is then deleted, we do need to unmount
the effects.

We're missing a check for legacy/concurrent mode.

* Fix: Unmount suspended tree when it is deleted
2022-04-19 17:09:07 -04:00
Josh Story
2bf5eba724 explain the rationale for the chosen escaping implemenation in a comment (#24389) 2022-04-16 14:29:12 -07:00
Josh Story
d40dc73cf9 Escape bootstrapScriptContent for javascript embedding into HTML (#24385)
The previous escape was for Text into HTML and breaks script contents. The new escaping ensures that the script contents cannot prematurely close the host script tag by escaping script open and close string sequences using a unicode escape substitution.
2022-04-16 10:47:46 -07:00
Billy Janitsch
726ba80298 Synchronize implementations of second render logging (#24381)
Minor followup to #24373. The fix for #24373 (comment) didn't get synchronized to the hook implementation.
2022-04-15 10:35:35 -05:00
Luna Ruan
d63cd97245 don't stringify objects for console log second render (#24373)
Fixes #24302 based on #24306.
---

The current implementation for strict mode double logging stringiness and dims the second log. However, because we stringify everything, including objects, this causes objects to be logged as `[object Object]` etc.

This PR creates a new function that formats console log arguments with a specified style. It does this by:
1. The first param is a string that contains %c: Bail out and return the args without modifying the styles. We don't want to affect styles that the developer deliberately set.
2. The first param is a string that doesn't contain %c but contains string formatting: `[`%c${args[0]}`, style, ...args.slice(1)]` Note: we assume that the string formatting that the developer uses is correct.
3. The first param is a string that doesn't contain string formatting OR is not a string: Create a formatting string where:
   -  boolean, string, symbol -> %s
   -  number -> %f OR %i depending on if it's an int or float
   -  default -> %o
---
Co-authored-by: Billy Janitsch <billy@kensho.com>
2022-04-14 11:30:04 -05:00
Luna Ruan
ddb1ab1e97 Rename react-dom/testing to react-dom/unstable_testing in yarn build-for-devtools (#24364)
The shell package wasn't compiling because yarn build-for-devtools was incorrect. The react-dom/test package was renamed to react-dom/unstable_testing. This PR fixes this in the package.json.

Note: Adding packages to the yarn build-for-devtools command isn't great in the long run. Eventually we should make devtools have its own build script.
2022-04-13 11:07:26 -07:00
Andrew Clark
168da8d557 Fix typo that happened during rebasing
I changed the type of this functions returned value but forgot to change
the check.

It happens to work before anyway, because eventually the interleaved
updates will get transferred at the beginning of the next render phase.
But this is more logically consistent.
2022-04-12 15:43:51 -04:00
Andrew Clark
8bc527a4cf Bugfix: Fix race condition between interleaved and non-interleaved updates (#24353)
* Regression test: Interleaved update race condition

Demonstrates the bug reported in #24350.

* Bugfix: Last update wins, even if interleaved

"Interleaved" updates are updates that are scheduled while a render is
already in progress. We put these on a special queue so that they don't
get processed during the current render. Then we transfer them to
the "real" queue after the render has finished.

There was a race condition where an update is received after the render
has finished but before the interleaved update queue had been
transferred, causing the updates to be queued in the wrong order.

The fix I chose is to check if the interleaved updates queue is empty
before adding any update to the real queue. If it's not empty, then
the new update must also be treated as interleaved.
2022-04-12 15:39:11 -04:00
Luna Ruan
f7cf077cca [Transition Tracing] Add Offscreen Queue (#24341)
Adds an Offscreen Queue. We use the offscreen queue to store not yet processed transitions. During the commit phase, we will add these transitions to the transitions field in memoizedState (in the subsequent PR) and clear the transitions field in the updateQueue
2022-04-12 08:42:08 -07:00
sunderls
4fc394bbec Fix suspense fallback throttling (#24253)
* fix suspense throttling

* fix lint

* Tweak tests + another test

Co-authored-by: Dan Abramov <dan.abramov@gmail.com>
2022-04-12 10:42:05 -04:00
Sebastian Markbåge
80170a0681 Match bundle.name and match upper case entry points (#24346)
Fix matching in the build script.

It's possible to provide a custom bundle name in the case we build deep
imports. We should match those names as a convenience.

The script also calls toLowerCase on requested names but some entries have
upper case now.
2022-04-11 21:01:48 -04:00
Luna Ruan
fea6f8da6a [Transition Tracing] Add transition to OffscreenState and pendingSuspenseBoundaries to RootState (#24340)
In this PR we:

Add transitions boilerplate to the OffscreenState. The transitions field will be null on initiation. During the commit phase, if there are any new transitions, we will add any new transitions (either as a result of a transition occurring or a parent suspense boundary completing) to the transitions field. Once the suspense boundary resolves, we no longer need to store the transitions on the boundary, so we can put this field on the Offscreen memoized state
Add pendingSuspenseBoundaries boilerplate to the RootState. This field starts as null. During the commit phase, if a suspense boundary has either gone from fallback to resolved or from resolved to fallback, we will create a new Map if there isn't one, and if there is, we will add (if the boundary is a fallback) or remove the suspense boundary (if the boundary has resolved) from the map.
Add an optional name field to the Suspense boundary
2022-04-11 14:56:20 -07:00
Luna Ruan
8e2f9b086e move passive flag (#24339)
Previously, we were only adding the passive flag when we add the Visibility flag, which is only set when we go from primary to fallback. Now, we add the passive flag BOTH when we go from primary to fallback and from fallback to primary.

An alternate solution is to add the passive flag in the same place as the visibility flag in the offscreen complete phase (rather than the suspense complete phase), but this feature is currently only for suspense, and offscreen can be used in different ways, so for now we add the passive flag only in the suspense component's complete phase. We might want to revisit this later when we think about how offscreen should work with transition tracing.
2022-04-11 14:54:57 -07:00
Luna Ruan
55a21ef7e7 fix pushTransition for transition tracing (#24338)
We forgot to move pushTransition out from the enableCache flag in #24321 in a place that both transition tracing and cache need to push transitions. Move it out from behind the enableCache to prepare for the next PRs.
2022-04-11 14:54:25 -07:00
Afzal Sayed
069d23bb74 [eslint-plugin-exhaustive-deps] Fix exhaustive deps check for unstable vars (#24343)
* Fix exhaustive deps for unstable vars

* Fix formatting

* Optimise iterations

* Fix linting
2022-04-11 21:43:16 +01:00
dan
4997515b96 Point useSubscription to useSyncExternalStore shim (#24289)
* Point useSubscription to useSyncExternalStore shim

* Update tests

* Update README

* Ad hoc case
2022-04-11 21:15:13 +01:00
Dan Abramov
df5d32f230 Remove create-subscription from the list 2022-04-11 20:12:59 +01:00
zhoulixiang
01e2bff1dc Remove unnecessary check (#24332) 2022-04-11 20:08:29 +01:00
dan
d9a0f9e203 Delete create-subscription folder (#24288) 2022-04-11 20:07:22 +01:00
Andrew Clark
f993ffc514 Fix infinite update loop that happens when an unmemoized value is passed to useDeferredValue (#24247)
* Fix infinite loop if unmemoized val passed to uDV

The current implementation of useDeferredValue will spawn a new
render any time the input value is different from the previous one. So
if you pass an unmemoized value (like an inline object), it will never
stop spawning new renders.

The fix is to only defer during an urgent render. If we're already
inside a transition, retry, offscreen, or other non-urgen render, then
we can use the latest value.

* Temporarily disable "long nested update" warning

DevTools' timeline profiler warns if an update inside a layout effect
results in an expensive re-render. However, it misattributes renders
that are spawned from a sync render at lower priority. This affects the
new implementation of useDeferredValue but it would also apply to things
like Offscreen.

It's not obvious to me how to fix this given how DevTools models the
idea of a "nested update" so I'm disabling the warning for now to
unblock the bugfix for useDeferredValue.
2022-04-11 12:34:03 -04:00
Josh Story
fa58002262 [Fizz] Pipeable Stream Perf (#24291)
* Add fixture for comparing baseline render perf for renderToString and renderToPipeableStream

Modified from ssr2 and https://github.com/SuperOleg39/react-ssr-perf-test

* Implement buffering in pipeable streams

The previous implementation of pipeable streaming (Node) suffered some performance issues brought about by the high chunk counts and innefficiencies with how node streams handle this situation. In particular the use of cork/uncork was meant to alleviate this but these methods do not do anything unless the receiving Writable Stream implements _writev which many won't.

This change adopts the view based buffering techniques previously implemented for the Browser execution context. The main difference is the use of backpressure provided by the writable stream which is not implementable in the other context. Another change to note is the use of standards constructs like TextEncoder and TypedArrays.

* Implement encodeInto during flushCompletedQueues

encodeInto allows us to write directly to the view buffer that will end up getting streamed instead of encoding into an intermediate buffer and then copying that data.
2022-04-11 09:13:44 -07:00
Leo
0568c0f8cd Replace zero with NoLanes for consistency in FiberLane (#24327) 2022-04-09 20:29:08 +01:00
Luna Ruan
e0160d50c5 add transition tracing transitions stack (#24321)
Added a transitions stack for to keep track of which transitions are still happening for the current boundary.
* On the root, we will get all transitions that have been initiated for the corresponding lanes.
* Whenever we encounter a suspended boundary, we will add all transitions on the stack onto the boundary
* Whenever we encounter a boundary that just unsuspended, we will add all transitions on the boundary onto the stack
A transition will be considered complete when there are no boundaries that have the associated transition
2022-04-08 17:48:30 -07:00
Luna Ruan
b0f13e5d39 add pendingPassiveTransitions (#24320)
Add pendingPassiveTransitions work loop module level variable. Because workInProgressTransitions might change before we process it in the passive effects, we introduce a new variable, pendingPassiveTransitions, where we store the transitions until we can actually process them in the commit phase.
2022-04-08 16:35:18 -07:00
Luna Ruan
60e63b960f remove console.error in ReactFiberLane (#24319)
We changed the implementation of root.transitionLanes so that, if there is no transitions for a given lane, we use null instead of an array. This means that this error is no longer valid, so we are removing it
2022-04-08 15:33:52 -07:00
Andrew Clark
ec52a5698e Fix: Don't call cWU if already unmounted
When a tree goes offscreen, we unmount all the effects just like we
would in a normal deletion. (Conceptually it _is_ a deletion; we keep
the fiber around so we can reuse its state if the tree mounts again.)

If an offscreen component gets deleted "for real", we shouldn't unmount
it again.

The fix is to track on the stack whether we're inside a hidden tree.

We already had a stack variable for this purpose, called
`offscreenSubtreeWasHidden`, in another part of the commit phase, so I
reused that variable instead of creating a new one. (The name is a bit
confusing: "was" refers to the current tree before this commit. So, the
"previous current".)

Co-authored-by: dan <dan.abramov@me.com>
2022-04-08 18:03:15 -04:00
Andrew Clark
46db4e996d Combine deletion phase into single recursive function
Similar to the previous step, this converts the deletion phase into
a single recursive function. Although there's less code, this one is
a bit trickier because it's already contains some stack-like logic
for tracking the nearest host parent. But instead of using the actual
stack, it repeatedly searches up the fiber return path to find the
nearest host parent.

Instead, I've changed it to track the nearest host parent on the
JS stack.

(We still search up the return path once, to set the initial host parent
right before entering a deleted tree. As a follow up, we can instead
push this to the stack as we traverse during the main mutation phase.)
2022-04-08 18:01:39 -04:00
Andrew Clark
481dece580 Use recursion to traverse during mutation phase
Most of the commit phase uses iterative loops to traverse the tree.
Originally we thought this would be faster than using recursion, but
a while back @trueadm did some performance testing and found that the
loop was slower because we assign to the `return` pointer before
entering a subtree (which we have to do because the `return` pointer
is not always consistent; it could point to one of two fibers).

The other motivation is so we can take advantage of the JS stack to
track contextual information, like the nearest host parent.

We already use recursion in a few places; this changes the mutation
phase to use it, too.
2022-04-08 18:01:21 -04:00
Andrew Clark
f9e6aef828 Wrap try-catch directly around each user function
This moves the try-catch from around each fiber's mutation phase to
direclty around each user function (effect function, callback, etc).

We already do this when unmounting because if one unmount function
errors, we still need to call all the others so they can clean up
their resources.

Previously we didn't bother to do this for anything but unmount,
because if a mount effect throws, we're going to delete that whole
tree anyway.

But now that we're switching from an iterative loop to a recursive one,
we don't want every call frame on the stack to have a try-catch, since
the error handling requires additional memory.

Wrapping every user function is a bit tedious, but it's better
for performance. Many of them already had try blocks around
them already.
2022-04-08 18:00:42 -04:00
Andrew Clark
bcc1b3121e Move reportUncaughtErrorInDev to captureCommitPhaseError
reportUncaughtErrorInDev is always followed by captureCommitPhaseError,
so we can move it into that function.
2022-04-08 18:00:33 -04:00
Andrew Clark
c99c5f1df6 Move ad hoc flag checks into main switch statement
We should always refine the type of fiber before checking the effect
flag, because the fiber tag is more specific.

Now we have a single switch statement for all mutation effects.
2022-04-08 18:00:13 -04:00
Andrew Clark
54b5b32d53 Move Update flag check into each switch case
The fiber tag is more specific than the effect flag, so we should always
refine the type of work first, to minimize redundant checks.

In the next step I'll move all other other flag checks in this function
into the same switch statement.
2022-04-08 17:59:54 -04:00
Andrew Clark
e66e7a0fb8 Inline commitWork into commitMutationOnFiber
There's not really any reason these should be separate functions. The
factoring has gotten sloppy and redundant because there's similar logic
in both places, which is more obvious now that they're combined.

Next I'll start combining the redundant branches.
2022-04-08 17:59:32 -04:00
Andrew Clark
12d7a9ad70 Combine commitWork into single switch statement
commitWork is forked into a separate implementation for mutation mode
(DOM) and persistent mode (React Native). But unlike when it was first
introduced, there's more overlap than differences between the forks,
mainly because we've added new types of fibers. So this joins the two
forks and adds more local branches where the behavior actually
diverges: host nodes, host containers, and portals.
2022-04-08 17:59:14 -04:00
Andrew Clark
ea7b2ec289 Remove wrong return pointer warning
I'm about to refactor part of the commit phase to use recursion instead
of iteration. As part of that change, we will no longer assign the
`return` pointer when traversing into a subtree. So I'm disabling
the internal warning that fires if the return pointer is not consistent
with the parent during the commit phase.

I had originally added this warning to help prevent mistakes when
traversing the tree iteratively, but since we're intentionally switching
to recursion instead, we don't need it.
2022-04-08 17:58:52 -04:00
Ricky
8dcedba15a Add fallback shim for AbortController (#24285)
* Add fallback shim for AbortController

* Replace shim with a minimal stub

* replace-fork

* Better minification

* Fix flow

* Even smaller

* replace-fork

* Revert back to object constructor

* replace-fork
2022-04-08 15:53:40 -04:00
Ricky
b86baa1cb7 Add back lost cache test (#24317) 2022-04-08 15:34:41 -04:00
Zhongjan
a9add2fe08 Fix file path separator compatibility in scripts/babel (#24318)
The problem in scripts\babel\transform-object-assign.js is that file path separator has '/' and '\' between Linux, MacOS and Windows, which causes yarn build error. See https://github.com/facebook/react/issues/24103
2022-04-08 19:47:31 +01:00
Leo
bafe912a5f update types for InputContinuousLane and DefaultLane (#24316) 2022-04-08 18:51:40 +01:00
Luna Ruan
4ebaeae40d moved mutation code to passive (#24251)
This PR moves the code for transition tracing in the mutation phase that adds transitions to the pending callbacks object (to be called sometime later after paint) from the mutation to the passive phase.

Things to think about:

Passive effects can be flushed before or after paint. How do we make sure that we get the correct end time for the interaction?
2022-04-08 09:28:20 -07:00
Brian Vaughn
5b2e7253f9 React DevTools 4.24.3 -> 4.24.4 (#24315) 2022-04-08 11:38:07 -04:00
Leo
caa60e8fcc update types for NonIdleLanes and IdleLane (#24313) 2022-04-08 11:01:18 -04:00
Brian Vaughn
65f35035a6 Allow react-devtools-inline createStore() method to override Store config params (#24303) 2022-04-08 08:59:12 -04:00
Stephen Cyron
1f7a901d7b Fix false positive lint error with large number of branches (#24287)
* Switched RulesOfHooks.js to use BigInt. Added test and updated .eslintrc.js to use es2020.

* Added BigInt as readonly global in eslintrc.cjs.js and eslintrc.cjs2015.js

* Added comment to RulesOfHooks.js that gets rid of BigInt eslint error

* Got rid of changes in .eslintrc.js and yarn.lock

* Move global down

Co-authored-by: stephen cyron <stephen.cyron@fdmgroup.com>
Co-authored-by: dan <dan.abramov@gmail.com>
2022-04-08 00:22:47 +01:00
dan
f56dfe950b Warn on setState() in useInsertionEffect() (#24298)
* Warn on setState() in useInsertionEffect()

* Use existing DEV reset mechanism
2022-04-07 20:12:49 +01:00
Sebastian Silbermann
548b542b41 Update renderToPipeableStream#options.onShellError to match usage (#24299) 2022-04-07 20:06:54 +01:00
dan
d68b09defc Fix warning about setState in useEffect (#24295)
* Fix warning about setState in useEffect

* Fix test

* Fix multiple roots
2022-04-07 18:06:35 +01:00
dan
0579154772 Update create-subscription README (#24294) 2022-04-07 16:41:38 +01:00
dan
e8f4a6653d Fix import in example 2022-04-07 14:12:58 +01:00
dan
3e8c91c5f8 Fix import in README 2022-04-07 13:46:36 +01:00
dan
bb49abea23 Update some READMEs (#24290)
* Update some READMEs

* Update README.md
2022-04-07 02:35:01 +01:00
Sebastian Markbåge
4bc465a16f Rename Controls to PipeableStream (#24286)
This type isn't exported so it's technically not public.

This object mimics a ReadableStream.

Currently this is safe to destructure and call separately but I'm not sure
that's even guaranteed. It should probably be treated as a class in docs.
2022-04-06 19:27:38 -04:00
zhoulixiang
ece5295e5a Remove unnecessary flag check (#24284) 2022-04-06 17:42:53 +01:00
Sebastian Silbermann
af730436c0 test: Update attribute fixture snapshot (#24083)
* test: Update attribute fixture snapshot

* Poke CircleCI

* Poke CircleCI
2022-04-05 02:59:26 +01:00
alireza molaee
1d1fa94a66 Fix false positive warning about react-dom/client with UMD builds (#24274) 2022-04-05 02:56:18 +01:00
dan
9ededef945 Don't mute hydration errors forcing client render (#24276)
* Don't mute hydration errors forcing client render

* Nits
2022-04-05 02:11:22 +01:00
dan
5f7f528083 Add more tests for suppressHydrationWarning (#24275)
* More tests for suppressHydrationWarning

* Move suppressHydration tests to new file

* Extract more tests

* Test name

* Test legacy behavior too
2022-04-05 00:04:15 +01:00
dan
fc47cb1b61 Fix suppressHydrationWarning not working in production (#24271) 2022-04-04 16:23:58 +01:00
Hikari Hayashi
985272e268 Fix name mismatch in react-reconciler custom build. (#24272) 2022-04-04 09:47:36 +01:00
Noel Kim (김민혁)
e912da964d Update Example render for React v18 (#24259) 2022-04-03 02:41:49 +01:00
Luna Ruan
b8cfda15e1 changed Transitions type to Array<Transition> (#24249)
Changed the Transitions type to Array<Transition> because Transitions was confusing
2022-04-01 17:02:28 -04:00
Mengdi "Monday" Chen
c89a15c716 [ReactDebugTools] wrap uncaught error from rendering user's component (#24216)
* [ReactDebugTools] wrap uncaught error from rendering user's component

* fix lint

* make error names more package specific

* update per review comments

* fix tests

* fix lint

* fix tests

* fix lint

* fix error name & nits

* try catch instead of mocking error

* fix test for older node.js version

* avoid false positive from try-catch in tests
2022-04-01 14:38:11 -04:00
dan
ebd7ff65b6 Don't recreate the same fallback on the client if hydrating suspends (#24236)
* Delay showing fallback if hydrating suspends

* Fix up

* Include all non-urgent lanes

* Moar tests

* Add test for transitions
2022-04-01 02:49:54 +01:00
Kay
d352fd0931 Fix for SSR2 fixture not working locally (#24237)
* SS2 fixture not working locally fix

* Fix prettier issue

* prettier excess line fix

* Update render.js

* Update README.md

Co-authored-by: dan <dan.abramov@gmail.com>
2022-04-01 00:26:12 +01:00
dan
4db3ff6c1a Test suite for hydration diff warnings (#24229)
* Test suite for hydration diff warnings

* Test both variants

* Add more edge cases
2022-03-31 17:35:51 +01:00
Brian Vaughn
aa05e73150 Add 4.4.0 release to eslint rules CHANGELOG (#24234) 2022-03-31 10:43:08 -04:00
dan
b76103d66f Remove React 18 issue template (#24220)
React 18 is just React now.
2022-03-30 19:37:31 +01:00
Andrew Clark
77938881f4 Update @next version (#24218)
Now that 18.0 is out, the next minor is 18.1
2022-03-30 12:28:49 -04:00
Sebastian Silbermann
7e3121e1cf Remove unstable_createMutableSource from experimental build (#24209) 2022-03-30 17:05:07 +01:00
dan
a0fb3cf37e Fix changelog typos 2022-03-30 17:00:29 +01:00
Mengdi "Monday" Chen
0415b18a10 [ReactDebugTools] add custom error type for future new hooks (#24168)
* [ReactDebugTools] add custom error type for future new hooks

* update per review comments

* remove unused argument
2022-03-30 11:07:12 -04:00
Brian Vaughn
8b95ea2cba Inline DevTools test snapshots and cleaned up tests (#24199) 2022-03-30 11:02:51 -04:00
Brian Vaughn
c9100d95b9 DevTools release script: Show changelog before minor/patch prompt (#24200) 2022-03-30 09:26:33 -04:00
Mengdi "Monday" Chen
27199d7567 fix build script for react dev tools (#24193) 2022-03-30 09:26:14 -04:00
Strek
cfc76b4658 Update CHANGELOG.md (#24206) 2022-03-30 07:48:32 +01:00
dan
8acc812c67 Add a missing breaking change to changelog 2022-03-29 23:13:50 +01:00
Mengdi "Monday" Chen
adb8ebc927 React DevTools 4.24.2 -> 4.24.3 (#24198) 2022-03-29 14:44:32 -04:00
dan
509d2d9065 Add React 18 changelog (#24195)
* Add React 18 to changelog

* Fix typo

Co-authored-by: Rick Hanlon <rickhanlonii@gmail.com>
2022-03-29 18:13:05 +01:00
Andrew Clark
b2b4bddeb8 Bump react-refresh version 2022-03-29 12:10:52 -04:00
Andrew Clark
3e997fdbaa Bump react-refresh version 2022-03-29 12:08:09 -04:00
Andrew Clark
34aa5cfe0d Update local package.jsons for 18 2022-03-29 12:07:33 -04:00
Brian Vaughn
eaa493e532 Profiler should only report stateful hooks that change between renders (#24189)
The Profiler has an advanced feature that shows why a component re-rendered. In the case of props and (class) state, it shows the names of props/state values that changed between renders. For hooks, DevTools tries to detect which ones may been related to the update by comparing prev/next internal hook structures.

My initial implementation tried to detect all changed hooks. In hindsight this is confusing, because only stateful hooks (e.g. useState, useReducer, and useSyncExternalStore) can schedule an update. (Other types of hooks can change between renders, but in a reactive way.) This PR changes the behavior to only report hooks that scheduled the update.
2022-03-29 11:11:31 -04:00
Andrew Clark
fc46dba67f Remove rc suffix from versions (#24190)
* Remove rc suffix from versions

* Bump eslint-plugin-react-hooks version

I noticed this one was behind the latest published version
2022-03-29 10:53:46 -04:00
Yash Srivastav
fe6e074128 Fix usage of console.error to prevent transform (#24188)
We were suppressing the `react-internals/warning-args` lint rule
for the call to `console.error` in `defaultOnRecoverableError`.

As far as I could tell, the lint rule exists because on dev builds,
we replace all calls to `console.error` with [this error
function](https://github.com/facebook/react/blob/main/packages/shared/consoleWithStackDev.js#L31-L37)
which expects a format string + args and nothing else. We were trying
to pass in an `Error` object directly. After this commit's change,
we will still be passing an `Error` but the transform won't occur.
2022-03-29 10:45:14 +01:00
Brian Vaughn
ba0aee5d71 DevTools bugfix: Ignore duplicate welcome "message" events (#24186) 2022-03-28 14:25:30 -04:00
salazarm
e7d0053e65 [fizz] Fix validateIterable call (#24166)
* fix validate iterable call

* supports iterable

* gate test by experimental
2022-03-25 14:03:06 -04:00
Dan Abramov
3787230b1b Fix fixture 2022-03-25 17:38:10 +00:00
Brian Vaughn
a6bdb882b7 Attach DevTools Tree keyboard events to the Tree container (not the document) (#24164)
We used to listen to at the document level for this event. That allowed us to listen to up/down arrow key events while another section
of DevTools (like the search input) was focused. This was a minor UX positive.

(We had to use ownerDocument rather than document for this, because the DevTools extension renders the Components and Profiler tabs into portals.)

This approach caused a problem though: it meant that a react-devtools-inline instance could steal (and prevent/block) keyboard events from other JavaScript on the page– which could even include other react-devtools-inline instances. This is a potential major UX negative.

Given the above trade offs, we now listen on the root of the Tree itself.
2022-03-25 12:41:13 -04:00
Brian Vaughn
033fe52b48 DevTools imports (#24163)
* Update DevTools imports: react-dom -> react-dom/client
* Silence ReactDOM.render warning in DevTools test shell
2022-03-25 12:02:39 -04:00
Dan Abramov
4072bdfd6d Add Node 17 to devEngines 2022-03-25 04:20:39 +00:00
Brian Vaughn
78fa7109c7 Release script prompts to stop running DEV scripts (#24154) 2022-03-24 19:33:59 -04:00
salazarm
6b85823b35 Clean up Selective Hydration / Event Replay flag (#24156)
* clean up selective hydration / replay flag

* dont export return_targetInst
2022-03-24 14:12:43 -04:00
Mengdi "Monday" Chen
1159ff6193 Add details in READMEs for react-devtools local developement (#24148)
* Add details in READMEs for react-devtools local developement

* typo

* update yarn for release script
2022-03-24 10:04:12 -04:00
Brian Vaughn
8df8a57edd React DevTools 4.24.1 -> 4.24.2 (#24150) 2022-03-24 09:06:10 -04:00
Brian Vaughn
e62a8d7545 Store throws a specific Error type (UnsupportedBridgeOperationError) (#24147)
When this Error type is detected, DevTools shows a custom error overlay with upgrade/downgrade instructions.
2022-03-23 17:04:54 -04:00
Sebastian Silbermann
3f89908983 Fix test-build-devtools if build was generated by build-for-devtools (#24088)
Co-authored-by: Brian Vaughn <brian.david.vaughn@gmail.com>
2022-03-23 09:51:59 -04:00
Andrew Clark
de516ca5a6 Bump versions to rc.3 (#24141) 2022-03-21 21:36:45 -04:00
David McCabe
577f2de46c enableCacheElement flag (#24131)
* enableCacheElement flag

* Update packages/shared/forks/ReactFeatureFlags.testing.js

Co-authored-by: Ricky <rickhanlonii@gmail.com>

* Update packages/shared/forks/ReactFeatureFlags.test-renderer.js

Co-authored-by: Ricky <rickhanlonii@gmail.com>

* Update packages/shared/forks/ReactFeatureFlags.native-oss.js

Co-authored-by: Ricky <rickhanlonii@gmail.com>

* Update packages/shared/ReactFeatureFlags.js

Co-authored-by: Ricky <rickhanlonii@gmail.com>

Co-authored-by: Dave McCabe <davemccabe@fb.com>
Co-authored-by: Ricky <rickhanlonii@gmail.com>
2022-03-20 20:41:02 -07:00
Andrew Clark
2e0d86d221 Allow updating dehydrated root at lower priority without forcing client render (#24082)
* Pass children to hydration root constructor

I already made this change for the concurrent root API in #23309. This
does the same thing for the legacy API.

Doesn't change any behavior, but I will use this in the next steps.

* Add isRootDehydrated function

Currently this does nothing except read a boolean field, but I'm about
to change this logic.

Since this is accessed by React DOM, too, I put the function in a
separate module that can be deep imported. Previously, it was accessing
the FiberRoot directly. The reason it's a separate module is to break a
circular dependency between React DOM and the reconciler.

* Allow updates at lower pri without forcing client render

Currently, if a root is updated before the shell has finished hydrating
(for example, due to a top-level navigation), we immediately revert to
client rendering. This is rare because the root is expected is finish
quickly, but not exceedingly rare because the root may be suspended.

This adds support for updating the root without forcing a client render
as long as the update has lower priority than the initial hydration,
i.e. if the update is wrapped in startTransition.

To implement this, I had to do some refactoring. The main idea here is
to make it closer to how we implement hydration in Suspense boundaries:

- I moved isDehydrated from the shared FiberRoot object to the
HostRoot's state object.
- In the begin phase, I check if the root has received an by comparing
the new children to the initial children. If they are different, we
revert to client rendering, and set isDehydrated to false using a
derived state update (a la getDerivedStateFromProps).
- There are a few places where we used to set root.isDehydrated to false
as a way to force a client render. Instead, I set the ForceClientRender
flag on the root work-in-progress fiber.
- Whenever we fall back to client rendering, I log a recoverable error.

The overall code structure is almost identical to the corresponding
logic for Suspense components.

The reason this works is because if the update has lower priority than
the initial hydration, it won't be processed during the hydration
render, so the children will be the same.

We can go even further and allow updates at _higher_ priority (though
not sync) by implementing selective hydration at the root, like we do
for Suspense boundaries: interrupt the current render, attempt hydration
at slightly higher priority than the update, then continue rendering the
update. I haven't implemented this yet, but I've structured the code in
anticipation of adding this later.

* Wrap useMutableSource logic in feature flag
2022-03-20 16:18:51 -04:00
Sebastian Markbåge
dbe9e732af Avoid conditions where control flow is sufficient (#24126)
This also fixes a type error since resetTextContent can only be called
on Instances.
2022-03-18 16:51:40 -04:00
Luna Ruan
645ec5d6fc fix inspecting an element in a nested renderer bug (#24116)
Fixes this issue, where inspecting components in nested renderers results in an error. The reason for this is because we have different fiberToIDMap instances for each renderer, and owners of a component could be in different renderers.

This fix moves the fiberToIDMap and idToArbitraryFiberMap out of the attach method so there's only one instance of each for all renderers.
2022-03-17 15:40:03 -04:00
Sebastian Markbåge
1c44437355 Fix createRoot container signature (#24110)
The internal Container type represents the types of containers that React
can support in its internals that deal with containers.

This didn't include DocumentFragment which we support specifically for
rendering into shadow roots.

However, not all types makes sense to pass into the createRoot API.

One of those is comment nodes that is deprecated and we don't really fully
support. It really only exists for FB legacy.

For createRoot it doesn't make sense to pass a Document since that will try
to empty the document which removes the HTML tag which doesn't work.
Documents can only be passed to hydrateRoot.

Conversely I'm not sure we actually support hydrating a shadow root properly
so I excluded DocumentFragment from hydrateRoot.
2022-03-16 20:06:00 -04:00
Luna
b075f97422 Fix dispatch config type for skipBubbling (#24109) 2022-03-16 12:05:57 -07:00
Brian Vaughn
8fce116998 Update DevTools READMEs (#24105) 2022-03-16 11:37:10 -04:00
salazarm
ef23a9ee81 Flag for text hydration mismatch (#24107)
* flag for text hydration mismatch

* rm unused import
2022-03-16 10:12:59 -04:00
Andrew Clark
ba5dc6ccde Add authorization header to artifacts request (#24106)
* Add authorization header to artifacts request

CircleCI's artifacts API was updated; it now errors unless you're
logged in. This affects any of our workflows that download
build artifacts.

To fix, I added an authorization header to the request.

* Update sizbot to pull artifacts from public mirror

We can't use the normal download-build script in sizebot because it
depends on the CircleCI artifacts API, which was recently changed to
require authorization. And we can't pass an authorization token
without possibly leaking it to the public, since we run sizebot on
PRs from external contributors. As a temporary workaround, this job
will pull the artifacts from a public mirror that I set up. But we
should find some other solution so we don't have to maintain
the mirror.
2022-03-15 23:10:23 -04:00
Luna Ruan
0412f0c1a4 add offscreen state node (#24026)
Add state node on Offscreen fibers with id (in preparation for transition tracing)
2022-03-15 13:28:50 -07:00
Brian Vaughn
d9677e3492 Update CHANGELOG.md 2022-03-15 14:21:21 -04:00
Luna Ruan
ac574d6883 React DevTools 4.24.0 -> 4.24.1 (#24100) 2022-03-15 14:13:00 -04:00
Brian Vaughn
63b86e1995 Disable unsupported Bridge protocol version dialog and add workaround for old protocol operations format (#24093)
Rationale: The only case where the unsupported dialog really matters is React Naive. That's the case where the frontend and backend versions are most likely to mismatch. In React Native, the backend is likely to send the bridge protocol version before sending operations– since the agent does this proactively during initialization.

I've tested the React Native starter app– after forcefully downgrading the backend version to 4.19.1 (see #23307 (comment)) and verified that this change "fixes" things. Not only does DevTools no longer throw an error that causes the UI to be hidden– it works (meaning that the Components tree can be inspected and interacted with).
2022-03-15 13:48:26 -04:00
Luna
43eb28339a Add skipBubbling property to dispatch config (#23366) 2022-03-14 10:59:21 -07:00
Sebastian Silbermann
2bf7c02f0e Don't hide console error|warn in inspectedElement-test (#24086) 2022-03-14 09:17:37 -04:00
Andrew Clark
061ac27bc9 Fix use of hydrateRoot in DevTools test (#24084)
I noticed while working on a different PR that this test was not
using hydrateRoot correctly. You're meant to pass the initial children
as the second argument.
2022-03-12 19:21:58 -05:00
Sebastian Markbåge
796724086a Match select value against primitives to string but not undefined (#24077) 2022-03-12 13:34:55 -05:00
Andrew Clark
832e2987e0 Revert accdientally merged PR (#24081) 2022-03-11 21:31:23 -05:00
Andrew Clark
02b65fd8c5 Allow updates at lower pri without forcing client render
Currently, if a root is updated before the shell has finished hydrating
(for example, due to a top-level navigation), we immediately revert to
client rendering. This is rare because the root is expected is finish
quickly, but not exceedingly rare because the root may be suspended.

This adds support for updating the root without forcing a client render
as long as the update has lower priority than the initial hydration,
i.e. if the update is wrapped in startTransition.

To implement this, I had to do some refactoring. The main idea here is
to make it closer to how we implement hydration in Suspense boundaries:

- I moved isDehydrated from the shared FiberRoot object to the
HostRoot's state object.
- In the begin phase, I check if the root has received an by comparing
the new children to the initial children. If they are different, we
revert to client rendering, and set isDehydrated to false using a
derived state update (a la getDerivedStateFromProps).
- There are a few places where we used to set root.isDehydrated to false
as a way to force a client render. Instead, I set the ForceClientRender
flag on the root work-in-progress fiber.
- Whenever we fall back to client rendering, I log a recoverable error.

The overall code structure is almost identical to the corresponding
logic for Suspense components.

The reason this works is because if the update has lower priority than
the initial hydration, it won't be processed during the hydration
render, so the children will be the same.

We can go even further and allow updates at _higher_ priority (though
not sync) by implementing selective hydration at the root, like we do
for Suspense boundaries: interrupt the current render, attempt hydration
at slightly higher priority than the update, then continue rendering the
update. I haven't implemented this yet, but I've structured the code in
anticipation of adding this later.
2022-03-11 20:44:32 -05:00
Andrew Clark
83b941a519 Add isRootDehydrated function
Currently this does nothing except read a boolean field, but I'm about
to change this logic.

Since this is accessed by React DOM, too, I put the function in a
separate module that can be deep imported. Previously, it was accessing
the FiberRoot directly. The reason it's a separate module is to break a
circular dependency between React DOM and the reconciler.
2022-03-11 20:44:28 -05:00
Andrew Clark
c8e4789e21 Pass children to hydration root constructor
I already made this change for the concurrent root API in #23309. This
does the same thing for the legacy API.

Doesn't change any behavior, but I will use this in the next steps.
2022-03-11 20:44:25 -05:00
Josh Story
581f0c42ed [Flight] add support for Lazy components in Flight server (#24068)
* [Flight] add support for Lazy components in Flight server

Lazy components suspend until resolved just like in Fizz. Add tests to confirm Lazy works with Shared Components and Client Component references.

* Support Lazy elements

React.Lazy can now return an element instead of a Component. This commit implements support for Lazy elements when server rendering.

* add lazy initialization to resolveModelToJson

adding lazying initialization toResolveModelToJson means we use attemptResolveElement's full logic on whatever the resolved type ends up being. This better aligns handling of misued Lazy types like a lazy element being used as a Component or a lazy Component being used as an element.
2022-03-10 11:18:54 -08:00
Brian Vaughn
82762bea55 React DevTools 4.23.0 -> 4.24.0 (#24066)
* Revert "React DevTools 4.23.0 -> 4.24.0 (#23400)"

This reverts commit f6c130f614.

* React DevTools 4.23.0 -> 4.24.0

* Added additional, pending bugfixes to CHANGELOG

* Updated DevTools build and release script to fix header format
2022-03-10 13:37:01 -05:00
Brian Vaughn
4a87fb5211 Better handle undefined Error stacks in DevTools error boundary (#24065) 2022-03-10 13:36:47 -05:00
Brian Vaughn
48a8574a68 Fixed edge case bug in Profiler (#24031) 2022-03-10 13:35:52 -05:00
Sebastian Markbåge
72a933d289 Gate legacy hidden (#24047)
* Gate legacy hidden

* Gate tests

* Remove export from experimental
2022-03-09 11:48:03 -05:00
Sebastian Markbåge
b9de50d2f9 Update test to reset modules instead of using private state (#24055) 2022-03-08 23:13:32 -05:00
Sebastian Markbåge
c91892ec3c [Fizz] Don't flush empty segments (#24054)
Before this change, we would sometimes write segments without any content
in them. For example for a Suspense boundary that immediately suspends
we might emit something like:

<div hidden id="123">
  <template id="456"></template>
</div>

Where the outer div is just a temporary wrapper and the inner one is a
placeholder for something to be added later.

This serves no purpose.

We should ideally have a heuristic that holds back segments based on byte
size and time. However, this is a straight forward clear win for now.
2022-03-08 23:12:50 -05:00
Andrew Clark
11c5bb6e16 Bump versions to rc.2 2022-03-08 14:37:05 -05:00
Andrew Clark
9fa654eccd Bump versions to rc.2 2022-03-08 14:36:24 -05:00
Sebastian Silbermann
a59f53a603 Fizz: Prevent UnhandledPromiseRejection if shell errors (#24043) 2022-03-08 09:13:47 -05:00
salazarm
d5f1b067c8 [ServerContext] Flight support for ServerContext (#23244)
* Flight side of server context

* 1 more test

* rm unused function

* flow+prettier

* flow again =)

* duplicate ReactServerContext across packages

* store default value when lazily initializing server context

* .

* better comment

* derp... missing import

* rm optional chaining

* missed feature flag

* React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED ??

* add warning if non ServerContext passed into useServerContext

* pass context in as array of arrays

* make importServerContext nott pollute the global context state

* merge main

* remove useServerContext

* dont rely on object getters in ReactServerContext and disallow JSX

* add symbols to devtools + rename globalServerContextRegistry to just ContextRegistry

* gate test case as experimental

* feedback

* remove unions

* Lint

* fix oopsies (tests/lint/mismatching arguments/signatures

* lint again

* replace-fork

* remove extraneous change

* rebase

* 1 more test

* rm unused function

* flow+prettier

* flow again =)

* duplicate ReactServerContext across packages

* store default value when lazily initializing server context

* .

* better comment

* derp... missing import

* rm optional chaining

* missed feature flag

* React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED ??

* add warning if non ServerContext passed into useServerContext

* pass context in as array of arrays

* make importServerContext nott pollute the global context state

* merge main

* remove useServerContext

* dont rely on object getters in ReactServerContext and disallow JSX

* add symbols to devtools + rename globalServerContextRegistry to just ContextRegistry

* gate test case as experimental

* feedback

* remove unions

* Lint

* fix oopsies (tests/lint/mismatching arguments/signatures

* lint again

* replace-fork

* remove extraneous change

* rebase

* reinline

* rebase

* add back changes lost due to rebase being hard

* emit chunk for provider

* remove case for React provider type

* update type for SomeChunk

* enable flag with experimental

* add missing types

* fix flow type

* missing type

* t: any

* revert extraneous type change

* better type

* better type

* feedback

* change import to type import

* test?

* test?

* remove react-dom

* remove react-native-renderer from react-server-native-relay/package.json

* gate change in FiberNewContext, getComponentNameFromType, use switch statement in FlightServer

* getComponentNameFromTpe: server context type gated and use displayName if available

* fallthrough

* lint....

* POP

* lint
2022-03-08 07:55:32 -05:00
Sebastian Markbåge
6edd55a3ff Gate unstable_expectedLoadTime on enableCPUSuspense (#24038) 2022-03-08 01:33:52 -05:00
Sebastian Markbåge
57799b912d Add more feature flag checks (#24037) 2022-03-08 00:13:22 -05:00
Josh Story
e09518e5bb [Fizz] write chunks to a buffer with no re-use (#24034)
* write chunks to a buffer with no re-use

chunks were previously enqueued to a ReadableStream as they were written. We now write them to a view over an ArrayBuffer
and enqueue them only when writing has completed or the buffer's size is exceeded. In addition this copy now ensures
we don't attempt to re-send buffers that have already been transferred.

* refactor writeChunk to be more defensive and efficient

We now defend against overflows using the next views length instead of the current one. this protects us against a future where we use byobRequest and we get longer initial views than we might create after overflowing the first time. Additionally we add in an optimization when we have completely filled up the currentView where we avoid creating subarrays of the chunk to write since it lands exactly on a view boundary. Finally we move the view creation to beginWriting to avoid a runtime check on each write and because we want to reset the view on each beginWriting call in case a throw elsewhere in the program leaves the currentView in an unfinished state

* add tests to exercise codepaths dealing with buffer overlows
2022-03-07 10:34:11 -08:00
Sebastian Markbåge
14c2be8dac Rename Node SSR Callbacks to onShellReady/onAllReady and Other Fixes (#24030)
* I forgot to call onFatalError

I can't figure out how to write a test for this because it only happens
when there is a bug in React itself which would then be fixed if we found
it.

We're also covered by the protection of ReadableStream which doesn't leak
other errors to us.

* Abort requests if the reader cancels

No need to continue computing at this point.

* Abort requests if node streams get destroyed

This is if the downstream cancels is for example.

* Rename Node APIs for Parity with allReady

The "Complete" terminology is a little misleading because not everything
has been written yet. It's just "Ready" to be written now.

onShellReady
onShellError
onAllReady

* 'close' should be enough
2022-03-04 14:38:46 -05:00
Sebastian Markbåge
cb1e7b1c6c Move onCompleteAll to .allReady Promise (#24025)
* Move onCompleteAll to .allReady Promise

The onCompleteAll callback can sometimes resolve before the promise that
returns the stream which is tough to coordinate. A more idiomatic API
for a one shot event is a Promise.

That way the way you render for SEO or SSG is:

const stream = await renderToReadableStream(...);
await stream.readyAll;
respondWith(stream);

Ideally this should be a sub-class of ReadableStream but we don't yet
compile these to ES6 and they'd had to be to native class to subclass
a native stream.

I have other ideas for overriding the .tee() method in a subclass anyway.
So this is inline with that strategy.

* Reject the Promise on fatal errors
2022-03-03 12:46:12 -05:00
salazarm
5662857616 [Fizz] Export debug function for FB (#24024)
* export debug function for FB

* silence flow
2022-03-03 12:02:37 -05:00
Joshua Gross
05c283c3c3 Fabric HostComponent as EventEmitter: support add/removeEventListener (unstable only) (#23386)
* Implement addEventListener and removeEventListener on Fabric HostComponent

* add files

* re-add CustomEvent

* fix flow

* Need to get CustomEvent from an import since it won't exist on the global scope by default

* yarn prettier-all

* use a mangled name consistently to refer to imperatively registered event handlers

* yarn prettier-all

* fuzzy null check

* fix capture phase event listener logic

* early exit from getEventListeners more often

* make some optimizations to getEventListeners and the bridge plugin

* fix accumulateInto logic

* fix accumulateInto

* Simplifying getListeners at the expense of perf for the non-hot path

* feedback

* fix impl of getListeners to correctly remove function

* pass all args in to event listeners
2022-03-02 12:00:08 -08:00
BIKI DAS
08644348b6 Added unit Tests in the ReactART, increasing the code coverage (#23195) 2022-03-02 14:10:06 -05:00
Brian Vaughn
f6c130f614 React DevTools 4.23.0 -> 4.24.0 (#23400)
* React DevTools 4.23.0 -> 4.24.0

* Fixed CHANGELOG header format

* Add separator line beween header version numbers
2022-03-02 13:28:42 -05:00
Brian Vaughn
0e0b1a45fa Show DevTools backend and frontend versions in UI (#23399)
This information can help with bug investigation for renderers (like React Native) that embed the DevTools backend into their source (separately from the DevTools frontend, which gets run by the user).

If the DevTools backend is too old to report a version, or if the version reported is the same as the frontend (as will be the case with the browser extension) then only a single version string will be shown, as before. If a different version is reported, then both will be shown separately.
2022-03-02 12:26:48 -05:00
Josh Story
f0dd459e0d reassign src from props not the dom element src property (#23395)
The src property on the dom element will return a fully qualified name and this does not match the dom
src attribute or the props provided to react. instead of reading from the element and re-assigning the property we
assign the property from props which is how it was initially assigned during the render

Co-authored-by: Josh Story <story@hey.com>
2022-03-01 18:23:16 -05:00
Luna Ruan
feefe437fe Refactor Cache Code (#23393)
This PR refactors the cache code by moving it out of ReactFiberCacheComponent to ReactFiberTransitionPool in anticipation of it being reused by multiple stacks (ie. transition tracing)
2022-03-01 12:39:51 -08:00
Sebastian Markbåge
17806594cc Move createRoot/hydrateRoot to react-dom/client (#23385)
* Move createRoot/hydrateRoot to /client

We want these APIs ideally to be imported separately from things you
might use in arbitrary components (like flushSync). Those other methods
are "isomorphic" to how the ReactDOM tree is rendered. Similar to hooks.

E.g. importing flushSync into a component that only uses it on the client
should ideally not also pull in the entry client implementation on the
server.

This also creates a nicer parity with /server where the roots are in a
separate entry point.

Unfortunately, I can't quite do this yet because we have some legacy APIs
that we plan on removing (like findDOMNode) and we also haven't implemented
flushSync using a flag like startTransition does yet.

Another problem is that we currently encourage these APIs to be aliased by
/profiling (or unstable_testing). In the future you don't have to alias
them because you can just change your roots to just import those APIs and
they'll still work with the isomorphic forms. Although we might also just
use export conditions for them.

For that all to work, I went with a different strategy for now where the
real API is in / but it comes with a warning if you use it. If you instead
import /client it disables the warning in a wrapper. That means that if you
alias / then import /client that will inturn import the alias and it'll
just work.

In a future breaking changes (likely when we switch to ESM) we can just
remove createRoot/hydrateRoot from / and move away from the aliasing
strategy.

* Update tests to import from react-dom/client

* Fix fixtures

* Update warnings

* Add test for the warning

* Update devtools

* Change order of react-dom, react-dom/client alias

I think the order matters here. The first one takes precedence.

* Require react-dom through client so it can be aliased

Co-authored-by: Andrew Clark <git@andrewclark.io>
2022-03-01 00:13:28 -05:00
Sebastian Markbåge
75662d6a7d Remove hacky stream.locked check, declare as byte stream instead (#23387)
We used to check for stream.locked in pull to see if we've been passed to
something that reads yet.

This was a bad hack because it won't actually call pull again if that changes.

The source of this is because the default for "highWaterMark" is 1 on some
streams. So it always wants to add one "chunk" (of size 1).

If we leave our high water mark as 0, we won't fill up any buffers unless we're
asked for more.

This web API is somewhat odd because it would be way more efficient if it
just told us how much the recipient wants instead of calling us once per
chunk.

Anyway, I turns out that if we define ourselves as a "bytes" type of
stream, the default also happens to be a high water mark of 0 so we can
just use that instead.
2022-02-28 21:35:00 -05:00
Josh Story
086fa8ee2f re-trigger load events for img elements on commit (#23316)
early load events will be missed by onLoad handlers if they trigger before the tree is committed
to avoid this we reset the src property on the img element to cause the browser to re-load
the img.

Co-authored-by: Josh Story <story@hey.com>
2022-02-28 18:07:39 -05:00
Sebastian Markbåge
a232744215 Remove flushControlled from experimental releases (#23384)
This brings the exports on npm to parity which simplifies things a bit.

We also don't plan to release this. It is used by Draft.js but that caller
will need to switch to flushSync.
2022-02-28 14:38:13 -05:00
Andrew Clark
a82ef6d40b Add back skipUnmountedBoundaries flag only for www (#23383)
There are a few internal tests that still need to be updated, so I'm
adding this flag back for www only.

The desired behavior rolled out to 10% public, so we're confident there
are no issues.

The open source behavior remains (skipUnmountedBoundaries = true).
2022-02-28 11:14:30 -05:00
Andrew Clark
f468816ef1 Fix false positive hydration warnings (#23364)
* Failing test for react#23331

* Don't warn on hydration mismatch if suspended

When something suspends during hydration, we continue rendering the
siblings to warm up the cache and fire off any lazy network requests.
However, if there are any mismatches while rendering the siblings, it's
likely a false positive caused by the earlier suspended component. So
we should suppress any hydration warnings until the tree no
longer suspends.

Fixes #23332

Co-authored-by: Marcel Laverdet <marcel@laverdet.com>
2022-02-25 18:10:10 -05:00
Andrew Clark
5d08a24c21 useId: Use 'H' to separate main id from hook index (#23363)
No id should be a subset of any other id. Currently, this is not true
when there are multiple hooks in the same component. We append the
hook index to the end of the id, except for the first one. So you get
this pattern.

Before this change:

- 1st hook's id: :R0:
- 2nd hook's id: :R0:1:

The first hook's id is a subset of all the other ids in the
same component.

The fix for this is to use a different character to separate the main
id from the hook index. I've chosen a captial 'H' for this because
capital letters are not part of the base 32 character set when encoding
with `toString(32)`.

After this change:

- 1st hook's id: :R0:
- 2nd hook's id: :R0H1:
2022-02-25 15:46:59 -05:00
Andrew Clark
629036a9c4 Bump versions to prepare for rc.1 (#23362) 2022-02-24 21:24:46 -05:00
Andrew Clark
3a60844a0f Update error message for suspending at sync priority (#23361)
Instead of adding a new Suspense boundary, the default recommendation
is to wrap the suspending update with startTransition.
2022-02-24 21:02:06 -05:00
Sebastian Markbåge
8d0d0e9a8a Deprecate renderToNodeStream (and fix textarea bug) (#23359)
* Deprecate renderToNodeStream

* Use renderToPipeableStream in tests instead of renderToNodeStream

This is the equivalent API. This means that we have way less test coverage
of this API but I feel like that's fine since it has a deprecation warning
in it and we have coverage on renderToString that is mostly the same.

* Fix textarea bug

The test changes revealed a bug with textarea. It happens because we
currently always insert trailing comment nodes. We should optimize that
away. However, we also don't really support complex children so we
should toString it anyway which is what partial renderer used to do.

* Update tests that assert number of nodes

These tests are unnecessarily specific about number of nodes.

I special case these, which these tests already do, because they're good
tests to test that the optimization actually works later when we do
fix it.
2022-02-24 20:09:03 -05:00
Andrew Clark
efe4121ee2 Add : to beginning and end of every useId (#23360)
The ids generated by useId are unique per React root. You can create
additional ids by concatenating them with locally unique strings.

To support this pattern, no id will ever be a subset of another id. We
achieve this by adding a special character to the beginning and end.

We use a colon (":") because it's uncommon — even if you don't prefix
the ids using the `identifierPrefix` option, collisions are unlikely.

One downside of a colon is that it's not a valid character in DOM
selectors, like `querySelectorAll`. We think this is probably
fine because it's not a common use case in React, and there are
workarounds or alternative solutions. But we're open to reconsidering
this in the future if there's a compelling argument.
2022-02-24 20:07:41 -05:00
Luna Ruan
42f15b324f [DevTools][Transition Tracing] onTransitionComplete and onTransitionStart implmentation (#23313)
* add transition name to startTransition

Add a transitionName to start transition, store the transition start time and name in the batch config, and pass it to the root on render

* Transition Tracing Types and Consts

* Root begin work

The root operates as a tracing marker that has all transitions on it. This PR only tested the root with one transition so far

- Store transitions in memoizedState. Do this in updateHostRoot AND attemptEarlyBailoutIfNoScheduledUpdate. We need to do this in the latter part because even if the root itself doesn't have an update, it could still have new transitions in its transitionLanes map that we need to process.

* Transition Tracing commit phase

- adds a module scoped pending transition callbacks object that contains all transition callbacks that have not yet been processed. This  contains all callbacks before the next paint occurs.
- Add code in the mutation phase to:
        * For the root, if there are transitions that were initialized during this commit in the root transition lanes map, add a transition start call to the pending transition callbacks object. Then, remove the transitions from the root transition lanes map.
        * For roots, in the commit phase, add a transition complete call

We add this code in the mutation phase because we can't add it to the passive phase because then the paint might have occurred before we even know which callbacks to call

* Process Callbacks after paint

At the end of the commit phase, call scheduleTransitionCallbacks to schedule all pending transition callbacks to be called after paint. Then clear the callbacks
2022-02-24 14:28:18 -08:00
Sebastian Markbåge
68cb55f262 Add more warnings for second argument to root.render. (#23358)
We already had one for callbacks but containers is also an easy mistake.
2022-02-24 16:31:48 -05:00
Andrew Clark
8c4cd65cfa Add warnings for common root API mistakes (#23356)
For createRoot, a common mistake is to pass JSX as the second argument,
instead of calling root.render.

For hydrateRoot, a common mistake is to forget to pass children as
the second argument.

The type system will enforce correct usage, but since not everyone uses
types we'll log a helpful warning, too.
2022-02-24 10:57:37 -05:00
Andrew Clark
a5b22155c8 Warn if renderSubtreeIntoContainer is called (#23355)
We already warn for all the other legacy APIs. Forgot to enable
this one.
2022-02-24 01:42:22 -05:00
Andrew Clark
52c393b5d2 Revert to client render on text mismatch (#23354)
* Refactor warnForTextDifference

We're going to fork the behavior of this function between concurrent
roots and legacy roots.

The legacy behavior is to warn in dev when the text mismatches during
hydration. In concurrent roots, we'll log a recoverable error and revert
to client rendering. That means this is no longer a development-only
function — it affects the prod behavior, too.

I haven't changed any behavior in this commit. I only rearranged the
code slightly so that the dev environment check is inside the body
instead of around the function call. I also threaded through an
isConcurrentMode argument.

* Revert to client render on text content mismatch

Expands the behavior of enableClientRenderFallbackOnHydrationMismatch to
check text content, too.

If the text is different from what was rendered on the server, we will
recover the UI by falling back to client rendering, up to the nearest
Suspense boundary.
2022-02-24 00:23:56 -05:00
Sebastian Markbåge
1ad8d81292 Remove object-assign polyfill (#23351)
* Remove object-assign polyfill

We really rely on a more modern environment where this is typically
polyfilled anyway and we don't officially support IE with more extensive
polyfilling anyway. So all environments should have the native version
by now.

* Use shared/assign instead of Object.assign in code

This is so that we have one cached local instance in the bundle.

Ideally we should have a compile do this for us but we already follow
this pattern with hasOwnProperty, isArray, Object.is etc.

* Transform Object.assign to now use shared/assign

We need this to use the shared instance when Object.spread is used.
2022-02-23 19:34:24 -05:00
Andrew Clark
b3f3da205b Land warnOnSubscriptionInsideStartTransition flag (#23353)
We're including this in 18. The feature was already enabled — this just
removes the flag.
2022-02-23 18:52:08 -05:00
Andrew Clark
990098f88a Re-arrange main ReactFeatureFlags module (#23350)
@sebmarkbage and I audited the feature flags file to review the status
of each feature or experiment. Based on that, I've added some more
comments to the main ReactFeatureFlags module and rearranged them
into groups.

I haven't changed the value of any flags, yet. There are a few we're
going to land but I'll do them as separate PRs.
2022-02-23 18:49:16 -05:00
Andrew Clark
1f3f6db73c Remove createMutableSource from stable exports (#23352)
I removed useMutableSource in a previous PR but forgot this one.

We still export it in the FB builds until we can migrate the internal
callers (Recoil).
2022-02-23 18:11:22 -05:00
Sebastian Markbåge
587e759302 Remove Numeric Fallback of Symbols (#23348)
This was already defeating the XSS issue that Symbols was meant to protect
against. So you were already supposed to use a polyfill for security.

We rely on real Symbol.for in Flight for Server Components so those require
real symbols anyway.

We also don't really support IE without additional polyfills anyway.
2022-02-23 18:08:30 -05:00
Sebastian Markbåge
40351575d3 Split writeChunk into void and return value (#23343)
This function was modeled after Node streams where write returns a boolean
whether to keep writing or not. I think we should probably switch this
up and read desired size explicitly in appropriate places.

However, in the meantime, we don't have to return a value where we're
not going to use it. So I split this so that we call writeChunkAndReturn
if we're going to return the boolean.

This should help with the compilation so that they can be inlined.
2022-02-23 11:35:21 -05:00
Sebastian Markbåge
2c693b2dee Re-add reentrancy avoidance (#23342)
* tests: add failing test to demonstrate bug in ReadableStream implementation

* Re-add reentrancy avoidance

I removed the equivalency of this in #22446. However, I didn't fully
understand the intended semantics of the spec but I understand this better
now.

The spec is not actually recursive. It won't call pull again inside of a
pull. It might not call it inside startWork neither which the original
issue avoided. However, it will call pull if you enqueue to the controller
without filling up the desired size outside any call.

We could avoid that by returning a Promise from pull that we wait to
resolve until we've performed all our pending tasks. That would be the
more idiomatic solution. That's a bit more involved but since we know
understand it, we can readd the reentrancy hack since we have an easy place
to detect it. If anything, it should probably throw or log here otherwise.

I believe this fixes #22772.

This includes the test from #22889 but should ideally have one for Fizz.

Co-authored-by: Josh Larson <josh.larson@shopify.com>
2022-02-23 00:33:41 -05:00
Andrew Clark
1760b27c02 Remove ./src/* export from public build (#23262)
We only export the source directory so Jest and Rollup can access them
during local development and at build time. The files don't exist in the
public builds, so we don't need the export entry, either.
2022-02-22 20:13:33 -05:00
Andrew Clark
552c067bb1 Remove public export for unstable-shared-subset.js (#23261)
The unstable-shared-subset.js file is not a public module — it's a
private module that the "react" package maps to when it's accessed from
the "react-server" package.

We originally added it because it was required to make our Rollup
configuration work, because at the time only "public" modules could act
as the entry point for a build artifact — that's why it's prefixed with
"unstable". We've since updated our Rollup config to support private
entry points, so we can remove the extra indirection.
2022-02-22 20:03:51 -05:00
OGURA Daiki
4de99b3ca6 fix getSnapshot warning when a selector returns NaN (#23333)
* fix getSnapshot warning when a selector returns NaN

useSyncExternalStoreWithSelector delegate a selector as
getSnapshot of useSyncExternalStore.

* Fiber's use sync external store has a same issue

* Small nits

We use Object.is to check whether the snapshot value has been updated,
so we should also use it to check whether the value is cached.

Co-authored-by: Andrew Clark <git@andrewclark.io>
2022-02-21 01:07:41 -05:00
Luna Ruan
40eaa22d9a Remove dependency on Offscreen Fiber updateQueue for React Cache (#23229)
We need to use the Offscreen Fiber's update queue for interaction tracing. This PR removes the optimization that React Cache uses to not need to push and pop the cache in special circumstances and defaults to always pushing and popping the cache as long as there was a previous cache.
2022-02-19 10:25:27 -05:00
David McCabe
caf6d47077 Enable enableCache on Test Renderer native (#23314)
Co-authored-by: Dave McCabe <davemccabe@fb.com>
2022-02-18 10:44:10 -08:00
Andrew Clark
419ccc2b19 Land skipUnmountedBoundaries experiment (#23322)
This has been rolled out to 10% of Facebook users for months without
any issues.
2022-02-17 21:43:25 -05:00
Andrew Clark
54f785bc51 Disallow comments as DOM containers for createRoot (#23321)
This is an old feature that we no longer support. `hydrateRoot` already
throws if you pass a comment node; this change makes `createRoot`
throw, too.

Still enabled in the Facebook build until we migrate the callers.
2022-02-17 16:44:22 -05:00
Luna Ruan
e9aa9592c1 change ReactBatchConfig.transition
Previously, ReactBatchConfig.transition was an number (1 = there is a transition, 0 = there isn't one). This PR changes this to a transition object (object = there is a transition, null = there isn't one) in preparation for transition tracing changes.
2022-02-17 13:13:27 -08:00
Andrew Clark
51c8411d9d Log a recoverable error whenever hydration fails (#23319)
There are several cases where hydration fails, server-rendered HTML is
discarded, and we fall back to client rendering. Whenever this happens,
we will now log an error with onRecoverableError, with a message
explaining why.

In some of these scenarios, this is not the only recoverable error that
is logged. For example, an error during hydration will cause hydration
to fail, which is itself an error. So we end up logging two separate
errors: the original error, and one that explains why hydration failed.

I've made sure that the original error always gets logged first, to
preserve the causal sequence.

Another thing we could do is aggregate the errors with the Error "cause"
feature and AggregateError. Since these are new-ish features in
JavaScript, we'd need a fallback behavior. I'll leave this for a
follow up.
2022-02-17 15:16:17 -05:00
Andrew Clark
79ed5e18fd Delete vestigial RetryAfterError logic (#23312)
This code was originally added to force a client render after receiving
an error during hydration. Later we added the ForceClientRender to
implement the same behavior, but scoped to an individual Suspense
boundary instead of all the boundaries in the entire root. So it's
now redudant.

We had some test coverage already but I added another test specifically
for the case of throwing a recoverable hydration error in the shell.
2022-02-17 10:24:03 -05:00
Andrew Clark
80059bb730 Switch to client rendering if root receives update (#23309)
If a hydration root receives an update before the outermost shell has
finished hydrating, we should give up hydrating and switch to
client rendering.

Since the shell is expected to commit quickly, this doesn't happen that
often. The most common sequence is something in the shell suspends, and
then the user quickly navigates to a different screen, triggering a
top-level update.

Instead of immediately switching to client rendering, we could first
attempt to hydration at higher priority, like we do for updates that
occur inside nested dehydrated trees.

But since this case is expected to be rare, and mainly only happens when
the shell is suspended, an attempt at higher priority would likely end
up suspending again anyway, so it would be wasted effort. Implementing
it this way would also require us to add a new lane especially for root
hydration. For simplicity's sake, we'll immediately switch to client
rendering. In the future, if we find another use case for a root
hydration lane, we'll reconsider.
2022-02-16 13:15:25 -05:00
Andrew Clark
f7f7ed089e Allow suspending in the shell during hydration (#23304)
* Allow suspending in the shell during hydration

Builds on behavior added in #23267.

Initial hydration should be allowed to suspend in the shell. In
practice, this happens because the code for the outer shell hasn't
loaded yet.

Currently if you try to do this, it errors because it expects there to
be a parent Suspense boundary, because without a fallback we can't
produce a consistent tree. However, for non-sync updates, we don't need
to produce a consistent tree immediately — we can delay the commit
until the data resolves.

In #23267, I added support for suspending without a parent boundary if
the update was wrapped with `startTransition`. Here, I've expanded this
to include hydration, too.

I wonder if we should expand this even further to include all non-sync/
discrete updates.

* Allow suspending in shell for all non-sync updates

Instead of erroring, we can delay the commit.

The only time we'll continue to error when there's no parent Suspense
boundary is during sync/discrete updates, because those are expected to
produce a complete tree synchronously to maintain consistency with
external state.
2022-02-16 12:47:50 -05:00
Andrew Clark
27b5699694 Simplify cache pool contexts (#23280)
The `pooledCache` variable always points to either `root.pooledCache`
or the stack cursor that is used to track caches that were resumed from
a previous render. We can get rid of it by reading from those instead.
This simplifies the code a lot and is harder to mess up, I think.
2022-02-11 17:51:57 -05:00
Luna Ruan
08fce6208e Gracefully handle empty "xstyle" prop values (Part 2) (#23279)
#23190 misses if entry is undefined or null. This fixes this issue.
2022-02-11 14:36:36 -05:00
Luna Ruan
1fb0d06878 [Devtools][Transition Tracing] Add Transition callbacks to createRoot (#23276)
- Add the type of transition tracing callbacks
- Add transition tracing callbacks as an option to `createRoot`
- Add transition tracing callbacks on the root
- Add option to pass transition tracing callbacks to createReactNoop
2022-02-11 10:15:10 -08:00
Luna Ruan
a6987bee73 add <TracingMarker> component boilerplate (#23275)
- Add Tracing Marker component type to React exports
- Add reconciler work tag
- Add devtools work tag
- Add boilerplate for the cache to render children

No functionality yet
2022-02-11 08:42:55 -08:00
Andrew Clark
796fff5483 Allow suspending outside a Suspense boundary (#23267)
(If the update is wrapped in startTransition)

Currently you're not allowed to suspend outside of a Suspense boundary.
We throw an error:

> A React component suspended while rendering, but no fallback UI
was specified

We treat this case like an error because discrete renders are expected
to finish synchronously to maintain consistency with external state.
However, during a concurrent transition (startTransition), what we can
do instead is treat this case like a refresh transition: suspend the
commit without showing a fallback.

The behavior is roughly as if there were a built-in Suspense boundary
at the root of the app with unstable_avoidThisFallback enabled.
Conceptually it's very similar because during hydration you're already
showing server-rendered UI; there's no need to replace that with
a fallback when something suspends.
2022-02-11 11:26:00 -05:00
Andrew Clark
64223fed82 Fix: Multiple hydration errors in same render (#23273)
I made a minor mistake in the original onRecoverableError PR that
only surfaces if there are hydration errors in two different Suspense
boundaries in the same render. This fixes it and adds a unit test.
2022-02-10 08:40:00 -08:00
Andrew Clark
efd8f6442d Resolve default onRecoverableError at root init (#23264)
Minor follow up to initial onRecoverableError PR.

When onRecoverableError is not provided to `createRoot`, the
renderer falls back to a default implementation. Originally I
implemented this with a host config method, but what we can do instead
is pass the default implementation the root constructor as if it were
a user provided one.
2022-02-10 07:59:10 -08:00
Andrew Clark
e0af1aabec Fix wrong context argument to apply
The context argument should be the array, not null.

I wrote a test that I'll include in the next PR.
2022-02-09 20:50:32 -05:00
Andrew Clark
9b5e0517b4 Remove deprecated wildcard folder mapping (#23256)
* Remove deprecated folder mapping

Node v16 deprecated the use of trailing "/" to define subpath folder
mappings in the "exports" field of package.json.

The recommendation is to explicitly list all our exports. We already do
that for all our public modules. I believe the only reason we have a
wildcard pattern is because our package.json files are also used at
build time (by Rollup) to resolve internal source modules that don't
appear in the final npm artifact.

Changing trailing "/" to "/*" fixes the warnings. See
https://nodejs.org/api/packages.html#subpath-patterns for more info.

Since the wildcard pattern only exists so our build script has access to
internal at build time, I've scoped the wildcard to "/src/*". Because
our public modules are located outside the "src" directory, this means
deep imports of our modules will no longer work: only packages that are
listed in the "exports" field.

The only two affected packages are react-dom and react. We need to be
sure that all our public modules are still reachable. I audited the
exports by comparing the entries to the "files" field in package.json,
which represents a complete list of the files that are included in the
final release artifact.

At some point, we should add an e2e packaging test to prevent
regressions; for now, we should have decent coverage because in CI we
run our Jest test suite against the release artifacts.

* Remove umd from exports

Our expectation is that if you're using the UMD builds, you're not
loading them through a normal module system like require or import.
Instead you're probably copying the files directly or loading them from
a CDN like unpkg.
2022-02-09 11:37:17 -08:00
Andrew Clark
274b9fb168 Remove path resolution from internal forks plugin (#23255)
Alternative to #23254

Our build script has a custom plugin to resolve internal module forks.
Currently, it uses require.resolve to resolve the path to a real file
on disk.

Instead, I've updated all the forked module paths to match their
location on disk, relative to the project root, to remove the need to
resolve them in the build script's runtime.

The main motivation is because require.resolve doesn't work with ESM
modules, but aside from that, hardcoding the relative paths is more
predictable — the Node module resolution algorithm is complicated, and
we don't really need its features for this purpose.
2022-02-09 08:44:02 -08:00
Sebastian Markbåge
a3bde7974c Exclude react-dom/unstable_testing entry point from stable releases (#23258)
* Use consistent naming for unstable_testing entry point

* Exclude the testing build from non-experimental builds except at FB

* FB builds shouldn't contribute to whether we include the npm files

* Exclude exports fields if we delete the files entry

* Move test to no longer be internal so we can test against the build

* Update the bundle artifact names since they've now changed

* Gate import since it doesn't exist
2022-02-08 23:12:31 -05:00
Sebastian Markbåge
5690932765 Add onErrorShell Callback (#23247)
This indicates that an error has happened before the shell completed and
there's no point in emitting the result of this stream.

This is not quite the same as other fatal errors that can happen even
after streaming as started.

It's also not quite the same as onError before onCompleteShell because
onError can be called for an error inside a Suspense boundary before the
shell completes.

Implement shell error handling in Node SSR fixtures

Instead of hanging indefinitely.

Update Browser Fixture

Expose onErrorShell to the Node build

This API is not Promisified so it's just a separate callback instead.

Promisify the Browser Fizz API

It's now a Promise of a readable stream. The Promise resolves when the
shell completes. If the shell errors, the Promise is rejected.
2022-02-08 22:38:14 -05:00
Sebastian Markbåge
0dedfcc681 Update the exports field (#23257)
* Add .browser and .node explicit entry points

This can be useful when the automatic selection doesn't work properly.

* Remove react/index

I'm not sure why I added this in the first place. Perhaps due to how our
builds work somehow.

* Remove build-info.json from files field
2022-02-08 21:07:26 -05:00
Sebastian Markbåge
7b541a980d Add exports field to react-dom (#23252)
This configures the exports field for react-dom.

Notably there are some conditions for the /server entry point where we pick
the export based on environments. Most environments now support Web Streams
which is preferred in those environments.

We already do this using the "browser" field so the "browser" condition
applies here too.

I don't think it's necessary, but I also specified "worker" explicitly
since this is for Service Workers and those are often targeted with
Web Pack's "webworker" target, which is also what Cloudflare currently
recommends.

I also added "deno" but deno is a bit special because this only works if
you run with the node compatibility since otherwise you have to specify
absolute URLs for the imports.
2022-02-08 17:19:52 -05:00
Joshua Gross
9d4e8e84f7 React Native raw event EventEmitter - intended for app-specific perf listeners and debugging (#23232)
* RawEventEmitter: new event perf profiling mechanism outside of Pressability to capture all touch events, and other event types

* sync

* concise notation

* Move event telemetry event emitter call from Plugin to ReactFabricEventEmitter, to reduce reliance on the plugin system and move the emit call further into the core

* Backout changes to ReactNativeEventPluginOrder

* Properly flow typing event emitter, and emit event to two channels: named and catchall

* fix typing for event name string

* fix typing for event name string

* fix flow

* Add more comments about how the event telemetry system works

* Add more comments about how the event telemetry system works

* rename to RawEventTelemetryEventEmitterOffByDefault

* yarn prettier-all

* rename event

* comments

* improve flow types

* renamed file
2022-02-07 18:34:01 -08:00
salazarm
1dece52350 Add back warning with component stack on Hydration mismatch (#23241)
* add back warning

* wrapper errorMock in __DEV__ flag

* lint
2022-02-07 17:25:33 -05:00
dan
cd4eb116cf Revert "update node.js version for CI (#23236)" (#23239)
This reverts commit 1d7728bf9d.
2022-02-07 03:55:57 +00:00
sunderls
1d7728bf9d update node.js version for CI (#23236) 2022-02-07 01:10:37 +00:00
Andrew Clark
848e802d20 Add onRecoverableError option to hydrateRoot, createRoot (#23207)
* [RFC] Add onHydrationError option to hydrateRoot

This is not the final API but I'm pushing it for discussion purposes.

When an error is thrown during hydration, we fallback to client
rendering, without triggering an error boundary. This is good because,
in many cases, the UI will recover and the user won't even notice that
something has gone wrong behind the scenes.

However, we shouldn't recover from these errors silently, because the
underlying cause might be pretty serious. Server-client mismatches are
not supposed to happen, even if UI doesn't break from the users
perspective. Ignoring them could lead to worse problems later. De-opting
from server to client rendering could also be a significant performance
regression, depending on the scope of the UI it affects.

So we need a way to log when hydration errors occur.

This adds a new option for `hydrateRoot` called `onHydrationError`. It's
symmetrical to the server renderer's `onError` option, and serves the
same purpose.

When no option is provided, the default behavior is to schedule a
browser task and rethrow the error. This will trigger the normal browser
behavior for errors, including dispatching an error event. If the app
already has error monitoring, this likely will just work as expected
without additional configuration.

However, we can also expose additional metadata about these errors, like
which Suspense boundaries were affected by the de-opt to client
rendering. (I have not exposed any metadata in this commit; API needs
more design work.)

There are other situations besides hydration where we recover from an
error without surfacing it to the user, or notifying an error boundary.
For example, if an error occurs during a concurrent render, it could be
due to a data race, so we try again synchronously in case that fixes it.
We should probably expose a way to log these types of errors, too. (Also
not implemented in this commit.)

* Log all recoverable errors

This expands the scope of onHydrationError to include all errors that
are not surfaced to the UI (an error boundary). In addition to errors
that occur during hydration, this also includes errors that recoverable
by de-opting to synchronous rendering. Typically (or really, by
definition) these errors are the result of a concurrent data race;
blocking the main thread fixes them by prevents subsequent races.

The logic for de-opting to synchronous rendering already existed. The
only thing that has changed is that we now log the errors instead of
silently proceeding.

The logging API has been renamed from onHydrationError
to onRecoverableError.

* Don't log recoverable errors until commit phase

If the render is interrupted and restarts, we don't want to log the
errors multiple times.

This change only affects errors that are recovered by de-opting to
synchronous rendering; we'll have to do something else for errors
during hydration, since they use a different recovery path.

* Only log hydration error if client render succeeds

Similar to previous step.

When an error occurs during hydration, we only want to log it if falling
back to client rendering _succeeds_. If client rendering fails,
the error will get reported to the nearest error boundary, so there's
no need for a duplicate log.

To implement this, I added a list of errors to the hydration context.
If the Suspense boundary successfully completes, they are added to
the main recoverable errors queue (the one I added in the
previous step.)

* Log error with queueMicrotask instead of Scheduler

If onRecoverableError is not provided, we default to rethrowing the
error in a separate task. Originally, I scheduled the task with
idle priority, but @sebmarkbage made the good point that if there are
multiple errors logs, we want to preserve the original order. So I've
switched it to a microtask. The priority can be lowered in userspace
by scheduling an additional task inside onRecoverableError.

* Only use host config method for default behavior

Redefines the contract of the host config's logRecoverableError method
to be a default implementation for onRecoverableError if a user-provided
one is not provided when the root is created.

* Log with reportError instead of rethrowing

In modern browsers, reportError will dispatch an error event, emulating
an uncaught JavaScript error. We can do this instead of rethrowing
recoverable errors in a microtask, which is nice because it avoids any
subtle ordering issues.

In older browsers and test environments, we'll fall back
to console.error.

* Naming nits

queueRecoverableHydrationErrors -> upgradeHydrationErrorsToRecoverable
2022-02-04 07:57:33 -08:00
Andrew Clark
5318971f50 Remove logic for multiple error recovery attempts (#23227)
This deletes some internal behavior that was only used by
useOpaqueIdentifier, as an implementation detail: if an update is
scheduled during the render phase, and something threw an error, we
would try rendering again, either until there were no more errors or
until there were no more render phase updates. This was not a publicly
defined behavior — regular render phase updates are accompanied by
a warning.

Because useOpaqueIdentifier has been replaced by useId, and does not
rely on this implementation detail, we can delete this code.
2022-02-02 13:14:20 -08:00
salazarm
3a44621296 Disable avoidThisFallback support in Fizz (#23224)
* disable fizz avoidThisFallback support

* true
2022-02-01 18:22:04 -05:00
Ricky
0318ac2c41 Revert 4f5449 2022-02-01 15:36:49 -05:00
Ricky
4f5449eb4b Remove main from scheduler index.js 2022-02-01 15:05:18 -05:00
salazarm
3f5ff16c1a [Hydration] Fallback to client render if server rendered extra nodes (#23176)
* rename

* rename

* replace-fork

* rename

* warn in a loop
2022-02-01 14:52:01 -05:00
Brian Vaughn
fa816be7f0 DevTools: Timeline profiler refactor
Refactor DevTools to record Timeline data (in memory) while profiling. Updated the Profiler UI to import/export Timeline data along with legacy profiler data.

Relates to issue #22529
2022-01-28 13:09:28 -05:00
Shivam Jha
2ed58eb889 Readme fixes (#23187)
* readme: fix contributing guide links
2022-01-26 19:13:17 -05:00
Brian Vaughn
3d1e7e7278 Suppress act() warnings in DevTools tests (#23192)
These warnings are not useful for DevTools tests– and sometimes may mask other, important warnings. This commit disables them.
2022-01-26 15:18:21 -05:00
Brian Vaughn
934f72221d Gracefully handle empty "xstyle" prop values (#23190) 2022-01-26 13:54:44 -05:00
Fran Dios
529dc3ce84 Fix context providers in SSR when handling multiple requests (#23171)
* add failing test for renderToPipeableStream

* Fix context providers in SSR when handling multiple requests. Closes #23089

* Add sibling regression test

Co-authored-by: zhuyi01 <zhuyi01@ke.com>
Co-authored-by: Dan Abramov <dan.abramov@me.com>
2022-01-24 17:52:51 +00:00
Brian Vaughn
e28a0db224 React DevTools 4.22.1 -> 4.23.0 2022-01-24 09:29:18 -05:00
Brian Vaughn
13036bfbc8 DevTools should not crawl unmounted subtrees when profiling starts (#23162)
Previously we crawled all subtrees, even not-yet-mounted ones, to initialize context values. This was not only unecessary, but it also caused an error to be thrown. This commit adds a test and fixes that behavior.
2022-01-21 11:05:49 -05:00
Andrew Clark
ca143e18d8 Prettier 2022-01-21 09:59:11 -05:00
Behnam Mohammadi
26baf6a174 styles: replace Array.isArray with module isArray (#23154) 2022-01-21 09:33:00 -05:00
Luna Ruan
7bee1379b7 Filter out deleted components that are added to the updaters list (#23156)
There was a bug that occurred when a destroy effect is called that causes an update. The update would be added to the updaters list even though the fiber that was calling the destroy effect was unmounted and no longer exists. This PR:

* Adds a patch to Devtools to filter out all in the update list that aren't in the fiberToIDMap (which contains all fibers currently on screen)
2022-01-20 13:29:43 -08:00
Brian Vaughn
a637084320 DevTools: Add Jest snapshot serializer for number formatting (#23139)
Numbers in JavaScript can have precision issues due to how they are encoded. This shows up in snapshot tests sometimes with values like 0.0009999999999999992, which makes the tests hard to read and visually diff.

This PR adds a new snapshot serializers which clamps numbers at 3 decimal points (e.g. the above number 0.0009999999999999992 is serialized as 0.001). This new serializer does not impact non-numeric values, integers, and special numbers like NaN and Infinity.
2022-01-20 15:52:17 -05:00
Brian Vaughn
505c15c9ef Don't inject timeline hooks unless React supports profiling (#23151)
This gives DevTools a way to detect whether the current React renderer supports Timeline profiling. (Version alone isn't enough to detect this, neither is general profiling support– since these two are controlled by different feature flags.)
2022-01-20 11:11:26 -05:00
Douglas Armstrong
e12a9dfc96 Fix production-only updateSyncExternalStore() crash when doing setState in render (#23150)
* Update ReactFiberHooks.new.js

* Add regression test + replace-fork

* Prettier

Co-authored-by: Dan Abramov <dan.abramov@me.com>
2022-01-20 15:22:17 +00:00
Ives van Hoorne
3fba8d64f1 Include other build types when building for CodeSandbox CI (#23152) 2022-01-20 15:20:02 +00:00
Dan Abramov
e489402557 Warn when a callback ref returns a function (#23145) 2022-01-20 15:18:38 +00:00
Joey Arhar
05a55a4b09 Fix change events for custom elements (#22938)
* Bypass react event system for custom elements

* Going to try fixing react event system instead

* finally got it to call onChange, but perhaps too many times

* update test

* Removed ReactDOMComponent changes, now works but still doubles for bubbles

* Maybe i should only support bubbling events

* removed some old stuff

* cleaned up changeeventplugin stuff

* prettier, lint

* removed changeeventplugin stuff

* remove unneeded gate for onInput test

* Go back to using ChangeEventPlugin

* Add input+change test

* lint

* Move logic to shouldUseChangeEvent

* use memoizedProps instead of pendingProps

* Run form control behavior before custom element behavior

* add bubbling test

* forgot to append container to body

* add child event target test

* expand <input is=...> test expectations

* Make tests more realistic

* Add extra test

* Add missing gating

* Actually fix gating

Co-authored-by: Dan Abramov <dan.abramov@me.com>
2022-01-19 19:34:07 +00:00
Dan Abramov
d8cfeaf221 Fix context propagation for offscreen/fallback trees (#23095)
* Failing test for Context.Consumer in suspended Suspense

See issue #19701.

* Fix context propagation for offscreen trees

* Address nits

* Specify propagation root for Suspense too

* Pass correct propagation root

* Harden test coverage

This test will fail if we remove propagation, or if we propagate with a root node like fiber.return or fiber.return.return. The additional DEV-only error helps detect a different kind of mistake, like if the thing being passed hasn't actually been encountered on the way up. However, we still leave the actual production loop to check against null so that there is no way we loop forever if the propagation root is wrong.

* Remove superfluous warning

Co-authored-by: overlookmotel <theoverlookmotel@gmail.com>
2022-01-19 16:30:34 +00:00
Brian Vaughn
d504824780 Enable scheduling profiler flag in react-dom/testing builds (#23142) 2022-01-19 11:20:42 -05:00
Dan Abramov
790b5246f6 Fix setState ignored in Safari when iframe is added to DOM in the same commit (#23111)
* Fix setState being ignored in Safari

* Add a regression test

* Add comment
2022-01-18 18:25:34 +00:00
Brian Vaughn
51947a14bb Refactored how React/DevTools log Timeline performance data (#23102)
Until now, DEV and PROFILING builds of React recorded Timeline profiling data using the User Timing API. This commit changes things so that React records this data by calling methods on the DevTools hook. (For now, DevTools still records that data using the User Timing API, to match previous behavior.)

This commit is large but most of it is just moving things around:

* New methods have been added to the DevTools hook (in "backend/profilingHooks") for recording the Timeline performance events.
* Reconciler's "ReactFiberDevToolsHook" has been updated to call these new methods (when they're present).
* User Timing method calls in "SchedulingProfiler" have been moved to DevTools "backend/profilingHooks" (to match previous behavior, for now).
* The old reconciler tests, "SchedulingProfiler-test" and "SchedulingProfilerLabels-test", have been moved into DevTools "TimelineProfiler-test" to ensure behavior didn't change unexpectedly.
* Two new methods have been added to the injected renderer interface: injectProfilingHooks() and getLaneLabelMap().

Relates to #22529.
2022-01-13 14:55:54 -05:00
Moti Zilberman
c09596cc60 Add RN_FB bundles for react-is (#23101)
* Add RN_FB bundles for react-is

* Update packaging.js

* Add ReactNativeInternalFeatureFlags to externals
2022-01-12 21:53:50 +00:00
Joey Arhar
a87adefecd Allow functions to be passed to custom element setters (#23042)
This is part of the new custom element features that were implemented
here:
24dd07bd26

When a custom element has a setter for a property and passes the `in`
heuristic, the value passed to the react property should be assigned
directly to the custom element's property, regardless of the type of the
value. However, it was discovered that this isn't working with
functions. This patch makes it work with functions.

Fixes https://github.com/facebook/react/issues/23041
2022-01-12 20:12:07 +00:00
Stefan Sundin
9a7e6bf0d0 Add --no-show-signature to "git show" commands (#23038)
* Add --no-show-signature to "git show" commands.

This fixes errors if the user has configured the following in their ~/.gitconfig:
[log]
showSignature = true

* yarn prettier-all
2022-01-11 12:14:08 -05:00
Gray Zhang
2f26eb85d6 Add exports field to react-refresh's package.json (#23087)
* Add exports field to react-refresh's package.json

* Update package.json

* Add runtime to exports
2022-01-11 16:48:09 +00:00
Luna Ruan
811634762a add enableTransitionTracing feature flag (#23079)
This PR adds the enableTransitionTracing feature flag
2022-01-10 12:32:40 -08:00
Jack Works
fe905f152f Update package.json (#22954) 2022-01-07 12:59:47 -08:00
Andrew Covenant
fe419346da Console message fixed for devtools (#23067) 2022-01-05 11:45:45 -05:00
Borja Paz Rodríguez
42c30e8b12 Correct typing errors detected in several files (#22965)
* Correct spelling errors in several files
* Correct typos in devtools-shared package files
2022-01-04 10:30:07 -05:00
Brian Vaughn
9724e18004 Run DevTools e2e tests on Circle CI (#23019) 2022-01-04 10:28:03 -05:00
btea
3dc41d8a25 fix: parseExportNamesInto specifiers typo (#22537) 2021-12-23 13:08:56 -05:00
BIKI DAS
20212349ad Fix variable name (#23021) 2021-12-23 08:35:54 -05:00
BIKI DAS
a8e9bbe0fe Made the variable name more meaningful (#23017) 2021-12-22 15:58:06 -05:00
Brian Vaughn
bcd24a6706 DevTools: Only show StrictMode badge on root elements (#23012)
* DevTools: Only show StrictMode badge on root elements

Showing an inline non-compliance badge for every element in the tree is noisy. This commit changes it so that we only show inline icons for root elements (although we continue to show an icon for inspected elements regardless).
2021-12-21 15:26:42 -05:00
Vitalie
bd0a5dd682 #22988 - Fix Bug: @license header in React 18 bundles contains vundefined (#23004)
* Fix Bug: @license header in React 18 bundles contains vundefined
* Remove React version from the header comment
2021-12-21 12:27:59 -05:00
Brian Vaughn
a4ead704ba Use ReactDOM Test Selector API in DevTools e2e tests (#22978)
Builds on top of the existing Playwright tests to plug in the test selector API: https://gist.github.com/bvaughn/d3c8b8842faf2ac2439bb11773a19cec

My goals in doing this are to...
1. Experiment with the new API to see what works and what doesn't.
2. Add some test selector attributes (and remove DOM-structure based selectors).
3. Focus the tests on DevTools itself (rather than the test app).

I also took this opportunity to add a few new test cases– like named hooks, editable props, component search, and profiling- just to play around more with the Playwright API.

Relates to issue #22646
2021-12-21 11:58:04 -05:00
Sebastian Markbåge
ceee524a8f Remove unnecessary clearContainer call (#22979)
This was added when we added error recovery for hydration errors. However,
when the fix up pass happens later on, it'll still call clearContainer in
the commit phase. So this call is unnecessary.
2021-12-17 09:40:39 -08:00
Brian Vaughn
aa8f2bdbce Refactored DevTools test shell for e2e (#22968)
Fixes a regression in the e2e target and makes things easier (hopefully) going forward when adding new e2e tests.
2021-12-15 11:42:59 -05:00
Brian Vaughn
e59233aa85 react-devtools-inline README updates (#22967) 2021-12-15 10:44:14 -05:00
Brian Vaughn
5b69c94eed React DevTools 4.22.0 -> 4.22.1 (#22962) 2021-12-14 23:52:50 -05:00
Brian Vaughn
b10c378024 Revert changes to react-devtools-inline Webpack config from PR #22760 (#22961) 2021-12-14 23:45:46 -05:00
Brian Vaughn
3f45b68141 Re-added deleted files array to react-devtools package.json (#22960) 2021-12-14 23:28:57 -05:00
Sebastian Markbåge
cd1a3e9b55 Build both a partial renderer and fizz renderer of the legacy API for FB (#22933)
This lets us test how the new architecture performs without comparing it to
other infra changes related to streaming.

I renamed the streaming one to ReactDOMServerStreaming so the references
in www need to be updated.

I'll open an adhoc sync with just those files.
2021-12-14 16:19:19 -08:00
Brian Vaughn
75d34aa083 Updated DevTools changelog 2021-12-14 16:50:17 -05:00
jstejada
0229baee21 React DevTools 4.21.0 -> 4.22.0 (#22951) 2021-12-14 14:19:21 -05:00
Brian Vaughn
911f92a44d DevTools: Support mulitple DevTools instances per page (#22949)
This is being done so that we can embed DevTools within the new React (beta) docs.

The primary changes here are to `react-devtools-inline/backend`:
* Add a new `createBridge` API
* Add an option to the `activate` method to support passing in the custom bridge object.

The `react-devtools-inline` README has been updated to include these new methods.

To verify these changes, this commit also updates the test shell to add a new entry-point for multiple DevTools.

This commit also replaces two direct calls to `window.postMessage()` with `bridge.send()` (and adds the related Flow types).
2021-12-14 12:16:16 -05:00
jstejada
5757919256 DevTools: Correctly log errors reported from the store (#22950) 2021-12-13 12:02:14 -05:00
jstejada
a049aa0155 [DevTools] Log errors occurring or reported to the frontend (#22948) 2021-12-13 11:38:45 -05:00
Brian Vaughn
3b3daf5573 Advocate for StrictMode usage within Components tree (#22886)
Adds the concept of subtree modes to DevTools to bridge protocol as follows:
1. Add-root messages get two new attributes: one specifying whether the root is running in strict mode and another specifying whether the root (really the root's renderer) supports the concept of strict mode.
2. A new backend message type (TREE_OPERATION_SET_SUBTREE_MODE). This type specifies a subtree root (id) and a mode (bitmask). For now, the only mode this message deals with is strict mode.

The DevTools frontend has been updated as well to highlight non-StrictMode compliant components.

The changes to the bridge protocol require incrementing the bridge protocol version number, which will also require updating the version of react-devtools-core backend that is shipped with React Native.
2021-12-10 11:05:18 -05:00
Brian Vaughn
2c1cf5618a DevTools should inject itself for XHTML pages too (not just HTML) (#22932) 2021-12-09 15:32:11 -05:00
salazarm
f2a59df48b Remove unstableAvoidThisFallback from OSS (#22884)
* avoidThisFallbackFlag

* avoidThisFallback flag

* missed a spot

* rm gating
2021-12-08 08:21:02 -08:00
Andrew Clark
d3001fb6f1 Use next as prerelease label
Instead of `rc`, which is redundant since it's in the next version
number already.
2021-12-08 10:57:25 -05:00
Andrew Clark
29d2bef9f5 Bump beta -> rc 2021-12-08 10:51:41 -05:00
Joey Arhar
24dd07bd26 Add custom element property support behind a flag (#22184)
* custom element props

* custom element events

* use function type for on*

* tests, htmlFor

* className

* fix ReactDOMComponent-test

* started on adding feature flag

* added feature flag to all feature flag files

* everything passes

* tried to fix getPropertyInfo

* used @gate and __experimental__

* remove flag gating for test which already passes

* fix onClick test

* add __EXPERIMENTAL__ to www flags, rename eventProxy

* Add innerText and textContent to reservedProps

* Emit warning when assigning to read only properties in client

* Revert "Emit warning when assigning to read only properties in client"

This reverts commit 1a093e584ce50e2e634aa743e04f9cb8fc2b3f7d.

* Emit warning when assigning to read only properties during hydration

* yarn prettier-all

* Gate hydration warning test on flag

* Fix gating in hydration warning test

* Fix assignment to boolean properties

* Replace _listeners with random suffix matching

* Improve gating for hydration warning test

* Add outerText and outerHTML to server warning properties

* remove nameLower logic

* fix capture event listener test

* Add coverage for changing custom event listeners

* yarn prettier-all

* yarn lint --fix

* replace getCustomElementEventHandlersFromNode with getFiberCurrentPropsFromNode

* Remove previous value when adding event listener

* flow, lint, prettier

* Add dispatchEvent to make sure nothing crashes

* Add state change to reserved attribute tests

* Add missing feature flag test gate

* Reimplement SSR changes in ReactDOMServerFormatConfig

* Test hydration for objects and functions

* add missing test gate

* remove extraneous comment

* Add attribute->property test
2021-12-08 15:11:42 +00:00
Andrew Clark
72e48b8e16 Fix: Don't skip writing updated package.json
Another fix to previous commit. The special case for
use-sync-external-store still needs to write out the updated
package.json, because we also use that branch to update the
version field.
2021-12-08 02:56:43 -05:00
Andrew Clark
e39b2c8998 Fix peer deps for use-sync-external-store
Merged last PR too quickly
2021-12-08 02:45:57 -05:00
Andrew Clark
ec78b135fb Don't override use-sync-external-store peerDeps (#22882)
Usually the build script updates transitive React dependencies so that
they refer to the corresponding release version.

For use-sync-external-store, though, we also want to support older
versions of React, too. So the normal behavior of the build script
isn't sufficient.

For now, to unblock, I hardcoded a special case, but we should consider
a better way to handle this in the future.
2021-12-07 23:26:12 -08:00
Andrew Clark
06f403481f Add CI job to check npm dependencies (#22881)
Checks that if one React package depends on another, the current
version satisfies the given dependency range.

That way we don't forget to bump dependencies when we release a
new version.
2021-12-07 23:09:00 -08:00
Brian Vaughn
ad607469c5 StyleX plug-in for resolving atomic styles to values for props.xstyle (#22808)
Adds the concept of "plugins" to the inspected element payload. Also adds the first plugin, one that resolves StyleX atomic style names to their values and displays them as a unified style object (rather than a nested array of objects and booleans).

Source file names are displayed first, in dim color, followed by an ordered set of resolved style values.

For builds with the new feature flag disabled, there is no observable change.

A next step to build on top of this could be to make the style values editable, but change the logic such that editing one directly added an inline style to the item (rather than modifying the stylex class– which may be shared between multiple other components).
2021-12-07 20:04:12 -05:00
salazarm
5041c37d27 Remove hydrate option from createRoot (#22878)
* remove hydrate: true option

* remove missed comment

* lint

* warning

* circumvent flow
2021-12-07 16:10:00 -05:00
salazarm
c7917fe769 Test showing that a mismatch at the root recovers with client render but shows loading state (#22873)
* rm console.log

* gate test

* move test

* show fallback state
2021-12-06 12:36:02 -05:00
jstejada
12bffc78d8 [DevTools] Emit new event when DevTools connects in standalone app (#22848) 2021-12-06 08:49:15 -05:00
salazarm
3f9480f0f5 enable continuous replay flag (#22863) 2021-12-03 19:35:20 -05:00
Brian Vaughn
8b8817845a Timeline search (#22799)
Refactor SearchInput component (used in Components tree) to be generic DevTools component with two uses: ComponentSearchInput and TimelineSearchInput.

Refactored Timeline Suspense to more closely match other, newer Suspense patterns (e.g. inspect component, named hooks) and colocated Susepnse code in timelineCache file.

Add search by component name functionality to the Timeline. For now, searching zooms in to the component measure and you can step through each time it rendered using the next/previous arrows.
2021-12-03 16:23:48 -05:00
Andrew Clark
4729ff6d1f Implement identifierPrefix option for useId (#22855)
When an `identifierPrefix` option is given, React will add it to the
beginning of ids generated by `useId`.

The main use case is to avoid conflicts when there are multiple React
roots on a single page.

The server API already supported an `identifierPrefix` option. It's not
only used by `useId`, but also for React-generated ids that are used to
stitch together chunks of HTML, among other things. I added a
corresponding option to the client.

You must pass the same prefix option to both the server and client.
Eventually we may make this automatic by sending the prefix from the
server as part of the HTML stream.
2021-12-02 17:49:43 -08:00
Dan Abramov
71d16750c5 Replay capture phase for continuous events (#22856)
Co-authored-by: Dan Abramov <dan.abramov@me.com>

Co-authored-by: Marco Salazar <salazarm@fb.com>
2021-12-02 14:33:44 +00:00
Dan Abramov
44f99d75fa Track currently replaying event (#22853)
* Track currently replaying event

Co-authored-by: Dan Abramov <dan.abramov@me.com>

* Add warnings

Co-authored-by: Marco Salazar <salazarm@fb.com>
2021-12-02 14:11:21 +00:00
Dan Abramov
e737ea9655 Fork dispatch function based on the flag (#22852)
* Fork function based on a flag

* Prune false branches

Co-authored-by: Marco Salazar <salazarm@fb.com>
2021-12-02 14:02:49 +00:00
Dan Abramov
ea5a413602 Decouple dispatching from attemptToDispatchEvent (#22851)
* Decoupled dispatching from attemptToDispatchEvent

* Remove unnecessary field

It is unnecessary because it's only true when retval is null.
2021-12-02 13:55:57 +00:00
Dan Abramov
ed00d2c3d8 Remove unused flag (#22854) 2021-12-02 02:25:32 +00:00
jstejada
a65ceef370 DevTools: Log version in internal logger (#22825) 2021-11-30 10:48:46 -05:00
Michelle Chen
0cc724c777 update ReactFlightWebpackPlugin to be compatiable with webpack v5 (#22739) 2021-11-25 22:43:22 +00:00
Sebastian Silbermann
ca106a02d1 Add imageSizes and imageSrcSet to know props (#22550)
* feat(react-dom): Add `imageSrcSet`

* feat(react-dom): Add `imageSizes`
2021-11-25 01:49:52 +00:00
Sebastian Silbermann
cbc484b5ae Update attribute-behavior fixture (#22522)
* Fix missing key warning

* Add build instructions

* Update interpretation now that React 17 is latest stable and 18 is next

* Ignore ReactDOM.render deprecation warning

* Ensure a server implementation with `renderToString` is used

* Update AttributeTableSnapshot

* Ensure Popover doesn't overflow
2021-11-25 01:37:09 +00:00
Simen Bekkhus
4e6eec69be fix: document can be null, not just undefined (#22695) 2021-11-24 20:51:15 +00:00
salazarm
c1220ebdde treat empty string as null (#22807) 2021-11-23 18:40:10 -05:00
Esteban
09d9b17757 Update deprecated features in ESLint configuration files. (#22767) 2021-11-23 22:53:26 +00:00
jstejada
a04795c89c Ensure react-is version used for resolution for playwright is installed (#22813) 2021-11-23 13:29:47 -05:00
Sebastian Silbermann
149b420f63 Ensure devtools e2e test use a compatible react-is version (#22790)
* Update lockfile by running `yarn install`

* Ensure devtools e2e test use a compatible react-is version
2021-11-19 10:18:02 -05:00
Sebastian Silbermann
bddbfb86d8 Revert "Fix Node package.json ./ exports deprecation warning (#22783)" (#22792)
This reverts commit 8edeb787b0.
2021-11-19 10:04:13 -05:00
anc95
b831aec48f chore(fast-refresh): double check wasMounted (#22740) 2021-11-18 21:15:07 +00:00
Esteban
b32b67706f Migrate from CLIEngine to the new ESLint class. (#22756)
* Migrate from CLIEngine to the new ESLint class.

* fix output property
2021-11-18 21:12:18 +00:00
Rin Arakaki
8edeb787b0 Fix Node package.json ./ exports deprecation warning (#22783) 2021-11-18 21:11:30 +00:00
salazarm
fdc1d617a4 Flag for client render fallback behavior on hydration mismatch (#22787)
* Add flag for new client-render fallback behavior on hydration mismatch

* gate test

* gate tests too

* fix test gating
2021-11-18 08:16:09 -05:00
hiro
f320ef88f5 fix(typo): Esacpe -> Escape (#22780) 2021-11-16 16:43:25 -05:00
Brian Vaughn
aa19d569b2 Add test selectors to experimental build (#22760)
This change adds a new "react-dom/unstable_testing" entry point but I believe its contents will exactly match "react-dom/index" for the stable build. (The experimental build will have the added new selector APIs.)
2021-11-16 16:27:10 -05:00
Jiachi Liu
520ffc77a3 Use globalThis if possible for native fetch in browser build (#22777) 2021-11-16 21:24:54 +00:00
Esteban
afbc2d08f4 Remove unused react-internal/invariant-args ESLint rule. (#22778) 2021-11-16 20:11:20 +00:00
Esteban
ca94e26802 Remove 'packages/shared/invariant.js' (#22779) 2021-11-16 20:11:11 +00:00
salazarm
4ff5f5719b Move unstable_scheduleHydration to ReactDOMHydrationRoot (#22455)
* move unstable_scheduleHydration to ReactDOMHydrationRoot

* move definition of schedule hydration

* fix test?

* prototype

* fix test

* remove gating because unstable_scheduleHydration is no longer gated through index.stable.js because its exposed through ReactDOMHydrationRoot instead of the ReactDOM package

* remove another gating
2021-11-15 17:15:01 -05:00
Abhay Gupta
ee8f146a61 Proof of Concept for E2E tests using playwright (#22754) 2021-11-15 16:44:45 -05:00
Andrew Clark
96ca8d9155 Allow publishing with beta tag (#22768) 2021-11-15 10:43:40 -08:00
Andrew Clark
a52d76b877 Bump 18 from alpha to beta (#22766) 2021-11-15 10:26:30 -08:00
Andrew Clark
83564712b6 Move SuspenseList to experimental channel (#22765)
There's more work to be done to implement this correctly on the server,
so we're going to wait to release it until an 18.x minor.
2021-11-15 10:12:56 -08:00
MalikIdreesHasanKhan
489b4bdcca Fixed typos (#22763)
* Fixed typos

* Update ReactFiberWorkLoop.new.js

* Update ReactFiberWorkLoop.old.js
2021-11-15 12:31:35 -05:00
Brijesh Prasad
d4144e6e54 fix : grammatical typo for test description (#22764)
* fix : grammatical typo for test description

* fix linting issues
2021-11-15 11:44:48 -05:00
Mert Ciflikli
200415c91c fix typos (#22288) 2021-11-15 10:59:35 -05:00
Han Han
0b329511b9 chore: fix comment typo (#22657) 2021-11-15 10:58:30 -05:00
180909
e6f60d2add fix typos (#22715) 2021-11-15 10:58:21 -05:00
Sebastian Silbermann
f86cd5408b devtools: dont restore profiling data if we're profling (#22753) 2021-11-15 10:46:17 -05:00
Ricky
c0c71a8685 Re-enable useMutableSource in internal RN (#22750) 2021-11-12 16:54:59 -05:00
Brian Vaughn
cb11155c86 Add runtime type checks around module boundary code (#22748) 2021-11-12 10:03:41 -05:00
Brian Vaughn
56efc65e58 DevTools should properly report re-renders due to (use)context changes (#22746)
Note that this only fixes things for newer versions of React (e.g. 18 alpha). Older versions will remain broken because there's not a good way to read the most recent context value for a location in the tree after render has completed. This is because React maintains a stack of context values during render, but by the time DevTools is called– render has finished and the stack is empty.
2021-11-11 14:22:22 -05:00
Brian Vaughn
a44a7a2a3f Filter empty commits (all Fibers bailed out) from Profiler (#22745) 2021-11-11 10:35:16 -05:00
Brian Vaughn
e0aa5e205f Add Scheduling Profiler GK link to Timeline UI for FB build (#22730)
This is a constant source of confusion for FB engineers trying to figure out why Chrome profiling data does not have any React marks.
2021-11-09 16:10:48 -05:00
Dan Abramov
a04f13d299 react-refresh@0.11.0 2021-11-09 20:23:32 +00:00
irinakk
ff9897d23e [React Refresh] support typescript namespace syntax (#22621)
* [React Refresh] support typescript namespace syntax

* [React Refresh] handle nested namespace

Co-authored-by: Wang Yilin <wang_yil@worksap.co.jp>
2021-11-09 20:22:19 +00:00
salazarm
0ddd69d122 Throw on hydration mismatch and force client rendering if boundary hasn't suspended within concurrent root (#22629)
* Throw on hydration mismatch

* remove debugger

* update error message

* update error message part2...

* fix test?

* test? :(

* tests 4real

* remove useRefAccessWarning gating

* split markSuspenseBoundary and getNearestBoundary

* also assert html is correct

* replace-fork

* also remove client render flag on suspend

* replace-fork

* fix mismerge????
2021-11-09 13:40:50 -05:00
Dan Abramov
c3f34e4beb eslint-plugin-react-hooks@4.3.0 2021-11-09 13:58:55 +00:00
Dan Abramov
827021c4e3 Changelog for eslint-plugin-react-hooks@4.3.0 2021-11-09 13:55:27 +00:00
Yash Joshi
2b77ab26ad fix(devtools): accept json file in import fileinput (#22717) 2021-11-08 16:35:35 -05:00
Yash Joshi
2db6d6a5a7 fix(devtools): expose css vars to reach-ui portal components (#22716) 2021-11-08 15:17:22 -05:00
Brian Vaughn
99a73ac670 Timeline: Improved snapshot view (#22706) 2021-11-08 12:28:33 -05:00
Esteban
327d5c4845 Delete unused Circle CI scripts. (#22710) 2021-11-06 14:16:49 +00:00
Sebastian Silbermann
ee069065db devtools: Display root type for root updates in "what caused this update?" (#22599) 2021-11-05 11:58:35 -04:00
Konstantin Popov
54f6ae9b1c Fix small typos (#22701) 2021-11-04 19:49:06 -04:00
Brian Vaughn
13455d26d1 Cleaned up remaining "scheduling profiler" references in DevTools (#22696) 2021-11-04 11:40:45 -04:00
Brian Vaughn
8ca3f567bc Fix module-boundary wrappers (#22688) 2021-11-04 10:40:35 -04:00
Brian Vaughn
1bf6deb865 Renamed packages/react-devtools-scheduling-profiler to packages/react-devtools-timeline (#22691) 2021-11-04 10:02:06 -04:00
Brian Vaughn
51c558aeb6 Rename (some) "scheduling profiler" references to "timeline" (#22690) 2021-11-03 15:10:29 -04:00
EzzAk
255221c869 [DevTools] Add open in editor for fb (#22649)
Co-authored-by: Brian Vaughn <bvaughn@fb.com>
2021-11-03 11:27:30 -04:00
Andrew Clark
00ced1e2b7 Fix useId in strict mode (#22681)
* Fix: useId in strict mode

In strict mode, `renderWithHooks` is called twice to flush out
side effects.

Modying the tree context (`pushTreeId` and `pushTreeFork`) is effectful,
so before this fix, the tree context was allocating two slots for a
materialized id instead of one.

To address, I lifted those calls outside of `renderWithHooks`. This
is how I had originally structured it, and it's how Fizz is structured,
too. The other solution would be to reset the stack in between the calls
but that's also a bit weird because we usually only ever reset the
stack during unwind or complete.

* Add test for render phase updates

Noticed this while fixing the previous bug
2021-11-02 17:59:17 -07:00
Brian Vaughn
9fb3442250 Fix DevTools advanced tooltip display conditional check (#22669) 2021-11-02 11:02:45 -04:00
Abhay Gupta
3fcd81dd1c Improved workers filenames in devtools-inline (#22676) 2021-11-02 10:30:37 -04:00
Andrew Clark
5cccacd131 Upgrade useId to alpha channel (#22674) 2021-11-01 15:26:42 -07:00
Andrew Clark
75f3ddebfa Remove experimental useOpaqueIdentifier API (#22672)
useId is the updated version of this API.
2021-11-01 15:02:39 -07:00
Brian Vaughn
8c4a05b8fb Remove @flow pragma comment from module registration start/stop templates (#22670) 2021-11-01 17:46:09 -04:00
Andrew Clark
ebf9ae8579 useId (#22644)
* Add useId to dispatcher

* Initial useId implementation

Ids are base 32 strings whose binary representation corresponds to the
position of a node in a tree.

Every time the tree forks into multiple children, we add additional bits
to the left of the sequence that represent the position of the child
within the current level of children.

    00101       00010001011010101
    ╰─┬─╯       ╰───────┬───────╯
  Fork 5 of 20       Parent id

The leading 0s are important. In the above example, you only need 3 bits
to represent slot 5. However, you need 5 bits to represent all the forks
at the current level, so we must account for the empty bits at the end.

For this same reason, slots are 1-indexed instead of 0-indexed.
Otherwise, the zeroth id at a level would be indistinguishable from
its parent.

If a node has only one child, and does not materialize an id (i.e. does
not contain a useId hook), then we don't need to allocate any space in
the sequence. It's treated as a transparent indirection. For example,
these two trees produce the same ids:

<>                          <>
  <Indirection>               <A />
    <A />                     <B />
  </Indirection>            </>
  <B />
</>

However, we cannot skip any materializes an id. Otherwise, a parent id
that does not fork would be indistinguishable from its child id. For
example, this tree does not fork, but the parent and child must have
different ids.

<Parent>
  <Child />
</Parent>

To handle this scenario, every time we materialize an id, we allocate a
new level with a single slot. You can think of this as a fork with only
one prong, or an array of children with length 1.

It's possible for the the size of the sequence to exceed 32 bits, the
max size for bitwise operations. When this happens, we make more room by
converting the right part of the id to a string and storing it in an
overflow variable. We use a base 32 string representation, because 32 is
the largest power of 2 that is supported by toString(). We want the base
to be large so that the resulting ids are compact, and we want the base
to be a power of 2 because every log2(base) bits corresponds to a single
character, i.e. every log2(32) = 5 bits. That means we can lop bits off
the end 5 at a time without affecting the final result.

* Incremental hydration

Stores the tree context on the dehydrated Suspense boundary's state
object so it resume where it left off.

* Add useId to react-debug-tools

* Add selective hydration test

Demonstrates that selective hydration works and ids are preserved even
after subsequent client updates.
2021-11-01 13:30:44 -07:00
Andrew Clark
a0d991fe65 Re-land #22292 (remove uMS from open source build) (#22664)
I had to revert #22292 because there are some internal callers of
useMutableSource that we haven't migrated yet. This removes
useMutableSource from the open source build but keeps it in the
internal one.
2021-10-31 21:39:51 -07:00
Andrew Clark
9db8713f9d Pin CI to Node 14 (#22665)
CI starting running Node 16, which breaks some of our tests because
the error message text for undefined property access has changed.

We should pin to Node 14 until we are able to update the messages.
2021-10-31 18:01:39 -07:00
Juan
6c7ef3fce5 React DevTools 4.20.2 -> 4.21.0 (#22661) 2021-10-31 19:19:02 -04:00
Andrew Clark
6bce0355c3 Upgrade useSyncExternalStore to alpha channel (#22662)
* Move useSyncExternalStore shim to a nested entrypoint

Also renames `useSyncExternalStoreExtra` to
`useSyncExternalStoreWithSelector`.

- 'use-sync-external-store/shim' -> A shim for `useSyncExternalStore`
  that works in React 16 and 17 (any release that supports hooks). The
  module will first check if the built-in React API exists, before
  falling back to the shim.
- 'use-sync-external-store/with-selector' -> An extended version of
  `useSyncExternalStore` that also supports `selector` and `isEqual`
  options. It does _not_ shim `use-sync-external-store`; it composes the
  built-in React API. **Use this if you only support 18+.**
- 'use-sync-external-store/shim/with-selector' -> Same API, but it
  composes `use-sync-external-store/shim` instead. **Use this for
  compatibility with 16 and 17.**
- 'use-sync-external-store' -> Re-exports React's built-in API. Not
  meant to be used. It will warn and direct users to either the shim or
  the built-in API.

* Upgrade useSyncExternalStore to alpha channel
2021-10-31 15:38:03 -07:00
Andrew Clark
7034408ff7 Follow-up improvements to error code extraction infra (#22516)
* Output FIXME during build for unminified errors

The invariant Babel transform used to output a FIXME comment if it
could not find a matching error code. This could happen if there were
a configuration mistake that caused an unminified message to
slip through.

Linting the compiled bundles is the most reliable way to do it because
there's not a one-to-one mapping between source modules and bundles. For
example, the same source module may appear in multiple bundles, some
which are minified and others which aren't.

This updates the transform to output the same messages for Error calls.

The source lint rule is still useful for catching mistakes during
development, to prompt you to update the error codes map before pushing
the PR to CI.

* Don't run error transform in development

We used to run the error transform in both production and development,
because in development it was used to convert `invariant` calls into
throw statements.

Now that don't use `invariant` anymore, we only have to run the
transform for production builds.

* Add ! to FIXME comment so Closure doesn't strip it

Don't love this solution because Closure could change this heuristic,
or we could switch to a differnt compiler that doesn't support it. But
it works.

Could add a bundle that contains an unminified error solely for the
purpose of testing it, but that seems like overkill.

* Alternate extract-errors that scrapes artifacts

The build script outputs a special FIXME comment when it fails to minify
an error message. CI will detect these comments and fail the workflow.

The comments also include the expected error message. So I added an
alternate extract-errors that scrapes unminified messages from the
build artifacts and updates `codes.json`.

This is nice because it works on partial builds. And you can also run it
after the fact, instead of needing build all over again.

* Disable error minification in more bundles

Not worth it because the number of errors does not outweight the size
of the formatProdErrorMessage runtime.

* Run extract-errors script in CI

The lint_build job already checks for unminified errors, but the output
isn't super helpful.

Instead I've added a new job that runs the extract-errors script and
fails the build if `codes.json` changes. It also outputs the expected
diff so you can easily see which messages were missing from the map.

* Replace old extract-errors script with new one

Deletes the old extract-errors in favor of extract-errors2
2021-10-31 15:37:32 -07:00
Juan
9c8161ba81 Reapply changes from #22631 (#22645) 2021-10-28 11:04:27 -04:00
Brian Vaughn
c624dc3598 DevTools supports ENV-injected version for better internal bug reports (#22635) 2021-10-27 17:18:48 -04:00
Juan
26bc8ff9bf Revert logic for checking for duplicate installations of DevTools (#22638)
* Revert "Only show DevTools warning about unrecognized build in Chrome (#22571)"

This reverts commit b72dc8e930.

* Revert "Show warning in UI when duplicate installations of DevTools extension are detected (#22563)"

This reverts commit 930c9e7eeb.

* Revert "Prevent errors/crashing when multiple installs of DevTools are present (#22517)"

This reverts commit 545d4c2de7.

* Remove all references to passing extensionId in postMessage

* Keep build changes

* lint
2021-10-27 16:34:44 -04:00
Erik Andersson
6c3dcc7a47 Enable 'Reload and Start Profiling' for Microsoft Edge (#22631) 2021-10-27 10:20:07 -04:00
Shu Ding
4298ddbc56 fix passing strings as chunks (#22617) 2021-10-23 23:21:55 -04:00
btea
90e5d36388 chore: fix comment typo (#22615) 2021-10-22 12:44:31 -04:00
Andrew Clark
3c4c1c4703 Remove warning for dangling passive effects (#22609)
In legacy mode, a test can get into a situation where passive effects are
"dangling" — an update finished, and scheduled some passive effects,
but the effects don't flush.

This is why React warns if you don't wrap updates in act. The act API is
responsible for flushing passive effects. But there are some cases where
the act API (in legacy roots) intentionally doesn't warn, like updates
that originate from roots and classes. It's possible those updates will
render children that contain useEffect. Because of this, dangling
effects are still possible, and React doesn't warn about it.

So we implemented a second act warning for dangling effects.

However, in concurrent roots, we now enforce that all APIs that schedule
React work must be wrapped in act. There's no scenario where dangling
passive effects can happen that doesn't already trigger the warning for
updates. So the dangling effects warning is redundant.

The warning was never part of a public release. It was only enabled
in concurrent roots.

So we can delete it.
2021-10-21 15:39:59 -07:00
Andrew Clark
d5b6b4b865 Expand act warning to cover all APIs that might schedule React work (#22607)
* Move isActEnvironment check to function that warns

I'm about to fork the behavior in legacy roots versus concurrent roots
even further, so I'm lifting this up so I only have to fork once.

* Lift `mode` check, too

Similar to previous commit. I only want to check this once. Not for
performance reasons, but so the logic is easier to follow.

* Expand act warning to include non-hook APIs

In a test environment, React warns if an update isn't wrapped with act
— but only if the update originates from a hook API, like useState.

We did it this way for backwards compatibility with tests that were
written before the act API was introduced. Those tests didn't require
act, anyway, because in a legacy root, all tasks are synchronous except
for `useEffect`.

However, in a concurrent root, nearly every task is asynchronous. Even
tasks that are synchronous may spawn additional asynchronous work. So
all updates need to be wrapped with act, regardless of whether they
originate from a hook, a class, a root, or any other type of component.

This commit expands the act warning to include any API that triggers
an update.

It does not currently account for renders that are caused by a Suspense
promise resolving; those are modelled slightly differently from updates.
I'll fix that in the next step.

I also removed the check for whether an update is batched. It shouldn't
matter, because even a batched update can spawn asynchronous work, which
needs to be flushed by act.

This change only affects concurrent roots. The behavior in legacy roots
is the same.

* Expand act warning to include Suspense resolutions

For the same reason we warn when an update is not wrapped with act,
we should warn if a Suspense promise resolution is not wrapped with act.
Both "pings" and "retries".

Legacy root behavior is unchanged.
2021-10-21 15:31:26 -07:00
Joseph Savona
fa9bea0c41 Initial implementation of cache cleanup (#22510)
This is an initial, partial implementation of a cleanup mechanism for the experimental Cache API. The idea is that consumers of the Cache API can register to be informed when a given Cache instance is no longer needed so that they can perform associated cleanup tasks to free resources stored in the cache. A canonical example would be cancelling pending network requests.

An overview of the high-level changes:

* Changes the `Cache` type from a Map of cache instances to be an object with the original Map of instances, a reference count (to count roughly "active references" to the cache instances - more below), and an AbortController.
* Adds a new public API, `unstable_getCacheSignal(): AbortSignal`, which is callable during render. It returns an AbortSignal tied to the lifetime of the cache - developers can listen for the 'abort' event on the signal, which React now triggers when a given cache instance is no longer referenced. 
  * Note that `AbortSignal` is a web standard that is supported by other platform APIs; for example a signal can be passed to `fetch()` to trigger cancellation of an HTTP request.
* Implements the above - triggering the 'abort' event - by handling passive mount/unmount for HostRoot and CacheComponent fiber nodes.

Cases handled:
* Aborted transitions: we clean up a new cache created for an aborted transition
* Suspense: we retain a fresh cache instance until a suspended tree resolves

For follow-ups:
* When a subsequent cache refresh is issued before a previous refresh completes, the refreshes are queued. Fresh cache instances for previous refreshes in the queue should be cleared, retaining only the most recent cache. I plan to address this in a follow-up PR.
* If a refresh is cancelled, the fresh cache should be cleaned up.
2021-10-21 14:11:42 -07:00
Brian Vaughn
bfb40225b5 Scheduling Profiler does not warn about long transitions (#22614) 2021-10-21 15:16:26 -04:00
Brian Vaughn
0e8a5aff3d Scheduling Profiler: Add marks for component effects (mount and unmount) (#22578)
DevTools (and its profilers) should not require users to be familiar with React internals. Although the scheduling profiler includes a CPU sample flame graph, it's there for advanced use cases and shouldn't be required to identify common performance issues.

This PR proposes adding new marks around component effects. This will enable users to identify components with slow effect create/destroy functions without requiring them to dig through the call stack. (Once #22529 lands, these new marks will also include component stacks, making them more useful still.)

For example, here's a profile with a long-running effect. Without this change, it's not clear why the effects phase takes so long. After this change, it's more clear why that the phase is longer because of a specific component.

We may consider adding similar marks around render phase hooks like useState, useReducer, useMemo. I avoided doing that in this PR because it would be a pretty pervasive change to the ReactFiberHooks file.

Note that this change should have no effect on production bundles since everything is guarded behind a profiling feature flag.

Going to tag more people than I normally would for this pR, since it touches both reconciler and DevTools packages. Feel free to ignore though if you don't have strong feelings.

Note that although this PR adds new marks to the scheduling profiler, it's done in a way that's backwards compatible for older profiles.
2021-10-21 14:41:44 -04:00
Brian Vaughn
4ba20579da Scheduling Profiler: De-emphasize React internal frames (#22588)
This commit adds code to all React bundles to explicitly register the beginning and ending of the module. This is done by creating Error objects (which capture the file name, line number, and column number) and passing them explicitly to a DevTools hook (when present).

Next, as the Scheduling Profiler logs metadata to the User Timing API, it prints these module ranges along with other metadata (like Lane values and profiler version number).

Lastly, the Scheduling Profiler UI compares stack frames to these ranges when drawing the flame graph and dims or de-emphasizes frames that fall within an internal module.

The net effect of this is that user code (and 3rd party code) stands out clearly in the flame graph while React internal modules are dimmed.

Internal module ranges are completely optional. Older profiling samples, or ones recorded without the React DevTools extension installed, will simply not dim the internal frames.
2021-10-21 14:40:41 -04:00
Konstantin Popov
f6abf4b400 Fix typos (#22494) 2021-10-20 23:22:41 -04:00
Juan
c213030b49 React DevTools 4.20.1 -> 4.20.2 (#22605) 2021-10-20 16:00:13 -04:00
Juan
5ca4b04332 Dev Tools: Relax constraint on passing extensionId for backend init (#22597) 2021-10-20 09:50:26 -04:00
Sebastian Markbåge
cdb8a1d19d [Fizz] Add option to inject bootstrapping script tags after the shell is injected (#22594)
* Add option to inject bootstrap scripts

These are emitted right after the shell as flushed.

* Update ssr fixtures to use bootstrapScripts instead of manual script tag

* Add option to FB renderer too
2021-10-19 19:36:10 -07:00
Sebastian Markbåge
3677c019af Support nonce option to be passed to inline scripts (#22593) 2021-10-19 18:14:26 -07:00
Sebastian Markbåge
34e4c97561 Clear extra nodes if there's a hydration mismatch within a suspense boundary (#22592)
* Clear extra nodes if there's a mismatch within a suspense boundary

This usually happens when we exit out a DOM node but a suspense boundary
is a virtual DOM node and we didn't do it in that case because we took a
short cut by calling resetHydrationState directly since we know we won't
need to pop.

* Tighten up the types of getFirstHydratableChild

We currently call getFirstHydratableChild to step into the children of
a suspense boundary. This can be a text node or a suspense boundary
which isn't compatible with getFirstHydratableChild, and we cheat the type.

This accidentally works because .firstChild always returns null on those
nodes in the DOM.

This just makes that explicit.
2021-10-19 16:28:01 -07:00
Juan
fe0356ce2b DevTools: Fix passing extensionId in evaled postMessage calls (#22590) 2021-10-19 17:43:59 -04:00
Andrew Clark
02f411578a Upgrade useInsertionEffect to stable (#22589)
@huozhi tried this out and says it's working as expected. I think we
can go ahead and move this into the stable channel, so that it is
available in the React 18 alpha releases.
2021-10-19 14:32:54 -07:00
Juan
b81de86332 React DevTools 4.20.0 -> 4.20.1 (#22583) 2021-10-19 10:55:39 -04:00
Juan
5b9d000c8a DevTools: Include Edge in browser name detection (#22584) 2021-10-19 09:52:55 -04:00
Sebastian Markbåge
2af4a79333 Hydrate using SuspenseComponent as the parent (#22582)
* Add a failing test for Suspense hydration

* Include salazarm's changes to the test

* The hydration parent of a suspense boundary should be the boundary itself

This eventually got set when we popped back out of its children but it
doesn't start out that way.

This fixes it so that the boundary parent is always the suspense boundary.

* We now need to log errors with a suspense boundary as a parent

For now, we just log this with commentNode.parentNode as the parent for
purposes of the error message.

* Make a special getFirstHydratableChildWithinSuspenseInstance

We currently call getNextHydratableSibling but conceptually it's the child
of the boundary. It just happens to be that when we use comment nodes, we
need to call nextSibling in the DOM.

This makes this separation a bit clearer.

* Sync old fork

Co-authored-by: Dan Abramov <dan.abramov@me.com>
2021-10-18 17:44:34 -07:00
Joseph Savona
b1acff0cc2 Enable cache in test renderer (#22580) 2021-10-18 16:23:43 -07:00
Andrew Clark
996da67b29 Replace global jest heuristic with IS_REACT_ACT_ENVIRONMENT (#22562)
* Remove `jest` global check in concurrent roots

In concurrent mode, instead of checking `jest`, we check the new
`IS_REACT_ACT_ENVIRONMENT` global. The default behavior is `false`.

Legacy mode behavior is unchanged.

React's own internal test suite use a custom version of `act` that works
by mocking the Scheduler — rather than the "real" act used publicly. So
we don't enable the flag in our repo.

* Warn if `act` is called in wrong environment

Adds a warning if `act` is called but `IS_REACT_ACT_ENVIRONMENT` is not
enabled. The goal is to prompt users to correctly configure their
testing environment, so that if they forget to use `act` in a different
test, we can detect and warn about.

It's expected that the environment flag will be configured by the
testing framework. For example, a Jest plugin. We will link to the
relevant documentation page, once it exists.

The warning only fires in concurrent mode. Legacy roots will keep the
existing behavior.
2021-10-18 08:59:18 -07:00
Andrew Clark
163e81c1f8 Support disabling spurious act warnings with a global environment flag (#22561)
* Extract `act` environment check into function

`act` checks the environment to determine whether to fire a warning.
We're changing how this check works in React 18. As a first step, this
refactors the logic into a single function. No behavior changes yet.

* Use IS_REACT_ACT_ENVIRONMENT to disable warnings

If `IS_REACT_ACT_ENVIRONMENT` is set to `false`, we will suppress
any `act` warnings. Otherwise, the behavior of `act` is the same as in
React 17: if `jest` is defined, it warns.

In concurrent mode, the plan is to remove the `jest` check and only warn
if `IS_REACT_ACT_ENVIRONMENT` is true. I have not implemented that
part yet.
2021-10-18 08:27:26 -07:00
Juan
b72dc8e930 Only show DevTools warning about unrecognized build in Chrome (#22571) 2021-10-15 17:18:20 -04:00
Juan
e5f486b5a8 React DevTools 4.19.2 -> 4.20.2 (#22569) 2021-10-15 12:50:17 -04:00
Juan
1def0a4244 DevTools prepare release script resets patch version when bumping minor (#22568) 2021-10-15 12:50:00 -04:00
Juan
930c9e7eeb Show warning in UI when duplicate installations of DevTools extension are detected (#22563) 2021-10-15 11:27:13 -04:00
Gabriel Trompiz
9d3d03025c Reattachment of the splash page event listeners (#22558) (#22560) 2021-10-15 09:16:43 -04:00
Brian Vaughn
23b7dfeff3 Enable scheduling profiler for RN FB profiling builds (#22566) 2021-10-15 08:03:18 -04:00
Juan
545d4c2de7 Prevent errors/crashing when multiple installs of DevTools are present (#22517)
## Summary

This commit is a proposal for handling duplicate installation of DevTools, in particular scoped to duplicates such as a dev build or the internal versions of DevTools installed alongside the Chrome Web Store extension.

Specifically, this commit makes it so when another instance of the DevTools extension is installed alongside the extension installed from the Chrome Web Store, we don't produce a stream of errors or crash Chrome, which is what would usually happen in this case. 


### Detecting Duplicate Installations

- First, we check what type of installation the extension is: from the Chrome Web Store, the internal build of the extension, or a local development build.
- If the extension is from the **Chrome Web Store**:
  - During initialization, we first check if the internal or local builds of the extension have already been installed and are enabled. To do this, we send a [cross-extension message](https://developer.chrome.com/docs/extensions/mv3/messaging/#external) to the internal and local builds of the extension using their extension IDs.  
    - We can do this because the extension ID for the internal build (and for the Chrome Web Store) is a stable ID.
    - For the local build, at build time we hardcode a [`key` in the `manifest.json`](https://developer.chrome.com/docs/extensions/mv2/manifest/key/) which allows us to have a stable ID even for local builds.
  - If we detect that the internal or local extensions are already installed, then we skip initializing the current extension altogether so as to not conflict with the other versions. This means we don't initialize the frontend or the backend at all.
- If the extension is the **Internal Build**:
  - During initialization, we first check if the local builds of the extension has already been installed and is enabled. To do this, we send a [cross-extension message](https://developer.chrome.com/docs/extensions/mv3/messaging/#external) to the local build of the extension using its extension ID.  
    - We can do this for the local build because at build time we hardcode a [`key` in the `manifest.json`](https://developer.chrome.com/docs/extensions/mv2/manifest/key/) which allows us to have a stable ID even for local builds.
  - If we detect that the local extension is already installed, then we skip initializing the current extension altogether so as to not conflict with the that  version. This means we don't initialize the frontend or the backend at all.
- If the extension is a **Local Dev Build**:
  - Since other extensions check for the existence of this extension and disable themselves if they detect it, we don't need any special handling during initialization and assume that there are no duplicate extensions. This means that we will generally prefer keeping this extension enabled.

This behavior means that the order of priority for keeping an extension enabled is the following:

1. Local build
2. Internal build
3. Public build


### Preventing duplicate backend initialization

Note that the backend is injected and initialized by the content script listening to a message posted to the inspected window (via `postMessage`). Since the content script will be injected twice, once each by each instance of the extension, even if we initialize the extension once, both content scripts would still receive the single message posted from the single frontend, and it would then still inject and initialize the backend twice. 

In order to prevent this, we also add the extension ID to the message for injecting the backend. That way each content script can check if the message comes from its own extension, and if not it can ignore the message and avoid double injecting the backend.
  
### Other approaches

- I considered using the [`chrome.management`](https://developer.chrome.com/docs/extensions/reference/management/) API generally to detect other installations, but that requires adding additional permissions to our production extension, which didn't seem ideal.
- I also considered a few options of writing a special flag to the inspected window and checking for it before initializing the extension. However, it's hard to avoid race conditions in that case, and it seemed more reliable to check specifically for the WebStore extension, which is realistically where we would encounter the overlap.
  
### Rollout

- This commit needs to be published and rolled out to the Chrome Web Store first.
- After this commit is published to the Chrome Web Store, any duplicate instances of the extension that are built and installed after this commit will no longer conflict with the Chrome Web Store version.
  
### Next Steps

- In a subsequent PR, I will extend this code to show a warning when duplicate extensions have been detected.

Part of #22486

## How did you test this change?

### Basic Testing

- yarn flow
- yarn test
- yarn test-build-devtools

### Double installation testing

Testing double-installed extensions for this commit is tricky because we are relying on the extension ID of the internal and Chrome Web Store extensions, but we obviously can't actually test the Web Store version (since we can't modify the already published version).

In order to simulate duplicate extensions installed, I did the following process:

- Built separate extensions where I hardcoded a constant for whether the extension is internal or public (e.g. `EXTENSION_INSTALLATION_TYPE = 'internal'`). Then I installed these built extensions corresponding to the "internal" and "Web Store" builds.
- Build and run the regular development extension (with `yarn build:chrome:dev && yarn test:chrome`), using the extension IDs of the previously built extensions as the "internal" and "public" extension IDs.

With this set up in place, I tested the following on pages both with and without React:

- When only the local extension enabled, DevTools works normally.
- When only the "internal" extension enabled, DevTools works normally.
- When only the "public" extension enabled, DevTools works normally.
- When "internal" and "public" extensions are installed, "public" extension is disabled and "internal" extension works normally.
- When the local extension runs alongside the other extensions, other extensions disable themselves and local build works normally.
- When we can't recognize what type of build the extension corresponds to, we show an error.
- When all 3 extensions are installed and enabled in all different combinations, DevTools no longer produces errors or crashes Chrome, and works normally.
2021-10-14 17:15:31 -04:00
Abhay Gupta
c3a19e5af0 Improved Workers filenames in devtools-core (#22559) 2021-10-14 10:54:06 -04:00
Gabriel Trompiz
a45533cc25 Allow to use the Profiler when no client is connected in standalone DevTools (#22551) 2021-10-14 08:31:45 -04:00
Joseph Savona
61455a25b7 Enable experimental Cache API in www TestRenderer (#22554) 2021-10-13 16:39:29 -07:00
Andrew Clark
7142d110b0 Bugfix: Nested useOpaqueIdentifier references (#22553)
* Handle render phase updates explicitly

We fire a warning in development if a component is updated during
the render phase (with the exception of local hook updates, which have
their own defined behavior).

Because it's not a supported React pattern, we don't have that many
tests that trigger this path. But it is meant to have reasonable
semantics when it does happen, so that if it accidentally ships to
production, the app doesn't crash unnecessarily. The behavior is not
super well-defined, though.

There are also some _internal_ React implementation details that
intentionally to rely on this behavior. Most prominently, selective
hydration and useOpaqueIdentifier.

I need to tweak the behavior of render phase updates slightly as part
of a fix for useOpaqueIdentifier. This shouldn't cause a user-facing
change in behavior outside of useOpaqueIdentifier, but it does require
that we explicitly model render phase updates.

* Bugfix: Nested useOpaqueIdentifier calls

Fixes an issue where multiple useOpaqueIdentifier hooks are upgraded
to client ids within the same render.

The way the upgrade works is that useOpaqueIdentifier schedules a
render phase update then throws an error to trigger React's error
recovery mechanism.

The normal error recovery mechanism is designed for errors that occur
as a result of interleaved mutations, so we usually only retry a single
time, synchronously, before giving up.

useOpaqueIdentifier is different because the error its throws when
upgrading is not caused by an interleaved mutation. Rather, it happens
when an ID is referenced for the first time inside a client-rendered
tree (i.e. sommething that wasn't part of the initial server render).
The fact that it relies on the error recovery mechanism is an
implementation detail. And a single recovery attempt may be
insufficient. For example, if a parent and a child component may
reference different ids, and both are mounted as a result of the same
client update, that will trigger two separate error recovery attempts.

Because render phase updates are not allowed when triggered from
userspace — we log a warning in developement to prevent them —
we can assume that if something does update during the render phase, it
is one of our "legit" implementation details like useOpaqueIdentifier.
So we can keep retrying until we succeed — up to a limit, to protect
against inifite loops. I chose 50 since that's the limit we use for
commit phase updates.
2021-10-13 15:44:36 -07:00
Brian Vaughn
8ee4ff8836 Surface backend errors during inspection in the frontend UI (#22546) 2021-10-13 10:35:21 -04:00
Brian Vaughn
1e247ff892 Enabled scheduling profiler marks for React Native FB target (#22544) 2021-10-12 11:04:10 -04:00
Brian Vaughn
c16b005f2d Update test and stack frame code to support newer V8 stack formats (#22477) 2021-10-11 18:40:42 -04:00
BIKI DAS
55d75005bc duplicate value in variable (#22390) 2021-10-11 09:20:15 -04:00
Juan
afcb9cdc93 [DevTools] Update Fiber logic in backend renderer to match implementation in React (#22527)
* [DevTools] Update isMountedImpl to match implementation in React

* Also sync findCurrentFiberUsingSlowPathById
2021-10-08 16:19:54 -04:00
Brian Vaughn
20ca9b565a React DevTools 4.19.1 -> 4.19.2 2021-10-08 13:51:25 -04:00
Juan
5fa4d79b00 [DevTools] Register logger for standalone DevTools (#22524) 2021-10-08 08:38:11 -04:00
Abhay Gupta
784a725fe1 Added Devtools Extension link for Microsoft Edge (#22515) 2021-10-07 18:52:08 -04:00
salazarm
6ecad79ccf Test that discrete events that aren't hydratable do not propagate (#22502)
* test that discrete events that arent hydratable do not propagate

* lint

* feedback

* feedback

* lint

* better test

* nits

* lint
2021-10-06 08:31:21 -04:00
Sebastian Markbåge
579c008a75 [Fizz/Flight] pipeToNodeWritable(..., writable).startWriting() -> renderToPipeableStream(...).pipe(writable) (#22450)
* Rename pipeToNodeWritable to renderToNodePipe

* Add startWriting API to Flight

We don't really need it in this case because there's way less reason to
delay the stream in Flight.

* Pass the destination to startWriting instead of renderToNode

* Rename startWriting to pipe

This mirrors the ReadableStream API in Node

* Error codes

* Rename to renderToPipeableStream

This mimics the renderToReadableStream API for the browser.
2021-10-06 00:31:06 -04:00
Sebastian Markbåge
6485ef7472 Remove duplicate error code (#22513) 2021-10-05 19:59:46 -07:00
Brian Vaughn
cadf94df1f Add new Jest --compact-console flag for DevTools tests (#22495) 2021-10-05 11:58:54 -04:00
Daishi Kato
f2c381131f fix: useSyncExternalStoreExtra (#22500)
* move setting memoizedSnapshot

* Revert "move setting memoizedSnapshot"

This reverts commit f01320689cebfcbc4f3a53208f879ed4a8d6613d.

* add failed tests

* Revert "Revert "move setting memoizedSnapshot""

This reverts commit cb43c4fdc6b0dcab3480f27d6fbbb3137dbc47bb.
2021-10-04 07:39:51 -07:00
salazarm
0ecbbe1422 Sync hydrate discrete events in capture phase and dont replay discrete events (#22448) 2021-10-04 09:54:33 -04:00
BIKI DAS
a4bc8ae4c1 Reopen #22481 Fixed modal closing issue (#22484)
Co-authored-by: Brian Vaughn <brian.david.vaughn@gmail.com>
2021-10-02 10:26:15 -04:00
Brian Vaughn
5f3b376c56 Show different error boundary UI for timeouts than normal errors (#22483) 2021-10-01 15:03:36 -04:00
Brian Vaughn
bdd6d5064d React DevTools 4.19.0 -> 4.19.1 (#22480) 2021-10-01 11:50:05 -04:00
Juan
2825a08dc0 [DevTools] Log basic usage events (#22478) 2021-09-30 17:19:07 -04:00
Andrew Clark
a724a3b578 [RFC] Codemod invariant -> throw new Error (#22435)
* Hoist error codes import to module scope

When this code was written, the error codes map (`codes.json`) was
created on-the-fly, so we had to lazily require from inside the visitor.

Because `codes.json` is now checked into source, we can import it a
single time in module scope.

* Minify error constructors in production

We use a script to minify our error messages in production. Each message
is assigned an error code, defined in `scripts/error-codes/codes.json`.
Then our build script replaces the messages with a link to our
error decoder page, e.g. https://reactjs.org/docs/error-decoder.html/?invariant=92

This enables us to write helpful error messages without increasing the
bundle size.

Right now, the script only works for `invariant` calls. It does not work
if you throw an Error object. This is an old Facebookism that we don't
really need, other than the fact that our error minification script
relies on it.

So, I've updated the script to minify error constructors, too:

Input:
  Error(`A ${adj} message that contains ${noun}`);
Output:
  Error(formatProdErrorMessage(ERR_CODE, adj, noun));

It only works for constructors that are literally named Error, though we
could add support for other names, too.

As a next step, I will add a lint rule to enforce that errors written
this way must have a corresponding error code.

* Minify "no fallback UI specified" error in prod

This error message wasn't being minified because it doesn't use
invariant. The reason it didn't use invariant is because this particular
error is created without begin thrown — it doesn't need to be thrown
because it's located inside the error handling part of the runtime.

Now that the error minification script supports Error constructors, we
can minify it by assigning it a production error code in
`scripts/error-codes/codes.json`.

To support the use of Error constructors more generally, I will add a
lint rule that enforces each message has a corresponding error code.

* Lint rule to detect unminified errors

Adds a lint rule that detects when an Error constructor is used without
a corresponding production error code.

We already have this for `invariant`, but not for regular errors, i.e.
`throw new Error(msg)`. There's also nothing that enforces the use of
`invariant` besides convention.

There are some packages where we don't care to minify errors. These are
packages that run in environments where bundle size is not a concern,
like react-pg. I added an override in the ESLint config to ignore these.

* Temporarily add invariant codemod script

I'm adding this codemod to the repo temporarily, but I'll revert it
in the same PR. That way we don't have to check it in but it's still
accessible (via the PR) if we need it later.

* [Automated] Codemod invariant -> Error

This commit contains only automated changes:

npx jscodeshift -t scripts/codemod-invariant.js packages --ignore-pattern="node_modules/**/*"
yarn linc --fix
yarn prettier

I will do any manual touch ups in separate commits so they're easier
to review.

* Remove temporary codemod script

This reverts the codemod script and ESLint config I added temporarily
in order to perform the invariant codemod.

* Manual touch ups

A few manual changes I made after the codemod ran.

* Enable error code transform per package

Currently we're not consistent about which packages should have their
errors minified in production and which ones should.

This adds a field to the bundle configuration to control whether to
apply the transform. We should decide what the criteria is going
forward. I think it's probably a good idea to minify any package that
gets sent over the network. So yes to modules that run in the browser,
and no to modules that run on the server and during development only.
2021-09-30 12:01:28 -07:00
Juan
f5d946da6b [DevTools] Enable logger for internal build of DevTools extensions (#22476) 2021-09-30 14:13:13 -04:00
Juan
75b9869648 [DevTools] Extension reports logged events when feature flag is enabled (#22475) 2021-09-30 13:47:14 -04:00
Brian Vaughn
47177247f8 DevTools: Fixed potential cache miss when insepcting elements (#22472) 2021-09-30 12:48:53 -04:00
Andrew Clark
7d38e4fd89 CodeSandbox CI: Fall back to local build (#22473)
The `download-experimental-build` script has been flaky on CodeSandbox
CI, I think because of GitHub rate limiting.

Until we figure out how to fix that, I've updated it to fall back to a
local build.
2021-09-30 08:12:25 -07:00
Ay-Ay-Ron
ec4ac97500 Fixed Link on Documentation (#22465) 2021-09-30 09:58:01 -04:00
Joseph Savona
201af81b01 Release pooled cache reference in complete/unwind (#22464) 2021-09-29 18:49:52 -04:00
Juan
95ecd4a2c3 [DevTools] Commands for internal builds all follow :fb convention (#22463) 2021-09-29 17:46:34 -04:00
Luna Ruan
0883c4cd3a React DevTools 4.18.0 -> 4.19.0 (#22461) 2021-09-29 12:06:13 -04:00
salazarm
033efe7312 Call get snapshot in useSyncExternalStore server shim (#22453)
* Call getSnapshot in shim

* just change useSyncExternalStoreServer

* remove builtInAPI Check in useSyncExternalStoreClient
2021-09-28 21:32:57 -04:00
Sebastian Markbåge
7843b142ac [Fizz/Flight] Pass in Destination lazily to startFlowing instead of in createRequest (#22449)
* Pass in Destination lazily in startFlowing instead of createRequest

* Delay fatal errors until we have a destination to forward them to

* Flow can now be inferred by whether there's a destination set

We can drop the destination when we're not flowing since there's nothing to
write to.

Fatal errors now close once flowing starts back up again.

* Defer fatal errors in Flight too
2021-09-28 15:32:09 -07:00
Andrew Clark
d9fb383d6f Extract queueing logic into shared functions (#22452)
As a follow up to #22445, this extracts the queueing logic that is
shared between `dispatchSetState` and `dispatchReducerAction` into
separate functions. It likely doesn't save any bytes since these will
get inlined, anyway, but it does make the flow a bit easier to follow.
2021-09-28 12:05:44 -07:00
Brian Vaughn
9175f4d15e Scheduling Profiler: Show Suspense resource .displayName (#22451) 2021-09-28 11:29:33 -04:00
Sebastian Markbåge
eba248c390 [Fizz/Flight] Remove reentrancy hack (#22446)
* Remove reentrant check from Fizz/Flight

* Make startFlowing explicit in Flight

This is already an explicit call in Fizz. This moves flowing to be explicit.

That way we can avoid calling it in start() for web streams and therefore
avoid the reentrant call.

* Add regression test

This test doesn't actually error due to the streams polyfill not behaving
like Chrome but rather according to spec.

* Update the Web Streams polyfill

Not that we need this but just in case there are differences that are fixed.
2021-09-27 17:47:56 -07:00
Joseph Savona
66388150ef Remove usereducer eager bailout (#22445)
* Fork dispatchAction for useState/useReducer

* Remove eager bailout from forked dispatchReducerAction, update tests

* Update eager reducer/state logic to handle state case only

* sync reconciler fork

* rename test

* test cases from #15198

* comments on new test cases

* comments on new test cases

* test case from #21419

* minor tweak to test name to kick CI
2021-09-27 16:25:10 -07:00
Behnam Mohammadi
8131de13e2 prevent unused exec getCurrentValue after re-render (#22442) 2021-09-27 17:20:32 -04:00
Behnam Mohammadi
580e2f56d5 Add isArray in devTools utils (#22438) 2021-09-27 17:17:30 -04:00
Andrew Clark
d3e0869324 Make root.unmount() synchronous (#22444)
* Move flushSync warning to React DOM

When you call in `flushSync` from an effect, React fires a warning. I've
moved the implementation of this warning out of the reconciler and into
React DOM.

`flushSync` is a renderer API, not an isomorphic API, because it has
behavior that was designed specifically for the constraints of React
DOM. The equivalent API in a different renderer may not be the same.
For example, React Native has a different threading model than the
browser, so it might not make sense to expose a `flushSync` API to the
JavaScript thread.

* Make root.unmount() synchronous

When you unmount a root, the internal state that React stores on the
DOM node is immediately cleared. So, we should also synchronously
delete the React tree. You should be able to create a new root using
the same container.
2021-09-27 14:04:39 -07:00
Sebastian Markbåge
2cc6d79c98 Rename onReadyToStream to onCompleteShell (#22443) 2021-09-27 12:38:22 -07:00
Brian Vaughn
2e41568313 DevTools encoding supports multibyte characters (e.g. "🟩") (#22424)
Changes our text encoding approach to properly support multibyte characters following this algorithm. Based on benchmarking, this new approach is roughly equivalent in terms of performance (sometimes slightly faster, sometimes slightly slower).

I also considered using TextEncoder/TextDecoder for this, but it was much slower (~85%).
2021-09-27 13:34:39 -04:00
Justin Grant
c88fb49d37 Improve DEV errors if string coercion throws (Temporal.*, Symbol, etc.) (#22064)
* Revise ESLint rules for string coercion

Currently, react uses `'' + value` to coerce mixed values to strings.
This code will throw for Temporal objects or symbols.

To make string-coercion safer and to improve user-facing error messages,
This commit adds a new ESLint rule called `safe-string-coercion`.

This rule has two modes: a production mode and a non-production mode.
* If the `isProductionUserAppCode` option is true, then `'' + value`
  coercions are allowed (because they're faster, although they may
  throw) and `String(value)` coercions are disallowed. Exception:
  when building error messages or running DEV-only code in prod
  files, `String()` should be used because it won't throw.
* If the `isProductionUserAppCode` option is false, then `'' + value`
  coercions are disallowed (because they may throw, and in non-prod
  code it's not worth the risk) and `String(value)` are allowed.

Production mode is used for all files which will be bundled with
developers' userland apps. Non-prod mode is used for all other React
code: tests, DEV blocks, devtools extension, etc.

In production mode, in addiiton to flagging `String(value)` calls,
the rule will also flag `'' + value` or `value + ''` coercions that may
throw. The rule is smart enough to silence itself in the following
"will never throw" cases:
* When the coercion is wrapped in a `typeof` test that restricts to safe
  (non-symbol, non-object) types. Example:
    if (typeof value === 'string' || typeof value === 'number') {
      thisWontReport('' + value);
    }
* When what's being coerced is a unary function result, because unary
   functions never return an object or a symbol.
* When the coerced value is a commonly-used numeric identifier:
  `i`, `idx`, or `lineNumber`.
* When the statement immeidately before the coercion is a DEV-only
  call to a function from shared/CheckStringCoercion.js. This call is a
  no-op in production, but in DEV it will show a console error
  explaining the problem, then will throw right after a long explanatory
  code comment so that debugger users will have an idea what's going on.
  The check function call must be in the following format:
    if (__DEV__) {
      checkXxxxxStringCoercion(value);
    };

Manually disabling the rule is usually not necessary because almost all
prod use of the `'' + value` pattern falls into one of the categories
above. But in the rare cases where the rule isn't smart enough to detect
safe usage (e.g. when a coercion is inside a nested ternary operator),
manually disabling the rule will be needed.

The rule should also be manually disabled in prod error handling code
where `String(value)` should be used for coercions, because it'd be
bad to throw while building an error message or stack trace!

The prod and non-prod modes have differentiated error messages to
explain how to do a proper coercion in that mode.

If a production check call is needed but is missing or incorrect
(e.g. not in a DEV block or not immediately before the coercion), then
a context-sensitive error message will be reported so that developers
can figure out what's wrong and how to fix the problem.

Because string coercions are now handled by the `safe-string-coercion`
rule, the `no-primitive-constructor` rule no longer flags `String()`
usage. It still flags `new String(value)` because that usage is almost
always a bug.

* Add DEV-only string coercion check functions

This commit adds DEV-only functions to check whether coercing
values to strings using the `'' + value` pattern will throw. If it will
throw, these functions will:
1. Display a console error with a friendly error message describing
   the problem and the developer can fix it.
2. Perform the coercion, which will throw. Right before the line where
   the throwing happens, there's a long code comment that will help
   debugger users (or others looking at the exception call stack) figure
   out what happened and how to fix the problem.

One of these check functions should be called before all string coercion
of user-provided values, except when the the coercion is guaranteed not
to throw, e.g.
* if inside a typeof check like `if (typeof value === 'string')`
* if coercing the result of a unary function like `+value` or `value++`
* if coercing a variable named in a whitelist of numeric identifiers:
  `i`, `idx`, or `lineNumber`.

The new `safe-string-coercion` internal ESLint rule enforces that
these check functions are called when they are required.

Only use these check functions in production code that will be bundled
with user apps.  For non-prod code (and for production error-handling
code), use `String(value)` instead which may be a little slower but will
never throw.

* Add failing tests for string coercion

Added failing tests to verify:
* That input, select, and textarea elements with value and defaultValue
  set to Temporal-like objects which will throw when coerced to string
  using the `'' + value` pattern.
* That text elements will throw for Temporal-like objects
* That dangerouslySetInnerHTML will *not* throw for Temporal-like
  objects because this value is not cast to a string before passing to
  the DOM.
* That keys that are Temporal-like objects will throw

All tests above validate the friendly error messages thrown.

* Use `String(value)` for coercion in non-prod files

This commit switches non-production code from `'' + value` (which
throws for Temporal objects and symbols) to instead use `String(value)`
which won't throw for these or other future plus-phobic types.

"Non-produciton code" includes anything not bundled into user apps:
* Tests and test utilities. Note that I didn't change legacy React
  test fixtures because I assumed it was good for those files to
  act just like old React, including coercion behavior.
* Build scripts
* Dev tools package - In addition to switching to `String`, I also
  removed special-case code for coercing symbols which is now
  unnecessary.

* Add DEV-only string coercion checks to prod files

This commit adds DEV-only function calls to to check if string coercion
using `'' + value` will throw, which it will if the value is a Temporal
object or a symbol because those types can't be added with `+`.

If it will throw, then in DEV these checks will show a console error
to help the user undertsand what went wrong and how to fix the
problem. After emitting the console error, the check functions will
retry the coercion which will throw with a call stack that's easy (or
at least easier!) to troubleshoot because the exception happens right
after a long comment explaining the issue. So whether the user is in
a debugger, looking at the browser console, or viewing the in-browser
DEV call stack, it should be easy to understand and fix the problem.

In most cases, the safe-string-coercion ESLint rule is smart enough to
detect when a coercion is safe. But in rare cases (e.g. when a coercion
is inside a ternary) this rule will have to be manually disabled.

This commit also switches error-handling code to use `String(value)`
for coercion, because it's bad to crash when you're trying to build
an error message or a call stack!  Because `String()` is usually
disallowed by the `safe-string-coercion` ESLint rule in production
code, the rule must be disabled when `String()` is used.
2021-09-27 10:05:07 -07:00
Andrew Clark
05726d72cc [Fix] Errors should not "unsuspend" a transition (#22423)
If an error is thrown during a transition where we would have otherwise
suspended without showing a fallback (i.e. during a refresh), we should
still suspend.

The current behavior is that the error will force the fallback to
appear, even if it's completely unrelated to the component that errored,
which breaks the contract of `startTransition`.
2021-09-27 08:44:39 -07:00
Behnam Mohammadi
c9d64e5f4c add hasOwnProperty to devTools backend (#22437) 2021-09-27 08:56:56 -04:00
BIKI DAS
3746eaf985 Packages/React/src/ReactLazy ---> changing -1 to unintialized (#22421) 2021-09-24 13:52:21 -04:00
Andrew Clark
04ccc01d96 Hydration errors should force a client render (#22416)
* Refactor throwException control flow

I'm about to add more branches to the Suspense-related logic in
`throwException`, so before I do, I split some of the steps into
separate functions so that later I can use them in multiple places.

This commit does not change any program behavior, only the control flow
surrounding existing code.

* Hydration errors should force a client render

If something errors during hydration, we should try rendering again
without hydrating.

We'll find the nearest Suspense boundary and force it to client render,
discarding the server-rendered content.
2021-09-24 10:47:19 -07:00
Andrew Clark
029fdcebbf root.hydrate -> root.isDehydrated (#22420)
I think this naming is a bit clearer. It means the root is currently
showing server rendered content that needs to be hydrated.

A dehydrated root is conceptually the same as what we call dehydrated
Suspense boundary, so this makes the naming of the root align with the
naming of subtrees.
2021-09-24 10:45:46 -07:00
Brian Vaughn
1c73ceed5f Scheduling Profiler marks should include thrown Errors (#22419) 2021-09-24 12:56:27 -04:00
Brian Vaughn
af87f5a83d Scheduling Profiler marks should include thrown Errors (#22417)
The scheduling profiler markComponentRenderStopped method is supposed to be called when rendering finishes or when a value is thrown (Suspense or Error). Previously we were calling this in a Suspense-only path of `throwException`.

This PR updates the code to handle errors (or non-Thenables) thrown as well.

It also moves the mark logic the work loop `handleError` method, with Suspense/Error agnostic cleanup.
2021-09-24 12:32:37 -04:00
Brian Vaughn
b1a1cb1168 DevTools: Lazily parse indexed map sections (#22415)
Indexed maps divide nested source maps into sections, annotated with a line and column offset. Since these sections are JSON and can be quickly parsed, we can easily separate them without doing the heavier base64 and VLQ decoding process. This PR updates our sourcemap parsing code to defer parsing of an indexed map section until we actually need to retrieve mappings from it.
2021-09-24 11:09:42 -04:00
Brian Vaughn
a01cdbf813 Update Yarn build-for-devtools script to account for build/build2 changes (#22418) 2021-09-24 10:54:57 -04:00
Sebastian Markbåge
d47339ea36 [Fizz] Remove assignID mechanism (#22410)
* Remove pushEmpty

This is only used to support the assignID mechanism.

* Remove assignID mechanism

This effectively isn't used anyway because we always insert a dummy tag
into the fallback.

* Emit the template tag with an ID directly in pending boundaries

This ensures that assigning the ID is deterministic since it's done during
writing.

This also avoids emitting it for client rendered boundaries that start as
client rendered since we never need to refer to them.

* Move lazy ID initialization to the core implementation

We never need an ID before we write a pending boundary. This also ensures
that ID generation is deterministic by moving it to the write phase.

* Simplify the inserted scripts

We can assume that there are no text nodes before the template tag so this
simplifies the script that finds the comment node. It should be the direct
previous child.
2021-09-24 10:22:02 -04:00
Damian Cyntler
1c58cfab95 Update Node.js to latest v14.17.6 LTS (#22401) 2021-09-24 00:30:12 +01:00
Andrew Clark
3a50d95573 Never attach ping listeners in legacy Suspense (#22407)
I noticed a weird branch where we attach a ping listener even in legacy
mode. It's weird because this shouldn't be necessary. Fallbacks always
synchronously commit in legacy mode, so pings never happen. (A "ping" is
when a suspended promise resolves before the fallback has committed.)

It took me a moment to remember why this case exists, but it's related
to React.lazy.

There's a special case where we suspend while reconciling the children
of a Suspense boundary's inner Offscreen wrapper fiber. This happens
when a React.lazy component is a direct child of a Suspense boundary.

Suspense boundaries are implemented as multiple fibers, but they are a
single conceptual unit. The legacy mode behavior where we pretend the
suspended fiber committed as `null` won't work, because in this case the
"suspended" fiber is the inner Offscreen wrapper.

Because the contents of the boundary haven't started rendering yet (i.e.
nothing in the tree has partially rendered) we can switch to the
regular, concurrent mode behavior: mark the boundary with ShouldCapture
and enter the unwind phase.

However, even though we're switching to the concurrent mode behavior, we
don't need to attach a ping listener. So I refactored the logic so that
it doesn't escape back into the regular path.

It's not really a big deal that we attach an unncessary ping listener,
since this case is so unusual. The motivation is not performance related
— it's to make the logic clearer, because I'm about to add another case
where we trigger a Suspense boundary without attaching a ping listener.
2021-09-23 11:07:38 -07:00
Brian Vaughn
d174d063d1 DevTools: Hook names optimizations (#22403)
This commit dramatically improves the performance of the hook names feature by replacing the source-map-js integration with custom mapping code built on top of sourcemap-codec. Based on my own benchmarking, this makes parsing 3-4 times faster. (The bulk of these changes are in SourceMapConsumer.js.)

While implementing this code, I also uncovered a problem with the way we were caching source-map metadata that was causing us to potential parse the same source-map multiple times. (I addressed this in a separate commit for easier reviewing. The bulk of these changes are in parseSourceAndMetadata.js.)

Altogether these changes dramatically improve the performance of the hooks parsing code.

One additional thing we could look into if the source-map download still remains a large bottleneck would be to stream it and decode the mappings array while it streams in rather than in one synchronous chunk after the full source-map has been downloaded.
2021-09-22 20:17:57 -04:00
Andrew Clark
95502f7b25 Update CodeSandbox to pull build artifacts from CI (#22400)
Instead of building them from source.

The `download-experimental-build` script polls CI until the build
has finished.
2021-09-22 11:35:56 -07:00
Andrew Clark
51e017c523 Revert "[Old server renderer] Retry error on client (#22399)"
Going to revert this until we figure out error reporting. It looks like
our downstream infra already supports some type of error recovery so
we might not need it here.
2021-09-22 12:32:28 -04:00
Andrew Clark
5a06072780 [Old server renderer] Retry error on client (#22399)
We're still in the process of migrating to the Fizz server renderer. In
the meantime, this makes the error semantics on the old server renderer
match the behavior of the new one: if an error is thrown, it triggers a
Suspense fallback, just as if it suspended (this part was already
implemented). Then the errored tree is retried on the client, where it
may recover and finish successfully.
2021-09-22 08:45:55 -07:00
Andrew Clark
82c8fa90be Add back useMutableSource temporarily (#22396)
Recoil uses useMutableSource behind a flag. I thought this was fine
because Recoil isn't used in any concurrent roots, so the behavior
would be the same, but it turns out that it is used by concurrent
roots in a few places.

I'm not expecting it to be hard to migrate to useSyncExternalStore, but
to de-risk the change I'm going to roll it out gradually with a flag. In
the meantime, I've added back the useMutableSource API.
2021-09-21 20:38:24 -07:00
Andrew Clark
8fcfdfff7e Scrape warning messages in CI (#22393)
There's a downstream workflow that runs the `print-warnings` command. We
can make it faster by scraping the warnings in CI and storing the
result as a build artifact.
2021-09-21 19:03:01 -07:00
Andrew Clark
ba07042c86 Fix sizebot mistakenly detecting deleted files (#22394) 2021-09-21 18:55:47 -07:00
Andrew Clark
d56947eb2c Increase polling threshold for publish-prereleases (#22392)
The publish-preleases command prints the URL of the publish workflow
so that you can visit the page and follow along.

But it can take a few seconds before the workflow ID is available, after
you create the pipeline. So the script polls the workflow endpoint
until it's available.

The current polling limit is too low so I increased it.

I also updated the error message to provide more info.
2021-09-21 18:43:59 -07:00
Luna Ruan
5b57bc6e31 [Draft] don't patch console during first render (#22308)
Previously, DevTools always overrode the native console to dim or supress StrictMode double logging. It also overrode console.log (in addition to console.error and console.warn). However, this changes the location shown by the browser console, which causes a bad developer experience. There is currently a TC39 proposal that would allow us to extend console without breaking developer experience, but in the meantime this PR changes the StrictMode console override behavior so that we only patch the console during the StrictMode double render so that, during the first render, the location points to developer code rather than our DevTools console code.
2021-09-21 15:00:11 -07:00
Andrew Clark
cf07c3df12 Delete all but one build2 reference (#22391)
This removes all the remaining references to the `build2` directory
except for the CI job that stores the artifacts. We'll keep the
`build2` artifact until downstream scripts are migrated to `build`.
2021-09-21 13:15:41 -07:00
Andrew Clark
bb0d069359 [build2 -> build] Local scripts
Update all our local scripts to use `build` instead of `build2`.

There are still downstream scripts that depend on `build2`, though, so
we can't remove it yet.
2021-09-21 15:14:09 -04:00
Andrew Clark
162bb8c978 [build -> build2] Sizebot 2021-09-21 15:07:16 -04:00
Andrew Clark
2375670a91 Delete unused CI jobs
These were replaced by the `build_combined` job.
2021-09-21 15:06:09 -04:00
Andrew Clark
f35287dda4 [build2 -> build] -> download-build-artifacts 2021-09-21 13:47:40 -04:00
Andrew Clark
e3c9cd9f41 Add COMMIT_SHA to build directory 2021-09-21 13:41:58 -04:00
Andrew Clark
0c81d347b6 Write artifacts to build instead of build2
Now that all the CI jobs have been migrated to the new build script,
we can start renaming the `build2` directory to `build`.

Since there are lots of scripts that reference `build2`, including
downstream scripts that live outside this repo, I'm going to keep
the `build2` directory around as a copy of `build`.

Then once all the references are updated, I will delete the copy.
2021-09-21 12:23:48 -04:00
Andrew Clark
baff3f2005 Move build_devtools_and_process_artifacts (#22388)
This is the last CI job that needs to be migrated to the new workflow.
2021-09-21 08:51:51 -07:00
Andrew Clark
7c6049695f Move lint job to new, combined CI workflow (#22386)
* Move lint job to new, combined CI workflow

Moves the lint job our new, combined CI workflow.

After this, there is only one job remaining to be migrated. Then we
can delete the old workflow and build script.

* Remove "stable" CI workflow

This workflow is now empty so we can remove it
2021-09-21 08:16:26 -07:00
salazarm
4da03c9fbd useSyncExternalStore React Native version (#22367) 2021-09-21 11:07:56 -04:00
Bowen
48d475c9ed correct typos (#22294)
Co-authored-by: Bowen Li <bowen31337@gmail.com>
2021-09-21 11:05:41 -04:00
Andrew Clark
fc57432966 Move DOM fixtures test job to main CI workflow (#22385)
Moves the RELEASE_CHANNEL_stable_yarn_test_dom_fixtures job to our new,
combined CI workflow.

After this, there are only two jobs remaining to be migrated. Then we
can delete the old workflow and build script.
2021-09-21 08:00:28 -07:00
Sebastian Silbermann
cb6c619c07 Remove Fiber fields that were used for hydrating useMutableSource (#22368) 2021-09-20 21:12:30 +01:00
salazarm
64e70f82e9 [Fizz] add avoidThisFallback support (#22318) 2021-09-20 15:44:48 -04:00
38elements
cbf6178ed3 Fix links in packages/react-devtools/README.md (#22356) 2021-09-20 15:10:29 -04:00
Konstantin Popov
acf8ada4c0 Fix typo in types.js (react-devtools-shared) (#22299)
Fix typo:

becuase -> because
2021-09-20 15:09:59 -04:00
BIKI DAS
c62d5831d3 react-devtools\OVERVIEW.md --> fixed typos (#22372) 2021-09-20 15:09:37 -04:00
Brian Vaughn
7e8fb98e14 Enabled enableProfilerChangedHookIndices feature flag for all builds (#22365) 2021-09-20 13:10:50 -04:00
Sebastian Silbermann
3ee7a004e5 devtools: Display actual ReactDOM API name in root type (#22363) 2021-09-20 11:44:21 -04:00
Andrew Clark
79b8fc6670 Implement getServerSnapshot in userspace shim (#22359)
* Convert useSES shim tests to use React DOM

Idea is that eventually we'll run these tests against an actual build of
React DOM 17 to test backwards compatibility.

* Implement getServerSnapshot in userspace shim

If the DOM is not present, we assume that we are running in a server
environment and return the result of `getServerSnapshot`.

This heuristic doesn't work in React Native, so we'll need to provide
a separate native build (using the `.native` extension). I've left this
for a follow-up.

We can't call `getServerSnapshot` on the client, because in versions of
React before 18, there's no built-in mechanism to detect whether we're
hydrating. To avoid a server mismatch warning, users must account for
this themselves and return the correct value inside `getSnapshot`.

Note that none of this is relevant to the built-in API that is being
added in 18. This only affects the userspace shim that is provided
for backwards compatibility with versions 16 and 17.
2021-09-20 08:32:13 -07:00
Andrew Clark
86b3e2461d Implement useSyncExternalStore on server (#22347)
Adds a third argument called `getServerSnapshot`.

On the server, React calls this one instead of the normal `getSnapshot`.
We also call it during hydration.

So it represents the snapshot that is used to generate the initial,
server-rendered HTML. The purpose is to avoid server-client mismatches.
What we render during hydration needs to match up exactly with what we
render on the server.

The pattern is for the server to send down a serialized copy of the
store that was used to generate the initial HTML. On the client, React
will call either `getSnapshot` or `getServerSnapshot` on the client as
appropriate, depending on whether it's currently hydrating.

The argument is optional for fully client rendered use cases. If the
user does attempt to omit `getServerSnapshot`, and the hook is called
on the server, React will abort that subtree on the server and
revert to client rendering, up to the nearest Suspense boundary.

For the userspace shim, we will need to use a heuristic (canUseDOM)
to determine whether we are in a server environment. I'll do that in
a follow up.
2021-09-20 08:31:02 -07:00
Brian Vaughn
57e4d6872f replace-fork: Cleanup after failure if no unstaged changes (#22364) 2021-09-20 11:10:17 -04:00
Andrew Clark
293059e52b replace-fork should not clear uncommitted changes (#22348)
The replace-fork script depends on ESLint to fix the reconciler imports
— `.old` -> `.new` or vice versa. If ESLint crashes, it can leave the
imports in an incorrect state.

As a convenience, @bvaughn updated the script to automatically run
`git checkout -- .` if the ESLint command fails. An unintended
consequence of the strategy is that if the working directory is not
clean, then any uncommitted changes will be lost.

We need a better strategy for this that prevents the accidental loss of
work. One option is to exit early if the working directory is not clean
before you run the script, though that affects the usability of
the script.

An ideal solution would reset the working directory back to whatever
state it was in before the script ran, perhaps by stashing all the
changes and restoring them if the script aborts.

Until we think of something better, I've commmented out the branch.
2021-09-20 10:07:25 -04:00
Andrew Clark
8209de2695 Delete useMutableSource implementation (#22292)
This API was replaced by useSyncExternalStore
2021-09-19 21:11:50 -07:00
Brian Vaughn
f50ff357cf DevTools: Fix memory leak via alternate Fiber pointer (#22346) 2021-09-17 12:53:07 -04:00
Brian Vaughn
bc9bb87c2b Clear performance marks after measuring (#22345) 2021-09-17 10:46:42 -04:00
Juan
1090ccd019 [DevTools] Enable hook names in standalone app (#22320) 2021-09-17 10:21:54 -04:00
Brian Vaughn
f2fd1b80d5 Updated the utfDecodeString() method to avoid call stack exceeded error (#22330) 2021-09-17 09:52:52 -04:00
BIKI DAS
b0803f255b VerticalScrollView -> fixed typos (#22341) 2021-09-17 09:05:09 -04:00
Ikko Ashimine
a7da457e6b Scheduling profiler: Fix typo in View.js (#22337) 2021-09-17 09:04:51 -04:00
Juan
a8cabb5648 [DevTools] Fix runtime error when inspecting an element times out (#22329) 2021-09-15 17:19:10 -04:00
Abhay Gupta
e8feb11b62 Fixed issue for better bundles,chunks and workers name in devtools-extensions. (#22322) 2021-09-15 13:51:33 -04:00
Brian Vaughn
f4ac680c7a Fixed broken build script --unsafe-partial flag (#22324)
This flag was broken due to a buggy race case in the ncp() command. The fix is amittedly a hack but improves on the existing behavior (of leaving the workspace in a broken state).
2021-09-15 13:32:09 -04:00
Dan Abramov
67222f044c [Experiment] Warn if callback ref returns a function (#22313) 2021-09-15 13:51:39 +01:00
Juan
50263d3273 [DevTools] Add initial APIs for logging instrumentation events under feature flag (#22276) 2021-09-14 11:10:24 -04:00
Ricky
263cfa6ecb [Experimental] Add useInsertionEffect (#21913) 2021-09-14 10:27:09 -04:00
Andrew Clark
806aaa2e21 [useSES shim] Import prefixed native API (#22310)
Until useSyncExternalStore is finalized, the shim should import the
prefixed version (unstable_useSyncExternalStore), which is available
in the experimental builds. That way our early testers can start
using it.
2021-09-13 21:55:18 -07:00
Andrew Clark
fd5e01c2e0 [useSES/extra] Reuse old selection if possible (#22307)
When you pass an unmemoized selector to useSyncExternalStoreExtra, we
have to reevaluate it on every render because we don't know whether
it depends on new props.

However, after reevalutating it, we should still compare the result
to the previous selection with `isEqual` and reuse the old one if it
hasn't changed.

Originally I did not implement this, because if the selector changes due
to new props or state, the component is going to have to re-render
anyway. However, it's still useful to return a memoized selection
when possible, because it may be the input to a downstream memoization.

In the test I wrote, the example I chose is selecting a list of
items from the store, and passing the list as a prop to a memoized
component. If the list prop is memoized, we can bail out.
2021-09-13 14:26:41 -07:00
Andrew Clark
33226fadaa Check for store mutations before commit (#22290)
* [useSyncExternalStore] Remove extra hook object

Because we already track `getSnapshot` and `value` on the store
instance, we don't need to also track them as effect dependencies. And
because the effect doesn't require any clean-up, we don't need to track
a `destroy` function.

So, we don't need to store any additional state for this effect. We can
call `pushEffect` directly, and only during renders where something
has changed.

This saves some memory, but my main motivation is because I plan to use
this same logic to schedule a pre-commit consistency check. (See the
inline comments for more details.)

* Split shouldTimeSlice into two separate functions

Lanes that are blocking (SyncLane, and DefaultLane inside a blocking-
by-default root) are always blocking for a given root. Whereas expired
lanes can expire while the render phase is already in progress.

I want to check if a lane is blocking without checking whether it
expired, so I split `shouldTimeSlice` into two separate functions.

I'll use this in the next step.

* Check for store mutations before commit

When a store is read for the first time, or when `subscribe` or
`getSnapshot` changes, during a concurrent render, we have to check
at the end of the render phase whether the store was mutated by
an concurrent event.

In the userspace shim, we perform this check in a layout effect, and
patch up any inconsistencies by scheduling another render + commit.
However, even though we patch them up in the next render, the parent
layout effects that fire in the original render will still observe an
inconsistent tree.

In the native implementation, we can instead check for inconsistencies
right after the root is completed, before entering the commit phase. If
we do detect a mutaiton, we can discard the tree and re-render before
firing any effects. The re-render is synchronous to block further
concurrent mutations (which is also what we do to recover from tearing
bugs that result in an error). After the synchronous re-render, we can
assume the tree the tree is consistent and continue with the normal
algorithm for finishing a completed root (i.e. either suspend
or commit).

The result is that layout effects will always observe a consistent tree.
2021-09-13 08:07:46 -07:00
Konstantin Popov
86c7ca70a9 Fix link (#22296)
Fix link (branch master was renamed to main): 

master -> main
2021-09-12 11:09:53 -04:00
Ricky
e73911e715 Clean up my "hard to read" code (#22295) 2021-09-11 15:05:54 -04:00
Brian Vaughn
d2f08dd40d DevTools: Add missing param to fetchFromPage() (#22291) 2021-09-10 16:26:46 -04:00
Brian Vaughn
81db4eb1d1 Replaced network.onRequestFinished() caching with network.getHAR() (#22285)
Replaced network.onRequestFinished() caching with network.getHAR() so that we can avoid redundantly (pre) caching JavaScript content. In the event that the HAR log doesn't contain a match, we'll fall back to fetching from the Network (and hoping for a cache hit from that layer).

I've tested both internally (internal Facebook DEV server) and externally (Code Sandbox) and it seems like this approach results in cache hits, so long as DevTools is opened when the page loads. (Otherwise it falls back to fetch().)
2021-09-10 15:11:18 -04:00
salazarm
0fd195f295 update error message to include useLayoutEffect or useEffect on bad e… (#22279)
* update error message to include useLayoutEffect or useEffect on bad effect return

* Update packages/react-reconciler/src/ReactFiberCommitWork.new.js

Co-authored-by: Ricky <rickhanlonii@gmail.com>

* use existing import

Co-authored-by: Ricky <rickhanlonii@gmail.com>
2021-09-10 12:19:51 -04:00
Luna Ruan
cb8a50619b [DevTools] Add React Devtools Extension Startup and File Structure to OVERVIEW.md (#22283) 2021-09-09 15:58:27 -07:00
Luna Ruan
43cf06daf9 [DevTools] Fix react-devtools-extension build error and react-devtools-inline's package.json (#22281) 2021-09-09 14:26:13 -07:00
Brian Vaughn
96814e71b2 Revert Suspense cache Thenable.catch() change (#22280)
Reverts part of #22275 (adding .catch() to Thenables in Suspense caches) in response to #22275 (comment).

After taking another look with fresh eyes, I think I see the "uncaught error" issue I initially noticed was in checkForUpdate() (which did not pass an error handler to .then)
2021-09-09 15:26:41 -04:00
Brian Vaughn
225740be48 Add named hooks support to react-devtools-inline (#22263)
This commit builds on PR #22260 and makes the following changes:
* Adds a DevTools feature flag for named hooks support. (This allows us to disable it entirely for a build via feature flag.)
* Adds a new Suspense cache for dynamically imported modules. (This allows a component to suspend while importing an external code chunk– like the hook names parsing code).
* DevTools supports a hookNamesModuleLoaderFunction param to import the hook names module. I wish this could be handles as part of the react-devtools-shared package, but I'm not sure how to configure Webpack (4) to serve the chunk from react-devtools-inline. This seemed like a reasonable workaround.

The PR also contains an additional unrelated change:
* Removes pre-fetch optimization (added in DevTools: Improve named hooks network caching #22198). This optimization was mostly only important for cases where sources needed to be re-downloaded, something which we can now avoid in most cases¹ thanks to using cached responses already loaded by the page. (I tested this locally on Facebook and this change has no negative performance impact. There is still some overhead from serializing the JS through the Bridge but that's constant between the two approaches.)

¹ The case where we don't benefit from cached responses is when DevTools are opened after the page has already loaded certain scripts. This seems uncommon enough that I don't think it justified the added complexity of prefetching.
2021-09-09 15:25:26 -04:00
Andrew Clark
8f96c6b2ac [Bugfix] Prevent infinite update loop caused by a synchronous update in a passive effect (#22277)
* Add test that triggers infinite update loop

In 18, passive effects are flushed synchronously if they are the
result of a synchronous update. We have a guard for infinite update
loops that occur in the layout phase, but it doesn't currently work for
synchronous updates from a passive effect.

The reason this probably hasn't come up yet is because synchronous
updates inside the passive effect phase are relatively rare: you either
have to imperatively dispatch a discrete event, like `el.focus`, or you
have to call `ReactDOM.flushSync`, which triggers a warning. (In
general, updates inside a passive effect are not encouraged.)

I discovered this because `useSyncExternalStore` does sometimes
trigger updates inside the passive effect phase.

This commit adds a failing test to prove the issue exists. I will fix
it in the next commit.

* Fix failing test added in previous commit

The way we detect a "nested update" is if there's synchronous work
remaining at the end of the commit phase.

Currently this check happens before we synchronously flush the passive
effects. I moved it to after the effects are fired, so that it detects
whether synchronous work was scheduled in that phase.
2021-09-09 08:14:30 -07:00
Brian Vaughn
24c2e27256 DevTools Suspense cache cleanup (#22275) 2021-09-09 09:28:17 -04:00
Sebastian Silbermann
4ce89a58da Test bad useEffect return value with noop-renderer (#22258)
* Test bad useEffect return value with noop-renderer

* Use previous "root"-approach

Tests should now be invariant under variants

* Add same test for layout effects
2021-09-08 18:58:53 -04:00
salazarm
a3fde23588 Detect subscriptions wrapped in startTransition (#22271)
* Detect subscriptions wrapped in startTransition
2021-09-08 17:01:09 -04:00
Andrew Clark
95d762e406 Remove duplicate test
Accidentally committed two copies of this test during a rebase.
2021-09-08 11:50:21 -04:00
Dan Abramov
d4d1dc085d Reorder VARIANT feature flags (#22266)
* Move variant tests up

* Add a comment
2021-09-07 23:28:38 +01:00
Riley Shaw
fbce2d5274 Fix #21972: Add onResize event to video elements (#21973)
* Fix #21972: Add `onResize` event to video elements

This is a simple fix for #21972 that adds support for the `onResize` media event.

I created a separate `videoEventTypes` array since I doubt anyone will want to add `onResize` to an audio event. It would simplify the code a bit to just add `resize` to the `mediaEventTypes` array, if that’s preferred.

Pre-commit checklist ([source](https://reactjs.org/docs/how-to-contribute.html#sending-a-pull-request))

 Fork the repository and create your branch from `main`.
 Run `yarn` in the repository root.
 If you’ve fixed a bug or added code that should be tested, add tests!
 Ensure the test suite passes (`yarn test`). Tip: `yarn test --watch TestName` is helpful in development.
 Run `yarn test --prod` to test in the production environment.
 If you need a debugger, run `yarn debug-test --watch TestName`, open chrome://inspect, and press “Inspect”.
 Format your code with prettier (`yarn prettier`).
 Make sure your code lints (`yarn lint`). Tip: `yarn linc` to only check changed files.
 Run the Flow typechecks (`yarn flow`).
 If you haven’t already, complete the CLA.

* Consolidate `videoEventTypes` array into `mediaEventTypes`
2021-09-07 23:28:19 +01:00
Dan Abramov
2f156eafb8 Adjust consoleManagedByDevToolsDuringStrictMode feature flag (#22253) 2021-09-07 19:51:12 +01:00
Andrew Clark
cfd8193328 Add useSyncExternalStore to react-debug-tools (#22240)
Adds support for useSyncExternalStore to react-debug-tools, which in
turn adds support for React Devtools.

Test plan: I added a test to ReactHooksInspectionIntegration, based on
existing one for useMutableSource.
2021-09-07 10:58:20 -07:00
Andrew Clark
8e80592a3a Remove state queue from useSyncExternalStore (#22265)
The userspace shim of useSyncExternalStore uses a useState hook because
it's the only way to trigger a re-render. We don't actually use the
queue to store anything, because we read the current value directly
from the store.

In the native implementation, we can schedule an update on the fiber
directly, without the overhead of a queue.
2021-09-07 10:27:01 -07:00
Andrew Clark
06f98c1680 Implement useSyncExternalStore in Fiber (#22239)
This adds an initial implementation of useSyncExternalStore to the
fiber reconciler. It's mostly a copy-paste of the userspace
implementation, which is not ideal but is a good enough starting place.

The main change we'll want to make to this native implementation is to
move the tearing checks from the layout phase to an earlier, pre-commit
phase so that code that runs in the commit phase always observes a
consistent tree.

Follow-ups:

- Implement in Fizz
- Implement in old SSR renderer
- Implement in react-debug-hooks
2021-09-07 10:22:05 -07:00
Andrew Clark
77912d9a05 Wire up the native API for useSyncExternalStore (#22237)
Adds useSyncExternalStore to the internal dispatcher, and exports
the native API from the React package without yet implementing it.
2021-09-07 10:20:24 -07:00
salazarm
031abd24b6 Add warning and test for useSyncExternalStore when getSnapshot isn't cached (#22262)
* add warning and test

* Wrap console error in __DEV__ flag

* prettier
2021-09-07 09:08:33 -07:00
Brian Vaughn
e07039bb61 Moved named hooks code (and tests) from react-devtools-extensions to react-devtools-shared (#22260) 2021-09-07 11:44:49 -04:00
Juan
abbc79d6fd [DevTools] Only call originalPositionFor once (#22181) 2021-09-07 10:39:55 -04:00
Dan Abramov
771da6e27b Update PULL_REQUEST_TEMPLATE.md 2021-09-07 07:54:34 +01:00
Ryota Murakami
d1f51f3453 [package:react-dom] updateREADME's Class Component to Function Component (#21829)
* [package:react-dom] updateREADME's Class Component to Function Component

* Update README.md

Co-authored-by: Dan Abramov <dan.abramov@gmail.com>
2021-09-06 21:23:13 +01:00
Jianhua Zheng
b8884de24e break up import keyword to avoid being accidentally parsed as dynamic import statement in external code (#21918)
Co-authored-by: zhengjianhua <zhengjianhua.michael@bytedance.com>
2021-09-06 21:20:33 +01:00
Ikko Ashimine
6d6bba5bfc Fix typo in ReactUpdatePriority-test.js (#21958)
continous -> continuous
2021-09-06 21:16:05 +01:00
Dan Abramov
37abc99418 Build ReactDOMServer on CodeSandbox CI (#22255) 2021-09-06 21:00:36 +01:00
Michaël De Boey
b394c38e88 feat(eslint-plugin-react-internal): support ESLint 8.x (#22249)
Co-authored-by: Dan Abramov <dan.abramov@gmail.com>
2021-09-06 20:42:40 +01:00
Dan Abramov
6f64eb5aa0 Update PULL_REQUEST_TEMPLATE.md 2021-09-06 20:36:46 +01:00
Dan Abramov
cdb08ebe0a Update PULL_REQUEST_TEMPLATE.md 2021-09-06 20:36:24 +01:00
Michaël De Boey
0c0d1ddae4 feat(eslint-plugin-react-hooks): support ESLint 8.x (#22248) 2021-09-06 20:17:51 +01:00
Mahyar Ebadi
380284a2b4 Add aria-description to the list of known ARIA attributes (#22142)
* Update validAriaProperties.js

https://w3c.github.io/aria/#aria-description is a valid aria property.

* Sort alphabetically

Co-authored-by: Dan Abramov <dan.abramov@gmail.com>
2021-09-06 20:12:51 +01:00
Kausik S S
c46c0733e2 Typo fixed (#22171) 2021-09-06 20:05:15 +01:00
dependabot[bot]
6a56ea89bc Bump tar from 5.0.5 to 5.0.11 (#22223)
Bumps [tar](https://github.com/npm/node-tar) from 5.0.5 to 5.0.11.
- [Release notes](https://github.com/npm/node-tar/releases)
- [Changelog](https://github.com/npm/node-tar/blob/main/CHANGELOG.md)
- [Commits](https://github.com/npm/node-tar/compare/v5.0.5...v5.0.11)

---
updated-dependencies:
- dependency-name: tar
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-09-06 20:03:12 +01:00
Konstantin Popov
99f9de9a6a Fix typo in ReactDOMServerFormatConfig.js (#22203)
Fix typo:

TOOD -> TODO
2021-09-06 19:58:46 +01:00
Andrew Clark
1314299c7f Initial shim of useSyncExternalStore (#22211)
This sets up an initial shim implementation of useSyncExternalStore,
via the use-sync-external-store package. It's designed to mimic the
behavior of the built-in API, but is backwards compatible to any version
of React that supports hooks.

I have not yet implemented the built-in API, but once it exists, the
use-sync-external-store package will always prefer that one. Library
authors can depend on the shim and trust that their users get the
correct implementation.

See https://github.com/reactwg/react-18/discussions/86 for background
on the API.

The tests I've added here are designed to run against both the shim and
built-in implementation, using our variant test flag feature. Tests that
only apply to concurrent roots will live in a separate suite.
2021-09-01 17:52:38 -07:00
Luna Ruan
3385b377f7 React DevTools 4.17.0 -> 4.18.0 (#22234) 2021-09-01 13:39:36 -07:00
Luna Ruan
2b7214033e [DevTools] Fix Issue in release script where commits for the last DevTools release are undefined #22233 2021-09-01 12:56:39 -07:00
Luna Ruan
ac8fc34e61 remove dist folder in release script for standalone and inline before building (#22232) 2021-09-01 12:16:00 -07:00
Luna Ruan
fc40f02adb Add consoleManagedByDevToolsDuringStrictMode feature flag in React Reconciler (#22196) 2021-09-01 11:56:52 -07:00
Brian Vaughn
9fc04eaf3f DevTools: Improve named hooks network caching (#22198)
While testing the recently-launched named hooks feature, I noticed that one of the two big performance bottlenecks is fetching the source file. This was unexpected since the source file has already been loaded by the page. (After all, DevTools is inspecting a component defined in that same file.)

To address this, I made the following changes:
- [x] Keep CPU bound work (parsing source map and AST) in a worker so it doesn't block the main thread but move I/O bound code (fetching files) to the main thread.
- [x] Inject a function into the page (as part of the content script) to fetch cached files for the extension. Communicate with this function using `eval()` (to send it messages) and `chrome.runtime.sendMessage()` to return its responses to the extension).

With the above changes in place, the extension gets cached responses from a lot of sites- but not Facebook. This seems to be due to the following:
* Facebook's response headers include [`vary: 'Origin'`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Vary).
* The `fetch` made from the content script does not include an `Origin` request header.

To reduce the impact of cases where we can't re-use the Network cache, this PR also makes additional changes:
- [x] Use `devtools.network.onRequestFinished` to (pre)cache resources as the page loads them. This allows us to avoid requesting a resource that's already been loaded in most cases.
- [x] In case DevTools was opened _after_ some requests were made, we also now pre-fetch (and cache in memory) source files when a component is selected (if it has hooks). If the component's hooks are later evaluated, the source map will be faster to access. (Note that in many cases, this prefetch is very fast since it is returned from the disk cache.)

With the above changes, we've reduced the time spent in `loadSourceFiles` to nearly nothing.
2021-09-01 14:10:07 -04:00
Luna Ruan
67f38366a5 Add consoleManagedByDevToolsDuringStrictMode feature flag in DevTools #22215 2021-08-30 15:16:53 -07:00
Luna Ruan
597ecd6a0c [DevTools] Throw error in console without interfering with logs (#22175) 2021-08-30 14:37:49 -07:00
Luna Ruan
36f0005b99 added react native feature flags (#22199)
lunaruan commented 3 days ago • 
This PR adds separate DevTools feature flag configurations for react-devtools-core. It also breaks the builds down into facebook specific and open source flags so we can experiment in React Native.

Tested yarn build:standalone, yarn build:backend, yarn build:standalone:fb, and yarn build:backend:fb and inspected the output to make sure each package used the correct feature flags (the first two use core-oss and the latter two use fb-oss.
2021-08-30 14:12:52 -07:00
Sebastian Silbermann
5037b4e2e6 devtools: Don't display hook index of useContext (#22200) 2021-08-30 15:44:12 -04:00
Andrew Clark
46a0f050aa Set up use-sync-external-store package (#22202)
This package will be a shim for the built-in useSyncExternalStore API
(not yet implemented).
2021-08-28 13:57:47 -07:00
Matt Hargett
8723e772b9 Fix a string interpolation typo in ReactHooks test (#22174) 2021-08-26 15:35:06 -04:00
Juan
0ba0564aee [DevTools] Add utils for perfomance marks (#22180) 2021-08-26 13:05:15 -04:00
Brian Vaughn
2bf2e76d36 Add performance marksf or individual fetch() requests (#22176) 2021-08-26 09:19:00 -04:00
Luna Ruan
60a30cf32e Console Logging for StrictMode Double Rendering (#22030)
React currently suppress console logs in StrictMode during double rendering. However, this causes a lot of confusion. This PR moves the console suppression logic from React into React Devtools. Now by default, we no longer suppress console logs. Instead, we gray out the logs in console during double render. We also add a setting in React Devtools to allow developers to hide console logs during double render if they choose.
2021-08-25 15:35:38 -07:00
Brian Vaughn
8456457c8d Added performance timings to DevTools named hooks parsing (#22173) 2021-08-25 15:39:15 -04:00
Brian Vaughn
b9964684bd DevTools release script updates: (#22170) 2021-08-24 18:59:34 -04:00
Brian Vaughn
582858083e React DevTools 4.16.0 -> 4.17.0 2021-08-24 11:12:42 -07:00
Brian Vaughn
b5fbf5464b Automated DevTools release process (#22161) 2021-08-24 14:05:50 -04:00
Ricky
76bbad3e34 Add maxYieldMs feature flag in Scheduler (#22165) 2021-08-24 13:03:07 -04:00
Ricky
b0b53ae2c1 Add feature flags for scheduler experiments (#22105) 2021-08-24 12:47:51 -04:00
Brian Vaughn
edfe50510b DevTools: Replaced WeakMap with LRU for inspected element cache (#22160)
We use an LRU for this rather than a WeakMap because of how the "no-change" optimization works.

When the frontend polls the backend for an update on the element that's currently inspected, the backend will send a "no-change" message if the element hasn't updated (rendered) since the last time it was asked. In thid case, the frontend cache should reuse the previous (cached) value. Using a WeakMap keyed on Element generally works well for this, since Elements are mutable and stable in the Store. This doens't work properly though when component filters are changed, because this will cause the Store to dump all roots and re-initialize the tree (recreating the Element objects).

So instead we key on Element ID (which is stable in this case) and use an LRU for eviction.
2021-08-23 19:22:31 -04:00
Byron Luk
bd5bf555e1 add more detailed error handling if profiling data does not have any React marks (#22157)
Co-authored-by: Brian Vaughn <brian.david.vaughn@gmail.com>
2021-08-23 11:01:00 -04:00
Junaid Farooq
0da5ad09db Renames master to main in fixtures/flight webpack config file (#21998) 2021-08-23 10:55:37 -04:00
Brian Vaughn
4df10c5871 Yarn replace-fork should not silently error (#22156) 2021-08-22 16:53:07 -04:00
Bowen
fc3b6a4118 Fix a few typos (#22154)
Co-authored-by: Bowen Li <bowen31337@gmail.com>
2021-08-22 14:11:35 -04:00
Konstantin Popov
f5e529176e Fix typo in preprocessData.js (#22150)
Fix typo:

SUSPEND_DURING_UPATE  ->  SUSPEND_DURING_UPDATE
2021-08-22 13:37:36 -04:00
Juan
9e8fe11e11 [DevTools] Keep query params in extracted source map urls (#22148)
## Summary

Our current logic for extracting source map urls assumed that the url contained no query params (e.g. `?foo=bar`), and when extracting the url we would cut off the query params. I noticed this during internal testing, since removing the query params would cause loading source maps to fail.

This commit fixes that behavior by ensuring that our regex captures the full url, including query params.

## Test Plan

- yarn flow
- yarn test
- yarn test-build-devtools
- added new regression tests 
- named hooks still work on manual test of browser extension on a few different apps (code sandbox, create-react-app, internally).
2021-08-20 18:04:30 -04:00
Holger Benl
83205c0aea [DevTools] Add options for disabling some features (#22136) 2021-08-20 12:55:50 -04:00
Brian Vaughn
75a3e9fa40 DevTools: Reset cached indices in Store after elements reordered (#22147) 2021-08-20 12:53:28 -04:00
Sebastian Silbermann
b6ff9ad163 DevTools: update error indices when elements are added/removed (#22144) 2021-08-20 11:55:42 -04:00
Andrew Clark
986d0e61d7 [Scheduler] Add tests for isInputPending (#22140)
This feature was already implemented but we didn't have any tests. So
I wrote some.
2021-08-20 06:57:29 -07:00
Andrew Clark
d54be90be6 Set up test infra for dynamic Scheduler flags (#22139)
I copied the set up we use for React.

In the www-variant test job, the Scheduler `__VARIANT__` flags will be
`true`. When writing a test, we can read the value of the flag with the
`gate` pragma and method.

Note: Since these packages are currently released in lockstep, maybe we
should remove SchedulerFeatureFlags and use ReactFeatureFlags for both.
2021-08-20 06:56:20 -07:00
Brian Vaughn
64f83a6fd2 Replace "source-map" library with "source-map-js" (#22126) 2021-08-19 11:25:38 -04:00
Brian Vaughn
aa25824f3e Scheduling profiler: Fix tooltip wheel event regression (#22130)
Panning horizontally via mouse wheel used to allow you to scrub over snapshot images. This was accidentally broken by a recent change. The core of the fix for this was to update `useSmartTooltip()` to remove the dependencies array so that a newly rendered tooltip is positioned even if the mouseX/mouseY coordinates don't change (as they don't when panning via wheel).

I also cleaned a couple of unrelated things up while doing this:
* Consolidated hover reset logic formerly split between `CanvasPage` and `Surface` into the `Surface` `handleInteraction()` function.
* Cleaned up redundant ref setting code in EventTooltip.
2021-08-18 19:51:34 -04:00
Juan
42ef45b129 [DevTools] Using array destructuring without assigning first variable does not error (#22129)
## Summary

Before this commit, if a hook returned an array the was destructured, but without assigning a variable to the first element in the array, this would produce an error. This was detected via internal testing.

This commit fixes that and adds regression tests.


## Test Plan

- yarn flow
- yarn test
- yarn test-build-devtools
- added new regression tests 
- named hooks still work on manual test of browser extension on a few different apps (code sandbox, create-react-app, internally).
2021-08-18 18:26:57 -04:00
Juan
f1db9c30cc [DevTools] Support object destructuring pattern without runtime errors (#22128)
## Summary

Before this commit, if a hook returned an object and we declared a variable using object destructuring on the returned value, we would produce a runtime error. This was detected via internal testing.

This commit fixes that and adds regression tests.


## Test Plan

- yarn flow
- yarn test
- yarn test-build-devtools
- added new regression tests 
- named hooks still work on manual test of browser extension on a few different apps (code sandbox, create-react-app, internally).
2021-08-18 18:17:29 -04:00
Dan Abramov
7ed0706d7e Remove the warning for setState on unmounted components (#22114)
* Remove warning for setState on unmounted components

* Trigger CI
2021-08-18 21:50:02 +01:00
Juan
6abda7f4f2 [DevTools] Access metadata in source maps correctly accounting for different formats (#22096)
## Summary

Follow up from https://github.com/facebook/react/pull/22010.

The initial implementation of named hooks and for looking up hook name metadata in an extended source map both assumed that the source maps would always have a `sources` field available, and didn't account for the source maps in the [Index Map](https://sourcemaps.info/spec.html#h.535es3xeprgt) format, which contain a list of `sections` and don't have the `source` field available directly. 

In order to properly access metadata in extended source maps, this commit:

-  Adds a new `SourceMapMetadataConsumer` api, which is a fork / very similar in structure to the corresponding [consumer in Metro](2b44ec39b4/packages/metro-symbolicate/src/SourceMetadataMapConsumer.js (L56)) (as specified by @motiz88 in https://github.com/facebook/react/issues/21782.
- Updates `parseHookNames` to use this new api

## Test Plan

- yarn flow
- yarn test
- yarn test-build-devtools
- added new regression tests covering the index map format
- named hooks still work on manual test of browser extension on a few different apps (code sandbox, create-react-app, internally).
2021-08-18 14:30:31 -04:00
Brian Vaughn
f51579fffe Scheduling Profiler: Add network measures (#22112) 2021-08-18 12:17:59 -04:00
Brian Vaughn
9eb2aaaf81 Fixed ReactSharedInternals export in UMD bundle (#22117) 2021-08-18 01:40:55 -04:00
Sota
bd255700d7 Show a soft error when a text string or number is supplied as a child to non text wrappers (#22109) 2021-08-16 21:43:24 -04:00
Sota
424fe58708 Revert "Show a soft error when a text string or number is supplied as a child to non text wrappers (#21953)" (#22108)
This reverts commit e9b2028b32.
2021-08-16 17:53:23 -07:00
Andrew Clark
aebf3b456b [Scheduler] Check for continuous input events (#22107)
* [Scheduler] Track start of current chunk

Currently in `shouldYield`, we compare the current time to a deadline
that is pre-computed at the beginning of the current chunk.

However, since we use different deadlines depending on whether an input
event is pending, it makes more sense to track the start of the current
chunk and check how much time has elapsed since then.

Doesn't change any behavior, just refactors the logic.

* [Scheduler] Check for continuous input events

`isInputPending` supports a `includeContinuous` option. When set to
`true`, the method will check for pending continuous inputs, like
`mousemove`, in addition to discrete ones, like `click`.

We will only check for pending continuous inputs if we've blocked the
main thread for a non-neglible amount of time. If we've only blocked
the main thread for, say, a few frames, then we'll only check for
discrete inputs.

I wrote a test for this but didn't include it because we haven't yet set
up the `gate` flag infra to work with Scheduler feature flags. For now,
I ran the test locally.

* Review nits
2021-08-16 15:48:50 -07:00
Luna Ruan
152ecce117 DevTools 4.15.0 -> 4.16.0 (#22104) 2021-08-16 14:55:47 -07:00
Luna Ruan
f6ec4661db make parseHookNames a separate bundle (#22102) 2021-08-16 16:46:46 -04:00
Brian Vaughn
55d01aa0f3 Scheduling profiler: Canvas views clip by default (#22100) 2021-08-16 13:20:07 -04:00
Tommy Groshong
bc4e751121 Typo: 'occured' -> 'occurred' in comment (#22094) 2021-08-15 17:25:22 -04:00
Brian Vaughn
89910635f7 Scheduling Profiler: Inline snapshots (#22091) 2021-08-14 11:10:36 -04:00
Brian Vaughn
54e170c794 [DevTools] Add screenshots to Scheduling Profiler (#22088) 2021-08-13 17:14:29 -04:00
Brian Vaughn
e4e8226c62 Fixed Components tree indentation bug for Chrome extension (#22083)
By upgrading react-virtualized-auto-sizer to 1.0.6

See https://github.com/bvaughn/react-virtualized-auto-sizer/pull/39
2021-08-12 20:41:56 -04:00
Brian Vaughn
82583617b7 Updated DevTools CHANGELOG
Fixed header typo
2021-08-12 11:03:33 -04:00
Brian Vaughn
c2bb975337 Added Scheduling Profiler notes and videos to the DevTools CHANGELOG 2021-08-12 11:02:30 -04:00
Brian Vaughn
07e58658c9 Add script to generate DevTools changelog text (#22077) 2021-08-12 10:43:56 -04:00
Brian Vaughn
ef582fbea1 Added taneliang and kartikcho to scheduling profiler credits 2021-08-11 17:48:37 -04:00
Juan
c6f2188ed6 DevTools 4.14.0 -> 4.15.0 2021-08-11 16:47:20 -04:00
Juan
531c97ef7a [DevTools] Updated source map extension format + more precise types (#22073)
## Summary

Follow up from https://github.com/facebook/react/pull/22010.

As suggested by @motiz88, update the way the react sources metadata is stored within the fb sources metadata. Specifically,  instead of `x_facebook_sources` directly containing a hook map in the second position of the metadata tuple for a given source, it contains the react sources metadata itself, which is also a tuple of react sources metadata for a given source, and which contains the hook map in the first position. This way the react sources metadata tuple can be extended to contain more react-specific metadata without taking up more positions in the top-level facebook sources metadata.

As part of this change:
- Adds more precise Flow types, mostly borrowed from Metro
- Fixes the facebook sources field name (we were using `x_fb_sources` but it should be `x_facebook_sources`

## Test Plan

- yarn flow
- yarn test
- yarn test-build-devtools
2021-08-11 15:46:22 -04:00
Brian Vaughn
ad150533d6 Updated @reach packages to fix unmount bug (#22075) 2021-08-11 14:43:25 -04:00
Brian Vaughn
280e3f936f DevTools: Scheduling profiler: Add vertical scroll bar (#22005)
Co-authored-by: E-Liang Tan <eliang@eliangtan.com>
2021-08-11 14:19:45 -04:00
Juan
88d121899a [DevTools] Support extended source maps with named hooks information (#22010)
## Summary

Adds support for statically extracting names for hook calls from source code, and extending source maps with that information so that DevTools does not have to directly parse source code at runtime, which will speed up the Named Hooks feature and allow it to be enabled by default.

Specifically, this PR includes the following parts:

- [x] Adding logic to statically extract relevant hook names from the parsed source code (i.e. the babel ast). Note that this logic differs slightly from the existing logic in that the existing logic also uses runtime information from DevTools (such as whether given hooks are a custom hook) to extract names for hooks, whereas this code is meant to run entirely at build time, so it does not rely on that information.
- [x] Generating an encoded "hook map", which encodes the information about a hooks *original* source location, and it's corresponding name. This "hook map" will be used to generate extended source maps, included tentatively under an extra `x_react_hook_map` field. The map itself is formatted and encoded in a very similar way as how the `names` and `mappings` fields of a standard source map are encoded ( = Base64 VLQ delta coding representing offsets into a string array), and how the "function map" in Metro is encoded, as suggested in #21782. Note that this initial version uses a very basic format, and we are not implementing our own custom encoding, but reusing the `encode` function from `sourcemap-codec`.
- [x] Updating the logic in `parseHookNames` to check if the source maps have been extended with the hook map information, and if so use that information to extract the hook names without loading the original source code. In this PR we are manually generating extended source maps in our tests in order to test that this functionality works as expected, even though we are not actually generating the extended source maps in production.

The second stage of this work, which will likely need to occur outside this repo, is to update bundlers such as Metro to use these new primitives to actually generate source maps that DevTools can use.

### Follow-ups

- Enable named hooks by default when extended source maps are present
- Support looking up hook names when column numbers are not present in source map.
- Measure performance improvement of using extended source maps (manual testing suggests ~4 to 5x faster)
- Update relevant bundlers to generate extended source maps.

## Test Plan

- yarn flow
- Tests still pass
  - yarn test
  - yarn test-build-devtools
- Named hooks still work on manual test of browser extension on a few different apps (code sandbox, create-react-app, facebook).
- For new functionality:
  - New tests for statically extracting hook names.
  - New tests for using extended source maps to look up hook names at runtime.
2021-08-11 10:46:19 -04:00
Sota
e9b2028b32 Show a soft error when a text string or number is supplied as a child to non text wrappers (#21953)
* Show soft errors when a text string or number is supplied as a child instead of throwing an error

* bring __DEV__ check first so that things inside get removed in prod.

* fix lint
2021-08-10 13:14:11 -07:00
Byron Luk
da627ded86 Devtools/function context change (#22047) 2021-08-10 14:16:54 -04:00
Brian Vaughn
5634ed16aa Scheduling Profiler: Misc UX and performance improvements (#22043) 2021-08-09 17:11:33 -04:00
Brian Vaughn
ecd73e17bc Enable enableSuspenseLayoutEffectSemantics flag statically for Facebook (#22050) 2021-08-09 15:45:12 -04:00
Konstantin Popov
64931821a9 Fix typo in parseHookNames.js (#22042)
representated -> represented
2021-08-08 15:58:50 -04:00
Brian Vaughn
2edf449803 Scheduling Profiler: Renamed a misnamed variable 2021-08-06 15:03:35 -04:00
Brian Vaughn
5660c52b89 Scheduling Profiler: Improve warnings and add unit tests (#22038)
* Scheduling Profiler: Updated instructions to mentioned v18+ requirement

* Moved long-event warning to post processing

This lets us rule out non-React work or React work that started before the event and finished quickly during the event.

Also added unit tests for this warning and the various cases.

* Moved long-event warning to post processing

This lets us rule out non-React work or React work that started before the event and finished quickly during the event.

Also added unit tests for this warning and the various cases.

* Updated nested update warning text

* Udpate warning about suspending outside of a transition

Handle edge case where component suspends before the first commit (and label metadata) has been logged.

Add unit tests.

* Fixed logic error in getBatchRange() with minStartTime

* PR feedback: Combined a conditional statement
2021-08-06 14:57:52 -04:00
Juan
b9934d6db5 [DevTools] Hook names are correctly extracted when parsing nested hook calls (#22037)
## Summary

This commit fixes an issue where DevTools would currently not correctly extract the hook names for a hook call when the hook call was nested under *another* hook call, e.g.:

```javascript
function Component() {
  const InnerComponent = useMemo(() => () => {
    const [state, setState] = useState(0);

    return state;
  }); 
  return null;
};
```

Although it seems pretty rare to encounter this case in actual product code, DevTools wasn't handling it correctly:

**Expected Names:**
- `InnerComponent` for the `useMemo()` call.
- `state` for the `useState()` call.

**Actual**
- `InnerComponent` for the `useMemo()` call.
- `InnerComponent` for the `useState()` call.

The reason that we were extracting the name for the nested hook call incorrectly is that the `checkNodeLocation` function (which attempts to check if the location of the hook matches the location in the original source code), was too "lenient" and would return a match even if the start lines of the locations didn't match.

Specifically, for our example, it would consider that the location of the outer hook call "matched" the location of the inner hook call (even though they were on different lines), and would then return the wrong hook name.


### Fix

The fix in this commit is to update the `checkNodeLocation` function to more strictly check for matching start lines. The assumption here is that if 2 locations are on different starting lines, they can't possibly correspond to the same hook call.

## Test Plan

- yarn flow
- Tests still pass
  - yarn test
  - yarn test-build-devtools
- new regression tests added
- named hooks still work on manual test of browser extension on a few different apps (code sandbox, create-react-app, internally). 
![image](https://user-images.githubusercontent.com/1271509/128409571-d62e0a74-6b7b-4c3f-ad86-6799ecd71962.png)

![image](https://user-images.githubusercontent.com/1271509/128409943-f898f27b-67ab-4260-a931-40d9c1942395.png)

![image](https://user-images.githubusercontent.com/1271509/128410326-79a0f822-55b1-4b90-a9b9-78f13fa0b5c5.png)
2021-08-05 16:36:59 -04:00
Brian Vaughn
a8725a3e62 Scheduling profiler: Added lane labels and durations to React measures (#22029) 2021-08-05 13:50:39 -04:00
Andrew Clark
19092ac8c3 Re-add old Fabric Offscreen impl behind flag (#22018)
* Re-add old Fabric Offscreen impl behind flag

There's a chance that #21960 will affect layout in a way that we don't
expect, so I'm adding back the old implementation so we can toggle the
feature with a flag.

The flag should read from the ReactNativeFeatureFlags shim so that we
can change it at runtime. I'll do that separately.

* Import dynamic RN flags from external module

Internal feature flags that we wish to control with a GK can now be
imported from an external module, which I've called
"ReactNativeInternalFeatureFlags".

We'll need to add this module to the downstream repo.

We can't yet use this in our tests, because we don't have a test
configuration that runs against the React Native feature flags fork. We
should set up that up the same way we did for www.
2021-08-03 19:30:20 -07:00
Andrew Clark
215db465a2 [Fabric] Add flex: 1 to Offscreen view container (#22019)
Without this style property, the layout of the children is messed up.

The goal is for the container view to have no layout at all. It should
be a completely transparent wrapper, except for when we set `display:
none` to hide its contents. On the web, the equivalent (at least in the
spec) is `display: contents`.

After some initial testing, this seems to be close enough to the desired
behavior that we can ship it. We'll try rolling it out behind a flag.
2021-08-03 19:26:49 -07:00
Sinan Sonmez (Chaush)
8a37b0ef3f typos fixed (#21955) 2021-08-03 14:05:20 -04:00
Brian Vaughn
e3049bb850 DevTools scheduling profiler: Add React component measures (#22013) 2021-08-03 13:03:29 -04:00
Vyacheslav 'SLEL' Solomin
b54f36f2b6 [DevTools] Fix: highlight updates with memoized components (#22008) 2021-08-03 11:50:00 -04:00
Kevin Chavez
3a1dc3ec85 Switch on enableProfilerChangedHookIndices flag for OSS devtools builds (#22011) 2021-08-03 08:55:15 -04:00
Brian Vaughn
42251331d8 DevTools: Scheduling profiler (#22006) 2021-08-02 14:30:43 -04:00
houssemchebeb
e3b76a85c5 Devtools: Refactor imperative theme code (#21950)
Co-authored-by: Brian Vaughn <bvaughn@fb.com>
2021-08-02 11:20:04 -04:00
Ryota Murakami
d3f8747c8d [DevTools] Disable sizeBot on DevTools Rull Request (#21885)
* [DevTools] Disable sizeBot on DevTools Rull Request

Because DevTools code doesn't affect production bundle size.
Meaningless sizeBot comment give us frastration within Pull Request discussion.

* Revert "[DevTools] Disable sizeBot on DevTools Rull Request"

This reverts commit a43aab9207d4abc85b60c22b21a374fc54b1c6ea.

* check whether devtools package file only committed
2021-08-02 09:51:53 -04:00
Brian Vaughn
d1a58da55d Optimized DevTools extension images 2021-08-02 09:32:46 -04:00
Ilham Syahid S
dfd9d62636 [DevTools] Optimize Images yarn command (part 2) (#21968) 2021-08-02 09:32:17 -04:00
Brian Vaughn
27bf6f9a83 Scheduling profiler UX changes (#21990) 2021-08-02 09:23:48 -04:00
Juan
b537247678 New devtools test for named hooks verifying case when hooks are used indirectly (#21996)
## Summary
Adds a new unit test to `parseHookNames-test` which verifies that we correctly give names to hooks when they are used indirectly: 

e.g.
```
  const countState = useState(0);
  const count = countState[0];
  const setCount = countState[1];
``` 

Should produce `count` as the name.

## Test plan

```
yarn test
yarn test-build-devtools
yarn test-build-devtools parseHookNames
```
2021-07-30 17:10:46 -04:00
Andrew Clark
f0d354efc6 [Fabric] Fix reparenting bug in legacy Suspense mount (#21995)
* Add reparenting invariant to React Noop

Fabric does not allow nodes to be reparented, so I added the equivalent
invariant to React Noop's so we can catch regressions.

This causes some tests to fail, which I'll fix in the next step.

* Fix: Use getOffscreenContainerProps

The type of these props is different per renderer. An oversight
from #21960. Unfortunately wasn't caught by Flow because fiber props
are `any`-typed.

* [Fabric] Fix reparenting in legacy Suspense mount

Fixes a weird case during legacy Suspense mount where the offscreen host
container of a tree that suspends during initial mount is recreated
instead of cloned, since there's no current fiber to clone from.

Fabric considers this a reparent even though the parent from the first
pass never committed.

Instead we can override the props from the first pass before the
container completes. It's a bit of a hack, but no more so than the rest
of the legacy root Suspense implementation — the hacks are designed
to make it usable by non-strict mode-compliant trees.
2021-07-30 12:47:40 -07:00
Shubham Pandey
6f3fcbd6fa Some remaining instances of master to main (#21982)
Co-authored-by: Shubham Pandey <shubham.pandey@mfine.co>
2021-07-30 08:56:55 -04:00
Andrew Clark
34308b5ada Tidy up early bailout logic at start of begin phase (#21852)
* Extract early bailout to separate function

This block is getting hard to read so I moved it to a separate function.
I'm about to refactor the logic that wraps around this path.

Ideally this early bailout path would happen before the begin phase
phase. Perhaps during reconcilation of the parent fiber's children.

* Extract state and context check to separate function

The only reason we pass `updateLanes` to some begin functions is to
check if we can perform an early bail out. But this is also available
as `current.lanes`, so we can read it from there instead.

I think the only reason we didn't do it this way originally is because
components that have two phases — error and Suspense boundaries —
use `workInProgress.lanes` to prevent a bail out, since during the
initial render there is no `current`. But we can check the `DidCapture`
flag instead, which we use elsewhere to detect the second phase.
2021-07-29 06:59:59 -07:00
Brian Vaughn
d9dd96530f Added testing instructions to devtools contributing guide 2021-07-28 19:05:01 -04:00
Piotr Szulc
9f88b5355b Devtools: Display as link if value is in specified protocols (#21964) 2021-07-28 09:29:13 -04:00
Sebastian Markbåge
321087d134 [Fizz] Don't add aborted segments to the completedSegments list (#21976)
* Don't add aborted segments to the completedSegments list

* Update error message to include aborted status
2021-07-27 21:53:37 -04:00
Brian Vaughn
cdccdbe171 Display warnings in tooltips for native events that render sync updates (#21975) 2021-07-27 17:22:44 -04:00
Brian Vaughn
d95434082f Scheduling profiler: UX tweaks (#21971) 2021-07-27 14:34:05 -04:00
Brian Vaughn
87239321b0 Sceduling profiler: Added custom view cursors (#21970) 2021-07-27 12:23:01 -04:00
Timothy Yung
4cc8ec64c2 Separate unit tests for ReactFabricHostComponent (#21969) 2021-07-26 23:45:26 -07:00
Timothy Yung
d4d7864934 Fix ReactFabricHostComponent methods if detached (#21967) 2021-07-26 21:02:06 -07:00
Brian Vaughn
c21e8fccad Scheduling profiler: Improve native events UI (#21966)
Also highlight events that have synchronous updates inside of them. (We may want to relax this highlighting later to not warn about event handlers that are still fast enough.)
2021-07-26 19:30:43 -04:00
Andrew Clark
392253a774 [Fabric] Use container node to toggle the visibility of Offscreen and Suspense trees (#21960)
* Fix type of Offscreen props argument

Fixes an oversight from a previous refactor. The fiber that wraps
a Suspense component's children used to be a Fragment but now it's on
Offscreen fiber, so its props type has changed. There's a special
hydration path where I forgot to update this. This isn't observable
because we don't ever end up rendering this particular fiber (because
the Suspense boundary is in its fallback state) but we should fix it
anyway to avoid a potential regression in the future.

* Extract createOffscreenFromFiber logic

...into a new method called `createWorkInProgressOffscreenFiber`. Just
for symmetry with `updateWorkInProgressOffscreenFiber`. Doesn't change
any behavior.

* [Fabric] Use container node to hide/show tree

This changes how we hide and show the contents of Offscreen boundaries
in the React Fabric renderer (persistent mode), and also Suspense
boundaries which use the same feature.=

The way it used to work was that when a boundary is hidden, in the
complete phase, instead of calling the normal `cloneInstance` method
inside `appendAllChildren`, we would call a forked method called
`cloneHiddenInstance` for each of the nearest host nodes within the
subtree. This design was largely based on how it works in React DOM
(mutation mode), where instead of cloning the nearest host nodes, we
mutate their `style.display` property.

The motivation for doing it this way in React DOM was because there's no
built-in browser API for hiding a collection of DOM nodes without
affecting their layout.

In Fabric, however, there is no such limitation, so we can instead wrap
in an extra host node and apply a hidden style.

The immediate motivation for this change is that Fabric on Android has a
view pooling mechanism for instances that relies on the assumption that
a current Fiber that is cloned and replaced by a new Fiber will never
appear in a future commit. When this assumption is broken, it may cause
crashes. In the current implementation, that can indeed happen when a
node that was previously hidden is toggled back to visible. Although
this change sidesteps the issue, we may introduce in other features in
the future that would benefit from being able to revert back to an older
node without cloning it again, such as animations.

The way I've implemented this is to insert an additional HostComponent
fiber as the child of each OffscreenComponent. The extra fiber is not
ideal — the way I'd prefer to do it is to attach the host instance to
the OffscreenComponent. However, the native Fabric implementation
currently expects a 1:1 correspondence between HostComponents and host
instances, so I've deferred that optimization to a future PR to derisk
fixing the Fabric pooling crash. I left a TODO in the host config with a
description of the remaining steps, but this alone should be sufficient
to unblock.
2021-07-26 13:17:08 -07:00
Andrew Clark
419cc9c379 Fix: Hide new/updated nodes in already hidden tree (#21929)
When a new node is added to an already hidden Offscreen tree, we need
to schedule a visibility effect to hide it. Previously we would only
hide when the boundary initially switches from visible to hidden, which
meant that newly inserted nodes would be visible.

We need to do the same thing for nodes that are updated, because the
update might affect the DOM node's `style.display` property.

The implementation is to check the `subtreeFlags` for an Insertion or
Update effect.

This only affects Offscreen, not Suspense, because Suspense boundaries
cannot be updated while in their fallback (hidden) state.

And it only affects mutation mode, because in persistent mode we
implement hiding by cloning the host tree during the complete phase,
which already happens on every update.
2021-07-26 08:18:55 -07:00
Brian Vaughn
b1811ebf01 [DevTools] Add native events to the scheduling profiler (#21947) 2021-07-26 10:36:16 -04:00
Brian Vaughn
4758e4533e React Native: Export getInspectorDataForInstance API (#21572)
This PR exports a new top-level API, getInspectorDataForInstance, for React Native (both development and production). Although this change adds a new export to the DEV bundle, it only impacts the production bundle for internal builds (not what's published to NPM).
2021-07-26 09:56:59 -04:00
Brian Vaughn
c76e4dbbc1 Removed an accidental console.log from DevTools source code 2021-07-22 16:11:37 -04:00
Brian Vaughn
f4161c3ec7 [DRAFT] Import scheduling profiler into DevTools Profiler (#21897) 2021-07-22 13:58:57 -04:00
Andrew Clark
ae5d26154b Fix: LegacyHidden should not toggle effects (#21928)
LegacyHidden is a transitional API that we added to replace the old
`<div hidden={true} />` API that we used to use for pre-rendering. The
plan is to replace this with the Offscreen component, once it's ready.

The idea is that LegacyHidden has identical behavior to Offscreen except
that it doesn't change the behavior of effects. (Which is basically how
`<div hidden={true} />` worked — it prerendered the hidden content in
the background, but nothing else.) That way, while we're rolling this
out, we could toggle the feature behind a feature flag either for
performance testing or as a kill switch.

It looks like we accidentally enabled the effects flag for both
Offscreen _and_ LegacyHidden. I suppose it's a good thing that nobody
has complained yet, since we eventually do want to ship this
behavior everywhere?

But I do think we should remove it from LegacyHidden, and roll it out by
gating the component type in the downstream repo. That way if there's an
issue related to the use of LegacyHidden, we can disable that without
disabling the behavior for Suspense boundaries.

In retrospect, I might have implemented this as an unstable prop on
Offscreen instead of a completely separate type — though at the time,
Offscreen didn't exist. I originally added LegacyHidden to unblock the
Lanes refactor, so I could move the deprioritization logic out of the
HostComponent implementation.

Not a big deal since we're going to remove this soon. The implementation
is almost the same regardless: before disconnecting or reconnecting
the effects, check the fiber tag. The rest of the logic is the same.
2021-07-21 10:34:08 -07:00
Lucas Correia
25f09e3e4e DevTools: Parse named source AST in a worker (#21902)
Resolves #21855

Ended up using workerize in order to setup the worker once it allows easy imports (for babel's parse function) and exports.
2021-07-21 12:16:08 -04:00
Andrew Clark
9ab90de602 Clean-up: Move Offscreen logic from Suspense fiber (#21925)
Much of the visibility-toggling logic is shared between the Suspense and
Offscreen types, but there is some duplicated code that exists in both.
Specifically, when a Suspense fiber's state switches from suspended to
resolved, we schedule an effect on the parent Suspense fiber, rather
than the inner Offscreen fiber. Then in the commit phase, the Suspense
fiber is responsible for committing the visibility effect on Offscreen.

There two main reasons we implemented it this way, neither of which
apply any more:

- The inner Offscreen fiber that wraps around the Suspense children used
  to be conditionally added only when the boundary was in its fallback
  state. So when toggling back to visible, there was no inner fiber to
  handle the visibility effect. This is no longer the case — the
  primary children are always wrapped in an Offscreen fiber.
- When the Suspense fiber is in its fallback state, the inner Offscreen
  fiber does not have a complete phase, because we bail out of
  rendering that tree. In the old effects list implementation, that
  meant the Offscreen fiber did not get added to the effect list, so
  it didn't have a commit phase. In the new recursive effects
  implementation, there's no list to maintain. Marking a flag on the
  inner fiber is sufficient to schedule a commit effect.

Given that these are no relevant, I was able to remove a lot of old
code and shift more of the logic out of the Suspense implementation
and into the Offscreen implementation so that it is shared by both.
(Being able to share the implementaiton like this was in fact one of
the reasons we stopped conditionally removing the inner
Offscreen fiber.)

As a bonus, this happens to fix a TODO in the Offscreen implementation
for persistent (Fabric) mode, where newly inserted nodes inside an
already hidden tree must also be hidden. Though we'll still need to
make this work in mutation (DOM) mode, too.
2021-07-20 16:05:16 -07:00
Andrew Clark
5c6543771b Fix global reference to Promise (#21926)
Referencing Promise without a type check will throw in environments
where Promise is not defined.

We will follow up with a lint rule that restricts access to all globals
except in dedicated module indirections.
2021-07-20 15:39:57 -07:00
Deniz Susman
3f62dec84a Typo fix (#21729)
emitted instead of emmitted
2021-07-19 17:19:52 -04:00
Ricky
5579f1dc87 Update test comments with explanations (#21857) 2021-07-19 15:07:38 -04:00
Christian Schulze
9b76d2d7b3 react-devtools: set icon on macos (#21908) 2021-07-19 10:26:41 -04:00
Andrew Clark
262ff7ad2c Refactor "disappear" logic into its own traversal (#21901)
Similar to #21898, but for "disappear" logic. Previously this lived
inside `hideOrUnhideAllChildren`, the function that mutates the nearest
DOM nodes to override their `display` style.

This makes the feature work in persistent mode (Fabric); it didn't
before because `hideOrUnhideAllChildren` only runs in mutation mode.
2021-07-16 15:58:11 -07:00
Andrew Clark
34600f4fad Refactor "reappear" logic into its own traversal (#21898)
When a Suspense boundary switches to its fallback state — or similarly,
when an Offscreen boundary switches from visible to hidden — we unmount
all its layout effects. When it resolves — or when Offscreen switches
back to visible — we mount them again. This "reappearing" logic
currently happens in the same commit phase traversal where we perform
normal layout effects.

I've changed it so that the "reappear" logic happens in its own
recurisve traversal that is separate from the commit phase one.

In the next step, I will do the same for the "disappear" logic that
currently lives in the `hideOrUnhideAllChildren` function.

There are a few reasons to model it this way, related to future
Offscreen features that we have planned. For example, we intend to
provide an imperative API to "appear" and "reappear" all the effects
within an Offscreen boundary. This API would be called from outside the
commit phase, during an arbitrary event. Which means it can't rely on
the regular commit phase — it's not part of a commit. This isn't the
only motivation but it illustrates why the separation makes sense.
2021-07-16 15:05:39 -07:00
Ricky
310187264d Clean up flushSync flow types (#21887) 2021-07-16 10:37:57 -04:00
Brian Vaughn
d0ec283819 DevTools 4.13.5 -> 4.14.0 2021-07-16 00:25:01 -04:00
Brian Vaughn
6840c98c32 Remove named hooks feature flag (#21894) 2021-07-16 00:14:20 -04:00
Brian Vaughn
e26cb8f86d Clear named hooks Suspense and AST cache after a Fast Refresh (#21891) 2021-07-15 23:39:30 -04:00
Ricky
682bbd0e72 Cache local reference to global Promise (#21886) 2021-07-15 12:39:56 -04:00
houssemchebeb
d5de45820a Fix typo (#21671) 2021-07-14 20:42:54 -04:00
Steve Rubin
232c67e911 Devtools Profiler: allow user to enter commit number (#19957)
Co-authored-by: Brian Vaughn <bvaughn@fb.com>
2021-07-14 20:37:02 -04:00
Brian Vaughn
87b3ada89d DevTools: Named hooks supports "cheap-module-source-map" (#21874)
"cheap-module-source-map" is the default source-map generation mode used in created-react-dev mode because of speed. The major trade-off is that the source maps generated don't contain column numbers, so DevTools needs to be more lenient when matching AST nodes in this mode.

In this case, it can ignore column numbers and match nodes using line numbers only– so long as only a single node matches. If more than one match is found, treat it the same as if none were found, and fall back to no name.
2021-07-14 14:37:27 -04:00
Andrew Clark
a97b5ac078 [Bugfix] Don't hide/unhide unless visibility changes (#21875)
* Use Visibility flag to schedule a hide/show effect

Instead of the Update flag, which is also used for other side-effects,
like refs.

I originally added the Visibility flag for this purpose in #20043 but
it got reverted last winter when we were bisecting the effects refactor.

* Added failing test case

Co-authored-by: Brian Vaughn <bvaughn@fb.com>
2021-07-14 10:37:10 -07:00
Andrew Clark
f0efb7b70f Add comment support to @gate pragma (#21881)
So you can more easily comment on why a test is gated.
2021-07-14 10:36:24 -07:00
Andrew Clark
81346764bb Run persistent tests in more configurations in CI (#21880)
I noticed that `enableSuspenseLayoutEffectSemantics` is not fully
implemented in persistent mode. I believe this was an oversight
because we don't have a CI job that runs tests in persistent mode and
with experimental flags enabled.

This adds additional test configurations to the CI job so we don't miss
stuff like this again. It doesn't fix the failing tests — I'll address
that separately.
2021-07-14 08:40:20 -07:00
Sebastian Silbermann
9090257e6e fix: restore execution context after RetryAfterError completed (#21766)
* test: Add failing test due to executionContext not being restored

* fix: restore execution context after RetryAfterError completed

* Poke codesandbox/ci

* Completely restore executionContext

* expect a specific error
2021-07-13 22:38:25 +01:00
Brian Vaughn
9fec3f2add DevTools: Ignore multiple sourceMappingUrls for external source maps (#21871)
Added an edge case regression test and bugfix.
2021-07-13 16:39:29 -04:00
Ricky
14bac6193a Allow components to render undefined (#21869) 2021-07-13 15:48:11 -04:00
Brian Vaughn
87b67d319f Enable scheduling profiler flag for react-dom profiling builds (#21867) 2021-07-13 13:41:19 -04:00
Brian Vaughn
64bbd7a7f1 Adjust Error stack columns numbers by 1 (#21865)
To account for differences between error stacks (1-based) and ASTs (0-based). In practice this change should not make an observable difference.
2021-07-13 13:28:01 -04:00
Ehsan Hosseini
464f275724 Update link to flow (#21862)
`main` branch does not exist in the `flow` project and it is `master`.

Co-authored-by: Ehsan Hosseini <53467610+dh-hosseini@users.noreply.github.com>
2021-07-13 10:55:54 -04:00
Ehsan Hosseini
b03293faaa Fix link to fbjs (#21863)
`fbjs` doesn't have the `main` branch and it is `master`
2021-07-13 10:55:33 -04:00
Dan Abramov
9f5224a9c6 Restore DevTools console message (#21864) 2021-07-13 15:41:51 +01:00
Andrew Clark
a4ecd85e86 act: Batch updates, even in legacy roots (#21797)
In legacy roots, if an update originates outside of `batchedUpdates`,
check if it's inside an `act` scope; if so, treat it as if it were
batched. This is only necessary in legacy roots because in concurrent
roots, updates are batched by default.

With this change, the Test Utils and Test Renderer versions of `act` are
nothing more than aliases of the isomorphic API (still not exposed, but
will likely be the recommended API that replaces the others).
2021-07-12 17:15:20 -07:00
Ricky
c2c6ea1fde Capture suspense boundaries with undefined fallbacks (#21854) 2021-07-12 14:50:33 -04:00
Andrew Clark
bfa50f8272 Inline discreteUpdates (#21784)
This API is only used by the event system, to set the event priority for
the scope of a function. We don't need it anymore because we can modify
the priority directly, like we already do for continuous input events.
2021-07-12 07:55:09 -07:00
Andrew Clark
0f09f14ae6 Check if already rendering before flushing
Forgot to stage this before committing 54e88ed12

I don't think is currently observable but should include the guard to
protect against regressions (though this whole block will be deleted
along with legacy mode, anyway).
2021-07-10 18:02:00 -04:00
Andrew Clark
54e88ed12c Bugfix: Flush legacy sync passive effects at beginning of event (#21846)
* Re-land recent flushSync changes

Adds back #21776 and #21775, which were removed due to an internal
e2e test failure.

Will attempt to fix in subsequent commits.

* Failing test: Legacy mode sync passive effects

In concurrent roots, if a render is synchronous, we flush its passive
effects synchronously. In legacy roots, we don't do this because all
updates are synchronous — so we need to flush at the beginning of the
next event. This is how `discreteUpdates` worked.

* Flush legacy passive effects at beginning of event

Fixes test added in previous commit.
2021-07-10 11:15:11 -07:00
Andrew Clark
cb8afda183 Add test for #21837 (#21842)
Taken from https://github.com/facebook/react/pull/21837#issuecomment-876788973

Co-Authored-By: Timothy Yung <yungsters@fb.com>

Co-authored-by: Timothy Yung <yungsters@fb.com>
2021-07-08 20:01:29 -07:00
Andrew Clark
f85f429d55 Use act() in ReactFabric tests (#21839) (#21841)
Co-authored-by: Timothy Yung <yungsters@fb.com>
2021-07-08 19:35:46 -07:00
Timothy Yung
84639ab53f Guard against reused fibers in React Native commands (#21837) 2021-07-08 16:01:51 -07:00
Timothy Yung
c549bc4918 Revert "Use act() in ReactFabric tests (#21839)" (#21840)
This reverts commit 59d3aca686.
2021-07-08 15:05:51 -07:00
Timothy Yung
59d3aca686 Use act() in ReactFabric tests (#21839) 2021-07-08 15:02:02 -07:00
Brian Vaughn
25984e5231 Update CONTRIBUTING.md 2021-07-08 17:38:59 -04:00
Brian Vaughn
32d88d4332 DevTools: Don't load source files contaning only unnamed hooks (#21835)
This wastes CPU cycles.
2021-07-08 16:46:17 -04:00
Brian Vaughn
f52b73f9d0 DevTools: Update named hooks match to use column number also (#21833)
This prevents edge cases where AST nodes are incorrectly matched.
2021-07-08 16:12:22 -04:00
Brian Vaughn
92af60afb2 Update CONTRIBUTING.md 2021-07-08 14:37:13 -04:00
Brian Vaughn
27423de395 Update CONTRIBUTING.md 2021-07-08 14:28:53 -04:00
Brian Vaughn
8148fe5ff4 Added DevTools CONTRIBUTING guide 2021-07-08 14:11:30 -04:00
Brian Vaughn
92f3414d03 Reset inspected element cache in the event of an error (#21821) 2021-07-08 14:07:15 -04:00
Brian Vaughn
feb2f6892a DevTool: hook names cache no longer loses entries between selection (#21831)
Made several changes to the hooks name cache to avoid losing cached data between selected elements:
1. No longer use React-managed cache. This had the unfortunate side effect of the inspected element cache also clearing the hook names cache. For now, instead, a module-level WeakMap cache is used. This isn't great but we can revisit it later.
2. Hooks are no longer the cache keys (since hook objects get recreated between element inspections). Instead a hook key string made of fileName + line number + column number is used.
3. If hook names have already been loaded for a component, skip showing the load button and just show the hook names by default when selecting the component.
2021-07-08 13:54:16 -04:00
Shannon Feng
241485a2c4 [SSR2 Fixture] Delete duplicate DOCTYPE (#21824) 2021-07-08 03:11:42 +01:00
Brian Vaughn
8b34d5a905 DevTools show error icon when hook name parsing fails (#21820) 2021-07-07 16:27:39 -04:00
Brian Vaughn
9ccc25a0ea Reverting recent flushSync changes (#21816) 2021-07-07 15:07:55 -04:00
Brian Vaughn
b6258b05f4 DevTools named hooks: Support FLow syntax (#21815)
Detect Flow pragma (@flow) and use Flow plug-in instead of TypeScript (default)
2021-07-07 14:29:41 -04:00
Brian Vaughn
42b3c89c57 DevTooks: Don't dehydrate hook source fileNames (#21814) 2021-07-07 14:24:17 -04:00
Moti Zilberman
9c7f29ebe7 [WIP] DevTools: Support named hooks for >1 module in a bundle (#21790)
* Add named hooks test case built with Rollup

* Fix prepareStackTrace unpatching, remove sourceURL

* Prettier

* Resolve source map URL/path relative to the script

* Add failing tests for multi-module bundle

* Parse hook names from multiple modules in a bundle

* Create a HookSourceData per location key (file, line, column).
* Cache the source map per runtime URL ( = file part of location key).
* Don't store sourceMapContents - only store a consumer instance.
* Look up original source URLs in the source map correctly.
* Cache the code + AST per original URL.
* Fix off-by-one column number lookup.
* Some naming and typing tweaks related to the above.
* Stop storing the consumer outside the with() callback, which is a bug.

* Lint fix for 8d8dd25

* Added devDependencies to react-devtools-extensions package.json

* Added some debug logging and TODO comments

* Added additional DEBUG logging to hook names cache

Co-authored-by: Brian Vaughn <bvaughn@fb.com>
2021-07-07 13:07:58 -04:00
Andrew Clark
ed6c091fe9 Replace unbatchedUpdates with flushSync (#21776)
There's a weird quirk leftover from the old Stack (pre-Fiber)
implementation where the initial mount of a leagcy (ReactDOM.render)
root is flushed synchronously even inside `batchedUpdates`.

The original workaround for this was an internal method called
`unbatchedUpdates`. We've since added another API that works almost the
same way, `flushSync`.

The only difference is that `unbatchedUpdates` would not cause other
pending updates to flush too, only the newly mounted root. `flushSync`
flushes all pending sync work across all roots. This was to preserve
the exact behavior of the Stack implementation.

But since it's close enough, let's just use `flushSync`. It's unlikely
anyone's app accidentally relies on this subtle difference, and the
legacy API is deprecated in 18, anyway.
2021-07-01 15:14:07 -07:00
Andrew Clark
32eefcb3c5 Replace flushDiscreteUpdates with flushSync (#21775)
* Replace flushDiscreteUpdates with flushSync

flushDiscreteUpdates is almost the same as flushSync. It forces passive
effects to fire, because of an outdated heuristic, which isn't ideal but
not that important.

Besides that, the only remaining difference between flushDiscreteUpdates
and flushSync is that flushDiscreteUpdates does not warn if you call it
from inside an effect/lifecycle. This is because it might get triggered
by a nested event dispatch, like `el.focus()`.

So I added a new method, flushSyncWithWarningIfAlreadyRendering, which
is used for the public flushSync API. It includes the warning. And I
removed the warning from flushSync, so the event system can call that
one. In production, flushSyncWithWarningIfAlreadyRendering gets inlined
to flushSync, so the behavior is identical.

Another way of thinking about this PR is that I renamed flushSync to
flushSyncWithWarningIfAlreadyRendering and flushDiscreteUpdates to
flushSync (and fixed the passive effects thing). The point is to prevent
these from subtly diverging in the future.

* Invert so the one with the warning is the default one

To make Seb happy
2021-07-01 15:13:00 -07:00
Brian Vaughn
c5cfa71948 DevTools: Show hook names based on variable usage (#21641)
Co-authored-by: Brian Vaughn <brian.david.vaughn@gmail.com>
Co-authored-by: Saphal Patro <saphal1998@gmail.com>
Co-authored-by: VibhorCodecianGupta <vibhordelgupta@gmail.com>
2021-07-01 14:39:18 -04:00
Brian Vaughn
ab390c65ee ReactDebugHooks optionally includes fileName, and line/column numbers (#21781) 2021-07-01 13:08:46 -04:00
Brian Vaughn
6bf111772a Install nested packages from Yarn cache before running build tests (#21779) 2021-07-01 11:37:56 -04:00
Andrew Clark
c96761c7b2 Delete batchedEventUpdates (#21774)
No longer used anywhere.
2021-06-30 15:09:14 -07:00
Andrew Clark
ae5afb3b9d Simplify discreteUpdates (#21773)
Now that discrete updates are flushed synchronously in a microtask,
the `discreteUpdates` method used by our event system is only a
optimization to save us from having to check `window.event.type` on
every update. So we should be able to remove the extra logic.

Assuming this lands successfully, we can remove `batchedEventUpdates`
and probably inline `discreteUpdates` into the renderer, like we do
for continuous updates.
2021-06-30 11:29:31 -07:00
郭帅彬
3e8c86c1c8 fix: maxYieldInterval should not compare with currentTime directly in Scheduler-shouldYieldToHost 2021-06-30 10:01:04 -04:00
Sebastian Silbermann
f6112ffe5a chore: Ignore build2/ when linting (#21204) 2021-06-30 14:27:32 +01:00
dependabot[bot]
2442d988ef Bump ws from 6.1.2 to 6.2.2 in /scripts/release (#21628)
Bumps [ws](https://github.com/websockets/ws) from 6.1.2 to 6.2.2.
- [Release notes](https://github.com/websockets/ws/releases)
- [Commits](https://github.com/websockets/ws/commits)

---
updated-dependencies:
- dependency-name: ws
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-06-29 16:53:39 -04:00
dependabot[bot]
83f38d0768 Bump ecstatic from 2.2.1 to 2.2.2 in /scripts/bench (#20468)
Bumps [ecstatic](https://github.com/jfhbrook/node-ecstatic) from 2.2.1 to 2.2.2.
- [Release notes](https://github.com/jfhbrook/node-ecstatic/releases)
- [Changelog](https://github.com/jfhbrook/node-ecstatic/blob/2.2.2/CHANGELOG.md)
- [Commits](https://github.com/jfhbrook/node-ecstatic/compare/2.2.1...2.2.2)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-06-29 16:53:31 -04:00
Brian Vaughn
d483463bc8 Updated scripts and config to replace "master" with "main" branch (#21768) 2021-06-29 14:26:24 -04:00
Andrew Clark
cae635054e act: Resolve to return value of scope function (#21759)
When migrating some internal tests I found it annoying that I couldn't
return anything from the `act` scope. You would have to declare the
variable on the outside then assign to it. But this doesn't play well
with type systems — when you use the variable, you have to check
the type.

Before:

```js
let renderer;
act(() => {
  renderer = ReactTestRenderer.create(<App />);
})

// Type system can't tell that renderer is never undefined
renderer?.root.findByType(Component);
```

After:

```js
const renderer = await act(() => {
  return ReactTestRenderer.create(<App />);
})
renderer.root.findByType(Component);
```
2021-06-26 11:51:23 -07:00
Andrew Clark
e2453e2007 act: Add test for bypassing queueMicrotask (#21743)
Test for fix added in #21740
2021-06-25 12:39:46 -07:00
Brian Vaughn
73ffce1b6f DevTools: Update tests to fix warnings/errors (#21748)
Some new ones had slipped in (e.g. deprecated ReactDOM.render message from 18)
2021-06-24 22:42:44 -04:00
Dan Abramov
534c9c52ec Move error logging to update callback (#21737)
* Move error logging to update callback

This prevents double logging for gDSFE boundaries with createRoot.

* Add an explanation for the rest of duplicates
2021-06-24 20:57:10 +01:00
Dan Abramov
51b0becf3e Always keep disabled logs in the second pass (#21739)
* Add tests for disabled logs

* Always keep disabled logs in the second pass

* Jest nit

* Always use the second result
2021-06-24 19:50:07 +01:00
Brian Vaughn
386e8f2ea7 DevTools: Fix Settings dialog scroll/size bug in Firefox (#21747) 2021-06-24 11:19:57 -04:00
Dan Abramov
7fec38041f Log and show error overlay for commit phase errors (#21723)
* Enable skipped tests from #21723

* Report uncaught errors in DEV

* Clear caught error

This is not necessary (as proven by tests) because next invokeGuardedCallback clears it anyway. But I'll keep it for consistency with other calls.
2021-06-24 15:48:28 +01:00
Andrew Clark
27c9c95e23 act: Bypass microtask for "default sync" updates (#21740)
When wrapping an update in act, instead of scheduling a microtask,
we can add the task to our internal queue.

The benefit is that the user doesn't have to await the act call. We can
flush the work synchronously. This doesn't account for microtasks that
are scheduled in userspace, of course, but it at least covers
React's usage.
2021-06-23 17:32:44 -07:00
Brian Vaughn
8426bb6956 Pass Jest useStderr flag when debugging (#21741)
This prevents it from buffering adn suppressing all console logs until a test has completed running (When debugging in Chrome).
2021-06-23 16:58:46 -04:00
Dan Abramov
e577bfb1ce Add tests for invokeGuardedCallback (#21734)
* Add tests for invokeGuardedCallback

* Add skipped failing tests

* Check next render works

* Mirror tests for createRoot

* Move comments around
2021-06-23 21:47:47 +01:00
Brian Vaughn
355591add4 Next/experimental release versions include commit date (#21700)
Change format of @next and @experimental release versions from <number>-<sha> to <number>-<sha>-<date> to make them more human readable. This format still preserves the ability for us to easily map a version number to the changes it contains, while also being able to more easily know at a glance how recent a release is.
2021-06-23 13:50:09 -04:00
Andrew Clark
d7dce572c7 Remove internal act builds from public modules (#21721)
* Move internal version of act to shared module

No reason to have three different copies of this anymore.

I've left the the renderer-specific `act` entry points because legacy
mode tests need to also be wrapped in `batchedUpdates`. Next, I'll update
the tests to use `batchedUpdates` manually when needed.

* Migrates tests to use internal module directly

Instead of the `unstable_concurrentAct` exports. Now we can drop those
from the public builds.

I put it in the jest-react package since that's where we put our other
testing utilities (like `toFlushAndYield`). Not so much so it can be
consumed publicly (nobody uses that package except us), but so it works
with our build tests.

* Remove unused internal fields

These were used by the old act implementation. No longer needed.
2021-06-22 14:29:35 -07:00
Andrew Clark
06f7b4f43a act should work without mock Scheduler (#21714)
Currently, in a React 18 root, `act` only works if you mock the
Scheduler package. This was because we didn't want to add additional
checks at runtime.

But now that the `act` testing API is dev-only, we can simplify its
implementation.

Now when an update is wrapped with `act`, React will bypass Scheduler
entirely and push its tasks onto a special internal queue. Then, when
the outermost `act` scope exists, we'll flush that queue.

I also removed the "wrong act" warning, because the plan is to move
`act` to an isomorphic entry point, simlar to `startTransition`. That's
not directly related to this PR, but I didn't want to bother
re-implementing that warning only to immediately remove it.

I'll add the isomorphic API in a follow up.

Note that the internal version of `act` that we use in our own tests
still depends on mocking the Scheduler package, because it needs to work
in production. I'm planning to move that implementation to a shared
(internal) module, too.
2021-06-22 14:25:07 -07:00
Andrew Clark
422e0bb360 Delete test-utils implementation of act (#21703)
* Delete test-utils implementation of `act`

Since it's dev-only now, we can use the one provided by the reconciler.

* Move act related stuff out of EventInternals
2021-06-22 14:21:22 -07:00
Sebastian Markbåge
568dc3532e Remove unstable_createRoot from internal builds (#21698)
These callsites were already removed as far as I can tell.
2021-06-17 11:29:30 -07:00
Dan Abramov
43f4cc1608 Fix failing test (#21697) 2021-06-17 13:56:18 +01:00
Brian Vaughn
d0f348dc1b Fix for failed Suspense layout semantics (#21694)
Co-authored-by: Dan Abramov <dan.abramov@me.com>
2021-06-16 19:44:44 -04:00
Andrew Clark
bd0a963445 Throw when act is used in production (#21686)
Upgrades the deprecation warning to a runtime error.

I did it this way instead of removing the export so the type is the same
in both builds. It will get dead code eliminated regardless.
2021-06-16 16:29:51 -04:00
Dan Abramov
a0d2d1e1e1 Fix fixture lockfile manually 2021-06-16 00:04:01 +01:00
Dan Abramov
6cbf2a8b3b Add missing package lock 2021-06-15 23:52:15 +01:00
Dan Abramov
c0a77029c4 Remove unused variable 2021-06-15 23:49:41 +01:00
Dan Abramov
f283d7524a Use npm lockfile for fixture 2021-06-15 23:49:04 +01:00
Dan Abramov
03c5314b44 [SSR2 Fixture] Update APIs (#21688) 2021-06-15 23:20:51 +01:00
Sebastian Markbåge
7ec4c55971 createRoot(..., {hydrate:true}) -> hydrateRoot(...) (#21687)
This adds a new top level API for hydrating a root. It takes the initial
children as part of its constructor. These are unlike other render calls
in that they have to represent what the server sent and they can't be
batched with other updates.

I also changed the options to move the hydrationOptions to the top level
since now these options are all hydration options.

I kept the createRoot one just temporarily to make it easier to codemod
internally but I'm doing a follow up to delete.

As part of this I un-dried a couple of paths. ReactDOMLegacy was intended
to be built on top of the new API but it didn't actually use those root
APIs because there are special paths. It also doesn't actually use most of
the commmon paths since all the options are ignored. It also made it hard
to add only warnings for legacy only or new only code paths.

I also forked the create/hydrate paths because they're subtly different
since now the options are different. The containers are also different
because I now error for comment nodes during hydration which just doesn't
work at all but eventually we'll error for all createRoot calls.

After some iteration it might make sense to break out some common paths but
for now it's easier to iterate on the duplicates.
2021-06-15 13:37:53 -07:00
Sebastian Markbåge
9212d994ba Merge /unstable-fizz entry point into /server (#21684) 2021-06-14 18:37:44 -07:00
Sebastian Markbåge
9343f87203 Use the server src files as entry points for the builds/tests (#21683)
* Use the server src files as entry points for the builds/tests

We need one top level entry point to target two builds so we can't have
the top level one be the entry point for the builds.

* Same thing but with the modern entry point
2021-06-14 16:23:19 -07:00
Sebastian Markbåge
e601854f07 Clean up partial renderer entry points (#21682)
* Clean up partial renderer entry points

I made a mistake by leaving server.browser.stable in which is the partial
renderer for the browser build of stable. That should use the legacy fizz
one.

Since the only usage of the partial renderer now is at FB and we don't use
it with Node, I removed the Node build of partial renderer too.

* Remove GC test

No code is running this path anymore. Ideally this should be ported to
a Fizz form.
2021-06-14 15:44:46 -07:00
Sebastian Markbåge
502f8a2a07 [Fizz/Flight] Don't use default args (#21681)
* Don't use default args

* Hoist out creation for better inlining

The closures prevent inlining otherwise.
2021-06-14 15:28:20 -07:00
Sebastian Markbåge
bd45ad05dc Add a DOCTYPE to the stream if the <html> tag is rendered (#21680)
This makes it a lot easier to render the whole document using React without
needing to patch into the stream.

We expect that currently people will still have to patch into the stream
to do advanced things but eventually the goal is that you shouldn't
need to.
2021-06-14 13:57:17 -07:00
Dan Abramov
a8f5e77b92 Remove invokeGuardedCallback from commit phase (#21666)
* Remove invokeGuardedCallback from commit phase

* Sync fork
2021-06-14 21:45:53 +01:00
Sebastian Markbåge
dbe3363ccd [Fizz] Implement Legacy renderToString and renderToNodeStream on top of Fizz (#21276)
* Wire up DOM legacy build

* Hack to filter extra comments for testing purposes

* Use string concat in renderToString

I think this might be faster. We could probably use a combination of this
technique in the stream too to lower the overhead.

* Error if we can't complete the root synchronously

Maybe this should always error but in the async forms we can just delay
the stream until it resolves so it does have some useful semantics.

In the synchronous form it's never useful though. I'm mostly adding the
error because we're testing this behavior for renderToString specifically.

* Gate memory leak tests of internals

These tests don't translate as is to the new implementation and have been
ported to the Fizz tests separately.

* Enable Fizz legacy mode in stable

* Add wrapper around the ServerFormatConfig for legacy mode

This ensures that we can inject custom overrides without negatively
affecting the new implementation.

This adds another field for static mark up for example.

* Wrap pushTextInstance to avoid emitting comments for text in static markup

* Don't emit static mark up for completed suspense boundaries

Completed and client rendered boundaries are only marked for the client
to take over.

Pending boundaries are still supported in case you stream non-hydratable
mark up.

* Wire up generateStaticMarkup to static API entry points

* Mark as renderer for stable

This shouldn't affect the FB one ideally but it's done with the same build
so let's hope this works.
2021-06-14 12:54:30 -07:00
Dan Abramov
101ea9f55c Set deletedTreeCleanUpLevel to 3 (#21679) 2021-06-14 20:10:24 +01:00
Dan Abramov
1a106bdc2a Wrap eventhandle-specific logic in a flag (#21657) 2021-06-11 21:08:32 +01:00
Brian Vaughn
3ba2b67f21 Update react_18.md 2021-06-11 14:27:09 -04:00
Brian Vaughn
905f6f48d4 Update react_18.md 2021-06-11 14:25:47 -04:00
Brian Vaughn
ca4e650ec1 Update react_18.md 2021-06-11 14:24:09 -04:00
Brian Vaughn
42a89d5c61 Update react_18.md 2021-06-11 14:22:57 -04:00
Brian Vaughn
1e3ceadcc0 Added React 18 issue template 2021-06-11 14:19:37 -04:00
Brian Vaughn
01be61c12f DevTools can inspect Proxies that return broken iterator functions (#21660) 2021-06-11 10:15:48 -04:00
Timothy Yung
cb30388d10 Export React Native AttributeType Types (#21661) 2021-06-11 00:45:49 -07:00
Sebastian Markbåge
c1536795ca Revert "Make enableSuspenseLayoutEffectSemantics static for www (#21617)" (#21656)
This reverts commit 39f0074892.
2021-06-10 10:12:31 -07:00
Samuel Susla
c96b78e0e7 Add concurrentRoot property to ReactNativeTypes (#21648)
* Add concurrentRoot property to ReactNativeTypes

* Add concurrentRoot to ReactNativeType

* Use ReactFabricType instead of ReactNativeType
2021-06-10 08:59:22 -04:00
Andrew Clark
aecb3b6d11 Deprecate ReactDOM.render and ReactDOM.hydrate (#21652)
* Use existing test warning filter for server tests

We have a warning filter for our internal tests to ignore warnings
that are too noisy or that we haven't removed from our test suite yet:
shouldIgnoreConsoleError.

Many of our server rendering tests don't use this filter, though,
because it has its own special of asserting warnings.

So I added the warning filter to the server tests, too.

* Deprecate ReactDOM.render and ReactDOM.hydrate

These are no longer supported in React 18. They are replaced by the
`createRoot` API.

The warning includes a link to documentation of the new API. Currently
it redirects to the corresponding working group post. Here's the PR to
set up the redirect: https://github.com/reactjs/reactjs.org/pull/3730

Many of our tests still use ReactDOM.render. We will need to gradually
migrate them over to createRoot.

In the meantime, I added the warnings to our internal warning filter.
2021-06-09 13:46:55 -07:00
Samuel Susla
1a3f1afbd3 [React Native] Fabric get current event priority (#21553)
* Call into Fabric to get current event priority

Fix flow errors

* Prettier

* Better handle null and undefined cases

* Remove optional chaining and use ?? operator

* prettier-all

* Use conditional ternary operator

* prettier
2021-06-08 12:26:21 -04:00
Andrew Clark
e6be2d531d Fix tag validation 2021-06-08 11:53:43 -04:00
Andrew Clark
6bbe7c3446 Remove space from tag arguments 2021-06-08 11:40:34 -04:00
Andrew Clark
bc7d5ac99d Allow alpha tags 2021-06-08 11:31:42 -04:00
Andrew Clark
48a11a3efc Update next React version (#21647)
This does not mean that a release of 18.0 is imminent, only that the
main branch includes breaking changes.

Also updates the versioning scheme of the `@next` channel to include
the upcoming semver number, as well as the word "alpha" to indicate the
stability of the release.

- Before:       0.0.0-e0d9b28999
- After:        18.0.0-alpha-e0d9b28999
2021-06-08 08:26:22 -07:00
Sebastian Markbåge
5aa0c5671f Fix Issue with Undefined Lazy Imports By Refactoring Lazy Initialization Order (#21642)
* Add a DEV warning for common case

* Don't set Pending flag before we know it's a promise

* Move default exports extraction to render phase

This is really where most unwrapping happen. The resolved promise is the
module object and then we read things from it.

This way it lines up a bit closer with the Promise model too since the
promise resolving to React gets passed this same value.

If this throws, then it throws during render so it's caught properly and
you can break on it and even see it on the right stack.

* Check if the default is in the module object instead of if it's undefined

Normally we'd just check if something is undefined but in this case it's
valid to have an undefined value in the export but if you don't have a
property then you're probably importing the wrong kind of object.

* We need to check if it's uninitialized for sync resolution

Co-authored-by: Dan Abramov <dan.abramov@me.com>
2021-06-07 14:47:18 -07:00
ithinker5
0eea577248 Fix typo in comment (accumlated → accumulated) (#21637)
Co-authored-by: HuJiajie <hujj@firstgrid.cn>
2021-06-07 08:52:49 -04:00
niexq
0706162ba7 Fix typo in comment (environement → environment) (#21635) 2021-06-07 08:52:42 -04:00
niexq
9d17b562ba Fix typo in comment (satsify → satisfy) (#21629) 2021-06-05 14:02:15 -04:00
Shannon Feng
b610fec00c fix comments: expiration time -> lanes (#21551) 2021-06-05 07:19:40 -07:00
Dan Abramov
23c80959ad Fix CSS 2021-06-04 23:12:01 +01:00
Dan Abramov
2568fecc38 Tweak fixture 2021-06-04 23:10:02 +01:00
Dan Abramov
fccfc24893 [Fizz] Add another fixture (#21627) 2021-06-04 23:04:06 +01:00
Dan Abramov
cc4d24ab0b [Fizz] Always call flush() if it exists (#21625) 2021-06-04 20:17:57 +01:00
Ikko Ashimine
46926993fc Fix typo in bridge.js (#21621) 2021-06-04 11:42:09 -04:00
Sebastian Markbåge
e0d9b28999 [Fizz] Minor Fixes for Warning Parity (#21618) 2021-06-03 19:54:31 -04:00
Sebastian Markbåge
1b7b3592f4 [Fizz] Implement Component Stacks in DEV for warnings (#21610)
* Implement component stacks

This uses a reverse linked list in DEV-only to keep track of where we're
currently executing.

* Fix bug that wasn't picking up the right stack at suspended boundaries

This makes it more explicit which stack we pass in to be retained by the
task.
2021-06-03 13:02:41 -07:00
Brian Vaughn
39f0074892 Make enableSuspenseLayoutEffectSemantics static for www (#21617)
This has been ramped up to 80% GK so the next step is to just turn it on for 100%
2021-06-03 15:40:59 -04:00
Andrew Clark
7747a5684d Support @latest in prepare-release-from-ci (#21616)
Since we track these versions in source, we can build `@latest`
releases in CI and store them as artifacts.

Then when it's time to release, and the build has been verified, we use
`prepare-release-from-ci` (the same script we use for `@next` and
`@experimental`) to fetch the already built and versioned packages.
2021-06-03 11:00:08 -07:00
Andrew Clark
8f37942765 Prepare semver (@latest) releases in CI (#21615)
Now that we track package versions in source, `@latest` builds should
be fully reproducible for a given commit. We can prepare the packages in
CI and store them as artifacts, the same way we do for `@next` and
`@experimental`.

Eventually this can replace the interactive script that we currently
use to swap out the version numbers.

The other nice thing about this approach is that we can run tests in CI
to verify that the packages are releasable, instead of waiting until
right before publish.

I named the output directory `oss-stable-semver`, to distinguish from
the `@next` prereleases that are located at `oss-stable`. I don't love
this naming. I'd prefer to use the name of the corresponding npm dist
tag. I'll do that in a follow-up, though, since the `oss-stable` name is
referenced in a handful of places.

Current naming (after this PR):

- `oss-experimental` → `@experimental`
- `oss-stable` → `@next`
- `oss-stable-semver` → `@latest`

Proposed naming (not yet implemented, requires more work):

- `oss-experimental` → `@experimental`
- `oss-next` → `@next`
- `oss-latest` → `@latest`
2021-06-03 10:26:11 -07:00
Andrew Clark
44cdfd6b7a Use ReactVersions module as package allowlist (#21613)
Instead of keeping a separate allowlist in sync, we use ReactVersions.js
as the source of truth for which packages get published.
2021-06-03 11:45:10 -04:00
Bao Pham
8b4201535c Devtools: add feature to trigger an error boundary (#21583)
Co-authored-by: Brian Vaughn <bvaughn@fb.com>
2021-06-03 11:21:44 -04:00
Sebastian Markbåge
2418f24b60 Fix <select> check of defaultValue/value type (#21611) 2021-06-03 09:13:00 -04:00
Andrew Clark
154a8cf328 Fix reference to wrong variable
Follow-up to #21608
2021-06-03 00:23:08 -04:00
Andrew Clark
6736a38b9a Add single source of truth for package versions (#21608)
The versioning scheme for `@next` releases does not include semver
information. Like `@experimental`, the versions are based only on the
hash, i.e. `0.0.0-<commit_sha>`. The reason we do this is to prevent
the use of a tilde (~) or caret (^) to match a range of
prerelease versions.

For `@experimental`, I think this rationale still makes sense — those
releases are very unstable, with frequent breaking changes. But `@next`
is not as volatile. It represents the next stable release. So, I think
we can afford to include an actual verison number at the beginning of
the string instead of `0.0.0`.

We can also add a label that indicates readiness of the upcoming
release, like "alpha", "beta", "rc", etc.

To prepare for this the new versioning scheme, I updated the build
script. However, **this PR does not enable the new versioning scheme
yet**. I left a TODO above the line that we'll change once we're ready.

We need to specify the expected next version numbers for each package,
somewhere. These aren't encoded anywhere today — we don't specify
version numbers until right before publishing to `@latest`, using an
interactive script: `prepare-release-from-npm`.

Instead, what we can do is track these version numbers in a module. I
added `ReactVersions.js` that acts as the single source of truth for
every package's version. The build script uses this module to build the
`@next` packages.

In the future, I want to start building the `@latest` packages the same
way we do `@next` and `@experimental`. (What we do now is download a
`@next` release from npm and swap out its version numbers.) Then we
could run automated tests in CI to confirm the packages are releasable,
instead of waiting to verify that right before publish.
2021-06-02 20:54:26 -07:00
Sebastian Markbåge
86715efa23 Resolve the true entry point during tests (#21505)
* Resolve the entry point for tests the same way builds do

This way the source tests, test the same entry point configuration.

* Gate test selectors on www

These are currently only exposed in www builds

* Gate createEventHandle / useFocus on www

These are enabled in both www variants but not OSS experimental.

* Temporarily disable www-modern entry point

Use the main one that has all the exports until we fix more tests.

* Remove enableCache override that's no longer correct

* Open gates for www

These used to not be covered because they used Cache which wasn't exposed.
2021-06-02 18:03:29 -07:00
Sebastian Markbåge
a8a4742f1c Convert ES6/TypeScript/CoffeeScript Tests to createRoot + act (#21598)
* Convert ES6/TypeScript CoffeeScript Tests to createRoot + act

* Change expectation for WWW+VARIANT because the deferRenderPhaseUpdateToNextBatch flag breaks this behavior
2021-06-02 11:36:59 -07:00
Sebastian Markbåge
1d3558965f Disable deferRenderPhaseUpdateToNextBatch by default (#21605)
We're still experimenting with this and it causes a breaking behavior
for setState in componentWillMount/componentWillReceiveProps atm.
2021-06-02 11:28:06 -07:00
okmttdhr
a8964649bb Delete an unused field (#21415) 2021-06-02 16:24:40 +01:00
Dan Abramov
76f85b3e50 Expose Fizz in stable builds (#21602) 2021-06-02 16:13:19 +01:00
Andrew Clark
e16d61c300 [Offscreen] Mount/unmount layout effects (#21386)
* [Offscreen] Mount/unmount layout effects

Exposes the Offscreen component type and implements basic support for
mount/unmounting layout effects when the visibility is toggled.

Mostly it works the same way as hidden Suspense trees, which use the
same internal fiber type. I had to add an extra bailout, though, that
doesn't apply to the Suspense case but does apply to Offscreen
components: a hidden Offscreen tree will eventually render at low
priority, and when we it does, its `subtreeTag` will have effects
scheduled on it. So I added a check to the layout phase where, if the
subtree is hidden, we skip over the subtree entirely. An alternate
design would be to clear the subtree flags in the render phase, but I
prefer doing it this way since it's harder to mess up.

We also need an API to enable the same thing for passive effects. This
is not yet implemented.

* Add test starting from hidden

Co-authored-by: Rick Hanlon <rickhanlonii@gmail.com>
2021-06-01 12:46:08 -07:00
Brian Vaughn
63091939bd OSS feature flag updates (#21597)
Co-authored-by: Dan Abramov <dan.abramov@me.com>
2021-06-01 13:44:10 -04:00
Sebastian Markbåge
efbd69b27e Define global __WWW__ = true flag during www tests (#21504)
* Define global __WWW__ = true flag during www tests

We already do that for __PERSISTENT__.

* Use @gate www in ReactSuspenseCallback

This allows it to not be internal anymore. We test it against the www build.
2021-06-01 10:16:06 -07:00
Sebastian Markbåge
8f6163cbed Fix Fizz exported types (#21596) 2021-06-01 10:02:04 -07:00
Brian Vaughn
28625c6f45 Disable strict effects for legacy roots (again) (#21591) 2021-05-31 13:05:50 -04:00
Brian Vaughn
d75105fa92 DevTools: Format error message (#21580)
To support GitHub API fuzzy issue search
2021-05-27 15:44:14 -04:00
Sebastian Silbermann
3c2341416a Update jest to v26 (#21574)
* Install jest 26

* jsdom env now uses 16 by default

* require.requireActual -> jest.requireActual

* deduplicate added deps
2021-05-27 16:33:57 +01:00
Brian Vaughn
5151466bab Updated DevTools bug Workflow
Workflow now auto-assigns issues needing more information to the person who reported them
2021-05-27 09:49:44 -04:00
Pulkit Sharma
0d493dcda9 Removed _debugID field from Fiber - Issue #21558 (#21570)
* Removed _debugID field from Fiber
* Update ReactFunctionComponent-test.js

Co-authored-by: Brian Vaughn <brian.david.vaughn@gmail.com>
2021-05-26 16:53:18 -04:00
Brian Vaughn
bb1c821556 Fixed localhost URL check
Noticed that it missed 21568 because of a leading "/"
2021-05-26 10:43:51 -04:00
Brian Vaughn
7841d0695a Enable the updater-tracking feature flag in more builds (#21567) 2021-05-25 17:41:19 -04:00
Brian Vaughn
6405efc368 Enabled Profiling feature flags for OSS release (#21565)
* Enabled Profiling feature flags for OSS release

`enableProfilerCommitHooks` and `enableProfilerNestedUpdatePhase`
2021-05-25 17:32:14 -04:00
Brian Vaughn
0ae5290b54 DevTools 4.13.4 -> 4.13.5 2021-05-25 15:18:47 -04:00
Brian Vaughn
965fb8be6b DevTools: Support an element mounting before its owner (#21562) 2021-05-25 14:49:05 -04:00
Ricky
2d8d133e17 Turn on enableSyncDefaultUpdates everywhere (#21548) 2021-05-25 11:21:58 -04:00
Samuel Susla
459c34fde6 Add flag concurrent root to Fabric render function (#21552)
* Add flag concurrent root to Fabric render function

* Lint
2021-05-24 10:56:47 -04:00
Brian Vaughn
a731a51696 Add GitHub action to check for bug repro (#21542) 2021-05-21 15:48:12 -04:00
Brian Vaughn
51ebccc374 DevTools: Add 4.13.4 changelog 2021-05-20 17:00:17 -04:00
Brian Vaughn
97c25b0e9c DevTools: Add 4.10.4 to CHANGELOG 2021-05-20 16:31:18 -04:00
Brian Vaughn
45f1a4a33f DevTools: Revert force deep re-mount when Fast Refresh detected (#21539)
This reverts the most expensive part of 1e3383a41 (which seems to no longer be necessary after subsequent changes).
2021-05-20 15:28:59 -04:00
Brian Vaughn
e0bffeeb01 Update devtools_bug_report.yml 2021-05-20 14:52:08 -04:00
Brian Vaughn
549aaacbb0 Update devtools_bug_report.yml 2021-05-20 14:51:35 -04:00
Brian Vaughn
132b72d7b6 DevTools 4.13.3 -> 4.13.4 2021-05-20 11:24:30 -04:00
Brian Vaughn
b8bbb6a13d Fix edge-case Fast Refresh bug that caused Fibers with warnings/errors to be untracked prematurely (#21536)
Refactor error/warning count tracking to avoid pre-allocating an ID for Fibers that aren't yet mounted. Instead, we store a temporary reference to the Fiber itself and later check to see if it successfully mounted before merging pending error/warning counts.

This avoids a problematic edge case where a force-remounted Fiber (from Fast Refresh) caused us to untrack a Fiber that was still mounted, resulting in a DevTools error if that Fiber was inspected in the Components tab.
2021-05-20 11:24:08 -04:00
Brian Vaughn
ebcec3cc20 Add key to inspected-element error boundary (#21535)
This way changing the selected element also recreates/resets the boundary automatically.
2021-05-19 17:38:12 -04:00
Brian Vaughn
99995c1063 Improve error boundary in inspected elements panel (#21531)
Show more info about the error as well as the option to report it to GitHub.
2021-05-19 13:27:56 -04:00
Brian Vaughn
3f8f4675d4 Updated DevTools CHANGELOG for 4.13.3 release 2021-05-19 10:59:32 -04:00
Brian Vaughn
d6604ac031 Account for another DevTools + Fast Refresh edge case (#21523)
DevTools now 'untrack' Fibers (cleans up the ID-to-Fiber mapping) after a slight delay in order to support a Fast Refresh edge case:
1. Component type is updated and Fast Refresh schedules an update+remount.
2. flushPendingErrorsAndWarningsAfterDelay() runs, sees the old Fiber is no longer mounted (it's been disconnected by Fast Refresh), and calls untrackFiberID() to clear it from the Map.
3. React flushes pending passive effects before it runs the next render, which logs an error or warning, which causes a new ID to be generated for this Fiber.
4. DevTools now tries to unmount the old Component with the new ID.

The underlying problem here is the premature clearing of the Fiber ID, but DevTools has no way to detect that a given Fiber has been scheduled for Fast Refresh. (The '_debugNeedsRemount' flag won't necessarily be set.)

The best we can do is to delay untracking by a small amount, and give React time to process the Fast Refresh delay.
2021-05-18 22:44:29 -04:00
Brian Vaughn
b15bf2b2f1 DevTools bugfix for useState() with hasOwnProperty key (#21524) 2021-05-18 16:43:33 -04:00
Brian Vaughn
343776fc90 Added React entry-points change to DevTools changelog 2021-05-18 13:25:29 -04:00
Brian Vaughn
4d402cdda0 Preparing DevTools 4.13.2 -> 4.13.3 for release 2021-05-18 13:23:06 -04:00
Brian Vaughn
63927e0843 Fixed another Symbol concatenation issue with DevTools format() util (#21521) 2021-05-18 11:46:04 -04:00
Brian Vaughn
1e3383a411 DevTools: Reload all roots after Fast Refresh force remount (#21516)
Works around the corrupted Store state by detecting a broken Fast Refresh remount and forcefully dropping the root and re-mounting the entire tree. This prevents Fibers from getting duplicated in the Store (and in the Components tree). The benefit of this approach is that it doesn't rely on an update or change in behavior to Fast Refresh. (This workaround is pretty dirty, but since it's a DEV-only code path, it's probably okay.)

Note that this change doesn't fix all of the reported issues (see #21442 (comment)) but it does fix some of them.

This commit also slightly refactors the way DevTools assigns and manages unique IDs for Fibers in the backend by removing the indirection of a "primary Fiber" and instead mapping both the primary and alternate.

It also removes the previous cache-on-read behavior of getFiberID and splits the method into three separate functions for different use cases:
* getOrGenerateFiberID – Like the previous function, this method returns an ID or generates and caches a new one if the Fiber hasn't been seen before.
* getFiberIDUnsafe – This function returns an ID if one has already been generated or null if not. (It can be used to e.g. log a message about a Fiber without potentially causing it to leak.)
* getFiberIDThrows – This function returns an ID if one has already been generated or it throws. (It can be used to guarantee expected behavior rather than to silently cause a leak.)
2021-05-18 11:42:08 -04:00
Brian Vaughn
7bef382bf9 Errors thrown by Store can be dismissed in boundary (#21520) 2021-05-18 10:36:31 -04:00
Brian Vaughn
316943091e Make StrictMode double rendering flag static for FB/www (#21517) 2021-05-18 10:07:58 -04:00
Ricky
e0f89aa056 Clean up Scheduler forks (#20915)
* Clean up Scheduler forks

* Un-shadow variables

* Use timer globals directly, add a test for overrides

* Remove more window references

* Don't crash for undefined globals + tests

* Update lint config globals

* Fix test by using async act

* Add test fixture

* Delete test fixture
2021-05-17 16:53:58 -04:00
Brian Vaughn
1a2d792503 Tweaked DevTools error template title to match issue form template 2021-05-14 10:19:58 -04:00
Brian Vaughn
9cf1069ffc DevTools: Fixed version range NPM syntax 2021-05-14 10:14:34 -04:00
Sebastian Markbåge
5890e0e692 Remove data-reactroot from server rendering and hydration heuristic (#20996)
This was used to implicitly hydrate if you call ReactDOM.render.

We've had a warning to explicitly use ReactDOM.hydrate(...) instead of
ReactDOM.render(...). We can now remove this from the generated markup.
(And avoid adding it to Fizz.)

This is a little strange to do now since we're trying hard to make the
root API work the same.

But if we kept it, we'd need to keep it in the generated output which adds
unnecessary bytes. It also risks people relying on it, in the Fizz world
where as this is an opportunity to create that clean state.

We could possibly only keep it in the old server rendering APIs but then
that creates an implicit dependency between which server API and which
client API that you use. Currently you can really mix and match either way.
2021-05-13 10:18:21 -07:00
Andrew Clark
46491dce96 [Bugfix] Prevent already-committed setState callback from firing again during a rebase (#21498)
* Failing test: Class callback fired multiple times

Happens during a rebase (low priority update followed by high priority
update). The high priority callback gets fired twice.

* Prevent setState callback firing during rebase

Before enqueueing the effect, adds a guard to check if the update was
already committed.
2021-05-12 10:40:17 -07:00
Andrew Clark
b770f75005 lint-build: Infer format from artifact filename (#21489)
Uses the layout of the build artifact directory to infer the format
of a given file, and which lint rules to apply.

This has the effect of decoupling the lint build job from the existing
Rollup script, so that if we ever add additional post-processing, or
if we replace Rollup, it will still work.

But the immediate motivation is to replace the separate "stable" and
"experimental" lint-build jobs with a single combined job.
2021-05-12 10:14:45 -07:00
Brian Vaughn
2bf4805e4b Update entry point exports (#21488)
The following APIs have been added to the `react` stable entry point:
* `SuspenseList`
* `startTransition`
* `unstable_createMutableSource`
* `unstable_useMutableSource`
* `useDeferredValue`
* `useTransition`

The following APIs have been added or removed from the `react-dom` stable entry point:
* `createRoot`
* `unstable_createPortal` (removed)

The following APIs have been added to the `react-is` stable entry point:
* `SuspenseList`
* `isSuspenseList`

The following feature flags have been changed from experimental to true:
* `enableLazyElements`
* `enableSelectiveHydration`
* `enableSuspenseServerRenderer`
2021-05-12 11:28:14 -04:00
Ricky
b8fda6cabc [React Native] Set allowConcurrentByDefault = true (#21491) 2021-05-11 10:12:46 -04:00
Brian Vaughn
3890fb52fe Update devtools_bug_report.yml 2021-05-08 10:46:02 -04:00
Brian Vaughn
57768ef90b Update devtools_bug_report.yml
Tweaked label to include emoji characters.
2021-05-07 09:10:50 -04:00
Brian Vaughn
e468072e17 Updated release scripts to work around GitHub / Circle CI integration problems (#21434) 2021-05-07 08:53:39 -04:00
Brian Vaughn
0a8fefca4c DevTools 4.13.1 -> 4.13.2 2021-05-07 08:52:02 -04:00
Brian Vaughn
6005a6ab2b Update devtools_bug_report.yml 2021-05-07 08:48:34 -04:00
Brian Vaughn
85b543c6b4 Added new GitHub issue form for React DevTools bug reports (#21450)
Added a new bug report template built with GitHub issue forms:
https://gh-community.github.io/issue-template-feedback/structured/

And updated DevTools bug report link to send information formatted for this new template.
2021-05-07 08:46:58 -04:00
faebzz
1bb8987cc9 Renamed function in error log issue #21446 (#21449) 2021-05-06 21:03:21 -04:00
Joshua Gross
bd070eb2c4 Enable setJSResponder/setIsJSResponder for React Native Fabric (#21439)
* Enable setJSResponder/setIsJSResponder for React Native

* yarn prettier

* add types to react-native-host-hooks

* yarn prettier

* mock setIsJSResponder
2021-05-05 21:09:04 -07:00
Sebastian Markbåge
46ef1ab32a Convert emulated-Fizz PartialHydration tests to Fizz tests (#21437) 2021-05-05 21:22:27 -04:00
Sebastian Markbåge
212d2909d3 [Fizz] Make some tests more resilient to implementation details (#21438)
* Make some tests resilient against changing the specifics of the HTML

This ensures that for example flipping order of attributes doesn't matter.

* Use getVisibleChildren approach for more resilient tests
2021-05-05 16:13:45 -07:00
Gang Chen
12751d2991 fix: version in nvmrc (#21430) 2021-05-05 12:39:06 -04:00
Sebastian Markbåge
8ea11306ad Allow complex objects as children of option only if value is provided (#21431) 2021-05-05 08:40:54 -07:00
Brian Vaughn
014edf1980 Prepare DevTools 4.13.1 release 2021-05-04 22:35:30 -04:00
Brian Vaughn
67ebdf88bf Fix DevTools bug with Suspense+LegacyHidden component (#21432) 2021-05-04 22:28:17 -04:00
Ricky
e9a4a44aae Add back root override for strict mode (#21428)
* Add back root override for strict mode

* Switch flag to boolean

* Fix flow
2021-05-04 15:42:48 -04:00
Brian Vaughn
d1542de3a6 Unify React.memo and React.forwardRef display name logic (#21392)
Co-authored-by: iChenLei <2470828450@qq.com>
2021-05-04 11:40:16 -04:00
Brian Vaughn
d19257b8fa DevTools Store emits errors before throwing (#21426)
The Store should never throw an Error without also emitting an event. Otherwise Store errors will be invisible to users, but the downstream errors they cause will be reported as bugs. (For example, github.com/facebook/react/issues/21402)

Emitting an error event allows the ErrorBoundary to show the original error.

Throwing is still valuable for local development and for unit testing the Store itself.
2021-05-04 10:46:26 -04:00
Sebastian Markbåge
442eb21e0e Allow dangerouslySetInnerHTML in <option> (#21373) 2021-05-04 07:45:54 -07:00
Brian Vaughn
9a130e1dec StrictMode includes strict effects by default (#21418)
Removed "unstable_level" attribute support for the time being.
2021-05-04 09:47:06 -04:00
Brian Vaughn
b522638b99 Add GitHub API query to bug report template (#21421)
This may help debug why sometimes the GitHub API search seems to not find a match when it should.
2021-05-04 00:09:11 -04:00
Brian Vaughn
4ca62cac45 Improve DevTools bug template text (#21413) 2021-05-03 16:57:17 -04:00
Brian Vaughn
15fb8c3045 createRoot API is no longer strict by default (#21417) 2021-05-03 16:57:03 -04:00
Andrew Clark
aea7c2aab1 Re-land "Support nesting of startTransition and flushSync (alt) (#21149)"
This re-lands commit faa1e127f1ba755da846bc6ce299cdefaf97721f.
2021-05-03 13:40:13 -05:00
Andrew Clark
bacc87068a Re-land "Flush discrete passive effects before paint (#21150)"
This re-lands commit 2e7aceeb5c8b6e5c61174c0e9731e263e956e445.
2021-05-03 13:36:38 -05:00
Andrew Clark
098600c42a Re-land "Fix: flushSync changes priority inside effect (#21122)"
This re-lands commit 0e3c7e1d62efb6238b69e5295d45b9bd2dcf9181.
2021-05-03 13:36:17 -05:00
Andrew Clark
df420bc0a3 Re-land "Delete LanePriority type (#21090)"
This re-lands commit 26ddc63f2dcc8e7dcbacf498237a2bb1e28a7d23.
2021-05-03 13:35:51 -05:00
Andrew Clark
ab5b379275 Re-land "Clean up host pointers in level 2 of clean-up flag (#21112)"
This re-lands commit 8ed0c85bf174ce6e501be62d9ccec1889bbdbce1.
2021-05-03 13:35:19 -05:00
Andrew Clark
fd907c1f15 Re-land "Use highest priority lane to detect interruptions (#21088)""
This re-lands commit b4044f8a07323bcad7d55cbaedc35c35b4acf7e0.
2021-05-03 13:34:19 -05:00
Ricky
79740da4c6 Update time-slicing demo (#21401) 2021-04-30 20:50:59 -04:00
Brian Vaughn
b6644fabb9 Added test fixture for scheduling profiler (#21397) 2021-04-30 15:23:45 -04:00
Andrew Clark
269dd6ec5d subtreeFlag warning: Fix legacy suspense false positive (#21388)
Legacy Suspense is weird. We intentionally commit a suspended fiber in
an inconsistent state. If the fiber suspended before it mounted any
effects, then the fiber won't have a PassiveStatic effect flag, which
will trigger the "missing expected subtreeFlag" warning.

To avoid the false positive, we'd need to mark fibers that commit in an
incomplete state, somehow. For now I'll disable the warning in legacy
mode, with the assumption that most of the bugs that would trigger it
are either exclusive to concurrent mode or exist in both.
2021-04-29 08:28:38 -05:00
Brian Vaughn
3c21aa855a DevTools refactor Profiler commit tree reconstruction to be iterative (#21383) 2021-04-28 16:32:35 -04:00
Ricky
9e9dac6505 Add unstable_concurrentUpdatesByDefault (#21227) 2021-04-28 16:09:30 -04:00
Andrew Clark
86f3385d9a Revert "Use highest priority lane to detect interruptions (#21088)"
This reverts commit b4044f8a07323bcad7d55cbaedc35c35b4acf7e0.

Instead of LanePriority.

I'm removing all uses of LanePriority so I can delete it.
2021-04-28 11:56:55 -05:00
Andrew Clark
c6702656ff Revert "Clean up host pointers in level 2 of clean-up flag (#21112)"
This reverts commit 8ed0c85bf174ce6e501be62d9ccec1889bbdbce1.

The host tree is a cyclical structure. Leaking a single DOM node can
retain a large amount of memory. React-managed DOM nodes also point
back to a fiber tree.

Perf testing suggests that disconnecting these fields has a big memory
impact. That suggests leaks in non-React code but since it's hard to
completely eliminate those, it may still be worth the extra work to
clear these fields.

I'm moving this to level 2 to confirm whether this alone is responsible
for the memory savings, or if there are other fields that are retaining
large amounts of memory.

In our plan for removing the alternate model, DOM nodes would not be
connected to fibers, except at the root of the whole tree, which is
easy to disconnect on deletion. So in that world, we likely won't have
to do any additional work.
2021-04-28 11:56:54 -05:00
Andrew Clark
1bd41c6645 Revert "Delete LanePriority type (#21090)"
This reverts commit 26ddc63f2dcc8e7dcbacf498237a2bb1e28a7d23.

No longer using LanePriority anywhere, so this deletes the
remaining references.
2021-04-28 11:56:54 -05:00
Andrew Clark
e7e0a90bd8 Revert "Fix: flushSync changes priority inside effect (#21122)"
This reverts commit 0e3c7e1d62efb6238b69e5295d45b9bd2dcf9181.

When called from inside an effect, flushSync cannot synchronously flush
its updates because React is already working. So we fire a warning.

However, we should still change the priority of the updates to sync so
that they flush at the end of the current task.

This only affects useEffect because updates inside useLayoutEffect (and
the rest of the commit phase, like ref callbacks) are already sync.
2021-04-28 11:56:54 -05:00
Andrew Clark
7bac7607a7 Revert "Flush discrete passive effects before paint (#21150)"
This reverts commit 2e7aceeb5c8b6e5c61174c0e9731e263e956e445.

If a discrete render results in passive effects, we should flush them
synchronously at the end of the current task so that the result is
immediately observable. For example, if a passive effect adds an event
listener, the listener will be added before the next input.

We don't need to do this for effects that don't have discrete/sync
priority, because we assume they are not order-dependent and do not
need to be observed by external systems.

For legacy mode, we will maintain the existing behavior, since it hasn't
been reported as an issue, and we'd have to do additional work to
distinguish "legacy default sync" from "discrete sync" to prevent all
passive effects from being treated this way.
2021-04-28 11:56:54 -05:00
Andrew Clark
207d4c3a53 Revert "Support nesting of startTransition and flushSync (alt) (#21149)"
This reverts commit faa1e127f1ba755da846bc6ce299cdefaf97721f.

* Support nesting of startTransition and flushSync

* Unset transition before entering any special execution contexts

Co-authored-by: Andrew Clark <git@andrewclark.io>
2021-04-28 11:56:54 -05:00
Brian Vaughn
2a7bb41548 Preparing DevTools 4.12.4 -> 4.13.0 release (#21378) 2021-04-28 12:36:24 -04:00
Brian Vaughn
7edd628134 Removed (deleted) tracing fixture test from relesae scripts 2021-04-28 12:36:09 -04:00
Brian Vaughn
a0d6b155dc DevTools should iterate over siblings during mount (#21377)
Previously, DevTools recursed over both children and siblings during mount. This caused potential stack overflows when there were a lot of children (e.g. a list containing many items).

Given the following example component tree:

       A
    B  C  D
    E     F
          G

A method that recurses for every child and sibling leads to a max depth of 6:

    A
    A -> B
    A -> B -> E
    A -> B -> C
    A -> B -> C -> D
    A -> B -> C -> D -> F
    A -> B -> C -> D -> F -> G

The stack gets deeper as the tree gets either deeper or wider.

A method that recurses for every child and iterates over siblings leads to a max depth of 4:

    A
    A -> B
    A -> B -> E
    A -> C
    A -> D
    A -> D -> F
    A -> D -> F -> G

The stack gets deeper as the tree gets deeper but is resilient to wide trees (e.g. lists containing many items).
2021-04-28 10:29:22 -04:00
Brian Vaughn
a5267faad5 Updated DevTools CHANGELOG for 4.10 releases 2021-04-28 08:58:27 -04:00
Brian Vaughn
5196a95fd1 Updated DevTools to replace fburl.com link with fb.me link 2021-04-27 23:49:30 -04:00
Brian Vaughn
ecb599cd87 DevTools supports multiple modal dialogs at once (#21370) 2021-04-27 20:33:11 -04:00
Brian Vaughn
8e2bb3e89c DevTools: Add Bridge protocol version backend/frontend (#21331)
Add an explicit Bridge protocol version to the frontend and backend components as well as a check during initialization to ensure that both are compatible. If not, the frontend will display either upgrade or downgrade instructions.

Note that only the `react-devtools-core` (React Native) and `react-devtools-inline` (Code Sandbox) packages implement this check. Browser extensions inject their own backend and so the check is unnecessary. (Arguably the `react-devtools-inline` check is also unlikely to be necessary _but_ has been added as an extra guard for use cases such as Replay.io.)
2021-04-27 17:26:07 -04:00
Brian Vaughn
22ab39be68 DevTools console patching should handle Symbols without erroring (#21368) 2021-04-27 16:36:20 -04:00
Sebastian Markbåge
2182563dc4 Let value override defaultValue if both are specified (#21369)
There's a DEV warning for this case but we still test for the production
behavior.
2021-04-27 13:18:42 -07:00
Sebastian Silbermann
29faeb2df3 Remove unnecessary type cast (#21363) 2021-04-27 12:37:14 -04:00
Sebastian Silbermann
4edbcdc327 Update supported devEngines (#21364) 2021-04-27 12:03:25 -04:00
Sebastian Markbage
9a2591681e Fix export 2021-04-27 09:44:17 -04:00
Sebastian Markbåge
4a8deb0836 Switch the isPrimaryRender flag based on the stream config (#21357) 2021-04-26 22:37:05 -04:00
Sebastian Markbåge
bd4f056a3e [Fizz] Implement lazy components and nodes (#21355)
* Implement lazy components

* Implement lazy elements / nodes

This is used by Flight to encode not yet resolved nodes of any kind.
2021-04-26 18:46:46 -07:00
Sebastian Markbåge
a2ae42db90 Escape style values (#21356) 2021-04-26 18:46:36 -07:00
Brian Vaughn
fc33f12bde Remove unstable scheduler/tracing API (#20037) 2021-04-26 19:16:18 -04:00
Brian Vaughn
7212383945 Enable strict effects mode for React Native Facebook builds (#21354) 2021-04-26 16:32:05 -04:00
Sebastian Silbermann
84b9162cbe Use toMatchInlineSnapshot for dehydrated values (#20618) 2021-04-26 12:30:34 -04:00
Andrew Clark
48740429b4 Expiration: Do nothing except disable time slicing (#21345)
We have a feature called "expiration" whose purpose is to prevent
a concurrent update from being starved by higher priority events.
If a lane is CPU-bound for too long, we finish the rest of the work
synchronously without allowing further interruptions.

In the current implementation, we do this in sort of a roundabout way:
once a lane is determined to have expired, we entangle it with SyncLane
and switch to the synchronous work loop.

There are a few flaws with the approach. One is that SyncLane has a
particular semantic meaning besides its non-yieldiness. For example,
`flushSync` will force remaining Sync work to finish; currently, that
also includes expired work, which isn't an intended behavior, but rather
an artifact of the implementation.

An event worse example is that passive effects triggered by a Sync
update are flushed synchronously, before paint, so that its result
is guaranteed to be observed by the next discrete event. But expired
work has no such requirement: we're flushing expired effects before
paint unnecessarily.

Aside from the behaviorial implications, the current implementation has
proven to be fragile: more than once, we've accidentally regressed
performance due to a subtle change in how expiration is handled.

This PR aims to radically simplify how we model starvation protection by
scaling back the implementation as much as possible. In this new model,
if a lane is expired, we disable time slicing. That's it. We don't
entangle it with SyncLane. The only thing we do is skip the call to
`shouldYield` in between each time slice. This is identical to how we
model synchronous-by-default updates in React 18.
2021-04-24 16:32:48 -07:00
Andrew Clark
0f5ebf366e Delete unreferenced type (#21343)
Had already deleted all the uses but didn't remove the type itself.
2021-04-23 15:41:53 -07:00
Sebastian Markbåge
9cd52b27fe Restore context after an error happens (#21341)
Typically we don't need to restore the context here because we assume that
we'll terminate the rest of the subtree so we don't need the correct
context since we're not rendering any siblings.

However, after a nested suspense boundary we need to restore the context.
The boundary could do this but since we're already doing this in the
suspense branch of renderNode, we might as well do it in the error case
which isn't very perf sensitive anyway.
2021-04-23 12:24:10 -07:00
Sebastian Markbåge
ad091759a9 Revert "Emit reactroot attribute on the first element we discover (#21154)" (#21340)
This reverts commit 266c26ad45.
2021-04-23 10:28:44 -07:00
Sebastian Markbåge
709f948412 [Fizz] Add FB specific streaming API and build (#21337)
Add FB specific streaming API and build
2021-04-22 16:54:29 -07:00
Sebastian Markbåge
af5037a7a8 [Fizz] Wire up the Fixture (#21273)
* Wire up fizz to fixture

* Fixed typo conditional
2021-04-22 15:00:35 -07:00
Andrew Clark
e8cdce40d6 Don't flush sync at end of discreteUpdates (#21327)
All it should do is change the priority. The updates will be flushed
by the microtask.
2021-04-22 15:28:05 -05:00
Andrew Clark
a155860018 Fix: Don't flush discrete at end of batchedUpdates (#21229)
The outermost `batchedUpdates` call flushes pending sync updates at the
end. This was intended for legacy sync mode, but it also happens to
flush discrete updates in concurrent mode.

Instead, we should only flush sync updates at the end of
`batchedUpdates` for legacy roots. Discrete sync updates can wait to
flush in the microtask.

`discreteUpdates` has the same issue, which is how I originally noticed
this, but I'll change that one in a separate commit since it requires
updating a few (no longer relevant) internal tests.
2021-04-21 09:32:09 -07:00
Andrew Clark
89847bf6e6 Continuous updates should interrupt transitions (#21323)
Even when updates are sync by default.

Discovered this quirk while working on #21322. Previously, when sync
default updates are enabled, continuous updates are treated like
default updates. We implemented this by assigning DefaultLane to
continous updates. However, an unintended consequence of that approach
is that continuous updates would no longer interrupt transitions,
because default updates are not supposed to interrupt transitions.

To fix this, I changed the implementation to always assign separate
lanes for default and continuous updates. Then I entangle the
lanes together.
2021-04-21 08:51:04 -07:00
Andrew Clark
ef37d55b68 Use performConcurrentWorkOnRoot for "sync default" (#21322)
Instead of `performSyncWorkOnRoot`.

The conceptual model is that the only difference between sync default
updates (in React 18) and concurrent default updates (in a future major
release) is time slicing. All other behavior should be the same
(i.e. the stuff in `finishConcurrentRender`).

Given this, I think it makes more sense to model the implementation this
way, too. This exposed a quirk in the previous implementation where
non-sync work was sometimes mistaken for sync work and flushed too
early. In the new implementation, `performSyncWorkOnRoot` is only used
for truly synchronous renders (i.e. `SyncLane`), which should make these
mistakes less common.

Fixes most of the tests marked with TODOs from #21072.
2021-04-21 08:29:31 -07:00
Ricky
a632f7de3b Flip tuple order of useTransition (#20976) 2021-04-20 12:21:44 -04:00
Andrew Clark
bd7f4a013b Fix sloppy factoring in performSyncWorkOnRoot (#21246)
* Warn if `finishedLanes` is empty in commit phase

See #21233 for context.

* Fix sloppy factoring when assigning finishedLanes

`finishedLanes` is assigned in `performSyncWorkOnRoot` and
`performSyncWorkOnRoot`. It's meant to represent whichever lanes we
used to render, but because of some sloppy factoring, it can sometimes
equal `NoLanes`.

The fixes are:
- Always check if the lanes are not `NoLanes` before entering the work
loop. There was a branch where this wasn't always true.
- In `performSyncWorkOnRoot`, don't assume the next lanes are sync; the
priority may have changed, or they may have been flushed by a
previous task.
- Don't re-assign the `lanes` variable (the one that gets assigned to
`finishedLanes` until right before we enter the work loop, so that it
is always corresponds to the newest complete root.
2021-04-20 09:14:55 -07:00
Andrew Clark
78120032d4 Remove flushDiscreteUpdates from end of event (#21223)
We don't need this anymore because we flush in a microtask.

This should allow us to remove the logic in the event system that
tracks nested event dispatches.

I added a test to confirm that nested event dispatches don't triggger
a synchronous flush, like they would if we wrapped them `flushSync`. It
already passed; I added it to prevent a regression.
2021-04-20 08:25:31 -07:00
Ricky
a3a7adb83e Turn off enableSyncDefaultUpdates in test renderer (#21319) 2021-04-19 22:20:48 -07:00
Brian Vaughn
cdb6b4c554 Only hide outermost host nodes when Offscreen is hidden (#21250) 2021-04-19 21:33:42 -04:00
Brian Vaughn
7becb2ff1b DevTools version bump 4.12.3 -> 4.12.4 2021-04-19 21:23:01 -04:00
Brian Vaughn
83bdc565f9 Remove @octokit/rest dependency from DevTools (#21317) 2021-04-19 21:20:34 -04:00
Brian Vaughn
b9c6a2b30e Remove LayoutStatic check from commit phase (#21249) 2021-04-19 15:16:24 -04:00
Brian Vaughn
8f202a7c8d DevTools version bump 4.12.2 -> 4.12.3 2021-04-19 13:09:07 -04:00
Brian Vaughn
4def1ceee2 Update DevTools Error strings to support GitHub fuzzy search (#21314) 2021-04-19 13:05:28 -04:00
Andrew Clark
af1a4cbf7a Revert expiration for retry lanes (#21300)
Retries should be allowed to expire if they are CPU bound for too long,
but when I made this change it caused a spike in browser crashes. There
must be some other underlying bug; not super urgent but ideally should
figure out why and fix it. Unfortunately we don't have a repro for the
crashes, only detected via production metrics.
2021-04-16 16:45:09 -05:00
Brian Vaughn
c3cb2c2b30 Fix DevTools test target (#21267) 2021-04-16 16:19:05 -04:00
Brian Vaughn
d14b6a4bdd DevTools version bump 4.12.1 -> 4.12.2 2021-04-16 12:35:29 -04:00
Brian Vaughn
5027eb4650 DevTools fork console patching logic (#21301)
React has its own component stack generation code that DevTools embeds a fork of, but both of them use a shared helper for disabling console logs. This shared helper is DEV only though, because it was intended for use with React DEV-only warnings and we didn't want to unnecessarily add bytes to production builds.

But DevTools itself always ships as a production build– even when it's used to debug DEV bundles of product apps (with third party DEV-only warnings). That means this helper was always a noop.

The resolveCurrentDispatcher method was changed recently to replace the thrown error with a call to console.error. This newly logged error ended up slipping through and being user visible because of the above issue.

This PR updates DevTools to also fork the console patching logic (to remove the DEV-only guard).

Note that I didn't spot this earlier because my test harness (react-devtools-shell) always runs in DEV mode. 🤡
2021-04-16 12:01:47 -04:00
Brian Vaughn
c1a53ad2b2 DevTools pre-filter GH issues by repo (#21292) 2021-04-15 19:56:41 -04:00
Sebastian Markbåge
cc4b431dab Mark boundary as client rendered even if aborting fallback (#21294) 2021-04-15 19:16:40 -04:00
Ricky
f7cdc89361 Also turn off enableSyncDefaultUpdates in RN test renderer (#21293) 2021-04-15 16:31:46 -04:00
Ricky
4c9eb2af1e Add dynamic flags to React Native (#21291)
* Add dynamic flags to React Native

* Hardcode the setting to false instead
2021-04-15 15:30:09 -04:00
Brian Vaughn
f3337aa544 DevTools error boundary: Search for pre-existing GH issues (#21279) 2021-04-15 13:34:54 -04:00
Sebastian Markbåge
9eddfbf5af [Fizz] Two More Fixes (#21288)
* Emit value of option tags

* Mask the legacy context passed to classes
2021-04-15 10:26:49 -07:00
Sebastian Markbåge
11b07597ee Fix classes (#21283) 2021-04-15 08:06:31 -07:00
Sebastian Markbåge
96d00b9bba [Fizz] Random Fixes (#21277) 2021-04-14 23:29:30 -04:00
Sebastian Markbåge
0e100ed00f Gate a test (#21275)
Rebase error
2021-04-14 16:37:44 -07:00
Sebastian Markbåge
81ef539535 Always insert a dummy node with an ID into fallbacks (#21272) 2021-04-14 15:39:51 -07:00
Sebastian Markbåge
266c26ad45 Emit reactroot attribute on the first element we discover (#21154)
This may not be the first root element if the root is a fragment and the
second one unsuspends first. But this tag doesn't work well for root
fragments anyway.
2021-04-14 15:09:22 -07:00
Sebastian Markbåge
a4a940d7a1 [Fizz] Add unsupported Portal/Scope components (#21261)
* Update Portal error message

* Add Scope Component
2021-04-14 14:35:36 -07:00
Sebastian Markbåge
f4d7a0f1ea Implement useOpaqueIdentifier (#21260)
The format of this ID is specific to the format.
2021-04-14 14:25:42 -07:00
Sebastian Markbåge
dde875dfb1 [Fizz] Implement Hooks (#21257)
* Implement Fizz Hooks

This is pretty much just a copy of the partial renderer Hooks.

* Implement forward ref and memo
2021-04-14 14:16:41 -07:00
Sebastian Markbåge
a597c2f5dc [Fizz] Fix reentrancy bug (#21270)
* Fix reentrancy bug

* Fix another reentrancy bug

There's also an issue if we try to schedule something to be client
rendered if its fallback hasn't rendered yet. So we don't do it
in that case.
2021-04-14 13:49:14 -07:00
Brian Vaughn
68097787f6 DevTools should use reconciler version (rather than renderer version)
when available (#21269)
2021-04-14 14:48:05 -04:00
Brian Vaughn
15e779d921 Reconciler should inject its own version into DevTools hook (#21268) 2021-04-14 14:47:36 -04:00
Sebastian Markbåge
4f76a28c93 [Fizz] Implement New Context (#21255)
* Add NewContext module

This implements a reverse linked list tree containing the previous
contexts.

* Implement recursive algorithm

This algorithm pops the contexts back to a shared ancestor on the way down
the stack and then pushes new contexts in reverse order up the stack.

* Move isPrimaryRenderer to ServerFormatConfig

This is primarily intended to be used to support renderToString with a
separate build than the main one. This allows them to be nested.

* Wire up more element type matchers

* Wire up Context Provider type

* Wire up Context Consumer

* Test

* Implement reader in class

* Update error codez
2021-04-14 11:45:42 -07:00
Brian Vaughn
6b3d86a2e9 Fixed bug in react-detools-inline frontend init method (#21265) 2021-04-14 13:27:21 -04:00
Henry Q. Dineen
82ef450e0e remove obsolete SharedArrayBuffer ESLint config (#21259) 2021-04-14 12:55:23 -04:00
Paul O’Shannessy
ea155e2267 Update code of conduct (#21251)
We are updating our code of conduct to include activities outside the project.

https://developers.facebook.com/blog/post/2021/04/12/facebook-open-source-ally/
2021-04-13 19:33:31 -04:00
Sebastian Markbåge
dbadfa2c36 [Fizz] Classes Follow Up (#21253)
* Port Classes from Fiber to Fizz

* Test
2021-04-13 13:57:36 -07:00
Brian Vaughn
84c06fef81 Add createBridge and createStore exports to react-devtools-inline (for Replay integration) (#21032) 2021-04-12 17:07:14 -04:00
Joshua Gross
686b635b71 Prevent reading canonical property of null (#21242)
* Prevent reading canonical property of null

* prettier
2021-04-12 11:10:51 -07:00
Andrew Clark
dd8552ae0d yarn test: Default to bleeding edge configuration (#21238)
My personal workflow is to develop against the www-modern release
channel, with the variant flags enabled, because it encompasses the
largest set of features. Then I rely on CI to run the tests against
all the other configurations.

So in practice, I almost always run

```
yarn test -r=www-modern --variant TEST_FILE
```

instead of

```
yarn test TEST_FILE
```

So, I've updated the `yarn test` command to use those options
by default.
2021-04-12 09:49:26 -07:00
Brian Vaughn
9d48779b36 Fixed broken feature flag import for DT inline package (#21237) 2021-04-11 14:59:52 -04:00
Andrew Clark
bb88ce95a8 Bugfix: Don't rely on finishedLanes for passive effects (#21233)
I recently started using `pendingPassiveEffectsLanes` to check if there were any pending
passive effects (530027a). `pendingPassiveEffectsLanes` is the value of
`root.finishedLanes` at the beginning of the commit phase. When there
are pending passive effects, it should always be a non-zero value,
because it represents the lanes used to render the effects.

But it turns out that `root.finishedLanes` isn't always correct.
Sometimes it's `NoLanes` even when there's a new commit.

I found this while investigating an internal bug report. The only repro
I could get was via a headless e2e test runner; I couldn't get one in an
actual browser, or other interactive environment. I used the e2e test to
bisect and confirm the fix. But I don't know yet know how to write a
regression test for the precise underlying scenario. I can probably
reverse engineer one by studying the code; after a quick glance
at `performConcurrentWorkOnRoot` and `performSyncWorkOnRoot`, it's not
hard to see how this might happen.

In the meantime, I'll revert the recent change that exposed the bug.

I was surprised that this had never come up before, since the code that
assigns `root.finishedLanes` is in an extremely hot path, and it hasn't
changed in a while. The reason is that, before 530027a,
`root.finishedLanes` was only used by the DevTools profiler, which is
probably why we had never noticed any issues. In addition to fixing the
inconsistency, we might also consider making `finishedLanes` a
profiling-only field.
2021-04-11 02:09:41 -07:00
Sebastian Markbåge
343710c923 [Fizz] Fragments and Iterable support (#21228) 2021-04-10 15:50:42 -04:00
Ricky
933880b454 Make time-slicing opt-in (#21072)
* Add enableSyncDefaultUpdates feature flag

* Add enableSyncDefaultUpdates implementation

* Fix tests

* Switch feature flag to true by default

* Finish concurrent render whenever for non-sync lanes

* Also return DefaultLane with eventLane

* Gate interruption test

* Add continuout native event test

* Fix tests from rebasing main

* Hardcode lanes, remove added export

* Sync forks
2021-04-09 19:50:09 -04:00
Sebastian Markbåge
b0407b55ff Support more empty types (#21225)
Undefined errors as a direct return value.

This changes semantics for "true" and functions to mirror the client.
2021-04-09 16:23:37 -07:00
Sebastian Markbåge
39713716aa Merge isObject branches (#21226)
We assume that isArray and getIteratorFn are only called on objects.

So we shouldn't have to check that again and again, and then check a flag.

We can just stay in this branch.

There is a slight semantic breakage here because you could have an
iterator on a function, such as if it's a generator function. But that's
not supported and that currently only works at the root. The inner slots
don't support this.

So this just makes it consistent.
2021-04-09 16:19:13 -07:00
Brian Vaughn
d4cae99f2a Prepare DevTools CHANGELOG and versions for 4.11.0 release (#21221) 2021-04-09 19:12:13 -04:00
Sebastian Markbåge
8a4a59c725 Remove textarea special case from child fiber (#21222) 2021-04-09 14:02:13 -07:00
Brian Vaughn
bdc23c3dba DevTools shows which fibers scheduled the current update (#21171) 2021-04-09 10:35:06 -04:00
Brian Vaughn
dc108b0f55 Track which fibers scheduled the current render work (#15658)
Tracked Fibers are called "updaters" and are exposed to DevTools via a 'memoizedUpdaters' property on the ReactFiberRoot. The implementation of this feature follows a vaguely similar approach as interaction tracing, but does not require reference counting since there is no subscriptions API.

This change is in support of a new DevTools Profiler feature that shows which Fiber(s) scheduled the selected commit in the Profiler.

All changes have been gated behind a new feature flag, 'enableUpdaterTracking', which is enabled for Profiling builds by default. We also only track updaters when DevTools has been detected, to avoid doing unnecessary work.
2021-04-09 10:34:33 -04:00
inokawa
6ea749170b Fix typo in comment (#21214) 2021-04-08 23:20:01 -04:00
Brian Vaughn
b38ac13f94 DevTools: Add post-commit hook (#21183)
I recently added UI for the Profiler's commit and post-commit durations to the DevTools, but I made two pretty silly oversights:

    1. I used the commit hook (called after mutation+layout effects) to read both the layout and passive effect durations. This is silly because passive effects may not have flushed yet git at this point.
    2. I didn't reset the values on the HostRoot node, so they accumulated with each commit.

    This commitR addresses both issues:

    1. First it adds a new DevTools hook, onPostCommitRoot*, to be called after passive effects get flushed. This gives DevTools the opportunity to read passive effect durations (if the build of React being profiled supports it).
    2. Second the work loop resets these durations (on the HostRoot) after calling the post-commit hook so address the accumulation problem.
    I've also added a unit test to guard against this regressing in the future.

    * Doing this in flushPassiveEffectsImpl seemed simplest, since there are so many places we flush passive effects. Is there any potential problem with this though?
2021-04-08 22:04:51 -04:00
Andrew Clark
b943aeba88 Fix: Passive effect updates are never sync (#21215)
I screwed this up in #21082. Got confused by the < versus > thing again.

The helper functions are annoying, too, because I always forget the
intended order of the arguments. But they're still helpful because when
we refactor the type we only have the change the logic in one place.

Added a regression test.
2021-04-08 18:45:35 -07:00
Brian Vaughn
d389c54d17 Offscreen: Use JS stack to track hidden/unhidden subtree state (#21211) 2021-04-08 17:27:18 -04:00
Sebastian Markbåge
c486dc1a46 Remove unnecessary processUpdateQueue (#21199)
We've just initialized the update queue above this and there's no user
code that executes between.

The general API that prevents this from mattering is that you can't
call setState in the constructor.
2021-04-08 11:14:51 -07:00
Sebastian Markbåge
cf45a623a1 [Fizz] Implement Classes (#21200)
* Legacy context

* Port Classes from Fiber to Fizz
2021-04-08 10:42:37 -07:00
Sebastian Silbermann
75c616554d Include actual type of Profiler#id on type mismatch (#20306) 2021-04-08 13:36:42 -04:00
Sebastian Silbermann
1214b302e1 test: Fix "couldn't locate all inline snapshots" (#21205) 2021-04-08 11:18:13 -04:00
wangao
1a02d2792e style: delete unused isHost check (#21203) 2021-04-08 13:58:24 +01:00
Sebastian Markbåge
782f689ca8 Don't double invoke getDerivedStateFromProps for module pattern (#21193) 2021-04-07 16:20:25 -07:00
Brian Vaughn
e90c76a651 Revert "Offscreen: Use JS stack to track hidden/unhidden subtree state" (#21194)
This reverts commit 1f8583de8c.
2021-04-07 17:51:48 -04:00
Brian Vaughn
1f8583de8c Offscreen: Use JS stack to track hidden/unhidden subtree state (#21192) 2021-04-07 17:45:19 -04:00
Sebastian Markbåge
ad6e6ec7bb [Fizz] Prepare Recursive Loop for More Types (#21186)
* Split out into helper functions

This is similar to the structure of beginWork in Fiber.

* Split the rendering of a node from recursively rendering a node

This lets us reuse render node at the root which doesn't spawn new work.
2021-04-07 11:29:06 -07:00
Sebastian Markbåge
172e89b4bf Reland Remove redundant initial of isArray (#21188)
* Remove redundant initial of isArray (#21163)

* Reapply prettier

* Type the isArray function with refinement support

This ensures that an argument gets refined just like it does if isArray is
used directly.

I'm not sure how to express with just a direct reference so I added a
function wrapper and confirmed that this does get inlined properly by
closure compiler.

* A few more

* Rename unit test to internal

This is not testing a bundle.

Co-authored-by: Behnam Mohammadi <itten@live.com>
2021-04-07 07:57:43 -07:00
Brian Vaughn
ee6a05c2bf Bumped DevTools Chrome and Firefox versions in Babel config (#21185)
We have been building DevTools to target Chrome 49 and Firefox 54. These are super old browser versions and they did not have full ES6 support, so the generated build is more bloated than it needs to be.

DevTools uses most modern language features. Off the top of my head, we it uses basically everything but async and generator functions.

Based on CanIUse charts– I believe that in order to avoid unnecessary polyfill/wrapper code being generated, we'd need to target Chrome 60+ (released 2017-07-25) and Firefox 55+ (released 2017-04-18). This seems like a reasonable set of browsers to target.

Note that we can't remove the IE 11 target from the react-devtools-core backend yet due to Hermes (React Native) ES6 support but that should be doable by the end of the year given current engineering targets. But we could update the frontend target, as well as the targets for the extensions and the react-devtools-inline package.

This commit increases the browser targets then for Chrome (from 49 to 60) and Firefox (from 54 to 55)
2021-04-06 11:18:46 -04:00
Brian Vaughn
d778518998 Update build-for-devtools script to prepare unit tests too (#21182) 2021-04-06 09:24:33 -04:00
Brian Vaughn
7c1ba2b57d Proposed new Suspense layout effect semantics (#21079)
This commit contains a proposed change to layout effect semantics within Suspense subtrees: If a component mounts within a Suspense boundary and is later hidden (because of something else suspending) React will cleanup that component’s layout effects (including React-managed refs).

This change will hopefully fix existing bugs that occur because of things like reading layout in a hidden tree and will also enable a point at which to e.g. pause videos and hide user-managed portals. After the suspended boundary resolves, React will setup the component’s layout effects again (including React-managed refs).

The scenario described above is not common. The useTransition API should ensure that Suspense does not revert to its fallback state after being mounted.

Note that these changes are primarily written in terms of the (as of yet internal) Offscreen API as we intend to provide similar effects semantics within recently shown/hidden Offscreen trees in the future. (More to follow.)

(Note that all changes in this PR are behind a new feature flag, enableSuspenseLayoutEffectSemantics, which is disabled for now.)
2021-04-06 09:21:02 -04:00
Andrey Marchenko
316aa36865 [Scheduler] Fix de-opt caused by out-of-bounds access (#21147)
Scheduler's heap implementation sometimes accesses indices that are out
of bounds (larger than the size of the array). This causes a VM de-opt.

This change fixes the de-opt by always checking the index before
accessing the array. In exchange, we can remove the typecheck on the
returned element.

Background: https://v8.dev/blog/elements-kinds#avoid-reading-beyond-the-length-of-the-array

Co-authored-by: Andrew Clark <git@andrewclark.io>
2021-04-05 21:05:02 -07:00
Brian Vaughn
a817840ea7 DevTools: useModalDismissSignal bugfix (#21173)
* DevTools: useModalDismissSignal bugfix

Make useModalDismissSignal's manually added click/keyboard events more robust to sync flushed passive effects. (Don't let the same click event that shows a modal dialog also dismiss it.)

* Replaced event.timeStamp check with setTimeout
2021-04-05 11:09:43 -04:00
Sebastian Markbage
b4f119cdf1 Revert "Remove redundant initial of isArray (#21163)"
This reverts commit b130a0f5cd.
2021-04-01 15:19:00 -04:00
Sebastian Markbage
c03197063d Revert "apply prettier (#21165)"
This reverts commit 94fd1214d2.
2021-04-01 15:18:56 -04:00
Behnam Mohammadi
94fd1214d2 apply prettier (#21165) 2021-04-01 12:09:16 -07:00
Behnam Mohammadi
b130a0f5cd Remove redundant initial of isArray (#21163) 2021-04-01 10:50:48 -07:00
Behnam Mohammadi
2c9fef32db Remove redundant initial of hasOwnProperty (#21134)
* remove redundant initial of hasOwnProperty

* remove redundant initial of hasOwnProperty part 2

* remove redundant initial of hasOwnProperty part 3
2021-04-01 09:05:10 -07:00
Sebastian Markbåge
1cf9978d89 Don't pass internals to callbacks (#21161)
I noticed that I accidentally pass the request object to public API callbacks
as "this".
2021-04-01 08:43:12 -07:00
Sebastian Markbåge
a423a01223 Ignore function and symbol values on custom-elements on the server (#21157) 2021-03-31 18:17:42 -07:00
Sebastian Markbåge
588db2e1fc Don't warn for casing if it's a custom element (#21156)
This replicates what we do on the client.
2021-03-31 18:10:27 -07:00
Sebastian Markbåge
9ed0167945 Don't lower case HTML tags in comparison for built-ins (#21155) 2021-03-31 18:00:22 -07:00
Sebastian Markbåge
b9e4c10e99 [Fizz] Implement all the DOM attributes and special cases (#21153)
* Implement DOM format config structure

* Styles

* Input warnings

* Textarea special cases

* Select special cases

* Option special cases

We read the currently selected value from the FormatContext.

* Warning for non-lower case HTML

We don't change to lower case at runtime anymore but keep the warning.

* Pre tags innerHTML needs to be prefixed

This is because if you do the equivalent on the client using innerHTML,
this is the effect you'd get.

* Extract errors
2021-03-31 17:39:38 -07:00
Lea Rosema
0e96bdd4ee Remove my deadname from AUTHORS (#21152) 2021-03-31 23:13:13 +01:00
Andrew Clark
f8ef4ff571 Flush discrete passive effects before paint (#21150)
If a discrete render results in passive effects, we should flush them
synchronously at the end of the current task so that the result is
immediately observable. For example, if a passive effect adds an event
listener, the listener will be added before the next input.

We don't need to do this for effects that don't have discrete/sync
priority, because we assume they are not order-dependent and do not
need to be observed by external systems.

For legacy mode, we will maintain the existing behavior, since it hasn't
been reported as an issue, and we'd have to do additional work to
distinguish "legacy default sync" from "discrete sync" to prevent all
passive effects from being treated this way.
2021-03-31 10:39:19 -07:00
Sebastian Markbåge
b48b38af68 Support nesting of startTransition and flushSync (alt) (#21149)
* Support nesting of startTransition and flushSync

* Unset transition before entering any special execution contexts

Co-authored-by: Andrew Clark <git@andrewclark.io>
2021-03-31 08:22:49 -07:00
Dan Abramov
c9aab1c9d0 react-refresh@0.10.0 2021-03-30 16:19:57 +01:00
Dan Abramov
516b76b9ae [Fast Refresh] Support callthrough HOCs (#21104)
* [Fast Refresh] Support callthrough HOCs

* Add a newly failing testing to demonstrate the flaw

This shows why my initial approach doesn't make sense.

* Attach signatures at every nesting level

* Sign nested memo/forwardRef too

* Add an IIFE test

This is not a case that is important for Fast Refresh, but we shouldn't change the code semantics. This case shows the transform isn't quite correct. It's wrapping the call at the wrong place.

* Find HOCs above more precisely

This fixes a false positive that was causing an IIFE to be wrapped in the wrong place, which made the wrapping unsafe.

* Be defensive against non-components being passed to setSignature

* Fix lint
2021-03-30 16:08:50 +01:00
Sebastian Markbåge
0853aab74d Log all errors to console.error by default (#21130) 2021-03-29 19:39:55 -07:00
Sebastian Markbåge
d1294c9d40 [Flight] Add global onError handler (#21129)
* Add onError option to Flight Server

The callback is called any time an error is generated in a server component.

This allows it to be logged on a server if needed. It'll still be rethrown
on the client so it can be logged there too but in case it never reaches
the client, here's a way to make sure it doesn't get lost.

* Add fatal error handling
2021-03-29 19:36:16 -07:00
Sebastian Markbåge
e40f0b2603 Remove checkReact (#21132)
I don't know what this is useful for but I suspect it was only useful at
FB and is not applicable to ES modules at FB nor elsewhere.
2021-03-29 19:35:58 -07:00
Sebastian Markbåge
cecfde51b6 Don't import star from ReactDOM (#21133) 2021-03-29 19:35:47 -07:00
Sebastian Markbåge
8e76371241 Move not shared to client (#21135) 2021-03-29 19:35:34 -07:00
Andrew Clark
64983aab5d Remove redundant setUpdatePriority call (#21127)
See removed TODO comment. This call is no longer necessary because we
use the dispatcher to track whether we're inside a transition, not the
event priority.
2021-03-29 11:20:40 -07:00
Andrew Clark
634cc52e61 Delete dead variable: currentEventWipLanes (#21123)
No longer used anywhere.
2021-03-28 16:51:11 -07:00
Andrew Clark
1102224bbb Fix: flushSync changes priority inside effect (#21122)
When called from inside an effect, flushSync cannot synchronously flush
its updates because React is already working. So we fire a warning.

However, we should still change the priority of the updates to sync so
that they flush at the end of the current task.

This only affects useEffect because updates inside useLayoutEffect (and
the rest of the commit phase, like ref callbacks) are already sync.
2021-03-28 16:50:30 -07:00
Andrew Clark
dbe98a5aae Move sync task queue to its own module (#21109)
The sync task queue is React-specific and doesn't really have anything
to do with Scheduler. We'd keep using it even once `postTask` exists.

By separating that part out, `SchedulerWithReactIntegration` is now
just a module that re-exports the Scheduler API. So I unforked it.
When we switch to ES Modules, we can remove this re-exporting module.
2021-03-28 14:15:53 -07:00
Andrew Clark
3ba5c87377 Remove Scheduler indirection (#21107)
* Bump version number

* Remove Scheduler indirection

I originally kept the React PriorityLevel and Scheduler PriorityLevel
types separate in case there was a versioning mismatch between the two
modules. However, it looks like we're going to keep the Scheduler module
private in the short to medium term, and longer term the public
interface will match postTask. So, I've removed the extra indirection
(the switch statements that convert between the two types).
2021-03-28 14:13:38 -07:00
Andrew Clark
46b68eaf62 Delete LanePriority type (#21090)
No longer using LanePriority anywhere, so this deletes the
remaining references.
2021-03-28 14:07:32 -07:00
Andrew Clark
dcd13045ef Use Lane to track root callback priority (#21089)
Instead of LanePriority.

I'm removing all uses of LanePriority so I can delete it.
2021-03-28 13:58:46 -07:00
Andrew Clark
5f21a9fca4 Clean up host pointers in level 2 of clean-up flag (#21112)
The host tree is a cyclical structure. Leaking a single DOM node can
retain a large amount of memory. React-managed DOM nodes also point
back to a fiber tree.

Perf testing suggests that disconnecting these fields has a big memory
impact. That suggests leaks in non-React code but since it's hard to
completely eliminate those, it may still be worth the extra work to
clear these fields.

I'm moving this to level 2 to confirm whether this alone is responsible
for the memory savings, or if there are other fields that are retaining
large amounts of memory.

In our plan for removing the alternate model, DOM nodes would not be
connected to fibers, except at the root of the whole tree, which is
easy to disconnect on deletion. So in that world, we likely won't have
to do any additional work.
2021-03-27 15:26:17 -05:00
Sebastian Markbåge
32d6f39edd [Fizz] Support special HTML/SVG/MathML tags to suspend (#21113)
* Encode tables as a special insertion mode

The table modes are special in that its children can't be created outside
a table context so we need the segment container to be wrapped in a table.

* Move formatContext from Task to Segment

It works the same otherwise. It's just that this context needs to outlive
the task so that I can use it when writing the segment.

* Use template tag for placeholders and inserted dummy nodes with IDs

These can be used in any parent. At least outside IE11. Not sure yet what
happens in IE11 to these.

Not sure if these are bad for perf since they're special nodes.

* Add special wrappers around inserted segments depending on their insertion mode

* Allow the root namespace to be configured

This allows us to insert the correct wrappers when streaming into an
existing non-HTML tree.

* Add comment
2021-03-27 10:50:38 -07:00
Erik
a5aa9d5253 Remove redundant if statement (#21101) 2021-03-26 13:50:58 -04:00
Andrew Clark
a77dd13ede Delete enableDiscreteEventFlushingChange (#21110)
This flag was meant to avoid flushing discrete updates unnecessarily,
if multiple discrete events were dispatched in response to the same
platform event.

But since we now flush all discrete events at the end of the task, in
a microtask, it no longer has any effect.
2021-03-25 22:05:59 -07:00
Andrew Clark
048ee4c0cd Use act in fuzz tester to flush expired work (#21108)
* Add failing hard-coded fuzz test

Caught in CI by the fuzz tester.

Related to expired updates.

* Use `act` in fuzz tester to flush expired work

Expired work gets scheduled in a microtask now, so we need to use `act`
to flush it.
2021-03-25 20:08:53 -07:00
Sebastian Markbåge
556644e237 Fix plurals (#21106) 2021-03-25 22:21:41 -04:00
Sebastian Markbåge
8b741437b1 Rename SuspendedWork to Task (#21105) 2021-03-25 18:39:59 -07:00
Sebastian Markbåge
38a1aedb49 [Fizz] Add FormatContext and Refactor Work (#21103)
* Add format context

* Let the Work node hold all working state for the recursive loop

Stacks are nice and all but there's a cost to maintaining each frame
both in terms of stack size usage and writing to it.

* Move current format context into work

* Synchronously render children of a Suspense boundary

We don't have to spawn work and snapshot the context. Instead we can try
to render the boundary immediately in case it works.

* Lazily create the fallback work

Instead of eagerly create the fallback work and then immediately abort it.
We can just avoid creating it if we finish synchronously.
2021-03-25 18:38:43 -07:00
Joshua Gross
1b7e471b91 React Fabric: Support passing nativeViewTag to getInspectorDataForViewAtPoint callback, for React DevTools compat (#21080)
React Fabric: Support passing nativeViewTag to getInspectorDataForViewAtPoint callback, for React DevTools compat
2021-03-25 16:23:39 -07:00
Dan Abramov
a7c57268fb Add aspectRatio to the unitless list (#21100) 2021-03-25 17:01:36 +00:00
Andrew Clark
4a99c5c3a7 Use highest priority lane to detect interruptions (#21088)
Instead of LanePriority.

I'm removing all uses of LanePriority so I can delete it.
2021-03-25 09:36:17 -07:00
Andrew Clark
77be527297 Remove LanePriority from computeExpirationTime (#21087)
I'm removing all uses of LanePriority so I can delete it.
2021-03-25 09:32:14 -07:00
Andrew Clark
3221e8fba4 Remove LanePriority from getBumpedLaneForHydration (#21086)
I'm removing all uses of LanePriority so I can delete it.
2021-03-25 09:27:36 -07:00
Andrew Clark
05ec0d7646 Entangled expired lanes with SyncLane (#21083)
Makes the implementation simpler. Expiration is now a special case of
entanglement.

Also fixes an issue where expired lanes weren't batched with normal
sync updates. (See deleted TODO comment in test.)
2021-03-25 09:24:49 -07:00
Andrew Clark
03ede83d2e Use EventPriority to track update priority (#21082)
Instead of LanePriority. Internally, EventPriority is just a lane, so
this skips an extra conversion. Since EventPriority is a "public" (to
the host config) type, I was also able to remove some deep imports
of the Lane module.

This gets us most of the way to deleting the LanePriority entirely.
2021-03-25 09:21:41 -07:00
Sebastian Markbåge
6a589ad711 Add separator comment between text nodes (#21099)
This is needed to avoid mutating the DOM during hydration. This *always*
adds it even when it's just text children.

We need to avoid this overhead but it's a somewhat tricky problem to solve
so we defer the optimization to later.
2021-03-25 08:48:39 -07:00
Dan Abramov
148f8e497c Add pointerenter/leave priorities (#21077) 2021-03-24 19:57:17 +00:00
Ricky
a63f0953be Delete SyncBatchedLane (#21061)
* Delete SyncBatchedLane

* Go back to 31 lanes
2021-03-24 15:04:19 -04:00
Sebastian Markbåge
fb8c1917e9 Don't use nested objects to "namespace" namespace constants (#21073) 2021-03-24 09:58:23 -07:00
Andrew Clark
fa868d6be7 Make opaque EventPriority type a Lane internally (#21065)
Instead of LanePriority, we can use a Lane and skip the extra
conversion. Eventually I want to get rid of LanePriority completely.
2021-03-24 09:55:24 -07:00
Ari Perkkiö
eb58c3909a react-hooks/exhaustive-deps: Handle optional chained methods as dependency (#20204) (#20247) 2021-03-24 16:45:27 +00:00
Dan Abramov
7b84dbd169 Fail build on deep requires in npm packages (#21063) 2021-03-24 02:43:55 +00:00
Dan Abramov
2c9d8efc8e Add react-reconciler/constants entry point (#21062)
* Add react-reconciler/constants entry point

* Move root tags to /constants
2021-03-24 02:13:43 +00:00
Andrew Clark
d0eaf78293 Move priorities to separate import to break cycle (#21060)
The event priority constants exports by the reconciler package are
meant to be used by the reconciler (host config) itself. So it doesn't
make sense to export them from a module that requires them.

To break the cycle, we can move them to a separate module and import
that. This looks like a "deep import" of an internal module, which we
try to avoid, but conceptually these are part of the public interface
of the reconciler module. So, no different than importing from the main
`react-reconciler`.

We do need to be careful about not mixing these types of imports with
implementation details. Those are the ones to really avoid.

An unintended benefit of the reconciler fork infra is that it makes
deep imports harder. Any module that we treat as "public", like this
one, needs to account for the `enableNewReconciler` flag and forward
to the correct implementation.
2021-03-23 13:57:28 -07:00
Sebastian Markbåge
435cff9866 [Fizz] Expose callbacks in options for when various stages of the content is done (#21056)
* Report errors to a global handler

This allows you to log errors or set things like status codes.

* Add complete callback

* onReadyToStream callback

This is typically not needed because if you want to stream when the
root is ready you can just start writing immediately.

* Rename onComplete -> onCompleteAll
2021-03-23 11:39:38 -07:00
Benoit Girard
25bfa287f6 [Experiment] Add feature flag for more aggressive memory clean-up of deleted fiber trees (#21039)
* Add feature flag: enableStrongMemoryCleanup

Add a feature flag that will test doing a recursive clean of an unmount
node. This will disconnect the fiber graph making leaks less severe.

* Detach sibling pointers in old child list

When a fiber is deleted, it's still part of the previous (alternate)
parent fiber's list of children. Because children are a linked list, an
earlier sibling that's still alive will be connected to the deleted
fiber via its alternate:


  live fiber
  --alternate--> previous live fiber
  --sibling--> deleted fiber

We can't disconnect `alternate` on nodes that haven't been deleted
yet, but we can disconnect the `sibling` and `child` pointers.

Will use this feature flag to test the memory impact.

* Combine into single enum flag

I combined `enableStrongMemoryCleanup` and `enableDetachOldChildList`
into a single enum flag. The flag has three possible values. Each level
is a superset of the previous one and performs more aggressive clean up.

We will use this to compare the memory impact of each level.

* Add Flow type to new host config method

* Re-use existing recursive clean up path

We already have a recursive loop that visits every deleted fiber. We
can re-use that one for clean up instead of adding another one.

Co-authored-by: Andrew Clark <git@andrewclark.io>
2021-03-22 21:54:53 -07:00
Dan Abramov
7c4e6aae3e Oops, it's 2021 already 2021-03-22 22:50:37 +00:00
Sebastian Markbåge
8fe7810e70 Remove already completed comment (#21054) 2021-03-22 15:41:22 -07:00
Dan Abramov
cc1a46dfd2 React 17.0.2 Changelog (#21052)
## 17.0.2 (March 22, 2020)

### React DOM

* Remove an unused dependency to address the [`SharedArrayBuffer` cross-origin isolation warning](https://developer.chrome.com/blog/enabling-shared-array-buffer/). ([@koba04](https://github.com/koba04) and [@bvaughn](https://github.com/bvaughn) in [#20831](https://github.com/facebook/react/pull/20831), [#20832](https://github.com/facebook/react/pull/20832), and [#20840](https://github.com/facebook/react/pull/20840))
2021-03-22 21:57:59 +00:00
Dan Abramov
a5c3baeecd Fix a broken link 2021-03-22 21:04:13 +00:00
Sebastian Markbåge
6c3202b1e1 [Fizz] Use identifierPrefix to avoid conflicts within the same response (#21037)
* Use identifierPrefix to avoid conflicts within the same response

identifierPrefix as an option exists to avoid useOpaqueIdentifier conflicting
when different renders are used within one HTML response.

This lets this be configured for the DOM renderer specifically since it's DOM
specific whether they will conflict across trees or not.

* Add test for using multiple containers in one HTML document
2021-03-22 13:10:57 -07:00
Andrew Clark
dcdf8de7e1 Remove discrete lanes and priorities (#21040)
We use SyncLane everywhere we used to use InputDiscreteLane or
InputDiscreteHydrationLane. So we can delete them now, along with their
associated lane priority levels.
2021-03-22 09:51:40 -07:00
Ricky
ca99ae97b4 Replace some flushExpired callsites (#20975) 2021-03-22 12:44:19 -04:00
Andrew Clark
1fafac0028 Use SyncLane for discrete event hydration (#21038)
Discrete event hydration doesn't need to be interruptible, since
there's nothing higher priority than discrete events. So we can use
SyncLane instead of a special hydration lane.
2021-03-22 09:05:43 -07:00
Andrew Clark
6d3ecb70dc Remove unstable_changedBits (#20953)
We added this unstable feature a few years ago, as a way to opt out of
context updates, but it didn't prove useful in practice.

We have other proposals for how to address the same problem, like
context selectors.

Since it was prefixed with `unstable_`, we should be able to remove it
without consequence. The hook API already warned if you used it.

Even if someone is using it somewhere, it's meant to be an optimization
only, so if they are using the API properly, it should not have any
semantic impact.
2021-03-19 15:36:51 -07:00
Andrew Clark
754e307284 Delete immediateQueueCallbackNode (#20980)
We don't need this anymore. It only existed so we could cancel the
callback later. But canceling isn't necessary, was only an
"optimization" for something that almost never happens in practice.
2021-03-19 15:36:23 -07:00
Andrew Clark
be5a2e231a Land enableSyncMicrotasks (#20979) 2021-03-19 15:28:41 -07:00
Sebastian Markbåge
f6bc9c8243 [Fizz] Expose maxBoundarySize as an option (#21029)
* Expose maxBoundarySize as an option

* Adjust the heuristic

* Rename to progressiveChunkSize
2021-03-19 09:41:25 -07:00
Brian Vaughn
7d06b80af6 Fixed primitive hook badge colors for light theme (#21034) 2021-03-19 09:52:59 -04:00
Sebastian Markbåge
154b85213a [Fizz] Expose a method to explicitly start writing to a Node stream (#21028)
* Expose an explicit point when to start writing in the Node API

* Add a previously failing test
2021-03-18 12:43:40 -07:00
Sebastian Markbåge
cf485e6f6b [Fizz] Expose a method to abort a pending request (#21027)
* Track all suspended work while it's still pending

This allows us to abort work and put everything into client rendered mode
if we don't want to wait for further I/O.

It also allows us to cancel fallbacks if we complete the main content
before the fallback.

* Expose abort API to the browser streams

Since this API already returns a value, we need to use destructuring to
expose more options.

* Add a test including the client actually client rendering it

* Use AbortSignal option for W3C streams instead of external control

* Clean up listener after it's used once
2021-03-18 09:46:15 -07:00
Timothy Yung
3fb11eed9a React Native: Touch Instrumentation Interface (#21024) 2021-03-17 13:46:43 -07:00
Brian Vaughn
119736b1c2 [FB-only] Show which hooks (indices) changed when profiling (#20998) 2021-03-17 12:28:21 -04:00
Brian Vaughn
bf11788bf0 DevTools Profiler: Add commit and post-commit durations to UI (#20984) 2021-03-17 12:27:37 -04:00
Sebastian Markbåge
825c3021f0 Don't delete trailing mismatches during hydration at the root (#21021)
* Don't delete any trailing nodes in the container during hydration error

* Warn when an error during hydration causes us to clear the container

* Encode unfortunate case in test

* Wrap the root for tests that are applicable to nested cases

* Now we can pipe Fizz into a container

* Grammatical fix
2021-03-17 08:18:42 -07:00
Sebastian Markbåge
1d1e49cfa4 [Fizz] Assign an ID to the first DOM element in a fallback or insert a dummy (and testing infra) (#21020)
* Patches

* Add Fizz testing infra structure

* Assign an ID to the first DOM node in a fallback or insert a dummy

* unstable_createRoot
2021-03-16 14:05:52 -07:00
Brian Vaughn
533aed8de6 Speed up DevTools local build script (#21018) 2021-03-16 14:02:24 -04:00
Brian Vaughn
466b26c926 Store commit durations on HostRoot for DevTools access (#20983)
Also add missing feature flag wrappers around effect duration attributes.
2021-03-16 13:53:15 -04:00
Ricky
89acfa639b Fix native event batching in concurrent mode (#21010)
* Fix native event batching in concurrent mode

* Wrap DevTools test updates with act

These tests expect the `scheduleUpdate` DevTools hook to trigger a
synchronous re-render with legacy semantics, but flushing in a microtask
is fine. Wrapping the updates with `act` fixes it.

* Testing nits

* Nit: Check executionContext === NoContext first

In the common case it will be false and the binary expression will
short circuit.

Co-authored-by: Andrew Clark <git@andrewclark.io>
2021-03-16 13:15:00 -04:00
susiwen8
0203b6567c chore: update react-reconciler README (#21016) 2021-03-16 11:37:34 +00:00
Timothy Yung
c9f6d0a3a8 Sync ReactNativeTypes from React Native (#21015) 2021-03-15 23:48:59 -07:00
Joshua Gross
f8979e0e28 Revert 'Fabric-compatible implementation of feature' and have Fabric noop when setJSResponder is called for now (#21009) 2021-03-15 12:22:26 -07:00
Sebastian Markbåge
b9c4a01f71 Allow the streaming config to decide how to precompute or compute chunks (#21008)
Some legacy environments can not encode non-strings. Those would specify
both as strings. They'll throw for binary data.

Some environments have to encode strings (like web streams). Those would
encode both as uint8array.

Some environments (like Node) can do either. It can be beneficial to leave
things as strings in case the native stream can do something smart with it.
2021-03-15 10:36:23 -07:00
Sebastian Silbermann
00d4f95c2a Document prerequisites for download-experimental-build (#21005) 2021-03-15 09:48:44 -04:00
Hector Rincon
c06d245fc7 Update devtools-extensions build script to reflect changes in local b… (#21004)
Co-authored-by: Brian Vaughn <bvaughn@fb.com>
2021-03-15 09:46:46 -04:00
Sebastian Markbåge
f227e7f26b Clean up unused functions from SSR (#20995) 2021-03-13 07:23:06 -08:00
Sebastian Markbåge
14e4fd1ff2 [Fizz] Move DOM/Native format configs to their respective packages (#20994)
* Move DOM/Native format configs to their respective packages

The streaming configs (Node/Browser) are different because they operate at
another dimension that exists in each package.

* Use escapeTextForBrowser to encode dynamic strings

We can now use local dependencies
2021-03-13 06:54:59 -08:00
Sebastian Markbåge
f2b6bf7c86 [Fizz] Destroy the stream with an error if the root throws (#20992)
* Destroy the stream with an error if the root throws

But not if the error happens inside a suspense boundary.

* Try rewriting the test to see if it works in other Node envs
2021-03-12 15:21:02 -08:00
Sebastian Markbåge
10cc400184 Basic Fizz Architecture (#20970)
* Copy some infra structure patterns from Flight

* Basic data structures

* Move structural nodes and instruction commands to host config

* Move instruction command to host config

In the DOM this is implemented as script tags. The first time it's emitted
it includes the function. Future calls invoke the same function.

The side of the complete boundary function in particular is unfortunately
large.

* Implement Fizz Noop host configs

This is implemented not as a serialized protocol but by-passing the
serialization when possible and instead it's like a live tree being
built.

* Implement React Native host config

This is not wired up. I just need something for the flow types since
Flight and Fizz are both handled by the isServerSupported flag.

Might as well add something though.

The principle of this format is the same structure as for HTML but a
simpler binary format.

Each entry is a tag followed by some data and terminated by null.

* Check in error codes

* Comment
2021-03-11 12:01:41 -08:00
Chris Dobson
bd245c1bab Ensure sync-xhr is allowed before reload and profile (#20879)
Co-authored-by: Brian Vaughn <brian.david.vaughn@gmail.com>
2021-03-11 10:31:57 -05:00
Andrew Clark
b7e6310669 Stop tracking roots with pending discrete updates (#20978)
Now that discrete updates are flushed synchronously in a microtask,
there's no need to track them in their on queue. They're already in
the queue we use for all sync work. So we can call that directly.
2021-03-10 23:29:29 -08:00
Ricky
860f673a7a Remove Blocking Mode (again) (#20974)
* Remove Blocking Mode (again)

* Rename batchingmode file and comment
2021-03-10 18:34:35 -05:00
Ricky
acde654698 Unify InputDiscreteLane with SyncLane (#20968)
* Unify sync priority and input discrete

* Fix lint

* Use update lane instead

* Update sync lane labels
2021-03-10 17:36:13 -05:00
Brian Vaughn
6556e2a874 Cleaned up unused PassiveUnmountPendingDev DEV flag (#20973) 2021-03-10 17:09:24 -05:00
Ricky
60182d64ca Cleanup tests using runWithPriority. (#20958)
* Remove Scheduler.runWithPriority from some tests

* Mark experimental test experimental
2021-03-10 12:44:25 -05:00
Brian Vaughn
ec372faefe Remove DevTools dependency on Scheduler runWithPriority (#20967) 2021-03-10 08:52:19 -05:00
Ricky
e4d4b7074d Land enableNativeEventPriorityInference (#20955)
* Land enableNativeEventPriorityInference

* Move schedulerPriorityToLanePriority

* Remove obsolete comment
2021-03-09 23:59:02 -05:00
Ricky
5d1d1679bf Remove scheduler priority from hydration (#20957) 2021-03-09 17:25:23 -05:00
Ricky
73e900b0e7 Land enableDiscreteEventMicroTasks (#20954) 2021-03-08 16:43:44 -05:00
Rick Hanlon
a3f30fed29 Trigger Build 2021-03-08 14:28:58 -07:00
Rick Hanlon
41e62e7719 Remove runWithPriority internally 2021-03-08 12:49:57 -07:00
Rick Hanlon
431e76e2db Switch callsites over to update lane priority 2021-03-08 12:49:57 -07:00
Rick Hanlon
e89d74ee67 Remove decoupleUpdatePriorityFromScheduler 2021-03-08 12:49:57 -07:00
Brian Vaughn
5fe091c778 Swap log with cbrt for commit bar height (#20952) 2021-03-08 14:02:09 -05:00
Sebastian Silbermann
ca15606d81 chore(build): Ensure experimental builds exists on windows (#20933)
* chore(build): Throw if `rsync` fails

* did not get cwrsync to work
2021-03-08 17:35:27 +00:00
Brian Vaughn
e7d2a558ad DevTools flushes updated passive warning/error info after delay (#20931)
* DevTools flushes updated passive warning/error info after delay
Previously this information was not flushed until the next commit, but this provides a worse user experience if the next commit is really delayed. Instead, the backend now flushes only the warning/error counts after a delay. As a safety, if there are already any pending operations in the queue, we bail.

Co-authored-by: eps1lon <silbermann.sebastian@gmail.com>
2021-03-08 11:33:14 -05:00
Brian Vaughn
cb88572227 Improve DevTools Profiler commit-selector UX (#20943)
* Improve DevTools Profiler commit-selector UX

1. Use natural log of durations (rather than linear) when calculating bar height. This reduces the impact of one (or few) outlier times on more common smaller durations. (Continue to use linear for bar color though.)
2. Decrease the minimum bar height to make the differences in height more noticeable.
3. Add a background hover highlight to increase contrast.
4. Add hover tooltip with commit duration and timestamp.
2021-03-08 11:09:55 -05:00
Ricky
d74559746c Use update lane priority to set pending updates on roots (#20918) 2021-03-07 18:43:29 -05:00
Andrew Clark
f04bcb8139 [Bugfix] Reset subtreeFlags in resetWorkInProgress (#20948)
* Add failing regression test

Based on #20932

Co-Authored-By: Dan Abramov <dan.abramov@gmail.com>

* Reset `subtreeFlags` in `resetWorkInProgress`

Alternate fix to #20942

There was already a TODO to make this change, but at the time I left it,
I couldn't think of a way that it would actually cause a bug, and I was
hesistant to change something without fully understanding the
ramifications. This was during a time when we were hunting down a
different bug, so we were especially risk averse.

What I should have done in retrospect is put the change behind a flag
and tried rolling it out once the other bug had been flushed out.

OTOH, now we have a regression test, which wouldn't have otherwise, and
the bug it caused rarely fired in production.

Co-authored-by: Dan Abramov <dan.abramov@gmail.com>
2021-03-07 09:20:01 -08:00
Andrew Clark
c7b4497988 [Experiment] Lazily propagate context changes (#20890)
* Move context comparison to consumer

In the lazy context implementation, not all context changes are
propagated from the provider, so we can't rely on the propagation alone
to mark the consumer as dirty. The consumer needs to compare to the
previous value, like we do for state and context.

I added a `memoizedValue` field to the context dependency type. Then in
the consumer, we iterate over the current dependencies to see if
something changed. We only do this iteration after props and state has
already bailed out, so it's a relatively uncommon path, except at the
root of a changed subtree. Alternatively, we could move these
comparisons into `readContext`, but that's a much hotter path, so I
think this is an appropriate trade off.

* [Experiment] Lazily propagate context changes

When a context provider changes, we scan the tree for matching consumers
and mark them as dirty so that we know they have pending work. This
prevents us from bailing out if, say, an intermediate wrapper is
memoized.

Currently, we propagate these changes eagerly, at the provider.

However, in many cases, we would have ended up visiting the consumer
nodes anyway, as part of the normal render traversal, because there's no
memoized node in between that bails out.

We can save CPU cycles by propagating changes only when we hit a
memoized component — so, instead of propagating eagerly at the provider,
we propagate lazily if or when something bails out.

Most of our bailout logic is centralized in
`bailoutOnAlreadyFinishedWork`, so this ended up being not that
difficult to implement correctly.

There are some exceptions: Suspense and Offscreen. Those are special
because they sometimes defer the rendering of their children to a
completely separate render cycle. In those cases, we must take extra
care to propagate *all* the context changes, not just the first one.

I'm pleasantly surprised at how little I needed to change in this
initial implementation. I was worried I'd have to use the reconciler
fork, but I ended up being able to wrap all my changes in a regular
feature flag. So, we could run an experiment in parallel to our other
ones.

I do consider this a risky rollout overall because of the potential for
subtle semantic deviations. However, the model is simple enough that I
don't expect us to have trouble fixing regressions if or when they arise
during internal dogfooding.

---

This is largely based on [RFC#118](https://github.com/reactjs/rfcs/pull/118),
by @gnoff. I did deviate in some of the implementation details, though.

The main one is how I chose to track context changes. Instead of storing
a dirty flag on the stack, I added a `memoizedValue` field to the
context dependency object. Then, to check if something has changed, the
consumer compares the new context value to the old (memoized) one.

This is necessary because of Suspense and Offscreen — those components
defer work from one render into a later one. When the subtree continues
rendering, the stack from the previous render is no longer available.
But the memoized values on the dependencies list are. This requires a
bit more work when a consumer bails out, but nothing considerable, and
there are ways we could optimize it even further. Conceptually, this
model is really appealing, since it matches how our other features
"reactively" detect changes — `useMemo`, `useEffect`,
`getDerivedStateFromProps`, the built-in cache, and so on.

I also intentionally dropped support for
`unstable_calculateChangedBits`. We're planning to remove this API
anyway before the next major release, in favor of context selectors.
It's an unstable feature that we never advertised; I don't think it's
seen much adoption.

Co-Authored-By: Josh Story <jcs.gnoff@gmail.com>

* Propagate all contexts in single pass

Instead of propagating the tree once per changed context, we can check
all the contexts in a single propagation. This inverts the two loops so
that the faster loop (O(numberOfContexts)) is inside the more expensive
loop (O(numberOfFibers * avgContextDepsPerFiber)).

This adds a bit of overhead to the case where only a single context
changes because you have to unwrap the context from the array. I'm also
unsure if this will hurt cache locality.

Co-Authored-By: Josh Story <jcs.gnoff@gmail.com>

* Stop propagating at nearest dependency match

Because we now propagate all context providers in a single traversal, we
can defer context propagation to a subtree without losing information
about which context providers we're deferring — it's all of them.

Theoretically, this is a big optimization because it means we'll never
propagate to any tree that has work scheduled on it, nor will we ever
propagate the same tree twice.

There's an awkward case related to bailing out of the siblings of a
context consumer. Because those siblings don't bail out until after
they've already entered the begin phase, we have to do extra work to
make sure they don't unecessarily propagate context again. We could
avoid this by adding an earlier bailout for sibling nodes, something
we've discussed in the past. We should consider this during the next
refactor of the fiber tree structure.

Co-Authored-By: Josh Story <jcs.gnoff@gmail.com>

* Mark trees that need propagation in readContext

Instead of storing matched context consumers in a Set, we can mark
when a consumer receives an update inside `readContext`.

I hesistated to put anything in this function because it's such a hot
path, but so are bail outs. Fortunately, we only need to set this flag
once, the first time a context is read. So I think it's a reasonable
trade off.

In exchange, propagation is faster because we no longer need to
accumulate a Set of matched consumers, and fiber bailouts are faster
because we don't need to consult that Set. And the code is simpler.

Co-authored-by: Josh Story <jcs.gnoff@gmail.com>
2021-03-06 22:56:53 -08:00
Andrew Clark
258b375a41 Move context comparison to consumer
In the lazy context implementation, not all context changes are
propagated from the provider, so we can't rely on the propagation alone
to mark the consumer as dirty. The consumer needs to compare to the
previous value, like we do for state and context.

I added a `memoizedValue` field to the context dependency type. Then in
the consumer, we iterate over the current dependencies to see if
something changed. We only do this iteration after props and state has
already bailed out, so it's a relatively uncommon path, except at the
root of a changed subtree. Alternatively, we could move these
comparisons into `readContext`, but that's a much hotter path, so I
think this is an appropriate trade off.
2021-03-07 00:37:15 -06:00
Brian Vaughn
7df65725ba Split getComponentName into getComponentNameFromFiber and getComponentNameFromType (#20940)
Split getComponentName into getComponentNameFromFiber and getComponentNameFromType
2021-03-05 16:02:02 -05:00
Andrew Clark
ee43263572 Revert "Remove blocking mode and blocking root (#20888)" (#20916)
This reverts commit 553440bd15.
2021-03-02 12:51:18 -08:00
Andrew Clark
de0ee76dbd Add unstable_strictModeLevel to test renderer (#20914)
Matches what we do for React DOM
2021-03-02 10:41:57 -08:00
Dan Abramov
d857f9e4d0 Land enableSetImmediate feature flag (#20906) 2021-03-01 18:34:12 +00:00
Ricky
553440bd15 Remove blocking mode and blocking root (#20888)
* Remove blocking mode and blocking root

* Add back SuspenseList test

* Clean up ReactDOMLegacyRoot

* Remove dupe ConcurrentRoot

* Update comment
2021-02-28 01:14:54 -05:00
Bowen
38f392ceda typo fix for the word 'Psuedo' (#20894)
Co-authored-by: Bowen Li <bowen31337@gmail.com>
2021-02-26 16:11:28 -05:00
Ricky
0cf9fc10ba Fix React Native flow types (#20889) 2021-02-26 00:00:32 -05:00
Ricky
2e8bbcb54e Fix react-devtools-scheduling-profiler tests on main (#20885) 2021-02-25 19:10:25 -05:00
Ricky
c581cdd480 Schedule sync updates in microtask (#20872)
* Schedule sync updates in microtask

* Updates from review

* Fix comment
2021-02-25 17:25:25 -05:00
Brian Vaughn
90bde6505e Add SuspenseList to react-is (#20874)
This commit also adds explicit index.stable and index.experimental forks to the react-is package so that we can avoid exporting references to SuspenseList in a stable release.
2021-02-25 16:22:33 -05:00
Rubén Norte
8336f19aa8 Update React Native types (#20883) 2021-02-25 16:10:17 -05:00
Brian Vaughn
9209c30ff9 Add StrictMode level prop and createRoot unstable_strictModeLevel option (#20849)
* The exported '<React.StrictMode>' tag remains the same and opts legacy subtrees into strict mode level one ('mode == StrictModeL1'). This mode enables DEV-only double rendering, double component lifecycles, string ref warnings, legacy context warnings, etc. The primary purpose of this mode is to help detected render phase side effects. No new behavior. Roots created with experimental 'createRoot' and 'createBlockingRoot' APIs will also (for now) continue to default to strict mode level 1.

In a subsequent commit I will add support for a 'level' attribute on the '<React.StrictMode>' tag (as well as a new option supported by ). This will be the way to opt into strict mode level 2 ('mode == StrictModeL2'). This mode will enable DEV-only double invoking of effects on initial mount. This will simulate future Offscreen API semantics for trees being mounted, then hidden, and then shown again. The primary purpose of this mode is to enable applications to prepare for compatibility with the new Offscreen API (more information to follow shortly).

For now, this commit changes no public facing behavior. The only mechanism for opting into strict mode level 2 is the pre-existing 'enableDoubleInvokingEffects' feature flag (only enabled within Facebook for now).

* Renamed strict mode constants

StrictModeL1 -> StrictLegacyMode and StrictModeL2 -> StrictEffectsMode

* Renamed tests

* Split strict effects mode into two flags

One flag ('enableStrictEffects') enables strict mode level 2. It is similar to 'debugRenderPhaseSideEffectsForStrictMode' which enables srtict mode level 1.

The second flag ('createRootStrictEffectsByDefault') controls the default strict mode level for 'createRoot' trees. For now, all 'createRoot' trees remain level 1 by default. We will experiment with level 2 within Facebook.

This is a prerequisite for adding a configurable option to 'createRoot' that enables choosing a different StrictMode level than the default.

* Add StrictMode 'unstable_level' prop and createRoot 'unstable_strictModeLevel' option

New StrictMode 'unstable_level' prop allows specifying which level of strict mode to use. If no level attribute is specified, StrictLegacyMode will be used to maintain backwards compatibility. Otherwise the following is true:
* Level 0 does nothing
* Level 1 selects StrictLegacyMode
* Level 2 selects StrictEffectsMode (which includes StrictLegacyMode)

Levels can be increased with nesting (0 -> 1 -> 2) but not decreased.

This commit also adds a new 'unstable_strictModeLevel' option to the createRoot and createBatchedRoot APIs. This option can be used to override default behavior to increase or decrease the StrictMode level of the root.

A subsequent commit will add additional DEV warnings:
* If a nested StrictMode tag attempts to explicitly decrease the level
* If a level attribute changes in an update
2021-02-24 16:14:14 -05:00
Brian Vaughn
4190a34588 Update scheduling profiler Webpack config (#20867)
Use the pre-built scheduler (which includes a check for 'window' being defined in order to load the right scheduler implementation) rather than just directly importing a version of the scheduler that relies on window. Since the scheduling profiler's code runs partially in a web worker, it can't rely on window.
2021-02-23 12:15:36 -05:00
Brian Vaughn
e5f6b91d29 Add Lane labels to scheduling profiler marks (#20808)
This commit changes scheduling profiler marks from a format like '--schedule-render-1' to '--schedule-render-1-Sync' (where 1 is the numeric value of the Sync lane). This will enable the profiler itself to show more meaningful labels for updates and render work.

The commit also refactors and adds additional tests for the scheduling profiler package.

It also updates the preprocessor to 'support' instant events. These are no-ops for us, but adding recognition of the event type will prevent profiles imported from e.g. Chrome Canary from throwing with an 'unrecognized event' error. (This will resolve issue #20767.)
2021-02-23 11:31:29 -05:00
Anthony Garritano
c62986cfd8 Add additional messaging for RulesOfHooks lint error (#20692)
* Add additional messaging for RulesOfHooks lint error

* Fix tests and spacing issue

* Prettify ESLintRulesOfHooks-test
2021-02-22 19:17:13 -05:00
Valentin Shergin
78d2f2d301 Fabric-compatible implementation of JSReponder feature (#20768)
With this change, if a node is a Fabric node, we route the setJSResponder call to FabricUIManager. Native counterpart is already landed. Tested internally as D26241364.
2021-02-22 16:50:03 -05:00
Brian Vaughn
cfd8c1bd43 DevTools: Restore inspect-element bridge optimizations (#20789)
* Restore inspect-element bridge optimizations

When the new Suspense cache was integrated (so that startTransition could be used) I removed a couple of optimizations between the backend and frontend that reduced bridge traffic when e.g. dehydrated paths were inspected for elements that had not rendered since previously inspected. This commit re-adds those optimizations as well as an additional test with a bug fix that I noticed while reading the backend code.

There are two remaining TODO items as of this commit:
- Make inspected element edits and deletes also use transition API
- Don't over-eagerly refresh the cache in our ping-for-updates handler

I will addres both in subsequent commits.

* Poll for update only refreshes cache when there's an update

* Added inline comment
2021-02-22 14:04:20 -05:00
Ricky
4d28eca97e Land enableNonInterruptingNormalPri (#20859) 2021-02-22 12:56:54 -05:00
Brian Vaughn
8af27aeedb Remove scheduler sampling profiler shared array buffer (#20840)
No one has been using this data so there's no reason to collect it. Event log has been maintained and tests have been updated.
2021-02-18 11:21:52 -05:00
Brian Vaughn
af3d52611d Disable (unstable) scheduler sampling profiler for OSS builds (#20832)
* Disabled Scheduler sampling profiler for OSS builds
* Added missing conditional feature flag around profiling calls
2021-02-18 11:06:53 -05:00
Toru Kobayashi
8fa0ccca00 fix: use SharedArrayBuffer only when cross-origin isolation is enabled (#20831)
* fix: check cross-origin isolation for SharedArrayBuffer

* chore: remove unused a $FlowFixMe comment

* prettier
2021-02-17 16:43:25 -05:00
Dan Abramov
0991647921 Use setImmediate when available over MessageChannel (#20834)
* Move direct port access into a function

* Fork based on presence of setImmediate

* Copy SchedulerDOM-test into another file

* Change the new test to use shimmed setImmediate

* Clarify comment

* Fix test to work with existing feature detection

* Add flags

* Disable OSS flag and skip tests

* Use VARIANT to reenable tests

* lol
2021-02-17 21:00:42 +00:00
Andrew Clark
e2fd460cca Bailout in sync task if work is not sync (#20813)
Because we don't cancel synchronous tasks, sometimes more than one
synchronous task ends up being scheduled. This is an artifact of the
fact that we have two different lanes that schedule sync tasks: discrete
and sync. So what can happen is that a discrete update gets scheduled,
then a sync update right after that. Because sync is encoded as higher
priority than discrete, we schedule a second sync task. And since we
don't cancel the first one, there are now two separate sync tasks.

As a next step, what we should do is merge InputDiscreteLane with
SyncLane, then (I believe) this extra bailout wouldn't be necessary,
because there's nothing higher priority than sync that would cause us to
cancel it. Though we may want to add logging to be sure.
2021-02-16 12:38:11 -08:00
Andrew Clark
9e8f3c8955 [CI] Use constant commit sha (#20828)
When running the publish workflow, either via the command line or
via the daily cron job, we should use a constant SHA instead of
whatever happens to be at the head of the main branch at the time the
workflow is run.

The difference is subtle: currently, the SHA is read at runtime,
each time the workflow is run. With this change, the SHA is read right
before the workflow is created and passed in as a constant parameter.

In practical terms, this means if a workflow is re-run via the CircleCI
web UI, it will always re-run using the same commit SHA as the original
workflow, instead of fetching the latest SHA from GitHub, which may
have changed.

Also avoids a race condition where the head SHA changes in between the
Next publish job and the Experimental publish job.
2021-02-16 08:31:24 -08:00
Andrew Clark
6f8843837c [CI] Publish to release channels sequentially (#20827)
npm will sometimes fail if you try to concurrently publish two different
versions of the same package, even if they use different dist tags.

So instead of publishing to the Next and Experimental channels
simultaneously, we'll do them one after the other.

If we did want to speed up these publish workflows, we could paralellize
by package instead of by release channel.
2021-02-15 22:04:13 -08:00
Andrew Clark
1a74726246 Add supportsMicrotasks to the host config (#20809)
* Add `supportsMicrotasks` to the host config

Only certain renderers support scheduling a microtask, so we need a
renderer specific flag that we can toggle. That way it's off for some
renderers and on for others.

I copied the approach we use for the other optional parts of the host
config, like persistent mode and test selectors.

Why isn't the feature flag sufficient?

The feature flag modules, confusingly, are not renderer-specific, at
least when running the our tests against the source files. They are
meant to correspond to a release channel, not a renderer, but we got
confused at some point and haven't cleaned it up.

For example, when we run `yarn test`, Jest loads the flags from the
default `ReactFeatureFlags.js` module, even when we import the React
Native renderer — but in the actual builds, we load a different feature
flag module, `ReactFeatureFlags.native-oss.js.` There's no way in our
current Jest load a different host config for each renderer, because
they all just import the same module. We should solve this by creating
separate Jest project for each renderer, so that the flags loaded when
running against source are the same ones that we use in the
compiled bundles.

The feature flag (`enableDiscreteMicrotasks`) still exists — it's used
to set the React DOM host config's `supportsMicrotasks` flag to `true`.
(Same for React Noop) The important part is that turning on the feature
flag does *not* affect the other renderers, like React Native.

The host config will likely outlive the feature flag, too, since the
feature flag only exists so we can gradually roll it out and measure the
impact in production; once we do, we'll remove it. Whereas the host
config flag may continue to be used to disable the discrete microtask
behavior for RN, because RN will likely use a native (non-JavaScript)
API to schedule its tasks.

* Add `supportsMicrotask` to react-reconciler README
2021-02-12 13:13:49 -08:00
Andrew Clark
696e736be1 Warn if static flag is accidentally cleared (#20807)
* Warn if static flag is accidentally cleared

"Static" fiber flags are flags that are meant to exist for the lifetime
of a component. It's really important not to accidentally reset these,
because we use them to decide whether or not to perform some operation
on a tree (which we can do because they get bubbled via `subtreeFlags)`.

We've had several bugs that were caused by this mistake, so we actually
don't rely on static flags anywhere, yet. But we'd like to.

So let's roll out this warning and see if it fires anywhere. Once we
can confirm that there are no warnings, we can assume that it's safe
to start using static flags.

I did not wrap it behind a feature flag, because it's dev-only, and we
can use our internal warning filter to hide this from the console.

* Intentionally clear static flag to test warning

* ...and fix it again
2021-02-11 14:20:46 -08:00
Andrew Clark
483358c38f Omit TransitionHydrationLane from TransitionLanes (#20802)
Follow up to #20793

I don't this makes any observable difference, but this is how it was
before so might as well be consistent just in case.
2021-02-10 22:07:19 -08:00
inokawa
78ec97d34a Fix typo (#20466) 2021-02-10 23:35:41 -05:00
Matt Wood
4c5275fec7 Fix typo in comment for react-devtools-shared (#20459) 2021-02-10 23:35:24 -05:00
Max Donchenko
67e8419823 Request to update email (#20533) 2021-02-10 23:34:07 -05:00
neroneroffy
6cdc35972d fix comments of markUpdateLaneFromFiberToRoot (#20546) 2021-02-10 23:26:26 -05:00
Andrew Clark
47dd9f4413 Remove fakeCallbackNode (#20799)
Don't need this, because sync tasks are never cancelled. We can do the
same thing we do for microtask callbacks.
2021-02-10 20:03:50 -08:00
Andrew Clark
114ab52953 Make remaining empty lanes Transition lanes (#20793)
Doesn't really have any effect now because we batch everything together
anyway but will allow for more parallelism once we support that.
2021-02-10 18:25:33 -06:00
Andrew Clark
d3d2451a08 Use a single lane per priority level (#20791)
(Except transitions and retries.)

The idea is that the only priorities that benefit from multiple parallel
updates are the ones that might suspend: transitions and retries. All
other priorities, including the ones that are interruptible like
Continuous and Idle, don't need multiple lanes because it's better to
batch everything together.
2021-02-10 16:09:35 -08:00
Andrew Clark
b593a6f778 CI job to check that forks are in sync (#20795)
We don't always keep the reconciler forks in sync (otherwise it we
wouldn't have forked it) but during periods when they are meant to be in
sync, we use this job to confirm there are no differences.
2021-02-10 16:09:20 -08:00
Andrew Clark
9e9be6c6b3 Parallelize Flow in CI (#20794)
* Parallelize Flow in CI

We added more host configs recently, and we run all the checks in
sequence, so sometimes Flow ends up being the slowest CI job.

This splits the job across multiple processes.

* Fix environment variable typo

Co-authored-by: Ricky <rickhanlonii@gmail.com>

Co-authored-by: Ricky <rickhanlonii@gmail.com>
2021-02-10 17:54:58 -06:00
Andrew Clark
eee874ce6e Cross-fork lint: Support named export declaration (#20784)
Noticed this didn't work when I ran `replace-fork` and a named export
declaration in ReactFiberReconciler was not properly fixed.
2021-02-10 11:01:52 -08:00
Andrew Clark
3b870b1e09 Lane enableTransitionEntanglement flag (#20775) 2021-02-10 00:25:39 -08:00
Andrew Clark
d1845ad0ff Default updates should not interrupt transitions (#20771)
The only difference between default updates and transition updates is
that default updates do not support suspended refreshes — they will
instantly display a fallback.

Co-authored-by: Rick Hanlon <rickhanlonii@gmail.com>
2021-02-10 00:00:24 -08:00
Andrew Clark
3499c343ab Apply #20778 to new fork, too (#20782)
* Apply #20778 to new fork, too

* Fix tests that use runWithPriority

Where possible, I tried to rewrite in terms of an idiomatic API.

For DOM tests, we should be dispatching an event with the desired
priority level.

For Idle updates (very unstable feature), probably need an unstable
API like ReactDOM.unstable_IdleUpdates.

Some of these fixes are not great, but we can replace them once we've
landed the more of our planned changes to the layering between
Scheduler, the reconciler, and the renderer.
2021-02-09 23:21:46 -08:00
Dan Abramov
3d10eca241 Move scheduler priority check into ReactDOM (#20778)
* Move scheduler priority check into ReactDOM

* TODO
2021-02-09 22:54:57 +00:00
Dan Abramov
ad8211d96a Add more non-React events to the priority list (#20774)
* Add a test for mouseover being continuous

* Add more non-React events to the priority list
2021-02-09 22:04:23 +00:00
Dan Abramov
d919e2c41c Add tests for non-React discrete events flushing in a microtask (#20772)
* Convert some old discrete tests to Hooks

I'm planning to copy paste so why not update them anyway.

* Copy paste discrete tests into another file

These are still using React events. I'll change that next.

* Convert the test to use native events
2021-02-09 19:56:15 +00:00
Dan Abramov
97fce318a6 Experiment: Infer the current event priority from the native event (#20748)
* Add the feature flag

* Add a host config method

* Wire it up to the work loop

* Export constants for third-party renderers

* Document for third-party renderers
2021-02-09 18:32:20 +00:00
Andrew Clark
6c526c5153 Don't shift interleaved updates to separate lane (#20681)
Now that interleaved updates are added to a special queue, we no longer
need to shift them into their own lane. We can add to a lane that's
already in the middle of rendering without risk of tearing.

See #20615 for more background.

I've only changed this in the new fork, and only behind the
enableTransitionEntanglements flag.

Most of this commit involves updating tests. The "shift-to-a-new" lane
trick was intentionally used in a handful of tests where two or more
updates need to be scheduled in different lanes. Most of these tests
were written before `startTransition` existed, and all of them were
written before transitions were assigned arbitrary lanes.

So I ported these tests to use `startTransition` instead, which is the
idiomatic way to mark an update as parallel.

I didn't change the old fork at all. Writing these tests in such a way
that they also pass in the old fork actually revealed a few flaws in the
current implementation regarding interrupting a suspended refresh
transition early, which is a good reminder that we should be writing our
tests using idiomatic patterns as much as we possibly can.
2021-02-09 00:03:07 -08:00
Dan Abramov
35f7441d37 Use Lanes instead of priority event constants (#20762) 2021-02-08 22:30:23 +00:00
Dan Abramov
b4658f2daa Reduce some constant duplication (#20761)
* Reduce some constant duplication

* Alphabetize
2021-02-08 22:30:12 +00:00
Andrew Clark
a014c915c7 Parallel transitions: Assign different lanes to consecutive transitions (#20672)
* Land enableTransitionEntanglement changes

Leaving the flag though because I plan to reuse it for additional,
similar changes.

* Assign different lanes to consecutive transitions

Currently we always assign the same lane to all transitions. This means
if there are two pending transitions at the same time, neither
transition can finish until both can finish, even if they affect
completely separate parts of the UI.

The new approach is to assign a different lane to each consecutive
transition, by shifting the bit to the right each time. When we reach
the end of the bit range, we cycle back to the first bit. In practice,
this should mean that all transitions get their own dedicated lane,
unless we have more pending transitions than lanes, which should
be rare.

We retain our existing behavior of assigning the same lane to all
transitions within the same event. This is achieved by caching the first
lane assigned to a transition, then re-using that one until the next
React task, by which point the event must have finished. This preserves
the guarantee that all transition updates that result from a single
event will be consistent.
2021-02-08 13:26:48 -08:00
Dan Abramov
77754ae618 Decouple event priority list from event name list (#20760)
* Remove some dead code

* Decouple event priority list from event name list

* Fix lint
2021-02-08 20:48:47 +00:00
Dan Abramov
b5bac18219 Align event group constant naming with lane naming (#20744)
* Rename ContinuousEvent to DefaultEvent

* Rename UserBlockingEvent to ContinuousEvent
2021-02-08 17:48:31 +00:00
Andrew Clark
bbb2ba8c8d sizebot: Combine stable and experimental results (#20753)
Because we have access to the artifacts in CI, we can read bundle sizes
directly from the filesystem, instead of the JSON files emitted by our
custom Rollup plugin.

This gives us some flexibility if we ever have artifacts that aren't
generated by Rollup, or if we rewrite our build script.

Personally, I also prefer to see the whole file path, instead of just
the name, because some of our names are repeated.

My immediate motivation, though, is because it gives us a way to merge
the separate "experimental" and "stable" size results. Instead
everything is reported in a single table and disambiguated by path.

I also added a section at the top that always displays the size impact
to certain critical bundles — right now, that's the React DOM production
bundles for each release channel. This section will also include any
size changes larger than 2%.

Below that is a section that is collapsed by default and includes all
size changes larger than 0.2%.
2021-02-06 12:57:11 -08:00
Andrew Clark
903384ab0c sizebot: Fix wrong order of base, head arguments (#20751)
The base and head arguments were flipped, so an n% decrease in bundle
size was instead reported as an n% increase.
2021-02-05 15:45:25 -08:00
Dan Abramov
4ecf11977c Remove the Fundamental internals (#20745) 2021-02-05 20:36:55 +00:00
Dan Abramov
eeb1325b03 Fix UMD bundles by removing usage of global (#20743) 2021-02-05 17:13:42 +00:00
Andrew Clark
4e08fb10c9 Update release documentation (#20736)
Added information about automated prereleases
2021-02-04 13:20:49 -08:00
Ricky
b12d0078a4 Fix codesandbox build command (#20731) 2021-02-04 11:24:07 -05:00
Andrew Clark
a703c3f7e8 Fix cron syntax
Let's try this again?
2021-02-04 10:07:39 -06:00
Andrew Clark
365080f4f5 Autopublish prereleases using head of main branch
Instead of using pipeline parameter. Fixes copypasta from the other
workflow, which accepts the SHA parameter via an API call.
2021-02-04 09:34:12 -06:00
Andrew Clark
f58ad2ad8e Auto-publish prereleases every weekday (#20733)
Sets up a cron trigger to publish prereleases at 16:00 UTC (11 am
Eastern, 8 am Pacific) on every weekday (Monday through Friday).
2021-02-03 21:08:34 -08:00
Andrew Clark
c64d6d21be Implement CI job that publishes prereleases (#20732)
PR #20728 added a command to initiate a prerelease using CI, but it left
the publish job unimplemented. This fills in the publish job.

Uses an npm automation token for authorization, which bypasses the need
for a one-time password. The token is configured via CircleCI's
environment variable panel.

Currently, it will always publish the head of the main branch. If the
head has already been published, it will exit gracefully.

It does not yet support publishing arbitrary commits, though we could
easily add that. I don't know how important that use case is, because
for PR branches, you can use CodeSandbox CI instead. Or as a last
resort, run the publish script locally.

Always publishing from main is nice because it further incentivizes us
to keep main in a releasable state. It also takes the guesswork out of
publishing a prerelease that's in a broken state: as long as we don't
merge broken PRs, we're fine.
2021-02-03 20:57:31 -08:00
Andrew Clark
4c019585e8 Empty commit to replace "broken" head of main
Head commit had a "broken" (but not really) CircleCI job and CircleCI
doesn't give me a way to clear/restart it. So I'm doing this.
2021-02-03 20:33:27 -06:00
Ricky
3b02ae5cc6 Add silent to codesandbox config (#20730) 2021-02-03 18:53:07 -05:00
Andrew Clark
c1cfa734fd Add command to publish preleases via CI (#20728)
```
yarn publish-prereleases
```

Script to trigger a CircleCI workflow that publishes preleases.

**The CI workflow doesn't actually publish yet; it just runs and logs
its inputs.**
2021-02-03 15:42:34 -08:00
Andrew Clark
00e38c80b2 Fallback if GitHub status is stuck as "pending" (#20729)
GitHub's status API is super flaky. Sometimes it reports a job as
"pending" even after it completes in CircleCI. If it's still pending
when we time out, return the build ID anyway. TODO: The location of the
retry loop is a bit weird. We should probably combine this function with
the one that downloads the artifacts, and wrap the retry loop around the
whole thing.
2021-02-03 15:33:46 -08:00
Andrew Clark
3be750eee9 Add --ci option to publish script (#20727)
When running in CI, the publish script will skip interactive prompts,
including the prompt for a one-time password.

Instead, CI will need to use an automation access token:
https://docs.npmjs.com/using-private-packages-in-a-ci-cd-workflow
2021-02-03 12:17:40 -08:00
Andrew Clark
85f489a129 Add publish workflow, triggerable via API request (#20726)
Adds a new CircleCI workflow, which I will use to publish prereleases
(`next` and `experimental`) for a given commit.

The CircleCI API doesn't yet support triggering a specific workflow, but
it does support triggering a pipeline. So as a workaround you can
triggger the entire pipeline and use parameters to disable everything
except the workflow you want. CircleCI recommends this workaround here:
https://support.circleci.com/hc/en-us/articles/360050351292-How-to-trigger-a-workflow-via-CircleCI-API-v2-

Eventually we can set this workflow to trigger on a cron schedule (once
per week, for example).
2021-02-03 12:17:29 -08:00
Andrew Clark
0935a1db3d Delete consolidateBundleSizes script (#20724)
This was ported to the new workflow by #20720
2021-02-03 08:45:29 -08:00
Andrew Clark
b936ab660a Update sizebot to new workflow (#20719)
* build-combined: Fix bundle sizes path

* Output COMMIT_SHA in build directory

Alternative to parsing an arbitrary package's version number, or
its `build-info.json`.

* Remove CircleCI environment variable requirement

I think this only reason we needed this was to support passing any
job id to `--build`, instead of requiring the `process_artifacts` job.
And to do that you needed to use the workflows API endpoint, which
requires an API token.

But now that the `--commit` argument exists and automatically finds the
correct job id, we can just use that.

* Add CI job that gets base artifacts

Uses download-experimental script and places the base artifacts into
a top-level folder.

* Migrate sizebot to combined workflow

Replaces the two separate sizebot jobs (one for each channel, stable and
experimental) with a single combined job that outputs size information
for all bundles in a single GitHub comment.

I didn't attempt to simplify the output at all, but we should. I think
what I would do is remove our custom Rollup sizes plugin, and read the
sizes from the filesystem instead. We would lose some information about
the build configuration used to generate each artifact, but that can be
inferred from the filepath. For example, the filepath
`fb-www/ReactDOM-dev.classic.js` already tells us everything we need to
know about the artifact. Leaving this for a follow up.

* Move GitHub status check inside retry loop

The download script will poll the CircleCI endpoint until the build job
is complete; it should also poll the GitHub status endpoint if the
build job hasn't been spawned yet.

* Only run get_base_build on main branch
2021-02-03 08:29:51 -08:00
Brian Vaughn
2d025753e2 Remove --build flag from release scripts (#20723)
Also update instructions to match recent script changes.

Also add reproducible commit SHA to post download instructions to support publishing the Firefox DevTools extension.
2021-02-03 11:11:56 -05:00
Andrew Clark
0e526bcec2 Fix release script --commit param (#20720)
PR #20717 accidentally broke the `--commit` parameter because the
script errors if you provide both a `--build` and a `--commit`.

I solved by removing the validation error. When there's a conflict, it
will choose the --`build`.

(Although maybe we should `--build` entirely and always uses `--commit`.
I think `--commit` is a sufficient replacement.)
2021-02-02 19:30:37 -08:00
Andrew Clark
7e36d8beba Some release script fixes (#20718)
* Retry loop should not start over from beginning

When the otp times out, we should not retry the packages that were
already successfully published. We should pick up where we left off.

* Don't crash if build-info.json doesn't exist

The "print follow up instructions" step crashes if build-info.json is
not found. The new build workflow doesn't include those yet (might not
need to) and since the instructions that depend on it only affect
semver (latest) releases, I've moved the code to that branch. Will
follow up with a proper fix, either by adding back a build-info.json
file or removing that dependency and reading the commit some other way.
2021-02-02 14:48:02 -08:00
Brian Vaughn
c47f3cfa17 Restore experimental build script's ability to auto download latest build (#20717) 2021-02-02 16:40:31 -05:00
Brian Vaughn
3e0bdbefa3 DevTools: Patch console methods even when only show-inline-warnings/errors enabled (#20688) 2021-02-02 10:19:53 -05:00
Andrew Clark
7cb9fd7ef8 Land interleaved updates change in main fork (#20710)
* Land #20615 in main fork

Includes change to interleaved updates.

```
yarn replace-fork
```

* Check deferRenderPhaseUpdateToNextBatch in test
2021-02-01 16:05:42 -08:00
Andrew Clark
dc27b5aaae useMutableSource: Use StrictMode double render to detect render phase mutation (#20698)
* Concurrent Mode test for uMS render mutation

Same test as the one added in #20665, but for Concurrent Mode.

* Use double render to detect render phase mutation

PR #20665 added a mechanism to detect when a `useMutableSource` source
is mutated during the render phase. It relies on the fact that we double
invoke components that error during development using
`invokeGuardedCallback`. If the version in the double render doesn't
match the first, that indicates there must have been a mutation during
render.

At first I thought it worked by detecting inside the *other* double
render, the one we do for Strict Mode. It turns out that while it does
warn then, the warning is suppressed, because we suppress all console
methods that occur during the Strict Mode double render. So it's really
the `invokeGuardedCallback` one that makes it work.

Anyway, let's set that aside that issue for a second. I realized during
review that errors that occur during the Strict Mode double render
reveal a useful property: A pure component will never throw during the
double render, because if it were pure, it would have also thrown during
the first render... in which case it wouldn't have double rendered! This
is true of all such errors, not just the one thrown by
`useMutableSource`.

Given this, we can simplify the `useMutableSource` mutation detection
mechanism. Instead of tracking and comparing the source's version, we
can instead check if we're inside a double render when the error is
thrown.

To get around the console suppression issue, I changed the warning to an
error. It errors regardless, in both dev and prod, so it doesn't have
semantic implications.

However, because of the paradox I described above, we arguably
_shouldn't_ throw an error in development, since we know that error
won't happen in production, because prod doesn't double render. (It's
still a tearing bug, but that doesn't mean the component will actually
throw.) I considered that, but that requires a larger conversation about
how to handle errors that we know are only possible in development. I
think we should probably be suppressing *all* errors (with a warning)
that occur during a double render.
2021-02-01 12:11:51 -08:00
Andrew Clark
f8545f6eb8 Add automatic retry to download script (#20704)
If build job is still pending, the script will continously poll until
it reaches the retry limit.

I've set the limit at 10 minutes, since our CI pipeline almost always
finishes before that.
2021-02-01 08:30:50 -08:00
Andrew Clark
f8b6969da6 Add --commit param to release scripts (#20703)
Alternative to `--build`. Uses same logic as sizebot and www
sync script.

Immediate motivation is I want sizebot to use the
`download-experimental-build` command in CI. Will do that next.
2021-02-01 08:27:59 -08:00
Sebastian Silbermann
bb1b7951d1 fix: don't run effects if a render phase update results in unchanged deps (#20676)
The memoized state of effect hooks is only invalidated when deps change. Deps are compared between the previous effect and the current effect. This can be problematic if one commit consists of an update that has changed deps followed by an update that has equal deps. That commit will lead to memoizedState containing the changed deps even though we committed with unchanged deps.

The n+1 update will therefore run an effect because we compare the updated deps with the deps with which we never actually committed.

To prevent this we now invalidate memoizedState on every updateEffectImpl call so that memoizedStat.deps always points to the latest deps.
2021-01-29 10:51:11 -05:00
Brian Vaughn
766a7a28a9 Improve React error message when mutable sources are mutated during render (#20665)
Changed previous error message from:
> Cannot read from mutable source during the current render without tearing. This is a bug in React. Please file an issue.

To:
> Cannot read from mutable source during the current render without tearing. This may be a bug in React. Please file an issue.

Also added a DEV only warning about the unsafe side effect:
> A mutable source was mutated while the %s component was rendering. This is not supported. Move any mutations into event handlers or effects.

I think this is the best we can do without adding production overhead that we'd probably prefer to avoid.
2021-01-29 10:22:55 -05:00
Andrew Clark
a922f1c710 Fix cache refresh bug that broke DevTools (#20687)
Will follow up with test
2021-01-28 13:07:00 -08:00
Ricky
e51bd6c1fa Queue discrete events in microtask (#20669)
* Queue discrete events in microtask

* Use callback priority to determine cancellation

* Add queueMicrotask to react-reconciler README

* Fix invatiant conditon for InputDiscrete

* Switch invariant null check

* Convert invariant to warning

* Remove warning from codes.json
2021-01-27 18:24:58 -05:00
Ricky
aa736a0fa6 Add queue microtask to host configs (#20668)
* Queue discrete events in microtask

* Fix flow types

* Add to createReactNoop

* More flow types

* Remove import

* Add to custom HostConfig as well
2021-01-27 15:01:21 -05:00
Andrew Clark
deeeaf1d22 Entangle overlapping transitions per queue (#20670)
When multiple transitions update the same queue, only the most recent
one should be allowed to finish. We shouldn't show intermediate states.

See #17418 for background on why this is important.

The way this currently works is that we always assign the same lane to
all transitions. It's impossible for one transition to finish without
also finishing all the others.

The downside of the current approach is that it's too aggressive. Not
all transitions are related to each other, so one should not block
the other.

The new approach is to only entangle transitions if they update one or
more of the same state hooks (or class components), because this
indicates that they are related. If they are unrelated, then they can
finish in any order, as long as they have different lanes.

However, this commit does not change anything about how the lanes are
assigned. All it does is add the mechanism to entangle per queue. So it
doesn't actually change any behavior, yet. But it's a requirement for my
next step, which is to assign different lanes to consecutive transitions
until we run out and cycle back to the beginning.
2021-01-27 11:55:27 -08:00
Joshua Gross
e316f78552 RN: Implement sendAccessibilityEvent in RN Renderer that proxies between Fabric/non-Fabric (#20554)
* RN: Implement `sendAccessibilityEvent` on HostComponent

Implement `sendAccessibilityEvent` on HostComponent for Fabric and non-Fabric RN.

Currently the Fabric version is a noop and non-Fabric uses
AccessibilityInfo directly. The Fabric version will be updated once
native Fabric Android/iOS support this method in the native UIManager.

* Move methods out of HostComponent

* Properly type dispatchCommand and sendAccessibilityEvent handle arg

* Implement Fabric side of sendAccessibilityEvent

* Add tests: 1. Fabric->Fabric, 2. Paper->Fabric, 3. Fabric->Paper, 4. Paper->Paper

* Fix typo: ReactFaricEventTouch -> ReactFabricEventTouch

* fix flow types

* prettier
2021-01-26 20:02:40 -08:00
Ricky
9c32622cf0 Improve tests that use discrete events (#20667) 2021-01-26 19:15:06 -05:00
Andrew Clark
d13f5b9538 Experiment: Unsuspend all lanes on update (#20660)
Adds a feature flag to tweak the internal heuristic used to "unsuspend"
lanes when a new update comes in.

A lane is "suspended" if we couldn't finish rendering it because it was
missing data, and we chose not to commit the fallback. (In this context,
"suspended" does not include updates that finished with a fallback.)

When we receive new data in the form of an update, we need to retry
rendering the suspended lanes, since the new data may have unblocked the
previously suspended work. For example, the new update could navigate
back to an already loaded route.

It's impractical to retry every combination of suspended lanes, so we
need some heuristic that decides which lanes to retry and in
which order.

The existing heuristic roughly approximates the old Expiration Times
model. It unsuspends all lower priority lanes, but leaves higher
priority lanes suspended.

Then when we start rendering, we choose the lanes that have the highest
LanePriority and render those -- and then we add to that all the lanes
that are highher priority.

If this sounds terribly confusing, it's because it barely makes sense.
(It made more sense in the Expiration Times world, I promise, but it
was still confusing.) I don't think it's worth me trying to explain the
old behavior too much because the point here is that we can replace it
with something simpler.

The new heurstic is to unsuspend all suspended lanes whenever there's
an update.

This is effectively what we already do except in a few very specific
edge cases, ever since we removed the delayed suspense feature from
everything that's not a refresh transition.

We can optimize this in the future to only unsuspend lanes that are
either 1) in the `lanes` or `subtreeLanes` of the node that was updated,
or 2) in the `lanes` of the return path of the node that was updated.
This would exclude lanes that are only located in unrelated sibling
trees. But, this optimization wouldn't be useful currently because we
assign the same transition lane to all transitions. It will become
relevant again once we start assigning arbitrary lanes to transitions
-- but that in turn requires us to implement entanglement of overlapping
transitions, one of our planned projects.

So to sum up: the goal here is to remove the weird edge cases and switch
to a simpler model, on top of which we can make more substantial
improvements.

I put it behind a flag so I can run an A/B test and confirm it doesn't
cause a regression.
2021-01-26 12:23:34 -08:00
Brian Vaughn
db5945efee Set default release channel for download-experimental-build script (#20663) 2021-01-26 15:17:56 -05:00
Sebastian Markbåge
a511dc7090 Error for deferred value and transition in Server Components (#20657) 2021-01-25 13:58:47 -08:00
Sebastian Markbåge
fb3f63f1ab Remove lazy invokation of segments (#20656)
This is a remainder from Blocks when these were separate query functions.
2021-01-25 13:04:36 -08:00
Brian Vaughn
6d94017c42 DevTools: Make it easier to write tests for inspected elements (#20655)
And also add a few tests for  which also cover a recent bugfix that just landed
2021-01-25 14:58:19 -05:00
Berton Zhu
f0031dc6ed Devtool: $r should contain hooks property when it is forwardRef or memo component (#20626) 2021-01-25 10:35:02 -05:00
Brian Vaughn
895ae67fd3 Improve error boundary handling for unmounted subtrees (#20645)
A passive effect's cleanup function may throw after an unmount. Prior to this commit, such an error would be ignored. (React would not notify any error boundaries.)

After this commit, React will skip any unmounted boundaries and look for a still-mounted boundary. If one is found, it will call getDerivedStateFromError and/or componentDidCatch (depending on the type of boundary). Unmounted boundaries will be ignored, but as they have been unmounted– this seems appropriate.
2021-01-25 08:54:20 -05:00
Andrew Clark
f15f8f64bb Store interleaved updates on separate queue until end of render (#20615)
## Motivation

An *interleaved* update is one that is scheduled while a render is
already in progress, typically from a concurrent user input event.

We have to take care not to process these updates during the current
render, because a multiple interleaved updates may have been scheduled
across many components; to avoid tearing, we cannot render some of
those updates without rendering all of them.

## Old approach

What we currently do when we detect an interleaved update is assign a
lane that is not part of the current render.

This has some unfortunate drawbacks. For example, we will eventually run
out of lanes at a given priority level. When this happens, our last
resort is to interrupt the current render and start over from scratch.
If this happens enough, it can lead to starvation.

More concerning, there are a suprising number of places that must
separately account for this case, often in subtle ways. The maintenance
complexity has led to a number of tearing bugs.

## New approach

I added a new field to the update queue, `interleaved`. It's a linked
list, just like the `pending` field. When an interleaved update is
scheduled, we add it to the `interleaved` list instead of `pending`.

Then we push the entire queue object onto a global array. When the
current render exits, we iterate through the array of interleaved queues
and transfer the `interleaved` list to the `pending` list.

So, until the current render has exited (whether due to a commit or an
interruption), it's impossible to process an interleaved update, because
they have not yet been enqueued.

In this new approach, we don't need to resort to clever lanes tricks to
avoid inconsistencies. This should allow us to simplify a lot of the
logic that's currently in ReactFiberWorkLoop and ReactFiberLane,
especially `findUpdateLane` and `getNextLanes`. All the logic for
interleaved updates is isolated to one place.
2021-01-22 14:01:54 -08:00
Andrew Clark
0fd6805c6d Land rest of effects refactor in main fork (#20644) 2021-01-22 14:49:33 -05:00
Brian Vaughn
a6b5256a29 Refactored recursive strict effects method to be iterative (#20642) 2021-01-22 11:27:39 -08:00
Brian Vaughn
3957853ae5 Re-add "strict effects mode" for legacy roots only (#20639)
This combines changes originally made in #19523, #20028, and #20415 but with slightly different semantics: "strict effects" mode is enabled only for the experimental root APIs (never for legacy render, regardless of <StrictMode> usage). These semantics may change slightly in the future.
2021-01-22 08:58:11 -05:00
Brian Vaughn
d4c05a1ead Flow ignore new build2 directory (#20635) 2021-01-21 10:43:52 -05:00
Andrew Clark
fceb75e899 Delete remaining references to effect list (#20625)
I think that's it!
2021-01-20 10:24:01 -08:00
Andrew Clark
741dcbdbec Schedule passive phase whenever there's a deletion (#20624)
We use the passive phase to detach the fibers.
2021-01-20 10:21:42 -08:00
Andrew Clark
11a983fc76 Remove references to Deletion flag (#20623)
We no longer use the Deletion flag anywhere in the new fork, so we can
stop marking it.
2021-01-20 10:18:19 -08:00
Dima Tisnek
2e948e0d91 Avoid .valueOf to close #20594 (#20617) 2021-01-19 20:59:31 -05:00
Andrew Clark
2a646f73e4 Convert snapshot phase to depth-first traversal (#20622) 2021-01-19 15:37:00 -08:00
Andrew Clark
fb3e158a64 Convert ReactSuspenseWithNoopRenderer tests to use built-in cache (#20601)
* Remove `ms` prop from SuspenseWithNoop tests

Use `resolveText` instead.

* Migrate SuspenseWithNoop tests to built-in cache
2021-01-19 14:38:54 -08:00
Ricky
e0fd9e67fc Use update lane priority in work loop (#20621) 2021-01-19 17:34:08 -05:00
Andrew Clark
58e8304483 Remove custom error message from hook access error (#20604)
It will still result in a null access error, so there's no change in
semantics. We will print a user-friendly error message in DEV.
2021-01-19 14:20:22 -08:00
Andrew Clark
9043626f09 Cache tests: Make it easier to test many caches (#20600)
Some rearranging to make it easier to write tests that assert on the
output of multiple caches.
2021-01-19 13:54:45 -08:00
Andrew Clark
af0bb68e87 Land #20595 and #20596 in main fork (#20602) 2021-01-19 08:37:51 -08:00
Sebastian Silbermann
2b6985114f build-combined: Fix failures when renaming across devices (#20620) 2021-01-19 08:14:06 -08:00
ChenLei
ba9582da27 [devtools] Fix can't expand prop value in some scenario (#20534)
Co-authored-by: Brian Vaughn <bvaughn@fb.com>
2021-01-19 10:26:52 -05:00
Brian Vaughn
af16f755dc Update DevTools to use getCacheForType API (#20548)
DevTools was built with a fork of an early idea for how Suspense cache might work. This idea is incompatible with newer APIs like `useTransition` which unfortunately prevented me from making certain UX improvements. This PR swaps out the primary usage of this cache (there are a few) in favor of the newer `unstable_getCacheForType` and `unstable_useCacheRefresh` APIs. We can go back and update the others in follow up PRs.

### Messaging changes

I've refactored the way the frontend loads component props/state/etc to hopefully make it better match the Suspense+cache model. Doing this gave up some of the small optimizations I'd added but hopefully the actual performance impact of that is minor and the overall ergonomic improvements of working with the cache API make this worth it.

The backend no longer remembers inspected paths. Instead, the frontend sends them every time and the backend sends a response with those paths. I've also added a new "force" parameter that the frontend can use to tell the backend to send a response even if the component hasn't rendered since the last time it asked. (This is used to get data for newly inspected paths.)

_Initial inspection..._
```
front |                                                      | back
      | -- "inspect" (id:1, paths:[], force:true) ---------> |
      | <------------------------ "inspected" (full-data) -- |
```
_1 second passes with no updates..._
```
      | -- "inspect" (id:1, paths:[], force:false) --------> |
      | <------------------------ "inspected" (no-change) -- |
```
_User clicks to expand a path, aka hydrate..._
```
      | -- "inspect" (id:1, paths:['foo'], force:true) ----> |
      | <------------------------ "inspected" (full-data) -- |
```
_1 second passes during which there is an update..._
```
      | -- "inspect" (id:1, paths:['foo'], force:false) ---> |
      | <----------------- "inspectedElement" (full-data) -- |
```

### Clear errors/warnings transition
Previously this meant there would be a delay after clicking the "clear" button. The UX after this change is much improved.

### Hydrating paths transition
I also added a transition to hydration (expanding "dehyrated" paths).

### Better error boundaries
I also added a lower-level error boundary in case the new suspense operation ever failed. It provides a better "retry" mechanism (select a new element) so DevTools doesn't become entirely useful. Here I'm intentionally causing an error every time I select an element.

### Improved snapshot tests
I also migrated several of the existing snapshot tests to use inline snapshots and added a new serializer for dehydrated props. Inline snapshots are easier to verify and maintain and the new serializer means dehydrated props will be formatted in a way that makes sense rather than being empty (in external snapshots) or super verbose (default inline snapshot format).
2021-01-19 09:51:32 -05:00
Sebastian Silbermann
9a2150719b Fix prod build in ci/codesandbox (#20606) 2021-01-18 14:56:17 -05:00
Andrew Clark
95feb0e701 Convert mutation phase to depth-first traversal (#20596) 2021-01-15 12:24:20 -08:00
Andrew Clark
6132919bf2 Convert layout phase to depth-first traversal (#20595) 2021-01-15 12:22:23 -08:00
Andrew Clark
98313aaa7e Migrate prepare-release-from-ci to new workflow (#20581)
* Migrate prepare-release-from-ci to new workflow

I added a `--releaseChannel (-r)` argument to script. You must choose
either "stable" or "experimental", because every build job now includes
both channels.

The prepare-release-from-npm script is unchanged since those releases
are downloaded from npm, nt CI.

(As a side note, I think we should start preparing semver releases using
the prepare-release-from-ci script, too, and get rid of
prepare-release-from-npm. I think that was a neat idea originally but
because we already run `npm pack` before storing the artifacts in CI,
there's really not much additional safety; the only safeguard it adds is
the requirement that a "next" release must have already been published.)

* Move validation to parse-params module
2021-01-14 09:20:20 -08:00
Andrew Clark
42e04b46d1 Fix: Detach deleted fiber's alternate, too (#20587)
We need to call `detachFiberAfterEffects` on the fiber's alternate to
clean it up. We're currently not, because the `alternate` field is
cleared during `detachFiberMutation`. So I deferred detaching the
`alternate` until the passive phase. Only the `return` pointer needs to
be detached for semantic purposes.

I don't think there's any good way to test this without using
reflection. It's not even observable using out our "supported"
reflection APIs (`findDOMNode`), or at least not that I can think of.
Which is a good thing, in a way.

It's not really a memory leak, either, because the only reference to the
alternate fiber is from the parent's alternate. Which will be
disconnected the next time the parent is updated or deleted.

It's really only observable if you mess around with internals in ways
you're not supposed to — I found it because a product test in www that
uses Enzyme was doing just that.

In lieu of a new unit test, I confirmed this patch fixes the broken
product test.
2021-01-14 08:18:55 -08:00
Andrew Clark
a656ace8da Deletion effects should fire parent -> child (#20584)
* Test: Deletion effects should fire parent -> child

Regression in new effect implementation

* Fix passive deletion effect ordering
2021-01-13 16:18:55 -08:00
Andrew Clark
fc07b070a0 Retry with fresh otp if publish fails (#20582)
Currently, if publishing a package fails, the script crashes, and the
user must start it again from the beginning. Usually this happens
because the one-time password has timed out.

With this change, the user will be prompted for a fresh otp, and the
script will resume publishing.
2021-01-13 11:54:56 -08:00
Andrew Clark
e6ed2bcf42 Update package.json versions as part of build step (#20579)
Fixes issue in the new build workflow where the experimental packages do
not include "experimental" in the version string. This was because the
previous approach relied on the RELEASE_CHANNEL environment variable,
which we are no longer setting in the outer CI job, since we use the
same job to build both channels. To solve, I moved the version
post-processing into the build script itself.

Only affects the new build workflow. Old workflow is unchanged.

Longer term, I would like to remove version numbers from the source
entirely, including the package.jsons. We should use a placeholder
instead; that's mostly how it already works, since the release script
swaps out the versions before we publish to stable.
2021-01-13 09:54:03 -08:00
Andrew Clark
b99ac3d6df Migrate remaining tests to combined workflow (#20577) 2021-01-12 10:58:49 -08:00
Andrew Clark
9a6a41d108 Migrate build tests to combined workflow (#20574) 2021-01-12 09:50:38 -08:00
Andrew Clark
eb0fb38230 Build stable and experimental with same command (#20573)
The goal is to simplify our CI pipeline so that all configurations
are built and tested in a single workflow.

As a first step, this adds a new build script entry point that builds
both the experimental and stable release channels into a single
artifacts directory.

The script works by wrapping the existing build script (which only
builds a single release channel at a time), then post-processing the
results to match the desired filesystem layout. A future version of the
build script would output the files directly without post-processing.

Because many parts of our infra depend on the existing layout of the
build artifacts directory, I have left the old workflows untouched.
We can incremental migrate to the new layout, then delete the old
workflows after we've finished.
2021-01-12 09:32:32 -08:00
Christian Ruigrok
e8eff119e0 Fix ESLint crash on empty react effect hook (#20385)
* Fix ESLint crash on empty react effect hook

* Add layout effect to test

* Improve wording in comment

* Improve lint warning wording

* Reword missing effect callback message
2021-01-11 15:18:45 -05:00
Brian Vaughn
27659559eb Add useRefresh hook to react-debug-tools (#20460) 2021-01-04 10:46:20 -05:00
Jaiwanth
beb38aba3e [devtools] Bump electron version from 9.1.0 to 11.1.0 for darwin-arm64 builds (#20496) 2021-01-04 10:38:11 -05:00
Brian Vaughn
6630c2de2a Add rudimentary support for Cache to DevTools (#20458) 2021-01-04 09:32:03 -05:00
Brian Vaughn
50393dc3a0 React Native fixes for new inline errors feature (#20502) 2020-12-22 13:58:47 -05:00
Sebastian Silbermann
09a2c363a5 Expose DEV-mode warnings in devtools UI (#20463)
Co-authored-by: Brian Vaughn <bvaughn@fb.com>
2020-12-22 11:09:29 -05:00
Sebastian Silbermann
6cbb9394d1 devtools: Display shortcuts for prev/next search result (#20470) 2020-12-20 21:48:36 -05:00
Andrew Clark
99554dc36f Add Flight packages to experimental allowlist (#20486)
- react-fetch
- react-fs
- react-pg
- react-server-dom-webpack
2020-12-18 14:29:48 -08:00
Andrew Clark
1bda600378 Hardcoded allowlist for publishing packages (#20485)
With separate lists for stable and experimental.
2020-12-18 14:20:37 -08:00
Andrew Clark
efc57e5cbb Add built-in Suspense cache with support for invalidation (refreshing) (#20456) 2020-12-18 10:57:24 -08:00
Andrew Clark
00a5b08e24 Remove PassiveStatic optimization
Passive flags are a new concept that is tricky to get right. We've
already found two bugs related to PassiveStatic. Let's remove this
optimization for now, and add it back once the main part of the effects
refactor lands.
2020-12-18 11:31:35 -06:00
Andrew Clark
a6329b1050 Don't clear static flags in resetWorkInProgress
Fixes the regression test added in #20433
2020-12-18 11:30:20 -06:00
Andrew Clark
1cf59f34b8 Convert passive unmount phase to tree traversal 2020-12-18 11:29:38 -06:00
Andrew Clark
ab29695a05 Defer more field detachments to passive phase
This allows us to use those fields during passive unmount traversal.
2020-12-18 11:28:49 -06:00
Andrew Clark
d37d7a4bb4 Convert passive mount phase to tree traversal 2020-12-18 11:27:53 -06:00
Andrew Clark
19e15a3986 Add PassiveStatic to trees with passive effects
Indicates that a tree needs passive clean-up on deletion.
2020-12-18 11:27:08 -06:00
Andrew Clark
ff17fc176f Don't clear other flags when adding Deletion
Same as #20398 but for Deletions. There's no new regression test, but in
the effects refactor, existing tests will fail without this.
2020-12-17 16:31:50 -06:00
Ricky
5687864eb7 Add back disableSchedulerTimeoutInWorkLoop flag (#20482)
* Add back enableSchedulerTimeoutInWorkLoop flag

* Nvm, keep it as disableSchedulerTimeoutInWorkLoop
2020-12-17 17:17:23 -05:00
Luna Ruan
9f338e5d77 clone json obj in react native flight client host config parser (#20474)
As per Seb's comment in #20465, we need to do the same thing in React Native as we do in Relay.

When `parseModel` suspends because of missing dependencies, it will exit and retry to parse later. However, in the relay implementation, the model is an object that we modify in place when we parse it, so when we we retry, part of the model might be parsed already into React elements, which will error because the parsing code expect a Flight model. This diff clones instead of mutating the original model, which fixes this error.
2020-12-16 11:53:51 -08:00
Luna Ruan
4e62fd2712 clone json obj in relay flight client host config parser (#20465)
When `parseModel` suspends because of missing dependencies, it will exit and retry to parse later. However, in the relay implementation, the model is an object that we modify in place when we parse it, so when we we retry, part of the model might be parsed already into React elements, which will error because the parsing code expect a Flight model. This diff clones instead of mutating the original model, which fixes this error.
2020-12-15 15:33:54 -08:00
Oliver Lassen
604bbcd87d [devtools] Increase the clickable area of the prop value (#20428) 2020-12-14 16:23:26 -05:00
Dan Abramov
070372cde2 [Flight] Fix webpack watch mode issue (#20457) 2020-12-14 15:50:20 +00:00
Dan Abramov
0f80dd1484 [Flight] Support concatenated modules in Webpack plugin (#20449)
* Extract recordModule

* Add support for concatenated modules
2020-12-13 17:44:59 +00:00
Dan Abramov
daf38ecdfc [Flight] Use lazy reference for existing modules (#20445) 2020-12-11 22:45:18 +00:00
Andrew Clark
3f9205c333 Regression test: SuspenseList causes lost unmount (#20433)
@sebmarkbage reminded me that the complete phase of SuspenseList
will sometimes enter the begin phase of the children without calling
`createWorkInProgress` again, instead calling `resetWorkInProgress`.

This was raised in the context of considering whether #20398 might
have accidentally caused a SuspenseList bug. (I did look at this code
at the time, but considering how complicated SuspenseList is it's not
hard to imagine that I made a mistake.)

Anyway, I think that PR is fine; however, reviewing it again did lead me
to find a different bug. This new bug is actually a variant of the bug
fixed by #20398.

`resetWorkInProgress` clears a fiber's static flags. That's wrong, since
static flags -- like PassiveStatic -- are meant to last the lifetime of
the component.

In more practical terms, what happens is that if a direct child of
SuspenseList contains a `useEffect`, then SuspenseList will cause the
child to "forget" that it contains passive effects. When the child
is deleted, its unmount effects are not fired :O

This is the second of this type of bug I've found, which indicates to me
that it's too easy to accidentally clear static flags.

Maybe we should only update the `flags` field using helper functions,
like we do with `lanes`.

Or perhaps we add an internal warning somewhere that detects when a
fiber has different static flags than its alternate.
2020-12-11 08:38:49 -08:00
Sebastian Markbåge
cdfde3ae11 Always rethrow original error when we replay errors (#20425)
We replay errors so you can break on paused exceptions. This is done in
the second pass so that the first pass can ignore suspense.

Originally this threw the original error. For suppression purposes
we copied the flag onto the original error.

f1dc626b29/packages/react-reconciler/src/ReactFiberScheduler.old.js (L367-L369)

During this refactor it changed to just throw the retried error:

https://github.com/facebook/react/pull/15151

We're not sure exactly why but it was likely just an optimization or
clean up.

So we can go back to throwing the original error. That helps in the case
where a memoized function is naively not rethrowing each time such as
in Node's module system.

Unfortunately this doesn't fix the problem fully.
Because invokeGuardedCallback captures the error and logs it to the browser.
So you still end up seeing the wrong message in the logs.

This just fixes so that the error boundary sees the first one.
2020-12-10 05:50:41 -08:00
Dan Abramov
b15d6e93e7 [Flight] Make PG and FS server-only (#20424)
* Make react-fs server-only

* Make react-pg server-only
2020-12-10 06:15:37 +00:00
Dan Abramov
40ff2395e4 [Flight] Prevent non-Server imports of aliased Server entrypoints (#20422)
* [Flight] Prevent non-Server imports of aliased Server entrypoints

* Fix Flow + await

* Tighten the types
2020-12-10 03:55:38 +00:00
Dan Abramov
94aa365e3a [Flight] Fix webpack plugin to use chunk groups (#20421) 2020-12-10 03:03:53 +00:00
Dan Abramov
842ee367e6 [Flight] Rename the shared entry point (#20420)
* [Flight] Rename the shared entry point

* Shared
2020-12-10 02:14:50 +00:00
Dan Abramov
dbf40ef759 Put .server.js at the end of bundle filenames (#20419)
* Put .server.js at the end of bundle filenames

* Client too
2020-12-09 22:47:17 +00:00
Dan Abramov
03126dd087 [Flight] Add read-only fs methods (#20412)
* Don't allocate the inner cache unnecessarily

We only need it when we're asking for text. I anticipate I'll want to avoid allocating it in other methods too when it's not strictly necessary.

* Add fs.access

* Add fs.lstat

* Add fs.stat

* Add fs.readdir

* Add fs.readlink

* Add fs.realpath

* Rename functions to disambiguate two caches
2020-12-09 21:46:50 +00:00
Brian Vaughn
b51a686a93 Turn on double effects for www test renderer (#20416) 2020-12-09 11:46:18 -08:00
Brian Vaughn
56a632adb6 Double Invoke Effects in __DEV__ (in old reconciler fork) (#20415)
We originally added a new DEV behavior of double-invoking effects during mount to our new reconciler fork in PRs #19523 and #19935 and later refined it to only affect modern roots in PR #20028. This PR adds that behavior to the old reconciler fork with a small twist– the behavior applies to StrictMode subtrees, regardless of the root type.

This commit also adds a few additional tests that weren't in the original commits.
2020-12-09 14:18:26 -05:00
togami2864
1a24223375 fixed typo (#20351) 2020-12-09 09:26:12 -05:00
Dan Abramov
a233c9e2aa Rename internal cache helpers (#20410) 2020-12-09 02:57:14 +00:00
Dan Abramov
6a4b12b81c [Flight] Add rudimentary FS binding (#20409)
* [Flight] Add rudimentary FS binding

* Throw for unsupported

* Don't mess with hidden class

* Use absolute path as the key

* Warn on relative and non-normalized paths
2020-12-09 02:37:29 +00:00
Andrew Clark
7659949d65 Clear deletions in detachFiber (#20401)
This was added in a later step of the refactor but since `deletions`
array already landed, clearing it should, too.

I think it's unlikely that this causes GC problems but worth
adding anyway.
2020-12-08 17:13:20 -08:00
Dan Abramov
b9680aef7d Cache react-fetch results in the Node version (#20407) 2020-12-08 22:37:24 +00:00
inokawa
cdae31ab8e Fix typo (#20279) 2020-12-08 10:40:35 -05:00
Hollow Man
51a7cfe210 Fix typo (#20300)
Signed-off-by: Hollow Man <hollowman@hollowman.ml>
2020-12-08 10:40:23 -05:00
Sam Zhou
373b297c55 fix: Fix typo in react-reconciler docs (#20284)
peristent -> persistent
2020-12-08 10:40:05 -05:00
Dan Abramov
1b5ca99063 Fix module ID deduplication (#20406) 2020-12-08 13:19:59 +00:00
Sebastian Markbåge
5fd9db732d [Flight] Rename react-transport-... packages to react-server-... (#20403)
* Move files

* Update paths

* Rename import variables

* Rename /server to /writer

This is mainly because "React Server Server" is weird so we need another
dimension.

* Use "react-server" convention to enforce that writer is only loaded in a server
2020-12-08 08:08:57 -05:00
Sebastian Markbåge
ce40f1dc2f Use assets API + writeToDisk instead of directly writing to disk (#20402) 2020-12-07 17:54:28 -08:00
Dan Abramov
0512cd6a26 Bump fixture dependency versions (#20397)
* Bump all versions

* Switch to CJS mode

* Revert "Switch to CJS mode"

This reverts commit b3c4fd92dcef6ecb4116fc66f674ae88aad3c582.

* Fix ES mode

* Add nodemon to restart the server on edits

* Ignore /server/ from compilation
2020-12-08 01:23:49 +00:00
Andrew Clark
b66ae09b6e Track subtreeFlags et al with bubbleProperties
Original PR: #19836
2020-12-07 15:50:43 -06:00
Andrew Clark
de75315d7e Track deletions using an array on the parent
Adds back the `deletions` array and uses it in the commit phase.

We use a trick where the first time we hit a deletion effect, we commit
all the deletion effects that belong to that parent. This is an
incremental step away from using the effect list and toward a DFS +
subtreeFlags traversal.

This will help determine whether the regression is caused by, say,
pushing the same fiber into the deletions array multiple times.
2020-12-07 15:11:25 -06:00
Andrew Clark
1377e465dd Add Placement bit without removing others (#20398)
When scheduling a Placement effect, we should add the Placement bit
without resetting the others.

In the old fork, there are no flags to reset, anyway, since by the
time we reach the child reconciler, the flags will have already been
reset.

However, in the effects refactor, "static" flags are not reset, so this
can actually manifest as a bug. See #20285 for a regression test.
2020-12-07 13:07:28 -08:00
Andrew Clark
18d7574ae2 Remove catch from Scheduler build (#20396)
Makes debugging errors harder.

In this case, we can use `finally` instead.
2020-12-07 11:10:53 -08:00
Sebastian Markbåge
30dfb86025 [Flight] Basic scan of the file system to find Client modules (#20383)
* Basic scan of the file system to find Client modules

This does a rudimentary merge of the plugins. It still uses the global
scan and writes to file system.

Now the plugin accepts a search path or a list of referenced client files.
In prod, the best practice is to provide a list of files that are actually
referenced rather than including everything possibly reachable. Probably
in dev too since it's faster.

This is using the same convention as the upstream ContextModule - which
powers the require.context helpers.

* Add neo-async to dependencies
2020-12-07 12:10:18 -05:00
Brian Vaughn
dd16b78990 Tweaked DevTools build command slightly 2020-12-07 10:10:43 -05:00
Brian Vaughn
4053c76b7d Add more DevTools tests for React.Lazy (#20380) 2020-12-06 09:10:15 -05:00
Sebastian Markbåge
0db61a08be Fix Flight Prod Fixture (#20382)
* Don't use async/await

Babel transpilation fails for some reason in prod.

* Set up production runner command

Uses python because meh. Just to show it's static.

* Use build folder in prod
2020-12-04 18:00:57 -08:00
Brian Vaughn
3a8c04e3b2 React DevTools 4.10.0 -> 4.10.1 2020-12-04 16:54:14 -05:00
Brian Vaughn
f160547f47 React DevTools 4.10.0 -> 4.10.1 2020-12-04 16:43:13 -05:00
Dan Abramov
9b8060041b Error when the number of parameters to a query changes (#20379) 2020-12-04 20:11:00 +00:00
Dan Abramov
60e4a76fa8 [Flight] Add rudimentary PG binding (#20372)
* [Flight] Add rudimentary PG binding

* Use nested Maps for parameters

* Inline and fix Flow
2020-12-04 17:27:33 +00:00
Andrew Clark
88ef95712d Fork ReactFiberLane (#20371)
This wasn't forked previously because Lane and associated types are
opaque, and they leak into non-reconciler packages. So forking the type
would also require forking all those other packages.

But I really want to use the reconciler fork infra for lanes changes.
So I made them no longer opaque.

Another possible solution would be to add separate `new` and `old`
fields to the Fiber type, like I did when migrating from expiration
times. But that seems so excessive. This seems fine.

But we should still treat them like they're opaque and only do lanes
manipulation in the ReactFiberLane module. At least until the model
stabilizes more. We'll just need to enforce this with discipline
instead of with the type system.
2020-12-04 10:54:09 -06:00
Arindam Pradhan
e9860d426f fixed: typo in react-devtools/README.md Websocked -> Websocket (#20376) 2020-12-04 09:59:17 -05:00
Dan Abramov
41c5d00fc9 [Flight] Minimal webpack plugin (#20228) 2020-12-03 21:21:19 +00:00
Dan Abramov
e23673b511 [Flight] Add getCacheForType() to the dispatcher (#20315)
* Remove react/unstable_cache

We're probably going to make it available via the dispatcher. Let's remove this for now.

* Add readContext() to the dispatcher

On the server, it will be per-request.

On the client, there will be some way to shadow it.

For now, I provide it on the server, and throw on the client.

* Use readContext() from react-fetch

This makes it work on the server (but not on the client until we implement it there.)

Updated the test to use Server Components. Now it passes.

* Fixture: Add fetch from a Server Component

* readCache -> getCacheForType<T>

* Add React.unstable_getCacheForType

* Add a feature flag

* Fix Flow

* Add react-suspense-test-utils and port tests

* Remove extra Map lookup

* Unroll async/await because build system

* Add some error coverage and retry

* Add unstable_getCacheForType to Flight entry
2020-12-03 03:44:56 +00:00
Philipp Spiess
555eeae33d Add disableNativeComponentFrames flag (#20364)
## Summary

We're experiencing some issues internally where the component stack is
getting into our way of fixing them as it causes the page to become
unresponsive. This adds a flag so that we can disable this feature as a
temporary workaround.

More internal context: https://fburl.com/go9yoklm

## Test Plan

I tried to default this flag to `__VARIANT__` but the variant tests
(`yarn test-www --variant`) started to fail across the board since a lot
of tests depend on the component tree, things like this:

https://user-images.githubusercontent.com/458591/100771192-6a1e1c00-33fe-11eb-9ab0-8ff46ba378a2.png

So, it seems to work :-)

Given that it's unhandy to update the hundreds of tests that are failing
I decided to hard code this to `false` like we already do for some other
options.
2020-12-02 16:25:55 +01:00
Dan Abramov
148ffe3cfe Failing test for Client reconciliation (#20318) 2020-12-01 16:40:12 +00:00
Sebastian Markbåge
ad6f3d5c55 Ignore node_modules when printing warnings (#20363)
This now finds acorn and fails to extract warnings from it. But also, this
seems slow.
2020-12-01 08:01:16 -08:00
Brian Vaughn
a2a025537d Fixed invalid DevTools work tags (#20362)
* Fixed invalid DevTools work tags

Work tags changed recently (PR #13902) but we didn't bump React versions. This meant that DevTools has valid work tags only for master (and FB www sync) but invalid work tags for the latest open source releases. To fix this, I incremneted React's version in Git (without an actual release) and added a new fork to the work tags detection branch.

This commit also adds tags for the experimental Scope and Fundamental APIs to DevTools so component names will at least display correctly. Technically these new APIs were first introduced to experimental builds ~16.9 but I didn't add a new branch to the work tags fork because I don't they're used commonly. I've just added them to the 17+ branches.

* Removed FundamentalComponent from DevTools tag defs
2020-12-01 10:33:32 -05:00
Sebastian Markbåge
5711811da1 Reconcile element types of lazy component yielding the same type (#20357)
* Reconcile element types of lazy component yielding the same type

* Add some legacy mode and suspense boundary flushing tests

* Fix infinite loop in legacy mode

In legacy mode we typically commit the suspending fiber and then rerender
the nearest boundary to render the fallback in a separate commit.

We can't do that when the boundary itself suspends because when we try to
do the second pass, it'll suspend again and infinite loop.

Interestingly the legacy semantics are not needed in this case because
they exist to let an existing partial render fully commit its partial state.

In this case there's no partial state, so we can just render the fallback
immediately instead.

* Check fast refresh compatibility first

resolveLazy can suspend and if it does, it can resuspend. Fast refresh
assumes that we don't resuspend. Instead it relies on updating the inner
component later.

* Use timers instead of act to force fallbacks to show
2020-12-01 07:14:04 -08:00
Sebastian Markbåge
3f73dcee37 Support named exports from client references (#20312)
* Rename "name"->"filepath" field on Webpack module references

This field name will get confused with the imported name or the module id.

* Switch back to transformSource instead of getSource

getSource would be more efficient in the cases where we don't need to read
the original file but we'll need to most of the time.

Even then, we can't return a JS file if we're trying to support non-JS
loader because it'll end up being transformed.

Similarly, we'll need to parse the file and we can't parse it before it's
transformed. So we need to chain with other loaders that know how.

* Add acorn dependency

This should be the version used by Webpack since we have a dependency on
Webpack anyway.

* Parse exported names of ESM modules

We need to statically resolve the names that a client component will
export so that we can export a module reference for each of the names.

For export * from, this gets tricky because we need to also load the
source of the next file to parse that. We don't know exactly how the
client is built so we guess it's somewhat default.

* Handle imported names one level deep in CommonJS using a Proxy

We use a proxy to see what property the server access and that will tell
us which property we'll want to import on the client.

* Add export name to module reference and Webpack map

To support named exports each name needs to be encoded as a separate
reference. It's possible with module splitting that different exports end
up in different chunks.

It's also possible that the export is renamed as part of minification.
So the map also includes a map from the original to the bundled name.

* Special case plain CJS requires and conditional imports using __esModule

This models if the server tries to import .default or a plain require.
We should replicate the same thing on the client when we load that
module reference.

* Dedupe acorn-related deps

Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com>
2020-11-30 14:37:27 -08:00
Sebastian Markbåge
565148d751 Disallow *.server.js imports from any other files (#20309)
This convention ensures that you can declare that you intend for a file
to only be used on the server (even if it technically might resolve
on the client).
2020-11-30 14:25:56 -08:00
Brian Vaughn
e6a0f27630 Profiler: Improve nested-update checks (#20299)
Previous checks were too naive when it comes to pending lower-pri work or batched updates. This commit adds two new (previously failing) tests and fixes.
2020-11-20 14:46:45 -05:00
Brian Vaughn
2cf8f7f61c Speed up local "build-for-detools" target (#20307) 2020-11-20 12:31:29 -05:00
Sebastian Markbåge
d93b58a5e3 Add flight specific entry point for react package (#20304)
This configures the Flight fixture to use the "react-server" environment.

This allows the package.json exports field to specify a different resolution
in this environment.

I use this in the "react" package to resolve to a new bundle that excludes
the Hooks that aren't relevant in this environment like useState and useEffect.

This allows us to error early if these names are imported. If we actually
published ESM, it would we a static error. Now it's a runtime error.

You can test this by importing useState in Container.js which is used
by the client and server.
2020-11-20 08:47:13 -08:00
Dan Abramov
89d4fe141a Exclude fixtures from Flow config (#20302) 2020-11-20 02:45:03 +00:00
Brian Vaughn
a81c02ac15 Profiler onNestedUpdateScheduled accepts id as first param (#20293) 2020-11-18 17:56:42 -05:00
Andrew Clark
ac2cff4b10 Warn if commit phase error thrown in detached tree (#20286)
Until `skipUnmountedBoundaries` lands again, we need some way to detect
when errors are thrown inside a deleted tree. I've added a warning to
`captureCommitPhaseError` that fires when we reach the root of a subtree
without finding either a boundary or a HostRoot.

Even after `skipUnmountedBoundaries`  lands, this warning could be a
useful guard against internal bugs, like a bug in the
`skipUnmountedBoundaries` implementation itself.

In the meantime, do not add this warning to the allowlist; this is only
for our internal use. For this reason, I've also only added it to the
new fork, not the old one, to prevent this from accidentally leaking
into the open source build.
2020-11-18 09:23:39 -08:00
Andrew Clark
0f83a64eda Regression test: Missing unmount after re-order (#20285)
Adds a regression test for a bug I found in the effects refactor.

The bug was that reordering a child that contains passive effects would
cause the child to "forget" that it contains passive effects. This is
because when a Placement effect is scheduled by the reconciler, it would
override all of the fiber's flags, including its "static" ones:

```
child.flags = Placement;
```

The problem is that we use a static flag to use a "static" flag to track
that a fiber contains passive effects.

So what happens is that when the tree is deleted, the unmount effect is
never fired.

In the new implementation, the fix is to add the Placement flag without
overriding the rest of the bitmask:

```
child.flags |= Placement;
```

(The old implementation doesn't need to be changed because it does not
use static flags for this purpose.)
2020-11-18 10:33:26 -06:00
Dan Abramov
ebf158965f Add best-effort documentation for third-party renderers (#20278)
* Add best-effort documentation for third-party renderers

* Update README.md

* Update README.md
2020-11-17 13:28:12 +00:00
Sebastian Markbåge
82e99e1b02 Add Node ESM Loader and Register Entrypoints (#20274)
* Add Node ESM loader build

This adds a loader build as a first-class export. This will grow in
complexity so it deserves its own module.

* Add Node CommonJS regiter build

This adds a build as a first-class export for legacy CommonJS registration
in Node.js. This will grow in complexity so it deserves its own module.

* Simplify fixture a bit to easier show usage with or without esm

* Bump es version

We leave async function in here which are newer than ES2015.
2020-11-16 23:46:27 -05:00
Andrew Clark
bf7b7aeb10 findDOMNode: Remove return pointer mutation (#20272)
The last step of the `findDOMNode` algorithm is a search of the
current tree.

When descending into a child node, it mutates `child.return` so that it
points to the current fiber pair, instead of a work-in-progress. This
can cause bugs if `findDOMNode` is called at the wrong time, like in
an interleaved event.

For this reason (among others), you're not suppposed to use
`findDOMNode` in Concurrent Mode. However, we still have some internal
uses that we haven't migrated.

To reduce the potential for bugs, I've removed the `.return` pointer
assignment in favor of recursion.
2020-11-16 15:09:53 -08:00
Andrew Clark
369c3db629 Add separate ChildDeletion flag (#20264)
In the old, effect list implementation, the Deletion flag is is set on
each deleted fiber.

In the new, subtreeTag implementation, the Deletion flag is set on the
parent of each deleted fiber, and the deleted fibers themselves are
pushed to the `deletions` array.

To better distinguish between these two uses, I've added a separate
ChildDeletion flag. That way we can, if desired, maintain both
implementations simultaneously, as we bisect to find the performance
regression that we're currently investigating.
2020-11-16 09:13:39 -06:00
Andrew Clark
765e89b908 Reset new fork to old fork (#20254)
* Fix typo

This typo was fixed in the new fork but not the old.

* Reset new fork to old fork

Something in the new fork is causing a topline metrics regression. We're
not sure what it is, so we're going to split it into steps and bisect.

As a first step, this resets the new fork back to the contents of the
old fork. We will land this to confirm that the fork infra itself is
not causing a regression.

* Fix tests: Add `dfsEffectsRefactor` flag

Some of the tests that gated on the effects refactor used the `new`
flag. In order to bisect, we'll need to decompose the new fork changes
into multiple steps.

So I added a hardcoded test flag called `dfsEffectsRefactor` and set it
to false. Will turn back on when we switch back to traversing the
finished tree using DFS and `subtreeTag`.
2020-11-13 11:54:33 -08:00
Brian Vaughn
7548dd573e Properly reset Profiler nested-update flag (#20253)
Previously this flag was not being reset correctly if a concurrent update followed a nested (sync) update. This PR fixes the behavior and adds a regression test.
2020-11-13 14:29:06 -05:00
Andrew Clark
bd8bc5afce Add --reverse option to replace-fork script (#20249)
When enabled, replaces new fork with old fork.

I've done this several times by manually editing the script file, so
seems useful enough to add an option.
2020-11-13 11:09:02 -08:00
Andrew Clark
453df3ff72 Autofix imports when running replace-fork (#20251)
* Pass extra CLI args through to ESLint

These now work:

```
yarn run lint --fix
yarn run linc --fix
```

* Autofix imports when running replace-fork

We have a custom ESLint rule that can autofix cross-fork imports.

Usually, after running the `replace-fork` script, you need to run
`yarn lint --fix` to fix the imports.

This combines the two steps into one.
2020-11-13 11:01:25 -08:00
Andrew Clark
73bf2d68ef Pass extra CLI args through to ESLint (#20250)
These now work:

```
yarn run lint --fix
yarn run linc --fix
```
2020-11-13 11:00:45 -08:00
Andrew Clark
b44e4b13a9 Check for deletions in hadNoMutationsEffects (#20252)
When detecting if a host tree was changed, we must check for deletions
in addition to mounts and updates.
2020-11-13 10:45:46 -08:00
Andrew Clark
3ebf05183d Add new effect fields to old fork, and vice versa (#20246)
* Add new effect fields to old fork

So that when comparing relative performance, we don't penalize the new
fork for using more memory.

* Add firstEffect, et al fields to new fork

We need to bisect the changes to the recent commit phase refactor. To
do this, we'll need to add back the effect list temporarily.

This only adds them to the Fiber type so that the memory is the same
as the old fork.
2020-11-13 08:09:48 -08:00
Paul Doyle
2fbcc98066 Remove cycle between ReactFiberHooks and ReactInternalTypes (#20242)
Co-authored-by: Paul Doyle <pauldoyle22@gmail.com>
2020-11-13 09:18:24 -05:00
Sebastian Markbåge
504222dcd2 Add Node ESM build option (#20243)
This allows exporting ESM modules for the Webpack plugin. This is necessary
for making a resolver plugin. We could probably make the whole plugin
use ESM instead of CJS ES2015.
2020-11-13 05:57:45 -08:00
Andrew Clark
1b96ee444e Remove noinline directives from new commit phase (#20241)
My theory for too much inlining contributing to overall stack size is
likely flawed, because Closure reuses variables within a function to
optimize registers.

Even if my theory were correct, the impact would be minimal anyway
because the recursive implementation of the commit phase traversals is
behind a disabled feature flag.

Going to revert this. We can maybe test the impact once we land the
commit phase changes. In the meantime, I'd prefer to eliminate this
delta from the new fork.
2020-11-12 10:21:56 -08:00
Sebastian Markbåge
e41fd1fc06 Support ESM module loaders in Flight fixture (#20229)
This lets the Flight fixture run as "type": "module" or "commonjs".

Experimental loaders can be used similar to require.extensions to do the
transpilation and replacement of .client.js references.
2020-11-12 08:11:05 -08:00
Brian Vaughn
760d9ab57a Scheduling profiler tweaks (#20215) 2020-11-12 09:47:04 -05:00
Brian Vaughn
9403c3b536 Add Profiler callback when nested updates are scheduled (#20211)
This callback accepts the no parameters (except for the current interactions). Users of this hook can inspect the call stack to access and log the source location of the component.
2020-11-12 09:31:27 -05:00
Brian Vaughn
11a2ae3a0d DevTools 4.9.0 -> 4.10.0 2020-11-12 09:07:10 -05:00
Dan Abramov
62efd9618b use-subscription@1.5.1 2020-11-12 00:36:00 +00:00
Billy Janitsch
e7006d67df Widen peer dependency range of use-subscription (#20225) 2020-11-12 00:30:19 +00:00
Andrew Clark
15df051c94 Add warning if return pointer is inconsistent (#20219)
Bugs caused by inconsistent return pointers are tricky to diagnose
because the source of the error is often in a different part of the
codebase from the actual mistake. For example, you might forget to set a
return pointer during the render phase, which later causes a crash in
the commit phase.

This adds a dev-only invariant to the commit phase to check for
inconsistencies. With this in place, we'll hopefully catch return
pointer errors quickly during local development, when we have the most
context for what might have caused it.
2020-11-11 09:06:37 -06:00
Alphabet Codes
9aca239f11 Improved dev experience when DevTools hook is disabled (#20208)
Co-authored-by: Brian Vaughn <brian.david.vaughn@gmail.com>
2020-11-11 09:36:51 -05:00
Sebastian Markbåge
12627f93b5 Perform hasOwnProperty check in Relay Flight (#20220)
We simulate JSON.stringify in this loop so we should do a has own check.
Otherwise we'll include things like constructor properties.

This will actually make things throw less even when it should.
2020-11-10 19:59:46 -08:00
Sebastian Markbåge
163199d8cc Dedupe module id generation (#20172) 2020-11-10 19:58:58 -08:00
Sebastian Markbåge
76a6dbcb9a [Flight] Encode Symbols as special rows that can be referenced by models … (#20171)
* Encode Symbols as special rows that can be referenced by models

If a symbol was extracted from Symbol.for(...) then we can reliably
recreate the same symbol on the client.

S123:"react.suspense"
M456:{mySymbol: '$123'}

This doesn't suffer from the XSS problem because you have to write actual
code to create one of these symbols. That problem is only a problem because
values pass through common other usages of JSON which are not secure.

Since React encodes its built-ins as symbols, we can now use them as long
as its props are serializable. Like Suspense.

* Refactor resolution to avoid memo hack

Going through createElement isn't quite equivalent for ref and key in props.

* Reuse symbol ids that have already been written earlier in the stream
2020-11-10 19:56:50 -08:00
Sebastian Markbåge
35e53b4653 [Flight] Simplify Relay row protocol (#20168)
* Simplify Relay protocol integration

* Encode Relay rows as tuples instead of objects

This is slightly more compact and more ressembles more closely the encoding
we use for the raw stream protocol.
2020-11-10 19:54:42 -08:00
Sebastian Markbåge
16e6dadba6 Encode throwing server components as lazy throwing references (#20217)
This ensures that if this server component was the child of a client
component that has an error boundary, it doesn't trigger the error until
this gets rendered so it happens as deep as possible.
2020-11-10 16:35:27 -08:00
Sebastian Markbåge
e855f91e85 [Flight] Expand the fixture to use require.extensions (#20209)
* Expand fixture

Use .server convention. /server/index.js should really change too so it can be compiled but for now we treat it as bootstrapping code outside the compiled code.

Move App.server. It's part of the application code rather than the infra.

Add hybrid component used in both server/client and an extra component shared by multiple entry points.

* Use require.extensions to replace .client imports

The simplest server doesn't need AOT compilation. Instead we can just
configure require.extensions. This is probably not the best idea to use
in prod but is enough to show the set up.
2020-11-10 12:48:51 -08:00
Andrew Clark
c896cf9617 Set return pointer when reusing current tree (#20212)
* Do not fix return pointers during commit phase

In the commit phase, we should be able to assume that the `return`
pointers in the just-completed tree are consistent. The render phase
should be responsible for ensuring these are always correct.

I've removed the `return` pointer assignments from the render phase
traversal logic. This isn't all of them, only the ones added recently
during the effects refactor. The other ones have been around longer so
I'll leave those for a later clean up.

This breaks a few SuspenseList tests; I'll fix in the next commit.

* Set return pointer when reusing current tree

We always set the return pointer on freshly cloned, work-in-progress
fibers. However, we were neglecting to set them on trees that are reused
from current.

I fixed this in the same path of the complete phase where we reset the
fiber flags.

This is a code smell because it assumes the commit phase is never
concurrent with the render phase. Our eventual goal is to make fibers a
lock free data structure.

Will address further during refactor to alternate model.
2020-11-10 11:20:04 -08:00
Ricky
0898660154 Add version of scheduler that only swaps MessageChannel for postTask (#20206)
* Fork SchedulerDOM to SchedulerPostTaskOnly

* Swap in postTask for MessageChannel

* Add SchedulerPostTaskOnly-test.js

* Update getCurrentTime

* Gate tests to source

* Prettier
2020-11-10 12:11:46 -05:00
Brian Vaughn
393c452e39 Add "nested-update" phase to Profiler API (#20163)
Background:
State updates that are scheduled in a layout effect (useLayoutEffect or componentDidMount / componentDidUpdate) get processed synchronously by React before it yields to the browser to paint. This is done so that components can adjust their layout (e.g. position and size a tooltip) without any visible shifting being seen by users. This type of update is often called a "nested update" or a "cascading update".

Because they delay paint, nested updates are considered expensive and should be avoided when possible. For example, effects that do not impact layout (e.g. adding event handlers, logging impressions) can be safely deferred to the passive effect phase by using useEffect instead.

This PR updates the Profiler API to explicitly flag nested updates so they can be monitored for and avoided when possible.

Implementation:
I considered a few approaches for this.

Add a new callback (e.g. onNestedUpdateScheduled) to the Profiler that gets called when a nested updates gets scheduled.
Add an additional boolean parameter to the end of existing callbacks (e.g. wasNestedUpdate).
Update the phase param to add an additional variant: "mount", "update", or "nested-update" (new).
I think the third option makes for the best API so that's what I've implemented in this PR.

Because the Profiler API is stable, this change will need to remain behind a feature flag until v18. I've turned the feature flag on for Facebook builds though after confirming that Web Speed does not currently make use of the phase parameter.

Quirks:
One quirk about the implementation I've chosen is that errors thrown during the layout phase are also reported as nested updates. I believe this is appropriate since these errors get processed synchronously and block paint. Errors thrown during render or from within passive effects are not affected by this change.
2020-11-10 09:40:30 -05:00
Sean Keenan
93c3dc54b6 react-devtools-inline: Remove css-sourcemap's when bundling for dist (#20170) 2020-11-10 08:47:39 -05:00
Ricky
13a62feab8 Fix path for SchedulerFeatureFlags (#20200) 2020-11-09 11:22:59 -05:00
Brian Vaughn
7a73d6a0f9 (Temporarily) revert unmounting error boundaries changes (#20147)
This reverts commits bcca5a6ca7 and ffb749c95e, although neither revert cleanly since methods have been moved between the work-loop and commit-work files. This commit is a mostly manual effort of undoing the changes.
2020-11-09 10:14:24 -05:00
inokawa
fc06cf8d35 Fix typo (#20188) 2020-11-09 09:17:40 -05:00
Jack Works
c29710a570 fix: useImperativeMethods to useImperativeHandle (#20194) 2020-11-08 19:59:53 +00:00
Ricky
6b28eb6175 Add workspaces hash to yarn cache key (#20154)
* Add branch to yarn cache key

* Add checksum check for workspace info

* Fix yaml

* Try moving the command

* How about here

* Just inline it

* i hate it here

* try reverting back

* Add run

* idk

* try inlining the command everywhere

* Create workspace_info.txt when we create the cache

* Delete the timestamp
2020-11-03 15:02:06 -05:00
Deniz Susman
31d096605c typo fix in comment (#20153) 2020-11-03 09:57:56 -05:00
Dan Abramov
2af07d3f4d [Flight Fixture] Server + Client Components (#20150) 2020-11-03 03:00:23 +00:00
Sebastian Markbåge
c3e20f18fe Add Relay specific React Native build of Flight (#20149)
This adds a new dimension similar to dom-relay. It's different from
"native" which would be Flight for RN without Relay.

This has some copy-pasta that's the same between the two Relay builds but
the key difference will be Metro and we're not quite sure what other
differences there will be yet.
2020-11-02 18:49:48 -08:00
Ricky
454c2211c0 Refactor SchedulerHostConfigs (#20025)
* Remove SchedulerHostConfigs

* Fix builds

* Fix forks

* Move SchedulerNoDom check to npm/index.js

* Fix tests

* Add @gate source

* Gate build-only test to build test runs
2020-11-02 12:46:58 -05:00
Sebastian Markbåge
56e9feead0 Remove Blocks (#20138)
* Remove Blocks

* Remove Flight Server Runtime

There's no need for this now that the JSResource is part of the bundler
protocol. Might need something for Webpack plugin specifically later.

* Devtools
2020-10-30 23:03:45 -07:00
Sebastian Markbåge
3fbd47b862 Serialize pending server components by reference (lazy component) (#20137)
This now means that if a server component suspends, its value becomes a
React.lazy object. I.e. the element that rendered the server component
gets replaced with a lazy node.

As of #19033 lazy objects can be rendered in the node position. This allows
us to suspend at the location of the server component while we're waiting
on its content.

Now server components has the same capabilities as Blocks to progressively
reveal its content.
2020-10-30 17:19:46 -07:00
Sebastian Markbåge
930ce7c15a Allow values to be encoded by "reference" to a value rather than the value itself (#20136)
These references are currently transformed into React.lazy values. We can use these in
React positions like element type or node position.

This could be expanded to a more general concept like Suspensey Promises, asset references or JSResourceReferences.

For now it's only used in React Element type position.

The purpose of these is to let you suspend deeper in the tree.
2020-10-30 13:02:03 -07:00
Sebastian Markbåge
39eb6d1765 Rename (#20134) 2020-10-29 18:58:32 -07:00
Sebastian Markbåge
ffd8423356 [Flight] Add support for Module References in transport protocol (#20121)
* Refactor Flight to require a module reference to be brand checked

This exposes a host environment (bundler) specific hook to check if an
object is a module reference. This will be used so that they can be passed
directly into Flight without needing additional wrapper objects.

* Emit module references as a special type of value

We already have JSON and errors as special types of "rows". This encodes
module references as a special type of row value. This was always the
intention because it allows those values to be emitted first in the stream
so that as a large models stream down, we can start preloading as early
as possible.

We preload the module when they resolve but we lazily require them as they
are referenced.

* Emit module references where ever they occur

This emits module references where ever they occur. In blocks or even
directly in elements.

* Don't special case the root row

I originally did this so that a simple stream is also just plain JSON.

However, since we might want to emit things like modules before the root
module in the stream, this gets unnecessarily complicated. We could add
this back as a special case if it's the first byte written but meh.

* Update the protocol

* Add test for using a module reference as a client component

* Relax element type check

Since Flight now accepts a module reference as returned by any bundler
system, depending on the renderer running. We need to drastically relax
the check to include all of them. We can add more as we discover them.

* Move flow annotation

Seems like our compiler is not happy with stripping this.

* Some bookkeeping bug

* Can't use the private field to check
2020-10-29 17:57:31 -07:00
Brian Vaughn
343d7a4a7e Fast Refresh: Don't block DevTools commit hook (#20129)
In some scenarios (either timing dependent, or pre-FR compatible React versions) FR blocked calling the React DevTools commit hook. This PR adds a test and a fix for that.
2020-10-29 13:23:57 -04:00
Brian Vaughn
b6a750be3c Make DevTools Websocket retry delay configurable (#20107) 2020-10-28 22:08:47 -04:00
Andrew Clark
779a472b09 Prevent inlining into recursive commit functions (#20105)
Adds a bunch of no-inline directives to commit phase functions to
prevent them from being inlined into one of our recursive algorithms.

The motivation is to minimize the number of variables in the recursive
functions, since each one contributes to the size of the stack frame.

Theoretically, this could help the performance of both the recursive
and non-recursive (iterative) implementations of the commit phase,
since even the iterative implementation sometimes uses the JS stack.
2020-10-27 12:51:34 -07:00
Andrew Clark
25b18d31c8 Traverse commit phase effects iteratively (#20094)
* Move traversal logic to ReactFiberCommitWork

The current traversal logic is spread between ReactFiberWorkLoop and
ReactFiberCommitWork, and it's a bit awkward, especially when
refactoring. Idk the ideal module structure, so for now I'd rather keep
it all in one file.

* Traverse commit phase effects iteratively

We suspect that using the JS stack to traverse through the tree in the
commit phase is slower than traversing iteratively.

I've kept the recursive implementation behind a flag, both so we have
the option to run an experiment comparing the two, and so we can revert
it easily later if needed.
2020-10-27 12:02:19 -07:00
Justus Hämäläinen
06a4615be2 Allow Node 15.x (#20108)
Co-authored-by: Justus Hämäläinen <me@justushamalainen.fi>
2020-10-27 15:16:16 +00:00
Sy Tran Dung
4e5d7faf54 Fix error loading source maps for devtools extension (#20079) 2020-10-22 11:26:24 -04:00
Abhyuday Bharat
3314115cb4 Overly eager update-notifier usage in react-devtools (#20078)
Co-authored-by: abhyuday <abhyuday@miqdigital.com>
2020-10-22 08:52:14 -04:00
Dan Abramov
eaaf4cbce7 17.0.1 2020-10-22 13:24:46 +01:00
Minh Nguyen
928a819a28 Use react-shallow-renderer@16.14.1 in yarn.lock (#20072)
This ensures that tests are run against the latest published version. This
merely updates the version in `yarn.lock` and not in `react-test-renderer`'s
`package.json` to avoid having to cut another release of `react-test-renderer`.
2020-10-21 13:37:34 +01:00
Dan Abramov
6f62abb58a Remove usage of Array#fill (#20071) 2020-10-21 13:17:44 +01:00
Dan Abramov
40cfe1f486 Update CHANGELOG.md 2020-10-21 01:15:28 +01:00
Dan Abramov
a50f638b06 Link to the blog post 2020-10-20 21:51:41 +01:00
Dan Abramov
f021a983aa Bump versions for 17 (#20062) 2020-10-20 21:41:18 +01:00
Dan Abramov
46ed268471 Add React 17 changelog 2020-10-20 21:22:00 +01:00
Brian Vaughn
d1bb4d851f Profiler: Include ref callbacks in onCommit duration (#20060) 2020-10-20 14:35:57 -04:00
Brian Vaughn
c59c3dfe55 useRef: Warn about reading or writing mutable values during render (#18545)
Reading or writing a ref value during render is only safe if you are implementing the lazy initialization pattern.

Other types of reading are unsafe as the ref is a mutable source.

Other types of writing are unsafe as they are effectively side effects.

This change also refactors useTransition to no longer use a ref hook, but instead manage its own (stable) hook state.
2020-10-19 16:05:00 -04:00
Brian Vaughn
75726fadfd DevTools fix props editing for host components (#20055) 2020-10-19 15:21:41 -04:00
Brian Vaughn
51a3aa6afb DevTools 4.8.2 -> 4.9.0 bump 2020-10-19 11:20:54 -04:00
Brian Vaughn
7b6cac9522 Improved Profiler commit hooks test (#20053)
Previously the tests didn't ensure that time spent during cascading render was not included in duration reported by commit hooks.
2020-10-19 09:36:00 -04:00
Kai Riemann
dfb6a40335 [Fast Refresh] Fix crashes caused by rogue Proxies (#20030) (#20039) 2020-10-17 17:47:52 +01:00
Andrew Clark
37cb732c59 Use bitwise OR to define flag masks (#20044)
Easier to read, harder to mess up. These expressions get simplified by
Closure, so there's no runtime impact.
2020-10-16 13:30:35 -07:00
Andrew Clark
eb3181e772 Add Visibility flag for hiding/unhiding trees (#20043)
* Add Visibility flag for hiding/unhiding trees

There's `beforeblur` logic in the snapshot phase that needs to visit
every Suspense boundary whose visibility is toggled. Right now it does
that by visiting Placement and Deletion effects. That includes many
unrelated nodes.

By adding a new flag specifically for toggling Visibility, we will only
visit the relevant Suspense (and Offscreen) boundaries, instead of all
nodes that have a Placement.

Potential follow-ups (not urgent):

- The `beforeblur` logic also has a check to see whether the visibility
was toggled on or off. It only cares about things being hidden. As a
follow up, I can split the Visibility flag into separate Hide/Show
flags, and only visit Hide.
- Now that this is separate from Update, we can move the rest of the
Suspense's layout effects (like attaching retry listeners) to the
passive phase.

* Gate behind createEventHandle feature flag

Only need to visit deleted and hidden trees during the snapshot phase
if the experimental `createEventHandle` flag is enabled. Currently,
it's only used internally at Facebook, not open source.
2020-10-16 09:49:07 -07:00
Andrew Clark
0dd809bdfa Remove last schedulePassiveEffectCallback call (#20042)
Now there's only a single place where the passive effect callback
is scheduled.
2020-10-16 09:06:55 -07:00
Dan Abramov
e9f5ad2584 Remove Set bookkeeping for root events (#19990)
* Remove dead code branch

This function is only called when initializing roots/containers (where we skip non-delegated events) and in the createEventHandle path for non-DOM nodes (where we never hit this path because targetElement is null).

* Move related functions close to each other

* Fork listenToNativeEvent for createEventHandle

It doesn't need all of the logic that's needed for normal event path.

And the normal codepath doesn't use the last two arguments.

* Expand test coverage for non-delegated events

This changes a test to fail if we removed the event handler Sets. Previously, we didn't cover that.

* Add DEV-level check that top-level events and non-delegated events do not overlap

This makes us confident that they're mutually exclusive and there is no duplication between them.

* Add a test verifying selectionchange deduplication

This is why we still need the Set bookkeeping. Adding a test for it.

* Remove Set bookkeeping for root events

Root events don't intersect with non-delegated bubbled events (so no need to deduplicate there). They also don't intersect with createEventHandle non-managed events (because those don't go on the DOM elements). So we can remove the bookeeping because we already have code ensuring the eager subscriptions only run once per element.

I've moved the selectionchange special case outside, and added document-level deduplication for it alone.

Technically this might change the behavior of createEventHandle with selectionchange on the document, but we're not using that, and I'm not sure that behavior makes sense anyway.

* Flow
2020-10-16 16:49:41 +01:00
Sebastian Silbermann
b093528650 test: Add regression test for hooks after error boundaries (#20002)
* test: Add regression test for hooks after error boundaries

* fix lint
2020-10-16 16:07:27 +01:00
oltrep
f668b6c351 Bump to latest eslint-config-fbjs (#20029)
* bump package to latest

* update files to respect lint

* disable object-type-delimiter rule to work with prettier

* disable rule to let flow check pass
2020-10-16 16:06:08 +01:00
Andrew Clark
8df7b7911a Remove Passive flag from "before mutation" phase (#20038)
We don't need to visit passive effect nodes during before mutation.

The only reason we were previously was to schedule the root-level
passive effect callback as early as possible, but now that
`subtreeFlags` exists, we can check that instead.

This should reduce the amount of traversal during the commit phase,
particularly when mounting or updating large trees that contain many
passive effects.
2020-10-16 08:21:58 -05:00
IDrissAitHafid
2eb3181eb4 fixed unfound node error when Suspense is filtered (#20019)
* fixed unfound node error when Suspense is filtered

* added a test for filtered Suspense node
2020-10-15 14:45:23 -04:00
adasq
c57fe4a2c1 ReactIs.isValidElementType Unit Test extended with PureComponent case (#20033)
Co-authored-by: Adam Plocieniak <adam.plocieniak@allegro.pl>
2020-10-15 08:48:28 -04:00
Brian Vaughn
02da938fd5 Don't double-invoke effects in legacy roots (#20028)
Large legacy applications are likely to be difficult to update to handle this feature, and it wouldn't add any value– since newer APIs that require this resilience are not legacy compatible.
2020-10-15 08:40:12 -04:00
Dominic Gannaway
d95c4938df [EventSystem] Revise onBeforeBlur propagation mechanics (#20020) 2020-10-14 23:38:57 +01:00
Dan Abramov
b5eabd543f Update changelog for 16.14, 15.7, 0.14.10 (#20027) 2020-10-14 20:52:37 +01:00
Simen Bekkhus
020d3aa4e8 chore: downgrade source-map-support for stack "fix" (#20026)
* chore: downgrade source-map-support for stack "fix"

* lint?
2020-10-14 20:45:54 +01:00
Saikat Guha
4eb589169c DevTools: Handle restricted browser pages properly like new tab page, extensions page etc(only chrome and edge for now) (#20023) 2020-10-14 13:59:05 -04:00
Dan Abramov
6d50a9d090 Fixture: Legacy JSX Runtimes (#20012)
* Fixture: Legacy JSX Runtimes

* Add more comments
2020-10-14 18:28:03 +01:00
Brian Vaughn
f75f8b48a2 DevTools always overrides the dispatcher when shallow rendering (#20011)
This is done so that any effects scheduled by the shallow render are thrown away.

Unlike the code this was forked from (in ReactComponentStackFrame) DevTools should override the dispatcher even when DevTools is compiled in production mode, because the app itself may be in development mode and log errors/warnings.
2020-10-14 13:19:47 -04:00
Ricky
880587366d Deprecate old test script commands (#19893)
* Deprecate old test script commands

* Update PR template test script

* Add test-stable and test-www-classic

* Update circle test names

* Rename test-www-classic to test-classic

* Missed some job renames

* Missed some more job renames
2020-10-14 08:54:34 -04:00
IDrissAitHafid
e614e69657 handled a missing suspense fiber when suspense is filtered on the profiler (#19987)
Co-authored-by: Brian Vaughn <bvaughn@fb.com>
2020-10-13 13:38:58 -04:00
Brian Vaughn
7559722a86 Fix bad null check in DevTools highlight code (#20010) 2020-10-13 13:08:12 -04:00
Nick Reiley
7e405d458d [DevTools] Add DevTools forked Feature flags (#18994)
Also resolve an uncaught error in extension build (#18843).

Co-authored-by: Brian Vaughn <brian.david.vaughn@gmail.com>
Co-authored-by: Brian Vaughn <bvaughn@fb.com>
2020-10-12 13:07:10 -04:00
IDrissAitHafid
4890779729 Updated OVERVIEW.md to the new infos required when adding a new leaf node to the tree (#19981)
Co-authored-by: Idriss AITHAFID <Idriss.AITHAFID@um6p.ma>
2020-10-09 09:29:30 -04:00
Saikat Guha
f46a80ae11 Update outdated links and fix two broken links (#19985)
* update all facebook.github.io links

* facebookincubator links : update some outdated links and fix two other broken links where they are actually the latest updated ones
2020-10-09 02:56:30 +01:00
Sebastian Markbåge
0a4c7c5651 [Flight] Don't warn for key, but error for ref (#19986)
* Improve error message by expanding the object in question

* Don't warn for key/ref getters

* Error if refs are passed in server components or to client components
2020-10-08 17:02:23 -07:00
Dan Abramov
993ca533b4 Enable eager listeners statically (#19983) 2020-10-08 19:32:28 +01:00
Sebastian Markbåge
40c52de960 [Flight] Add Runtime Errors for Non-serializable Values (#19980)
* Error on encoding non-serializable props

* Add DEV time warnings to enforce that values are plain objects
2020-10-08 11:11:15 -07:00
IDrissAitHafid
6eca8eff08 updating the informations needed when adding a root node to a tree in react-devtools overview doc (#19979)
Co-authored-by: Idriss AITHAFID <Idriss.AITHAFID@um6p.ma>
2020-10-08 08:46:15 -04:00
Shivam Sandbhor
4ead6b5305 Treat <time> tag as a normal HTML tag. (#19951)
<time> tag has been supported by Chrome since Chrome 62.0.
Remove workarounds which were in place to avoid friction with
versions before Chrome 62.

Signed-off-by: Shivam Sandbhor <shivam.sandbhor@gmail.com>
2020-10-06 03:15:32 +01:00
Brian Vaughn
1992d97306 Revert "Temporarily disable Profiler commit hooks flag (#19900)" (#19960) 2020-10-05 15:49:52 -04:00
Brian Vaughn
44d39c4d76 Removed skip-error-boundaries modifications from old fork (#19961)
Technically this change is unnecessary, since the feature is controlled by a flag, but since we decided not to ship this in v17– I'm going to remove it for now entirely.
2020-10-05 15:49:44 -04:00
Brian Vaughn
461cd84944 Revert "DevTools: Improve browser extension iframe support (#19854)" (#19959)
This reverts commit a99bf5c5f4.
2020-10-05 09:44:08 -04:00
Paul Doyle
cc77be957e Remove unnecessary error overriding in (#19949) 2020-10-02 22:10:46 +01:00
Brian Vaughn
97625272ab Debug tracing tests for CPU bound suspense (#19943) 2020-10-01 12:02:26 -04:00
Eugene Maslovich
43363e2795 Fix codestyle for typeof comparison (#19928) 2020-10-01 16:26:49 +01:00
John Wilson
8657ad4278 Fix(React DevTools) - prevent phishing attacks (#19934)
When a link opens a URL in a new tab with target="_blank", it is very simple for the opened page to change the location of the original page because the JavaScript variable window.opener is not null and thus "window.opener.location can be set by the opened page. This exposes the user to very simple phishing attacks.
2020-10-01 16:25:38 +01:00
Saikat Guha
91d2b6ef01 DevTools: Remove ReactJS.org version check "cheat" (#19939)
Remove dead code as facebook.github.io/react always redirects to reactjs.org, which has prod version of react. so removing the "cheat" (#19939)
2020-10-01 10:16:50 -04:00
Brian Vaughn
5427b4657b Temporarily disable Profiler commit hooks flag (#19900)
Temporarily disable Profiler commit hooks flag to verify it does not cause a regression.
2020-09-30 15:58:20 -04:00
Andrew Clark
1faf9e3dd5 Suspense for CPU-bound trees (#19936)
Adds a new prop to the Suspense component type,
`unstable_expectedLoadTime`. The presence of this prop indicates that
the content is computationally expensive to render.

During the initial mount, React will skip over expensive trees by
rendering a placeholder — just like we do with trees that are waiting
for data to resolve. That will help unblock the initial skeleton for the
new screen. Then we will continue rendering in the next commit.

For now, while we experiment with the API internally, any number passed
to `unstable_expectedLoadTime` will be treated as "computationally
expensive", no matter how large or small. So it's basically a boolean.
The reason it's a number is that, in the future, we may try to be clever
with this additional information. For example, SuspenseList could use
it as part of its heuristic to determine whether to keep rendering
additional rows.

Background
----------

Much of our early messaging and research into Suspense focused on its
ability to throttle the appearance of placeholder UIs. Our theory was
that, on a fast network, if everything loads quickly, excessive
placeholders will contribute to a janky user experience. This was backed
up by user research and has held up in practice.

However, our original demos made an even stronger assertion: not only is
it preferable to throttle successive loading states, but up to a certain
threshold, it’s also preferable to remain on the previous screen; or in
other words, to delay the transition.

This strategy has produced mixed results. We’ve found it works well for
certain transitions, but not for all them. When performing a full page
transition, showing an initial skeleton as soon as possible is crucial
to making the transition feel snappy. You still want throttle the nested
loading states as they pop in, but you need to show something on the new
route. Remaining on the previous screen can make the app feel
unresponsive.

That’s not to say that delaying the previous screen always leads to a
bad user experience. Especially if you can guarantee that the delay is
small enough that the user won’t notice it. This threshold is a called a
Just Noticeable Difference (JND). If we can stay under the JND, then
it’s worth skipping the first placeholder to reduce overall thrash.

Delays that are larger than the JND have some use cases, too. The main
one we’ve found is to refresh existing data, where it’s often preferable
to keep stale content on screen while the new data loads in the
background. It’s also useful as a fallback strategy if something
suspends unexpectedly, to avoid hiding parts of the UI that are already
visible.

We’re still in the process of optimizing our heuristics for the most
common patterns. In general, though, we are trending toward being more
aggressive about prioritizing the initial skeleton.

For example, Suspense is usually thought of as a feature for displaying
placeholders when the UI is missing data — that is, when rendering is
bound by pending IO.

But it turns out that the same principles apply to CPU-bound
transitions, too. It’s worth deferring a tree that’s slow to render if
doing so unblocks the rest of the transition — regardless of whether
it’s slow because of missing data or because of expensive CPU work.

We already take advantage of this idea in a few places, such as
hydration. Instead of hydrating server-rendered UI in a single pass,
React splits it into chunks. It can do this because the initial HTML
acts as its own placeholder. React can defer hydrating a chunk of UI as
long as it wants until the user interacts it. The boundary we use to
split the UI into chunks is the same one we use for IO-bound subtrees:
the <Suspense /> component.

SuspenseList does something similar. When streaming in a list of items,
it will occasionally stop to commit whatever items have already
finished, before continuing where it left off. It does this by showing a
placeholder for the remaining items, again using the same <Suspense />
component API, even if the item is CPU-bound.

Unresolved questions
--------------------

There is a concern that showing a placeholder without also loading new
data could be disorienting. Users are trained to believe that a
placeholder signals fresh content. So there are still some questions
we’ll need to resolve.
2020-09-30 12:57:33 -07:00
Brian Vaughn
7f08e908b1 Fix missing context to componentDidMount() when double-invoking lifecycles (#19935) 2020-09-30 15:56:19 -04:00
Brian Vaughn
9198a5cec0 Refactor layout effect methods (#19895)
Commit phase durations (layout and passive) are stored on the nearest (ancestor) Profiler and bubble up during the commit phase. This bubbling used to be implemented by traversing the return path each time we finished working on a Profiler to find the next nearest Profiler.

This commit removes that traversal. Instead, we maintain a stack of nearest Profiler ancestor while recursing the tree. This stack is maintained in the work loop (since that's where the recursive functions are) and so bubbling of durations has also been moved from commit-work to the work loop.

This PR also refactors the methods used to recurse and apply effects in preparation for the new Offscreen component type.
2020-09-29 15:58:20 -04:00
Andrew Clark
ba82eea383 Remove disableSchedulerTimeoutInWorkLoop flag (#19902)
We found and mitigated the root cause of the regression that led us to
temporarily revert this change. So now I'm un-reverting it.
2020-09-28 10:19:14 -07:00
Dmitriy Kovalenko
71bc8ac74c Improve wording for inline DevTools README.md (#19897) 2020-09-28 09:25:18 -04:00
Dan Abramov
480626a9e9 Create Synthetic Events Lazily (#19909) 2020-09-25 13:33:28 +01:00
Dan Abramov
0a00804494 Remove Array.from() from hot path (#19908)
* Remove Array.from() from hot path

* Fix build

Don't declare block variables inside loops
2020-09-25 11:33:07 +01:00
Dan Abramov
1890159a5d Separate SyntheticEvent constructors to prevent deopts (#19907)
* Remove arguments from hot path

* Make SyntheticEvent subtypes monomorphic

* Maybe fix Flow?
2020-09-25 11:31:00 +01:00
Luna Ruan
c63741fb3d offscreen double invoke effects (#19523)
This PR double invokes effects in __DEV__ mode.

We are thinking about unmounting layout and/or passive effects for a hidden tree. To understand potential issues with this, we want to double invoke effects. This PR changes the behavior in DEV when an effect runs from create() to create() -> destroy() -> create(). The effect cleanup function will still be called before the effect runs in both dev and prod. (Note: This change is purely for research for now as it is likely to break real code.)

**Note: The change is fully behind a flag and does not affect any of the code on npm.**
2020-09-24 13:42:17 -07:00
6h057
a99bf5c5f4 DevTools: Improve browser extension iframe support (#19854)
Co-authored-by: Joel DSouza <joel.dsouza@kapturecrm.com>
Co-authored-by: Damien Maillard <damien.maillard@dailymotion.com>
Co-authored-by: Brian Vaughn <brian.david.vaughn@gmail.com>
2020-09-23 16:56:13 -04:00
Brian Vaughn
c6917346ff Fixed broken Profiler test (#19894) 2020-09-23 15:33:25 -04:00
Brian Vaughn
87c023b1c1 Profiler onRender only called when we do work (#19885)
If we didn't perform any work in the subtree, skip calling onRender.
2020-09-22 14:47:13 -04:00
Todor Totev
92c7e49895 Don't consumer iterators while inspecting (#19831)
Co-authored-by: Brian Vaughn <bvaughn@fb.com>
2020-09-22 14:23:20 -04:00
Andrew Clark
81aaee56af Don't call onCommit et al if there are no effects (#19863)
* Don't call onCommit et al if there are no effects

Checks `subtreeFlags` before scheduling an effect on the Profiler.

* Fix failing Profiler tests

The change to conditionally call Profiler commit hooks only if updates were scheduled broke a few of the Profiler tests. I've fixed the tests by either:
* Adding a no-op passive effect into the subtree or
* Converting onPostCommit to onCommit

When possible, I opted to add the no-op passive effect to the tests since that that hook is called later (during passive phase) so the test is a little broader. In a few cases, this required adding awkward act() wrappers so I opted to go with onCommit instead.

Co-authored-by: Brian Vaughn <bvaughn@fb.com>
2020-09-22 11:20:26 -07:00
Andrew Clark
7355bf575a Consolidate commit phase hook functions (#19864)
There were a few pairs of commit phase functions that were almost
identical except for one detail. I've refactored them a bit to
consolidate their implementations:

- Lifted error handling logic when mounting a fiber's passive hook
effects to surround the entire list, instead of surrounding each effect.
- Lifted profiler duration tracking to surround the entire list.

In both cases, this matches the corresponding code for the layout phase.

The naming is still a bit of a mess but I'm not too concerned because
my next step is to refactor each commit sub-phase (layout, mutation)
so that we can store values on the JS stack. So the existing function
boundaries are about to change, anyway.
2020-09-22 11:16:27 -07:00
Dan Abramov
c91c1c4ebe Release script: allow preparing RC from npm 2020-09-22 14:27:50 +01:00
E-Liang Tan
04e21efd09 Add scheduling profiler deployment CI job (#19874)
* Add vercel to scheduling profiler dev deps
* Add vercel.json
* Add CD job
* Add CD setup instructions
2020-09-22 08:34:06 -04:00
Brian Vaughn
ded2a83ebf Improved DevTools context test harness (#19878) 2020-09-21 16:39:53 -04:00
E-Liang Tan
6d73063ddf Enable building of DevTools and scheduling profiler in CI (#19691)
Re-enables building of main DevTools in CI and add new CI target for building the scheduling profiler.
2020-09-21 11:49:07 -04:00
Brian Vaughn
a8de69f358 DevTools: Drop IE 11 support (#19875)
DevTools shared Babel config previously supported IE 11 to target Hermes (for the standalone backend that gets embedded within React Native apps). This targeting resulted in less optimal code for other DevTools targets though which did not need to support IE 11. This PR updates the shared config to remove IE 11 support by default, and only enables it for the standalone backend target.
2020-09-21 11:07:45 -04:00
Dan Abramov
bc6b7b6b16 Don't trigger lazy in DEV during element creation (#19871) 2020-09-21 16:04:49 +01:00
Gustavo Saiani
a774502e0f Use single quotes in getComponentName return (#19873) 2020-09-21 13:35:21 +01:00
Andrew Clark
8b2d3783e5 Use Passive flag to schedule onPostCommit (#19862)
Instead of calling `onPostCommit` in a separate phase, we can fire
them during the same traversal as the rest of the passive effects.

This works because effects are executed depth-first. So by the time we
reach a Profiler node, we'll have already executed all the effects in
its subtree.
2020-09-18 13:02:26 -07:00
Brian Vaughn
50d9451f32 Improve DevTools editing interface (#19774)
* Improve DevTools editing interface

This commit adds the ability to rename or delete keys in the props/state/hooks/context editor and adds tests to cover this functionality. DevTools will degrade gracefully for older versions of React that do not inject the new reconciler rename* or delete* methods.

Specifically, this commit includes the following changes:
* Adds unit tests (for modern and legacy renderers) to cover overriding props, renaming keys, and deleting keys.
* Refactor backend override methods to reduce redundant Bridge/Agent listeners and methods.
* Inject new (DEV-only) methods from reconciler into DevTools to rename and delete paths.
* Refactor 'inspected element' UI components to improve readability.
* Improve auto-size input to better mimic Chrome's Style editor panel. (See this Code Sandbox for a proof of concept.)

It also contains the following code cleanup:
* Additional unit tests have been added for modifying values as well as renaming or deleting paths.
* Four new DEV-only methods have been added to the reconciler to be injected into the DevTools hook: overrideHookStateDeletePath, overrideHookStateRenamePath, overridePropsDeletePath, and overridePropsRenamePath. (DevTools will degrade gracefully for older renderers without these methods.)
* I also took this as an opportunity to refactor some of the existing code in a few places:
  * Rather than the backend implementing separate methods for editing props, state, hooks, and context– there are now three methods: deletePath, renamePath, and overrideValueAtPath that accept a type argument to differentiate between props, state, context, or hooks.
  * The various UI components for the DevTools frontend have been refactored to remove some unnecessary repetition.

This commit also adds temporary support for override* commands with mismatched backend/frontend versions:
* Add message forwarding for older backend methods (overrideContext, overrideHookState, overrideProps, and overrideState) to the new overrideValueAtPath method. This was done in both the frontend Bridge (for newer frontends passing messages to older embedded backends) and in the backend Agent (for older frontends passing messages to newer backends). We do this because React Native embeds the React DevTools backend, but cannot control which version of the frontend users use.
* Additional unit tests have been added as well to cover the older frontend to newer backend case. Our DevTools test infra does not make it easy to write tests for the other way around.
2020-09-18 11:07:18 -04:00
Johnny Pribyl
b3b1bb9ce2 Enable source maps for DevTools production builds (#19773)
Co-authored-by: Brian Vaughn <bvaughn@fb.com>
2020-09-18 10:07:22 -04:00
Brian Vaughn
26857ecfa9 Revert "DevTools: Improve browser extension iframe support (#19827)" (#19852)
This reverts commit ec39a5e901.
2020-09-17 14:57:44 -04:00
Dan Abramov
6fddca27e7 Remove passive intervention flag (#19849) 2020-09-17 15:37:12 +01:00
Adnaan Bheda
36df9185c5 chore(docs): Removed outdated comment about fb.me link (#19830) 2020-09-16 08:07:16 -04:00
Brian Vaughn
16fb2b6f9e Moved resetChildLanes into complete work (#19836)
This allows us to inline a few checks that are specific to a certain tag-type.
2020-09-15 17:12:48 -04:00
Andrew Clark
b93f3e7d2d Fix act bundle size regression (#19832)
Adds back the `TestUtils.act` implementation that I had removed
in #19745. This version of `act` is implemented in "userspace" (i.e. not
the reconciler), so it doesn't add to the production bundle size.

I had removed this in #19745 in favor of the `act` exported by the
reconciler because I thought we would remove support for `act` in
production in the impending major release. (It currently warns.)

However, we've since decided to continue supporting `act` in prod for
now, so that it doesn't block people from upgrading to v17. We'll drop
support in a future major release.

So, to avoid bloating the production bundle size, we need to move the
public version of `act` back to "userspace", like it was before.

This doesn't negate the main goal of #19745, though, which was to
decouple the public version(s) of `act` from the internal one that we
use to test React itself.
2020-09-14 10:11:47 -07:00
6h057
ec39a5e901 DevTools: Improve browser extension iframe support (#19827)
Co-authored-by: Joel DSouza <joel.dsouza@kapturecrm.com>
Co-authored-by: Damien Maillard <damien.maillard@dailymotion.com>
Co-authored-by: Brian Vaughn <brian.david.vaughn@gmail.com>
2020-09-14 10:04:46 -04:00
6h057
917cb01a58 React DevTools: Show symbols used as keys in state (#19786)
Co-authored-by: Brian Vaughn <bvaughn@fb.com>
2020-09-14 09:55:19 -04:00
Dan Abramov
11ee82df45 [Events] Make passiveness and priority non-configurable (#19807) 2020-09-14 13:54:08 +01:00
Seth Webster
ebb2253428 updates mailmap entries (#19824) 2020-09-12 13:05:52 -04:00
Dan Abramov
cc581065df eslint-plugin-react-hooks@4.1.2 2020-09-11 13:18:44 +01:00
Dan Abramov
0044805c88 Update CHANGELOG.md 2020-09-11 13:17:55 +01:00
Sebastian Silbermann
0f70d4dd66 Consider components in jsx as missing dependencies in @typescript-eslint/parser@4.x (#19815)
* Run JS tests with TS esling parser

* Add failing test

* fix: Mark JSXIdentifier has missing dependency

* Safe isSameIdentifier
2020-09-11 13:13:43 +01:00
Andrew Clark
84558c61ba Don't visit passive effects during layout phase (#19809)
Removes the `Update` flag when scheduling a passive effect for
`useEffect`. The `Passive` flag alone is sufficient.

This doesn't affect any behavior, but does optimize the performance of
the commit phase.
2020-09-10 14:00:41 -07:00
Dan Abramov
ad8a0a8cd0 eslint-plugin-react-hooks@4.1.1 2020-09-10 19:54:42 +01:00
Dan Abramov
77544a0d6f Update CHANGELOG.md 2020-09-10 19:54:10 +01:00
Sebastian Silbermann
ed4fdfc737 test(eslint-plugin-react-hooks): Run with TS parsers >= 2.x (#19792)
* test(eslint-plugin-react-hooks): Run with TS parsers >= 2.x

* name test suites for each parser
2020-09-10 19:08:47 +01:00
Matthias Schiffer
cd75f93c03 eslint-plugin-react-hooks: fix compatibility with @typescript-eslint/parser@4.0.0+ (#19751)
In addition to `TSTypeQuery`, dependency nodes with a `TSTypeReference`
parent need to be ignored as well. Without this fix, generic type
variables will be listed as missing dependencies.

Example:

    export function useFoo<T>(): (foo: T) => boolean {
        return useCallback((foo: T) => false, []);
    }

This will report the following issue:

    React Hook useCallback has a missing dependency: 'T'. Either include
    it or remove the dependency array

Closes: #19742
2020-09-10 11:30:18 +01:00
Dan Abramov
a08ae9f147 Listen to onScroll during hydration (#19803) 2020-09-10 11:00:02 +01:00
Gustavo Saiani
781212aab3 Remove double space in test name (#19762) 2020-09-09 18:26:44 -04:00
Andrew Clark
e7b255341b Internal act: Flush timers at end of scope (#19788)
If there are any suspended fallbacks at the end of the `act` scope,
force them to display by running the pending timers (i.e. `setTimeout`).

The public implementation of `act` achieves the same behavior with an
extra check in the work loop (`shouldForceFlushFallbacks`). Since our
internal `act` needs to work in both development and production, without
additional runtime checks, we instead rely on Jest's mock timers.

This doesn't not affect refresh transitions, which are meant to delay
indefinitely, because in that case we exit the work loop without
posting a timer.
2020-09-08 21:55:23 -07:00
Andrew Clark
d17086c7c8 Decouple public, internal act implementation (#19745)
In the next major release, we intend to drop support for using the `act`
testing helper in production. (It already fires a warning.) The
rationale is that, in order for `act` to work, you must either mock the
testing environment or add extra logic at runtime. Mocking the testing
environment isn't ideal because it requires extra set up for the user.
Extra logic at runtime is fine only in development mode — we don't want
to slow down the production builds.

Since most people only run their tests in development mode, dropping
support for production should be fine; if there's demand, we can add it
back later using a special testing build that is identical to the
production build except for the additional testing logic.

One blocker for removing production support is that we currently use
`act` to test React itself. We must test React in both development and
production modes.

So, the solution is to fork `act` into separate public and
internal implementations:

- *public implementation of `act`* – exposed to users, only works in
  development mode, uses special runtime logic, does not support partial
  rendering
- *internal implementation of `act`* – private, works in both
  development and productionm modes, only used by the React Core test
  suite, uses no special runtime logic, supports partial rendering (i.e.
  `toFlushAndYieldThrough`)

The internal implementation should mostly match the public
implementation's behavior, but since it's a private API, it doesn't have
to match exactly. It works by mocking the test environment: it uses a
mock build of Scheduler to flush rendering tasks, and Jest's mock timers
to flush Suspense placeholders.

---

In this first commit, I've added the internal forks of `act` and
migrated our tests to use them. The public `act` implementation is
unaffected for now; I will leave refactoring/clean-up for a later step.
2020-09-08 08:11:45 -07:00
Joseph Savona
d38ec17b1d [Flight] Set dispatcher for duration of performWork() (#19776) 2020-09-07 19:41:22 -04:00
Andrew Clark
4f3f7eeb7f Bugfix: Effect clean up when deleting suspended tree (#19752)
* Bug: Effect clean up when deleting suspended tree

Adds a failing unit test.

* Re-use static flags from suspended primary tree

When switching to a Suspense boundary's fallback, we need to be sure
to preserve static subtree flags from the primary tree.
2020-09-04 15:46:44 -07:00
Andrew Clark
7baf9d4128 Combine Flags and SubtreeFlags types (#19775)
Because the `subtreeFlags` is the union of all the flags present in
a subtree, we can use the same type as `flags`.

One practical benefit is that we can bubble up the flags from the
children with a single `|=` operator.

Structurally, everything else about the effect algorithm is unchanged.
2020-09-04 14:48:30 -07:00
Andrew Clark
1665443603 Rename effect fields (#19755)
- `effectTag` -> `flags`
- `subtreeTag` -> `subtreeFlags`
2020-09-04 14:34:07 -07:00
Andrew Clark
708fa77a78 Decrease expiration time of input updates (#19772)
Changes the expiration time of input updates from 1000ms to 250ms, to
match the corresponding constant in Scheduler.js.

When we made it larger, a product metric in www regressed, suggesting
there's a user interaction that's being starved by a series of
synchronous updates. If that theory is correct, the proper solution is
to fix the starvation. However, this scenario supports the idea that
expiration times are an important safeguard when starvation does happen.

Also note that, in the case of user input specifically, this will soon
no longer be an issue because we plan to make user input synchronous by
default (until you enter `startTransition`, of course.)

If weren't planning to make these updates synchronous soon anyway, I
would probably make this number a configurable parameter.
2020-09-04 10:42:09 -07:00
Ricky
36df483af4 Add feature flag to disable scheduler timeout in work loop (#19771) 2020-09-04 10:58:17 -04:00
E-Liang Tan
eabd18c73f Scheduling Profiler: Move preprocessing to web worker and add loading indicator (#19759)
* Move preprocessData into a web worker
* Add UI feedback for loading/import error states
* Terminate worker when done handling profile
* Add display density CSS variables
2020-09-04 10:57:32 -04:00
E-Liang Tan
38a512acad Scheduling Profiler: Redesign with DevTools styling (#19707)
Co-authored-by: Brian Vaughn <bvaughn@fb.com>
2020-09-03 12:08:40 -04:00
Dan Abramov
bcc0aa4633 Revert "Revert "Remove onScroll bubbling flag (#19535)" (#19655)" (#19761)
This reverts commit 64ddef44c6.
2020-09-03 17:06:20 +01:00
E-Liang Tan
e9454894ff Scheduling Profiler: Extract and test scroll state from horizontal pan and zoom view (#19682)
* Extract reusable scroll logic from HorizontalPanAndZoomView

* Change VerticalScrollView to use scrollState

* Clarify test name
2020-09-03 10:27:35 -04:00
E-Liang Tan
9340083395 Scheduling Profiler: Add Fast Refresh (#19757) 2020-09-03 09:17:57 -04:00
Meghnath Pillay
835c11eba7 Add checkbox toggle for boolean values (#19714)
* added a checkbox which appears to the right of a value when value is boolean
* checkbox with toggle capability created for boolean props

Co-authored-by: Brian Vaughn <brian.david.vaughn@gmail.com>
2020-09-03 08:57:12 -04:00
Brian Vaughn
99cae887f3 Add failing test for passive effect cleanup functions and memoized components (#19750)
* Add failing tests for passive effects cleanup not being called for memoized components

* Bubble passive static subtreeTag even after bailout

This prevents subsequent unmounts from skipping over any pending passive effect destroy functions
2020-09-02 13:01:52 -04:00
Ikko Ashimine
2cfd73c4d0 Fix typo in comment (Noticable→Noticeable) (#19737) 2020-09-01 20:19:10 -04:00
Brian Vaughn
98dba66ee1 Add ⎇ + arrow key navigation to DevTools (#19741)
⎇ + left/right navigates between owners (similar to owners tree) and ⎇ + up/down navigations between siblings.
2020-09-01 20:03:44 -04:00
Bhumij Gupta
53e622ca7f Fix instances of function declaration after return (#19733)
* Add ESLint plugin to check for any function declare after return
* Refactor code to move function declarations before return and fix failing lint
2020-09-01 08:55:10 -04:00
Kevin Weber
b7d18c4daf Support Babel's envName option in React Refresh plugin (#19009)
* Fix envName bug

* Replace getEnv with env
2020-09-01 13:50:54 +01:00
Andrew Clark
1f38dcff67 Remove withSuspenseConfig (#19724)
Removes `withSuspenseConfig` and migrates relevant tests to
`startTransition` instead.

We only had one caller in www, which I've removed.
2020-08-31 09:16:49 -07:00
Pascal Fong Kye
1396e4a8f5 Fixes eslint warning when node type is ChainExpression (#19680)
* Add babel parser which supports ChainExpression

* Add and fix tests for new babel eslint parser

* extract function to mark node

* refactor for compatibility with eslint v7.7.0+

* Update eslint to v7.7.0
Update hook test since eslint now supports nullish coalescing
2020-08-29 21:03:23 +01:00
Andrew Clark
a8500be893 Add startTransition as a known stable method (#19720)
The `startTransition` method returned from `useTransition` is a stable
method, like `dispatch` or `setState`. You should not have to specify
it as a hook dependency.
2020-08-28 16:44:39 -07:00
Andrew Clark
4f5fb56100 Use gate pragma instead of if (__EXPERIMENTAL__) (#19722)
* Use gate pragma instead of if (__EXPERIMENTAL__)

* Fix stream error handling in tests

Added an error listener so that the tests fail within their Jest scope,
instead of crashing the whole process.
2020-08-28 14:21:01 -07:00
Timothy Yung
380dc95de8 Revert "Append text string to <Text> error message (#19581)" (#19723)
This reverts commit 1a41a196bc.
2020-08-28 13:46:59 -07:00
Andrew Clark
ddd1faa197 Remove config argument from useTransition (#19719)
And `useDeferredValue`.

The options were already disabled in previous commits, so this doesn't
change any behavior. I upated type signatures and cleaned up the hook
implementation a bit — no longer have to wrap the `start` method with
`useCallback`, because its only remaining dependency is a `setState`
method, which never changes. Instead, we can store the `start` method
on a ref.
2020-08-28 11:49:01 -07:00
Andrew Clark
92fcd46cc7 Replace SuspenseConfig object with an integer (#19706)
Now that the options in SuspenseConfig are no longer supported, the
only thing we use it for is to track whether an update is part of
a transition.

I've renamed `ReactCurrentBatchConfig.suspense` to
`ReactCurrentBatchConfig.transition`, and changed the type to a number.
The number is always either 0 or 1. I could have made it a boolean;
however, most likely this will eventually be either a Lane or an
incrementing identifier.

The `withSuspenseConfig` export still exists until we've removed
all the callers from www.
2020-08-28 10:52:56 -07:00
Dan Abramov
b754caaaf2 Enable eager listeners in open source (#19716)
* Enable eager listeners in open source

* Fix tests

* Enable in all places
2020-08-28 12:23:28 +01:00
Dan Abramov
c1ac052158 [Flight] Support more element types and Hooks for Server and Hybrid Components (#19711)
* Shim support for more element types

* Shim commonly used Hooks that are safe

* Flow

* Oopsie
2020-08-27 20:19:13 +01:00
Andrew Clark
1eaafc9ade Clean up timeoutMs-related implementation details (#19704)
* Disable busyDelayMs and busyMinDurationMs

Refer to explanation in previous commit.

* Remove unnecessary work loop variables

Since we no longer support SuspenseConfig options, we don't need to
track these values.

* Remove unnecessary Update fields
2020-08-27 09:47:58 -07:00
Andrew Clark
8da0da0937 Disable timeoutMs argument (#19703)
* Remove distinction between long, short transitions

We're removing the `timeoutMs` option, so there's no longer any
distinction between "short" and "long" transitions. They're all treated
the same.

This commit doesn't remove `timeoutMs` yet, only combines the internal
priority levels.

* Disable `timeoutMs` argument

tl;dr
-----

- We're removing the `timeoutMs` argument from `useTransition`.
- Transitions will either immediately switch to a skeleton/placeholder
  view (when loading new content) or wait indefinitely until the data
  resolves (when refreshing stale content).
- This commit disables the `timeoutMS` so that the API has the desired
  semantics. It doesn't yet update the types or migrate all the test
  callers. I'll do those steps in follow-up PRs.

Motivation
----------

Currently, transitions initiated by `startTransition` / `useTransition`
accept a `timeoutMs` option. You can use this to control the maximum
amount of time that a transition is allowed to delay before we give up
and show a placeholder.

What we've discovered is that, in practice, every transition falls into
one of two categories: a **load** or a **refresh**:

- **Loading a new screen**: show the next screen as soon as possible,
  even if the data hasn't finished loading. Use a skeleton/placeholder
  UI to show progress.
- **Refreshing a screen that's already visible**: keep showing the
  current screen indefinitely, for as long as it takes to load the fresh
  data, even if the current data is stale. Use a pending state (and
  maybe a busy indicator) to show progress.

In other words, transitions should either *delay indefinitely* (for a
refresh) or they should show a placeholder *instantly* (for a load).
There's not much use for transitions that are delayed for a
small-but-noticeable amount of time.

So, the plan is to remove the `timeoutMs` option. Instead, we'll assign
an effective timeout of `0` for loads, and `Infinity` for refreshes.

The mechanism for distinguishing a load from a refresh already exists in
the current model. If a component suspends, and the nearest Suspense
boundary hasn't already mounted, we treat that as a load, because
there's nothing on the screen. However, if the nearest boundary is
mounted, we treat that as a refresh, since it's already showing content.

If you need to fix a transition to be treated as a load instead of a
refresh, or vice versa, the solution will involve rearranging the
location of your Suspense boundaries. It may also involve adding a key.

We're still working on proper documentation for these patterns. In the
meantime, please reach out to us if you run into problems that you're
unsure how to fix.

We will remove `timeoutMs` from `useDeferredValue`, too, and apply the
same load versus refresh semantics to the update that spawns the
deferred value.

Note that there are other types of delays that are not related to
transitions; for example, we will still throttle the appearance of
nested placeholders (we refer to this as the placeholder "train model"),
and we may still apply a Just Noticeable Difference heuristic (JND) in
some cases. These aren't going anywhere. (Well, the JND heuristic might
but for different reasons than those discussed above.)
2020-08-26 14:35:13 -07:00
Ben Pernick
60ba723bf7 Add SuspenseList to devTools (#19684)
* ensure getDisplayName is only called on functions

* add SuspenseList to Dev tools element names

* Add SuspenseList and pass tests

* Import SuspenseList directly

* run prettier

* Refactor tests to use real components

* run linter
2020-08-26 18:04:43 +01:00
Ricky
5564f2c95b Add React.startTransition (#19696)
* Add React.startTransition

* Export startTransition from index.js as well
2020-08-26 11:34:17 -04:00
inottn
c4e0768d74 Remove unused argument from finishConcurrentRender (#19689) 2020-08-25 13:49:57 +01:00
Andrew Clark
af219cc6e6 Lint rule to forbid access of cross-fork fields (#19679)
* Lint rule to forbid access of cross-fork fields

We use a shared Fiber type for both reconciler forks (old and new). It
is a superset of all the fields used by both forks. However, there are
some fields that should only be used in the new fork, and others that
should only be used in the old fork.

Ideally we would enforce this with separate Flow types for each fork.
The problem is that the Fiber type is accessed by some packages outside
the reconciler (like React DOM), and get passed into the reconciler as
arguments. So there's no way to fork the Fiber type without also forking
the packages where they are used. FiberRoot has the same issue.

Instead, I've added a lint rule that forbids cross-fork access of
fork-specific fields. Fields that end in `_old` or `_new` are forbidden
from being used inside the new or old fork respectively. Or you can
specific custom fields using the ESLint plugin options.

I used this plugin to find and remove references to the effect list
in d2e914a.

* Mark effect list fields as old

And `subtreeTag` as new.

I didn't mark `lastEffect` because that name is also used by the
Hook type. Not super important; could rename to `lastEffect_old` but
idk if it's worth the effort.
2020-08-24 10:07:11 -07:00
Dan Abramov
848bb2426e Attach Listeners Eagerly to Roots and Portal Containers (#19659)
* Failing test for #19608

* Attach Listeners Eagerly to Roots and Portal Containers

* Forbid createEventHandle with custom events

We can't support this without adding more complexity. It's not clear that this is even desirable, as none of our existing use cases need custom events. This API primarily exists as a deprecation strategy for Flare, so I don't think it is important to expand its support beyond what Flare replacement code currently needs. We can later revisit it with a better understanding of the eager/lazy tradeoff but for now let's remove the inconsistency.

* Reduce risk by changing condition only under the flag

Co-authored-by: koba04 <koba0004@gmail.com>
2020-08-24 16:50:20 +01:00
Dominic Gannaway
8c9fc4e90f Remove usage of PossiblyWeakSet from createEventHandle (#19686) 2020-08-24 16:10:23 +01:00
Toru Kobayashi
2ada4bd0c2 Add a test for non-passive event handlers for events affected by the browsers' intervention (#19658) 2020-08-24 14:30:17 +01:00
Andrew Clark
d2e914ab4e Remove remaining references to effect list (#19673)
* Remove `firstEffect` null check

This is the last remaining place where the effect list has semantic
implications.

I've replaced it with a check of `effectTag` and `subtreeTag`, to see
if there are any effects in the whole tree. This matches the semantics
of the old check. However, I think only reason this optimization exists
is because it affects profiling. We should reconsider whether this
is necessary.

* Remove remaining references to effect list

We no longer use the effect list anywhere in our implementation. It's
been replaced by a recursive traversal in the commit phase.

This removes all references to the effect list in the new fork.
2020-08-21 20:42:32 -05:00
Brian Vaughn
0386bd0da2 Tweaked landing page styles (#19665)
* Tweaked landing page styles

* Update GitHub link

Co-authored-by: E-Liang Tan <eliang@eliangtan.com>
2020-08-21 14:06:01 -04:00
Dan Abramov
90d212d326 Fix movementX/Y polyfill with capture events (#19672)
* Fix movementX/Y polyfill with capture events

* Remove unnecesary call for better inlining
2020-08-21 16:55:41 +01:00
6h057
49af88991c Fix DevTools crash when inspecting document.all (#19619)
* Add html_all_collection type to correct typeof document.all

* process HTMLAllCollection like HTMLElement + fix flow issue

* fix lint

* move flow fix comment

* Make it work with iframes too

* optimize how we get html_all_collection type

* use once Object.prototype.toString.call
2020-08-21 14:31:16 +01:00
Sebastian Markbåge
d6e433899f Use Global Render Timeout for CPU Suspense (#19643)
* Use Retry lane for resuming CPU suspended work

* Use a global render timeout for CPU suspense heuristics

* Fix profiler test since we're now reading time more often

* Sync to new reconciler

* Test synchronously rerendering should not render more rows
2020-08-20 14:39:29 -07:00
Hemakshi Sachdev
f912186012 Fix: Unspecified error for IE11 (#19530) (#19664) 2020-08-20 21:53:23 +01:00
Brian Vaughn
d5ed78764f Visually distinguish user timing marks from React events (#19663) 2020-08-20 14:43:40 -04:00
E-Liang Tan
2bea3fb0b8 Import React Concurrent Mode Profiler (#19634)
Co-authored-by: Brian Vaughn <bvaughn@fb.com>
Co-authored-by: Kartik Choudhary <kartikc.918@gmail.com>
2020-08-20 14:06:28 -04:00
E-Liang Tan
c641b611c4 Upgrade all @babel/* packages to fix DevTools builds on newer Node versions (#19647) 2020-08-20 11:47:16 -04:00
Dan Abramov
08e69f65b4 Fix incorrect copy-paste in test (#19657) 2020-08-20 01:47:32 +01:00
Dan Abramov
64ddef44c6 Revert "Remove onScroll bubbling flag (#19535)" (#19655)
This reverts commit e9721e14e4.
2020-08-19 20:54:54 +01:00
Dan Abramov
dd651df05e Keep onTouchStart, onTouchMove, and onWheel passive (#19654)
* Keep onTouchStart, onTouchMove, and onWheel passive

* Put it behind a feature flag on WWW
2020-08-19 18:42:33 +01:00
Sebastian Silbermann
87b3e2d257 Add flow to SyntheticEvent (#19564)
* Add flow to SyntheticEvent

* Minimal implementation of known and unknown synthetic events

* less casting

* Update EnterLeaveEventPlugin.js

Co-authored-by: Dan Abramov <dan.abramov@gmail.com>
2020-08-19 14:16:48 +01:00
Julien Gilli
b8fa09e9e2 provide profiling bundle for react-reconciler (#19559) 2020-08-19 14:11:27 +01:00
Toru Kobayashi
32ca313060 refactor: remove unnecessary return statements (#19625) 2020-08-19 14:10:41 +01:00
Sam Marks
c45a195429 fix: property list values should show whitespace (#19640) 2020-08-19 08:50:46 -04:00
Brian Vaughn
23595ff593 Add missing param to safelyCallDestroy() (#19638) 2020-08-18 12:02:04 -04:00
ᴜɴвʏтᴇ
24f1923b1b fix: open two same tabs on firefox (#19632)
close #19629
2020-08-18 10:17:00 -04:00
Luna Ruan
ee409ea3b5 change destroy to safelyCallDestroy (#19605)
We use safelyCallDestroy for commitUnmount and passive effects unmounts but we call destroy directly in commitHookEffectListUnmount (AKA layout effects unmounts because we don't use this anywhere else). This PR changes the direct destroy call to safelyCallDestroy for consistency
2020-08-17 17:32:50 -07:00
Brian Vaughn
bcca5a6ca7 Always skip unmounted/unmounting error boundaries (#19627)
The behavior of error boundaries for passive effects that throw during cleanup was recently changed so that React ignores boundaries which are also unmounting in favor of still-mounted boundaries. This commit implements that same behavior for layout effects (useLayoutEffect, componentWillUnmount, and ref-detachment).

The new, skip-unmounting-boundaries behavior is behind a feature flag (`skipUnmountedBoundaries`).
2020-08-17 15:01:06 -04:00
Timothy Yung
1a41a196bc Append text string to <Text> error message (#19581)
* Append text string to <Text> error message

* Truncate text in <Text> error message

* Regenerate `codes.json`
2020-08-17 10:47:49 -07:00
Jack Works
1287670191 Fix: React cannot render in ShadowRoot (#15894)
* fix: render in shadow root

* fix: flow typing

* Remove types and turn invariant into warning

Co-authored-by: Dan Abramov <dan.abramov@me.com>
2020-08-17 15:47:49 +01:00
Dan Abramov
e4afb2fddf eslint-plugin-react-hooks@4.1.0 2020-08-17 13:31:20 +01:00
Dan Abramov
ced05c46c1 Update CHANGELOG.md 2020-08-17 13:30:16 +01:00
CY Lim
702fad4b1b refactor fb.me redirect link to reactjs.org/link (#19598)
* refactor fb.me url to reactjs.org/link

* Update ESLintRuleExhaustiveDeps-test.js

* Update ReactDOMServerIntegrationUntrustedURL-test.internal.js

* Update createReactClassIntegration-test.js

* Update ReactDOMServerIntegrationUntrustedURL-test.internal.js

Co-authored-by: Dan Abramov <dan.abramov@gmail.com>
2020-08-17 13:25:50 +01:00
Toru Kobayashi
49cd77d24a fix: leak strict mode with UMD builds (#19614) 2020-08-15 14:42:49 +01:00
Brian Vaughn
ffb749c95e Improve error boundary handling for unmounted subtrees (#19542)
A passive effect's cleanup function may throw after an unmount. Prior to this commit, such an error would be ignored. (React would not notify any error boundaries.) After this commit, React's behavior varies depending on which reconciler fork is being used.

For the old reconciler, React will call componentDidCatch for the nearest unmounted error boundary (if there is one). If there are no unmounted error boundaries, React will still swallow the error because the return pointer has been disconnected, so the normal error handling logic does not know how to traverse the tree to find the nearest still-mounted ancestor.

For the new reconciler, React will skip any unmounted boundaries and look for a still-mounted boundary. If one is found, it will call getDerivedStateFromError and/or componentDidCatch (depending on the type of boundary).

Tests have been added for both reconciler variants for now.
2020-08-14 16:46:46 -04:00
Brian Vaughn
9b35dd2fcc Permanently removed component stacks from scheduling profiler data (#19615)
These stacks improve the profiler data but they're expensive to generate and generating them can also cause runtime errors in larger applications (although an exact repro has been hard to nail down). Removing them for now. We can revisit adding them after this profiler has been integrated into the DevTools extension and we can generate them lazily.
2020-08-14 15:21:13 -04:00
Andrew Clark
3f8115cdd1 Remove didTimeout check from work loop
No longer need this, since we have starvation protection in userspace.

This will also allow us to remove the concept from the Scheduler
package, which is nice because `postTask` doesn't currently support it.
2020-08-14 10:45:24 -04:00
Andrew Clark
9abc2785cb Remove wasteful checks from shouldYield
`shouldYield` will currently return `true` if there's a higher priority
task in the Scheduler queue.

Since we yield every 5ms anyway, this doesn't really have any practical
benefit. On the contrary, the extra checks on every `shouldYield` call
are wasteful.
2020-08-14 10:45:11 -04:00
Clay Tercek
fe6d05229f fix event.relatedTarget fallback logic for firefox (#19607)
* fix event.relatedTarget fallback logic for firefox

* check if relatedTarget is undefined for fallback
2020-08-14 13:05:53 +01:00
Jordan Eldredge
1d5e10f703 [eslint-plugin-react-hooks] Report constant constructions (#19590)
* [eslint-plugin-react-cooks] Report constant constructions

The dependency array passed to a React hook can be thought of as a list of cache keys. On each render, if any dependency is not `===` its previous value, the hook will be rerun. Constructing a new object/array/function/etc directly within your render function means that the value will be referentially unique on each render. If you then use that value as a hook dependency, that hook will get a "cache miss" on every render, making the dependency array useless.

This can be especially dangerous since it can cascade. If a hook such as `useMemo` is rerun on each render, not only are we bypassing the option to avoid potentially expensive work, but the value _returned_ by `useMemo` may end up being referentially unique on each render causing other downstream hooks or memoized components to become deoptimized.

* Fix/remove existing tests

* Don't give an autofix of wrapping object declarations

It may not be safe to just wrap the declaration of an object, since the object may get mutated.

Only offer this autofix for functions which are unlikely to get mutated.

Also, update the message to clarify that the entire construction of the value should get wrapped.

* Handle the long tail of nodes that will be referentially unique

* Catch let/var constant constructions on initial assignment

* Trim trailing whitespace

* Address feedback from @gaearon

* Rename "assignment" to "initialization"

* Add test for a constant construction used in multiple dependency arrays
2020-08-13 20:54:33 +01:00
Sebastian Markbåge
dab0854c5e Move commit passive unmount/mount to CommitWork (#19599) 2020-08-13 09:17:33 -07:00
Brian Vaughn
c3ee973c56 Fix emoji character displayed in Chrome extension (#19603) 2020-08-13 11:16:35 -04:00
inottn
ccb6c39451 Remove unused argument (#19600) 2020-08-13 15:11:01 +01:00
Andrew Clark
629125555f [Scheduler] Re-throw unhandled errors (#19595)
Because `postTask` returns a promise, errors inside a `postTask`
callback result in the promise being rejected.

If we don't catch those errors, then the browser will report an
"Unhandled promise rejection" error. This is a confusing message to see
in the console, because the fact that `postTask` is a promise-based API
is an implementation detail from the perspective of the developer.
"Promise rejection" is a red herring.

On the other hand, if we do catch those errors, then we need to report
the error to the user in some other way.

What we really want is the default error reporting behavior that a
normal, non-Promise browser event gets.

So, we'll re-throw inside `setTimeout`.
2020-08-12 20:06:43 -07:00
Pascal Fong Kye
b6e1d08604 DevTools bug fix: Proxied methods should be safely dehydrated for display 2020-08-12 12:15:53 -04:00
Andrew Clark
b8ed6a1aa5 [Scheduler] Call postTask directly (#19551)
This updates the experimental Scheduler postTask build to call postTask
directly, instead of managing our own custom queue and work loop.

We still use a deadline 5ms mechanism to implement `shouldYield`.

The main thing that postTask is currently missing is the continuation
feature — when yielding to the main thread, the yielding task is sent
to the back of the queue, instead of maintaining its position.

While this would be nice to have, even without it, postTask may be good
enough to replace our userspace implementation.

We'll run some tests to see.
2020-08-12 08:39:47 -05:00
Ricky
c8d9b8878a Speed up yarn cache in circle (#19566) 2020-08-11 14:05:15 -04:00
Dan Abramov
ce37bfad5f Remove resolutions from test renderer package.json (#19577) 2020-08-10 20:45:12 +01:00
Kartik Choudhary
2704bb5374 Add ReactVersion to SchedulingProfiler render scheduled marks (#19553)
* Add ReactVersion to SchedulingProfiler render scheduled marks

* Move ReactVersion to a new --react-init-* mark

Co-authored-by: E-Liang Tan <eliang@eliangtan.com>
2020-08-10 10:51:25 -04:00
Brian Vaughn
0c52e24cb6 Support inner component _debugOwner in memo (#19556)
* Support inner component _debugOwner in memo

* test with devtool context

* remove memo test

* Merged master; tweaked test and snapshot

* Pass owner to createFiber fn when creating a memo component.

Co-authored-by: Theodore Han <tqhan317@gmail.com>
2020-08-10 10:49:10 -04:00
Dan Abramov
94c0244bab Fix double-firing mouseenter (#19571)
* test: Simulate mouseover in browser

* Fix duplicate onMouseEnter event when relatedTarget is a root

* Test leave as well

Co-authored-by: Sebastian Silbermann <silbermann.sebastian@gmail.com>
2020-08-10 15:08:22 +01:00
Dan Abramov
aa99b0b08e Rename test files 2020-08-10 12:58:42 +01:00
Sebastian Silbermann
7f696bd99c fix: onFocus/onBlur/onBeforeInput have a matching event type (#19561)
* test: Add current behavior for event types of onFocus/onBlur

* fix: onFocus/onBlur have a matching event type

* fix useFocus

* fix: don't compare native event types with react event types

* Add FocusIn/FocusOutEventInterface

* A simpler alternative fix

* Add regression tests

* Always pass React event type and fix beforeinput

Co-authored-by: Dan Abramov <dan.abramov@me.com>
2020-08-10 12:54:10 +01:00
Sebastian Silbermann
7c30fb3b0b Update outdated lockfile (#19568) 2020-08-10 11:59:37 +01:00
Andrew Clark
0cd9a6de55 Parallelize Jest in CI (#19552)
Uses CircleCI's `parallelism` key to split our test jobs across multiple
processes, like we do for the build job.
2020-08-07 16:32:59 -04:00
Dan Abramov
2d9ec9199c Indent a command 2020-08-07 19:24:49 +01:00
Dan Abramov
db2f229110 Fix command 2020-08-07 19:23:43 +01:00
Dan Abramov
336729856a Nesting Fixture (#19531)
* Nesting Fixture

* Add README to nesting fixture

* Apply suggestions from code review

Co-authored-by: Ricky <rickhanlonii@gmail.com>

* Fixes

* Add Redux

* Use different versions

* Use Consumer API

* Rename helper

* Write docs

* Update README.md

* Update README.md

Co-authored-by: Rick Hanlon <rickhanlonii@gmail.com>
2020-08-07 02:08:41 +01:00
Brian Vaughn
a63893ff32 Warn about undefined return value for memo and forwardRef (#19550) 2020-08-06 16:12:32 -04:00
Ricky
32ff428687 Add feature flag for setting update lane priority (#19401)
* Add feature flag for setting update lane priority

* Remove second feature flag

* Refactor feature flag locations

* Add missing else
2020-08-06 12:47:32 -04:00
Gustavo Saiani
5bdd4c8c60 Remove unused argument from call to jest method (#19546) 2020-08-06 16:55:01 +01:00
Mateusz Burzyński
a5fed98a96 Register more node types that are used later as JSXIdentifiers (#19514) 2020-08-06 16:37:32 +01:00
DaniAcu
50893dbcb7 fix(react-dom): unnecesary path on DOMEventProperties (#19544) 2020-08-06 16:37:06 +01:00
Dominic Gannaway
f77c7b9d76 Re-add discrete flushing timeStamp heuristic (behind flag) (#19540) 2020-08-06 13:21:05 +01:00
Brian Vaughn
e67a6b1603 Fix runtime error that happens if a passive destroy function throws within an unmounted tree (#19543)
A passive effect's cleanup function may throw after an unmount. In that event, React sometimes threw an uncaught runtime error trying to access a property on a null stateNode field. This commit fixes that (and adds a regression test).
2020-08-05 18:22:18 -04:00
Emilis Baliukonis
5cff775502 [Scheduler] Get current time from performance.now in non-DOM environments (#19532)
* Get current time from performance.now in non-DOM environments

* Use local references to native APIs for Date and Performance

* Refactored to read globals directly
2020-08-05 17:29:06 +01:00
Dan Abramov
e9721e14e4 Remove onScroll bubbling flag (#19535) 2020-08-05 16:07:58 +01:00
Dominic Gannaway
b61174fb7b Remove the deprecated React Flare event system (#19520) 2020-08-05 15:13:29 +01:00
Halit Ogunc
8d57ca519a fix: typo in React Release Scripts (#19524) 2020-08-04 13:22:50 -04:00
Ricky
a437f3ff30 Use RN fork in default branch of feature flags (#19522) 2020-08-03 17:40:58 -04:00
Ricky
86314d5b45 Turn off new component stacks for React Native (#19521) 2020-08-03 14:45:50 -04:00
Andrew Clark
5f1890f12b Bugfix: Don't unmount siblings of deleted node (#19516)
* Test: Don't unmount siblings of deleted node

Adds a failing regression test. Will fix in the next commit.

* Refactor to accept deleted fiber, not child list

A deleted fiber is passed to
flushPassiveUnmountEffectsInsideOfDeletedTree, but the code is written
as if it accepts the first node of a child list. This is likely because
the function was based on similar functions like
`flushPassiveUnmountEffects`, which do accept a child list.

Unfortunately, types don't help here because we use the first node
in the list to represent the whole list, so in both cases, the type
is Fiber.

Might be worth changing the other functions to also accept individual
fibers instead of a child list, to help avoid confusion.

* Add layout effect to regression test, just in case
2020-08-03 08:57:41 -07:00
Andrew Clark
93a0c28305 Add static version of Passive subtree tag (#19510)
Creates new subtree tag, PassiveStatic, that represents whether a
tree contains any passive effect hooks.

It corresponds to the PassiveStatic effect tag, which represents the
same concept for an individual fiber.

This allows us to remove the PassiveStatic effect tag from PassiveMask.
Its presence was causing us to schedule a passive effect phase callback
on every render, instead of only when something changed. That's now
fixed; this is reflected in the SchedulerProfiler tests.

(The naming is getting really confusing. Need to do some bikeshedding.)
2020-08-01 08:15:46 -05:00
Dan Abramov
a1c0864d19 Support untagged releases (#19509) 2020-07-31 20:47:28 +01:00
Dan Abramov
5d271fc3b1 Revert "Support untagged releases (#19507)" (#19508)
This reverts commit 58b3ee7a88.
2020-07-31 19:57:32 +01:00
Dan Abramov
58b3ee7a88 Support untagged releases (#19507)
* Support untagged releases

* Fix
2020-07-31 19:18:37 +01:00
Dan Abramov
7543459a48 Allow publishing untagged releases (#19505) 2020-07-31 16:10:01 +01:00
Dan Abramov
3d0895557a Disable onScroll bubbling statically except for WWW (#19503) 2020-07-31 15:09:24 +01:00
Dan Abramov
332eceface Revert "Statically enable enableFilterEmptyStringAttributesDOM (#19502)" (#19504)
This reverts commit 815ee89bf5.
2020-07-31 15:01:27 +01:00
Dan Abramov
815ee89bf5 Statically enable enableFilterEmptyStringAttributesDOM (#19502) 2020-07-31 14:57:57 +01:00
Andrew Clark
ede9170648 Move passive logic out of layout phase (#19500)
* setCurrentFiber per fiber, instead of per effect

* Re-use safelyCallDestroy

Part of the code in flushPassiveUnmountEffects is a duplicate of the
code used for unmounting layout effects. I did some minor refactoring to
so we could use the same function in both places.

Closure will inline anyway so it doesn't affect code size or
performance, just maintainability.

* Don't check HookHasEffect during deletion

We don't need to check HookHasEffect during a deletion; all effects are
unmounted.

So we also don't have to set HookHasEffect during a deletion, either.

This allows us to remove the last remaining passive effect logic from
the synchronous layout phase.
2020-07-30 21:43:03 -07:00
Dan Abramov
22d16cc15d Remove event constants (#19276)
* Remove opaque event type

* Rename type and merge files

* Use literals where we have Flow coverage

* Flowify some plugins

* Remove constants except necessary ones
2020-07-30 21:52:37 +01:00
Andrew Clark
6ef997b534 Check for passive effects on the root fiber (#19488)
The root fiber doesn't have a parent from which we can read the
`subtreeTag`, so we need to check its `effectTag` directly.

The root fiber previously did not have any pending passive effects,
but it does now that deleted fibers are cleaned up in the passive phase.

This allows us to remove a `schedulePassiveEffectCallback` call from the
synchronous unmount path.

Co-authored-by: Brian Vaughn <bvaughn@fb.com>
2020-07-30 09:17:22 -04:00
Andrew Clark
e1f96b82b4 Check PassiveStatic instead of Passive (#19489)
Saves us from having to set a flag on `current` during the layout phase.

Could result in some redundant traversal, since PassiveStatic includes
effects that don't need clean-up. But it's worth it to remove the work
from the layout phase.

While I was editing this, I also re-arranged it so that we check the
`effectTag` check before we check the `tag`, since the `effectTag` check
is the one that's more likely to fail.
2020-07-30 09:13:04 -04:00
Dan Abramov
dff97a6915 Fix onGot/LostPointerCapture events (#19487) 2020-07-29 21:54:48 +01:00
Brian Vaughn
eae90cdbe9 Effects list refactor continued: passive effects traversal (#19374)
* Adds new `Passive` subtree tag value.
* Adds recursive traversal for passive effects (mounts and unmounts).
* Removes `pendingPassiveHookEffectsMount` and `pendingPassiveHookEffectsUnmount` arrays from work loop.
* Re-adds sibling and child pointer detaching (temporarily removed in previous PR).
* Addresses some minor TODO comments left over from previous PRs.

---

Co-authored-by: Luna Ruan <luna@fb.com>
2020-07-29 16:54:22 -04:00
Ricky
74cd7e5f17 Use feature flags for React Native in the test renderer (#19486) 2020-07-29 16:31:05 -04:00
Dan Abramov
291db05a75 Add regression tests for all events (#19485) 2020-07-29 21:13:56 +01:00
Ricky
7c8cc4358e Add postTask browser scheduler implementation (#19479)
* Reduce code to necessities

* Switch to postTask API

* Add SchedulerPostTask tests

* Updates from review

* Fix typo from review

* Generate build of unstable_post_task
2020-07-29 15:27:59 -04:00
Dan Abramov
0eea16601c Event propagation test suite (#19483) 2020-07-29 15:34:57 +01:00
Brian Vaughn
5227a37868 Add "unstable_" prefix to experimental mutable source APIs (#19472)
* Add "unstbale_" prefix to mutable source APIs

* DebugHooks no longer calls useMutableSource() on init

This was causing an observable behavioral difference between experimental DEV and PROD builds.

We don't initialize stack position for other composite hooks (e.g. useDeferredValue, useTransition, useOpaqueIdentifier). If we did, it would cause the same obesrvable behavioral difference.
2020-07-28 12:38:13 -04:00
Ricky
52c5146274 Add SchedulerHostConfig fork for post task (#19470) 2020-07-28 11:11:31 -04:00
Andrew Clark
722bc046dc Don't rely on didTimeout for SyncBatched (#19469)
Tasks with SyncBatchedPriority — used by Blocking Mode — should always
be rendered by the `peformSyncWorkOnRoot` path, not
`performConcurrentWorkOnRoot`.

Currently, they go through the `performConcurrentWorkOnRoot` callback.
Then, we check `didTimeout` to see if the task expired. Since
SyncBatchedPriority translates to ImmediatePriority in the Scheduler,
`didTimeout` is always `true`, so we mark it as expired. Then it exits
and re-enters in the `performSyncWorkOnRoot` path.

Aside from being overly convoluted, we shouldn't rely on Scheduler to
tell us that SyncBatchedPriority work is synchronous. We should handle
that ourselves.

This will allow us to remove the `didTimeout` check. And it further
decouples us from the Scheduler priority, so we can eventually remove
that, too.
2020-07-27 14:42:44 -07:00
Sebastian Silbermann
feb134c30d feat(react-dom): Add enterKeyHint (#18634) 2020-07-27 21:07:08 +01:00
Andrew Clark
96ac799eac Remove callbackId field from FiberRoot (#19458)
The old expiration times implementation used this field to infer when
the priority of a task had changed at a more granular level than a
Scheduler priority level.

Now that we have the LanePriority type, which is React-specific, we no
longer need the `callbackId` field.
2020-07-27 10:39:07 -07:00
Andrew Clark
c24b641b76 Remove timeout option from scheduleCallback (#19457)
Since the Lanes refactor landed, we no longer rely on this anywhere, so
we can remove it.

The `delay` option is still needed by our timer implementation
(setTimeout polyfill). We'll keep the feature, but we'll likely change
how it's exposed once we figure out the proper layering between the
various Scheduler APIs.
2020-07-27 09:56:25 -07:00
Dominic Gannaway
144297165b Bail-out of attaching non-delegated listeners (#19466)
* Bail-out of attaching non-delegated listeners

Revise comment

* Fix tests/add tests

* Add onInvalid test
2020-07-27 17:47:14 +01:00
Dan Abramov
06d104e8ec Don't emulate bubbling of the scroll event (#19464)
* Don't emulate bubbling of the scroll event

* Put behind a flag
2020-07-27 17:33:54 +01:00
Dominic Gannaway
217ecf581b Re-added toggle event to non-delegated events (#19465) 2020-07-27 16:58:38 +01:00
Dominic Gannaway
6bb86fd162 Delegated all capture events (#19463) 2020-07-27 15:36:43 +01:00
Dominic Gannaway
05344faca4 Follow up fix to 19452 (#19454) 2020-07-27 15:03:11 +01:00
Ricky
d29bf59a6e Update my mailmap entries (#19455) 2020-07-26 22:47:32 -04:00
Ashwin Ramaswami
5530f1ccfb Upgrade art fixtures to babel 7 (#16235)
* chore: upgrade art fixtures to babel 7

* upgrade

* use yarn
2020-07-25 23:43:49 -04:00
Dominic Gannaway
242a50a652 Fix issue with capture phase non-bubbling events (#19452) 2020-07-25 12:32:21 +01:00
Dominic Gannaway
ef22aecfc5 Add invalid/close events to <dialog> element (#19439)
Support dialog

Fix
2020-07-24 20:36:46 +01:00
Robert Ferentz
b55f75d0a5 fix issue #19362 + test (#19412) 2020-07-24 14:34:16 -04:00
Sebastian Markbåge
d93c8faada Move Persistent Mode Optimization away from firstEffect (#19381)
Persistent mode needs to clone a parent and add its children if a child has
changed.

We have an optimization in persistent mode where we don't do that if no
child could've changed. If there are no effects scheduled for any child
then there couldn't have been changes.

Instead of checking for this on firstEffect, we now check this on the
children's effectTag and subtreeTags.

This is quite unfortunate because if we could just do this check a little
bit later we would've already gotten it transferred to the completed work's
subtreeTag. Now we have to loop over all the children and if any of them
changed, we have to loop over them again. Doing at least two loops per
parent.
2020-07-24 09:31:30 -07:00
Ricky
909b612e27 Sync React Native types (#19437) 2020-07-22 22:56:05 -04:00
Dan Abramov
76ce685d0f Remove SyntheticEvent subtypes (#19436)
* Remove SyntheticEvent subtypes

* Code golf
2020-07-23 01:02:59 +01:00
Dominic Gannaway
30e3cfe406 Fix scope issue (#19434) 2020-07-22 23:05:50 +01:00
Dan Abramov
125d1a19a2 Move event things around (#19433)
* Put all synthetic events in one file

* Inline other helpers

* Remove Modern from filenames
2020-07-22 22:12:15 +01:00
Dominic Gannaway
1aae05c436 Revise comment + add non-bubbling event test (#19432) 2020-07-22 21:41:40 +01:00
Dominic Gannaway
356c17108f Remove capturePhaseEvents and separate events by bubbling (#19278)
* Remove capturePhaseEvents and separate events by bubbling

WIP

Refine all logic

Revise types

Fix

Fix conflicts

Fix flags

Fix

Fix

Fix test

Revise

Cleanup

Refine

Deal with replaying

Fix

* Add non delegated listeners unconditionally

* Add media events

* Fix a previously ignored test

* Address feedback

Co-authored-by: Dan Abramov <dan.abramov@me.com>
2020-07-21 22:40:50 +01:00
Dan Abramov
1dcee86565 Regression test for media event bubbling (#19428) 2020-07-21 22:26:09 +01:00
Ricky
c9749d38e3 Generate RN renderers for stable builds (#19421)
* Generate RN renderers for experimental builds

* Don't generate FB builds for experimental channels
2020-07-20 17:15:06 -04:00
Sebastian Markbåge
ab1f517000 isFBBundle should be true if it's FB for www or FB for RN (#19420)
This ensures that the .fb.js override files kick in for RN. Otherwise we
won't have FB specific exports in the isomorphic modules.
2020-07-20 10:37:04 -07:00
Haseeb Khan
ecbdb74d7c Added the word "events" to clear ambiguousness. (#19409) 2020-07-20 18:26:41 +01:00
Andrew Clark
b23ea02be5 Track event times per lane on the root (#19387)
* Pass event time to markRootUpdated

Some minor rearranging so that eventTime gets threaded through. No
change in behavior.

* Track event times per lane on the root

Previous strategy was to store the event time on the update object
and accumulate the most recent one during the render phase.

Among other advantages, by tracking them on the root, we can read the
event time before the render phase has finished.

I haven't removed the `eventTime` field from the update object yet,
because it's still used to compute the timeout. Tracking the timeout
on the root is my next step.
2020-07-17 10:47:39 -07:00
Ricky
faa697f4f9 Set current update lane priority for user blocking events (#19342)
* Set current update lane priority for user blocking events

* Update to use LanePriority and not use runWithPriority

* Remove unused imports

* Fix tests, and I missed ReactDOMEventListener

* Fix more tests

* Add try/finally and hardcode lane priorities instead

* Also hard code InputContinuousLanePriority in tests

* Remove un-needed exports

* Comment rollbacks
2020-07-17 12:58:44 -04:00
Dominic Gannaway
4c8c98ab9b Sync latest useFocus/useFocusWithin changes (#19397) 2020-07-17 16:26:40 +01:00
Brian Vaughn
51267c4ac9 Sync scheduling profiler marks and debug tracing to new reconciler fork (#19375, #19376, #19396)
* Make enableSchedulingProfiler flag static

* Copied debug tracing and scheduler profiling to .new fork and updated feature flags

* Move profiler component stacks behind a feature flag
2020-07-17 11:24:26 -04:00
Dan Abramov
aec934af7f Remove form event delegation flag (#19395) 2020-07-17 14:19:39 +01:00
Dominic Gannaway
a59f899a1d Modern Event System: use focusin/focusout for onFocus/onBlur (#19186) 2020-07-16 18:12:03 +01:00
Dominic Gannaway
9102719baa Tidy up React Scope API (#19352) 2020-07-16 16:21:21 +01:00
Ricky
bc4cd92cd5 Use jest-environment-jsdom-sixteen (#19288)
* Use jest-environment-jsdom-sixteen

* Update yarn.lock

* Dedupe new jest packages in yarn.lock

* Pull upstream changes
2020-07-16 10:17:31 -04:00
Dominic Gannaway
e387c98ffa Fix bug with enableLegacyFBSupport click handlers (#19378) 2020-07-16 14:56:31 +01:00
Brian Vaughn
a226b9b445 Effects list refactor continued: did-bailout flag (#19322)
* Effects list rewrite

* Improved deletions approach

Process deletions as we traverse the tree during commit, before we process other effects. This has the result of better mimicking the previous sequencing.

* Made deletions field nullable

* Revert (no longer necessary) change to ReactNative test

* Eagerly set Deletions effect on Fiber when adding child to deletions array

* Initialize deletions array to null

* Null out deletions array instead of splicing 🤡

* Removed TODO comment

* Initial exploration on a did-bailout flag

* fixed the rest of the bugs

* Rolled temporary didBailout attribute into subtreeTag

* addressed comments

* Removed DidBailout subtree tag

* Removed stale comment

* use while loop instead of recursion for siblings

* move bailout flag from while loop

* Removed some unnecessary Deletion effectTags from children

* Move Deletion effect assignment to deletions array initialization

Co-authored-by: Luna <lunaris.ruan@gmail.com>
2020-07-16 09:10:00 -04:00
Brian Vaughn
fed4ae0247 DevTools 4.8.1 -> 4.8.2 (and CHANGELOG) 2020-07-15 12:37:08 -04:00
Brian Vaughn
a89854bc93 Fix Suspense-wrapping heuristic (and bump version numbers) (#19373)
* Fixed suspense wrapping heuristic

* Bump package numbers 16.13.1 -> 17.0.0-alpha.0 to fix DevTools Suspense heuristic
2020-07-15 12:25:27 -04:00
Dan Abramov
4961833dbf Don't build shallow renderer UMD bundles 2020-07-15 16:53:02 +01:00
Brian Vaughn
a9ba5283d9 Disable DevTools minification (#19369)
DevTools isn't being downloaded like typical JavaScript, so bundle size concerns don't apply. Parsing is still a consideration (so I'm open for discussion here) but I think this change would provide a couple of benefits:
* People are more likely to *actually read* non-minified source code when e.g. a breakpoint is hit (as with the recent debugger statement)
* Component stacks will be easier to parse on bug reports
2020-07-15 10:38:30 -04:00
Dominic Gannaway
45eef8b6b5 Devtools: improve getID guard (#19364) 2020-07-15 14:17:48 +01:00
Dominic Gannaway
392277f0ab Revert "Scheduling profiler updates (#19334)" (#19366)
This reverts commit 6d7555b014.
2020-07-15 12:36:40 +01:00
Dominic Gannaway
c604b69973 Revert "Revert "Fix createEventHandle bug with comment containers (#19348)" (#19354)" (#19365)
This reverts commit 566f613763.
2020-07-15 12:35:46 +01:00
Dominic Gannaway
566f613763 Revert "Fix createEventHandle bug with comment containers (#19348)" (#19354)
This reverts commit 147179ae82.
2020-07-15 12:27:22 +01:00
Dominic Gannaway
147179ae82 Fix createEventHandle bug with comment containers (#19348) 2020-07-14 13:09:39 +01:00
Brian Vaughn
6d7555b014 Scheduling profiler updates (#19334)
* Make enableSchedulingProfiler static for profiling+experimental builds

* Copied debug tracing and scheduler profiling to .new fork

* Updated test @gate conditions
2020-07-13 22:20:53 -04:00
Bogdan Ponomarenko
9ea0f6752d fix mistake in React devtools (#19336)
Co-authored-by: Пономаренко Богдан <b.ponomarenko@tinkoff.ru>
2020-07-13 16:49:52 -04:00
Brian Vaughn
fbc6386369 Fix DevTools handling of empty Suspense tag for legacy renderer versions (#19337) 2020-07-13 16:21:56 -04:00
Andrew Clark
d1f2143aa6 Use RetryLanes instead of event time (follow up) (#19335)
Same logic as #19307. Uses RetryLanes instead of event time to
determine if a render includes new updates.
2020-07-13 10:37:33 -07:00
Dan Abramov
fe19b4247b eslint-plugin-react-hooks@4.0.8 2020-07-13 17:58:49 +01:00
Bianca Del Carretto
84479046f7 reference not add to dependencies if only its type is used as typeof arg (#19316)
* reference not add to dependencies if only its type is used as typeof arg

* Add a few more tests
2020-07-13 17:57:00 +01:00
Dan Abramov
26472c8897 Bubble onSubmit/onReset behind a feature flag (#19333) 2020-07-13 17:17:28 +01:00
Sebastian Silbermann
e2d73e91cc chore: Build react-dom/test-utils in codesandbox deploy (#19321) 2020-07-13 16:15:37 +01:00
Dominic Gannaway
61dd00db24 Extract some of the tidy up changes from 19278 (#19315) 2020-07-10 22:33:42 +01:00
Dan Abramov
a2b4db05bc eslint-plugin-react-hooks@4.0.7 2020-07-10 19:08:05 +01:00
Dan Abramov
47915fd6e1 [ESLint] Fix a bug causing a too coarse dependency suggestion (#19313)
* Add regression test for ESLint rule

* Fix the issue
2020-07-10 19:02:08 +01:00
Brian Vaughn
d5d659062d Updated DevTools test snapshots 2020-07-10 13:06:50 -04:00
Dominic Gannaway
2562e758ea Revise useFocus/useFocusWithin (#19310) 2020-07-10 17:23:00 +01:00
Nick Reiley
17efbf7d63 [DevTools] Show HOC names in profiler (#19283)
* show hoc names in profiler

* Added hocDisplayNames.length check

Co-authored-by: Brian Vaughn <brian.david.vaughn@gmail.com>
2020-07-10 11:21:19 -04:00
Andrew Clark
970fa122d8 Use lanes to check if a render is a Suspense retry (#19307)
Now that Suspense retries have their own dedicated set of lanes
(#19287), we can determine if a render includes only retries by checking
if its lanes are a subset of the retry lanes.

Previously we inferred this by checking
`workInProgressRootLatestProcessedEventTime`. If it's not set, that
implies that no updates were processed in the current render, which
implies it must be a Suspense retry. The eventual plan is to get rid of
`workInProgressRootLatestProcessedEventTime` and instead track event
times on the root; this change is one the steps toward that goal.

The relevant tests were originally added in #15769.
2020-07-10 08:58:05 -05:00
Dan Abramov
2663a12eb3 Tweak wording 2020-07-10 14:56:28 +01:00
Dan Abramov
d4eadea6c7 React DevTools 4.8.1 2020-07-10 14:11:55 +01:00
Dan Abramov
8eaf05e0e8 DevTools: Make break-on-warn off by default (#19309) 2020-07-10 14:11:32 +01:00
Andrew Clark
14084be286 Refactor algorithm for next Lanes to work on (#19302)
Some clean up to make the Lanes type easier to maintain.

I removed the "start" and "end" range markers; they don't provide any
information that isn't already encoded in the bitmask for each range,
and there's no computation saved compared to the
`pickArbitraryLane` function.

The overall algorithm is largely the same but I did tweak some of the
details. For example, if the lanes for a given priority are already
being worked on, the previous algorithm would assign to the next
available lane, including the dedicated hydration lanes that exist
in between each priority.

The updated algorithm skips over the hydration lanes and goes to the
next priority level. In the rare instance when all the non-Idle update
lanes are occupied, it will pick an abitrary default lane. This will
have the effect of invalidating the current work-in-progress, and
indicates a starvation scenario.

Eventually, if there are too many interruptions, the expiration time
mechanism will kick in and force the update to synchronously finish.
2020-07-09 18:53:54 -05:00
Brian Vaughn
08b8e6e1dc DevTools 4.7.0 -> 4.8.0 (#19297) 2020-07-09 10:49:44 -04:00
Brian Vaughn
e760d1fb0f Fixed test script for DevTools build config (#19295) 2020-07-09 10:49:33 -04:00
Gianmarco
a5b4492950 Updates Electron version for react-devtools (#19280) 2020-07-09 10:13:26 -04:00
Rimil Dey
6508ab3be8 Fix typo in Overview doc for react-devtools (#19289) 2020-07-09 09:13:15 -04:00
Andrew Clark
965d08cfff Add dedicated LanePriority for Suspense retries (#19287)
A "retry" is a special type of update that attempts to flip a Suspense
boundary from its placeholder state back to its primary/resolved state.

Currently, retries are given default priority, using the same algorithm
as normal updates and occupying range of lanes.

This adds a new range of lanes dedicated specifically to retries, and
gives them lower priority than normal updates.

A couple of existing tests were affected because retries are no longer
batched with normal updates; they commit in separate batches.

Not totally satisfied with this design, but I think things will snap more
into place once the rest of the Lanes changes (like how we handle
parallel Suspense transitions) have settled.
2020-07-08 21:09:22 -07:00
Dominic Gannaway
766af5968a Move Scope API ref resolution to mutation phase (#19264)
* Move Scope API ref resolution to mutation phase
2020-07-08 23:41:39 +01:00
Dan Abramov
c7805b8d57 Use a custom jsdom fork (#19284) 2020-07-08 21:26:54 +01:00
Dan Abramov
e0e6b9c036 Add regression test for #19269 (#19282) 2020-07-08 20:48:43 +01:00
Behnam Mohammadi
77e872217c Improve readability of isValidElementType (#19251)
* improve readability

* replace condition by switch/case

* replace condition by switch/case

* remove unnecessary braces

* replace switch/case to ifs

* replace switch/case to ifs

* fix by multiline if statements

* fix multiple if statements
2020-07-08 19:25:24 +01:00
Dan Abramov
7b0ef42bcc Update README.md 2020-07-08 18:30:18 +01:00
Giovanni Fumagalli
d87220f217 Add console group methods to dev disabled groups (#19069)
Co-authored-by: Dan Abramov <dan.abramov@gmail.com>
2020-07-08 17:28:49 +01:00
Dominic Gannaway
f5ea39c182 Modern Event System: make on*Capture events use capture phase (#19221) 2020-07-08 17:10:06 +01:00
falguniraina
e18fb91852 Text improvement (#19167)
text improvement in README.md
2020-07-08 17:07:27 +01:00
E-Liang Tan
40cddfeeb1 Add user timing marks for scheduling profiler tool (#19223)
High level breakdown of this commit:

* Add a enableSchedulingProfiling feature flag.
* Add functions that call User Timing APIs to a new SchedulingProfiler file. The file follows DebugTracing's structure.
* Add user timing marks to places where DebugTracing logs.
* Add user timing marks to most other places where @bvaughn's original draft DebugTracing branch marks.
* Tests added
* More context (and discussions with @bvaughn) available at our internal PR MLH-Fellowship#11 and issue MLH-Fellowship#5.

Similar to DebugTracing, we've only added scheduling profiling calls to the old reconciler fork.

Co-authored-by: Kartik Choudhary <kartik.c918@gmail.com>
Co-authored-by: Kartik Choudhary <kartikc.918@gmail.com>
Co-authored-by: Brian Vaughn <brian.david.vaughn@gmail.com>
2020-07-08 10:36:02 -04:00
Phil MacCart
b85b47630b Fix state leaking when a function component throws on server render (#19212)
* add unit test asserting internal hooks state is reset

* Reset internal hooks state before rendering

* reset hooks state on error

* Use expect...toThrow instead of try/catch in test

* reset dev-only hooks state inside resetHooksState

* reset currentlyRenderingComponent to null
2020-07-08 03:10:23 +01:00
Dan Abramov
6fd4321135 eslint-plugin-react-hooks@4.0.6 2020-07-07 22:39:40 +01:00
Dan Abramov
7c35cb20ef [ESLint] Handle optional member chains (#19275)
* Rename internal variables

This disambiguates "optional"/"required" because that terminology is taken by optional chaining.

* Handle optional member chains

* Update comment

Co-authored-by: Ricky <rickhanlonii@gmail.com>

Co-authored-by: Ricky <rickhanlonii@gmail.com>
2020-07-07 21:34:16 +01:00
Ricky
dccf541ec5 Allow decoupleUpdatePriorityFromScheduler to be set (#19272) 2020-07-07 12:58:10 -04:00
Dan Abramov
7ca1d861e8 [ESLint] Consistently treat optional chaining as regular chaining (#19273)
* Revert "Fix ExhaustiveDeps ESLint rule throwing with optional chaining (#19260)"

This reverts commit 0f84b0f02b.

* Re-add a test from #19260

* Remove all code for optional chaining support

* Consistently treat optional chaining as regular chaining

This is not ideal because our suggestions use normal chaining. But it gets rid of all current edge cases.

* Add more tests

* More consistency in treating normal and optional expressions

* Add regression tests for every occurrence of Optional*
2020-07-07 17:38:44 +01:00
Dominic Gannaway
98390f11f6 Update useEvent implementation (#19271) 2020-07-07 14:44:56 +01:00
Dominic Gannaway
4eb9b1d2b4 Refactor createEventHandle signature (#19174) 2020-07-07 13:05:06 +01:00
Dominic Gannaway
97b96da295 Fix event replaying logic (#19269) 2020-07-07 02:28:55 +01:00
Ricky
91a2e8173f Decouple update priority tracking from Scheduler package (#19121)
* Initial currentLanePriority implementation

* Minor updates from review

* Fix typos and enable flag

* Fix feature flags and lint

* Fix simple event tests by switching to withSuspenseConfig

* Don't lower the priority of setPending in startTransition below InputContinuous

* Move currentUpdateLanePriority in commit root into the first effect block

* Refactor requestUpdateLane to log for priority mismatches

Also verifies that the update lane priority matches the scheduler lane priority before using it

* Fix four tests by adding ReactDOM.unstable_runWithPriority

* Fix partial hydration when using update lane priority

* Fix partial hydration when using update lane priority

* Rename feature flag and only log for now

* Move unstable_runWithPriority to ReactFiberReconciler

* Add unstable_runWithPriority to ReactNoopPersistent too

* Bug fixes and performance improvements

* Initial currentLanePriority implementation

* Minor updates from review

* Fix typos and enable flag

* Remove higherLanePriority from ReactDOMEventReplaying.js

* Change warning implementation and startTransition update lane priority

* Inject reconciler functions to avoid importing src/

* Fix feature flags and lint

* Fix simple event tests by switching to withSuspenseConfig

* Don't lower the priority of setPending in startTransition below InputContinuous

* Move currentUpdateLanePriority in commit root into the first effect block

* Refactor requestUpdateLane to log for priority mismatches

Also verifies that the update lane priority matches the scheduler lane priority before using it

* Fix four tests by adding ReactDOM.unstable_runWithPriority

* Fix partial hydration when using update lane priority

* Fix partial hydration when using update lane priority

* Rename feature flag and only log for now

* Move unstable_runWithPriority to ReactFiberReconciler

* Bug fixes and performance improvements

* Remove higherLanePriority from ReactDOMEventReplaying.js

* Change warning implementation and startTransition update lane priority

* Inject reconciler functions to avoid importing src/

* Fixes from bad rebase
2020-07-06 18:53:42 -04:00
Dominic Gannaway
c3e42a962b Fix master tests (#19267) 2020-07-06 17:36:19 -04:00
Dominic Gannaway
0c0aaeb6bc Handle test-cli failure case for CI (#19265) 2020-07-06 22:05:51 +01:00
Joe Lencioni
0f84b0f02b Fix ExhaustiveDeps ESLint rule throwing with optional chaining (#19260)
Certain code patterns using optional chaining syntax causes
eslint-plugin-react-hooks to throw an error.

We can avoid the throw by adding some guards. I didn't read through the
code to understand how it works, I just added a guard to every place
where it threw, so maybe there is a better fix closer to the root cause
than what I have here.

In my test case, I noticed that the optional chaining that was used in
the code was not included in the suggestions description or output,
but it seems like it should be. This might make a nice future
improvement on top of this fix, so I left a TODO comment to that effect.

Fixes #19243
2020-07-06 15:52:14 -04:00
Brian Vaughn
670c0376ea Enable createEventHandle API for wWW test builds (#19262) 2020-07-06 15:19:50 -04:00
Dominic Gannaway
26071abbe1 Refine event registration + event signatures (#19244)
* Refine event registration + event signatures

* Address feedback
2020-07-06 17:42:01 +01:00
Ittai Baratz
1cbaf48889 Add SSL support to React devtools standalone (#19191)
Co-authored-by: Brian Vaughn <brian.david.vaughn@gmail.com>
2020-07-06 10:09:41 -04:00
Dominic Gannaway
65c137768a Fix Flow from #19239 (#19242) 2020-07-02 16:37:10 +01:00
Son Ki-Kyun
cd9046f815 Add some type detection (#19239) 2020-07-02 15:54:36 +01:00
Dan Abramov
b6df4417c7 Remove event config (#19237) 2020-07-02 00:26:29 +01:00
Dan Abramov
991c3b8193 Make event config an implementation detail of each plugin (#19236)
* Merge two variables with same purpose

* Replace dispatchConfig with _reactName on event object
2020-07-02 00:03:17 +01:00
Dan Abramov
b683c07ccc Remove TestUtils dependency on event registry (#19235) 2020-07-01 22:54:28 +01:00
Dan Abramov
9e7f5c02ca Make event plugin injection statically resolvable (#19234)
* Make plugins ESM

* Resolve extractEvents statically

* Resolve eventTypes statically

* Fix flow types and inconsistent naming

* Move injection into the plugin system itself

* Fix Flow
2020-07-01 22:11:05 +01:00
Dominic Gannaway
67eb6ff4a8 Add Flow to ModernChangeEventPlugin (#19232) 2020-07-01 21:49:03 +01:00
Dan Abramov
75b6921d64 Remove dead code from modern event system (#19233)
* Remove dead code from modern event system

* Remove SSR dependency on EventPluginRegistry
2020-07-01 21:04:14 +01:00
Dan Abramov
9fba65efa5 Enable modern event system and delete dead code (#19230) 2020-07-01 17:43:34 +01:00
Dan Abramov
e3f4eb7272 Fork legacy-events folder into react-dom and react-native (#19228) 2020-07-01 16:37:13 +01:00
Dominic Gannaway
cd0275dcb2 Fix responder logic in ReactDOMServerSelectiveHydration-test (#19227) 2020-07-01 16:28:49 +01:00
Dan Abramov
b231445f96 Move responder tests and remove dead code (#19226) 2020-07-01 16:20:49 +01:00
Dan Abramov
5707eeb2d2 Run ReactBrowserEventEmitter test on bundles (#19225)
* Run ReactBrowserEventEmitter test on bundles

* Rm bad tests
2020-07-01 16:01:46 +01:00
Dominic Gannaway
b2bac7311a Remove React Flare Keyboard responder (#19222) 2020-07-01 15:43:16 +01:00
Dan Abramov
f918b0eb41 Fix development mode hang when iframe is removed (#19220)
* Fix development mode hang when iframe is removed

* Also fix #16734
2020-07-01 15:33:29 +01:00
Dan Abramov
8bff8987e5 Don't bailout after Suspending in Legacy Mode (#19216)
* Add a failing test for legacy Suspense blocking context updates in memo

* Add more test case coverage for variations of #17356

* Don't bailout after Suspending in Legacy Mode

Co-authored-by: Tharuka Devendra <tsdevendra1@gmail.com>
2020-06-30 22:06:46 +01:00
Shailendra Gupta
f4097c1aef Added warning to <Context.Provider> in case no value prop is provided (#19054)
* added warning to context.provider in case no value prop

* update message

* updated message and pass undefined
2020-06-30 19:50:55 +01:00
Dan Abramov
47ff31a77a Revert "Add regression test for #18497 (#18538)" (#19215)
This reverts commit e9c1445ba0.
2020-06-30 13:38:31 +01:00
Vetrivel Chinnasamy
b621dab5d4 make link https (#19147) 2020-06-30 12:43:52 +01:00
jddxf
fa32cf299f Add regression tests where sync render causes later concurrent render to expire soon (#18608)
* Add a failing test for #17911

* Add more test cases where sync render causes later concurrent render to expire soon
2020-06-30 12:42:59 +01:00
Dan Abramov
1887c5d946 eslint-plugin-react-hooks@4.0.5 2020-06-30 12:16:49 +01:00
Fred Vollmer
b0533fe33c fix(eslint-plugin-react-hooks): Support optional chaining when accessing prototype method inside useCallback and useMemo #19061 (#19062)
* fix(eslint-plugin-react-hooks): Support optional chaining when accessing prototype method #19061

* run prettier

* Add fix for #19043
2020-06-30 12:14:00 +01:00
Sophie Alpert
e9c1445ba0 Add regression test for #18497 (#18538) 2020-06-30 12:09:05 +01:00
Brian Vaughn
9d9cf383c9 Fixed test script handling of unknown/additional args (#19209) 2020-06-29 15:36:45 -04:00
Dominic Gannaway
3c1a7ac87c Move TOP_BEFORE_BLUR to bubble phase (#19197) 2020-06-26 20:35:21 +01:00
Ricky
72bbcad160 Add new test cli (#19184)
* Add new test cli

* Remove --variant accidentally added to test-persist

* s/test/tests

* Updates from review

* Update package.json tests

* Missed a release channel in circle.yaml

* Update config.yml to use just run: with test commands

* Update release-channel options and add build dir checks

* Update test args to use the new release-channel options

* Fix error in circle config.yml

* Fix a wrong condition for the --variant check

* Fix a wrong condition for the --persistent check

* Prettier

* Require build check for devtool tests as well
2020-06-25 20:39:50 -04:00
Christoph Nakazawa
7d0e4150aa Fix react-runtime main field (#19193)
The "main" field in this package points to a non-existent file. This fixes it.
2020-06-25 12:17:42 -04:00
finico
ed94600fc6 Remove unnecessary tag end from CommitRanked view (#19195) 2020-06-25 12:10:47 -04:00
Chen Gang
ffe516f3bf use NoTimestamp instead of -1 (#19182) 2020-06-23 16:28:24 -04:00
Brian Vaughn
1425fcbb86 Re-enabled DebugTracing feature for old reconciler fork (#19161)
* Re-enabled DebugTracing feature for old reconciler fork

It was temporarily removed by @sebmarkbage via PR #18697. Newly re-added tracing is simplified, since the lane(s) data type does not require the (lossy) conversion between priority and expiration time values.

@sebmarkbage mentioned that he removed this because it might get in the way of his planned discrete/sync refactor. I'm not sure if that concern still applies, but just in case- I have only re-added it to the old reconciler fork for now.

* Force Code Sandbox CI to re-run
2020-06-23 12:16:23 -04:00
Brian Vaughn
0836f62a5b Updates the DevTools test script to make it easier to test other URLs. (#19179) 2020-06-23 11:48:35 -04:00
Brian Vaughn
1cfd332fd7 Shutdown DevTools Bridge synchronously when unmounting (#19180) 2020-06-23 11:48:04 -04:00
Jack Works
5b98656909 fix: use define property to overwrite console, close #19099 (#19123)
* fix: use define property to overwrite console, close #19099

* fix: lint error
2020-06-23 10:34:53 -04:00
Andrew Clark
6ba25b96df Bugfix: Legacy Mode + DevTools "force fallback" (#19164)
DevTools has a feature to force a Suspense boundary to show a fallback.
This feature causes us to skip the first render pass (where we render
the primary children) and go straight to rendering the fallback.

There's a Legacy Mode-only codepath that failed to take this scenario
into account, instead assuming that whenever a fallback is being
rendered, it was preceded by an attempt to render the primary children.

SuspenseList can also cause us to skip the first pass, but the relevant
branch is Legacy Mode-only, and SuspenseList is not supported in
Legacy Mode.

Fixes a test that I had temporarily disabled when upstreaming the Lanes
implementation in #19108.
2020-06-19 11:06:42 -07:00
Luna Ruan
d1d9054e09 Revert "Re-enabled DebugTracing feature for old reconciler fork (#19142)" (#19159)
This reverts commit cc7c1aece4.
2020-06-18 18:18:56 -07:00
YeonJuan
090c6ed751 [eslint-plugin-react-hooks]: handling sparse array when no-inline callback (#19145) 2020-06-17 12:29:02 -04:00
Brian Vaughn
cc7c1aece4 Re-enabled DebugTracing feature for old reconciler fork (#19142)
It was temporarily removed by @sebmarkbage via PR #18697. Newly re-added tracing is simplified, since the lane(s) data type does not require the (lossy) conversion between priority and expiration time values.

@sebmarkbage mentioned that he removed this because it might get in the way of his planned discrete/sync refactor. I'm not sure if that concern still applies, but just in case- I have only re-added it to the old reconciler fork for now.
2020-06-16 15:16:15 -04:00
阿林
d4fc2c1457 Fix spelling (#19084) 2020-06-15 20:56:56 -04:00
Ricky
30b47103d4 Fix spelling errors and typos (#19138) 2020-06-15 19:59:44 -04:00
Rick Hanlon
655affa302 Clarifications
Co-authored-by: shengxinjing <316783812@qq.com>
2020-06-12 21:09:29 -04:00
Andrew Clark
103ed08c46 Remove shouldDeprioritizeSubtree from host config (#19124)
No longer being used.
2020-06-12 12:57:20 -07:00
Andrew Clark
8f05f2bd6d Land Lanes implementation in old fork (#19108)
* Add autofix to cross-fork lint rule

* replace-fork: Replaces old fork contents with new

For each file in the new fork, copies the contents into the
corresponding file of the old fork, replacing what was already there.

In contrast to merge-fork, which performs a three-way merge.

* Replace old fork contents with new fork

First I ran  `yarn replace-fork`.

Then I ran `yarn lint` with autofix enabled. There's currently no way to
do that from the command line (we should fix that), so I had to edit the
lint script file.

* Manual fix-ups

Removes dead branches, removes prefixes from internal fields.  Stuff
like that.

* Fix DevTools tests

DevTools tests only run against the old fork, which is why I didn't
catch these earlier.

There is one test that is still failing. I'm fairly certain it's related
to the layout of the Suspense fiber: we no longer conditionally wrap the
primary children. They are always wrapped in an extra fiber.

Since this has been running in www for weeks without major issues, I'll
defer fixing the remaining test to a follow up.
2020-06-11 20:05:15 -07:00
Sebastian Markbåge
7f28234f84 Enable component stacks everywhere except RN (#19120)
This would still affect test renderer and isomorphic in RN.
2020-06-11 19:13:13 -07:00
Dominic Gannaway
e3ccdf1544 Remove synamic modern event system flag for FB (#19059)
* Remove synamic modern event system flag for FB
2020-06-11 19:49:45 +01:00
Andrew Clark
4c7036e807 Bugfix: Infinite loop in beforeblur event (#19053)
* Failing test: Infinite loop in beforeblur event

If the focused node is hidden by a Suspense boundary, we fire the
beforeblur event. Our check for whether a tree is being hidden isn't
specific enough. It should only fire when the tree is initially hidden,
but it's being fired for updates, too.

* Only fire beforeblur on visible -> hidden

Should only beforeblur fire if the node was previously visible. Not
during updates to an already hidden tree.

To optimize this, we should use a dedicated effect tag and mark it in
the render phase. I've left this for a follow-up, though. Maybe can
revisit after the planned refactor of the commit phase.

* Move logic to commit phase

isFiberSuspenseAndTimedOut is used elsewhere, so I inlined the commit
logic into the commit phase itself.
2020-06-01 09:01:21 -07:00
Sebastian Markbåge
1d85bb3ce1 Build FB specific Isomorphic Bundles (#19049)
We need this so we can version them separately and use different
feature flags than we use for OSS RN.

I put them in a separate facebook-react-native folder which won't go
into the RN GH repo. I plan on moving the renderers there too but not yet.
2020-05-29 15:32:38 -07:00
Brian Vaughn
2efe63d99c DevTools: Add break-on-warn feature (#19048)
This commit adds a new tab to the Settings modal: Debugging

This new tab has the append component stacks feature and a new one: break on warn

This new feature adds a debugger statement into the console override
2020-05-29 14:34:43 -07:00
Sebastian Markbåge
89edb0eae3 Enable component stack locations in www (#19047) 2020-05-29 13:26:38 -07:00
Sebastian Markbåge
cb14168175 Remove unnecessary throw catch (#19044)
This was originally added so you could use "break on caught exceptions"
but that feature is pretty useless these days since it's used for feature
detection and Suspense.

The better pattern is to use the stack trace, jump to source and set a
break point here.

Since DevTools injects its own console.error, we could inject a "debugger"
statement in there. Conditionally. E.g. React DevTools could have a flag
to toggle "break on warnings".
2020-05-29 11:25:48 -07:00
Sebastian Markbåge
c03b8661a9 Upgrade Closure Compiler (#19041)
The Symbol bug has now been fixed so we can remove the hack that renames
the global variable.
2020-05-29 09:17:14 -07:00
Sebastian Markbåge
6d375f3078 Revert autofix lint (#19040)
I accidentally committed this since I had it on locally so I didn't have
to manually convert things to const.

However, this causes things to always pass lint since CI also runs this.
2020-05-28 20:32:34 -07:00
Sebastian Markbåge
8f511754db Prettier wants me to change this (#19039) 2020-05-28 20:13:56 -07:00
Sebastian Markbåge
2e7cc949ae Remove www builds of fetch (#19038)
I don't think we'll ever use this just because we have such a unique set up
for network delivery so we'll use something custom for this case.

Also, we don't need a profiling build for this since it doesn't have an
entry point.
2020-05-28 16:12:37 -07:00
Sebastian Markbåge
76f157e3dd Add simple Node build (#19022)
The webpack plugin doesn't really need a separate prod and dev build.
It also needs to be ES2015 otherwise we can't extend native classes.
2020-05-28 15:56:34 -07:00
Sebastian Markbåge
60afa3c117 Lint bundles using the bundle config instead of scanning for files (#19025)
* Lint bundles using the bundle config instead of scanning for files

This ensures that we look for all the files that we expect to see there.
If something doesn't get built we wouldn't detect it.

However, this doesn't find files that aren't part of our builds such as
indirection files in the root. This will need to change with ESM anyway
since indirection files doesn't work. Everything should be built anyway.

This ensures that we can use the bundles.js config to determine special
cases instead of relying on file system conventions.

* Run lint with flag
2020-05-28 15:04:25 -07:00
Sebastian Markbåge
518ce9c25f Add Lazy Elements Behind a Flag (#19033)
We really needed this for Flight before as well but we got away with it
because Blocks were lazy but with the removal of Blocks, we'll need this
to ensure that we can lazily stream in part of the content.

Luckily LazyComponent isn't really just a Component. It's just a generic
type that can resolve into anything kind of like a Promise.

So we can use that to resolve elements just like we can components.

This allows keys and props to become lazy as well.

To accomplish this, we suspend during reconciliation. This causes us to
not be able to render siblings because we don't know if the keys will
reconcile. For initial render we could probably special case this and
just render a lazy component fiber.

Throwing in reconciliation didn't work correctly with direct nested
siblings of a Suspense boundary before but it does now so it depends
on new reconciler.
2020-05-28 14:16:35 -07:00
Sebastian Markbåge
4985bb0a80 Rename 17 to 18 in warnings (#19031)
We're not really supposed to refer to future versions by numbers.

These will all slip so these numbers don't make sense anymore.
2020-05-28 10:25:39 -07:00
Brian Vaughn
86b4070ddb Cleaned up passive effects experimental flags (#19021) 2020-05-28 08:32:37 -07:00
Sebastian Markbåge
607148673b Remove ReactComponentTreeHook from internals (#19032)
We don't really support mixing minor versions anymore anyway. But seems
safe to remove in 17.
2020-05-27 20:41:13 -07:00
Sebastian Markbåge
43e59f29d6 Delete Entries without Build Output from package.json and the build directory (#19029)
* Gate test

* Delete entrypoints without Build Outputs from package.json and build output

If an entry point exists in bundles.js but doesn't have any bundleTypes,
I delete that entry point file from the build directory. I also remove it
from the files field in package.json if it exists.

This allows us to remove bundles from being built in the stable release
channel.
2020-05-27 19:43:08 -07:00
Sebastian Markbåge
e668f1b54f Remove unstable-fire from package.json (#19026)
This hasn't existed for a while now.
2020-05-27 17:07:25 -07:00
Sebastian Markbåge
0219925e02 Remove regenerator from noop (#19024)
This isn't used and it wouldn't work anyway.
2020-05-27 16:14:46 -07:00
Sebastian Markbåge
c66ac10f4d Lint classic www build (#19023) 2020-05-27 14:13:54 -07:00
Dan Abramov
b41beb1a35 Revert "Fix mistyped script arbitrary code execution vulnerability (#18660)" (#19018)
This reverts commit e5cc1462b3.
2020-05-27 17:37:27 +01:00
Sebastian Markbåge
55cb0b7eeb Only prepare extra stack frames if needed (#19014)
We currently prepare an extra stack frame before they're needed.
Particularly for propTypes. This causes problems as they can have
side-effects with the new component stacks and it's slow.

This moves it to be lazy.
2020-05-27 08:43:50 -07:00
Aaron Pettengill
9752d31f12 Document additionalHooks option (#19005)
* Document `additionalHooks` option

* Update README.md

Co-authored-by: Aaron Pettengill <aaron.pettengill@echoman.com>
Co-authored-by: Dan Abramov <dan.abramov@gmail.com>
2020-05-27 15:27:43 +01:00
Dan Abramov
b7ff888190 eslint-plugin-react-hooks@4.0.4 2020-05-27 14:38:27 +01:00
Andrew Clark
18de3b6e7c Bug: Spawning hydration in response to Idle update (#19011)
* Bug: Spawning hydration in response to Idle update

Adds a test that fails in the new fork.

* Fix typos related to Idle priority

These are just silly mistakes that weren't caught by any of our tests.

There's a lot of duplication in the Lanes module right now. It's also
not super stable as we continue to refine our heuristics. Hopefully the
final state is simpler and less prone to these types of mistakes.
2020-05-26 18:53:50 -07:00
Andrew Clark
9273e6585f Disable DevTools build job to unblock master (#19012) 2020-05-26 18:52:58 -07:00
Toru Kobayashi
fb735423bb Fix rollup validate script (#18900)
* Revert "Revert "deps: update ESLint version to v7 (#18897)" (#18899)"

This reverts commit 84fd4b853f.

* fix rollup validate script
2020-05-27 01:19:32 +01:00
Julien Deniau
8abc202c7f [eslint-plugin-react-hooks] Prefer recommended eslint configuration (#18951)
* [eslint-plugin-react-hooks] Prefer recommended eslint configuration

* Update README.md

Co-authored-by: Dan Abramov <dan.abramov@gmail.com>
2020-05-27 01:08:41 +01:00
Yann アウネ Eves
4821d609e9 fix(eslint-plugin-react-hooks): Added matching for nullish coalescing and optional chaining of dependencies, relates to #18985 (#19008) 2020-05-27 01:07:10 +01:00
Brian Vaughn
a012858ba9 Move isCustomComponent() function call outside of loop (#19007) 2020-05-26 13:41:27 -07:00
Dan Abramov
67e130fc68 eslint-plugin-react-hooks@4.0.3 2020-05-26 16:11:08 +01:00
Dan Abramov
bb2239dc90 Revert "Feature: Add support to exhaustive-deps rule for any hook ending with Effect (#18580)" (#19004)
This reverts commit 5ac9ca72df.
2020-05-26 16:08:50 +01:00
Andrew Clark
03e6b8ba2f Make LegacyHidden match semantics of old fork (#18998)
Facebook currently relies on being able to hydrate hidden HTML. So
skipping those trees is a regression.

We don't have a proper solution for this in the new API yet. So I'm
reverting it to match the old behavior.

Now the server renderer will treat LegacyHidden the same as a fragment,
with no other special behavior. We can only get away with this because
we assume that every instance of LegacyHidden is accompanied by a host
component wrapper. In the hidden mode, the host component is given a
`hidden` attribute, which ensures that the initial HTML is not visible.
To support the use of LegacyHidden as a true fragment, without an extra
DOM node, we will have to hide the initial HTML in some other way.
2020-05-25 18:16:53 -07:00
Dan Abramov
3ca1904b37 react-refresh@0.8.3 2020-05-23 14:26:26 +01:00
yjimk
0aa4cc544c Resolve an edge case where ref.node can be falsy (#18984)
Co-authored-by: Jimmy Cann <jimmy.cann@ironstar.io>
2020-05-23 14:25:24 +01:00
Brian Vaughn
8f4dc3e5d0 Warn if MutableSource snapshot is a function (#18933)
* Warn if MutableSource snapshot is a function

useMutableSource does not properly support snapshots that are functions. In part this is because of how it is implemented internally (the function gets mistaken for a state updater function). To fix this we could just wrap another function around the returned snapshot, but this pattern seems problematic to begin with- because the function that gets returned might itself close over mutable values, which would defeat the purpose of using the hook in the first place.

This PR proposes adding a new DEV warning if the snapshot returned is a function. It does not change the behavior (meaning that a function could still work in some cases- but at least the current behavior prevents passing around a closure that may later become stale unless you're really intentional about it e.g. () => () => {...}).

* Replaced .warn with .error
2020-05-21 16:14:29 -07:00
Brian Vaughn
142d4f1c00 useMutableSource hydration support (#18771)
* useMutableSource hydration support

* Remove unnecessary ReactMutableSource fork

* Replaced root.registerMutableSourceForHydration() with mutableSources option

* Response to PR feedback:

1. Moved mutableSources root option to hydrationOptions object
2. Only initialize root mutableSourceEagerHydrationData if supportsHydration config is true
3. Lazily initialize mutableSourceEagerHydrationData on root object
2020-05-21 16:00:46 -07:00
Brian Vaughn
aefb97e6bb DevTools: Add root and renderer version to inspected props panel (#18963)
* DevTools: Add root and renderer version to inspected props panel
* Removed redundant .length check
2020-05-21 14:40:49 -07:00
Andrew Clark
74394aa8cb Add unstable_isNewReconciler to dispatcher (#18975)
This is a bit gross but I need to be able to access it without importing
the renderer.

There might be a better way but I need this to unblock internal bugfix.
2020-05-21 11:56:00 -07:00
Brian Vaughn
099f73710e DevTools: Improve error boundary (#18956)
1. Add support for dark mode
2. Add retry option for case where Profiler data is corrupted
2020-05-21 11:21:22 -07:00
Dominic Gannaway
730ae7afa2 Clear fiber.sibling field when clearing nextEffect (#18970)
* Clear fiber.sibling field when clearing nextEffect
2020-05-21 18:53:56 +01:00
Brian Vaughn
c93a6cb4d5 DevTools: Fix highlight updates Canvas side problem (#18973) 2020-05-21 10:04:37 -07:00
Andrew Clark
f9bf828701 Add `unstable_isNewReconciler export to FB builds (#18974)
Should check this at runtime instead of the GK
2020-05-21 10:03:59 -07:00
Dominic Gannaway
4a3f779d67 Remove event pooling in the modern system (#18969) 2020-05-21 13:54:05 +01:00
Brian Vaughn
22f7663f14 Profiler: Don't count timed out (hidden) subtrees in base duration (#18966) 2020-05-20 18:36:57 -07:00
Andrew Clark
64f50c667a Remove disableHiddenPropDeprioritization flag (#18964)
This is rolled out to 100% public, so we can remove it.
2020-05-20 15:29:34 -07:00
Sebastian Markbåge
a30a1c6ef3 Transfer actualDuration only once for SuspenseList (#18959) 2020-05-20 15:12:38 -07:00
Andrew Clark
8b3b5c3524 Bugfix: Missing mode check in resetChildLanes (#18961)
Deferring a hidden tree is only supported in Concurrent Mode.

The missing check leads to an infinite loop when an update is scheduled
inside a hidden tree, because the pending work never gets reset.

This "accidentally" worked in the old reconciler because the heurstic
we used to detect offscreen trees was if `childExpirationTime`
was `Never`.

In the new reconciler, we check the tag instead. Which means we also
need to check the mode, like we do in the begin phase.

We should move this check out of the hot path. It shouldn't have been
in the hot path of the old reconciler, either.

Probably by moving `resetChildLanes` into the switch statement
in ReactFiberCompleteWork.
2020-05-19 23:10:49 -07:00
Andrew Clark
95ea8ed47c LegacyHidden: mode that defers without hiding (#18958)
Need this to unblock www. Not sure yet how we'll support this properly
long term.

While adding this, I noticed that the normal "hidden" mode of
LegacyHidden doesn't work properly because it doesn't toggle the
visibility of newly inserted nodes. This is fine for now since we only
use it via a userspace abstraction that wraps the children in an
additional node. But implementing this correctly is required for us
to start using it like a fragment, without the wrapper node.
2020-05-19 15:58:02 -07:00
Brian Vaughn
5aa967b69b DevTools editable props tweaks (#18954)
1. Made non-editable prop text higher contrast (easier to read)
2. Also makes it stand out as different from dimmer placeholder text for "new prop"
2020-05-19 09:42:00 -07:00
Toru Kobayashi
dbf2bba632 remove an unused ISSUE_TEMPLATE.md (#18953) 2020-05-19 08:44:01 -07:00
Brian Vaughn
23309eb386 DevTools 4.6.0 -> 4.7.0 2020-05-18 14:16:04 -07:00
Nick Reiley
d897c35ecf [DevTools] Add Component Highlighting to Profiler (#18745)
Co-authored-by: Moji Izadmehr <m.eezadmehr@gmail.com>
Co-authored-by: Brian Vaughn <bvaughn@fb.com>
2020-05-18 11:13:16 -07:00
Nick Reiley
081b565cd7 [DevTools] enable Electron interactions on Linux & auto copy script tags (#18772)
Co-authored-by: Brian Vaughn <brian.david.vaughn@gmail.com>
2020-05-18 10:27:40 -07:00
Sebastian Silbermann
c390ab3643 Add test for displayName on React.memo components (#18925)
* Add test for displayName on React.memo components

* Added extra memo displayName test

Co-authored-by: Brian Vaughn <brian.david.vaughn@gmail.com>
2020-05-15 15:56:50 -07:00
Gabriele Prestifilippo
6ed5c2243f Add MIT license to use-subscription package (#18927)
This package is missing the license attribute (or a license file).

Being a sub-package of React, it should get the same license, however, none was specified.
A scan with `license_checker` would recognize this as `UNKNOWN`.
2020-05-15 15:36:48 -07:00
Brian Vaughn
8dba6691d0 Updated DevTools CHANGELOG for upcoming changes 2020-05-15 10:50:39 -07:00
Nick Reiley
dd2e36df33 Profiler: Skip reading element for imported data (#18913)
* skip reading element for imported data

* rename nodes & enable store lookup for components tab

* replace names

* Added some more test coverage; reverted rename

Co-authored-by: Brian Vaughn <bvaughn@fb.com>
2020-05-15 10:38:01 -07:00
Nick Reiley
7c080902ef [DevTools] Improve HOC search UX (#18802)
Co-authored-by: Brian Vaughn <brian.david.vaughn@gmail.com>
2020-05-15 10:37:34 -07:00
Ricky Vetter
121af3143c Update inaccurate mapChildren comment (#18931)
The function you provide will only be passed a child and an index. It will not be passed a key. This is confirmed in the source, the Flow types, and the jsdoc comments.
2020-05-15 18:05:08 +01:00
Sophie Alpert
21dc41c320 Simplify logic for mutable workInProgressSources (#18920)
isPrimaryRenderer is always constant for a given React build, so these two arrays do nothing.
2020-05-14 14:30:44 -07:00
Andrew Clark
0fb747f368 Add LegacyHidden to server renderer (#18919)
* Add LegacyHidden to server renderer

When the tree is hidden, the server renderer renders nothing. The
contents will be completely client rendered.

When the tree is visible it acts like a fragment.

The future streaming server renderer may want to pre-render these trees
and send them down in chunks, as with Suspense boundaries.

* Force client render, even at Offscreen pri
2020-05-14 11:28:11 -07:00
Andrew Clark
b4a1a4980c Disable <div hidden /> API in old fork, too (#18917)
The motivation for doing this is to make it impossible for additional
uses of pre-rendering to sneak into www without going through the
LegacyHidden abstraction. Since this feature was already disabled in
the new fork, this brings the two closer to parity.

The LegacyHidden abstraction itself still needs to opt into
pre-rendering somehow, so rather than totally disabling the feature, I
updated the `hidden` prop check to be obnoxiously specific. Before, you
could set it to any truthy value; now, you must set it to the string
"unstable-do-not-use-legacy-hidden".

The node will still be hidden in the DOM, since any truthy value will
cause the browser to apply a style of `display: none`.

I will have to update the LegacyHidden component in www to use the
obnoxious string prop. This doesn't block merge, though, since the
behavior is gated by a dynamic flag. I will update the component before
I enable the flag.
2020-05-13 20:01:10 -07:00
Brian Vaughn
9e5b2c94e6 Add expando prop to disabledLog function (#18914)
This will enable it to be identified by Facebook infra even if the function name is mangled during DevTools build process.
2020-05-13 17:03:50 -07:00
Andrew Clark
fdb641629e Fix useMutableSource tearing bug (#18912)
* Failing useMutableSource test

If a source is mutated after initial read but before subscription is set
up, it should still entangle all pending mutations even if snapshot of
new subscription happens to match.

Test case illustrates how not doing this can lead to tearing.

* Fix useMutableSource tearing bug

Fix is to move the entanglement call outside of the block that checks
if the snapshot has changed.
2020-05-13 14:28:17 -07:00
Andrew Clark
33589f7423 useMutableSource: "Entangle" instead of expiring (#18889)
* useMutableSource: "Entangle" instead of expiring

A lane is said to be entangled with another when it's not allowed to
render in a batch that does not also include the other lane.

This commit implements entanglement for `useMutableSource`. If a source
is mutated in between when it's read in the render phase, but before
it's subscribed to in the commit phase, we must account for whether the
same source has pending mutations elsewhere. The old subscriptions must
not be allowed to re-render without also including the new subscription
(and vice versa), to prevent tearing.

In the old reconciler, we did this by synchronously flushing all the
pending subscription updates. This works, but isn't ideal. The new
reconciler can entangle the updates without de-opting to sync.

In the future, we plan to use this same mechanism for other features,
like skipping over intermediate useTransition states.

* Use clz instead of ctrz to pick an arbitrary lane

Should be slightly faster since most engines have built-in support.
2020-05-13 11:33:32 -07:00
Dan Abramov
43063fd844 eslint-plugin-react-hooks@4.0.2 2020-05-13 16:46:26 +01:00
Dan Abramov
f6ff4c43dd Update changelog 2020-05-13 16:45:50 +01:00
Boris Sergeev
487c693846 [eslint-plugin-react-hooks] useWithoutEffectSuffix fix (#18902) (#18907)
* [eslint-plugin-react-hooks] reproduce bug with a test and fix it (#18902)

Since we only reserve `-Effect` suffix, react-hooks/exhaustive-deps is
expected to succeed without warning on a custom hook which contains -Effect- in
the middle of it's name (but does NOT contain it as a suffix).

* [eslint-plugin-react-hooks] reproduced bug with a test and fix it

Since we only reserve `-Effect` suffix, react-hooks/exhaustive-deps is expected
to succeed without warning on a render helper which contains -use- in the middle
of it's name (but does NOT contain it as a prefix, since that would violate hook
naming convetion).

Co-authored-by: Boris Sergeyev <boris.sergeyev@quolab.com>
2020-05-13 16:44:05 +01:00
Dominic Gannaway
6514e4a179 React Flare: fix PressLegacy preventDefault issue (#18904) 2020-05-13 13:59:32 +01:00
Nick Reiley
a3fccd2567 Fix Profiler root change error (#18880) 2020-05-12 15:47:23 -07:00
Dominic Gannaway
61f2a560e0 Add experimental ReactDOM.createEventHandle (#18756) 2020-05-12 20:24:25 +01:00
Dan Abramov
84fd4b853f Revert "deps: update ESLint version to v7 (#18897)" (#18899)
This reverts commit 039ad34a05.
2020-05-12 20:06:14 +01:00
Dan Abramov
14e554b310 Add missing changelog item 2020-05-12 19:18:26 +01:00
Dominic Gannaway
80c4dea0d1 Modern Event System: Add scaffolding for createEventHandle (#18898) 2020-05-12 19:01:12 +01:00
Toru Kobayashi
039ad34a05 deps: update ESLint version to v7 (#18897) 2020-05-12 18:41:37 +01:00
Dan Abramov
9f396bdd5d eslint-plugin-react-hooks@4.0.1 2020-05-12 17:22:00 +01:00
Richard Maisano
c512aa0081 [Blocks] Scaffolding react-fetch + first pass at node implementation (#18863)
* First pass at scaffolding out the Node implementation of react-data.

While incomplete, this patch contains some changes to the react-data
package in order to start adding support for Node.

The first part of this change accounts for splitting react-data/fetch
into two discrete entries, adding (and defaulting to) the Node
implementation.

The second part is sketching out a rough approximation of `fetch` for
Node. This implementation is not complete by any means, but provides a
starting point.

* Remove NodeFetch module and put it directly into ReactDataFetchNode.

* Replaced react-data with react-fetch.

This patch shuffles around some of the scaffolding that was in
react-data in favor of react-fetch. It also removes the additional
"fetch" package in favor of something flatter.

* Tweak package organization

* Simplify and add a test

Co-authored-by: Dan Abramov <dan.abramov@me.com>
2020-05-12 17:21:45 +01:00
Dan Abramov
e936034eec Add item to ESLint Hooks plugin changelog 2020-05-12 17:02:37 +01:00
Michaël De Boey
c3ff21e01b feat(eslint-plugin-react-hooks): Support ESLint 7.x (#18878) 2020-05-12 17:01:28 +01:00
Andrew Clark
8b9c4d1688 Expose LegacyHidden type and disable <div hidden /> API in new fork (#18891)
* Expose LegacyHidden type

I will use this internally at Facebook to migrate away from
<div hidden />. The end goal is to migrate to the Offscreen type, but
that has different semantics. This is an incremental step.

* Disable <div hidden /> API in new fork

Migrates to the unstable_LegacyHidden type instead. The old fork does
not support the new component type, so I updated the tests to use an
indirection that picks the correct API. I will remove this once the
LegacyHidden (and/or Offscreen) type has landed in both implementations.

* Add gated warning for `<div hidden />` API

Only exists so we can detect callers in www and migrate them to the new
API. Should not visible to anyone outside React Core team.
2020-05-11 20:02:08 -07:00
Dominic Gannaway
ef0bf8e31c Revert "Hard code enableComponentStacks in www (#18869)" (#18890)
This reverts commit fd696df472.
2020-05-11 23:29:24 +01:00
Dominic Gannaway
e16703e6c7 Modern Event System: revise ancestor logic (#18886) 2020-05-11 22:09:52 +01:00
Karl Horky
2b9d7cf65f Devtools: Show inspectedElement key in right pane (#18737)
* Start MVP for showing inspected element key

* Add key in other places

* Add key from backend

* Remove unnecessary hydrateHelper call

* Hide copy button when no label

* Move above props

* Revert changes to InspectedElementTree.js

* Move key to left of component name

* Updated CSS

Co-authored-by: Brian Vaughn <brian.david.vaughn@gmail.com>
2020-05-11 13:17:13 -07:00
Rohith Srivathsav
ddcc69c83b Added clear message for functional component starting with lowercase (#18881) 2020-05-10 01:52:11 +01:00
Sebastian Markbåge
539527b642 Don't cut off effects at end of list if hydrating (#18872) 2020-05-08 21:26:51 -07:00
Sebastian Markbåge
fd696df472 Hard code enableComponentStacks in www (#18869)
This is now fully rolled out.
2020-05-08 18:14:54 -07:00
Andrew Clark
6edaf6f764 Detect and prevent render starvation, per lane (#18864)
* Detect and prevent render starvation, per lane

If an update is CPU-bound for longer than expected according to its
priority, we assume it's being starved by other work on the main thread.

To detect this, we keep track of the elapsed time using a fixed-size
array where each slot corresponds to a lane. What we actually store is
the event time when the lane first became CPU-bound.

Then, when receiving a new update or yielding to the main thread, we
check how long each lane has been pending. If the time exceeds a
threshold constant corresponding to its priority, we mark it as expired
to force it to synchronously finish.

We don't want to mistake time elapsed while an update is IO-bound
(waiting for data to resolve) for time when it is CPU-bound. So when a
lane suspends, we clear its associated event time from the array. When
it receives a signal to try again, either a ping or an update, we assign
a new event time to restart the clock.

* Store as expiration time, not start time

I originally stored the start time because I thought I could use this
in the future to also measure Suspense timeouts. (Event times are
currently stored on each update object for this purpose.) But that
won't work because in the case of expiration times, we reset the clock
whenever the update becomes IO-bound. So to replace the per-update
field, I'm going to have to track those on the room separately from
expiration times.
2020-05-08 12:47:51 -07:00
Nick Reiley
6207743168 [DevTools] Allow to continue dragging when leaving profiler picker (#18852)
Co-authored-by: Brian Vaughn <brian.david.vaughn@gmail.com>
2020-05-08 11:19:57 -07:00
Luna Ruan
df14b5bcc1 add new IDs for each each server renderer instance and prefixes to distinguish between each server render (#18576)
There is a worry that `useOpaqueIdentifier` might run out of unique IDs if running for long enough. This PR moves the unique ID counter so it's generated per server renderer object instead. For people who render different subtrees, this PR adds a prefix option to `renderToString`, `renderToStaticMarkup`, `renderToNodeStream`, and `renderToStaticNodeStream` so identifiers can be differentiated for each individual subtree.
2020-05-07 20:46:27 -07:00
Brian Vaughn
69e732ac9d Disable Profiler commit filtering (#18862)
* Disable Profiler commit filtering

We used to filter "empty" DevTools commits, but it was error prone (see #18798). A commit may appear to be empty (no actual durations) because of component filters, but filtering these empty commits causes interaction commit indices to be off by N. This not only corrupts the resulting data, but also potentially causes runtime errors.

For that matter, hiding "empty" commits might cause confusion too. A commit *did happen* even if none of the components the Profiler is showing were involved.

* Restart flaky CI
2020-05-07 17:07:20 -07:00
Brian Vaughn
fb3f0acad9 Disable Webpack setImmediate polyfill for DevTools (#18860)
* Upgrade Webpack deps to latet

* Disable Webpack setImmediate polyfill
2020-05-07 13:13:47 -07:00
Sebastian Markbåge
edf6eac8a1 Don't cut off the tail of a SuspenseList if hydrating (#18854) 2020-05-06 23:51:46 -07:00
Sebastian Markbåge
55f5cdee01 Disable setState before mount in legacy mode (#18851)
We kind of "support" this pattern in legacy mode. It's only deprecated in
Concurrent Mode.
2020-05-06 20:30:59 -07:00
Andrew Clark
47ebc90b08 Put render phase update change behind a flag (#18850)
In the new reconciler, I made a change to how render phase updates
work. (By render phase updates, I mean when a component updates
another component during its render phase. Or when a class component
updates itself during the render phase. It does not include when
a hook updates its own component during the render phase. Those have
their own semantics. So really I mean anything triggers the "`setState`
in render" warning.)

The old behavior is to give the update the same "thread" (expiration
time) as whatever is currently rendering. So if you call `setState` on a
component that happens later in the same render, it will flush during
that render. Ideally, we want to remove the special case and treat them
as if they came from an interleaved event.

Regardless, this pattern is not officially supported. This behavior is
only a fallback. The flag only exists until we can roll out the
`setState` warnning, since existing code might accidentally rely on the
current behavior.
2020-05-06 19:19:14 -07:00
Dominic Gannaway
6778c53c16 Modern Event System: fix bug in EnterLeave (#18849) 2020-05-07 00:13:13 +01:00
Brian Vaughn
7eaa1d7e33 Updated DevTools unstable_ API references (#18847) 2020-05-06 11:14:30 -07:00
Andrew Clark
a71aa803a1 [Release] Follow redirect when downloading tarball (#18845)
Adds -L option to `curl` command.

See: https://curl.haxx.se/docs/manpage.html#-L
2020-05-06 10:28:49 -07:00
Sebastian Markbåge
96f3b7d1c3 Warn if calling setState outside of render but before commit (#18838)
* Don't attempt to render the children of a dehydrated Suspense boundary

The DehydratedFragment tag doesn't exist so doing so throws.

This can happen if we schedule childExpirationTime on the boundary and
bail out.

* Warn if scheduling work on a component before it is committed
2020-05-06 09:45:35 -07:00
Dan Abramov
33c3af284c [Blocks Fixture] Remove remaining Blocks (#18840) 2020-05-06 15:53:51 +01:00
Dan Abramov
595d27bd73 [Blocks Fixture] Drop the Blocks (#18837)
* [Blocks Fixture] Add a tiny router

* Add a way to load nested entrypoint

* Only expose URL params to nested routers

* Add keys to route definitions

* [Blocks Fixture] Drop the Blocks
2020-05-06 05:17:44 +01:00
Dominic Gannaway
823dc581fe Modern Event System: fix EnterLeave plugin logic (#18830) 2020-05-05 22:10:07 +01:00
Fernando Lores
40e6029462 wrap SuspenseInstanceRetry callback so scheduler waits for it (#18805) 2020-05-05 12:47:49 -07:00
Brian Vaughn
3cde22a84e Experimental test selector API (#18607)
Adds several new experimental APIs to aid with automated testing.

Each of the methods below accepts an array of "selectors" that identifies a path (or paths) through a React tree. There are four basic selector types:

* Component: Matches Fibers with the specified React component type
* Role: Matches Host Instances matching the (explicit or implicit) accessibility role.
* Test name: Matches Host Instances with a data-testname attribute.
* Text: Matches Host Instances that directly contain the specified text.
* There is also a special lookahead selector type that enables further matching within a path (without actually including the path in the result). This selector type was inspired by the :has() CSS pseudo-class. It enables e.g. matching a <section> that contained a specific header text, then finding a like button within that <section>.

API
* findAllNodes(): Finds all Host Instances (e.g. HTMLElement) within a host subtree that match the specified selector criteria.
* getFindAllNodesFailureDescription(): Returns an error string describing the matched and unmatched portions of the selector query.
* findBoundingRects(): For all React components within a host subtree that match the specified selector criteria, return a set of bounding boxes that covers the bounds of the nearest (shallowed) Host Instances within those trees.
* observeVisibleRects(): For all React components within a host subtree that match the specified selector criteria, observe if it’s bounding rect is visible in the viewport and is not occluded.
* focusWithin(): For all React components within a host subtree that match the specified selector criteria, set focus within the first focusable Host Instance (as if you started before this component in the tree and moved focus forwards one step).
2020-05-05 10:37:46 -07:00
Dan Abramov
c13a59c7d6 Fix Blocks fixture 2020-05-05 18:14:06 +01:00
Kevin Lewis
7992ca10df eslint-plugin-react-hooks: allow OptionalMemberExpression in deps (#18819) (#18820)
* eslint-plugin-react-hooks: allow OptionalMemberExpression in deps (#18819)

* add test case for #18819

* fix test

* run prettier
2020-05-05 13:53:42 +01:00
Dominic Gannaway
e028ce2ab7 Modern Event System: ensure target ancestors are only host nodes (#18827) 2020-05-05 13:10:05 +01:00
Dan Abramov
4d124a4f67 [Blocks Fixture] Misc updates (#18811)
* [Blocks Fixture] Update navigation buttons immediately

* Add more profile links

* Minor refactor

* Add subroutes to Profile
2020-05-05 11:53:02 +01:00
Andrew Clark
fe7163e73d Add unstable prefix to experimental APIs (#18825)
We've been shipping unprefixed experimental APIs (like `createRoot` and
`useTransition`) to the Experimental release channel, with the rationale
that because these APIs do not appear in any stable release, we're free
to change or remove them later without breaking any downstream projects.

What we didn't consider is that downstream projects might be tempted to
use feature detection:

```js
const useTransition = React.useTransition || fallbackUseTransition;
```

This pattern assumes that the version of `useTransition` that exists in
the Experimental channel today has the same API contract as the final
`useTransition` API that we'll eventually ship to stable.

To discourage feature detection, I've added an `unstable_` prefix to
all of our unstable APIs.

The Facebook builds still have the unprefixed APIs, though. We will
continue to support those; if we make any breaking changes, we'll
migrate the internal callers like we usually do. To make testing easier,
I added the `unstable_`-prefixed APIs to the www builds, too. That way
our tests can always use the prefixed ones without gating on the
release channel.
2020-05-04 22:25:41 -07:00
Sebastian Markbåge
cd4a96035f Remove old CM exports (#18710) 2020-05-04 21:39:57 -07:00
Dominic Gannaway
9751935abf Modern Event System: improve dispatching queue (#18799) 2020-05-04 16:55:45 +01:00
Dan Abramov
3e13d70984 [RN] Remove debugging invariant (#18813) 2020-05-04 15:48:35 +01:00
Dan Abramov
f6fcae58e9 [Blocks] Add Shell to Fixture (#18803)
* [Blocks] Add Feed page to fixture

* Add minimal routing

* Always show post with comments
2020-05-04 01:59:55 +01:00
Dan Abramov
d830cd9984 [Blocks] Fix stale data on updates (#18810)
* [Blocks] Failing test for nested load

* Simplify the test

* Add a similar test that fails in PROD

* Copy .type when cloning work in progress
2020-05-04 01:43:51 +01:00
Sebastian Markbåge
64d4b84204 Rename Flight to Transport (#18808)
* Rename Flight to Transport

Flight is still the codename for the implementation details (like Fiber).

However, now the public package is react-transport-... which is only
intended to be used directly by integrators.

* Rename names
2020-05-03 11:33:48 -07:00
Andrew Clark
93e078ddf2 Initial Lanes implementation (#18796)
See PR #18796 for more information.

All of the changes I've made in this commit are behind the
`enableNewReconciler` flag. Merging this to master will not affect the
open source builds or the build that we ship to Facebook.

The only build that is affected is the `ReactDOMForked` build, which is
deployed to Facebook **behind an experimental flag (currently disabled
for all users)**. We will use this flag to gradually roll out the new
reconciler, and quickly roll it back if we find any problems.

Because we have those protections in place, what I'm aiming for with
this initial PR is the **smallest possible atomic change that lands
cleanly and doesn't rely on too many hacks**. The goal has not been to
get every single test or feature passing, and it definitely is not to
implement all the features that we intend to build on top of the new
model. When possible, I have chosen to preserve existing semantics and
defer changes to follow-up steps. (Listed in the section below.)

(I did not end up having to disable any tests, although if I had, that
should not have necessarily been a merge blocker.)

For example, even though one of the primary goals of this project is to
improve our model for parallel Suspense transitions, in this initial
implementation, I have chosen to keep the same core heuristics for
sequencing and flushing that existed in the ExpirationTimes model: low
priority updates cannot finish without also finishing high priority
ones.

Despite all these precautions, **because the scope of this refactor is
inherently large, I do expect we will find regressions.** The flip side
is that I also expect the new model to improve the stability of the
codebase and make it easier to fix bugs when they arise.
2020-05-02 17:09:31 -07:00
Moti Zilberman
3c7d52c3d6 Give unresolved lazy() a name in component stack (#16104)
* Give unresolved lazy() a name in component stack

* Normalize stack in tests

Co-authored-by: Sebastian Markbage <sema@fb.com>
2020-05-01 16:41:39 -07:00
Benedikt Franke
333deb707d Remove hint to post feedback about exhaustive-deps rule (#18712)
The thread is closed and locked.
2020-05-01 19:13:59 +01:00
Dominic Gannaway
aa88589d0b Refine experimental Scopes API (#18778)
* Refine experimental Scopes API
2020-05-01 19:01:43 +01:00
Dan Abramov
d804f99b9e eslint-plugin-react-hooks@4.0.0 2020-05-01 17:13:56 +01:00
Dan Abramov
4e93b9364c Add changelog for eslint-plugin-react-hooks (#18801) 2020-05-01 17:12:32 +01:00
Aaron Pettengill
5ac9ca72df Feature: Add support to exhaustive-deps rule for any hook ending with Effect (#18580)
* Add test cases for support exhaustive deps ending in Effect

* Apply the exhaustive deps lint rule to any hook ending with Effect

* Add another test for supporting linting useXEffect hooks

Co-authored-by: Aaron Pettengill <aaron.pettengill@echoman.com>
2020-05-01 16:57:25 +01:00
Dan Abramov
eab94403d7 Build Flight runtime for WWW (revert part of earlier change) 2020-05-01 16:44:25 +01:00
Sebastian Markbåge
17dcc29cd1 Don't "schedule" discrete work if we're scheduling sync work (#18797) 2020-05-01 08:43:15 -07:00
Dan Abramov
9491f39472 react-refresh@0.8.2 2020-05-01 16:18:13 +01:00
Dan Abramov
43a1c72751 Don't build react-data for WWW 2020-05-01 16:13:11 +01:00
Dan Abramov
01914a7673 Update bundle configs to not build some packages (#18800)
* Stop building old ReactCache for FB

* Update other bundle configs
2020-05-01 16:07:36 +01:00
Sophie Alpert
21670cf4be [react-refresh/babel] Always insert registrations after var (#18794)
Previously, we transformed

```
let Foo = styled.div``;
```

to

```
let Foo = _c1 = styled.div``;
```

and then babel-plugin-styled-components would infer `_c1` as the display name. Widen the existing case that applies to function expressions to apply to any type of variable declaration.
2020-05-01 16:01:11 +01:00
Andrew Clark
914b57be27 Move legacy hidden API to new internal Fiber type (#18782)
* Unhide Suspense trees without entanglement

When a Suspense boundary is in its fallback state, you cannot switch
back to the main content without also finishing any updates inside the
tree that might have been skipped. That would be a form of tearing.

Before we fixed this in #18411, the way this bug manifested was that a
boundary was suspended by an update that originated from a child
component (as opposed to props from a parent). While the fallback was
showing, it received another update, this time at high priority. React
would render the high priority update without also including the
original update. That would cause the fallback to switch back to the
main content, since the update that caused the tree to suspend was no
longer part of the render. But then, React would immediately try to
render the original update, which would again suspend and show the
fallback, leading to a momentary flicker in the UI.

The approach added in #18411 is, when receiving a high priority update
to a Suspense tree that's in its fallback state is to bail out, keep
showing the fallback and finish the update in the rest of the tree.
After that commits, render again at the original priority. Because low
priority expiration times are inclusive of higher priority expiration
times, this ensures that all the updates are committed together.

The new approach in this commit is to turn `renderExpirationTime` into a
context-like value that lives on the stack. Then, when unhiding the
Suspense boundary, we can push a new `renderExpirationTime` that is
inclusive of both the high pri update and the original update that
suspended. Then the boundary can be unblocked in a single render pass.

An advantage of the old approach is that by deferring the work of
unhiding, there's less work to do in the high priority update.

The key advantage of the new approach is that it solves the consistency
problem without having to entangle the entire root.

* Create internal LegacyHidden type

This only exists so we can clean up the internal implementation of
`<div hidden={isHidden} />`, which is not a stable feature. The goal
is to move everything to the new Offscreen type instead. However,
Offscreen has different semantics, so before we can remove the legacy
API, we have to migrate our internal usage at Facebook. So we'll need
to maintain both temporarily.

In this initial commit, I've only added the type. It's not used
anywhere. The next step is to use it to implement `hidden`.

* Use LegacyHidden to implement old hidden API

If a host component receives a `hidden` prop, we wrap its children in
an Offscreen fiber. This is similar to what we do for Suspense children.

The LegacyHidden type happens to share the same implementation as the
new Offscreen type, for now, but using separate types allows us to fork
the behavior later when we implement our planned changes to the
Offscreen API.

There are two subtle semantic changes here. One is that the children of
the host component will have their visibility toggled using the same
mechanism we use for Offscreen and Suspense: find the nearest host node
children and give them a style of `display: none`. We didn't used to do
this in the old API, because the `hidden` DOM attribute on the parent
already hides them. So with this change, we're actually "overhiding" the
children. I considered addressing this, but I figure I'll leave it as-is
in case we want to expose the LegacyHidden component type temporarily
to ease migration of Facebook's internal callers to the Offscreen type.

The other subtle semantic change is that, because of the extra fiber
that wraps around the children, this pattern will cause the children
to lose state:

```js
return isHidden ? <div hidden={true} /> : <div />;
```

The reason is that I didn't want to wrap every single host component
in an extra fiber. So I only wrap them if a `hidden` prop exists. In
the above example, that means the children are conditionally wrapped
in an extra fiber, so they don't line up during reconciliation, so
they get remounted every time `isHidden` changes.

The fix is to rewrite to:

```js
return <div hidden={isHidden} />;
```

I don't anticipate this will be a problem at Facebook, especially since
we're only supposed to use `hidden` via a userspace wrapper component.
(And since the bad pattern isn't very React-y, anyway.)

Again, the eventual goal is to delete this completely and replace it
with Offscreen.
2020-04-30 19:37:27 -07:00
Brian Vaughn
ac533fde3d Prevent stale legacy root from clearing a container (DRAFT) (#18792)
* Don't clear a container because of a stale legacy root

* Added test repro for FB error
2020-04-30 15:56:21 -07:00
Dan Abramov
5b89d353e2 Update react-refresh README 2020-04-30 15:43:21 +01:00
Dan Abramov
3a9c373521 [Blocks] Add preload to fetch (#18785) 2020-04-30 02:23:18 +01:00
Dan Abramov
dd7f0deb94 [Blocks] Use native fetch (#18784)
* [Blocks] Use native fetch

* Use the prototype

* Support arrayBuffer() and blob()

* ctor

* Simplify

* Use an expando

* Keep a map of formats

* Unused

* Remove unnecessary second property read

* Keep it simple

* Store the original thenable
2020-04-30 01:24:04 +01:00
Alex Taylor
e71f5df9c3 Consistent useCallback implementation in ReactDOMServer (#18783) 2020-04-29 16:22:10 -07:00
Dan Abramov
515326753b [Blocks] Initial implementation of cache and data/fetch (#18774)
* Rename ReactCache -> ReactCacheOld

We still use it in some tests so I'm going to leave it for now. I'll start making the new one in parallel in the react package.

* Add react/unstable-cache entry point

* Add react-data entry point

* Initial implementation of cache and data/fetch

* Address review
2020-04-29 19:14:15 +01:00
Dan Abramov
53d68b33ff [Blocks] Add Client Fixture (#18773)
* [Blocks] Add Client Fixture

* Add more TODOs
2020-04-29 02:23:09 +01:00
Dominic Gannaway
88d0be6da5 Refactor ElementListenerMap (#18766) 2020-04-28 21:53:51 +01:00
Brian Vaughn
ea2af878cc Root API should clear non-empty roots before mounting (#18730)
* Root API should clear non-empty roots before mounting

Legacy render-into-subtree API removes children from a container before rendering into it. The root API did not do this previously, but just left the children around in the document.

This commit adds a new FiberRoot flag to clear a container's contents before mounting. This is done during the commit phase, to avoid multiple, observable mutations.
2020-04-28 13:07:42 -07:00
Nick Reiley
d2ef120089 Allow Node 14.x (#18755) 2020-04-28 15:57:45 +01:00
Sebastian Markbåge
53ce0c3452 Allow flushSync to noop in life cycles but with a warning (#18759) 2020-04-27 20:07:39 -07:00
Andrew Clark
f342a2399f SuspenseList: Reschedule at same priority (#18738)
SuspenseList progressively renders items even if the list is CPU bound,
i.e. it isn't waiting for missing data. It does this by showing a
fallback for the remaining items, committing the items in that have
already finished, then starting a new render to continue working on
the rest.

When it schedules that subsequent render, it uses a slightly lower
priority than the current render: `renderExpirationTime - 1`.

This commit changes it to reschedule at `renderExpirationTime` instead.

I don't know what the original motivation was for bumping the expiration
time slightly lower. The comment says that the priorities of the two
renders are the same (which makes sense to me) so I imagine it was
motivated by some implementation detail. I don't think it's necessary
anymore, though perhaps it was when it was originally written. If it is
still necessary, we should write a test case that illustrates why.
2020-04-25 20:27:35 -07:00
Andrew Clark
cb70753993 Move hide/unhide logic to Offscreen component
The Offscreen component is not a public type, yet, but once it is, it
will share the same hide/unhide logic as Suspense children.
2020-04-25 00:10:09 -07:00
Andrew Clark
cb48f974c9 Wrap primary tree in Offscreen fiber type
Still just acts like a fragment. Next step is to move the hide/unhide
logic to the Offscreen implementation.
2020-04-25 00:10:09 -07:00
Luna Ruan
ed01fdacce Add Offscreen component type
Doesn't do anything special in this initial commit. Just acts like a
fragment.
2020-04-25 00:10:09 -07:00
Andrew Clark
1df756ba2c Always wrap Suspense children in fragment (#18711)
Changes the internal fiber structure of the Suspense component. When a
Suspense boundary can't finish rendering and switches to a fallback, we
wrap the "primary" tree in a Fragment fiber and hide all its DOM nodes.
Then we mount the fallback tree into a separate Fragment fiber. Both
trees will render into the same parent DOM node (since React fragments
aren't part of the host tree), but the wrappers ensure that the children
in each tree are reconciled separately.

The old implementation would try to be clever and only add the fragment
wrapper when the fallback was in place, to save memory. This "worked"
but was prone to regressions, since this is the only such place in the
codebase where we wrap existing nodes in a new node. (In other words,
it's a form of reparenting, which we don't implement elsewhere).

Since the original implementation, we've also added lots of additional
requirements to the Suspense component that have led to an explosion in
complexity, like limited support in Legacy Mode (with very different
semantics) and progressive hydration.

We're planning to add even more features to the Suspense boundary, so
we're going to sacrifice a bit more memory for a simpler implementation
that is less prone to regressions.

This ended up removing a lot of weird hacks and edge cases, but there
are still plenty left over. Most of the remaining complexity is related
to Legacy mode. That's the next thing we should aim to drop support for.

Because this is a risky change, I've only changed this in the new
reconciler. It blocks some other features, but as of now we're not
planning to implement those in the old reconciler. If that changes, this
should cherry-pick to the other implementation without much effort.
2020-04-25 00:09:19 -07:00
Andrew Clark
db6513914f Make ExpirationTime an opaque type (#18732)
* Add LanePriority type

React's internal scheduler has more priority levels than the external
Scheduler package. Let's use React as the source of truth for tracking
the priority of updates so we have more control. We'll still fall back
to Scheduler in the default case. In the future, we should consider
removing `runWithPriority` from Scheduler and replacing the valid use
cases with React-specific APIs.

This commit adds a new type, called a LanePriority to disambiguate from
the Scheduler one.

("Lane" refers to another type that I'm planning. It roughly translates
to "thread." Each lane will have a priority associated with it.)

I'm not actually using the lane anywhere, yet. Only setting stuff up.

* Remove expiration times train model

In the old reconciler, expiration times are computed by applying an
offset to the current system time. This has the effect of increasing
the priority of updates as time progresses. Because we also use
expiration times as a kind of "thread" identifier, it turns out this
is quite limiting because we can only flush work sequentially along
the timeline.

The new model will use a bitmask to represent parallel threads that
can be worked on in any combination and in any order.

In this commit, expiration times and the linear timeline are still in
place, but they are no longer based on a timestamp. Effectively, they
are constants based on their priority level.

* Stop using ExpirationTime to represent timestamps

Follow up to the previous commit. This converts the remaining places
where we were using the ExpirationTime type to represent a timestamp,
like Suspense timeouts.

* Fork Dependencies and PendingInteractionMap types

These contain expiration times

* Make ExpirationTime an opaque type

ExpirationTime is currently just an alias for the `number` type, for a
few reasons. One is that it predates Flow's opaque type feature. Another
is that making it opaque means we have to move all our comparisons and
number math to the ExpirationTime module, and use utility functions
everywhere else.

However, this is actually what we want in the new system, because the
Lanes type that will replace ExpirationTime is a bitmask with a
particular layout, and performing operations on it will involve more
than just number comparisions and artihmetic. I don't want this logic to
spread ad hoc around the whole codebase.

The utility functions get inlined by Closure so it doesn't matter
performance-wise.

I automated most of the changes with JSCodeshift, with only a few manual
tweaks to stuff like imports. My goal was to port the logic exactly to
prevent subtle mistakes, without trying to simplify anything in the
process. I'll likely need to audit many of these sites again when I
replace them with the new type, though, especially the ones
in ReactFiberRoot.

I added the codemods I used to the `scripts` directory. I won't merge
these to master. I'll remove them in a subsequent commit. I'm only
committing them here so they show up in the PR for future reference.

I had a lot of trouble getting Flow to pass. Somehow it was not
inferring the correct type of the constants exported from the
ExpirationTime module, despite being annotated correctly.

I tried converting them them to constructor functions — `NoWork`
becomes `NoWork()` — and that made it work. I used that to unblock me,
and fixed all the other type errors. Once there were no more type
errors, I tried converting the constructors back to constants. Started
getting errors again.

Then I added a type constraint everywhere a constant was referenced.
That fixed it. I also figured out that you only have to add a constraint
when the constant is passed to another function, even if the function is
annotated. So this indicates to me that it's probably a Flow bug. I'll
file an issue with Flow.

* Delete temporary codemods used in previous commit

I only added these to the previous commit so that I can easily run it
again when rebasing. When the stack is squashed, it will be as if they
never existed.
2020-04-24 23:26:04 -07:00
Chang Yan
4b02b66111 [ESLint] Extend isHook to recognize those under PascalCase's namespace (#18722)
* Extend Namespace to PascalCase

* Add valid case for jest.useFakeTimer

* format

* format :(

* fix nits
2020-04-24 02:50:52 +01:00
Dominic Gannaway
30cee2f4c7 Modern Event System: register onMouseEnter for portals (#18720) 2020-04-23 20:57:52 +01:00
Dominic Gannaway
4e3545fd6f ReactDOMEventListener: clean up module (#18713) 2020-04-23 20:19:28 +01:00
Sebastian Markbåge
b58dec979a Remove unnecessary stack (#18707) 2020-04-23 09:44:37 -07:00
Sebastian Markbåge
a2fb84bebd Disable prepareStackTrace while we're generating stacks (#18708)
This could be used to do custom formatting of the stack trace in a way
that isn't compatible with how we use it. So we disable it while we use
it.

In theory we could call this ourselves with the result of our stack.
It would be a lot of extra production code though. My personal opinion
is that this should always be done server side instead of on the client.

We could expose a custom parser that converts it and passes it through
prepareStackTrace as structured data. That way it's external and doesn't
have to be built-in to React.
2020-04-23 09:16:58 -07:00
Brian Vaughn
b9fc3d8d59 DevTools temporarily disable prepareStackTrace before creating custom component stacks (#18717) 2020-04-23 09:02:42 -07:00
Sebastian Markbåge
b0cb137bcb Don't dedupe using the stack (#18693)
We currently use the stack to dedupe warnings in a couple of places.
This is a very heavy weight way of computing that a warning doesn't need
to be fired.

This uses parent component name as a heuristic for deduping. It's not
perfect but as soon as you fix one you'll uncover the next. It might be a
little annoying but having many logs is also annoying.

We now have no special cases for stacks. The only thing that uses stacks in
dev is the console.error and dev tools. This means that we could
externalize this completely to an console.error patching module and drop
it from being built-in to react.

The only prod/dev behavior is the one we pass to error boundaries or the
error we throw if you don't have an error boundary.
2020-04-22 19:02:11 -07:00
Sebastian Markbåge
571f5ad2d6 Temporarily Remove DebugTracing from the New Reconciler (#18697)
* Remove priority field from tracing

* Remove DebugTracing mode from new reconciler (temporarily)

* Run DebugTracing tests in the *other* variant so it's no on for new reconciler
2020-04-21 20:14:40 -07:00
Sebastian Markbåge
2325375f4f Nit: add suffix _TIMEOUT consistently in scheduler (#18696) 2020-04-21 19:44:42 -07:00
Nick Reiley
e5cc1462b3 Fix mistyped script arbitrary code execution vulnerability (#18660)
* add test to trustedTypes-test.internal.js

* fix mistyped script arbitrary code execution

* Removed redundant .toLowerCase() call

Co-authored-by: Brian Vaughn <brian.david.vaughn@gmail.com>
2020-04-21 12:10:25 -07:00
Brian Vaughn
9025949d84 Pin RNW to canary (#18692)
This unbreaks DevTools shell with the latest ReactDOM in master.
2020-04-21 11:46:29 -07:00
Brian Vaughn
36cab2720a DevTools: Improved "native" component stacks (#18656)
* DevTools console override handles new component stack format

DevTools does not attempt to mimic the default browser console format for its component stacks but it does properly detect the new format for Chrome, Firefox, and Safari.
2020-04-21 11:46:11 -07:00
Sebastian Markbåge
940f48b999 Avoid passing custom stacks to console.error (#18685)
* Detect double stacks in the new format in tests

* Remove unnecessary uses of getStackByFiberInDevAndProd

These all execute in the right execution context already.

* Set the debug fiber around the cases that don't have an execution context

* Remove stack detection in our console log overrides

We never pass custom stacks as part of the args anymore.

* Bonus: Don't append getStackAddendum to invariants

We print component stacks for every error anyway so this is just duplicate
information.
2020-04-21 09:22:46 -07:00
Dominic Gannaway
ff431b7fc4 Remove ReactDOM.useEvent and associated types+tests (#18689) 2020-04-21 16:40:44 +01:00
Dominic Gannaway
7b3934b34f Revert "Pressable click fix (#18625)" (#18688)
This reverts commit 5f7b175b35.
2020-04-21 11:08:30 +01:00
Dominic Gannaway
80d39d8b57 Remove null sibling (#18687) 2020-04-21 10:43:50 +01:00
Sebastian Markbåge
0960b7ba58 Upgrade fbjs-scripts (#18684)
* Upgrade fbjs-scripts

This script takes into account the NODE_ENV as part of jest cache keys.
This avoids flaky tests since we depend on different transforms in prod
and dev.

* Upgrade Fresh test to Babel 7 transform
2020-04-20 18:20:03 -07:00
Naman Goel
5f7b175b35 Pressable click fix (#18625)
* Update press-legacy to use native click events

* update tests for pressable change

* fix formatting issue

* Address comments. Bring back some tests, remove others. Cleanup

* Fix flow and lint errors

* formatting fix missed by yarn lint
2020-04-20 23:13:17 +01:00
Dominic Gannaway
4f59a149b8 Modern event system: fix selectionchange bug (#18680) 2020-04-20 19:54:12 +01:00
Dominic Gannaway
a152827ef6 Refine the heuristics around beforeblur/afterblur (#18668)
* Refine the heuristics around beforeblur/afterblur
2020-04-20 19:32:22 +01:00
Sebastian Silbermann
707478e68a chore: Build react-dom/server in codesandbox CI (#18679) 2020-04-20 18:48:07 +01:00
Sebastian Silbermann
ffb6c6c07b fix: skip dangerouslySetInnerHtml hydration warning if it's undefined (#18676)
* test: Add failing case for dangerouslySetInnerHtml=undefined

* fix: skip dangerouslySetInnerHtml warning if it's undefined

* test: add similar test that should trigger the warning

* chore: Remove redundant nullish check

* Poke yarn_test_www_variant which timed out

* test: Add smaller test for innerHTML=string to innerHTML=undefined
2020-04-20 18:46:55 +01:00
Dominic Gannaway
1078029af6 Revert "Revert focus event PRs (#18655)" (#18671)
This reverts commit 58c895e59c.
2020-04-20 16:00:33 +01:00
Nicolas Gallagher
96203240d3 ReactDOM: remove unstable-native-dependencies bundle (#18483)
This is only used by react-native-web and will be replaced by a user-space
implementation. See: https://github.com/necolas/react-native-web/issues/1568
2020-04-18 15:40:13 -07:00
Brian Vaughn
263bc5d54b Fix incorrect unmounted state update warning (#18617)
* Fix incorrect unmounted state update warning

We detach fibers (which nulls the  field) when we commit a deletion, so any state updates scheduled between that point and when we eventually flush passive effect destroys won't have a way to check if there is a pending passive unmount effect scheduled for its alternate unless we also explicitly track this for both the current and the alternate.

This commit adds a new DEV-only effect type, `PendingPassiveUnmountDev`, to handle this case.
2020-04-18 12:18:19 -07:00
Andrew Clark
52a0d6b5ab Make Flow work with your editor (#18664)
We typecheck the reconciler against each one of our host configs.
`yarn flow dom` checks it against the DOM renderer, `yarn flow native`
checks it against the native renderer, and so on.

To do this, we generate separate flowconfig files.

Currently, there is no root-level host config, so running Flow
directly via `flow` CLI doesn't work. You have to use the `yarn flow`
command and pick a specific renderer.

A drawback of this design, though, is that our Flow setup doesn't work
with other tooling. Namely, editor integrations.

I think the intent of this was maybe so you don't run Flow against a
renderer than you intended, see it pass, and wrongly think you fixed
all the errors. However, since they all run in CI, I don't think this
is a big deal. In practice, I nearly always run Flow against the same
renderer (DOM), and I'm guessing that's the most common workflow for
others, too.

So what I've done in this commit is modify the `yarn flow` command to
copy the generated `.flowconfig` file into the root directory. The
editor integration will pick this up and show Flow information for
whatever was the last renderer you checked.

Everything else about the setup is the same, and all the renderers will
continue to be checked by CI.
2020-04-18 10:24:46 -07:00
Andrew Clark
cfefc81ab2 Fix for #18657 (#18663)
* Failing test for #18657

* Remove incorrect priority check

I think this was just poor factoring on my part in #18411. Honestly it
doesn't make much sense to me, but my best guess is that I must have
thought that when `baseTime > currentChildExpirationTime`, the function
would fall through to the
`currentChildExpirationTime < renderExpirationTime` branch below.

Really I think just made an oopsie.

Regardless, this logic is galaxy brainéd. A goal of the Lanes refactor
I'm working on is to make these types of checks -- is there remaining
work in this tree? -- a lot easier to think about. Hopefully.
2020-04-17 16:32:55 -07:00
Dominic Gannaway
e7163a9c2f Revise isFiberInsideHiddenOrRemovedTree (#18662) 2020-04-17 23:58:40 +01:00
Andrew Clark
a4b1e65afc Remove redundant expiration time comparisons (#18620)
I'm going through all the expiration times comparisons as part of my
refactor and I noticed this one has a redundancy.
2020-04-17 11:48:05 -07:00
Dominic Gannaway
58c895e59c Revert focus event PRs (#18655)
* Revert "Further cleanup to before/after blur (#18649)"

This reverts commit e2ccbf0358.

* Revert "Unify Flare FocusWithin responder with useFocusWithin (#18636)"

This reverts commit f24a9e7098.
2020-04-17 16:27:19 +01:00
Dominic Gannaway
e2ccbf0358 Further cleanup to before/after blur (#18649) 2020-04-17 11:52:29 +01:00
Brian Vaughn
c5c25d35a3 Fixed DevTools extension build:dev command (#18648) 2020-04-16 17:39:16 -07:00
dependabot[bot]
f8b084276d Bump https-proxy-agent from 2.2.1 to 2.2.4 in /scripts/release (#18642)
Bumps [https-proxy-agent](https://github.com/TooTallNate/node-https-proxy-agent) from 2.2.1 to 2.2.4.
- [Release notes](https://github.com/TooTallNate/node-https-proxy-agent/releases)
- [Commits](https://github.com/TooTallNate/node-https-proxy-agent/compare/2.2.1...2.2.4)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2020-04-16 16:06:13 -07:00
dependabot[bot]
0f9b30f7b5 Bump https-proxy-agent from 2.2.2 to 2.2.4 (#18643)
Bumps [https-proxy-agent](https://github.com/TooTallNate/node-https-proxy-agent) from 2.2.2 to 2.2.4.
- [Release notes](https://github.com/TooTallNate/node-https-proxy-agent/releases)
- [Commits](https://github.com/TooTallNate/node-https-proxy-agent/compare/2.2.2...2.2.4)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2020-04-16 16:06:06 -07:00
Dominic Gannaway
32bb44c80a Clean up modern plugins to remove dead code (#18639) 2020-04-16 20:10:23 +01:00
Dan Abramov
0301f3e24f Statically disable factory components for WWW (#18641) 2020-04-16 19:42:30 +01:00
Dominic Gannaway
f24a9e7098 Unify Flare FocusWithin responder with useFocusWithin (#18636) 2020-04-16 19:35:41 +01:00
Dominic Gannaway
b1a083183c Revert legacy plugin modules (#18638) 2020-04-16 18:46:24 +01:00
Dominic Gannaway
31977d1bb3 Create copy of Legacy event plugins for Modern system (#18637) 2020-04-16 16:09:05 +01:00
Andrew Clark
c12c2c4c8c Run error replay test again new reconciler (#18628)
This is one of our few tests of an internal function. Need to import
the module that corresponds to the reconciler that's being tested.
2020-04-16 08:08:22 -07:00
Boris Serdiuk
7b4403cecd Fix requiring timers module with non standard require (#18632)
fixes #18589
2020-04-16 12:36:09 +01:00
Thomas Brown
5f6b75dd26 ADD: disableRemotePlayback attribute for HTML5 videos (#18619)
* Add support for disableremoteplayback

* Order attributes alphabetically

Co-authored-by: Tom Brown <Thomas.Brown-CIC-UK@ibm.com>
2020-04-16 10:23:48 +01:00
Brian Vaughn
71964c0346 Fix CI (#18626) 2020-04-15 22:27:24 -07:00
Andrew Clark
50b9f154c1 Fix wrong command in config.yml (#18624) 2020-04-15 21:44:38 -07:00
Brian Vaughn
22dc2e42bd Add experimental DebugTracing logger for internal use (#18531) 2020-04-15 19:10:15 -07:00
Andrew Clark
dbd2626855 Update nvmrc to the same one used in CI (#18623) 2020-04-15 16:03:02 -07:00
Andrew Clark
b680174841 Delete mutableSourceFirstPendingUpdateTime (#18613) 2020-04-15 07:47:37 -07:00
Andrew Clark
cbafbf4f32 Fix typo in TestFlags
Copypasta when setting up `old` and `new` aliases. `old` should mean
that `enableNewReconciler` is off.
2020-04-14 23:32:53 -07:00
Dominic Gannaway
d53988a9d1 ReactDOM.useEvent: add useEvent interaction hook (#18604) 2020-04-14 22:06:46 +01:00
Dominic Gannaway
bf55ea7434 Move beforeblur phase to prepareForCommit (#18609) 2020-04-14 21:30:54 +01:00
Andrew Clark
843b50cbe1 Remove .internal from more test suites (#18597) 2020-04-14 07:43:00 -07:00
BetaSu
1d7bd52688 remove unnecessary variable comparation (#18598)
Since it will continue when the props are equal in line 767, there is no need to compare whether they are not equal.
2020-04-14 14:53:47 +01:00
Andrew Clark
b928fc030a Delete flushSuspenseFallbacksInTests flag (#18596)
* Move renderer `act` to work loop

* Delete `flushSuspenseFallbacksInTests`

This was meant to be a temporary hack to unblock the `act` work, but it
quickly spread throughout our tests.

What it's meant to do is force fallbacks to flush inside `act` even in
Concurrent Mode. It does this by wrapping the `setTimeout` call in a
check to see if it's in an `act` context. If so, it skips the delay and
immediately commits the fallback.

Really this is only meant for our internal React tests that need to
incrementally render. Nobody outside our team (and Relay) needs to do
that, yet. Even if/when we do support that, it may or may not be with
the same `flushAndYield` pattern we use internally.

However, even for our internal purposes, the behavior isn't right
because a really common reason we flush work incrementally is to make
assertions on the "suspended" state, before the fallback has committed.
There's no way to do that from inside `act` with the behavior of this
flag, because it causes the fallback to immediately commit. This has led
us to *not* use `act` in a lot of our tests, or to write code that
doesn't match what would actually happen in a real environment.

What we really want is for the fallbacks to be flushed at the *end` of
the `act` scope. Not within it.

This only affects the noop and test renderer versions of `act`, which
are implemented inside the reconciler. Whereas `ReactTestUtils.act` is
implemented in "userspace" for backwards compatibility. This is fine
because we didn't have any DOM Suspense tests that relied on this flag;
they all use test renderer or noop.

In the future, we'll probably want to move always use the reconciler
implementation of `act`. It will not affect the prod bundle, because we
currently only plan to support `act` in dev. Though we still haven't
completely figured that out. However, regardless of whether we support a
production `act` for users, we'll still need to write internal React
tests in production mode. For that use case, we'll likely add our own
internal version of `act` that assumes a mock Scheduler and might rely
on hacks that don't 100% align up with the public one.
2020-04-13 20:02:18 -07:00
Andrew Clark
f3f3d77c20 Fix www tests not running in prod (#18593)
I made a mistake when setting these up a while ago. Setting the NODE_ENV
in the CircleCI config doesn't work because it's also set in the node
script command.

The number of test commands is getting out of control. Might need to fix
it at some point. Not today for me.
2020-04-13 15:53:13 -07:00
Andrew Clark
bec7599067 Migrate conditional tests to gate pragma (#18585)
* Migrate conditional tests to gate pragma

I searched through the codebase for this pattern:

```js
describe('test suite', () => {
  if (!__EXPERIMENTAL__) { // or some other condition
    test("empty test so Jest doesn't complain", () => {});
    return;
  }

  // Unless we're in experimental mode, none of the tests in this block
  // will run.
})
```

and converted them to the `@gate` pragma instead.

The reason this pattern isn't preferred is because you end up disabling
more tests than you need to.

* Add flag for www release channels

Using a heuristic where I check a flag that is known to only be enabled
in www. I left a TODO to instead set the release channel explicitly in
each test config.
2020-04-13 14:45:52 -07:00
Chris Dobson
6c43a62c0f DevTools: Switch between "Rendered At" renders using keyboard arrow keys (#18586)
* Add keyboard navigation to fibre info sidebar

Co-authored-by: Brian Vaughn <brian.david.vaughn@gmail.com>
2020-04-13 13:00:13 -07:00
Andrew Clark
0c3c27a718 Fix "missing flag" error for non-boolean types (#18592)
Not all test flags are booleans, e.g. the build type
2020-04-13 12:57:31 -07:00
Andrew Clark
65237a237e Codemod it.experimental to gate pragma (#18582)
* Codemod it.experimental to gate pragma

Find-and-replace followed by Prettier

* Delete it.experimental

Removes the API from our test setup script
2020-04-13 10:28:59 -07:00
Andrew Clark
42d7c2e8f7 Add pragma for feature testing: @gate (#18581)
* Add pragma for feature testing: @gate

The `@gate` pragma declares under which conditions a test is expected to
pass.

If the gate condition passes, then the test runs normally (same as if
there were no pragma).

If the conditional fails, then the test runs and is *expected to fail*.

An alternative to `it.experimental` and similar proposals.

Examples
--------

Basic:

```js
// @gate enableBlocksAPI
test('passes only if Blocks API is available', () => {/*...*/})
```

Negation:

```js
// @gate !disableLegacyContext
test('depends on a deprecated feature', () => {/*...*/})
```

Multiple flags:

```js
// @gate enableNewReconciler
// @gate experimental
test('needs both useEvent and Blocks', () => {/*...*/})
```

Logical operators (yes, I'm sorry):

```js
// @gate experimental && (enableNewReconciler || disableSchedulerTimeoutBasedOnReactExpirationTime)
test('concurrent mode, doesn\'t work in old fork unless Scheduler timeout flag is disabled', () => {/*...*/})
```

Strings, and comparion operators

No use case yet but I figure eventually we'd use this to gate on
different release channels:

```js
// @gate channel ===  "experimental" || channel === "modern"
test('works in OSS experimental or www modern', () => {/*...*/})
```

How does it work?

I'm guessing those last two examples might be controversial. Supporting
those cases did require implementing a mini-parser.

The output of the transform is very straightforward, though.

Input:
```js
// @gate a && (b || c)
test('some test', () => {/*...*/})
```

Output:

```js
_test_gate(ctx => ctx.a && (ctx.b || ctx.c, 'some test'), () => {/*...*/});
```

It also works  with `it`, `it.only`, and `fit`. It leaves `it.skip` and
`xit` alone because those tests are disabled anyway.

`_test_gate` is a global method that I set up in our Jest config. It
works about the same as the existing `it.experimental` helper.

The context (`ctx`) argument is whatever we want it to be. I set it up
so that it throws if you try to access a flag that doesn't exist. I also
added some shortcuts for common gating conditions, like `old`
and `new`:

```js
// @gate experimental
test('experimental feature', () => {/*...*/})

// @gate new
test('only passes in new reconciler', () => {/*...*/})
```

Why implement this as a pragma instead of a runtime API?

- Doesn't require monkey patching built-in Jest methods. Instead it
  compiles to a runtime function that composes Jest's API.
- Will be easy to upgrade if Jest ever overhauls their API or we switch
  to a different testing framework (unlikely but who knows).
- It feels lightweight so hopefully people won't feel gross using it.
  For example, adding or removing a gate pragma will never affect the
  indentation of the test, unlike if you wrapped the test in a
  conditional block.

* Compatibility with console error/warning tracking

We patch console.error and console.warning to track unexpected calls
in our tests. If there's an unexpected call, we usually throw inside
an `afterEach` hook. However, that's too late for tests that we
expect to fail, because our `_test_gate` runtime can't capture the
error. So I also check for unexpected calls inside `_test_gate`.

* Move test flags to dedicated file

Added some instructions for how the flags are set up and how to
use them.

* Add dynamic version of gate API

Receives same flags as the pragma.

If we ever decide to revert the pragma, we can codemod them to use
this instead.
2020-04-13 10:14:34 -07:00
Sebastian Markbåge
72d00ab623 Fix Component Stacks for IE and Native Classes in Safari (#18575)
* Add more edge cases to fixture

Also adjust some expectations. I think the column should ideally be 1 but varies.
The Example row is one line off because it throws on the hook but should ideally be the component.
Similarly class components with constructors may have the line in the constructor.

* Account for the construct call taking a stack frame

We do this by first searching for the first different frame, then find
the same frames and then find the first different frame again.

* Throw controls

Otherwise they don't get a stack frame associated with them in IE.

* Protect against generating stacks failing

Errors while generating stacks will bubble to the root. Since this technique
is a bit sketchy, we should probably protect against it.

* Don't construct the thing that throws

Instead, we pass the prototype as the "this". It's new every time anyway.
2020-04-10 19:39:02 -07:00
Sebastian Markbåge
98d410f500 Build Component Stacks from Native Stack Frames (#18561)
* Implement component stack extraction hack

* Normalize errors in tests

This drops the requirement to include owner to pass the test.

* Special case tests

* Add destructuring to force toObject which throws before the side-effects

This ensures that we don't double call yieldValue or advanceTime in tests.

Ideally we could use empty destructuring but ES lint doesn't like it.

* Cache the result in DEV

In DEV it's somewhat likely that we'll see many logs that add component
stacks. This could be slow so we cache the results of previous components.

* Fixture

* Add Reflect to lint

* Log if out of range.

* Fix special case when the function call throws in V8

In V8 we need to ignore the first line. Normally we would never get there
because the stacks would differ before that, but the stacks are the same if
we end up throwing at the same place as the control.
2020-04-10 13:32:12 -07:00
Brian Vaughn
8e13f099ab Overhauled release scripts and docs (#18569)
* Overhauled release scripts and docs
2020-04-10 12:28:40 -07:00
Andrew Clark
af1b039bdd ESLint rule to forbid cross fork imports (#18568)
Modules that belong to one fork should not import modules that belong to
the other fork.

Helps make sure you correctly update imports when syncing changes across
implementations.

Also could help protect against code size regressions that might happen
if one of the forks accidentally depends on two copies of the same
module.
2020-04-09 18:11:34 -07:00
Sebastian Markbåge
50bdd75a60 Bubble errors if processing the error itself errors (#18567)
If we've tried completing an incomplete boundary once and failed, we don't
need to try again.
2020-04-09 17:40:11 -07:00
Sebastian Markbåge
348ed0e93f Don't return from perform/completeUnitOfWork (#18566)
* Remove unnecessary workInProgress line

* Mutate workInProgress instead of returning

We were ambivalent about this before.

* Make handleError a void method too
2020-04-09 17:12:04 -07:00
Andrew Clark
b04c7fa28c Decouple expiration times and transition timeouts (#17920)
We currently use the expiration time to represent the timeout of a
transition. Since we intend to stop treating work priority as a
timeline, we can no longer use this trick.

In this commit, I've changed it to store the event time on the update
object instead. Long term, we will store event time on the root as a map
of transition -> event time. I'm only storing it on the update object
as a temporary workaround to unblock the rest of the changes.
2020-04-09 15:09:36 -07:00
Andrew Clark
dc630d3374 Fork ReactFiberExpirationTime
I had thought I wouldn't fork this one because the new "lanes" module
will be pretty different, but I need it to make some
incremental changes.
2020-04-09 15:09:34 -07:00
Dan Abramov
e5d06e34b6 Revert "Clear more Fiber fields in detachFiber (#18556)" (#18562)
This reverts commit d48dbb8249.
2020-04-09 20:45:02 +01:00
Sebastian Markbåge
cbab25bb51 Exclude forwardRef and memo from stack frames (#18559)
We can't patch the row. We could give these their own "built-in" stack
frame since they're conceptually HoCs. However, from a debugging
perspective this is not very useful meta data and quite noisy. So I'm
just going to exclude them.
2020-04-09 11:42:22 -07:00
Andrew Clark
26fc16484e Script for syncing changes between forks (#18550)
Adds command `yarn merge-fork`.

```sh
yarn merge-fork --base-dir=packages/react-reconciler/src ReactFiberWorkLoop
```

This will take all the changes in `ReactFiberWorkLoop.new.js` and apply
them to `ReactFiberWorkLoop.old.js`.

You can merge multiple modules at a time:

```sh
yarn merge-fork \
  --base-dir=packages/react-reconciler/src \
  ReactFiberWorkLoop \
  ReactFiberBeginWork \
  ReactFiberCompleteWork \
  ReactFiberCommitWork
```

You can provide explicit "old" and "new" file names. This only works
for one module at a time:

```sh
yarn merge-fork \
  --base-dir=packages/react-reconciler/src \
  --old=ReactFiberExpirationTime.js \
  --new=ReactFiberLane.js
```

The default is to merge changes from the new module to the old one. To
merge changes in the opposite direction, use `--reverse`.

```sh
yarn merge-fork \
  --reverse \
  --base-dir=packages/react-reconciler/src \
  ReactFiberWorkLoop
```

By default, the changes are compared to HEAD. You can use `--base-ref`
to compare to any rev. For example, while working on a PR, you might
make multiple commits to the new fork before you're ready to backport
them to the old one. In that case, you want to compare to the merge
base of your PR branch:

```sh
yarn merge-fork \
  --base-ref=$(git merge-base HEAD origin/master)
  --base-dir=packages/react-reconciler/src \
  ReactFiberWorkLoop
```
2020-04-09 11:37:13 -07:00
Sebastian Markbåge
11ac10b44e Port error boundaries test to yieldValue (#18558) 2020-04-09 11:13:01 -07:00
Dominic Gannaway
d48dbb8249 Clear more Fiber fields in detachFiber (#18556) 2020-04-09 18:31:34 +01:00
Dominic Gannaway
0566b706ee Fix fiber memory leak with runAllPassiveEffectDestroysBeforeCreates (#18554) 2020-04-09 15:35:07 +01:00
Dominic Gannaway
ca1a703d21 Make enableLegacyFBSupport flag dynamic for www (#18551) 2020-04-09 15:31:36 +01:00
Dominic Gannaway
8cbce05be1 Move plugins into their own directory (#18553) 2020-04-09 14:18:33 +01:00
Dan Abramov
c74f0b0646 Update stale.yml 2020-04-09 13:36:11 +01:00
Andrew Clark
4c6470cb3b Point ReactDOMForked to the new implementation
Updates Rollup, Jest, and Flow configuration to point to the new
entry points.
2020-04-09 00:03:35 -07:00
Andrew Clark
17f582e045 Add forked copies of reconciler modules
All changes in this commit were generated by the following commands.

Copy each module that ends with `.old` to a new file that ends
with `.new`:

```sh
for f in packages/react-reconciler/src/*.old.js; do cp "$f" "$(echo "$f" | sed s/\.old/\.new/)"; done
```

Then transform the internal imports:

```sh
grep -rl --include="*.new.js" '.old' packages/react-reconciler/src/| xargs sed -i '' "s/\.old\'/\.new\'/g"
```
2020-04-09 00:03:35 -07:00
Andrew Clark
376d5c1b5a Split cross-package types from implementation
Some of our internal reconciler types have leaked into other packages.
Usually, these types are treated as opaque; we don't read and write
to its fields. This is good.

However, the type is often passed back to a reconciler method. For
example, React DOM creates a FiberRoot with `createContainer`, then
passes that root to `updateContainer`. It doesn't do anything with the
root except pass it through, but because `updateContainer` expects a
full FiberRoot, React DOM is still coupled to all its fields.

I don't know if there's an idiomatic way to handle this in Flow. Opaque
types are simlar, but those only work within a single file. AFAIK,
there's no way to use a package as the boundary for opaqueness.

The immediate problem this presents is that the reconciler refactor will
involve changes to our internal data structures. I don't want to have to
fork every single package that happens to pass through a Fiber or
FiberRoot, or access any one of its fields. So my current plan is to
share the same Flow type across both forks. The shared type will be a
superset of each implementation's type, e.g. Fiber will have both an
`expirationTime` field and a `lanes` field. The implementations will
diverge, but not the types.

To do this, I lifted the type definitions into a separate module.
2020-04-08 23:49:23 -07:00
Andrew Clark
d686f3f16a Add .old prefix to reconciler modules 2020-04-08 23:49:19 -07:00
Sebastian Markbåge
147bdef11b Port more tests to the Scheduler.unstable_yieldValue pattern and drop internal.js (#18549)
* Drop the .internal.js suffix on some files that don't need it anymore

* Port some ops patterns to scheduler yield

* Fix triangle test to avoid side-effects in constructor

* Move replaying of setState updaters until after the effect

Otherwise any warnings get silenced if they're deduped.

* Drop .internal.js in more files

* Don't check propTypes on a simple memo component unless it's lazy

Comparing the elementType doesn't work for this because it will never be
the same for a simple element.

This caused us to double validate these. This was covered up because in
internal tests this was deduped since they shared the prop types cache
but since we now inline it, it doesn't get deduped.
2020-04-08 20:54:54 -07:00
Sebastian Markbåge
b014e2d5e3 Don't use closures in DevTools injection (#18278)
* Don't use closures in DevTools injection

Nested closures are tricky. They're not super efficient and when they share
scope between multiple closures they're hard for a compiler to optimize.
It's also unclear how many versions will be created.

By hoisting things out an just make it simple calls the compiler can do
a much better job.

* Store injected hook to work around fast refresh
2020-04-08 17:57:17 -07:00
Sebastian Markbåge
5474a83e25 Disable console.logs in the second render pass of DEV mode double render (#18547)
* Disable console log during the second rerender

* Use the disabled log to avoid double yielding values in scheduler mock

* Reenable debugRenderPhaseSideEffectsForStrictMode in tests that can
2020-04-08 16:43:51 -07:00
Dan Abramov
b225d4f261 Revert "Revert "Refactor commitPlacement to recursively insert nodes (#17996)" (#18517)" (#18540)
This reverts commit e69ca310ea.
2020-04-08 11:22:02 +01:00
jddxf
241103a6fb Fix bailout broken in lazy components due to default props resolving (#18539)
* Add failing tests for lazy components

* Fix bailout broken in lazy components due to default props resolving

We should never compare unresolved props with resolved props. Since comparing
resolved props by reference doesn't make sense, we use unresolved props in that
case. Otherwise, resolved props are used.

* Avoid reassigning props warning when we bailout
2020-04-08 10:58:57 +01:00
Andrew Clark
2dddd1e00c Bugfix: Render phase update causes remaining updates in same component to be dropped (#18537)
* Bugfix: Render phase update leads to dropped work

Render phase updates should not affect the `fiber.expirationTime` field.
We don't have to set anything on the fiber because we're going to
process the render phase update immediately.

We also shouldn't reset the `expirationTime` field in between render
passes because it represents the remaining work left in the update
queues. During the re-render, the updates that were skipped in the
original pass are not processed again.

I think my original motivation for using this field for render phase
updates was so I didn't have to add another module level variable.

* Add repro case for #18486

Co-authored-by: Dan Abramov <dan.abramov@me.com>
2020-04-07 19:17:01 -07:00
Andrew Clark
2def7b3caf More robust fix for #18515 (#18535)
* Add another test for #18515 using pings

Adds a regression test for the same underlying bug as #18515 but using
pings.

Test already passes, but I confirmed it fails if you revert the fix
in #18515.

* Set nextPendingLevel after commit, too
2020-04-07 18:52:31 -07:00
Dominic Gannaway
948fad357b Improve detachFiber (#18536) 2020-04-08 01:45:23 +01:00
Carl Vitullo
03de849af0 Make uncontrolled -> controlled warning clearer (#17070)
* Make uncontrolled -> controlled warning clearer

* Update phrasing, mirror for opposite direction

* Remove unused substitution

* Update warning tests

* Literally got these backwards, womp womp

* Rerere-fix tests
2020-04-07 23:19:56 +01:00
jddxf
ddc4b65cfe Clear finished discrete updates during commit phase (#18515)
* Reproduce a bug where `flushDiscreteUpdates` causes fallback never to be committed

* Ping suspended level when canceling its timer

Make sure the suspended level is marked as pinged so that we return back
to it later, in case the render we're about to start gets aborted.
Generally we only reach this path via a ping, but we shouldn't assume
that will always be the case.

* Clear finished discrete updates during commit phase

If a root is finished at a priority lower than that of the latest pending discrete
updates on it, these updates must have been finished so we can clear them now.
Otherwise, a later call of `flushDiscreteUpdates` would start a new empty render
pass which may cause a scheduled timeout to be cancelled.

* Add TODO

Happened to find this while writing a test. A JSX element comparison
failed because one of them elements had a functional component as an
owner, which should ever happen.

I'll add a regression test later.

Co-authored-by: Andrew Clark <git@andrewclark.io>
2020-04-07 13:34:41 -07:00
Dominic Gannaway
d53a4dbbc2 Export unstable_useEvent for www FB ReactDOM builds (#18532) 2020-04-07 21:32:38 +01:00
Brian Vaughn
8edcd03b64 DevTools Profiler: Fix "cannot read property 'memoizedState' of null" (#18522) 2020-04-07 10:30:25 -07:00
Brian Vaughn
e8ac48f90b Fix whitespace problem wiht DevTools Components search (#18527) 2020-04-07 10:28:21 -07:00
Brian Vaughn
dc49ea108c Filter certain DOM attributes (e.g. src) if value is empty string (#18513)
* Filter certain DOM attributes (e.g. src, href) if their values are empty strings

This prevents e.g. <img src=""> from making an unnecessar HTTP request for certain browsers.

* Expanded warning recommendation

* Improved error message

* Further refined error message
2020-04-07 09:52:36 -07:00
Dan Abramov
bce982b799 Change stalebot messages (#18524) 2020-04-07 17:30:45 +01:00
Brian Vaughn
32621a354f Improved Profiler tooltip confusing/misleading wording (#18523) 2020-04-07 09:26:50 -07:00
Dan Abramov
e69ca310ea Revert "Refactor commitPlacement to recursively insert nodes (#17996)" (#18517)
This reverts commit df5faddcc2.
2020-04-07 13:41:51 +01:00
Luna Ruan
3278d24218 Add useOpaqueIdentifier Hook (#17322)
* Add useOpaqueIdentifier Hook

We currently use unique IDs in a lot of places. Examples are:
  * `<label for="ID">`
  * `aria-labelledby`

This can cause some issues:
  1. If we server side render and then hydrate, this could cause an
     hydration ID mismatch
  2. If we server side render one part of the page and client side
     render another part of the page, the ID for one part could be
     different than the ID for another part even though they are
     supposed to be the same
  3. If we conditionally render something with an ID ,  this might also
     cause an ID mismatch because the ID will be different on other
     parts of the page

This PR creates a new hook `useUniqueId` that generates a different
unique ID based on whether the hook was called on the server or client.
If the hook is called during hydration, it generates an opaque object
that will rerender the hook so that the IDs match.

Co-authored-by: Andrew Clark <git@andrewclark.io>
2020-04-06 17:17:27 -07:00
Sebastian Markbåge
4169420198 Refactor Component Stack Traces (#18495)
* Add feature flag

* Split stack from current fiber

You can get stack from any fiber, not just current.

* Refactor description of component frames

These should use fiber tags for switching. This also puts the relevant code
behind DEV flags.

* We no longer expose StrictMode in component stacks

They're not super useful and will go away later anyway.

* Update tests

Context is no longer part of SSR stacks. This was already the case on the
client.

forwardRef no longer is wrapped on the stack. It's still in getComponentName
but it's probably just noise in stacks. Eventually we'll remove the wrapper
so it'll go away anyway. If we use native stack frames they won't have this
extra wrapper.

It also doesn't pick up displayName from the outer wrapper. We could maybe
transfer it but this will also be fixed by removing the wrapper.

* Forward displayName onto the inner function for forwardRef and memo in DEV

This allows them to show up in stack traces.

I'm not doing this for lazy because lazy is supposed to be called on the
consuming side so you shouldn't assign it a name on that end. Especially
not one that mutates the inner.

* Use multiple instances of the fake component

We mutate the inner component for its name so we need multiple copies.
2020-04-06 15:43:39 -07:00
Dominic Gannaway
a3875663f6 React Event System: cleanup plugins + break out update batching logic (#18503) 2020-04-06 22:01:20 +01:00
dependabot[bot]
717a33abb9 Bump minimist from 1.2.0 to 1.2.3 in /scripts/bench (#18500)
Bumps [minimist](https://github.com/substack/minimist) from 1.2.0 to 1.2.3.
- [Release notes](https://github.com/substack/minimist/releases)
- [Commits](https://github.com/substack/minimist/compare/1.2.0...1.2.3)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2020-04-06 19:29:11 +01:00
dependabot[bot]
8c974a70c9 Bump minimist from 1.2.0 to 1.2.3 (#18501)
Bumps [minimist](https://github.com/substack/minimist) from 1.2.0 to 1.2.3.
- [Release notes](https://github.com/substack/minimist/releases)
- [Commits](https://github.com/substack/minimist/compare/1.2.0...1.2.3)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2020-04-06 19:28:56 +01:00
Brian Vaughn
3498f13669 Profiler tooltip shows self duration (#18510) 2020-04-06 09:47:15 -07:00
Faelivrinx
c781156163 Fix performance issue in react-devtools when highlight enabled (#18498)
* Fix performance issue in react-devtools when highlight enabled

* getting minimum expiration time (fix)
2020-04-06 16:17:45 +01:00
Sophie Alpert
fe2cb52554 [eslint] Consider useRef() as ... as constant (#18496)
Sometimes you need to use casts, eg: https://github.com/DefinitelyTyped/DefinitelyTyped/issues/28884#issuecomment-471341041. This change ignores them and allows you to still omit the ref object from the deps list.

Test Plan: unit tests
2020-04-05 14:13:34 -07:00
Sebastian Markbåge
1fd45437d7 Don't use checkPropTypes for internals (#18488)
We use console.error for internal warnings.
2020-04-04 15:10:46 -07:00
Zen
2ff27ec112 [eslint] strip tailing property in assignments (#16784)
* [eslint] strip tailing property in assignments

* inline `stripTailingPropInAssignment`
2020-04-04 14:26:39 +01:00
Nick Reiley
f625fce857 Add KeyboardEvent.code to synthetic event (#18287)
* Add KeyboardEvent.code to synthetic event

* remove null to 0 transformation

* make onKeyPress work
2020-04-04 14:24:46 +01:00
Sebastian Markbåge
5022fdfd5f Refactor Error Dialog Logging (#18487)
* Remove unnecessary CapturedError fields.

componentName is not necessary and is misleading when the error is caused
elsewhere in the stack. The stack is sufficient.

The many error boundary fields are unnecessary because they can be inferred
by the boundary itself.

* Don't attempt to build a stack twice

If it was possible, it would've been done in createCapturedValue.

* Push the work needed by the works into the forks

This avoids needing this in the npm published case.
2020-04-03 19:01:40 -07:00
Sebastian Markbåge
e2dd30898e [Flight] Lazily parse models and allow any value to suspend (#18476)
* Lazily initialize models as they're read intead of eagerly when received

This ensures that we don't spend CPU cycles processing models that we're
not going to end up rendering.

This model will also allow us to suspend during this initialization if
data is not yet available to satisfy the model.

* Refactoring carefully to ensure bundles still compile to something optimal

* Remove generic from Response

The root model needs to be cast at one point or another same as othe
chunks. So we can parameterize the read instead of the whole Response.

* Read roots from the 0 key of the map

The special case to read the root isn't worth the field and code.

* Store response on each Chunk

Instead of storing it on the data tuple which is kind of dynamic, we store
it on each Chunk. This uses more memory. Especially compared to just making
initializeBlock a closure, but overall is simpler.

* Rename private fields to underscores

Response objects are exposed.

* Encode server components as delayed references

This allows us to stream in server components one after another over the
wire. It also allows parallelizing their fetches and resuming only the
server component instead of the whole parent block.

This doesn't yet allow us to suspend deeper while waiting on this content
because we don't have "lazy elements".
2020-04-03 14:58:02 -07:00
Sebastian Markbåge
59fd09cb67 [Flight] Add webpack plugin build (#18485)
* Eject CRA from Flight

We need to eject because we're going to add a custom Webpack Plugin.

We can undo this once the plugin has upstreamed into CRA.

* Add Webpack plugin build

I call this entry point "webpack-plugin" instead of "plugin" even though
this is a webpack specific package. That's because there will also be a
Node.js plugin to do the server transform.

* Add Flight Webpack plugin to fixture

* Rm UMD builds

* Transform classes

* Rename webpack-plugin to plugin

This avoids the double webpack name. We're going to reuse this for both
server and client.
2020-04-03 14:04:56 -07:00
Luna Ruan
a876808f0a remove jsx plugin from react (#18484)
Now that the React JSX Babel Plugin is in Babel, remove this code from react
2020-04-03 13:00:50 -07:00
Hristo Kanchev
7785a5263e [DevTools] - Highlight rendered by elements on hover. (#18479)
* [DevTools] - Highlight rendered by elements on hover.

* Fixed formatting issue.

* DevTools - Extracted highlight logic to custom hook. Added highlight support for rendered by elements.

* Removed unnecessary padding style

* Removed unnecessary wrapper function.

Co-authored-by: Brian Vaughn <brian.david.vaughn@gmail.com>
2020-04-03 10:49:49 -07:00
Brian Vaughn
f312a3fc36 useMutableSource: bugfix for new getSnapshot with mutation (#18297) 2020-04-03 10:20:17 -07:00
Dan Abramov
a8f2165e83 Update to Jest 25 (#18480)
* Revert "Revert "Upgrade to jest 25 (#17896)" (#18376)"

This reverts commit fc7835c657.

* Other fixes

* Fix a broken test
2020-04-03 16:37:36 +01:00
Nick Reiley
c083a643b1 Add <progress> to DOM fixtures (#18293)
* Add <progress> to DOM fixtures

* Remove uncontrolled
2020-04-03 14:39:59 +01:00
Sebastian Markbåge
3c16baf848 Remove /dist/ UMD builds (#18473)
* Remove /dist/ UMD builds

We publish UMDs to npm (and we're considering stopping even that).

This means we'll stop publishing to http://react.zpao.com/builds/master/latest/

* Update fixture paths
2020-04-02 17:52:32 -07:00
Dominic Gannaway
91c9d69f9a Modern Event System: Remove TestUtils.SimulateNative support (#18471) 2020-04-03 00:12:47 +01:00
Dan Abramov
e55855e7ae Deprecate TestUtils.SimulateNative (#13407) 2020-04-02 23:48:03 +01:00
Brian Vaughn
4123d729e5 Revert "Revert: Enable new passive effect behavior for FB builds (#18467)" (#18468)
This reverts commit 3966081cf2.
2020-04-02 15:24:36 -07:00
Dominic Gannaway
8815e4cc72 Cleanup getListener and EventSystemFlags (#18469) 2020-04-02 23:17:10 +01:00
Dominic Gannaway
5e464546af ReactDOM.useEvent: fix scope propagation issue (#18464) 2020-04-02 18:26:56 +01:00
Dominic Gannaway
d5e4b3ae1d Modern Event System: refine flags and handling of enableLegacyFBSupport (#18466) 2020-04-02 18:26:34 +01:00
Dominic Gannaway
3966081cf2 Revert: Enable new passive effect behavior for FB builds (#18467) 2020-04-02 16:25:35 +01:00
Dan Abramov
7dfdff42af Run more flags in VARIANT tests (#18461)
* Run more flags in VARIANT tests

* Revert enabling modern system

* Fix
2020-04-02 16:19:09 +01:00
Dan Abramov
31734540dc Remove a flag for style collision warning (#18462) 2020-04-02 11:55:17 +01:00
Dominic Gannaway
663c13d71d Refactor Enter/Leave listener accumulation (#18405)
* Refactor Enter/Leave listener accumulation
2020-04-02 11:07:20 +01:00
Dan Abramov
c80cd8ee27 Revert "Fix email cursor jump (#18379)" (#18459)
* Revert "Fix email cursor jump (#18379)"

This reverts commit 9b88b78b3d.

* Leave fixtures be
2020-04-01 22:44:59 +01:00
Andrew Clark
58afba0663 Fix: Don't read primaryChild.childExpirationTime (#18457)
This is a variant of the fix in 5a0f1d. We can't rely on the primary
fiber's `childExpirationTime` field to be correct.

In this case, we can read from the Suspense boundary fiber instead.
This will include updates that exist in the fallback fiber, but that's
not a big deal; the important thing is that we don't drop updates.
2020-04-01 14:36:42 -07:00
Brian Vaughn
2ea7c60794 Fixed race condition in release script (#18456) 2020-04-01 14:17:55 -07:00
Dan Abramov
99d779f629 Don't close "Needs Investigation" issues (#18458) 2020-04-01 22:08:09 +01:00
Gabriel McAdams
3f46844899 [eslint-plugin-react-hooks] Added meta property (including docs) (#16607)
* [eslint-plugin-react-hooks] Added meta property (including docs)

* [eslint-plugin-react-hooks] Fixed typo (`RuleOfHooks` -> `RulesOfHooks`)

Co-authored-by: Dan Abramov <dan.abramov@gmail.com>
2020-04-01 21:13:10 +01:00
Dan Abramov
2bf60d9f9c Fix ESLint rule crash (#18455) 2020-04-01 20:54:42 +01:00
Sebastian Markbåge
3e94bce765 Enable prefer-const lint rules (#18451)
* Enable prefer-const rule

Stylistically I don't like this but Closure Compiler takes advantage of
this information.

* Auto-fix lints

* Manually fix the remaining callsites
2020-04-01 12:35:52 -07:00
Sebastian Markbåge
e6ea3d3873 Use Closure Compiler to compile to ES5 instead of Babel (#18449)
* Upgrade Closure

There are newer versions but they don't yet have corresponding releases
of google-closure-compiler-osx.

* Configure build

* Refactor ReactSymbols a bit

Provides a little better output.
2020-04-01 12:08:37 -07:00
Utkarsh Kukreti
5200547100 Do not warn when a controlled input has onInput handler. (#18189)
`onInput` behaves the same as `onChange` for controlled inputs as far as I
know, so React should not print the following warning when `onInput` is
present.

> Failed prop type: You provided a `value` prop to a form field without an `onChange` handler. This will render a read-only field. If the field should be mutable use `defaultValue`. Otherwise, set either `onChange` or `readOnly`.
2020-04-01 19:58:07 +01:00
Sebastian Silbermann
7516bdfce3 feat(createContext): Include displayName in warning (#18386) 2020-04-01 19:42:38 +01:00
Nick Reiley
9b88b78b3d Fix email cursor jump (#18379)
* add email input fixture to show cursor jump

* fix cursor jump in email input

Co-authored-by: Peter Potapov <dr.potapoff-peter@yandex.ru>

* add regression tests to ensure attributes are working

Co-authored-by: Peter Potapov <dr.potapoff-peter@yandex.ru>
2020-04-01 19:30:26 +01:00
Brian Vaughn
5ee0efe832 Remove state update warning for passive effect cleanup functions (#18453) 2020-04-01 10:49:24 -07:00
Dan Abramov
d8d2b6e89c Disable module components dynamically for WWW (#18446)
* Make disableModulePatternComponents dynamic for WWW

* Run both flags and tests and respect the flag in SSR
2020-04-01 18:31:59 +01:00
Sebastian Markbåge
e2c6702fca Remove ConcurrentMode and AsyncMode symbols (#18450)
This API was never released.
2020-04-01 10:18:52 -07:00
Dominic Gannaway
d6d5f5aabe Move accumulateEventTargetListeners to its own module/function (#18407) 2020-04-01 14:19:21 +01:00
Dominic Gannaway
dc3c6c9565 ReactDOM.useEvent: revert and add guard for null stateNode (#18441) 2020-04-01 12:45:26 +01:00
Sebastian Markbåge
0f334553c9 Reset stateNode in resetWorkInProgress (#18448)
* test(SuspenseList): Add failing test for class component

* Reset stateNode when resetWorkInProgress

This is supposed to put the Fiber into the same state as if it was just
created by child fiber reconciliation. For newly created fibers, that means
that stateNode is null.

Co-authored-by: Sebastian Silbermann <silbermann.sebastian@gmail.com>
2020-03-31 21:14:59 -07:00
Brian Vaughn
153b5c305d Cleanup previous shims directories before re-copying (#18447) 2020-03-31 12:22:02 -07:00
Brian Vaughn
4de3a60325 Remove disableMapsAsChildren flag (#18445)
Change warning to say the case is unsupported (not "will be deprecated")
2020-03-31 11:00:51 -07:00
Brian Vaughn
f4cc970276 Enable new passive effect behavior for FB builds (#18444)
* Enable new passive effect behavior for FB builds

Previously this behavior was controlled by GKs. This PR updates the flags to be enabled statically. It also enables the flags in the test builds.
2020-03-31 10:05:15 -07:00
Dan Abramov
9065e02d66 Fix a warning typo (#18443) 2020-03-31 15:55:30 +01:00
Dan Abramov
1960131f11 Add opt-in support for dangerous autofix (#18437) 2020-03-31 11:43:01 +01:00
Andrew Clark
90e90ac8e0 Revert useEvent PRs (#18438)
* Revert "ReactDOM.useEvent: enable on internal www and add inspection test (#18395)"

This reverts commit e0ab1a429d.

* Revert "ReactDOM.useEvent: Add support for experimental scopes API (#18375)"

This reverts commit a16b349745.

* ReactDOM.useEvent: Add support for experimental scopes API
2020-03-30 19:16:28 -07:00
Dan Abramov
da54641a10 [ESLint] Check deps when callback body is outside the Hook call, too (#18435)
* Refactor: visit CallExpression

Instead of visiting the functions and looking up to see if they're in a Hook call, visit Hook calls and look down to see if there's a callback inside. I will need this refactor so I can visit functions declared outside the call.

* Check deps when callback body is outside the Hook call

* Handle the unknown case
2020-03-31 02:09:32 +01:00
Dan Abramov
bf30e370a5 Remove User Timings (#18417) 2020-03-31 00:29:53 +01:00
Ricky
dd7e5e4f5a Add getInspectorDataForViewAtPoint (take two) (#18388)
* Add getInspectorDataForViewAtPoint (take two)

* Updates from review

* Add DEV to dev-only variable

* Missed this rename
2020-03-30 15:42:41 -04:00
Andrew Clark
d7382b6c43 Bugfix: Do not unhide a suspended tree without finishing the suspended update (#18411)
* Bugfix: Suspended update must finish to unhide

When we commit a fallback, we cannot unhide the content without including
the level that originally suspended. That's because the work at level
outside the boundary (i.e. everything that wasn't hidden during that
render) already committed.

* Test unblocking with a high-pri update
2020-03-30 11:25:04 -07:00
Dan Abramov
1f8c40451a Make interaction tracing on by default in all WWW builds (#18419) 2020-03-30 16:07:58 +01:00
Sebastian Silbermann
ba31ad40a9 feat(StrictMode): Double-invoke render for every component (#18430)
* feat(StrictMode): Double-invoke render for every component

* fix: Mark ReactTestRendererAsync as internal
2020-03-29 23:13:46 +01:00
Sebastian Markbåge
689d27586e Reset lastEffect when resuming SuspenseList (#18412)
We store an effect pointer so we can backtrack in the effect list in some
cases. This is a stateful variable. If we interrupt a render we need to
reset it.

This field was added after the optimization was added and I didn't remember
to reset it here.

Otherwise we end up not resetting the firstEffect so it points to a stale
list. As a result children don't end up inserted like we think they were.
Then we try to remove them it errors.

It would be nicer to just get rid of the effect list and use the tree for
effects instead. Maybe we still need something for deletions tho.
2020-03-29 10:13:17 -07:00
Rodrigo Graça
1af2a10891 https link to editorconfig.org (#18421) 2020-03-29 15:18:52 +01:00
zefeng
d7918f4a9b chore: npm link more directly (#18428) 2020-03-29 15:18:15 +01:00
Brian Vaughn
be4c8b19c1 Don't show destroy function state update warning when updating ancestors (#18409)
React can't directly detect a memory leak, but there are some clues that warn about one. One of these clues is when an unmounted React component tries to update its state. For example, if a component forgets to remove an event listener when unmounting, that listener may be called later and try to update state, at which point React would warn about the potential leak.

Warning signals like this are more useful if they're strong. For this reason, it's good to always avoid updating state from inside of an effect's cleanup function. Even when you know there is no potential leak, React has no way to know and so it will warn anyway.

In most cases we suggest moving state updates to the useEffect() body instead (to avoid triggering the warning). This works so long as the component is updating its own state (or the state of a descendant). However this will not work when a component updates its parent state in a cleanup function. If such a component is unmounted but its parent remains mounted, the state will be incorrect. For this reason, we now avoid showing the warning if a component is updating an ancestor.
2020-03-28 10:18:14 -07:00
Andrew Clark
35a2f74974 Delete leftover assignment from #18384
This assignment should have been deleted in #18384. It was deleted in
the other branches, but I missed this one. About to open a PR that
includes a test that covers this branch.
2020-03-27 15:17:30 -07:00
Andrew Clark
9d67847f7b [Bugfix] Dropped updates inside a suspended tree (#18384)
* Minor test refactor: `resolveText`

Adds a `resolveText` method as an alternative to using timers. Also
removes dependency on react-cache (for just this one test file; can do
the others later).

Timer option is still there if you provide a `ms` prop.

* Bugfix: Dropped updates in suspended tree

When there are multiple updates at different priority levels inside
a suspended subtree, all but the highest priority one is dropped after
the highest one suspends.

We do have tests that cover this for updates that originate outside of
the Suspense boundary, but not for updates that originate inside.

I'm surprised it's taken us this long to find this issue, but it makes
sense in that transition updates usually originate outside the boundary
or "seam" of the part of the UI that is transitioning.

* Bugfix: Suspense fragment skipped by setState

Fixes a bug where updates inside a suspended tree are dropped because
the fragment fiber we insert to wrap the hidden children is not part of
the return path, so it doesn't get marked during setState.

As a workaround, I recompute `childExpirationTime` right before deciding
to bail out by bubbling it up from the next level of children.

This is something we should consider addressing when we refactor the
Fiber data structure.

* Add back `lastPendingTime` field

This reverts commit 9a541139dfe36e8b9b02b1c6585889e2abf97389.

I want to use this so we can check if there might be any lower priority
updates in a suspended tree.

We can remove it again during the expiration times refactor.

* Use `lastPendingTime` instead of Idle

We don't currently have an mechanism to check if there are lower
priority updates in a subtree, but we can check if there are any in the
whole root. This still isn't perfect but it's better than using Idle,
which frequently leads to redundant re-renders.

When we refactor `expirationTime` to be a bitmask, this will no longer
be necessary because we'll know exactly which "task bits" remain.

* Add a test for updating the fallback
2020-03-26 11:31:40 -07:00
Dan Abramov
5bd1bc29b3 eslint-plugin-react-hooks@3.0.0 2020-03-26 17:59:25 +00:00
Dominic Gannaway
e0ab1a429d ReactDOM.useEvent: enable on internal www and add inspection test (#18395) 2020-03-26 17:13:05 +00:00
Brian Vaughn
6cceaeb67a DevTools v4.5.0 -> 4.6.0 2020-03-26 10:00:37 -07:00
Brian Vaughn
d92631eab1 Remove "es6-symbol" package from DevTools (#18397) 2020-03-26 09:31:36 -07:00
Dominic Gannaway
a16b349745 ReactDOM.useEvent: Add support for experimental scopes API (#18375)
* ReactDOM.useEvent: Add support for experimental scopes API
2020-03-26 13:29:54 +00:00
Sebastian Markbåge
dbb060d561 Pass BundlerConfig through to Relay Integration (#18393)
I wasn't sure we needed this but looks like it'll come in handy.
2020-03-25 20:25:54 -07:00
Sebastian Markbåge
ce6fe50b01 Add server-runtime to create Server Blocks (#18392)
This is equivalent to the jsx-runtime in that this is what the compiled
output on the server is supposed to target.

It's really just the same code for all the different Flights, but they
have different types in their arguments so each one gets their own entry
point. We might use this to add runtime warnings per entry point.

Unlike the client-side React.block call this doesn't provide the factory
function that curries the load function. The compiler is expected to wrap
this call in the currying factory.
2020-03-25 19:03:31 -07:00
Sebastian Markbåge
64ed221c3d Formalize the Wakeable and Thenable types (#18391)
* Formalize the Wakeable and Thenable types

We use two subsets of Promises throughout React APIs. This introduces
the smallest subset - Wakeable. It's the thing that you can throw to
suspend. It's something that can ping.

I also use a shared type for Thenable in the cases where we expect a value
so we can be a bit more rigid with our us of them.

* Make Chunks into Wakeables instead of using native Promises

This value is just going from here to React so we can keep it a lighter
abstraction throughout.

* Renamed thenable to wakeable in variable names
2020-03-25 16:49:37 -07:00
Sebastian Markbåge
a6924d77b1 Change .model getter to .readRoot method (#18382)
Originally the idea was to hide all suspending behind getters or proxies.
However, this has some issues with perf on hot code like React elements.

It also makes it too easy to accidentally access it the first time in an
effect or callback where things aren't allowed to suspend. Making it
an explicit method call avoids this issue.

All other suspending has moved to explicit lazy blocks (and soon elements).
The only thing remaining is the root. We could require the root to be an
element or block but that creates an unfortunate indirection unnecessarily.

Instead, I expose a readRoot method on the response. Typically we try to
avoid virtual dispatch but in this case, it's meant that you build
abstractions on top of a Flight response so passing it a round is useful.
2020-03-25 11:47:55 -07:00
Brian Vaughn
bd5781962a Inlined DevTools event emitter impl (#18378)
DevTools previously used the NPM events package for dispatching events. This package has an unfortunate flaw though- if a listener throws during event dispatch, no subsequent listeners are called. I've replaced that event dispatcher with my own implementation that ensures all listeners are called before it re-throws an error.

This commit replaces that event emitter with a custom implementation that calls all listeners before re-throwing an error.
2020-03-25 10:26:40 -07:00
Dan Abramov
6498f62edc Fix a mistake in ReactChildren refactor (#18380)
* Regression test for map() returning an array

* Add forgotten argument

This fixes the bug.

* Remove unused arg and retval

These aren't directly observable. The arg wasn't used, it's accidental and I forgot to remove. The retval was triggering a codepath that was unnecessary (pushing to array) so I removed that too.

* Flowify ReactChildren

* Tighten up types

* Rename getComponentKey to getElementKey
2020-03-25 09:20:46 +00:00
Dan Abramov
2ba43edc26 Rename internal fields (#18377) 2020-03-24 18:19:20 +00:00
Sebastian Markbåge
a317bd033f Flip the arguments of Blocks and make the query optional (#18374)
* Flip the arguments of Blocks and make the query optional

* Rename Query to Load
2020-03-24 10:58:23 -07:00
Andrew Clark
fc7835c657 Revert "Upgrade to jest 25 (#17896)" (#18376)
This reverts commit cf0081263c.

The changes to the test code relate to changes in JSDOM that come with Jest 25:

* Several JSDOM workarounds are no longer needed.
* Several tests made assertions to match incorrect JSDOM behavior (e.g. setAttribute calls) that JSDOM has now patched to match browsers.
  * https://codesandbox.io/s/resets-value-of-datetime-input-to-fix-bugs-in-ios-safari-1ppwh
* JSDOM no longer triggers default actions when dispatching click events.
  * https://codesandbox.io/s/beautiful-cdn-ugn8f
* JSDOM fixed (jsdom/jsdom#2700) a bug so that calling focus() on an already focused element does not dispatch a FocusEvent.
* JSDOM now supports passive events.
* JSDOM has improved support for custom CSS properties.
  * But requires jsdom/cssstyle#112 to land to support webkit prefixed properties.
2020-03-24 10:51:48 -07:00
Dominic Gannaway
0140118e8e ReactDOM.useEvent: add support for beforeblur/afterblur (#18370)
* ReactDOM.useEvent: add support for beforeblur/afterblur
2020-03-24 16:14:55 +00:00
Sebastian Markbåge
a56309fb88 [Flight] Integrate Blocks into Flight (#18371)
* Resolve Server-side Blocks instead of Components

React elements should no longer be used to extract arbitrary data but only
for prerendering trees.

Blocks are used to create asynchronous behavior.

* Resolve Blocks in the Client

* Tests

* Bug fix relay JSON traversal

It's supposed to pass the original object and not the new one.

* Lint

* Move Noop Module Test Helpers to top level entry points

This module has shared state. It needs to be external from builds.

This lets us test the built versions of the Noop renderer.
2020-03-23 17:53:45 -07:00
Dan Abramov
fc96a52be3 Refactor React.Children to reduce indirection (#18332)
* Don't pool traversal context

* Remove traverseAllChildrenImpl indirection

All usages are internal so we can simply use the inner function directly.

* Implement forEach through map

* Remove second usage of traverseAllChildren

This isn't useful by itself but makes the layering easier to follow. traverseAllChildren is only used at the lowest layer now.

* Reimplement count() and toArray() in terms of map()

* Inline the only use of mapSingleChildIntoContext

* Move forEach down in the file

* Use the language

Get rid of the traversal context. Use closures.

* Make mapIntoArray take an already escaped prefix

* Move count state out of mapIntoArray

* Inline traverseAllChildren into mapIntoArray

* Inline handleChild into mapIntoArray
2020-03-23 22:56:00 +00:00
Sebastian Markbåge
fd61f7ea53 Refactor Lazy Components to use teh Suspense (and wrap Blocks in Lazy) (#18362)
* Refactor Lazy Components

* Switch Blocks to using a Lazy component wrapper

Then resolve to a true Block inside.

* Test component names of lazy Blocks
2020-03-22 21:53:05 -07:00
Mohammad Aziz
31a9e391f7 Remove unnecessary lines for hasBadMapPolyfill issue for rollup (#16231) 2020-03-22 14:52:59 +00:00
Sebastian Markbåge
c0cd1be908 [Flight] Move bundler configs to use Suspense instead of returning thenable (#18367)
* Move bundler configs to use suspense instead of returning thenable

* Fix some Flow types
2020-03-21 22:28:36 -07:00
Sebastian Markbåge
4b7f8496a8 Rename CI jobs after the command line equivalent (#18364)
This makes it easier to know what to write on your command line to replicate
a failure locally.
2020-03-21 16:02:01 -07:00
Sebastian Markbåge
b779dd51e8 Stop syncing ReactTypes to RN (#18366)
This is a really old one and all callers have since been codemodded away
anyway because of problems.

This file is not really as rigorously maintained as the official Flow types
but has a few more specifics. However, the inconsistency causes problems
when you try to pass files typed using the built-in Flow typing for React
and mix it with these.

We just happen to get away with it because we compile out the types. If we
didn't we would hit those problems by even using these in our renderers.
2020-03-21 15:22:40 -07:00
Sebastian Markbåge
c5d2fc7127 Move some files out of /shared and rename to upper case (#18363)
* Rename lower case isomorphic default exports modules to upper case named exports

We're somewhat inconsistent here between e.g. ReactLazy and memo.

Let's pick one.

This also moves the responder, fundamental, scope creators from shared
since they're isomorphic and same as the other creators.

* Move some files that are specific to the react-reconciler from shared

Individual renderers are allowed to deep require into the reconciler.

* Move files specific to react-dom from shared

react-interactions is right now dom specific (it wasn't before) so we can
type check it together with other dom stuff. Avoids the need for
a shared ReactDOMTypes to be checked by RN for example.

* Move ReactWorkTags to the reconciler

* Move createPortal to export from reconciler

Otherwise Noop can't access it since it's not allowed deep requires.
2020-03-21 15:22:01 -07:00
Dominic Gannaway
a600408b28 ReactDOM.useEvent: add EventTarget support (#18355)
* ReactDOM.useEvent: add support for all EventTarget types
2020-03-20 18:31:47 +00:00
Dominic Gannaway
dbd85a08d9 ReactDOM.useEvent: support custom types (#18351)
* ReactDOM.useEvent: support custom types
2020-03-20 14:45:33 +00:00
Luna Ruan
7c1478680f fix string ref cannot be auto converted warning for React.jsxDEV (#18354)
The string ref cannot be auto converted warning was using the wrong _self. This diff fixes this so it is now using the correct __self
2020-03-19 23:47:53 -07:00
Andrew Clark
f198872716 Empty commit to fix master.
I accidentally did that thing again where I updated a PR branch to
be the same as the tip of master, which confused GitHub and caused it
to run PR checks against master.
2020-03-19 17:53:09 -07:00
Sebastian Markbåge
fc91508c1f Follow ups to bundler configs (#18352)
Follow ups from https://github.com/facebook/react/pull/18334

I also introduced the concept of a module reference on the client too.
We don't need this for webpack so that gets compiled out but we need it
for www. Similarly I also need a difference between preload and load.
2020-03-19 17:49:40 -07:00
Andrew Clark
31e6756b8c Remove error code step from publish script (#18350)
Error codes don't need to be pulled from CI anymore because the ones
in source are already expected to match the build output.

I noticed this when running the 16.13.1 release. Patch releases are cut
with the commit used to build the previous release as a base. So the
publish script accidentally reverted the changes that had landed to
the error codes file since then.
2020-03-19 14:45:07 -07:00
Dominic Gannaway
9e7f334c71 ModernEventSystem: fix event replaying (#18346)
* ModernEventSystem: fix event replaying
2020-03-19 20:44:38 +00:00
Dominic Gannaway
ffefb4e77f ModernEventSystem: refine Flow types (#18349) 2020-03-19 20:25:52 +00:00
Andrew Clark
6818a2aa01 Revert accidental changes to package.json (#18348)
The publish script was written before we switched to running patch
releases out-of-band, so when updating the local package.json version
numbers, it accidentally reverted other changes that have landed to
master since 16.13 was released.
2020-03-19 13:16:37 -07:00
Andrew Clark
ad445b127e Update package.jsons for 16.13.1 patch relase 2020-03-19 12:58:31 -07:00
Andrew Clark
8b48d52fb4 Changelog for 16.13.1 2020-03-19 12:36:34 -07:00
Dominic Gannaway
8311cb5d24 Modern Event System: refactor legacy FB support logic (#18336) 2020-03-19 13:22:36 +00:00
Dan Abramov
1cf4a170ac Stop exposing ReactDOMComponentTree from FB builds (#18338) 2020-03-18 20:35:58 +00:00
Ian Obermiller
d3368beeec [eslint-plugin-react-hooks] Disallow hooks in class components (#18341)
Per discussion at Facebook, we think hooks have reached a tipping point where it is more valuable to lint against potential hooks in classes than to worry about false positives.

Test plan:
```
# run from repo root
yarn test --watch RuleOfHooks
```
2020-03-18 19:55:13 +00:00
Sebastian Markbåge
8206b4b864 Wire up bundler configs (#18334)
This allows different flight server and clients to have different configs
depending on bundler to serialize and resolve modules.
2020-03-18 12:18:34 -07:00
Kerollos Magdy
6b7281ec14 [DevTools] Add shortcut keys for tab switching (#18248)
* [DevTools] Add shortcut keys for tab switching
* Use LocalStorage to remember most recently selected tab

Resolves #18227 and #18226

Co-authored-by: Brian Vaughn <brian.david.vaughn@gmail.com>
2020-03-18 11:05:41 -07:00
ItsByteMe
5152c4a9fd Fixed inconcistency with surrounding punctuation (#18339)
There was an inconsistency present on line 99 regarding the punctuation of the comment, all other comments found end in a period and this line had it's period omitted.
2020-03-18 17:10:32 +00:00
Sebastian Markbåge
94505b9613 Don't use EventListener Fork in Modern WWW Builds (#18333)
* Move unsubscribe fork to EventListener

That way we can statically compile out more of these indirections.

* Don't use the EventListener fork for Modern WWW builds
2020-03-18 13:13:50 +00:00
Luna Ruan
aae83a4b9a Fix UMD Builds (ReactSharedInternals)
ReactCurrentBatchConfig.suspense does not exist in ReactSharedInternals.umd. This PR adds it.
2020-03-17 17:56:14 -07:00
Dominic Gannaway
7d466bcc25 React Event System: Refactor ElementListenerMap for upgrading (#18308) 2020-03-18 00:15:50 +00:00
Dan Abramov
fe1f79b95b Don't fire the render phase update warning for class lifecycles (#18330)
* Change the warning to not say "function body"

This warning is more generic and may happen with class components too.

* Dedupe by the rendering component

* Don't warn outside of render
2020-03-18 00:07:14 +00:00
Sebastian Silbermann
22cab1cbd6 test(getComponentName): Increase test coverage (#18149)
Co-authored-by: Brian Vaughn <brian.david.vaughn@gmail.com>
2020-03-17 14:47:24 -07:00
Sebastian Silbermann
756e1ea5d4 fix(react-devtools-shared): useDebugValue with complex types (#18070)
Co-authored-by: Brian Vaughn <brian.david.vaughn@gmail.com>
2020-03-17 13:57:01 -07:00
Luna Ruan
90f8fe6f55 add jsx-runtime and jsx-dev-runtime (#18299)
This PR adds the jsx-runtime and jsx-dev-runtime modules for the JSX Babel Plugin. WWW still relies on jsx/jsxs/jsxDEV from the "react" module, so once we refactor the code to point to the runtime modules we will remove jsx/jsxs/jsxDEV from the "react" module.
2020-03-17 13:22:19 -07:00
Dan Abramov
26666427d6 Don't support older isomorphic React with newer renderers (#18329)
* Don't support older isomorphic React with newer renderers

* Remove the lazy hack
2020-03-17 19:30:10 +00:00
Dominic Gannaway
3a0076e0e8 useEvent: Small tweaks and changes (#18328) 2020-03-17 15:32:26 +00:00
Minh Nguyen
9240918536 Bump react-shallow-renderer to 16.13.1 (#18187) 2020-03-17 00:35:28 +00:00
Dominic Gannaway
c804f9aebb ReactDOM.useEvent: wire to event system to the hook (#18304) 2020-03-16 21:46:17 +00:00
Brian Vaughn
297f7588c4 Moved passive effects flag to be beside execution context (#18322) 2020-03-16 10:27:42 -07:00
Jovi De Croock
95df39b6b1 improve error message for cross-functional component updates (#18316)
* improve error message for cross-functional component updates

* correctly use %s by quoting it

* use workInProgress and lint

* add test assertion

* fix test

* Improve the error message

Co-authored-by: Dan Abramov <dan.abramov@me.com>
2020-03-16 17:05:30 +00:00
Brian Vaughn
c0ed0a2468 Replace passive effect context with boolean (#18309) 2020-03-16 09:56:43 -07:00
Brian Vaughn
730389b9d3 Warn against state updates from useEffect destroy functions (#18307)
Don't warn about unmounted state updates from within passive destroy function

* Fixed test conditional. (It broke after recent variant refactor.)
* Changed warning wording for setState from within useEffect destroy callback
2020-03-13 15:33:50 -07:00
Dominic Gannaway
0705b7282f Refine event system types + pass through priority (#18305) 2020-03-13 17:57:17 +00:00
Dominic Gannaway
45d26f6edb Remove un-used function arg (#18303) 2020-03-13 14:16:12 +00:00
Dan Abramov
73ff8b9094 Run ReactElementJSX-test against bundles (#18301)
* Run ReactElementJSX-test against bundles

* Try the new thing
2020-03-13 12:07:22 +00:00
Andrew Clark
8c015e0e14 Revert "Move MS Windows build to CircleCI (#17984)" (#18302)
This reverts commit 885ed46909.
2020-03-12 20:57:13 -07:00
wittgenst
885ed46909 Move MS Windows build to CircleCI (#17984)
* Move MS Windows build to CircleCI

* Update to latest NodeJS

Co-authored-by: Chris Lüer <lueer@fb.com>
2020-03-12 17:15:30 -07:00
Dominic Gannaway
2a7cd58956 ReactDOM.useEvent: Add DOM host event listener logic (#18292) 2020-03-12 22:41:33 +00:00
Dominic Gannaway
d3ec42020d Address feedback for accumulateTwoPhaseListeners (#18289) 2020-03-12 21:48:29 +00:00
Andrew Clark
cd48a06547 Set up infra for react-reconciler fork (#18285)
* ReactFiberReconciler -> ReactFiberReconciler.old

* Set up infra for react-reconciler fork

We're planning to land some significant refactors of the reconciler.
We want to be able to gradually roll out the new implementation side-by-
side with the existing one. So we'll create a short lived fork of the
react-reconciler package. Once the new implementation has stabilized,
we'll delete the old implementation and promote the new one.

This means, for as long as the fork exists, we'll need to maintain two
separate implementations. This sounds painful, but since the forks will
still be largely the same, most changes will not require two separate
implementations. In practice, you'll implement the change in the old
fork and then copy paste it to the new one.

This commit only sets up the build and testing infrastructure. It does
not actually fork any modules. I'll do that in subsequent PRs.

The forked version of the reconciler will be used to build a special
version of React DOM. I've called this build ReactDOMForked. It's only
built for www; there's no open source version.

The new reconciler is disabled by default. It's enabled in the
`yarn test-www-variant` command. The reconciler fork isn't really
related to the "variant" feature of the www builds, but I'm piggy
backing on that concept to avoid having to add yet another
testing dimension.
2020-03-12 11:38:32 -07:00
Andrew Clark
615df434bb Remove manual feature flag overrides (#18291)
Tests now run against both versions of these flags, using the
test-www-variant command. So we can remove the manual overrides.
2020-03-12 10:17:02 -07:00
Dominic Gannaway
99d271228d ReactDOM.useEvent: more scaffolding changes (#18282) 2020-03-12 09:12:06 +00:00
Brian Vaughn
97a8c72bf8 Wrap Components and Profiler tabs with box-size style too (#18286)
For the browser extension, these views get rendered into portals and so they don't inherit the box-sizing style from the .DevTools wrapper element. This causes views like the Profiler commit selector to subtly break.
2020-03-11 19:12:57 -07:00
Andrew Clark
5374919033 Empty commit to fix CI on master
Weird GitHub bug caused CI jobs to run against master as if it was
a PR. Now it looks like master is failing, even though it isn't.

Bloop.
2020-03-11 18:29:46 -07:00
Dominic Gannaway
8b155d2613 Flow type ReactDOMComponentTree (#18280) 2020-03-11 19:38:23 +00:00
Brian Vaughn
322cdcd3ab useMutableSource hook (#18000)
useMutableSource hook

useMutableSource() enables React components to safely and efficiently read from a mutable external source in Concurrent Mode. The API will detect mutations that occur during a render to avoid tearing and it will automatically schedule updates when the source is mutated.

RFC: reactjs/rfcs#147
2020-03-11 12:34:39 -07:00
Dominic Gannaway
30a998debf ModernEventSystem: refactor accumulateTwoPhaseListeners (#18274) 2020-03-11 18:55:01 +00:00
Andrew Clark
8fe066fdac Bugfix: "Captured" updates on legacy queue (#18265)
* Bugfix: "Captured" updates on legacy queue

This fixes a bug with error boundaries. Error boundaries have a notion
of "captured" updates that represent errors that are thrown in its
subtree during the render phase. These updates are meant to be dropped
if the render is aborted.

The bug happens when there's a concurrent update (an update from an
interleaved event) in between when the error is thrown and when the
error boundary does its second pass. The concurrent update is
transferred from the pending queue onto the base queue. Usually, at this
point the base queue is the same as the current queue. So when we
append the pending updates to the work-in-progress queue, it also
appends to the current queue.

However, in the case of an error boundary's second pass, the base queue
has already forked from the current queue; it includes both the
"captured" updates and any concurrent updates. In that case, what we
need to do is append separately to both queues. Which we weren't doing.

That isn't the full story, though. You would expect that this mistake
would manifest as dropping the interleaved updates. But instead what
was happening is that the "captured" updates, the ones that are meant
to be dropped if the render is aborted, were being added to the
current queue.

The reason is that the `baseQueue` structure is a circular linked list.
The motivation for this was to save memory; instead of separate `first`
and `last` pointers, you only need to point to `last`.

But this approach does not work with structural sharing. So what was
happening is that the captured updates were accidentally being added
to the current queue because of the circular link.

To fix this, I changed the `baseQueue` from a circular linked list to a
singly-linked list so that we can take advantage of structural sharing.

The "pending" queue, however, remains a circular list because it doesn't
need to be persistent.

This bug also affects the root fiber, which uses the same update queue
implementation and also acts like an error boundary.

It does not affect the hook update queue because they do not have any
notion of "captured" updates. So I've left it alone for now. However,
when we implement resuming, we will have to account for the same issue.

* Ensure base queue is a clone

When an error boundary captures an error, we append the error update
to the work-in-progress queue only so that if the render is aborted,
the error update is dropped.

Before appending to the queue, we need to make sure the queue is a
work-in-progress copy. Usually we clone the queue during
`processUpdateQueue`; however, if the base queue has lower priority
than the current render, we may have bailed out on the boundary fiber
without ever entering `processUpdateQueue`. So we need to lazily clone
the queue.

* Add warning to protect against refactor hazard

The hook queue does not have resuming or "captured" updates, but if
we ever add them in the future, we'll need to make sure we check if the
queue is forked before transfering the pending updates to them.
2020-03-11 11:53:45 -07:00
Sebastian Markbåge
b5c6dd2de5 Don't use Spread in DevTools Injection (#18277) 2020-03-11 10:58:25 -07:00
Sebastian Markbage
a463fef31b Revert "[React Native] Add getInspectorDataForViewAtPoint (#18233)"
This reverts commit bf351089a0.
2020-03-11 10:05:26 -07:00
Sebastian Markbåge
dc7eedae3c Encode server rendered host components as array tuples (#18273)
This replaces the HTML renderer with instead resolving host elements into
arrays tagged with the react.element symbol. These turn into proper
React Elements on the client.

The symbol is encoded as the magical value "$". This has security implications
so this special value needs to remain escaped for other strings.

We could just encode the element as {$$typeof: "$", key: key props: props}
but that's a lot more bytes. So instead I encode it as:
["$", key, props] and then convert it back.

It would be nicer if React's reconciler could just accept these tuples.
2020-03-11 09:48:02 -07:00
Ricky
bf351089a0 [React Native] Add getInspectorDataForViewAtPoint (#18233) 2020-03-11 16:12:41 +00:00
Sebastian Markbåge
99d7371863 [Flight] Split Streaming from Relay Implemenation (#18260)
* Add ReactFlightServerConfig intermediate

This just forwards to the stream version of Flight which is itself forked
between Node and W3C streams.

The dom-relay goes directly to the Relay config though which allows it to
avoid the stream part of Flight.

* Separate streaming protocol into the Stream config

* Split streaming parts into the ReactFlightServerConfigStream

This decouples it so that the Relay implementation doesn't have to encode
the JSON to strings. Instead it can be fed the values as JSON objects and
do its own encoding.

* Split FlightClient into a basic part and a stream part

Same split as the server.

* Expose lower level async hooks to Relay

This requires an external helper file that we'll wire up internally.
2020-03-10 14:55:04 -07:00
Dominic Gannaway
160505b0ca ReactDOM.useEvent: Add more scaffolding for useEvent hook (#18271) 2020-03-10 20:31:12 +00:00
Dominic Gannaway
a3bf668812 Flare: Fix listener upgrade bug (#18270) 2020-03-10 17:59:03 +00:00
Brian Vaughn
526c12f49e Enable enableProfilerCommitHooks flag for FB (#18230) 2020-03-10 10:40:45 -07:00
Kerollos Magdy
9e5626cdde Fix yarn warning on running 'yarn build-for-devtools' (#18232)
fixes #18231
2020-03-10 15:37:02 +00:00
Dominic Gannaway
29534252ad ReactDOM.useEvent add flag and entry point (#18267) 2020-03-10 12:18:49 +00:00
Dominic Gannaway
704c8b0118 Fix Flow type for AnyNativeEvent (#18266) 2020-03-10 10:46:12 +00:00
Sebastian Markbåge
bdc5cc4635 Add Relay Flight Build (#18242)
* Rename to clarify that it's client-only

* Rename FizzStreamer to FizzServer for consistency

* Rename react-flight to react-client/flight

For consistency with react-server. Currently this just includes flight
but it could be expanded to include the whole reconciler.

* Add Relay Flight Build

* Rename ReactServerHostConfig to ReactServerStreamConfig

This will be the config specifically for streaming purposes.
There will be other configs for other purposes.
2020-03-07 11:23:30 -08:00
Sebastian Markbåge
7a1691cdff Refactor Host Config Infra (getting rid of .inline*.js) (#18240)
* Require deep for reconcilers

* Delete inline* files

* Delete react-reconciler/persistent

This no longer makes any sense because it react-reconciler takes
supportsMutation or supportsPersistence as options. It's no longer based
on feature flags.

* Fix jest mocking

* Fix Flow strategy

We now explicitly list which paths we want to be checked by a renderer.
For every other renderer config we ignore those paths.

Nothing is "any" typed. So if some transitive dependency isn't reachable
it won't be accidentally "any" that leaks.
2020-03-06 16:20:42 -08:00
Sebastian Markbåge
238b57f0f7 [Blocks] Make it possible to have lazy initialized and lazy loaded Blocks (#18220)
* Lazify Blocks

Blocks now initialize lazily.

* Initialize Blocks eagerly in ChildFiber

This is for the case when it's a new Block that hasn't yet initialized.
We need to first initialize it to see what "render function" it resolves
to so that we can use that in our comparison.

* Remove extra import type line
2020-03-06 15:14:46 -08:00
Andrew Clark
235a6c4af6 Bugfix: Dropped effects in Legacy Mode Suspense (#18238)
* Failing: Dropped effects in Legacy Mode Suspense

* Transfer mounted effects on suspend in legacy mode

In legacy mode, a component that suspends bails out and commit in
its previous state. If the component previously had mounted effects,
we must transfer those to the work-in-progress so they don't
get dropped.
2020-03-06 11:10:01 -08:00
Andrew Clark
5fbb165602 Hard-code disableModulePatternComponents (#18239)
Hard-coding this until tests are fixed, to unblock master.
2020-03-06 11:09:36 -08:00
Brian Vaughn
cccba39f5b Fixed broken anchor tag for patch release 2020-03-06 11:05:01 -08:00
Dan Abramov
562cf013db Add a flag to disable module pattern components (#18133) 2020-03-06 18:46:32 +00:00
Andrew Clark
115cd12d9b Add test run that uses www feature flags (#18234)
In CI, we run our test suite against multiple build configurations. For
example, we run our tests in both dev and prod, and in both the
experimental and stable release channels. This is to prevent accidental
deviations in behavior between the different builds. If there's an
intentional deviation in behavior, the test author must account
for them.

However, we currently don't run tests against the www builds. That's
a problem, because it's common for features to land in www before they
land anywhere else, including the experimental release channel.
Typically we do this so we can gradually roll out the feature behind
a flag before deciding to enable it.

The way we test those features today is by mutating the
`shared/ReactFeatureFlags` module. There are a few downsides to this
approach, though. The flag is only overridden for the specific tests or
test suites where you apply the override. But usually what you want is
to run *all* tests with the flag enabled, to protect against unexpected
regressions.

Also, mutating the feature flags module only works when running the
tests against source, not against the final build artifacts, because the
ReactFeatureFlags module is inlined by the build script.

Instead, we should run the test suite against the www configuration,
just like we do for prod, experimental, and so on. I've added a new
command, `yarn test-www`. It automatically runs in CI.

Some of the www feature flags are dynamic; that is, they depend on
a runtime condition (i.e. a GK). These flags are imported from an
external module that lives in www. Those flags will be enabled for some
clients and disabled for others, so we should run the tests against
*both* modes.

So I've added a new global `__VARIANT__`, and a new test command `yarn
test-www-variant`. `__VARIANT__` is set to false by default; when
running `test-www-variant`, it's set to true.

If we were going for *really* comprehensive coverage, we would run the
tests against every possible configuration of feature flags: 2 ^
numberOfFlags total combinations. That's not practical, though, so
instead we only run against two combinations: once with `__VARIANT__`
set to `true`, and once with it set to `false`. We generally assume that
flags can be toggled independently, so in practice this should
be enough.

You can also refer to `__VARIANT__` in tests to detect which mode you're
running in. Or, you can import `shared/ReactFeatureFlags` and read the
specific flag you can about. However, we should stop mutating that
module going forward. Treat it as read-only.

In this commit, I have only setup the www tests to run against source.
I'll leave running against build for a follow up.

Many of our tests currently assume they run only in the default
configuration, and break when certain flags are toggled. Rather than fix
these all up front, I've hard-coded the relevant flags to the default
values. We can incrementally migrate those tests later.
2020-03-06 09:29:05 -08:00
Christoph Nakazawa
4027f2a3b8 Break up require/import statements in strings (#18222) 2020-03-05 22:27:55 +00:00
Brian Vaughn
024a764310 Implemented Profiler onCommit() and onPostCommit() hooks (#17910)
* Implemented Profiler onCommit() and onPostCommit() hooks
* Added enableProfilerCommitHooks feature flag for commit hooks
* Moved onCommit and onPassiveCommit behind separate feature flag
2020-03-05 11:02:00 -08:00
Brian Vaughn
d35f8a5818 feat: honor displayName of context types (#18224)
* Revert "Revert "feat: honor displayName of context types (#18035)" (#18223)"

This reverts commit 3ee812e6b6.

* Add warning of displayName is set on the consumer

* dedupe warning
2020-03-05 10:13:52 -08:00
Dominic Gannaway
3ee812e6b6 Revert "feat: honor displayName of context types (#18035)" (#18223)
This reverts commit 45c172d948.
2020-03-05 15:58:04 +00:00
Dominic Gannaway
6a0efddd89 Modern Event System: export internal FB flag for testing (#18221) 2020-03-05 14:05:00 +00:00
Sunil Pai
21b713b9fd Updated React Native home URL (#18218) 2020-03-05 13:15:46 +00:00
Dominic Gannaway
60b11f6c1b Modern Event System: Support nested portal/root boundaries (#18201) 2020-03-05 09:00:13 +00:00
Sebastian Markbåge
fa03206ee4 Remove _ctor field from Lazy components (#18217)
* This type is all wrong and nothing cares because it's all any

* Refine Flow types of Lazy Components

We can type each condition.

* Remove _ctor field from Lazy components

This field is not needed because it's only used before we've initialized,
and we don't have anything else to store before we've initialized.

* Check for _ctor in case it's an older isomorphic that created it

We try not to break across minors but it's no guarantee.

* Move types and constants from shared to isomorphic

The "react" package owns the data structure of the Lazy component. It
creates it and decides how any downstream renderer may use it.

* Move constants to shared

Apparently we can't depend on react/src/ because the whole package is
considered "external" as far as rollup is concerned.
2020-03-04 20:52:48 -08:00
Dominic Gannaway
2fe0fbb05e Use accumulateTwoPhaseDispatchesSingle directly (#18203) 2020-03-05 00:04:27 +00:00
Dominic Gannaway
503fd82b42 Modern Event System: Add support for internal FB Primer (#18210) 2020-03-04 23:41:59 +00:00
Brian Vaughn
45c172d948 feat: honor displayName of context types (#18035)
* test: Add test for current behavior of displayName
* feat: consider displayName of context types
2020-03-04 14:54:16 -08:00
Dominic Gannaway
83c3ed290c Fix instanceContainsElem bug from typo (#18213) 2020-03-04 19:53:16 +00:00
Vishal Jagtap
7e94d89f3e Updated React Native Website URL (#18207) 2020-03-04 12:10:48 +00:00
Brian Vaughn
355970aa4b DevTools 4.4.0 -> 4.5.0 2020-03-03 15:04:07 -08:00
Andrew Clark
ec652f4daf Bugfix: Expired partial tree infinite loops (#17949)
* Bugfix: Expiring a partially completed tree (#17926)

* Failing test: Expiring a partially completed tree

We should not throw out a partially completed tree if it expires in the
middle of rendering. We should finish the rest of the tree without
yielding, then finish any remaining expired levels in a single batch.

* Check if there's a partial tree before restarting

If a partial render expires, we should stay in the concurrent path
(performConcurrentWorkOnRoot); we'll stop yielding, but the rest of the
behavior remains the same.

We will only revert to the sync path (performSyncWorkOnRoot) when
starting on a new level.

This approach prevents partially completed concurrent work from
being discarded.

* New test: retry after error during expired render

* Regression: Expired partial tree infinite loops

Adds regression tests that reproduce a scenario where a partially
completed tree expired then fell into an infinite loop.

The code change that exposed this bug made the assumption that if you
call Scheduler's `shouldYield` from inside an expired task, Scheduler
will always return `false`. But in fact, Scheduler sometimes returns
`true` in that scenario, which is a bug.

The reason it worked before is that once a task timed out, React would
always switch to a synchronous work loop without checking `shouldYield`.

My rationale for relying on `shouldYield` was to unify the code paths
between a partially concurrent render (i.e. expires midway through) and
a fully concurrent render, as opposed to a render that was synchronous
the whole time. However, this bug indicates that we need a stronger
guarantee within React for when tasks expire, given that the failure
case is so catastrophic. Instead of relying on the result of a dynamic
method call, we should use control flow to guarantee that the work is
synchronously executed.

(We should also fix the Scheduler bug so that `shouldYield` always
returns false inside an expired task, but I'll address that separately.)

* Always switch to sync work loop when task expires

Refactors the `didTimeout` check so that it always switches to the
synchronous work loop, like it did before the regression.

This breaks the error handling behavior that I added in 5f7361f (an
error during a partially concurrent render should retry once,
synchronously). I'll fix this next. I need to change that behavior,
anyway, to support retries that occur as a result of `flushSync`.

* Retry once after error even for sync renders

Except in legacy mode.

This is to support the `useOpaqueReference` hook, which uses an error
to trigger a retry at lower priority.

* Move partial tree check to performSyncWorkOnRoot

* Factor out render phase

Splits the work loop and its surrounding enter/exit code into their own
functions. Now we can do perform multiple render phase passes within a
single call to performConcurrentWorkOnRoot or performSyncWorkOnRoot.
This lets us get rid of the `didError` field.
2020-03-03 13:42:18 -08:00
Brian Vaughn
d2158d6ccb Fix flow types (#18204)
* Added missing @flow pragma to React.js

* Fixed useContext() return type definition

* Fixed previously masked Flow errors in DevTools and react-interactions packages

* Added displayName to internal Context Flow type

* Removed Flow generic annotations for createResponder

This seems to cause a parsing error. (Not sure why.) The API is deprecated anyway so I'm being lazy for now and just adding a .
2020-03-03 12:46:24 -08:00
Dominic Gannaway
8e6a08ea4f Modern Event System: add plugin handling and forked paths (#18195) 2020-03-03 14:37:06 +00:00
Luna Ruan
7e83af17ce Put React.jsx and React.jsxDEV behind experimental build (#18023)
This PR puts the React.jsx and React.jsxDEV (enableJSXTransformAPI feature flag) in the experimental build so that we can use it to test React Native.
2020-03-02 18:08:40 -08:00
Dominic Gannaway
8cb2fb21eb Refine isFiberSuspenseAndTimedOut (#18184) 2020-03-02 14:15:42 +00:00
Dominic Gannaway
dbc7b9f50c Fix bug with PressLegacy blur (#18194) 2020-03-02 13:42:46 +00:00
Dominic Gannaway
62861bbcc7 More event system cleanup and scaffolding (#18179) 2020-03-02 10:59:07 +00:00
Sebastian Markbåge
8ccfce460f Only use Rollup's CommonJS plugin for "react-art" (#18186)
* Only use Rollup's CommonJS plugin for "react-art"

We still need it for the "art" UMD builds but nothing else should have
CommonJS dependencies anymore.

* react-debug-tools and jest-react should leave object-assign as an external dep

This avoids it being compiled into the output.
2020-02-28 16:46:16 -08:00
Minh Nguyen
c26506a7d2 Update react-shallow-renderer from 16.12.0 to 16.13.0 (#18185) 2020-02-28 16:35:52 -08:00
Eli White
26aa1987ce [Native] Enable and remove targetAsInstance feature flag. (#18182) 2020-02-28 13:45:42 -08:00
Sebastian Markbåge
4469700bb6 Change ReactVersion from CJS to ES module (#18181) 2020-02-28 13:09:02 -08:00
Sebastian Markbåge
58eedbb024 Check in a forked version of object-assign only for UMD builds (#18180)
* Check in a forked version of object-assign

This one uses ES modules so that we can inline it into UMD builds.

We could wait for object-assign to make an ESM export but we're going to
remove this dependency and assume global polyfills in the next version
anyway. However, we'd have to figure out how to keep the copyright header
and it'll get counted in terms of byte size (even if other tooling removes
it).

A lot of headache when we have our own implementation anyway. So I'll just
use that.

Ours is not resilient to checking certain browser bugs but those browsers
are mostly unused anyway. (Even FB breaks on them presumably.)

We also don't need to be resilient to Symbols since the way React uses it
we shouldn't need to copy symbols

* Don't transpile Object.assign to object-assign in object-assign

The polyfill needs to be able to feature detect Object.assign.
2020-02-28 11:14:09 -08:00
Henry Q. Dineen
053347e6bc react-test-renderer: improve findByType() error message (#17439)
* improve findByType error message

* fix flow typing

* Adding a test for the "Unknown" branch when `getComponentName()` returns a falsy value. The error message in this case not the most descriptive but seems consistent with the `getComponentName(type) || 'Unknown'` pattern seen in multiple places in this code base.
2020-02-28 17:55:33 +00:00
Dan Abramov
4ee592e95a Add an early invariant to debug a mystery crash (#18159) 2020-02-28 11:56:36 +00:00
Sophie Alpert
7ea4e4111f Fix typo in warning text (#18103)
Mentioned in #18090.
2020-02-28 11:53:20 +00:00
Simen Bekkhus
79a25125b1 feat: add recommended config eslint rule (#14762)
* feat: add recommended config eslint rule

* add exhaustive-deps to recommended as well
2020-02-28 02:01:17 +00:00
Joshua Gross
ae60caacfd [Fabric] Fix targetAsInstance dispatchEvent "cannot read property of null" (#18156)
* Fix Fabric targetAsInstance dispatchEvent: targetFiber stateNode is null in some cases

Co-authored-by: Dan Abramov <dan.abramov@gmail.com>
2020-02-27 17:23:25 -08:00
Dan Abramov
d72700ff5a Remove runtime dependency on prop-types (#18127)
* Remove runtime dep on prop-types

* Fix test
2020-02-28 01:21:54 +00:00
Sebastian Markbåge
549e418830 Move remaining things to named exports (#18165)
* Move remaining things to named exports

The interesting case here is the noop renderers. The wrappers around the
reconciler now changed to use a local export that gets mutated.

ReactNoop and ReactNoopPersistent now have to destructure the object to
list out the names it's going to export. We should probably refactor
ReactNoop away from createReactNoop. Especially since it's also not Flow
typed.

* Switch interactions to star exports

This will have esModule compatibility flag on them. They should ideally
export default instead.
2020-02-27 17:18:55 -08:00
Sebastian Markbåge
739f20beda Remove Node shallow builds (#18157)
This is just a forwarding module. We can hardcode it.
2020-02-27 14:11:40 -08:00
Sebastian Markbåge
3e809bf5d4 Convert React Native builds to named exports (#18136)
These don't need any forks because we always export the same things atm.
2020-02-27 11:33:44 -08:00
Dan Abramov
869dbda722 Don't build shallow renderer for FB (#18153) 2020-02-27 18:17:58 +00:00
Minh Nguyen
293878e079 Replace ReactShallowRenderer with a dependency (#18144)
Closes #17321.
2020-02-27 18:10:25 +00:00
Dan Abramov
abcca45951 Run test-prod job for experimental builds (#18152) 2020-02-27 16:21:36 +00:00
Dan Abramov
1ad2179002 Bust Circle caches 2020-02-27 15:33:10 +00:00
Dan Abramov
b4e3148918 Remove unused flag (#18132) 2020-02-27 12:58:15 +00:00
Dan Abramov
849e8328b5 Remove unnecessary warnings (#18135) 2020-02-27 02:14:30 +00:00
Sebastian Markbåge
f9c0a45441 Convert the rest of react-dom and react-test-renderer to Named Exports (#18145)
Nothing interesting here except that ReactShallowRenderer currently exports
a class with a static method instead of an object.

I think the public API is probably just meant to be createRenderer but
currently the whole class is exposed. So this means that we have to keep
it as default export. We could potentially also expose a named export for
createRenderer but that's going to cause compatibility issues.

So I'm just going to make that export default.

Unfortunately Rollup and Babel (which powers Jest) disagree on how to
import this. So to make it work I had to move the jest tests to imports.

This doesn't work with module resetting. Some tests weren't doing that
anyway and the rest is just testing ReactShallowRenderer so meh.
2020-02-26 18:04:32 -08:00
Brian Vaughn
2738b6d022 Updated CHANGELOG to remove passive effects change from 16.13 release. (It wasn't part of that release.) 2020-02-26 13:06:02 -08:00
Dan Abramov
69c769ae04 Fix changelog link 2020-02-26 21:04:36 +00:00
Dan
efaffc4797 Prettier 2020-02-26 21:02:20 +00:00
Sunil Pai
c1c5499cc3 update version numbers for 16.13 (#18143)
also includes a bugfix when downloading error codes from circleci.
2020-02-26 20:33:29 +00:00
Sunil Pai
169b1f79be Changelog for 16.13.0 (#18124)
* Changelog for 16.13.0

* Update CHANGELOG.md
2020-02-26 20:15:01 +00:00
Brian Vaughn
71418fda3b Rearranged some DevTools Components code 2020-02-26 11:33:52 -08:00
Hristo Kanchev
d166319e86 [DevTools] Added resize support for Components panel. (#18046)
* feat: DevTools - Added Resize Support.

* feat: Prettier.

* feat: DevTools - Added debug comments.

* feat: DevTools - Removed Use Memo.

* feat: DevTools - Added types.

* feat: DevTools - Extracted values to constants.

* feat: DevTools - Removed useCallback.

* feat: DevTools - Finished refactoring.

* feat: DevTools - Merging fixup.

* feat: DevTools - Prettier fix.

* feat: DevTools - Extracted code from Components fil.

* feat: DevTools - Fixed orientation change issue.

* feat: DevTools - Added flow types for reducer and refs.

* feat: DevTools - Fixed orientation change on initial load.

* Update packages/react-devtools-shared/src/devtools/views/Components/ComponentsResizer.js

* Removed unused `orientationRef`

* Fix Flow ref issue

Co-authored-by: Brian Vaughn <brian.david.vaughn@gmail.com>
2020-02-26 11:30:42 -08:00
Brian Vaughn
e1c7e651fe Update ReactDebugHooks to handle composite hooks (#18130)
The useState hook has always composed the useReducer hook. 1:1 composition like this is fine.

But some more recent hooks (e.g. useTransition, useDeferredValue) compose multiple hooks internally. This breaks react-debug-tools because it causes off-by-N errors when the debug tools re-renders the function.

For example, if a component were to use the useTransition and useMemo hooks, the normal hooks dispatcher would create a list of first state, then callback, then memo hooks, but the debug tools package would expect a list of transition then memo. This can break user code and cause runtime errors in both the react-debug-tools package and in product code.

This PR fixes the currently broken hooks by updating debug tools to be aware of the composite hooks (how many times it should call nextHook essentially) and adds tests to make sure they don't get out of sync again. We'll need to add similar tests for future composite hooks (like useMutableSource #18000).
2020-02-26 09:28:35 -08:00
Sunil Pai
d28bd2994b remove OSS testing builds (#18138)
The testing build versions of react-dom are included in the builds right now, but we're not ready to share them yet. This PR removes them for now (back soon for the next release)
2020-02-26 13:12:55 +00:00
Sebastian Markbåge
8e13e770e3 Remove /testing entry point from 'react' package (#18137)
We're not actually building this entry point. I can't think of a reason
we'd need to fork the isomorphic one. We don't really fork it for
anything since it's so generic to work with all renderers.

Since /profiling doesn't have this, it might confuse the story if we made
people alias two things for testing but not profiling.
2020-02-26 10:48:34 +00:00
Steve Harrison
f3ecd56bea Fixed a spelling mistake in a comment. (#18119) 2020-02-25 21:01:08 -08:00
Sebastian Markbåge
60016c448b Export React as Named Exports instead of CommonJS (#18106)
* Add options for forked entry points

We currently fork .fb.js entry points. This adds a few more options.

.modern.fb.js - experimental FB builds
.classic.fb.js - stable FB builds
.fb.js - if no other FB build, use this for FB builds
.experimental.js - experimental builds
.stable.js - stable builds
.js - used if no other override exists

This will be used to have different ES exports for different builds.

* Switch React to named exports

* Export named exports from the export point itself

We need to re-export the Flow exported types so we can use them in our code.

We don't want to use the Flow types from upstream since it doesn't have the non-public APIs that we have.

This should be able to use export * but I don't know why it doesn't work.

This actually enables Flow typing of React which was just "any" before.
This exposed some Flow errors that needs fixing.

* Create forks for the react entrypoint

None of our builds expose all exports and they all differ in at least one
way, so we need four forks.

* Set esModule flag to false

We don't want to emit the esModule compatibility flag on our CommonJS
output. For now we treat our named exports as if they're CommonJS.

This is a potentially breaking change for scheduler (but all those apis
are unstable), react-is and use-subscription. However, it seems unlikely
that anyone would rely on this since these only have named exports.

* Remove unused Feature Flags

* Let jest observe the stable fork for stable tests

This lets it do the negative test by ensuring that the right tests fail.

However, this in turn will make other tests that are not behind
__EXPERIMENTAL__ fail. So I need to do that next.

* Put all tests that depend on exports behind __EXPERIMENTAL__

Since there's no way to override the exports using feature flags
in .intern.js anymore we can't use these APIs in stable.

The tradeoff here is that we can either enable the negative tests on
"stable" that means experimental are expected to fail, or we can disable
tests on stable. This is unfortunate since some of these APIs now run on
a "stable" config at FB instead of the experimental.

* Switch ReactDOM to named exports

Same strategy as React.

I moved the ReactDOMFB runtime injection to classic.fb.js

Since we only fork the entrypoint, the `/testing` entrypoint needs to
be forked too to re-export the same things plus `act`. This is a bit
unfortunate. If it becomes a pattern we can consider forking in the
module resolution deeply.

fix flow

* Fix ReactDOM Flow Types

Now that ReactDOM is Flow type checked we need to fix up its types.

* Configure jest to use stable entry for ReactDOM in non-experimental

* Remove additional FeatureFlags that are no longer needed

These are only flagging the exports and no implementation details so we
can control them fully through the export overrides.
2020-02-25 13:54:27 -08:00
Dominic Gannaway
8d7535e540 Add @nolint to FB bundle headers (#18126) 2020-02-25 14:45:31 +00:00
Dominic Gannaway
a29a273c17 [react-interactions] Ensure blur to window disengages press (#18125) 2020-02-25 14:14:19 +00:00
Moji Izadmehr
bf13d3e3c6 [eslint-plugin-react-hooks] Fix cyclic caching for loops containing a… (#16853)
* [eslint-plugin-react-hooks] Fix cyclic caching for loops containing a condition

* [eslint-plugin-react-hooks] prettier write

* [eslint-plugin-react-hooks] Fix set for tests

* Update packages/eslint-plugin-react-hooks/src/RulesOfHooks.js

Co-Authored-By: Luke Kang <kidkkr@icloud.com>

Co-authored-by: Luke Kang <kidkkr@icloud.com>
2020-02-25 11:38:23 +00:00
Haseeb Furkhan Mohammed
0e49074f7a Cross platform support to run yarn test:edge for Microsoft Edge dev tools extension (#18108)
* Test automation for edge dev tools extension

* Linter changes

* Load extension automatically.

* Fixed path in `test` command

Co-authored-by: Brian Vaughn <brian.david.vaughn@gmail.com>
2020-02-24 18:17:01 -08:00
Sebastian Markbåge
ccab494738 Move type DOMContainer to HostConfig (#18112)
Exports from ReactDOM represents React's public API. This include types
exported by React. At some point we'll start building Flow types from
these files.

The duplicate name between DOMContainer and Container seems confusing too
since it was used in the same files even though they're the same.
2020-02-24 08:57:48 -08:00
adasq
501a78881e runAllPassiveEffectDestroysBeforeCreates's feature flag description typo fixed (#18115) 2020-02-24 14:49:13 +00:00
Sebastian Markbåge
be76966f6b Code mod import * as React from 'react' in react-window (#18105) 2020-02-21 23:20:17 -08:00
Sebastian Markbåge
09348798a9 Codemod to import * as React from "react"; (#18102)
* import * as React from "react";

This is the correct way to import React from an ES module since the ES
module will not have a default export. Only named exports.

* import * as ReactDOM from "react-dom"
2020-02-21 19:45:20 -08:00
Brian Vaughn
78e816032c Don't warn about unmounted updates if pending passive unmount (#18096)
I recently landed a change to the timing of passive effect cleanup functions during unmount (see #17925). This change defers flushing of passive effects for unmounted components until later (whenever we next flush pending passive effects).

Since this change increases the likelihood of a (not actionable) state update warning for unmounted components, I've suppressed that warning for Fibers that have scheduled passive effect unmounts pending.
2020-02-21 13:11:53 -08:00
Sebastian Markbåge
2c4221ce8b Change string refs in function component message (#18031)
This should refer to string refs specifically. The forwardRef part doesn't
make any sense in this case. I think this was just an oversight.
2020-02-21 10:12:34 -08:00
Sebastian Markbåge
65bbda7f16 Rename Chunks API to Blocks (#18086)
Sounds like this is the name we're going with. This also helps us
distinguish it from other "chunking" implementation details.
2020-02-20 23:56:40 -08:00
Dan Abramov
8b596e00a4 Remove unused arguments in the reconciler (#18092) 2020-02-21 02:26:19 +00:00
Andrew Clark
5de5b61507 Bugfix: memo drops lower pri updates on bail out (#18091)
Fixes a bug where lower priority updates on a components wrapped with
`memo` are sometimes left dangling in the queue without ever being
processed, if they are preceded by a higher priority bailout.

Cause
-----

The pending update priority field is cleared at the beginning of
`beginWork`. If there is remaining work at a lower priority level, it's
expected that it will be accumulated on the work-in-progress fiber
during the begin phase.

There's an exception where this assumption doesn't hold:
SimpleMemoComponent contains a bailout that occurs *before* the
component is evaluated and the update queues are processed, which means
we don't accumulate the next priority level. When we complete the fiber,
the work loop is left to believe that there's no remaining work.

Mitigation
----------

Since this only happens in a single case, a late bailout in
SimpleMemoComponent, I've mitigated the bug in that code path by
restoring the original update priority from the current fiber.

This same case does not apply to MemoComponent, because MemoComponent
fibers do not contain hooks or update queues; rather, they wrap around
an inner fiber that may contain those. However, I've added a test case
for MemoComponent to protect against a possible future regression.

Possible next steps
-------------------

We should consider moving the update priority assignment in `beginWork`
out of the common path and into each branch, to avoid similar bugs in
the future.
2020-02-20 16:21:31 -08:00
Kunuk Nykjær
abfbae02a4 Update Rollup version to 1.19.4 and fix breaking changes (#15037)
* update rollup versioni

* ignore Rollup warnings for known warning codes

* add lecacy support from elas7

* rollup 1.5

* upd to ver 1.6.0

* don't throw error

* use return instead of throw error

* upd code in comment

* fix getters test

* rollup 1.7

* rollup 1.7.3

* remove comments

* use rollup 1.7.4

* update yarn.lock for new rollup version

* rollup version 1.9.0

* rollback to version 1.7.4

* add globalThis to eslintrc.umd

* rollup 1.9.0

* upd rollup plugin versions to satisfied latest versions

* add result.json update

* rollup 1.9.3

* rollup 1.10.0

* ver 1.10.1

* rollup 1.11.3

* rollup ver 1.12.3

* rollup 1.13.1

* rollup 1.14.6

* rollup 1.15.6

* rollup 1.16.2

* upd tests

* prettier

* Rollup 1.16.3

* upd

* should throw when finding getters with a different syntax from the ones generated by Rollup

* add more one test

* rollup-plugin-prettier updated changed stuff, revert them

* don't upd all the Rollup plugins

* rollup-plugin-babel 3.0.7

* upd rollup plugin versions

* upd rollup-plugin-commonjs

* bracket spacing

* rollup 1.16.6

* rollup 1.16.7

* rename test description

* rollup 1.18.0

* use externalLiveBindings: false

* rollup 1.19.3

* remove remove-getters

* simplify CIRCULAR_DEPENDENCY warning

* simplify if logic in sizes-plugin

* rollup 1.19.4

* update output for small optimizations

* remove globalThis

* remove results.json file

* re-add globalThis
2020-02-20 22:09:30 +00:00
Sunil Pai
b789060dca Feature Flag for React.jsx` "spreading a key to jsx" warning (#18074)
Adds a feature flag for when React.jsx warns you about spreading a key into jsx. It's false for all builds, except as a dynamic flag for fb/www.

I also included the component name in the warning.
2020-02-20 11:30:04 +00:00
Dominic Gannaway
3f85d53ca6 Further pre-requisite changes to plugin event system (#18083) 2020-02-20 00:46:03 +00:00
Andrew Clark
ea6ed3dbbd Warn for update on different component in render (#17099)
This warning already exists for class components, but not for functions.

It does not apply to render phase updates to the same component, which
have special semantics that we do support.
2020-02-19 12:43:14 -08:00
Eli White
085d02133e [Native] Migrate focus/blur to call TextInputState with the host component (#18068) 2020-02-19 11:33:40 -08:00
Brian Vaughn
7e770dae93 Profiler tooltip tweaks (#18082)
* Moved Profiler views into Profiler folder

* Tweaked Profiler tooltip CSS styles

* Tweaked Tooltip positioning code
2020-02-19 10:58:45 -08:00
Dominic Gannaway
b6c94d636c Add guard around FocusWithin responder root events (#18080) 2020-02-19 18:32:18 +00:00
Dominic Gannaway
1000f6135e Add container to event listener signature (#18075) 2020-02-19 18:00:57 +00:00
Dan Abramov
a12dd52a4a Don't build some packages for WWW (#18078) 2020-02-19 17:59:42 +00:00
Moji Izadmehr
44e5f5e645 Add fiber summary tooltip to devtools profiling (#18048)
* Add tooltip component

* Separate logic of ProfilerWhatChanged to a component

* Add hovered Fiber info tooltip component

* Add flame graph chart tooltip

* Add commit ranked list tooltip

* Fix flow issues

* Minor improvement in filter

* Fix flickering issue

* Resolved issues on useCallbacks and mouse event listeners

* Fix lints

* Remove unnecessary useCallback
2020-02-19 09:44:31 -08:00
Dominic Gannaway
2512c309e3 Remove Flare bundles from build (#18077) 2020-02-19 17:25:41 +00:00
Sunil Pai
a8643e905e add no-restricted-globals to eslint config (#18076)
Our current lint config assumes a browser environment, which means it won't warn you if you use a variable like `name` without declaring it earlier. This imports the same list as the one used by create-react-app, and enables it against our codebase.
2020-02-19 17:14:53 +00:00
Dominic Gannaway
4912ba31e3 Add modern event system flag + rename legacy plugin module (#18073) 2020-02-19 14:36:39 +00:00
Andrew Clark
4d9f850065 Re-throw errors thrown by the renderer at the root in the complete phase (#18029)
* Re-throw errors thrown by the renderer at the root

React treats errors thrown at the root as a fatal because there's no
parent component that can capture it. (This is distinct from an
"uncaught error" that isn't wrapped in an error boundary, because in
that case we can fall back to deleting the whole tree -- not great, but
at least the error is contained to a single root, and React is left in a
consistent state.)

It turns out we didn't have a test case for this path. The only way it
can happen is if the renderer's host config throws. We had similar test
cases for host components, but none for the host root.

This adds a new test case and fixes a bug where React would keep
retrying the root because the `workInProgress` pointer was not advanced
to the next fiber. (Which in this case is `null`, since it's the root.)

We could consider in the future trying to gracefully exit from certain
types of root errors without leaving React in an inconsistent state. For
example, we should be able to gracefully exit from errors thrown in the
begin phase. For now, I'm treating it like an internal invariant and
immediately exiting.

* Add comment
2020-02-18 15:55:38 -08:00
Brian Vaughn
14afeb1033 Added missing feature flag 2020-02-18 14:49:57 -08:00
Brian Vaughn
691096c95d Split recent passive effects changes into 2 flags (#18030)
* Split recent passive effects changes into 2 flags

Separate flags can now be used to opt passive effects into:
1) Deferring destroy functions on unmount to subsequent passive effects flush
2) Running all destroy functions (for all fibers) before create functions

This allows us to test the less risky feature (2) separately from the more risky one.

* deferPassiveEffectCleanupDuringUnmount is ignored unless runAllPassiveEffectDestroysBeforeCreates is true
2020-02-18 14:19:43 -08:00
Andrew Clark
56d8a73aff [www] Disable Scheduler timeout w/ dynamic flag (#18069)
Before attempting to land an expiration times refactor, I want to see
if this particular change will impact performance (either positively
or negatively). I will test this with a GK.
2020-02-18 13:43:16 -08:00
Dominic Gannaway
1a6d8179b6 [react-interactions] Ensure onBeforeBlur fires for hideInstance (#18064) 2020-02-18 18:50:38 +00:00
Ryota Murakami
48c4867d74 Update issue templates to directly link to relevant sources (#18039)
GitHub supports linking to off-site sources for certain types of issue.
2020-02-18 10:30:00 -08:00
Brian Vaughn
90be006da8 Updated Yarn lockfile 2020-02-18 09:40:59 -08:00
Haseeb Furkhan Mohammed
d5ddc16a33 React developer tools extension for Microsoft Edge (#18041)
* Port Chrome extension to Microsoft Edge
2020-02-18 09:40:30 -08:00
Dominic Gannaway
f48a5e64e8 Further cleanup of plugin event system (#18056) 2020-02-18 13:31:59 +00:00
Dan Abramov
d533229fba Fix Prettier 2020-02-17 20:36:16 +00:00
Dan Abramov
56a8c35321 eslint-plugin-react-hooks@2.4.0 2020-02-17 20:26:56 +00:00
Will Douglas
93a229bab5 Update eslint rule exhaustive deps to use new suggestions feature (#17385)
This closes #16313
2020-02-17 20:24:27 +00:00
Dominic Gannaway
9def56ec0e Refactor DOM plugin system to single module (#18025) 2020-02-14 08:10:42 +00:00
Eli White
2d6be757df [Native] Delete NativeComponent and NativeMethodsMixin (#18036)
* [Native] Delete NativeComponent and NativeMethodsMixin

* Remove more files
2020-02-13 15:09:25 -08:00
Luna Ruan
d4f2b0379c Add Auto Import to Babel Plugin (#16626)
This babel transform is a fork of the @babel/plugin-transform-react-jsx transform and is for experimentation purposes only. We don't plan to own this code in the future, and we will upstream this to Babel at some point once we've proven out the concept.

As per the RFC to simplify element creation, we want to add the ability to auto import "react' directly from the babel plugin. This commit updates the babel plugin with two options:

1.) importSource: The React module to import from. Defaults to react.
2.) autoImport: The type of import. Defaults to none.
- none: Does not import React. JSX compiles to React.jsx etc.
- namespace: import * as _react from "react";. JSX compiles to _react.jsx etc.
- default: import _default from "react"; JSX compiles to _default.jsx etc.
- namedExports: import {jsx as _jsx} from "react"; JSX compiles to _jsx etc.
- require: var _react = _interopRequireWildcard(require("react"));. jSX compiles to _react.jsx etc.

namespace, default, and namedExports can only be used when sourceType: module and require can only be used when sourceType: script.

It also adds two pragmas (jsxAutoImport and jsxImportSource) that allow users to specify autoImport and importSource in the docblock.
2020-02-13 12:36:19 -08:00
Dan Abramov
8777b44e98 Add Modern WWW build (#18028)
* Build both stable and experimental WWW builds

* Flip already experimental WWW flags to true

* Remove FB-specific internals from modern FB builds

We think we're not going to need these.

* Disable classic features in modern WWW builds

* Disable legacy ReactDOM API for modern WWW build

* Don’t include user timing in prod

* Fix bad copy paste and add missing flags to test renderer

* Add testing WWW feature flag file

We need it because WWW has a different meaning of experimental now.
2020-02-13 20:33:53 +00:00
Sunil Pai
58b8797b73 remove "Unreleased" section from CHANGELOG (#18027)
This section is empty, and imo isn't really helpful in React's changelog. I'm honestly not sure why this is even here? Figured I'd start a discussion with a PR, or we can remove it right now.
2020-02-12 17:17:49 +00:00
Dan Abramov
a607ea4c42 Remove getIsHydrating (#18019) 2020-02-12 01:01:29 +00:00
Dominic Gannaway
988f4b14ee Do not export passiveBrowserEventsSupported from Focus responder (#18022)
Remove code
2020-02-11 15:57:37 -08:00
Brian Vaughn
f7278034de Flush all passive destroy fns before calling create fns (#17947)
* Flush all passive destroy fns before calling create fns

Previously we only flushed destroy functions for a single fiber.

The reason this is important is that interleaving destroy/create effects between sibling components might cause components to interfere with each other (e.g. a destroy function in one component may unintentionally override a ref value set by a create function in another component).

This PR builds on top of the recently added deferPassiveEffectCleanupDuringUnmount kill switch to separate passive effects flushing into two separate phases (similar to layout effects).

* Change passive effect flushing to use arrays instead of lists

This change offers a small advantage over the way we did things previous: it continues invoking destroy functions even after a previous one errored.
2020-02-11 09:52:54 -08:00
Dominic Gannaway
529e58ab0a Remove legacy www config from Rollup build (#18016) 2020-02-11 13:42:19 +00:00
Dominic Gannaway
42918f40aa Change build from babylon to babel (#18015) 2020-02-11 11:56:26 +00:00
Dominic Gannaway
df5faddcc2 Refactor commitPlacement to recursively insert nodes (#17996) 2020-02-10 23:38:24 +00:00
Dan Abramov
ab7b83a924 Stop exposing some internals on FB build (#18011) 2020-02-10 19:52:27 +00:00
Dan Abramov
517de74b0c Tweak comment wording (#18007)
* Revert "Update ReactFiberExpirationTime.js (#17825)"

This reverts commit b63cb6f6cf.

* Reword
2020-02-10 16:15:10 +00:00
haseeb
b63cb6f6cf Update ReactFiberExpirationTime.js (#17825)
replaced 'add' with 'subtract'
2020-02-10 12:37:49 +00:00
Jesse Katsumata
89c6042df3 fix: typo in test (#18005) 2020-02-10 12:34:09 +00:00
Sophie Alpert
4f71f25a34 Re-enable shorthand CSS property collision warning (#18002)
Originally added in https://github.com/facebook/react/pull/14181; disabled in https://github.com/facebook/react/pull/14245. Intention was to enable it in React 16.7 but we forgot.
2020-02-10 11:42:11 +00:00
Brian Vaughn
e05dedc415 Added $FlowFixMe to DevTools shell for module we Flow-ignore (#18001) 2020-02-07 14:36:51 -08:00
Dan Abramov
d1bfdfb861 Ignore react-native-web in Flow checks (#17999) 2020-02-07 16:24:25 +00:00
Dominic Gannaway
c55c34e46a Move React Map child check to behind flags or __DEV__ (#17995) 2020-02-07 12:21:50 +00:00
cutjavascript
901d76bc5c dataForRoots.set duplicate removal (#17993)
dataForRoots.set duplicate removal
2020-02-06 11:48:02 -08:00
Dan Abramov
3f814e7582 Fix Flow type for React Native (#17992) 2020-02-06 18:31:13 +00:00
Dominic Gannaway
256d78d11f Add feature flag for removing children Map support (#17990) 2020-02-06 13:19:35 +00:00
Dominic Gannaway
df134d31cb Use babel parser rather than Babylon in extract errors (#17988) 2020-02-06 12:46:32 +00:00
Brian Vaughn
9e158c091b Updated release script documentation and command names (#17929)
* Updated release script documentation and command names

* Update scripts/release/README.md

Co-Authored-By: Sunil Pai <threepointone@oculus.com>

* Updated README

Co-authored-by: Sunil Pai <threepointone@oculus.com>
2020-02-05 08:52:31 -08:00
Sunil Pai
d84c539b31 fix sizebot - point correctly to circleci artifact (#17975)
similar to #17972, this should fix sizebot not reporting stats right now
2020-02-04 14:03:12 -08:00
Brian Vaughn
613cbd3ace Formatting fix (Prettier) to build script 2020-02-04 11:37:38 -08:00
Brian Vaughn
562d2fbc49 Fix release scripts (#17972)
Circle CI seems to have changed the reported artifact path which broke our scripts.
2020-02-04 11:36:49 -08:00
Andrew Clark
9dba218d93 [Mock Scheduler] Mimic browser's advanceTime (#17967)
The mock Scheduler that we use in our tests has its own fake timer
implementation. The `unstable_advanceTime` method advances the timeline.

Currently, a call to `unstable_advanceTime` will also flush any pending
expired work. But that's not how it works in the browser: when a timer
fires, the corresponding task is added to the Scheduler queue. However,
we will still wait until the next message event before flushing it.

This commit changes `unstable_advanceTime` to more closely resemble the
browser behavior, by removing the automatic flushing of expired work.

```js
// Before this commit
Scheduler.unstable_advanceTime(ms);

// Equivalent behavior after this commit
Scheduler.unstable_advanceTime(ms);
Scheduler.unstable_flushExpired();
```

The general principle is to prefer separate APIs for scheduling tasks
and flushing them.

This change does not affect any public APIs. `unstable_advanceTime` is
only used by our own test suite. It is not used by `act`.

However, we may need to update tests in www, like Relay's.
2020-02-04 11:35:21 -08:00
Murat ÇATAL
cddde45806 apply changes on editablevalue on blur feature implemented (#17062)
* apply changes on editablevalue on blur feature implemented

* Removed "Undo" button and unnecessary event.preventDefault()

Co-authored-by: Brian Vaughn <brian.david.vaughn@gmail.com>
2020-02-04 11:05:01 -08:00
Dan Abramov
d6e08fe0a8 Remove Suspense priority warning (#17971)
* Remove Suspense priority warning

* Fix tests
2020-02-04 18:05:15 +00:00
Alfredo Granja
812277dab6 Fix onMouseEnter is fired on disabled buttons (#17675) 2020-02-04 14:56:55 +00:00
Hassan Alam
2078aa9a40 Add dom fixture for autofilled form state (#17951) 2020-02-04 14:53:35 +00:00
Sunil Pai
3e9251d605 make testing builds for React/ReactDOM (#17915)
This PR introduces adds `react/testing` and `react-dom/testing`.
- changes infra to generate these builds
- exports act on ReactDOM in these testing builds
- uses the new test builds in fixtures/dom

In the next PR -

- I'll use the new builds for all our own tests
- I'll replace usages of TestUtils.act with ReactDOM.act.
2020-02-03 23:31:31 +00:00
Sebastian Markbåge
ace9e8134c Simplify Continuous Hydration Targets (#17952)
* Simplify Continuous Hydration Targets

Let's use a constant priority for this. This helps us avoid restarting
a render when switching targets and simplifies the model.

The downside is that now we're not down-prioritizing the previous hover
target. However, we think that's ok because it'll only do one level too
much and then stop.

* Add test meant to show why it's tricky to merge both hydration levels

Having both levels co-exist works. However, if we deprioritize hydration
using a single level, we might deprioritize the wrong thing.

This adds a test that catches it if we ever try a naive deprioritization
in the future.

It also tests that we don't down-prioritize if we're changing the hover
in the middle of doing continuous priority work.
2020-02-03 12:47:14 -08:00
Brian Vaughn
7df32c4c8c Flush useEffect clean up functions in the passive effects phase (#17925)
* Flush useEffect clean up functions in the passive effects phase

This is a change in behavior that may cause broken product code, so it has been added behind a killswitch (deferPassiveEffectCleanupDuringUnmount)

* Avoid scheduling unnecessary callbacks for cleanup effects

Updated enqueuePendingPassiveEffectDestroyFn() to check rootDoesHavePassiveEffects before scheduling a new callback. This way we'll only schedule (at most) one.

* Updated newly added test for added clarity.

* Cleaned up hooks effect tags

We previously used separate Mount* and Unmount* tags to track hooks work for each phase (snapshot, mutation, layout, and passive). This was somewhat complicated to trace through and there were man tag types we never even used (e.g. UnmountLayout, MountMutation, UnmountSnapshot). In addition to this, it left passive and layout hooks looking the same after renders without changed dependencies, which meant we were unable to reliably defer passive effect destroy functions until after the commit phase.

This commit reduces the effect tag types to only include Layout and Passive and differentiates between work and no-work with an HasEffect flag.

* Disabled deferred passive effects flushing in OSS builds for now

* Split up unmount and mount effects list traversal
2020-02-03 12:30:01 -08:00
Evyatar
9944bf27fb Add version property to ReactDOM (#15780) 2020-02-03 11:19:04 -08:00
Dominic Gannaway
434770c3b4 Add beforeRemoveInstance method to ReactNoop (#17959) 2020-02-03 11:31:51 +00:00
Mark Huang
08c1f79e1e Fix Cannot read property 'sub' of undefined when navigating to plain-text pages (#17848)
Update various parts of DevTools to account for the fact that the global "hook" might be undefined if DevTools didn't inject it (due to the page's `contentType`) it (due to the page's `contentType`)
2020-02-02 12:04:48 -08:00
Brian Vaughn
9ad35905fa Add DevTools tests for copying complex values (#17948) 2020-01-31 15:17:57 -08:00
Deniz Susman
00745b053f Typo fix (#17946) 2020-01-31 14:51:43 -08:00
Farhad Yasir
d9a5170594 fix: check bigint in serializeToString and change it to string (#17931) 2020-01-31 14:35:59 -08:00
Nicolas Gallagher
38cd75861f Update google-closure-compiler (#17902) 2020-01-30 17:34:03 -08:00
Brian Vaughn
6ae2c33a75 StrictMode should call sCU twice in DEV (#17942) 2020-01-30 13:03:44 -08:00
Andrew Clark
9dbe1c54df Revert "Bugfix: Expiring a partially completed tree (#17926)" (#17941)
This reverts commit 01974a867c.

* Failing test: Expiring a partially completed tree

We should not throw out a partially completed tree if it expires in the
middle of rendering. We should finish the rest of the tree without
yielding, then finish any remaining expired levels in a single batch.

* Check if there's a partial tree before restarting

If a partial render expires, we should stay in the concurrent path
(performConcurrentWorkOnRoot); we'll stop yielding, but the rest of the
behavior remains the same.

We will only revert to the sync path (performSyncWorkOnRoot) when
starting on a new level.

This approach prevents partially completed concurrent work from
being discarded.

* New test: retry after error during expired render
2020-01-30 11:14:57 -08:00
Brian Vaughn
d2ae77d0e4 Remove root.unmount() callback from DevTools code (#17939) 2020-01-30 09:36:43 -08:00
Sebastian Markbåge
e98797f7b9 Fix Event Replaying in Flare by Eagerly Adding Active Listeners (#17933)
* Add test of Event Replaying using Flare

* Fix Event Replaying in Flare by Eagerly Adding Active Listeners

This effectively reverts part of https://github.com/facebook/react/pull/17513
2020-01-30 09:32:41 -08:00
Dominic Gannaway
1662035852 Ensure createRoot warning parity with ReactDOM.render (#17937) 2020-01-30 17:17:42 +00:00
Dominic Gannaway
b2382a7150 Add ReactDOM.unstable_renderSubtreeIntoContainer warning flag (#17936) 2020-01-30 11:56:04 +00:00
Andrew Clark
01974a867c Bugfix: Expiring a partially completed tree (#17926)
* Failing test: Expiring a partially completed tree

We should not throw out a partially completed tree if it expires in the
middle of rendering. We should finish the rest of the tree without
yielding, then finish any remaining expired levels in a single batch.

* Check if there's a partial tree before restarting

If a partial render expires, we should stay in the concurrent path
(performConcurrentWorkOnRoot); we'll stop yielding, but the rest of the
behavior remains the same.

We will only revert to the sync path (performSyncWorkOnRoot) when
starting on a new level.

This approach prevents partially completed concurrent work from
being discarded.

* New test: retry after error during expired render
2020-01-29 12:40:18 -08:00
Dan Abramov
241c4467ee Add a note about expiring OTP codes 2020-01-29 16:31:51 +00:00
Dan Abramov
faabe22b4f Use next tag for canary releases in the doc (#17923) 2020-01-29 16:09:05 +00:00
Dan Abramov
57333ca33a Show first component stack in context warning (#17922)
* Update tests

* Show first component stack in context warning

Co-authored-by: Dominic Gannaway <trueadm@users.noreply.github.com>
2020-01-29 14:57:52 +00:00
Dan Abramov
a8fce06d3e Fix Jest diff call (#17921) 2020-01-29 14:38:22 +00:00
Dan Abramov
29a1559619 Add semver dependency explicitly to DevTools (#17919) 2020-01-29 14:20:56 +00:00
Dominic Gannaway
b7f217d40c [Concurrent Mode] Add missing event plugin priorities (#17914) 2020-01-28 13:20:26 +00:00
Brian Vaughn
e26682a9f3 Removed Root API callback params and added warnings (#17916) 2020-01-27 12:35:08 -08:00
Simen Bekkhus
cf0081263c Upgrade to jest 25 (#17896)
The changes to the test code relate to changes in JSDOM that come with Jest 25:

* Several JSDOM workarounds are no longer needed.
* Several tests made assertions to match incorrect JSDOM behavior (e.g. setAttribute calls) that JSDOM has now patched to match browsers.
  * https://codesandbox.io/s/resets-value-of-datetime-input-to-fix-bugs-in-ios-safari-1ppwh
* JSDOM no longer triggers default actions when dispatching click events.
  * https://codesandbox.io/s/beautiful-cdn-ugn8f
* JSDOM fixed (jsdom/jsdom#2700) a bug so that calling focus() on an already focused element does not dispatch a FocusEvent.
* JSDOM now supports passive events.
* JSDOM has improved support for custom CSS properties.
  * But requires jsdom/cssstyle#112 to land to support webkit prefixed properties.
2020-01-25 08:43:02 -08:00
Nicolas Gallagher
6faf6f5eb1 Update to flow 0.97 (#17892) 2020-01-24 10:52:38 -08:00
Nicolas Gallagher
81e30c7ff6 Remove unused modules from legacy event responders (#17907) 2020-01-24 10:50:27 -08:00
Nicolas Gallagher
9d09052d2f Update various monorepo dependencies (#17901) 2020-01-24 10:28:50 -08:00
Simen Bekkhus
3c713d5131 chore: update to latest release of babel (#17897) 2020-01-24 17:49:24 +00:00
Luna Ruan
3b3decf871 add warning when owner and self are different for string refs (#17864)
When owner and self are different for string refs, we can't easily convert them to callback refs. This PR adds a warning for string refs when owner and self are different to tell users to manually update these refs.
2020-01-22 12:32:51 -08:00
Nicolas Gallagher
6c00c5bba4 Update to flow-bin@0.89 (#17842) 2020-01-22 10:02:30 -08:00
Sebastian Markbåge
cf7a0c24d4 Remove dynamic GKs for selective/train (#17888)
There are shipped/shipping.
2020-01-21 19:43:35 -08:00
Dominic Gannaway
c322f5913f Add unstable_renderSubtreeIntoContainer and unstable_createPortal feature flags (#17880) 2020-01-21 21:17:42 +00:00
Dominic Gannaway
f2fd484afd Add React.createFactory() deprecation warning (#17878) 2020-01-21 15:51:39 +00:00
Sebastian Markbåge
0c04acaf89 Remove FB specific build (#17875)
I moved unstable_SuspenseList internally. We don't need the FB build.
I plan on also removing the ReactDOM fb specific entry. We shouldn't add
any more FB specific internals nor APIs. If they're experimental they
should go onto the experimental builds to avoid too many permutations.
2020-01-20 16:06:01 -08:00
Dominic Gannaway
9fd760ce75 Add disable <textarea/> children flag (#17874) 2020-01-20 15:12:30 +00:00
Dominic Gannaway
a209a97ed7 Add feature flag around React.createFactory (#17873) 2020-01-20 15:00:18 +00:00
Andrew Clark
95bd7aad7d Remove renderPhaseUpdates Map (#17625)
* Remove renderPhaseUpdates Map

Follow up to #17484, which was reverted due to a bug found in www.

* Failing test: Dropped updates

When resetting render phase updates after a throw, we should only clear
the pending queue of hooks that were already processed.

* Fix non-render-phase updates being dropped

Detects if a queue has been processed by whether the hook was cloned.
If we change the implementation to an array instead of a list, we'll
need some other mechanism to determine whether the hook was processed.

* Regression test: startTransition in render phase

useTransition uses the state hook as part of its implementation, so we
need to fork it in the dispatcher used for re-renders, too.
2020-01-17 16:00:35 -05:00
6716 changed files with 808024 additions and 180700 deletions

View File

@@ -1,441 +1,591 @@
version: 2
version: 2.1
aliases:
- &docker
- image: circleci/openjdk:8-jdk-node-browsers
- image: cimg/node:18.20.1-browsers
- &environment
TZ: /usr/share/zoneinfo/America/Los_Angeles
- &restore_yarn_cache
- &restore_yarn_cache_fixtures_dom
restore_cache:
name: Restore node_modules cache
name: Restore yarn cache for fixtures/dom
keys:
- v1-node-{{ arch }}-{{ .Branch }}-{{ checksum "yarn.lock" }}
- v1-node-{{ arch }}-{{ .Branch }}-
- v1-node-{{ arch }}-
- &run_yarn
- v2-yarn_cache-{{ arch }}-{{ checksum "yarn.lock" }}-fixtures/dom
- &yarn_install_fixtures_dom
run:
name: Install Packages
command: yarn --frozen-lockfile
name: Install dependencies in fixtures/dom
working_directory: fixtures/dom
command: yarn install --frozen-lockfile --cache-folder ~/.cache/yarn
- &yarn_install_fixtures_dom_retry
run:
name: Install dependencies in fixtures/dom (retry)
when: on_fail
working_directory: fixtures/dom
command: yarn install --frozen-lockfile --cache-folder ~/.cache/yarn
- &save_yarn_cache_fixtures_dom
save_cache:
name: Save yarn cache for fixtures/dom
key: v2-yarn_cache-{{ arch }}-{{ checksum "yarn.lock" }}-fixtures/dom
paths:
- ~/.cache/yarn
- &TEST_PARALLELISM 20
- &attach_workspace
at: build
- &process_artifacts
docker: *docker
environment: *environment
commands:
setup_node_modules:
description: "Restore node_modules"
steps:
- checkout
- attach_workspace: *attach_workspace
- *restore_yarn_cache
- *run_yarn
- run: node ./scripts/rollup/consolidateBundleSizes.js
- run: ./scripts/circleci/upload_build.sh
- run: ./scripts/circleci/pack_and_store_artifact.sh
- store_artifacts:
path: ./node_modules.tgz
- store_artifacts:
path: ./build.tgz
- store_artifacts:
path: ./build/bundle-sizes.json
- store_artifacts:
# TODO: Update release script to use local file instead of pulling
# from artifacts.
path: ./scripts/error-codes/codes.json
- persist_to_workspace:
root: build
paths:
- bundle-sizes.json
jobs:
setup:
docker: *docker
environment: *environment
steps:
- checkout
- restore_cache:
name: Restore yarn cache
keys:
- v2-yarn_cache-{{ arch }}-{{ checksum "yarn.lock" }}
- run:
name: Nodejs Version
command: node --version
- *restore_yarn_cache
- *run_yarn
name: Install dependencies
command: |
yarn install --frozen-lockfile --cache-folder ~/.cache/yarn
if [ $? -ne 0 ]; then
yarn install --frozen-lockfile --cache-folder ~/.cache/yarn
fi
environment:
# If we start needing the Electron binary, please ensure the binary is cached in CI following https://www.electronjs.org/docs/latest/tutorial/installation
ELECTRON_SKIP_BINARY_DOWNLOAD: 1
- save_cache:
name: Save node_modules cache
key: v1-node-{{ arch }}-{{ .Branch }}-{{ checksum "yarn.lock" }}
name: Save yarn cache
key: v2-yarn_cache-{{ arch }}-{{ checksum "yarn.lock" }}
paths:
- ~/.cache/yarn
lint:
# The CircleCI API doesn't yet support triggering a specific workflow, but it
# does support triggering a pipeline. So as a workaround you can triggger the
# entire pipeline and use parameters to disable everything except the workflow
# you want. CircleCI recommends this workaround here:
# https://support.circleci.com/hc/en-us/articles/360050351292-How-to-trigger-a-workflow-via-CircleCI-API-v2-
parameters:
# This is only set when triggering the CI pipeline via an API request.
prerelease_commit_sha:
type: string
default: ''
jobs:
scrape_warning_messages:
docker: *docker
environment: *environment
steps:
- checkout
- *restore_yarn_cache
- *run_yarn
- run: node ./scripts/prettier/index
- run: node ./scripts/tasks/eslint
- run: ./scripts/circleci/check_license.sh
- run: ./scripts/circleci/check_modules.sh
- run: ./scripts/circleci/test_print_warnings.sh
flow:
docker: *docker
environment: *environment
steps:
- checkout
- *restore_yarn_cache
- *run_yarn
- run: node ./scripts/tasks/flow-ci
test_source:
docker: *docker
environment: *environment
steps:
- checkout
- *restore_yarn_cache
- *run_yarn
- setup_node_modules
- run:
environment:
RELEASE_CHANNEL: stable
command: yarn test --maxWorkers=2
test_source_experimental:
docker: *docker
environment: *environment
steps:
- checkout
- *restore_yarn_cache
- *run_yarn
- run:
environment:
RELEASE_CHANNEL: experimental
command: yarn test --maxWorkers=2
test_source_persistent:
docker: *docker
environment: *environment
steps:
- checkout
- *restore_yarn_cache
- *run_yarn
- run:
environment:
RELEASE_CHANNEL: stable
command: yarn test-persistent --maxWorkers=2
test_source_prod:
docker: *docker
environment: *environment
steps:
- checkout
- *restore_yarn_cache
- *run_yarn
- run:
environment:
RELEASE_CHANNEL: stable
command: yarn test-prod --maxWorkers=2
build:
docker: *docker
environment: *environment
parallelism: 20
steps:
- checkout
- *restore_yarn_cache
- *run_yarn
- run:
environment:
RELEASE_CHANNEL: stable
command: |
./scripts/circleci/add_build_info_json.sh
./scripts/circleci/update_package_versions.sh
yarn build
- run: echo "stable" >> build/RELEASE_CHANNEL
mkdir -p ./build/__test_utils__
node ./scripts/print-warnings/print-warnings.js > build/__test_utils__/ReactAllWarnings.js
- persist_to_workspace:
root: build
root: .
paths:
- RELEASE_CHANNEL
- facebook-www
- node_modules
- react-native
- dist
- sizes/*.json
- build
build_experimental:
yarn_build:
docker: *docker
environment: *environment
parallelism: 20
parallelism: 40
steps:
- checkout
- *restore_yarn_cache
- *run_yarn
- setup_node_modules
- run: yarn build
- persist_to_workspace:
root: .
paths:
- build
download_build:
docker: *docker
environment: *environment
parameters:
revision:
type: string
steps:
- checkout
- setup_node_modules
- run:
environment:
RELEASE_CHANNEL: experimental
name: Download artifacts for revision
command: |
./scripts/circleci/add_build_info_json.sh
./scripts/circleci/update_package_versions.sh
yarn build
- run: echo "experimental" >> build/RELEASE_CHANNEL
git fetch origin main
cd ./scripts/release && yarn && cd ../../
scripts/release/download-experimental-build.js --commit=<< parameters.revision >> --allowBrokenCI
- persist_to_workspace:
root: build
root: .
paths:
- RELEASE_CHANNEL
- facebook-www
- node_modules
- react-native
- dist
- sizes/*.json
- build
build_devtools_and_process_artifacts:
download_base_build_for_sizebot:
docker: *docker
environment: *environment
parallelism: 20
steps:
- checkout
- attach_workspace: *attach_workspace
- *restore_yarn_cache
- *run_yarn
- setup_node_modules
- run:
environment:
RELEASE_CHANNEL: experimental
command: ./scripts/circleci/pack_and_store_devtools_artifacts.sh
name: Download artifacts for base revision
command: |
git fetch origin main
cd ./scripts/release && yarn && cd ../../
scripts/release/download-experimental-build.js --commit=$(git merge-base HEAD origin/main) --allowBrokenCI
mv ./build ./base-build
- run:
# TODO: The `download-experimental-build` script copies the npm
# packages into the `node_modules` directory. This is a historical
# quirk of how the release script works. Let's pretend they
# don't exist.
name: Delete extraneous files
command: rm -rf ./base-build/node_modules
- persist_to_workspace:
root: .
paths:
- base-build
process_artifacts_combined:
docker: *docker
environment: *environment
steps:
- checkout
- attach_workspace:
at: .
- setup_node_modules
- run: echo "<< pipeline.git.revision >>" >> build/COMMIT_SHA
# Compress build directory into a single tarball for easy download
- run: tar -zcvf ./build.tgz ./build
# TODO: Migrate scripts to use `build` directory instead of `build2`
- run: cp ./build.tgz ./build2.tgz
- store_artifacts:
path: ./build/devtools.tgz
# These jobs are named differently so we can distinguish the stable and
# and experimental artifacts
process_artifacts: *process_artifacts
process_artifacts_experimental: *process_artifacts
path: ./build2.tgz
- store_artifacts:
path: ./build.tgz
sizebot:
docker: *docker
environment: *environment
steps:
- checkout
- attach_workspace: *attach_workspace
- *restore_yarn_cache
- *run_yarn
# This runs in the process_artifacts job, too, but it's faster to run
# this step in both jobs instead of running the jobs sequentially
- run: node ./scripts/rollup/consolidateBundleSizes.js
- attach_workspace:
at: .
- run: echo "<< pipeline.git.revision >>" >> build/COMMIT_SHA
- setup_node_modules
- run:
environment:
RELEASE_CHANNEL: stable
command: node ./scripts/tasks/danger
- store_artifacts:
path: sizebot-message.md
sizebot_experimental:
build_devtools_and_process_artifacts:
docker: *docker
environment: *environment
steps:
- checkout
- attach_workspace: *attach_workspace
- *restore_yarn_cache
- *run_yarn
# This runs in the process_artifacts job, too, but it's faster to run
# this step in both jobs instead of running the jobs sequentially
- run: node ./scripts/rollup/consolidateBundleSizes.js
- attach_workspace:
at: .
- setup_node_modules
- run:
environment:
RELEASE_CHANNEL: experimental
command: node ./scripts/tasks/danger
command: ./scripts/circleci/pack_and_store_devtools_artifacts.sh
- store_artifacts:
path: ./build/devtools.tgz
# Simplifies getting the extension for local testing
- store_artifacts:
path: ./build/devtools/chrome-extension.zip
destination: react-devtools-chrome-extension.zip
- store_artifacts:
path: ./build/devtools/firefox-extension.zip
destination: react-devtools-firefox-extension.zip
lint_build:
run_devtools_e2e_tests:
docker: *docker
environment: *environment
steps:
- checkout
- attach_workspace: *attach_workspace
- *restore_yarn_cache
- *run_yarn
- attach_workspace:
at: .
- setup_node_modules
- run:
name: Playwright install deps
command: |
npx playwright install
sudo npx playwright install-deps
- run:
environment:
RELEASE_CHANNEL: experimental
command: ./scripts/circleci/run_devtools_e2e_tests.js
run_fixtures_flight_tests:
docker: *docker
environment: *environment
steps:
- checkout
- attach_workspace:
at: .
# Fixture copies some built packages from the workroot after install.
# That means dependencies of the built packages are not installed.
# We need to install dependencies of the workroot to fulfill all dependency constraints
- setup_node_modules
- restore_cache:
name: Restore yarn cache of fixture
keys:
- v2-yarn_cache_fixtures_flight-{{ arch }}-{{ checksum "yarn.lock" }}
- run:
name: Install fixture dependencies
working_directory: fixtures/flight
command: |
yarn install --frozen-lockfile --cache-folder ~/.cache/yarn
if [ $? -ne 0 ]; then
yarn install --frozen-lockfile --cache-folder ~/.cache/yarn
fi
- save_cache:
name: Save yarn cache of fixture
key: v2-yarn_cache_fixtures_flight-{{ arch }}-{{ checksum "yarn.lock" }}
paths:
- ~/.cache/yarn
- run:
working_directory: fixtures/flight
name: Playwright install deps
command: |
npx playwright install
sudo npx playwright install-deps
- run:
name: Run tests
working_directory: fixtures/flight
command: yarn test
environment:
# Otherwise the webserver is a blackbox
DEBUG: pw:webserver
- store_artifacts:
path: fixtures/flight/playwright-report
- store_artifacts:
path: fixtures/flight/test-results
run_devtools_tests_for_versions:
docker: *docker
environment: *environment
parallelism: *TEST_PARALLELISM
parameters:
version:
type: string
steps:
- checkout
- attach_workspace:
at: .
- setup_node_modules
- run: ./scripts/circleci/download_devtools_regression_build.js << parameters.version >> --replaceBuild
- run: node ./scripts/jest/jest-cli.js --build --project devtools --release-channel=experimental --reactVersion << parameters.version >> --ci=circleci
run_devtools_e2e_tests_for_versions:
docker: *docker
environment: *environment
parallelism: *TEST_PARALLELISM
parameters:
version:
type: string
steps:
- checkout
- attach_workspace:
at: .
- setup_node_modules
- run:
name: Playwright install deps
command: |
npx playwright install
sudo npx playwright install-deps
- run: ./scripts/circleci/download_devtools_regression_build.js << parameters.version >>
- run:
environment:
RELEASE_CHANNEL: experimental
command: ./scripts/circleci/run_devtools_e2e_tests.js << parameters.version >>
- run:
name: Cleanup build regression folder
command: rm -r ./build-regression
- store_artifacts:
path: ./tmp/screenshots
yarn_lint_build:
docker: *docker
environment: *environment
steps:
- checkout
- attach_workspace:
at: .
- setup_node_modules
- run: yarn lint-build
- run: scripts/circleci/check_minified_errors.sh
test_build:
yarn_check_release_dependencies:
docker: *docker
environment: *environment
steps:
- checkout
- attach_workspace:
at: .
- setup_node_modules
- run: yarn check-release-dependencies
check_error_codes:
docker: *docker
environment: *environment
steps:
- checkout
- attach_workspace: *attach_workspace
- *restore_yarn_cache
- *run_yarn
- setup_node_modules
- run:
environment:
RELEASE_CHANNEL: stable
command: yarn test-build --maxWorkers=2
name: Search build artifacts for unminified errors
command: |
yarn extract-errors
git diff --quiet || (echo "Found unminified errors. Either update the error codes map or disable error minification for the affected build, if appropriate." && false)
test_build_experimental:
yarn_test_build:
docker: *docker
environment: *environment
parallelism: *TEST_PARALLELISM
parameters:
args:
type: string
steps:
- checkout
- attach_workspace:
at: .
- setup_node_modules
- run: yarn test --build <<parameters.args>> --ci=circleci
RELEASE_CHANNEL_stable_yarn_test_dom_fixtures:
docker: *docker
environment: *environment
steps:
- checkout
- attach_workspace: *attach_workspace
- *restore_yarn_cache
- *run_yarn
- run:
environment:
RELEASE_CHANNEL: experimental
command: yarn test-build --maxWorkers=2
test_devtools:
docker: *docker
environment: *environment
steps:
- checkout
- attach_workspace: *attach_workspace
- *restore_yarn_cache
- *run_yarn
- run:
environment:
RELEASE_CHANNEL: experimental
command: yarn test-build-devtools --maxWorkers=2
test_dom_fixtures:
docker: *docker
environment: *environment
steps:
- checkout
- attach_workspace: *attach_workspace
- *restore_yarn_cache
- attach_workspace:
at: .
- setup_node_modules
- *restore_yarn_cache_fixtures_dom
- *yarn_install_fixtures_dom
- *yarn_install_fixtures_dom_retry
- *save_yarn_cache_fixtures_dom
- run:
name: Run DOM fixture tests
environment:
RELEASE_CHANNEL: stable
working_directory: fixtures/dom
command: |
cd fixtures/dom
yarn --frozen-lockfile
yarn prestart
yarn predev
yarn test --maxWorkers=2
test_fuzz:
publish_prerelease:
parameters:
commit_sha:
type: string
release_channel:
type: string
dist_tag:
type: string
docker: *docker
environment: *environment
steps:
- checkout
- *restore_yarn_cache
- *run_yarn
- setup_node_modules
- run:
name: Run fuzz tests
name: Run publish script
command: |
FUZZ_TEST_SEED=$RANDOM yarn test fuzz --maxWorkers=2
FUZZ_TEST_SEED=$RANDOM yarn test-prod fuzz --maxWorkers=2
test_build_prod:
docker: *docker
environment: *environment
steps:
- checkout
- attach_workspace: *attach_workspace
- *restore_yarn_cache
- *run_yarn
- run:
environment:
RELEASE_CHANNEL: stable
command: yarn test-build-prod --maxWorkers=2
test_build_prod_experimental:
docker: *docker
environment: *environment
steps:
- checkout
- attach_workspace: *attach_workspace
- *restore_yarn_cache
- *run_yarn
- run:
environment:
RELEASE_CHANNEL: experimental
command: yarn test-build-prod --maxWorkers=2
git fetch origin main
cd ./scripts/release && yarn && cd ../../
scripts/release/prepare-release-from-ci.js --skipTests -r << parameters.release_channel >> --commit=<< parameters.commit_sha >>
cp ./scripts/release/ci-npmrc ~/.npmrc
scripts/release/publish.js --ci --tags << parameters.dist_tag >>
workflows:
version: 2
stable:
jobs:
- setup
- lint:
requires:
- setup
- flow:
requires:
- setup
- test_source:
requires:
- setup
- test_source_prod:
requires:
- setup
- test_source_persistent:
requires:
- setup
- build:
requires:
- setup
- process_artifacts:
requires:
- build
- sizebot:
requires:
- build
- lint_build:
requires:
- build
- test_build:
requires:
- build
- test_build_prod:
requires:
- build
- test_dom_fixtures:
requires:
- build
experimental:
build_and_test:
unless: << pipeline.parameters.prerelease_commit_sha >>
jobs:
- setup
- test_source_experimental:
- yarn_build:
filters:
branches:
ignore:
- builds/facebook-www
- scrape_warning_messages:
filters:
branches:
ignore:
- builds/facebook-www
- process_artifacts_combined:
requires:
- setup
- build_experimental:
- scrape_warning_messages
- yarn_build
- yarn_test_build:
requires:
- setup
- process_artifacts_experimental:
- yarn_build
matrix:
parameters:
args:
# Intentionally passing these as strings instead of creating a
# separate parameter per CLI argument, since it's easier to
# control/see which combinations we want to run.
- "-r=stable --env=development"
- "-r=stable --env=production"
- "-r=experimental --env=development"
- "-r=experimental --env=production"
# Dev Tools
- "--project=devtools -r=experimental"
# TODO: Update test config to support www build tests
# - "-r=www-classic --env=development --variant=false"
# - "-r=www-classic --env=production --variant=false"
# - "-r=www-classic --env=development --variant=true"
# - "-r=www-classic --env=production --variant=true"
# - "-r=www-modern --env=development --variant=false"
# - "-r=www-modern --env=production --variant=false"
# - "-r=www-modern --env=development --variant=true"
# - "-r=www-modern --env=production --variant=true"
# TODO: Update test config to support xplat build tests
# - "-r=xplat --env=development --variant=false"
# - "-r=xplat --env=development --variant=true"
# - "-r=xplat --env=production --variant=false"
# - "-r=xplat --env=production --variant=true"
# TODO: Test more persistent configurations?
- download_base_build_for_sizebot:
filters:
branches:
ignore:
- main
- builds/facebook-www
- sizebot:
filters:
branches:
ignore:
- main
requires:
- build_experimental
- sizebot_experimental:
- download_base_build_for_sizebot
- yarn_build
- yarn_lint_build:
requires:
- build_experimental
- test_build_experimental:
- yarn_build
- yarn_check_release_dependencies:
requires:
- build_experimental
- test_build_prod_experimental:
- yarn_build
- check_error_codes:
requires:
- build_experimental
- lint_build:
- yarn_build
- RELEASE_CHANNEL_stable_yarn_test_dom_fixtures:
requires:
- build_experimental
- test_devtools:
requires:
- build_experimental
- yarn_build
- build_devtools_and_process_artifacts:
requires:
- build_experimental
- yarn_build
- run_devtools_e2e_tests:
requires:
- build_devtools_and_process_artifacts
- run_fixtures_flight_tests:
requires:
- yarn_build
fuzz_tests:
devtools_regression_tests:
unless: << pipeline.parameters.prerelease_commit_sha >>
triggers:
- schedule:
# Fuzz tests run hourly
cron: "0 * * * *"
# DevTools regression tests run once a day
cron: "0 0 * * *"
filters:
branches:
only:
- master
- main
jobs:
- setup
- test_fuzz:
- download_build:
revision: << pipeline.git.revision >>
- build_devtools_and_process_artifacts:
requires:
- setup
- download_build
- run_devtools_tests_for_versions:
requires:
- build_devtools_and_process_artifacts
matrix:
parameters:
version:
- "16.0"
- "16.5" # schedule package
- "16.8" # hooks
- "17.0"
- "18.0"
- run_devtools_e2e_tests_for_versions:
requires:
- build_devtools_and_process_artifacts
matrix:
parameters:
version:
- "16.0"
- "16.5" # schedule package
- "16.8" # hooks
- "17.0"
- "18.0"
# Used to publish a prerelease manually via the command line
publish_preleases:
when: << pipeline.parameters.prerelease_commit_sha >>
jobs:
- publish_prerelease:
name: Publish to Canary channel
commit_sha: << pipeline.parameters.prerelease_commit_sha >>
release_channel: stable
# The tags to use when publishing canaries. The main one we should
# always include is "canary" but we can use multiple (e.g. alpha,
# beta, rc). To declare multiple, use a comma-separated string, like
# this:
# dist_tag: "canary,alpha,beta,rc"
#
# TODO: We currently tag canaries with "next" in addition to "canary"
# because this used to be called the "next" channel and some
# downstream consumers might still expect that tag. We can remove this
# after some time has elapsed and the change has been communicated.
dist_tag: "canary,next,rc"
- publish_prerelease:
name: Publish to Experimental channel
requires:
# NOTE: Intentionally running these jobs sequentially because npm
# will sometimes fail if you try to concurrently publish two
# different versions of the same package, even if they use different
# dist tags.
- Publish to Canary channel
commit_sha: << pipeline.parameters.prerelease_commit_sha >>
release_channel: experimental
dist_tag: experimental
# Publishes on a cron schedule
publish_preleases_nightly:
unless: << pipeline.parameters.prerelease_commit_sha >>
triggers:
- schedule:
# At 10 minutes past 16:00 on Mon, Tue, Wed, Thu, and Fri
cron: "10 16 * * 1,2,3,4,5"
filters:
branches:
only:
- main
jobs:
- publish_prerelease:
name: Publish to Canary channel
commit_sha: << pipeline.git.revision >>
release_channel: stable
dist_tag: "canary,next,rc"
- publish_prerelease:
name: Publish to Experimental channel
requires:
# NOTE: Intentionally running these jobs sequentially because npm
# will sometimes fail if you try to concurrently publish two
# different versions of the same package, even if they use different
# dist tags.
- Publish to Canary channel
commit_sha: << pipeline.git.revision >>
release_channel: experimental
dist_tag: experimental

View File

@@ -1,10 +1,12 @@
{
"packages": ["packages/react", "packages/react-dom", "packages/scheduler"],
"buildCommand": "build --type=NODE react/index,react-dom/index,scheduler/index,scheduler/tracing",
"buildCommand": "download-build-in-codesandbox-ci",
"node": "18",
"publishDirectory": {
"react": "build/node_modules/react",
"react-dom": "build/node_modules/react-dom",
"scheduler": "build/node_modules/scheduler"
"react": "build/oss-experimental/react",
"react-dom": "build/oss-experimental/react-dom",
"scheduler": "build/oss-experimental/scheduler"
},
"sandboxes": ["new"]
"sandboxes": ["new"],
"silent": true
}

View File

@@ -1,4 +1,4 @@
# http://editorconfig.org
# https://editorconfig.org
root = true
[*]

View File

@@ -13,9 +13,18 @@ scripts/bench/benchmarks/**/*.js
# React repository clone
scripts/bench/remote-repo/
# Compiler uses its own lint setup
compiler/
packages/react-devtools-core/dist
packages/react-devtools-extensions/chrome/build
packages/react-devtools-extensions/firefox/build
packages/react-devtools-extensions/shared/build
packages/react-devtools-extensions/src/ErrorTesterCompiled.js
packages/react-devtools-fusebox/dist
packages/react-devtools-inline/dist
packages/react-devtools-shell/dist
packages/react-devtools-shared/src/hooks/__tests__/__source__/__compiled__/
packages/react-devtools-shared/src/hooks/__tests__/__source__/__untransformed__/
packages/react-devtools-shell/dist
packages/react-devtools-timeline/dist
packages/react-devtools-timeline/static

View File

@@ -5,32 +5,223 @@ const {
esNextPaths,
} = require('./scripts/shared/pathsByLanguageVersion');
const restrictedGlobals = require('confusing-browser-globals');
const OFF = 0;
const WARNING = 1;
const ERROR = 2;
module.exports = {
extends: [
'fbjs',
'prettier'
],
extends: ['prettier', 'plugin:jest/recommended'],
// Stop ESLint from looking for a configuration file in parent folders
root: true,
plugins: ['jest', 'no-for-of-loops', 'react', 'react-internal'],
reportUnusedDisableDirectives: true,
parser: 'babel-eslint',
plugins: [
'babel',
'ft-flow',
'jest',
'no-for-of-loops',
'no-function-declare-after-return',
'react',
'react-internal',
],
parser: 'hermes-eslint',
parserOptions: {
ecmaVersion: 8,
ecmaVersion: 9,
sourceType: 'script',
ecmaFeatures: {
experimentalObjectRestSpread: true,
},
},
// We're stricter than the default config, mostly. We'll override a few rules
// and then enable some React specific ones.
rules: {
'ft-flow/array-style-complex-type': [OFF, 'verbose'],
'ft-flow/array-style-simple-type': [OFF, 'verbose'], // TODO should be WARNING
'ft-flow/boolean-style': ERROR,
'ft-flow/no-dupe-keys': ERROR,
'ft-flow/no-primitive-constructor-types': ERROR,
'ft-flow/no-types-missing-file-annotation': OFF, // TODO should be ERROR
'ft-flow/no-unused-expressions': ERROR,
// 'ft-flow/no-weak-types': WARNING,
// 'ft-flow/require-valid-file-annotation': ERROR,
'no-cond-assign': OFF,
'no-constant-condition': OFF,
'no-control-regex': OFF,
'no-debugger': ERROR,
'no-dupe-args': ERROR,
'no-dupe-keys': ERROR,
'no-duplicate-case': WARNING,
'no-empty-character-class': WARNING,
'no-empty': OFF,
'no-ex-assign': WARNING,
'no-extra-boolean-cast': WARNING,
'no-func-assign': ERROR,
'no-invalid-regexp': WARNING,
'no-irregular-whitespace': WARNING,
'no-negated-in-lhs': ERROR,
'no-obj-calls': ERROR,
'no-regex-spaces': WARNING,
'no-sparse-arrays': ERROR,
'no-unreachable': ERROR,
'use-isnan': ERROR,
'valid-jsdoc': OFF,
'block-scoped-var': OFF,
complexity: OFF,
'default-case': OFF,
'guard-for-in': OFF,
'no-alert': OFF,
'no-caller': ERROR,
'no-case-declarations': OFF,
'no-div-regex': OFF,
'no-else-return': OFF,
'no-empty-pattern': WARNING,
'no-eq-null': OFF,
'no-eval': ERROR,
'no-extend-native': WARNING,
'no-extra-bind': WARNING,
'no-fallthrough': WARNING,
'no-implicit-coercion': OFF,
'no-implied-eval': ERROR,
'no-invalid-this': OFF,
'no-iterator': OFF,
'no-labels': [ERROR, {allowLoop: true, allowSwitch: true}],
'no-lone-blocks': WARNING,
'no-loop-func': OFF,
'no-magic-numbers': OFF,
'no-multi-str': ERROR,
'no-native-reassign': [ERROR, {exceptions: ['Map', 'Set']}],
'no-new-func': ERROR,
'no-new': WARNING,
'no-new-wrappers': WARNING,
'no-octal-escape': WARNING,
'no-octal': WARNING,
'no-param-reassign': OFF,
'no-process-env': OFF,
'no-proto': ERROR,
'no-redeclare': OFF, // TODO should be WARNING?
'no-return-assign': OFF,
'no-script-url': ERROR,
'no-self-compare': WARNING,
'no-sequences': WARNING,
'no-throw-literal': ERROR,
'no-useless-call': WARNING,
'no-void': OFF,
'no-warning-comments': OFF,
'no-with': OFF,
radix: WARNING,
'vars-on-top': OFF,
yoda: OFF,
'init-declarations': OFF,
'no-catch-shadow': ERROR,
'no-delete-var': ERROR,
'no-label-var': WARNING,
'no-shadow-restricted-names': WARNING,
'no-undef-init': OFF,
'no-undef': ERROR,
'no-undefined': OFF,
'callback-return': OFF,
'global-require': OFF,
'handle-callback-err': OFF,
'no-mixed-requires': OFF,
'no-new-require': OFF,
'no-path-concat': OFF,
'no-process-exit': OFF,
'no-restricted-modules': OFF,
'no-sync': OFF,
camelcase: [OFF, {properties: 'always'}],
'consistent-this': [OFF, 'self'],
'func-names': OFF,
'func-style': [OFF, 'declaration'],
'id-length': OFF,
'id-match': OFF,
'max-depth': OFF,
'max-nested-callbacks': OFF,
'max-params': OFF,
'max-statements': OFF,
'new-cap': OFF,
'newline-after-var': OFF,
'no-array-constructor': ERROR,
'no-continue': OFF,
'no-inline-comments': OFF,
'no-lonely-if': OFF,
'no-negated-condition': OFF,
'no-nested-ternary': OFF,
'no-new-object': WARNING,
'no-plusplus': OFF,
'no-ternary': OFF,
'no-underscore-dangle': OFF,
'no-unneeded-ternary': WARNING,
'one-var': [WARNING, {initialized: 'never'}],
'operator-assignment': [WARNING, 'always'],
'require-jsdoc': OFF,
'sort-vars': OFF,
'spaced-comment': [
OFF,
'always',
{exceptions: ['jshint', 'jslint', 'eslint', 'global']},
],
'constructor-super': ERROR,
'no-class-assign': WARNING,
'no-const-assign': ERROR,
'no-dupe-class-members': ERROR,
'no-this-before-super': ERROR,
'object-shorthand': OFF,
'prefer-const': OFF,
'prefer-spread': OFF,
'prefer-reflect': OFF,
'prefer-template': OFF,
'require-yield': OFF,
'babel/generator-star-spacing': OFF,
'babel/new-cap': OFF,
'babel/array-bracket-spacing': OFF,
'babel/object-curly-spacing': OFF,
'babel/object-shorthand': OFF,
'babel/arrow-parens': OFF,
'babel/no-await-in-loop': OFF,
'babel/flow-object-type': OFF,
'react/display-name': OFF,
'react/forbid-prop-types': OFF,
'react/jsx-closing-bracket-location': OFF,
'react/jsx-curly-spacing': OFF,
'react/jsx-equals-spacing': WARNING,
'react/jsx-filename-extension': OFF,
'react/jsx-first-prop-new-line': OFF,
'react/jsx-handler-names': OFF,
'react/jsx-indent': OFF,
'react/jsx-indent-props': OFF,
'react/jsx-key': OFF,
'react/jsx-max-props-per-line': OFF,
'react/jsx-no-bind': OFF,
'react/jsx-no-duplicate-props': ERROR,
'react/jsx-no-literals': OFF,
'react/jsx-no-target-blank': OFF,
'react/jsx-pascal-case': OFF,
'react/jsx-sort-props': OFF,
'react/jsx-uses-vars': ERROR,
'react/no-comment-textnodes': OFF,
'react/no-danger': OFF,
'react/no-deprecated': OFF,
'react/no-did-mount-set-state': OFF,
'react/no-did-update-set-state': OFF,
'react/no-direct-mutation-state': OFF,
'react/no-multi-comp': OFF,
'react/no-render-return-value': OFF,
'react/no-set-state': OFF,
'react/no-string-refs': OFF,
'react/no-unknown-property': OFF,
'react/prefer-es6-class': OFF,
'react/prefer-stateless-function': OFF,
'react/prop-types': OFF,
'react/require-extension': OFF,
'react/require-optimization': OFF,
'react/require-render-return': OFF,
'react/sort-comp': OFF,
'react/sort-prop-types': OFF,
'accessor-pairs': OFF,
'brace-style': [ERROR, '1tbs'],
'consistent-return': OFF,
@@ -43,18 +234,28 @@ module.exports = {
'jsx-quotes': [ERROR, 'prefer-double'],
'keyword-spacing': [ERROR, {after: true, before: true}],
'no-bitwise': OFF,
'no-console': OFF,
'no-inner-declarations': [ERROR, 'functions'],
'no-multi-spaces': ERROR,
'no-restricted-syntax': [ERROR, 'WithStatement'],
'no-restricted-globals': [ERROR].concat(restrictedGlobals),
'no-restricted-syntax': [
ERROR,
'WithStatement',
{
selector: 'MemberExpression[property.name=/^(?:substring|substr)$/]',
message: 'Prefer string.slice() over .substring() and .substr().',
},
],
'no-shadow': ERROR,
'no-unused-expressions': ERROR,
'no-unused-vars': [ERROR, {args: 'none'}],
'no-unused-vars': [ERROR, {args: 'none', ignoreRestSiblings: true}],
'no-use-before-define': OFF,
'no-useless-concat': OFF,
quotes: [ERROR, 'single', {avoidEscape: true, allowTemplateLiterals: true}],
'space-before-blocks': ERROR,
'space-before-function-paren': OFF,
'valid-typeof': [ERROR, {requireStringLiterals: true}],
// Flow fails with non-string literal keys
'no-useless-computed-key': OFF,
// We apply these settings to files that should run on Node.
// They can't use JSX or ES6 modules, and must be in strict mode.
@@ -91,16 +292,59 @@ module.exports = {
// You can disable this rule for code that isn't shipped (e.g. build scripts and tests).
'no-for-of-loops/no-for-of-loops': ERROR,
// Prevent function declarations after return statements
'no-function-declare-after-return/no-function-declare-after-return': ERROR,
// CUSTOM RULES
// the second argument of warning/invariant should be a literal string
'react-internal/no-primitive-constructors': ERROR,
'react-internal/safe-string-coercion': [
ERROR,
{isProductionUserAppCode: true},
],
'react-internal/no-to-warn-dev-within-to-throw': ERROR,
'react-internal/invariant-args': ERROR,
'react-internal/warning-args': ERROR,
'react-internal/no-production-logging': ERROR,
},
overrides: [
{
// By default, anything error message that appears the packages directory
// must have a corresponding error code. The exceptions are defined
// in the next override entry.
files: ['packages/**/*.js'],
rules: {
'react-internal/prod-error-codes': ERROR,
},
},
{
// These are files where it's OK to have unminified error messages. These
// are environments where bundle size isn't a concern, like tests
// or Node.
files: [
'packages/react-dom/src/test-utils/**/*.js',
'packages/react-devtools-shared/**/*.js',
'packages/react-noop-renderer/**/*.js',
'packages/react-refresh/**/*.js',
'packages/react-server-dom-esm/**/*.js',
'packages/react-server-dom-webpack/**/*.js',
'packages/react-server-dom-turbopack/**/*.js',
'packages/react-server-dom-fb/**/*.js',
'packages/react-test-renderer/**/*.js',
'packages/react-debug-tools/**/*.js',
'packages/react-devtools-extensions/**/*.js',
'packages/react-devtools-timeline/**/*.js',
'packages/react-native-renderer/**/*.js',
'packages/eslint-plugin-react-hooks/**/*.js',
'packages/jest-react/**/*.js',
'packages/internal-test-utils/**/*.js',
'packages/**/__tests__/*.js',
'packages/**/npm/*.js',
],
rules: {
'react-internal/prod-error-codes': OFF,
},
},
{
// We apply these settings to files that we ship through npm.
// They must be ES5.
@@ -119,13 +363,14 @@ module.exports = {
// We apply these settings to the source files that get compiled.
// They can use all features including JSX (but shouldn't use `var`).
files: esNextPaths,
parser: 'babel-eslint',
parser: 'hermes-eslint',
parserOptions: {
ecmaVersion: 8,
sourceType: 'module',
},
rules: {
'no-var': ERROR,
'prefer-const': ERROR,
strict: OFF,
},
},
@@ -133,9 +378,49 @@ module.exports = {
files: ['**/__tests__/*.js'],
rules: {
// https://github.com/jest-community/eslint-plugin-jest
'jest/no-focused-tests': ERROR,
'jest/valid-expect': ERROR,
'jest/valid-expect-in-promise': ERROR,
// Meh, who cares.
'jest/consistent-test-it': OFF,
// Meh, we have a lot of these, who cares.
'jest/no-alias-methods': OFF,
// We do conditions based on feature flags.
'jest/no-conditional-expect': OFF,
// We have our own assertion helpers.
'jest/expect-expect': OFF,
// Lame rule that fires in itRender helpers or in render methods.
'jest/no-standalone-expect': OFF,
},
},
{
// Rules specific to test setup helper files.
files: [
'**/setupTests.js',
'**/setupEnv.js',
'**/jest/TestFlags.js',
'**/dom-event-testing-library/testHelpers.js',
'**/utils/ReactDOMServerIntegrationTestUtils.js',
'**/babel/transform-react-version-pragma.js',
'**/babel/transform-test-gate-pragma.js',
],
rules: {
// Some helpers intentionally focus tests.
'jest/no-focused-tests': OFF,
// Test fn helpers don't use static text names.
'jest/valid-title': OFF,
// We have our own assertion helpers.
'jest/expect-expect': OFF,
// Some helpers intentionally disable tests.
'jest/no-disabled-tests': OFF,
// Helpers export text function helpers.
'jest/no-export': OFF,
// The examples in comments trigger false errors.
'jest/no-commented-out-tests': OFF,
},
},
{
files: ['**/jest/TestFlags.js'],
rules: {
// The examples in comments trigger false errors.
'jest/no-commented-out-tests': OFF,
},
},
{
@@ -144,30 +429,171 @@ module.exports = {
'scripts/**/*.js',
'packages/*/npm/**/*.js',
'packages/dom-event-testing-library/**/*.js',
'packages/react-devtools*/**/*.js'
'packages/react-devtools*/**/*.js',
'dangerfile.js',
'fixtures',
'packages/react-dom/src/test-utils/*.js',
],
rules: {
'react-internal/no-production-logging': OFF,
'react-internal/warning-args': OFF,
'react-internal/safe-string-coercion': [
ERROR,
{isProductionUserAppCode: false},
],
},
},
{
files: [
'scripts/eslint-rules/*.js',
'packages/eslint-plugin-react-hooks/src/*.js',
],
plugins: ['eslint-plugin'],
rules: {
'eslint-plugin/prefer-object-rule': ERROR,
'eslint-plugin/require-meta-fixable': [
ERROR,
{catchNoFixerButFixableProperty: true},
],
'eslint-plugin/require-meta-has-suggestions': ERROR,
},
},
{
files: ['packages/react-native-renderer/**/*.js'],
globals: {
nativeFabricUIManager: true,
nativeFabricUIManager: 'readonly',
RN$enableMicrotasksInReact: 'readonly',
},
},
{
files: ['packages/react-server-dom-webpack/**/*.js'],
globals: {
__webpack_chunk_load__: 'readonly',
__webpack_require__: 'readonly',
},
},
{
files: ['packages/react-server-dom-turbopack/**/*.js'],
globals: {
__turbopack_load__: 'readonly',
__turbopack_require__: 'readonly',
},
},
{
files: ['packages/scheduler/**/*.js'],
globals: {
TaskController: 'readonly',
},
},
{
files: [
'packages/react-devtools-extensions/**/*.js',
'packages/react-devtools-shared/src/hook.js',
'packages/react-devtools-shared/src/backend/console.js',
],
globals: {
__IS_CHROME__: 'readonly',
__IS_FIREFOX__: 'readonly',
__IS_EDGE__: 'readonly',
__IS_INTERNAL_VERSION__: 'readonly',
},
},
{
files: ['packages/react-devtools-shared/**/*.js'],
globals: {
__IS_INTERNAL_VERSION__: 'readonly',
},
},
],
globals: {
SharedArrayBuffer: true,
env: {
browser: true,
es6: true,
node: true,
jest: true,
},
spyOnDev: true,
spyOnDevAndProd: true,
spyOnProd: true,
__PROFILE__: true,
__UMD__: true,
__EXPERIMENTAL__: true,
trustedTypes: true,
globals: {
$Call: 'readonly',
$ElementType: 'readonly',
$Flow$ModuleRef: 'readonly',
$FlowFixMe: 'readonly',
$Keys: 'readonly',
$NonMaybeType: 'readonly',
$PropertyType: 'readonly',
$ReadOnly: 'readonly',
$ReadOnlyArray: 'readonly',
$ArrayBufferView: 'readonly',
$Shape: 'readonly',
CallSite: 'readonly',
ConsoleTask: 'readonly', // TOOD: Figure out what the official name of this will be.
ReturnType: 'readonly',
AnimationFrameID: 'readonly',
// For Flow type annotation. Only `BigInt` is valid at runtime.
bigint: 'readonly',
BigInt: 'readonly',
BigInt64Array: 'readonly',
BigUint64Array: 'readonly',
Class: 'readonly',
ClientRect: 'readonly',
CopyInspectedElementPath: 'readonly',
DOMHighResTimeStamp: 'readonly',
EventListener: 'readonly',
Iterable: 'readonly',
AsyncIterable: 'readonly',
$AsyncIterable: 'readonly',
$AsyncIterator: 'readonly',
Iterator: 'readonly',
AsyncIterator: 'readonly',
IteratorResult: 'readonly',
JSONValue: 'readonly',
JSResourceReference: 'readonly',
MouseEventHandler: 'readonly',
PropagationPhases: 'readonly',
PropertyDescriptor: 'readonly',
React$AbstractComponent: 'readonly',
React$Component: 'readonly',
React$ComponentType: 'readonly',
React$Config: 'readonly',
React$Context: 'readonly',
React$Element: 'readonly',
React$ElementConfig: 'readonly',
React$ElementProps: 'readonly',
React$ElementRef: 'readonly',
React$ElementType: 'readonly',
React$Key: 'readonly',
React$Node: 'readonly',
React$Portal: 'readonly',
React$Ref: 'readonly',
ReadableStreamController: 'readonly',
ReadableStreamReader: 'readonly',
RequestInfo: 'readonly',
RequestOptions: 'readonly',
StoreAsGlobal: 'readonly',
symbol: 'readonly',
SyntheticEvent: 'readonly',
SyntheticMouseEvent: 'readonly',
Thenable: 'readonly',
TimeoutID: 'readonly',
WheelEventHandler: 'readonly',
FinalizationRegistry: 'readonly',
Omit: 'readonly',
spyOnDev: 'readonly',
spyOnDevAndProd: 'readonly',
spyOnProd: 'readonly',
__DEV__: 'readonly',
__EXPERIMENTAL__: 'readonly',
__EXTENSION__: 'readonly',
__PROFILE__: 'readonly',
__TEST__: 'readonly',
__VARIANT__: 'readonly',
__unmockReact: 'readonly',
gate: 'readonly',
trustedTypes: 'readonly',
IS_REACT_ACT_ENVIRONMENT: 'readonly',
AsyncLocalStorage: 'readonly',
async_hooks: 'readonly',
globalThis: 'readonly',
},
};

1
.git-blame-ignore-revs Normal file
View File

@@ -0,0 +1 @@
c998bb1ed4b3285398c9c7797135d3f060243c6a

View File

@@ -1,4 +0,0 @@
👉 Please follow one of these issue templates:
- https://github.com/facebook/react/issues/new/choose
Note: to keep the backlog clean and actionable, issues may be immediately closed if they do not follow one of the above issue templates.

18
.github/ISSUE_TEMPLATE/19.md vendored Normal file
View File

@@ -0,0 +1,18 @@
---
name: "⚛React 19 beta issue"
about: Report a issue with React 19 beta.
title: '[React 19]'
labels: 'React 19'
---
## Summary
<!--
Please provide a CodeSandbox (https://codesandbox.io/s/new), a link to a
repository on GitHub, or provide a minimal code example that reproduces the
problem. You may provide a screenshot of the application if you think it is
relevant to your bug report. Here are some tips for providing a minimal
example: https://stackoverflow.com/help/mcve.
-->

View File

@@ -0,0 +1,57 @@
name: "⚛️ ✨ Compiler bug report"
description: "Report a problem with React Compiler. Please provide enough information that we can reproduce the problem."
title: "[Compiler Bug]: "
labels: ["Component: Optimizing Compiler", "Type: Bug", "Status: Unconfirmed"]
body:
- type: checkboxes
attributes:
label: What kind of issue is this?
description: |
Please indicate if this issue affects the following tools provided by React Compiler.
options:
- label: React Compiler core (the JS output is incorrect, or your app works incorrectly after optimization)
- label: babel-plugin-react-compiler (build issue installing or using the Babel plugin)
- label: eslint-plugin-react-compiler (build issue installing or using the eslint plugin)
- label: react-compiler-healthcheck (build issue installing or using the healthcheck script)
- type: input
attributes:
label: Link to repro
description: |
Please provide a repro by either sharing a [Playground link](https://playground.react.dev), or a public GitHub repo so the React team can reproduce the error being reported. Please do not share localhost links!
placeholder: |
e.g. public GitHub repo, or Playground link
validations:
required: true
- type: textarea
attributes:
label: Repro steps
description: |
What were you doing when the bug happened? Detailed information helps maintainers reproduce and fix bugs.
Issues filed without repro steps will be closed.
placeholder: |
Example bug report:
1. Log in with username/password
2. Click "Messages" on the left menu
3. Open any message in the list
validations:
required: true
- type: dropdown
attributes:
label: How often does this bug happen?
description: |
Following the repro steps above, how easily are you able to reproduce this bug?
options:
- Every time
- Often
- Sometimes
- Only once
validations:
required: true
- type: input
attributes:
label: What version of React are you using?
description: |
Please provide your React version in the app where this issue occurred.
validations:
required: true

8
.github/ISSUE_TEMPLATE/config.yml vendored Normal file
View File

@@ -0,0 +1,8 @@
blank_issues_enabled: false
contact_links:
- name: 📃 Documentation Issue
url: https://github.com/reactjs/react.dev/issues/new/choose
about: This issue tracker is not for documentation issues. Please file documentation issues here.
- name: 🤔 Questions and Help
url: https://reactjs.org/community/support.html
about: This issue tracker is not for support questions. Please refer to the React community's help and discussion forums.

View File

@@ -0,0 +1,81 @@
name: "⚛️ 🛠 DevTools bug report"
description: "Report a problem with React DevTools. Please provide enough information that we can reproduce the problem."
title: "[DevTools Bug]: "
labels: ["Component: Developer Tools", "Type: Bug", "Status: Unconfirmed"]
body:
- type: input
attributes:
label: Website or app
description: |
Which website or app were you using when the bug happened?
This should be a public URL, GitHub repo, or Code Sandbox app so the React team can reproduce the error being reported. (Please no localhost URLs.)
placeholder: |
e.g. website URL, public GitHub repo, or Code Sandbox app
validations:
required: true
- type: textarea
attributes:
label: Repro steps
description: |
What were you doing on the website or app when the bug happened? Detailed information helps maintainers reproduce and fix bugs.
Issues filed without repro steps will be closed.
placeholder: |
Example bug report:
1. Log in with username/password
2. Click "Messages" on the left menu
3. Open any message in the list
validations:
required: true
- type: dropdown
attributes:
label: How often does this bug happen?
description: |
Following the repro steps above, how easily are you able to reproduce this bug?
options:
- Every time
- Often
- Sometimes
- Only once
validations:
required: true
- type: input
id: automated_package
attributes:
label: DevTools package (automated)
description: |
Please do not edit this field.
- type: input
id: automated_version
attributes:
label: DevTools version (automated)
description: |
Please do not edit this field.
- type: input
id: automated_error_message
attributes:
label: Error message (automated)
description: |
Please do not edit this field.
- type: textarea
id: automated_call_stack
attributes:
label: Error call stack (automated)
description: |
Please do not edit this field.
render: text
- type: textarea
id: automated_component_stack
attributes:
label: Error component stack (automated)
description: |
Please do not edit this field.
render: text
- type: textarea
id: automated_github_query_string
attributes:
label: GitHub query string (automated)
description: |
Please do not edit this field.
render: text

View File

@@ -1,13 +0,0 @@
---
name: "📃 Documentation Issue"
about: This issue tracker is not for documentation issues. Please file documentation issues at https://github.com/reactjs/reactjs.org.
title: 'Docs: '
labels: 'Resolution: Invalid'
---
🚨 This issue tracker is not for documentation issues. 🚨
The React website is hosted on a separate repository. You may let the
team know about any issues with the documentation by opening an issue there:
- https://github.com/reactjs/reactjs.org/issues/new

View File

@@ -1,29 +0,0 @@
---
name: "🤔 Questions and Help"
about: This issue tracker is not for questions. Please ask questions at https://stackoverflow.com/questions/tagged/react.
title: 'Question: '
labels: 'Resolution: Invalid, Type: Question'
---
🚨 This issue tracker is not for questions. 🚨
As it happens, support requests that are created as issues are likely to be closed. We want to make sure you are able to find the help you seek. Please take a look at the following resources.
## Coding Questions
If you have a coding question related to React and React DOM, it might be better suited for Stack Overflow. It's a great place to browse through frequent questions about using React, as well as ask for help with specific questions.
https://stackoverflow.com/questions/tagged/react
## Talk to other React developers
There are many online forums which are a great place for discussion about best practices and application architecture as well as the future of React.
https://reactjs.org/community/support.html#popular-discussion-forums
## Proposals
If you'd like to discuss topics related to the future of React, or would like to propose a new feature or change before sending a pull request, please check out the discussions and proposals repository.
https://github.com/reactjs/rfcs

View File

@@ -4,15 +4,15 @@
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 `master`.
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".
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/) typechecks (`yarn flow`).
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
@@ -20,8 +20,14 @@
## Summary
<!-- Explain the **motivation** for making this change. What existing problem does the pull request solve? -->
<!--
Explain the **motivation** for making this change. What existing problem does the pull request solve?
-->
## Test Plan
## 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. -->
<!--
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.
-->

107
.github/dependabot.yml vendored Normal file
View File

@@ -0,0 +1,107 @@
version: 2
updates:
- package-ecosystem: "npm"
directory: "/fixtures/art"
schedule:
interval: "weekly"
open-pull-requests-limit: 0
- package-ecosystem: "npm"
directory: "/fixtures/attribute-behavior"
schedule:
interval: "weekly"
open-pull-requests-limit: 0
- package-ecosystem: "npm"
directory: "/fixtures/concurrent"
schedule:
interval: "weekly"
open-pull-requests-limit: 0
- package-ecosystem: "npm"
directory: "/fixtures/devtools"
schedule:
interval: "weekly"
open-pull-requests-limit: 0
- package-ecosystem: "npm"
directory: "/fixtures/dom"
schedule:
interval: "weekly"
open-pull-requests-limit: 0
- package-ecosystem: "npm"
directory: "/fixtures/eslint"
schedule:
interval: "weekly"
open-pull-requests-limit: 0
- package-ecosystem: "npm"
directory: "/fixtures/expiration"
schedule:
interval: "weekly"
open-pull-requests-limit: 0
- package-ecosystem: "npm"
directory: "/fixtures/fiber-debugger"
schedule:
interval: "weekly"
open-pull-requests-limit: 0
- package-ecosystem: "npm"
directory: "/fixtures/fiber-triangle"
schedule:
interval: "weekly"
open-pull-requests-limit: 0
- package-ecosystem: "npm"
directory: "/fixtures/fizz"
schedule:
interval: "weekly"
open-pull-requests-limit: 0
- package-ecosystem: "npm"
directory: "/fixtures/fizz-ssr-browser"
schedule:
interval: "weekly"
open-pull-requests-limit: 0
- package-ecosystem: "npm"
directory: "/fixtures/flight"
schedule:
interval: "weekly"
open-pull-requests-limit: 0
- package-ecosystem: "npm"
directory: "/fixtures/flight-browser"
schedule:
interval: "weekly"
open-pull-requests-limit: 0
- package-ecosystem: "npm"
directory: "/fixtures/flight-esm"
schedule:
interval: "weekly"
open-pull-requests-limit: 0
- package-ecosystem: "npm"
directory: "/fixtures/legacy-jsx-runtimes"
schedule:
interval: "weekly"
open-pull-requests-limit: 0
- package-ecosystem: "npm"
directory: "/fixtures/nesting"
schedule:
interval: "weekly"
open-pull-requests-limit: 0
- package-ecosystem: "npm"
directory: "/fixtures/packaging"
schedule:
interval: "weekly"
open-pull-requests-limit: 0
- package-ecosystem: "npm"
directory: "/fixtures/scheduler"
schedule:
interval: "weekly"
open-pull-requests-limit: 0
- package-ecosystem: "npm"
directory: "/fixtures/ssr"
schedule:
interval: "weekly"
open-pull-requests-limit: 0
- package-ecosystem: "npm"
directory: "/fixtures/ssr-2"
schedule:
interval: "weekly"
open-pull-requests-limit: 0
- package-ecosystem: "npm"
directory: "/fixtures/stacks"
schedule:
interval: "weekly"
open-pull-requests-limit: 0

31
.github/stale.yml vendored
View File

@@ -1,31 +0,0 @@
# Configuration for probot-stale - https://github.com/probot/stale
# Number of days of inactivity before an issue becomes stale
daysUntilStale: 90
# Number of days of inactivity before a stale issue is closed
daysUntilClose: 7
# Issues with these labels will never be considered stale
exemptLabels:
- "Partner"
- "React Core Team"
- "Resolution: Backlog"
- "Type: Bug"
- "Type: Discussion"
- "Type: Regression"
# Label to use when marking an issue as stale
staleLabel: "Resolution: Stale"
issues:
# Comment to post when marking an issue as stale.
markComment: >
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
Thank you for your contribution.
# Comment to post when closing a stale issue.
closeComment: >
Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please create a new issue with up-to-date information. Thank you!
pulls:
# Comment to post when marking a pull request as stale.
markComment: >
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
Thank you for your contribution.
# Comment to post when closing a stale pull request.
closeComment: >
Closing this pull request after a prolonged period of inactivity. If this issue is still present in the latest release, please ask for this pull request to be reopened. Thank you!

View File

@@ -0,0 +1,34 @@
name: (Compiler) Playground
on:
push:
branches: [main]
pull_request:
paths:
- "compiler/**"
- .github/workflows/compiler-playground.yml
defaults:
run:
working-directory: compiler
jobs:
playground:
name: Test playground
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 18.x
cache: "yarn"
cache-dependency-path: compiler/yarn.lock
- name: Restore cached node_modules
uses: actions/cache@v4
id: node_modules
with:
path: "**/node_modules"
key: ${{ runner.arch }}-${{ runner.os }}-modules-${{ hashFiles('compiler/**/yarn.lock') }}
- run: yarn install --frozen-lockfile
- run: npx playwright install --with-deps chromium
- run: yarn workspace playground test

72
.github/workflows/compiler_rust.yml vendored Normal file
View File

@@ -0,0 +1,72 @@
name: (Compiler) Rust
on:
push:
branches: ["main"]
paths:
- .github/workflows/**
- compiler/crates/**
- compiler/Cargo.*
- compiler/*.toml
pull_request:
paths:
- .github/workflows/**
- compiler/crates/**
- compiler/Cargo.*
- compiler/*.toml
env:
CARGO_TERM_COLOR: always
RUSTFLAGS: -Dwarnings
defaults:
run:
working-directory: compiler
jobs:
test:
name: Rust Test (${{ matrix.target.os }})
strategy:
matrix:
target:
- target: ubuntu-latest
os: ubuntu-latest
# TODO: run on more platforms
# - target: macos-latest
# os: macos-latest
# - target: windows-latest
# os: windows-latest
runs-on: ${{ matrix.target.os }}
steps:
- uses: actions/checkout@v4
- uses: Swatinem/rust-cache@v2
- name: cargo test
run: cargo test --manifest-path=Cargo.toml --locked ${{ matrix.target.features && '--features' }} ${{ matrix.target.features }}
lint:
name: Rust Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions-rs/toolchain@v1
with:
# NOTE: use `rustup run <toolchain> <command>` in commands below
# with this exact same toolchain value
toolchain: nightly-2023-08-01
override: true
components: rustfmt, clippy
- uses: Swatinem/rust-cache@v2
- name: rustfmt
run: grep -r --include "*.rs" --files-without-match "@generated" crates | xargs rustup run nightly-2023-08-01 rustfmt --check --config="skip_children=true"
# - name: cargo clippy
# run: rustup run nightly-2023-08-01 cargo clippy -- -Dclippy::correctness
build:
name: Rust Build
runs-on: ubuntu-latest
# TODO: build on more platforms, deploy, etc
steps:
- uses: actions/checkout@v4
- uses: Swatinem/rust-cache@v2
- name: cargo build
run: cargo build --release

View File

@@ -0,0 +1,87 @@
name: (Compiler) TypeScript
on:
push:
branches: [main]
pull_request:
paths:
- "compiler/**"
- .github/workflows/compiler-typescript.yml
defaults:
run:
working-directory: compiler
jobs:
discover_yarn_workspaces:
name: Discover yarn workspaces
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- uses: actions/checkout@v4
- id: set-matrix
run: echo "matrix=$(find packages -mindepth 1 -maxdepth 1 -type d | sed 's!packages/!!g' | tr '\n' ',' | sed s/.$// | jq -Rsc '. / "," - [""]')" >> $GITHUB_OUTPUT
# Hardcoded to improve parallelism
lint:
name: Lint babel-plugin-react-compiler
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 18.x
cache: "yarn"
cache-dependency-path: compiler/yarn.lock
- name: Restore cached node_modules
uses: actions/cache@v4
with:
path: "**/node_modules"
key: ${{ runner.arch }}-${{ runner.os }}-modules-${{ hashFiles('compiler/**/yarn.lock') }}
- run: yarn install --frozen-lockfile
- run: yarn workspace babel-plugin-react-compiler lint
# Hardcoded to improve parallelism
jest:
name: Jest babel-plugin-react-compiler
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 18.x
cache: "yarn"
cache-dependency-path: compiler/yarn.lock
- name: Restore cached node_modules
uses: actions/cache@v4
id: node_modules
with:
path: "**/node_modules"
key: ${{ runner.arch }}-${{ runner.os }}-modules-${{ hashFiles('compiler/**/yarn.lock') }}
- run: yarn install --frozen-lockfile
- run: yarn workspace babel-plugin-react-compiler jest
test:
name: Test ${{ matrix.workspace_name }}
needs: discover_yarn_workspaces
runs-on: ubuntu-latest
continue-on-error: true
strategy:
matrix:
workspace_name: ${{ fromJSON(needs.discover_yarn_workspaces.outputs.matrix) }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 18.x
cache: "yarn"
cache-dependency-path: compiler/yarn.lock
- name: Restore cached node_modules
uses: actions/cache@v4
id: node_modules
with:
path: "**/node_modules"
key: ${{ runner.arch }}-${{ runner.os }}-modules-${{ hashFiles('compiler/**/yarn.lock') }}
- run: yarn install --frozen-lockfile
- run: yarn workspace ${{ matrix.workspace_name }} test

View File

@@ -0,0 +1,205 @@
name: (DevTools) Check for bug repro
on:
issues:
types: [opened, edited]
issue_comment:
types: [created, edited]
jobs:
check-repro:
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v3
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const URL_REGEXP = /### Website or app[\r\n]+([^#]+)###/m;
const REPRO_STEPS_REGEXP = /### Repro steps[\r\n]+([^#]+)###/m;
const LABEL_NEEDS_MORE_INFORMATION = "Resolution: Needs More Information";
const LABEL_UNCONFIRMED = "Status: Unconfirmed";
function debug(...args) {
core.info(args.map(JSON.stringify).join(' '));
}
if (context.payload.comment) {
debug('Ignoring comment update.');
return;
}
const user = context.payload.sender.login;
const issue = context.payload.issue;
const body = issue.body;
const urlMatch = body.match(URL_REGEXP);
const reproStepsMatch = body.match(REPRO_STEPS_REGEXP);
const url = urlMatch !== null ? urlMatch[1].trim() : null;
const reproSteps = reproStepsMatch !== null ? reproStepsMatch[1].trim() : null;
if (!url || !reproSteps) {
debug('This issue is not a DevTools bug report.');
return;
}
debug(`found URL "${url}"`);
debug(`found repro steps "${reproSteps}"`);
async function createComment(comment) {
// Format
comment = comment
.split("\n")
.map((line) => line.trim())
.join("\n")
.trim();
await github.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: comment,
});
}
async function getGitHubActionComments() {
debug(`Loading existing comments...`);
const comments = await github.issues.listComments({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
});
return comments.data.filter(comment => {
debug(`comment by user: "${comment.user.login}"`);
return comment.user.login === 'github-actions[bot]';
});
}
async function getIssueLabels() {
const issues = await github.issues.listLabelsOnIssue({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
});
return issues.data;
}
async function updateIssue(state, assignees = []) {
await github.issues.update({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
state,
assignees,
});
}
async function closeWithComment(comment) {
if (issue.state !== 'open') {
debug(`Issue is not open`);
return;
}
const labels = await getIssueLabels();
const label = labels.find(label => label.name === LABEL_UNCONFIRMED);
if (!label) {
debug(`Issue was not opened via DevTools bug report template`);
return;
}
const comments = await getGitHubActionComments();
if (comments.length > 0) {
debug(`Already commented on issue; won't comment again`);
return;
}
debug(`Missing required information`);
await github.issues.addLabels({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: [LABEL_NEEDS_MORE_INFORMATION],
});
await createComment(comment);
await updateIssue('closed', [user]);
}
async function openWithComment(comment) {
if (issue.state !== 'closed') {
debug(`Issue is already open`);
return;
}
const labels = await getIssueLabels();
const label = labels.find(label => label.name === LABEL_NEEDS_MORE_INFORMATION);
if (!label) {
debug(`Issue was not tagged as needs information`);
return;
}
const comments = await getGitHubActionComments();
if (comments.length === 0) {
debug(`Issue was closed by someone else; won't reopen`);
return;
}
debug(`Re-opening closed issue`);
await github.issues.removeLabel({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
name: LABEL_NEEDS_MORE_INFORMATION,
});
await createComment(comment);
await updateIssue('open');
}
const PROBABLY_NOT_A_URL_REGEX = /(^Chrome$|^Firefox$| Website)/i;
const COMMENT_HEADER = `
@${user}: We're sorry you've seen this error. ❤️
`.trim();
const COMMENT_FOOTER = `
Please help us by providing a link to a CodeSandbox (https://codesandbox.io/s/new), a repository on GitHub, or a minimal code example that reproduces the problem. (Screenshots or videos can also be helpful if they help provide context on how to repro the bug.)
Here are some tips for providing a minimal example: https://stackoverflow.com/help/mcve
Issues without repros are automatically closed but we will re-open if you update with repro info.
`.trim();
if (url.includes("localhost")) {
closeWithComment(`
${COMMENT_HEADER}
Unfortunately the URL you provided ("localhost") is not publicly accessible. (This means that we will not be able to reproduce the problem you're reporting.)
${COMMENT_FOOTER}
`);
} else if (url.length < 10 || url.match(PROBABLY_NOT_A_URL_REGEX)) {
closeWithComment(`
${COMMENT_HEADER}
It looks like you forgot to specify a valid URL. (This means that we will not be able to reproduce the problem you're reporting.)
${COMMENT_FOOTER}
`);
} else if (reproSteps.length < 25) {
closeWithComment(`
${COMMENT_HEADER}
Unfortunately, it doesn't look like this issue has enough info for one of us to reproduce and fix it though.
${COMMENT_FOOTER}
`);
} else {
openWithComment(`
Thank you for providing repro steps! Re-opening issue now for triage.
`);
}

View File

@@ -0,0 +1,462 @@
name: (Runtime) Commit Artifacts for Meta WWW and fbsource
on:
push:
branches: [main, meta-www, meta-fbsource]
jobs:
download_artifacts:
runs-on: ubuntu-latest
outputs:
www_branch_count: ${{ steps.check_branches.outputs.www_branch_count }}
fbsource_branch_count: ${{ steps.check_branches.outputs.fbsource_branch_count }}
last_version_classic: ${{ steps.get_last_version_www.outputs.last_version_classic }}
last_version_modern: ${{ steps.get_last_version_www.outputs.last_version_modern }}
last_version_rn: ${{ steps.get_last_version_rn.outputs.last_version_rn }}
current_version_classic: ${{ steps.get_current_version.outputs.current_version_classic }}
current_version_modern: ${{ steps.get_current_version.outputs.current_version_modern }}
current_version_rn: ${{ steps.get_current_version.outputs.current_version_rn }}
steps:
- uses: actions/checkout@v4
with:
ref: builds/facebook-www
- name: "Get last version string for www"
id: get_last_version_www
run: |
# Empty checks only needed for backwards compatibility,can remove later.
VERSION_CLASSIC=$( [ -f ./compiled/facebook-www/VERSION_CLASSIC ] && cat ./compiled/facebook-www/VERSION_CLASSIC || echo '' )
VERSION_MODERN=$( [ -f ./compiled/facebook-www/VERSION_MODERN ] && cat ./compiled/facebook-www/VERSION_MODERN || echo '' )
echo "Last classic version is $VERSION_CLASSIC"
echo "Last modern version is $VERSION_MODERN"
echo "last_version_classic=$VERSION_CLASSIC" >> "$GITHUB_OUTPUT"
echo "last_version_modern=$VERSION_MODERN" >> "$GITHUB_OUTPUT"
- uses: actions/checkout@v4
with:
ref: builds/facebook-fbsource
- name: "Get last version string for rn"
id: get_last_version_rn
run: |
# Empty checks only needed for backwards compatibility,can remove later.
VERSION_NATIVE_FB=$( [ -f ./compiled-rn/VERSION_NATIVE_FB ] && cat ./compiled-rn/VERSION_NATIVE_FB || echo '' )
echo "Last rn version is $VERSION_NATIVE_FB"
echo "last_version_rn=$VERSION_NATIVE_FB" >> "$GITHUB_OUTPUT"
- uses: actions/checkout@v4
- name: "Check branches"
id: check_branches
run: |
echo "www_branch_count=$(git ls-remote --heads origin "refs/heads/meta-www" | wc -l)" >> "$GITHUB_OUTPUT"
echo "fbsource_branch_count=$(git ls-remote --heads origin "refs/heads/meta-fbsource" | wc -l)" >> "$GITHUB_OUTPUT"
- name: Download and unzip artifacts
uses: actions/github-script@v6
env:
CIRCLECI_TOKEN: ${{secrets.CIRCLECI_TOKEN_DIFFTRAIN}}
with:
script: |
// TODO: Move this to a script file.
const cp = require('child_process');
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
function execHelper(command, options, streamStdout = false) {
return new Promise((resolve, reject) => {
const proc = cp.exec(
command,
options,
(error, stdout) => (error ? reject(error) : resolve(stdout.trim())),
);
if (streamStdout) {
proc.stdout.pipe(process.stdout);
}
});
}
let artifactsUrl = null;
// This is a temporary, dirty hack to avoid needing a GitHub auth token in the circleci
// workflow to notify this GitHub action. Sorry!
let iter = 0;
spinloop: while (iter < 15) {
const res = await github.rest.repos.listCommitStatusesForRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: context.sha
});
for (const status of res.data) {
if (/process_artifacts_combined/.test(status.context)) {
switch (status.state) {
case 'pending': {
console.log(`${status.context} is still pending`);
break;
}
case 'failure':
case 'error': {
throw new Error(`${status.context} has failed or errored`);
}
case 'success': {
// The status does not include a build ID, but we can extract it
// from the URL. I couldn't find a better way to do this.
const ciBuildId = /\/facebook\/react\/([0-9]+)/.exec(
status.target_url,
)[1];
if (Number.parseInt(ciBuildId, 10) + '' === ciBuildId) {
artifactsUrl =
`https://circleci.com/api/v1.1/project/github/facebook/react/${ciBuildId}/artifacts`;
console.log(`Found artifactsUrl: ${artifactsUrl}`);
break spinloop;
} else {
throw new Error(`${ciBuildId} isn't a number`);
}
break;
}
default: {
throw new Error(`Unhandled status state: ${status.state}`);
break;
}
}
}
}
iter++;
console.log("Sleeping for 60s...");
await sleep(60_000);
}
if (artifactsUrl != null) {
const {CIRCLECI_TOKEN} = process.env;
const res = await fetch(artifactsUrl, {
headers: {
'Circle-Token': CIRCLECI_TOKEN
}
});
const data = await res.json();
if (!Array.isArray(data) && data.message != null) {
throw `CircleCI returned: ${data.message}`;
}
for (const artifact of data) {
if (artifact.path === 'build.tgz') {
console.log(`Downloading and unzipping ${artifact.url}`);
await execHelper(
`curl -L ${artifact.url} -H "Circle-Token: ${CIRCLECI_TOKEN}" | tar -xvz`
);
}
}
} else {
process.exitCode = 1;
}
- name: Strip @license from eslint plugin and react-refresh
run: |
sed -i -e 's/ @license React*//' \
build/oss-experimental/eslint-plugin-react-hooks/cjs/eslint-plugin-react-hooks.development.js \
build/oss-experimental/react-refresh/cjs/react-refresh-babel.development.js
- name: Move relevant files for React in www into compiled
run: |
# Move the facebook-www folder into compiled
mkdir ./compiled
mv build/facebook-www ./compiled
# Move ReactAllWarnings.js to facebook-www
mkdir ./compiled/facebook-www/__test_utils__
mv build/__test_utils__/ReactAllWarnings.js ./compiled/facebook-www/__test_utils__/ReactAllWarnings.js
# Move eslint-plugin-react-hooks into facebook-www
mv build/oss-experimental/eslint-plugin-react-hooks/cjs/eslint-plugin-react-hooks.development.js \
./compiled/facebook-www/eslint-plugin-react-hooks.js
# Move unstable_server-external-runtime.js into facebook-www
mv build/oss-experimental/react-dom/unstable_server-external-runtime.js \
./compiled/facebook-www/unstable_server-external-runtime.js
# Move react-refresh-babel.development.js into babel-plugin-react-refresh
mkdir ./compiled/babel-plugin-react-refresh
mv build/oss-experimental/react-refresh/cjs/react-refresh-babel.development.js \
./compiled/babel-plugin-react-refresh/index.js
ls -R ./compiled
- name: Move relevant files for React in fbsource into compiled-rn
run: |
BASE_FOLDER='compiled-rn/facebook-fbsource/xplat/js'
mkdir -p ${BASE_FOLDER}/react-native-github/Libraries/Renderer/
mkdir -p ${BASE_FOLDER}/RKJSModules/vendor/react/{scheduler,react,react-is,react-test-renderer}/
# Move React Native renderer
mv build/react-native/implementations/ $BASE_FOLDER/react-native-github/Libraries/Renderer/
mv build/react-native/shims/ $BASE_FOLDER/react-native-github/Libraries/Renderer/
mv build/facebook-react-native/scheduler/cjs/ $BASE_FOLDER/RKJSModules/vendor/react/scheduler/
mv build/facebook-react-native/react/cjs/ $BASE_FOLDER/RKJSModules/vendor/react/react/
mv build/facebook-react-native/react-is/cjs/ $BASE_FOLDER/RKJSModules/vendor/react/react-is/
mv build/facebook-react-native/react-test-renderer/cjs/ $BASE_FOLDER/RKJSModules/vendor/react/react-test-renderer/
# Delete OSS renderer. OSS renderer is synced through internal script.
RENDERER_FOLDER=$BASE_FOLDER/react-native-github/Libraries/Renderer/implementations/
rm $RENDERER_FOLDER/ReactFabric-{dev,prod,profiling}.js
rm $RENDERER_FOLDER/ReactNativeRenderer-{dev,prod,profiling}.js
# Move React Native version file
mv build/facebook-react-native/VERSION_NATIVE_FB ./compiled-rn/VERSION_NATIVE_FB
ls -R ./compiled-rn
- name: Add REVISION files
run: |
echo ${{ github.sha }} >> ./compiled/facebook-www/REVISION
cp ./compiled/facebook-www/REVISION ./compiled/facebook-www/REVISION_TRANSFORMS
echo ${{ github.sha }} >> ./compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/REVISION
- name: "Get current version string"
id: get_current_version
run: |
VERSION_CLASSIC=$(cat ./compiled/facebook-www/VERSION_CLASSIC)
VERSION_MODERN=$(cat ./compiled/facebook-www/VERSION_MODERN)
VERSION_NATIVE_FB=$(cat ./compiled-rn/VERSION_NATIVE_FB)
echo "Current classic version is $VERSION_CLASSIC"
echo "Current modern version is $VERSION_MODERN"
echo "Current rn version is $VERSION_NATIVE_FB"
echo "current_version_classic=$VERSION_CLASSIC" >> "$GITHUB_OUTPUT"
echo "current_version_modern=$VERSION_MODERN" >> "$GITHUB_OUTPUT"
echo "current_version_rn=$VERSION_NATIVE_FB" >> "$GITHUB_OUTPUT"
- uses: actions/upload-artifact@v3
with:
name: compiled
path: compiled/
- uses: actions/upload-artifact@v3
with:
name: compiled-rn
path: compiled-rn/
commit_www_artifacts:
needs: download_artifacts
if: ${{ (github.ref == 'refs/heads/main' && needs.download_artifacts.outputs.www_branch_count == '0') || github.ref == 'refs/heads/meta-www' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: builds/facebook-www
- name: Ensure clean directory
run: rm -rf compiled
- uses: actions/download-artifact@v3
with:
name: compiled
path: compiled/
- name: Revert version changes
if: needs.download_artifacts.outputs.last_version_classic != '' && needs.download_artifacts.outputs.last_version_modern != ''
env:
CURRENT_VERSION_CLASSIC: ${{ needs.download_artifacts.outputs.current_version_classic }}
CURRENT_VERSION_MODERN: ${{ needs.download_artifacts.outputs.current_version_modern }}
LAST_VERSION_CLASSIC: ${{ needs.download_artifacts.outputs.last_version_classic }}
LAST_VERSION_MODERN: ${{ needs.download_artifacts.outputs.last_version_modern }}
run: |
echo "Reverting $CURRENT_VERSION_CLASSIC to $LAST_VERSION_CLASSIC"
grep -rl "$CURRENT_VERSION_CLASSIC" ./compiled || echo "No files found with $CURRENT_VERSION_CLASSIC"
grep -rl "$CURRENT_VERSION_CLASSIC" ./compiled | xargs -r sed -i -e "s/$CURRENT_VERSION_CLASSIC/$LAST_VERSION_CLASSIC/g"
grep -rl "$CURRENT_VERSION_CLASSIC" ./compiled || echo "Classic version reverted"
echo "===================="
echo "Reverting $CURRENT_VERSION_MODERN to $LAST_VERSION_MODERN"
grep -rl "$CURRENT_VERSION_MODERN" ./compiled || echo "No files found with $CURRENT_VERSION_MODERN"
grep -rl "$CURRENT_VERSION_MODERN" ./compiled | xargs -r sed -i -e "s/$CURRENT_VERSION_MODERN/$LAST_VERSION_MODERN/g"
grep -rl "$CURRENT_VERSION_MODERN" ./compiled || echo "Modern version reverted"
- name: Check for changes
id: check_should_commit
run: |
echo "Full git status"
git add .
git status
echo "===================="
if git status --porcelain | grep -qv '/REVISION'; then
echo "Changes detected"
echo "===== Changes ====="
git --no-pager diff -U0 | grep '^[+-]' | head -n 50
echo "==================="
echo "should_commit=true" >> "$GITHUB_OUTPUT"
else
echo "No Changes detected"
echo "should_commit=false" >> "$GITHUB_OUTPUT"
fi
- name: Re-apply version changes
if: steps.check_should_commit.outputs.should_commit == 'true' && needs.download_artifacts.outputs.last_version_classic != '' && needs.download_artifacts.outputs.last_version_modern != ''
env:
CURRENT_VERSION_CLASSIC: ${{ needs.download_artifacts.outputs.current_version_classic }}
CURRENT_VERSION_MODERN: ${{ needs.download_artifacts.outputs.current_version_modern }}
LAST_VERSION_CLASSIC: ${{ needs.download_artifacts.outputs.last_version_classic }}
LAST_VERSION_MODERN: ${{ needs.download_artifacts.outputs.last_version_modern }}
run: |
echo "Re-applying $LAST_VERSION_CLASSIC to $CURRENT_VERSION_CLASSIC"
grep -rl "$LAST_VERSION_CLASSIC" ./compiled || echo "No files found with $LAST_VERSION_CLASSIC"
grep -rl "$LAST_VERSION_CLASSIC" ./compiled | xargs -r sed -i -e "s/$LAST_VERSION_CLASSIC/$CURRENT_VERSION_CLASSIC/g"
grep -rl "$LAST_VERSION_CLASSIC" ./compiled || echo "Classic version re-applied"
echo "===================="
echo "Re-applying $LAST_VERSION_MODERN to $CURRENT_VERSION_MODERN"
grep -rl "$LAST_VERSION_MODERN" ./compiled || echo "No files found with $LAST_VERSION_MODERN"
grep -rl "$LAST_VERSION_MODERN" ./compiled | xargs -r sed -i -e "s/$LAST_VERSION_MODERN/$CURRENT_VERSION_MODERN/g"
grep -rl "$LAST_VERSION_MODERN" ./compiled || echo "Classic version re-applied"
- name: Will commit these changes
if: steps.check_should_commit.outputs.should_commit == 'true'
run: |
echo ":"
git status -u
- name: Commit changes to branch
if: steps.check_should_commit.outputs.should_commit == 'true'
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: |
${{ github.event.head_commit.message }}
DiffTrain build for [${{ github.sha }}](https://github.com/facebook/react/commit/${{ github.sha }})
branch: builds/facebook-www
commit_user_name: ${{ github.actor }}
commit_user_email: ${{ github.actor }}@users.noreply.github.com
create_branch: true
commit_fbsource_artifacts:
needs: download_artifacts
if: ${{ (github.ref == 'refs/heads/main' && needs.download_artifacts.outputs.fbsource_branch_count == '0') || github.ref == 'refs/heads/meta-fbsource' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: builds/facebook-fbsource
- name: Ensure clean directory
run: rm -rf compiled-rn
- uses: actions/download-artifact@v3
with:
name: compiled-rn
path: compiled-rn/
- name: Revert version changes
if: needs.download_artifacts.outputs.last_version_rn != ''
env:
CURRENT_VERSION: ${{ needs.download_artifacts.outputs.current_version_rn }}
LAST_VERSION: ${{ needs.download_artifacts.outputs.last_version_rn }}
run: |
echo "Reverting $CURRENT_VERSION to $LAST_VERSION"
grep -rl "$CURRENT_VERSION" ./compiled-rn || echo "No files found with $CURRENT_VERSION"
grep -rl "$CURRENT_VERSION" ./compiled-rn | xargs -r sed -i -e "s/$CURRENT_VERSION/$LAST_VERSION/g"
grep -rl "$CURRENT_VERSION" ./compiled-rn || echo "Version reverted"
- name: Check for changes
id: check_should_commit
run: |
echo "Full git status"
git add .
git --no-pager diff -U0 --cached | grep '^[+-]' | head -n 100
echo "===================="
# Ignore REVISION or lines removing @generated headers.
if git diff --cached ':(exclude)*REVISION' | grep -vE "^(@@|diff|index|\-\-\-|\+\+\+|\- \* @generated SignedSource)" | grep "^[+-]" > /dev/null; then
echo "Changes detected"
echo "===== Changes ====="
git --no-pager diff --cached ':(exclude)*REVISION' | grep -vE "^(@@|diff|index|\-\-\-|\+\+\+|\- \* @generated SignedSource)" | grep "^[+-]" | head -n 50
echo "==================="
echo "should_commit=true" >> "$GITHUB_OUTPUT"
else
echo "No Changes detected"
echo "should_commit=false" >> "$GITHUB_OUTPUT"
fi
- name: Re-apply version changes
if: steps.check_should_commit.outputs.should_commit == 'true' && needs.download_artifacts.outputs.last_version_rn != ''
env:
CURRENT_VERSION: ${{ needs.download_artifacts.outputs.current_version_rn }}
LAST_VERSION: ${{ needs.download_artifacts.outputs.last_version_rn }}
run: |
echo "Re-applying $LAST_VERSION to $CURRENT_VERSION"
grep -rl "$LAST_VERSION" ./compiled-rn || echo "No files found with $LAST_VERSION"
grep -rl "$LAST_VERSION" ./compiled-rn | xargs -r sed -i -e "s/$LAST_VERSION/$CURRENT_VERSION/g"
grep -rl "$LAST_VERSION" ./compiled-rn || echo "Version re-applied"
- name: Add files for signing
if: steps.check_should_commit.outputs.should_commit == 'true'
run: |
echo ":"
git add .
- name: Signing files
if: steps.check_should_commit.outputs.should_commit == 'true'
uses: actions/github-script@v6
with:
script: |
// TODO: Move this to a script file.
// We currently can't call scripts from the repo because
// at this point in the workflow, we're on the compiled
// artifact branch (so the scripts don't exist).
// We can fix this with a composite action in the main repo.
// This script is duplicated above.
const fs = require('fs');
const crypto = require('crypto');
const {execSync} = require('child_process');
// TODO: when we move this to a script, we can use this from npm.
// Copy of signedsource since we can't install deps on this branch.
const GENERATED = '@' + 'generated';
const NEWTOKEN = '<<SignedSource::*O*zOeWoEQle#+L!plEphiEmie@IsG>>';
const PATTERN = new RegExp(`${GENERATED} (?:SignedSource<<([a-f0-9]{32})>>)`);
const TokenNotFoundError = new Error(
`SignedSource.signFile(...): Cannot sign file without token: ${NEWTOKEN}`
);
function hash(data, encoding) {
const md5sum = crypto.createHash('md5');
md5sum.update(data, encoding);
return md5sum.digest('hex');
}
const SignedSource = {
getSigningToken() {
return `${GENERATED} ${NEWTOKEN}`;
},
isSigned(data) {
return PATTERN.exec(data) != null;
},
signFile(data) {
if (!data.includes(NEWTOKEN)) {
if (SignedSource.isSigned(data)) {
// Signing a file that was previously signed.
data = data.replace(PATTERN, SignedSource.getSigningToken());
} else {
throw TokenNotFoundError;
}
}
return data.replace(NEWTOKEN, `SignedSource<<${hash(data, 'utf8')}>>`);
},
};
const directory = './compiled-rn';
console.log('Signing files in directory:', directory);
try {
const result = execSync(`git status --porcelain ${directory}`, {encoding: 'utf8'});
// Parse the git status output to get file paths
const files = result.split('\n').filter(file => file.endsWith('.js'));
if (files.length === 0) {
throw new Error(
'git status returned no files to sign. this job should not have run.'
);
} else {
files.forEach(line => {
const file = line.slice(3).trim();
if (file) {
console.log(' Signing file:', file);
const originalContents = fs.readFileSync(file, 'utf8');
const signedContents = SignedSource.signFile(
originalContents
// Need to add the header in, since it's not inserted at build time.
.replace(' */\n', ` * ${SignedSource.getSigningToken()}\n */\n`)
);
fs.writeFileSync(file, signedContents, 'utf8');
}
});
}
} catch (e) {
process.exitCode = 1;
console.error('Error signing files:', e);
}
- name: Will commit these changes
if: steps.check_should_commit.outputs.should_commit == 'true'
run: |
git add .
git status
- name: Commit changes to branch
if: steps.check_should_commit.outputs.should_commit == 'true'
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: |
${{ github.event.head_commit.message }}
DiffTrain build for commit https://github.com/facebook/react/commit/${{ github.sha }}.
branch: builds/facebook-fbsource
commit_user_name: ${{ github.actor }}
commit_user_email: ${{ github.actor }}@users.noreply.github.com
create_branch: true

30
.github/workflows/runtime_fizz.yml vendored Normal file
View File

@@ -0,0 +1,30 @@
name: (Runtime) Fizz
on:
push:
branches: [main]
pull_request:
paths-ignore:
- 'compiler/**'
jobs:
check_generated_fizz_runtime:
name: Confirm generated inline Fizz runtime is up to date
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 18.x
cache: "yarn"
cache-dependency-path: yarn.lock
- name: Restore cached node_modules
uses: actions/cache@v4
id: node_modules
with:
path: "**/node_modules"
key: ${{ runner.arch }}-${{ runner.os }}-modules-${{ hashFiles('yarn.lock') }}
- run: yarn install --frozen-lockfile
- run: |
yarn generate-inline-fizz-runtime
git diff --quiet || (echo "There was a change to the Fizz runtime. Run `yarn generate-inline-fizz-runtime` and check in the result." && false)

28
.github/workflows/runtime_flags.yml vendored Normal file
View File

@@ -0,0 +1,28 @@
name: (Runtime) Flags
on:
push:
branches: [main]
pull_request:
paths-ignore:
- 'compiler/**'
jobs:
flags:
name: Check flags
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 18.x
cache: "yarn"
cache-dependency-path: yarn.lock
- name: Restore cached node_modules
uses: actions/cache@v4
id: node_modules
with:
path: "**/node_modules"
key: ${{ runner.arch }}-${{ runner.os }}-modules-${{ hashFiles('yarn.lock') }}
- run: yarn install --frozen-lockfile
- run: yarn flags

47
.github/workflows/runtime_flow.yml vendored Normal file
View File

@@ -0,0 +1,47 @@
name: (Runtime) Flow
on:
push:
branches: [main]
pull_request:
paths-ignore:
- 'compiler/**'
jobs:
discover_flow_inline_configs:
name: Discover flow inline configs
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.result }}
steps:
- uses: actions/checkout@v4
- uses: actions/github-script@v7
id: set-matrix
with:
script: |
const inlinedHostConfigs = require('./scripts/shared/inlinedHostConfigs.js');
return inlinedHostConfigs.map(config => config.shortName);
flow:
name: Flow check ${{ matrix.flow_inline_config_shortname }}
needs: discover_flow_inline_configs
runs-on: ubuntu-latest
continue-on-error: true
strategy:
matrix:
flow_inline_config_shortname: ${{ fromJSON(needs.discover_flow_inline_configs.outputs.matrix) }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 18.x
cache: "yarn"
cache-dependency-path: yarn.lock
- name: Restore cached node_modules
uses: actions/cache@v4
id: node_modules
with:
path: "**/node_modules"
key: ${{ runner.arch }}-${{ runner.os }}-modules-${{ hashFiles('yarn.lock') }}
- run: yarn install --frozen-lockfile
- run: node ./scripts/tasks/flow-ci ${{ matrix.flow_inline_config_shortname }}

View File

@@ -0,0 +1,32 @@
name: (Runtime) Fuzz tests
on:
schedule:
- cron: 0 * * * *
push:
branches:
- main
workflow_dispatch:
inputs:
prerelease_commit_sha:
required: false
jobs:
test_fuzz:
if: inputs.prerelease_commit_sha == ''
runs-on: ubuntu-latest
env:
TZ: "/usr/share/zoneinfo/America/Los_Angeles"
steps:
- uses: actions/checkout@v4.1.0
- uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: 'yarn'
- name: Install dependencies
run: yarn install --frozen-lockfile
env:
ELECTRON_SKIP_BINARY_DOWNLOAD: "1"
shell: bash
- name: Run fuzz tests
run: |-
FUZZ_TEST_SEED=$RANDOM yarn test fuzz --ci=github
FUZZ_TEST_SEED=$RANDOM yarn test --prod fuzz --ci=github

85
.github/workflows/runtime_test.yml vendored Normal file
View File

@@ -0,0 +1,85 @@
name: (Runtime) Test
on:
push:
branches: [main]
pull_request:
paths-ignore:
- 'compiler/**'
env:
# Number of workers (one per shard) to spawn
SHARD_COUNT: 5
jobs:
# Define the various test parameters and parallelism for this workflow
build_test_params:
name: Build test params
runs-on: ubuntu-latest
outputs:
params: ${{ steps.define-params.outputs.result }}
shard_id: ${{ steps.define-shards.outputs.result }}
steps:
- uses: actions/github-script@v7
id: define-shards
with:
script: |
function range(from, to) {
const arr = [];
for (let n = from; n <= to; n++) {
arr.push(n);
}
return arr;
}
return range(1, process.env.SHARD_COUNT);
- uses: actions/github-script@v7
id: define-params
with:
script: |
return [
"-r=stable --env=development",
"-r=stable --env=production",
"-r=experimental --env=development",
"-r=experimental --env=production",
"-r=www-classic --env=development --variant=false",
"-r=www-classic --env=production --variant=false",
"-r=www-classic --env=development --variant=true",
"-r=www-classic --env=production --variant=true",
"-r=www-modern --env=development --variant=false",
"-r=www-modern --env=production --variant=false",
"-r=www-modern --env=development --variant=true",
"-r=www-modern --env=production --variant=true",
"-r=xplat --env=development --variant=false",
"-r=xplat --env=development --variant=true",
"-r=xplat --env=production --variant=false",
"-r=xplat --env=production --variant=true",
// TODO: Test more persistent configurations?
"-r=stable --env=development --persistent",
"-r=experimental --env=development --persistent"
];
# Spawn a job for each shard for a given set of test params
test:
name: yarn test ${{ matrix.params }} (Shard ${{ matrix.shard_id }})
runs-on: ubuntu-latest
needs: build_test_params
strategy:
matrix:
params: ${{ fromJSON(needs.build_test_params.outputs.params) }}
shard_id: ${{ fromJSON(needs.build_test_params.outputs.shard_id) }}
continue-on-error: true
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 18.x
cache: "yarn"
cache-dependency-path: yarn.lock
- name: Restore cached node_modules
uses: actions/cache@v4
id: node_modules
with:
path: "**/node_modules"
key: ${{ runner.arch }}-${{ runner.os }}-modules-${{ hashFiles('yarn.lock') }}
- run: yarn install --frozen-lockfile
- run: yarn test ${{ matrix.params }} --ci=github --shard=${{ matrix.shard_id }}/${{ env.SHARD_COUNT }}

79
.github/workflows/shared_lint.yml vendored Normal file
View File

@@ -0,0 +1,79 @@
name: (Shared) Lint
on:
push:
branches: [main]
pull_request:
jobs:
prettier:
name: Run prettier
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 18.x
cache: "yarn"
cache-dependency-path: yarn.lock
- name: Restore cached node_modules
uses: actions/cache@v4
with:
path: "**/node_modules"
key: ${{ runner.arch }}-${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }}
- run: yarn install --frozen-lockfile
- run: yarn prettier-check
eslint:
name: Run eslint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 18.x
cache: "yarn"
cache-dependency-path: yarn.lock
- name: Restore cached node_modules
uses: actions/cache@v4
with:
path: "**/node_modules"
key: ${{ runner.arch }}-${{ runner.os }}-modules-${{ hashFiles('yarn.lock') }}
- run: yarn install --frozen-lockfile
- run: node ./scripts/tasks/eslint
check_license:
name: Check license
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 18.x
cache: "yarn"
cache-dependency-path: yarn.lock
- name: Restore cached node_modules
uses: actions/cache@v4
with:
path: "**/node_modules"
key: ${{ runner.arch }}-${{ runner.os }}-modules-${{ hashFiles('yarn.lock') }}
- run: yarn install --frozen-lockfile
- run: ./scripts/circleci/check_license.sh
test_print_warnings:
name: Test print warnings
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 18.x
cache: "yarn"
cache-dependency-path: yarn.lock
- name: Restore cached node_modules
uses: actions/cache@v4
with:
path: "**/node_modules"
key: ${{ runner.arch }}-${{ runner.os }}-modules-${{ hashFiles('yarn.lock') }}
- run: yarn install --frozen-lockfile
- run: ./scripts/circleci/test_print_warnings.sh

46
.github/workflows/shared_stale.yml vendored Normal file
View File

@@ -0,0 +1,46 @@
# Configuration for stale action workflow - https://github.com/actions/stale
name: (Shared) Manage stale issues and PRs
on:
schedule:
# Run hourly
- cron: '0 * * * *'
jobs:
stale:
runs-on: ubuntu-latest
steps:
- uses: actions/stale@v9
with:
# --- Issues & PRs ---
# Number of days of inactivity before an issue or PR becomes stale
days-before-stale: 90
# Number of days of inactivity before a stale issue or PR is closed
days-before-close: 7
# API calls per run
operations-per-run: 100
# --- Issues ---
stale-issue-label: "Resolution: Stale"
# Comment to post when marking an issue as stale
stale-issue-message: >
This issue has been automatically marked as stale.
**If this issue is still affecting you, please leave any comment** (for example, "bump"), and we'll keep it open.
We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment!
# Comment to post when closing a stale issue
close-issue-message: >
Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please create a new issue with up-to-date information. Thank you!
# Issues with these labels will never be considered stale
exempt-issue-labels: "Partner,React Core Team,Resolution: Backlog,Type: Bug,Type: Discussion,Type: Needs Investigation,Type: Regression,Type: Feature Request,Type: Enhancement"
# --- PRs ---
stale-pr-label: "Resolution: Stale"
# Comment to post when marking a pull request as stale
stale-pr-message: >
This pull request has been automatically marked as stale.
**If this pull request is still relevant, please leave any comment** (for example, "bump"), and we'll keep it open.
We are sorry that we haven't been able to prioritize reviewing it yet. Your contribution is very much appreciated.
# Comment to post when closing a stale pull request
close-pr-message: >
Closing this pull request after a prolonged period of inactivity. If this issue is still present in the latest release, please ask for this pull request to be reopened. Thank you!
# PRs with these labels will never be considered stale
exempt-pr-labels: "Partner,React Core Team,Resolution: Backlog,Type: Bug,Type: Discussion,Type: Needs Investigation,Type: Regression,Type: Feature Request,Type: Enhancement"

6
.gitignore vendored
View File

@@ -1,6 +1,7 @@
.DS_STORE
node_modules
scripts/flow/*/.flowconfig
.flowconfig
*~
*.pyc
.grunt
@@ -31,5 +32,8 @@ packages/react-devtools-extensions/firefox/build
packages/react-devtools-extensions/firefox/*.xpi
packages/react-devtools-extensions/firefox/*.pem
packages/react-devtools-extensions/shared/build
packages/react-devtools-extensions/.tempUserDataDir
packages/react-devtools-fusebox/dist
packages/react-devtools-inline/dist
packages/react-devtools-shell/dist
packages/react-devtools-shell/dist
packages/react-devtools-timeline/dist

View File

@@ -127,6 +127,8 @@ Rainer Oviir <roviir@gmail.com> <raineroviir@rainers-MacBook-Pro.local>
Ray <ray@tomo.im>
Richard Feldman <richard.t.feldman@gmail.com> <richard@noredink.com>
Richard Livesey <Livesey7@hotmail.co.uk>
Rick Hanlon <rickhanlonii@gmail.com>
Rick Hanlon <rickhanlonii@gmail.com> <rickhanlonii@fb.com>
Rob Arnold <robarnold@cs.cmu.edu>
Robert Binna <rbinna@gmail.com> <speedskater@users.noreply.github.com>
Robin Frischmann <robin@rofrischmann.de>
@@ -145,6 +147,7 @@ Steven Luscher <react@steveluscher.com> <github@steveluscher.com>
Steven Luscher <react@steveluscher.com> <steveluscher@fb.com>
Steven Luscher <react@steveluscher.com> <steveluscher@instagram.com>
Steven Luscher <react@steveluscher.com> <steveluscher@users.noreply.github.com>
Seth Webster <sethwebster@gmail.com> <sethwebster@fb.com>
Stoyan Stefanov <ssttoo@ymail.com>
Tengfei Guo <terryr3rd@yeah.net> <tfguo369@gmail.com>
Thomas Aylott <oblivious@subtlegradient.com> <aylott@fb.com>

2
.nvmrc
View File

@@ -1 +1 @@
v10.16.3
v18.20.0

View File

@@ -1,6 +1,39 @@
# react runtime
build
packages/react-devtools-core/dist
packages/react-devtools-extensions/chrome/build
packages/react-devtools-extensions/firefox/build
packages/react-devtools-extensions/edge/build
packages/react-devtools-extensions/shared/build
packages/react-devtools-extensions/src/ErrorTesterCompiled.js
packages/react-devtools-fusebox/dist
packages/react-devtools-inline/dist
packages/react-devtools-shell/dist
packages/react-devtools-shared/src/hooks/__tests__/__source__/__compiled__/
packages/react-devtools-shared/src/hooks/__tests__/__source__/__untransformed__/
packages/react-devtools-shell/dist
packages/react-devtools-timeline/dist
packages/react-devtools-timeline/static
# react compiler
compiler/**/dist
compiler/**/__tests__/fixtures/**/*.expect.md
compiler/**/__tests__/fixtures/**/*.flow.js
compiler/**/.next
compiler/crates
compiler/apps/playground/public
compiler/**/LICENSE
compiler/.*
compiler/*.md*
compiler/*.json
compiler/*.css
compiler/*.webmanifest
compiler/*.map
compiler/*.sh
compiler/*.txt
compiler/*.ico
compiler/*.svg
compiler/*.lock
compiler/*.toml

View File

@@ -1,21 +1,52 @@
'use strict';
const {esNextPaths} = require('./scripts/shared/pathsByLanguageVersion');
const {
compilerPaths,
esNextPaths,
typescriptPaths,
} = require('./scripts/shared/pathsByLanguageVersion');
module.exports = {
bracketSpacing: false,
singleQuote: true,
jsxBracketSameLine: true,
bracketSameLine: true,
trailingComma: 'es5',
printWidth: 80,
parser: 'babel',
parser: 'flow',
arrowParens: 'avoid',
overrides: [
{
files: ['*.code-workspace'],
options: {
parser: 'json-stringify',
},
},
{
files: esNextPaths,
options: {
trailingComma: 'all',
},
},
{
files: typescriptPaths,
options: {
trailingComma: 'all',
parser: 'typescript',
},
},
{
files: compilerPaths,
options: {
requirePragma: false,
parser: 'babel-ts',
semi: true,
singleQuote: false,
trailingComma: 'es5',
bracketSpacing: true,
bracketSameLine: false,
printWidth: 80,
arrowParens: 'always',
},
},
],
};

1131
AUTHORS

File diff suppressed because it is too large Load Diff

18
CHANGELOG-canary.md Normal file
View File

@@ -0,0 +1,18 @@
## March 22, 2024 (18.3.0-canary-670811593-20240322)
## React
- Added `useActionState` to replace `useFormState` and added `pending` value ([#28491](https://github.com/facebook/react/pull/28491)).
## October 5, 2023 (18.3.0-canary-546178f91-20231005)
### React
- Added support for async functions to be passed to `startTransition`.
- `useTransition` now triggers the nearest error boundary instead of a global error.
- Added `useOptimistic`, a new Hook for handling optimistic UI updates. It optimistically updates the UI before receiving confirmation from a server or external source.
### React DOM
- Added support for passing async functions to the `action` prop on `<form>`. When the function passed to `action` is marked with [`'use server'`](https://react.dev/reference/react/use-server), the form is [progressively enhanced](https://developer.mozilla.org/en-US/docs/Glossary/Progressive_Enhancement).
- Added `useFormStatus`, a new Hook for checking the submission state of a form.
- Added `useFormState`, a new Hook for updating state upon form submission. When the function passed to `useFormState` is marked with [`'use server'`](https://react.dev/reference/react/use-server), the update is [progressively enhanced](https://developer.mozilla.org/en-US/docs/Glossary/Progressive_Enhancement).

View File

@@ -1,10 +1,374 @@
## [Unreleased]
<details>
<summary>
Changes that have landed in master but are not yet released.
Click to see more.
</summary>
</details>
## 18.3.1 (April 26, 2024)
- Export `act` from `react` [f1338f](https://github.com/facebook/react/commit/f1338f8080abd1386454a10bbf93d67bfe37ce85)
## 18.3.0 (April 25, 2024)
This release is identical to 18.2 but adds warnings for deprecated APIs and other changes that are needed for React 19.
Read the [React 19 Upgrade Guide](https://react.dev/blog/2024/04/25/react-19-upgrade-guide) for more info.
### React
- Allow writing to `this.refs` to support string ref codemod [909071](https://github.com/facebook/react/commit/9090712fd3ca4e1099e1f92e67933c2cb4f32552)
- Warn for deprecated `findDOMNode` outside StrictMode [c3b283](https://github.com/facebook/react/commit/c3b283964108b0e8dbcf1f9eb2e7e67815e39dfb)
- Warn for deprecated `test-utils` methods [d4ea75](https://github.com/facebook/react/commit/d4ea75dc4258095593b6ac764289f42bddeb835c)
- Warn for deprecated Legacy Context outside StrictMode [415ee0](https://github.com/facebook/react/commit/415ee0e6ea0fe3e288e65868df2e3241143d5f7f)
- Warn for deprecated string refs outside StrictMode [#25383](https://github.com/facebook/react/pull/25383)
- Warn for deprecated `defaultProps` for function components [#25699](https://github.com/facebook/react/pull/25699)
- Warn when spreading `key` [#25697](https://github.com/facebook/react/pull/25697)
- Warn when using `act` from `test-utils` [d4ea75](https://github.com/facebook/react/commit/d4ea75dc4258095593b6ac764289f42bddeb835c)
### React DOM
- Warn for deprecated `unmountComponentAtNode` [8a015b](https://github.com/facebook/react/commit/8a015b68cc060079878e426610e64e86fb328f8d)
- Warn for deprecated `renderToStaticNodeStream` [#28874](https://github.com/facebook/react/pull/28874)
## 18.2.0 (June 14, 2022)
### React DOM
* Provide a component stack as a second argument to `onRecoverableError`. ([@gnoff](https://github.com/gnoff) in [#24591](https://github.com/facebook/react/pull/24591))
* Fix hydrating into `document` causing a blank page on mismatch. ([@gnoff](https://github.com/gnoff) in [#24523](https://github.com/facebook/react/pull/24523))
* Fix false positive hydration errors with Suspense. ([@gnoff](https://github.com/gnoff) in [#24480](https://github.com/facebook/react/pull/24480) and [@acdlite](https://github.com/acdlite) in [#24532](https://github.com/facebook/react/pull/24532))
* Fix ignored `setState` in Safari when adding an iframe. ([@gaearon](https://github.com/gaearon) in [#24459](https://github.com/facebook/react/pull/24459))
### React DOM Server
* Pass information about server errors to the client. ([@salazarm](https://github.com/salazarm) and [@gnoff](https://github.com/gnoff) in [#24551](https://github.com/facebook/react/pull/24551) and [#24591](https://github.com/facebook/react/pull/24591))
* Allow to provide a reason when aborting the HTML stream. ([@gnoff](https://github.com/gnoff) in [#24680](https://github.com/facebook/react/pull/24680))
* Eliminate extraneous text separators in the HTML where possible. ([@gnoff](https://github.com/gnoff) in [#24630](https://github.com/facebook/react/pull/24630))
* Disallow complex children inside `<title>` elements to match the browser constraints. ([@gnoff](https://github.com/gnoff) in [#24679](https://github.com/facebook/react/pull/24679))
* Fix buffering in some worker environments by explicitly setting `highWaterMark` to `0`. ([@jplhomer](https://github.com/jplhomer) in [#24641](https://github.com/facebook/react/pull/24641))
### Server Components (Experimental)
* Add support for `useId()` inside Server Components. ([@gnoff](https://github.com/gnoff) in [#24172](https://github.com/facebook/react/pull/24172))
## 18.1.0 (April 26, 2022)
### React DOM
* Fix the false positive warning about `react-dom/client` when using UMD bundle. ([@alireza-molaee](https://github.com/alireza-molaee) in [#24274](https://github.com/facebook/react/pull/24274))
* Fix `suppressHydrationWarning` to work in production too. ([@gaearon](https://github.com/gaearon) in [#24271](https://github.com/facebook/react/pull/24271))
* Fix `componentWillUnmount` firing twice inside of Suspense. ([@acdlite](https://github.com/acdlite) in [#24308](https://github.com/facebook/react/pull/24308))
* Fix some transition updates being ignored. ([@acdlite](https://github.com/acdlite) in [#24353](https://github.com/facebook/react/pull/24353))
* Fix `useDeferredValue` causing an infinite loop when passed an unmemoized value. ([@acdlite](https://github.com/acdlite) in [#24247](https://github.com/facebook/react/pull/24247))
* Fix throttling of revealing Suspense fallbacks. ([@sunderls](https://github.com/sunderls) in [#24253](https://github.com/facebook/react/pull/24253))
* Fix an inconsistency in whether the props object is the same between renders. ([@Andarist](https://github.com/Andarist) and [@acdlite](https://github.com/acdlite) in [#24421](https://github.com/facebook/react/pull/24421))
* Fix a missing warning about a `setState` loop in `useEffect`. ([@gaearon](https://github.com/gaearon) in [#24298](https://github.com/facebook/react/pull/24298))
* Fix a spurious hydration error. ([@gnoff](https://github.com/gnoff) in [#24404](https://github.com/facebook/react/pull/24404))
* Warn when calling `setState` in `useInsertionEffect`. ([@gaearon](https://github.com/gaearon) in [#24295](https://github.com/facebook/react/pull/24295))
* Ensure the reason for hydration errors is always displayed. ([@gaearon](https://github.com/gaearon) in [#24276](https://github.com/facebook/react/pull/24276))
### React DOM Server
* Fix escaping for the `bootstrapScriptContent` contents. ([@gnoff](https://github.com/gnoff) in [#24385](https://github.com/facebook/react/pull/24385))
* Significantly improve performance of `renderToPipeableStream`. ([@gnoff](https://github.com/gnoff) in [#24291](https://github.com/facebook/react/pull/24291))
### ESLint Plugin: React Hooks
* Fix false positive errors with a large number of branches. ([@scyron6](https://github.com/scyron6) in [#24287](https://github.com/facebook/react/pull/24287))
* Don't consider a known dependency stable when the variable is reassigned. ([@afzalsayed96](https://github.com/afzalsayed96) in [#24343](https://github.com/facebook/react/pull/24343))
### Use Subscription
* Replace the implementation with the `use-sync-external-store` shim. ([@gaearon](https://github.com/gaearon) in [#24289](https://github.com/facebook/react/pull/24289))
## 18.0.0 (March 29, 2022)
Below is a list of all new features, APIs, deprecations, and breaking changes.
Read [React 18 release post](https://reactjs.org/blog/2022/03/29/react-v18.html) and [React 18 upgrade guide](https://reactjs.org/blog/2022/03/08/react-18-upgrade-guide.html) for more information.
### New Features
### React
* `useId` is a new hook for generating unique IDs on both the client and server, while avoiding hydration mismatches. It is primarily useful for component libraries integrating with accessibility APIs that require unique IDs. This solves an issue that already exists in React 17 and below, but its even more important in React 18 because of how the new streaming server renderer delivers HTML out-of-order.
* `startTransition` and `useTransition` let you mark some state updates as not urgent. Other state updates are considered urgent by default. React will allow urgent state updates (for example, updating a text input) to interrupt non-urgent state updates (for example, rendering a list of search results).
* `useDeferredValue` lets you defer re-rendering a non-urgent part of the tree. It is similar to debouncing, but has a few advantages compared to it. There is no fixed time delay, so React will attempt the deferred render right after the first render is reflected on the screen. The deferred render is interruptible and doesn't block user input.
* `useSyncExternalStore` is a new hook that allows external stores to support concurrent reads by forcing updates to the store to be synchronous. It removes the need for `useEffect` when implementing subscriptions to external data sources, and is recommended for any library that integrates with state external to React.
* `useInsertionEffect` is a new hook that allows CSS-in-JS libraries to address performance issues of injecting styles in render. Unless youve already built a CSS-in-JS library we dont expect you to ever use this. This hook will run after the DOM is mutated, but before layout effects read the new layout. This solves an issue that already exists in React 17 and below, but is even more important in React 18 because React yields to the browser during concurrent rendering, giving it a chance to recalculate layout.
### React DOM Client
These new APIs are now exported from `react-dom/client`:
* `createRoot`: New method to create a root to `render` or `unmount`. Use it instead of `ReactDOM.render`. New features in React 18 don't work without it.
* `hydrateRoot`: New method to hydrate a server rendered application. Use it instead of `ReactDOM.hydrate` in conjunction with the new React DOM Server APIs. New features in React 18 don't work without it.
Both `createRoot` and `hydrateRoot` accept a new option called `onRecoverableError` in case you want to be notified when React recovers from errors during rendering or hydration for logging. By default, React will use [`reportError`](https://developer.mozilla.org/en-US/docs/Web/API/reportError), or `console.error` in the older browsers.
### React DOM Server
These new APIs are now exported from `react-dom/server` and have full support for streaming Suspense on the server:
* `renderToPipeableStream`: for streaming in Node environments.
* `renderToReadableStream`: for modern edge runtime environments, such as Deno and Cloudflare workers.
The existing `renderToString` method keeps working but is discouraged.
## Deprecations
* `react-dom`: `ReactDOM.render` has been deprecated. Using it will warn and run your app in React 17 mode.
* `react-dom`: `ReactDOM.hydrate` has been deprecated. Using it will warn and run your app in React 17 mode.
* `react-dom`: `ReactDOM.unmountComponentAtNode` has been deprecated.
* `react-dom`: `ReactDOM.renderSubtreeIntoContainer` has been deprecated.
* `react-dom/server`: `ReactDOMServer.renderToNodeStream` has been deprecated.
## Breaking Changes
### React
* **Automatic batching:** This release introduces a performance improvement that changes to the way React batches updates to do more batching automatically. See [Automatic batching for fewer renders in React 18](https://github.com/reactwg/react-18/discussions/21) for more info. In the rare case that you need to opt out, wrap the state update in `flushSync`.
* **Stricter Strict Mode**: In the future, React will provide a feature that lets components preserve state between unmounts. To prepare for it, React 18 introduces a new development-only check to Strict Mode. React will automatically unmount and remount every component, whenever a component mounts for the first time, restoring the previous state on the second mount. If this breaks your app, consider removing Strict Mode until you can fix the components to be resilient to remounting with existing state.
* **Consistent useEffect timing**: React now always synchronously flushes effect functions if the update was triggered during a discrete user input event such as a click or a keydown event. Previously, the behavior wasn't always predictable or consistent.
* **Stricter hydration errors**: Hydration mismatches due to missing or extra text content are now treated like errors instead of warnings. React will no longer attempt to "patch up" individual nodes by inserting or deleting a node on the client in an attempt to match the server markup, and will revert to client rendering up to the closest `<Suspense>` boundary in the tree. This ensures the hydrated tree is consistent and avoids potential privacy and security holes that can be caused by hydration mismatches.
* **Suspense trees are always consistent:** If a component suspends before it's fully added to the tree, React will not add it to the tree in an incomplete state or fire its effects. Instead, React will throw away the new tree completely, wait for the asynchronous operation to finish, and then retry rendering again from scratch. React will render the retry attempt concurrently, and without blocking the browser.
* **Layout Effects with Suspense**: When a tree re-suspends and reverts to a fallback, React will now clean up layout effects, and then re-create them when the content inside the boundary is shown again. This fixes an issue which prevented component libraries from correctly measuring layout when used with Suspense.
* **New JS Environment Requirements**: React now depends on modern browsers features including `Promise`, `Symbol`, and `Object.assign`. If you support older browsers and devices such as Internet Explorer which do not provide modern browser features natively or have non-compliant implementations, consider including a global polyfill in your bundled application.
### Scheduler (Experimental)
* Remove unstable `scheduler/tracing` API
## Notable Changes
### React
* **Components can now render `undefined`:** React no longer throws if you return `undefined` from a component. This makes the allowed component return values consistent with values that are allowed in the middle of a component tree. We suggest to use a linter to prevent mistakes like forgetting a `return` statement before JSX.
* **In tests, `act` warnings are now opt-in:** If you're running end-to-end tests, the `act` warnings are unnecessary. We've introduced an [opt-in](https://github.com/reactwg/react-18/discussions/102) mechanism so you can enable them only for unit tests where they are useful and beneficial.
* **No warning about `setState` on unmounted components:** Previously, React warned about memory leaks when you call `setState` on an unmounted component. This warning was added for subscriptions, but people primarily run into it in scenarios where setting state is fine, and workarounds make the code worse. We've [removed](https://github.com/facebook/react/pull/22114) this warning.
* **No suppression of console logs:** When you use Strict Mode, React renders each component twice to help you find unexpected side effects. In React 17, we've suppressed console logs for one of the two renders to make the logs easier to read. In response to [community feedback](https://github.com/facebook/react/issues/21783) about this being confusing, we've removed the suppression. Instead, if you have React DevTools installed, the second log's renders will be displayed in grey, and there will be an option (off by default) to suppress them completely.
* **Improved memory usage:** React now cleans up more internal fields on unmount, making the impact from unfixed memory leaks that may exist in your application code less severe.
### React DOM Server
* **`renderToString`:** Will no longer error when suspending on the server. Instead, it will emit the fallback HTML for the closest `<Suspense>` boundary and then retry rendering the same content on the client. It is still recommended that you switch to a streaming API like `renderToPipeableStream` or `renderToReadableStream` instead.
* **`renderToStaticMarkup`:** Will no longer error when suspending on the server. Instead, it will emit the fallback HTML for the closest `<Suspense>` boundary and retry rendering on the client.
## All Changes
## React
* Add `useTransition` and `useDeferredValue` to separate urgent updates from transitions. ([#10426](https://github.com/facebook/react/pull/10426), [#10715](https://github.com/facebook/react/pull/10715), [#15593](https://github.com/facebook/react/pull/15593), [#15272](https://github.com/facebook/react/pull/15272), [#15578](https://github.com/facebook/react/pull/15578), [#15769](https://github.com/facebook/react/pull/15769), [#17058](https://github.com/facebook/react/pull/17058), [#18796](https://github.com/facebook/react/pull/18796), [#19121](https://github.com/facebook/react/pull/19121), [#19703](https://github.com/facebook/react/pull/19703), [#19719](https://github.com/facebook/react/pull/19719), [#19724](https://github.com/facebook/react/pull/19724), [#20672](https://github.com/facebook/react/pull/20672), [#20976](https://github.com/facebook/react/pull/20976) by [@acdlite](https://github.com/acdlite), [@lunaruan](https://github.com/lunaruan), [@rickhanlonii](https://github.com/rickhanlonii), and [@sebmarkbage](https://github.com/sebmarkbage))
* Add `useId` for generating unique IDs. ([#17322](https://github.com/facebook/react/pull/17322), [#18576](https://github.com/facebook/react/pull/18576), [#22644](https://github.com/facebook/react/pull/22644), [#22672](https://github.com/facebook/react/pull/22672), [#21260](https://github.com/facebook/react/pull/21260) by [@acdlite](https://github.com/acdlite), [@lunaruan](https://github.com/lunaruan), and [@sebmarkbage](https://github.com/sebmarkbage))
* Add `useSyncExternalStore` to help external store libraries integrate with React. ([#15022](https://github.com/facebook/react/pull/15022), [#18000](https://github.com/facebook/react/pull/18000), [#18771](https://github.com/facebook/react/pull/18771), [#22211](https://github.com/facebook/react/pull/22211), [#22292](https://github.com/facebook/react/pull/22292), [#22239](https://github.com/facebook/react/pull/22239), [#22347](https://github.com/facebook/react/pull/22347), [#23150](https://github.com/facebook/react/pull/23150) by [@acdlite](https://github.com/acdlite), [@bvaughn](https://github.com/bvaughn), and [@drarmstr](https://github.com/drarmstr))
* Add `startTransition` as a version of `useTransition` without pending feedback. ([#19696](https://github.com/facebook/react/pull/19696) by [@rickhanlonii](https://github.com/rickhanlonii))
* Add `useInsertionEffect` for CSS-in-JS libraries. ([#21913](https://github.com/facebook/react/pull/21913) by [@rickhanlonii](https://github.com/rickhanlonii))
* Make Suspense remount layout effects when content reappears. ([#19322](https://github.com/facebook/react/pull/19322), [#19374](https://github.com/facebook/react/pull/19374), [#19523](https://github.com/facebook/react/pull/19523), [#20625](https://github.com/facebook/react/pull/20625), [#21079](https://github.com/facebook/react/pull/21079) by [@acdlite](https://github.com/acdlite), [@bvaughn](https://github.com/bvaughn), and [@lunaruan](https://github.com/lunaruan))
* Make `<StrictMode>` re-run effects to check for restorable state. ([#19523](https://github.com/facebook/react/pull/19523) , [#21418](https://github.com/facebook/react/pull/21418) by [@bvaughn](https://github.com/bvaughn) and [@lunaruan](https://github.com/lunaruan))
* Assume Symbols are always available. ([#23348](https://github.com/facebook/react/pull/23348) by [@sebmarkbage](https://github.com/sebmarkbage))
* Remove `object-assign` polyfill. ([#23351](https://github.com/facebook/react/pull/23351) by [@sebmarkbage](https://github.com/sebmarkbage))
* Remove unsupported `unstable_changedBits` API. ([#20953](https://github.com/facebook/react/pull/20953) by [@acdlite](https://github.com/acdlite))
* Allow components to render undefined. ([#21869](https://github.com/facebook/react/pull/21869) by [@rickhanlonii](https://github.com/rickhanlonii))
* Flush `useEffect` resulting from discrete events like clicks synchronously. ([#21150](https://github.com/facebook/react/pull/21150) by [@acdlite](https://github.com/acdlite))
* Suspense `fallback={undefined}` now behaves the same as `null` and isn't ignored. ([#21854](https://github.com/facebook/react/pull/21854) by [@rickhanlonii](https://github.com/rickhanlonii))
* Consider all `lazy()` resolving to the same component equivalent. ([#20357](https://github.com/facebook/react/pull/20357) by [@sebmarkbage](https://github.com/sebmarkbage))
* Don't patch console during first render. ([#22308](https://github.com/facebook/react/pull/22308) by [@lunaruan](https://github.com/lunaruan))
* Improve memory usage. ([#21039](https://github.com/facebook/react/pull/21039) by [@bgirard](https://github.com/bgirard))
* Improve messages if string coercion throws (Temporal.*, Symbol, etc.) ([#22064](https://github.com/facebook/react/pull/22064) by [@justingrant](https://github.com/justingrant))
* Use `setImmediate` when available over `MessageChannel`. ([#20834](https://github.com/facebook/react/pull/20834) by [@gaearon](https://github.com/gaearon))
* Fix context failing to propagate inside suspended trees. ([#23095](https://github.com/facebook/react/pull/23095) by [@gaearon](https://github.com/gaearon))
* Fix `useReducer` observing incorrect props by removing the eager bailout mechanism. ([#22445](https://github.com/facebook/react/pull/22445) by [@josephsavona](https://github.com/josephsavona))
* Fix `setState` being ignored in Safari when appending iframes. ([#23111](https://github.com/facebook/react/pull/23111) by [@gaearon](https://github.com/gaearon))
* Fix a crash when rendering `ZonedDateTime` in the tree. ([#20617](https://github.com/facebook/react/pull/20617) by [@dimaqq](https://github.com/dimaqq))
* Fix a crash when document is set to `null` in tests. ([#22695](https://github.com/facebook/react/pull/22695) by [@SimenB](https://github.com/SimenB))
* Fix `onLoad` not triggering when concurrent features are on. ([#23316](https://github.com/facebook/react/pull/23316) by [@gnoff](https://github.com/gnoff))
* Fix a warning when a selector returns `NaN`. ([#23333](https://github.com/facebook/react/pull/23333) by [@hachibeeDI](https://github.com/hachibeeDI))
* Fix the generated license header. ([#23004](https://github.com/facebook/react/pull/23004) by [@vitaliemiron](https://github.com/vitaliemiron))
* Add `package.json` as one of the entry points. ([#22954](https://github.com/facebook/react/pull/22954) by [@Jack](https://github.com/Jack-Works))
* Allow suspending outside a Suspense boundary. ([#23267](https://github.com/facebook/react/pull/23267) by [@acdlite](https://github.com/acdlite))
* Log a recoverable error whenever hydration fails. ([#23319](https://github.com/facebook/react/pull/23319) by [@acdlite](https://github.com/acdlite))
### React DOM
* Add `createRoot` and `hydrateRoot`. ([#10239](https://github.com/facebook/react/pull/10239), [#11225](https://github.com/facebook/react/pull/11225), [#12117](https://github.com/facebook/react/pull/12117), [#13732](https://github.com/facebook/react/pull/13732), [#15502](https://github.com/facebook/react/pull/15502), [#15532](https://github.com/facebook/react/pull/15532), [#17035](https://github.com/facebook/react/pull/17035), [#17165](https://github.com/facebook/react/pull/17165), [#20669](https://github.com/facebook/react/pull/20669), [#20748](https://github.com/facebook/react/pull/20748), [#20888](https://github.com/facebook/react/pull/20888), [#21072](https://github.com/facebook/react/pull/21072), [#21417](https://github.com/facebook/react/pull/21417), [#21652](https://github.com/facebook/react/pull/21652), [#21687](https://github.com/facebook/react/pull/21687), [#23207](https://github.com/facebook/react/pull/23207), [#23385](https://github.com/facebook/react/pull/23385) by [@acdlite](https://github.com/acdlite), [@bvaughn](https://github.com/bvaughn), [@gaearon](https://github.com/gaearon), [@lunaruan](https://github.com/lunaruan), [@rickhanlonii](https://github.com/rickhanlonii), [@trueadm](https://github.com/trueadm), and [@sebmarkbage](https://github.com/sebmarkbage))
* Add selective hydration. ([#14717](https://github.com/facebook/react/pull/14717), [#14884](https://github.com/facebook/react/pull/14884), [#16725](https://github.com/facebook/react/pull/16725), [#16880](https://github.com/facebook/react/pull/16880), [#17004](https://github.com/facebook/react/pull/17004), [#22416](https://github.com/facebook/react/pull/22416), [#22629](https://github.com/facebook/react/pull/22629), [#22448](https://github.com/facebook/react/pull/22448), [#22856](https://github.com/facebook/react/pull/22856), [#23176](https://github.com/facebook/react/pull/23176) by [@acdlite](https://github.com/acdlite), [@gaearon](https://github.com/gaearon), [@salazarm](https://github.com/salazarm), and [@sebmarkbage](https://github.com/sebmarkbage))
* Add `aria-description` to the list of known ARIA attributes. ([#22142](https://github.com/facebook/react/pull/22142) by [@mahyareb](https://github.com/mahyareb))
* Add `onResize` event to video elements. ([#21973](https://github.com/facebook/react/pull/21973) by [@rileyjshaw](https://github.com/rileyjshaw))
* Add `imageSizes` and `imageSrcSet` to known props. ([#22550](https://github.com/facebook/react/pull/22550) by [@eps1lon](https://github.com/eps1lon))
* Allow non-string `<option>` children if `value` is provided. ([#21431](https://github.com/facebook/react/pull/21431) by [@sebmarkbage](https://github.com/sebmarkbage))
* Fix `aspectRatio` style not being applied. ([#21100](https://github.com/facebook/react/pull/21100) by [@gaearon](https://github.com/gaearon))
* Warn if `renderSubtreeIntoContainer` is called. ([#23355](https://github.com/facebook/react/pull/23355) by [@acdlite](https://github.com/acdlite))
### React DOM Server
* Add the new streaming renderer. ([#14144](https://github.com/facebook/react/pull/14144), [#20970](https://github.com/facebook/react/pull/20970), [#21056](https://github.com/facebook/react/pull/21056), [#21255](https://github.com/facebook/react/pull/21255), [#21200](https://github.com/facebook/react/pull/21200), [#21257](https://github.com/facebook/react/pull/21257), [#21276](https://github.com/facebook/react/pull/21276), [#22443](https://github.com/facebook/react/pull/22443), [#22450](https://github.com/facebook/react/pull/22450), [#23247](https://github.com/facebook/react/pull/23247), [#24025](https://github.com/facebook/react/pull/24025), [#24030](https://github.com/facebook/react/pull/24030) by [@sebmarkbage](https://github.com/sebmarkbage))
* Fix context providers in SSR when handling multiple requests. ([#23171](https://github.com/facebook/react/pull/23171) by [@frandiox](https://github.com/frandiox))
* Revert to client render on text mismatch. ([#23354](https://github.com/facebook/react/pull/23354) by [@acdlite](https://github.com/acdlite))
* Deprecate `renderToNodeStream`. ([#23359](https://github.com/facebook/react/pull/23359) by [@sebmarkbage](https://github.com/sebmarkbage))
* Fix a spurious error log in the new server renderer. ([#24043](https://github.com/facebook/react/pull/24043) by [@eps1lon](https://github.com/eps1lon))
* Fix a bug in the new server renderer. ([#22617](https://github.com/facebook/react/pull/22617) by [@shuding](https://github.com/shuding))
* Ignore function and symbol values inside custom elements on the server. ([#21157](https://github.com/facebook/react/pull/21157) by [@sebmarkbage](https://github.com/sebmarkbage))
### React DOM Test Utils
* Throw when `act` is used in production. ([#21686](https://github.com/facebook/react/pull/21686) by [@acdlite](https://github.com/acdlite))
* Support disabling spurious act warnings with `global.IS_REACT_ACT_ENVIRONMENT`. ([#22561](https://github.com/facebook/react/pull/22561) by [@acdlite](https://github.com/acdlite))
* Expand act warning to cover all APIs that might schedule React work. ([#22607](https://github.com/facebook/react/pull/22607) by [@acdlite](https://github.com/acdlite))
* Make `act` batch updates. ([#21797](https://github.com/facebook/react/pull/21797) by [@acdlite](https://github.com/acdlite))
* Remove warning for dangling passive effects. ([#22609](https://github.com/facebook/react/pull/22609) by [@acdlite](https://github.com/acdlite))
### React Refresh
* Track late-mounted roots in Fast Refresh. ([#22740](https://github.com/facebook/react/pull/22740) by [@anc95](https://github.com/anc95))
* Add `exports` field to `package.json`. ([#23087](https://github.com/facebook/react/pull/23087) by [@otakustay](https://github.com/otakustay))
### Server Components (Experimental)
* Add Server Context support. ([#23244](https://github.com/facebook/react/pull/23244) by [@salazarm](https://github.com/salazarm))
* Add `lazy` support. ([#24068](https://github.com/facebook/react/pull/24068) by [@gnoff](https://github.com/gnoff))
* Update webpack plugin for webpack 5 ([#22739](https://github.com/facebook/react/pull/22739) by [@michenly](https://github.com/michenly))
* Fix a mistake in the Node loader. ([#22537](https://github.com/facebook/react/pull/22537) by [@btea](https://github.com/btea))
* Use `globalThis` instead of `window` for edge environments. ([#22777](https://github.com/facebook/react/pull/22777) by [@huozhi](https://github.com/huozhi))
### Scheduler (Experimental)
* Remove unstable `scheduler/tracing` API ([#20037](https://github.com/facebook/react/pull/20037) by [@bvaughn](https://github.com/bvaughn))
## 17.0.2 (March 22, 2021)
### React DOM
* Remove an unused dependency to address the [`SharedArrayBuffer` cross-origin isolation warning](https://developer.chrome.com/blog/enabling-shared-array-buffer/). ([@koba04](https://github.com/koba04) and [@bvaughn](https://github.com/bvaughn) in [#20831](https://github.com/facebook/react/pull/20831), [#20832](https://github.com/facebook/react/pull/20832), and [#20840](https://github.com/facebook/react/pull/20840))
## 17.0.1 (October 22, 2020)
### React DOM
* Fix a crash in IE11. ([@gaearon](https://github.com/gaearon) in [#20071](https://github.com/facebook/react/pull/20071))
## 17.0.0 (October 20, 2020)
Today, we are releasing React 17!
**[Learn more about React 17 and how to update to it on the official React blog.](https://reactjs.org/blog/2020/10/20/react-v17.html)**
### React
* Add `react/jsx-runtime` and `react/jsx-dev-runtime` for the [new JSX transform](https://babeljs.io/blog/2020/03/16/7.9.0#a-new-jsx-transform-11154-https-githubcom-babel-babel-pull-11154). ([@lunaruan](https://github.com/lunaruan) in [#18299](https://github.com/facebook/react/pull/18299))
* Build component stacks from native error frames. ([@sebmarkbage](https://github.com/sebmarkbage) in [#18561](https://github.com/facebook/react/pull/18561))
* Allow to specify `displayName` on context for improved stacks. ([@eps1lon](https://github.com/eps1lon) in [#18224](https://github.com/facebook/react/pull/18224))
* Prevent `'use strict'` from leaking in the UMD bundles. ([@koba04](https://github.com/koba04) in [#19614](https://github.com/facebook/react/pull/19614))
* Stop using `fb.me` for redirects. ([@cylim](https://github.com/cylim) in [#19598](https://github.com/facebook/react/pull/19598))
### React DOM
* Delegate events to roots instead of `document`. ([@trueadm](https://github.com/trueadm) in [#18195](https://github.com/facebook/react/pull/18195) and [others](https://github.com/facebook/react/pulls?q=is%3Apr+author%3Atrueadm+modern+event+is%3Amerged))
* Clean up all effects before running any next effects. ([@bvaughn](https://github.com/bvaughn) in [#17947](https://github.com/facebook/react/pull/17947))
* Run `useEffect` cleanup functions asynchronously. ([@bvaughn](https://github.com/bvaughn) in [#17925](https://github.com/facebook/react/pull/17925))
* Use browser `focusin` and `focusout` for `onFocus` and `onBlur`. ([@trueadm](https://github.com/trueadm) in [#19186](https://github.com/facebook/react/pull/19186))
* Make all `Capture` events use the browser capture phase. ([@trueadm](https://github.com/trueadm) in [#19221](https://github.com/facebook/react/pull/19221))
* Don't emulate bubbling of the `onScroll` event. ([@gaearon](https://github.com/gaearon) in [#19464](https://github.com/facebook/react/pull/19464))
* Throw if `forwardRef` or `memo` component returns `undefined`. ([@gaearon](https://github.com/gaearon) in [#19550](https://github.com/facebook/react/pull/19550))
* Remove event pooling. ([@trueadm](https://github.com/trueadm) in [#18969](https://github.com/facebook/react/pull/18969))
* Stop exposing internals that wont be needed by React Native Web. ([@necolas](https://github.com/necolas) in [#18483](https://github.com/facebook/react/pull/18483))
* Attach all known event listeners when the root mounts. ([@gaearon](https://github.com/gaearon) in [#19659](https://github.com/facebook/react/pull/19659))
* Disable `console` in the second render pass of DEV mode double render. ([@sebmarkbage](https://github.com/sebmarkbage) in [#18547](https://github.com/facebook/react/pull/18547))
* Deprecate the undocumented and misleading `ReactTestUtils.SimulateNative` API. ([@gaearon](https://github.com/gaearon) in [#13407](https://github.com/facebook/react/pull/13407))
* Rename private field names used in the internals. ([@gaearon](https://github.com/gaearon) in [#18377](https://github.com/facebook/react/pull/18377))
* Don't call User Timing API in development. ([@gaearon](https://github.com/gaearon) in [#18417](https://github.com/facebook/react/pull/18417))
* Disable console during the repeated render in Strict Mode. ([@sebmarkbage](https://github.com/sebmarkbage) in [#18547](https://github.com/facebook/react/pull/18547))
* In Strict Mode, double-render components without Hooks too. ([@eps1lon](https://github.com/eps1lon) in [#18430](https://github.com/facebook/react/pull/18430))
* Allow calling `ReactDOM.flushSync` during lifecycle methods (but warn). ([@sebmarkbage](https://github.com/sebmarkbage) in [#18759](https://github.com/facebook/react/pull/18759))
* Add the `code` property to the keyboard event objects. ([@bl00mber](https://github.com/bl00mber) in [#18287](https://github.com/facebook/react/pull/18287))
* Add the `disableRemotePlayback` property for `video` elements. ([@tombrowndev](https://github.com/tombrowndev) in [#18619](https://github.com/facebook/react/pull/18619))
* Add the `enterKeyHint` property for `input` elements. ([@eps1lon](https://github.com/eps1lon) in [#18634](https://github.com/facebook/react/pull/18634))
* Warn when no `value` is provided to `<Context.Provider>`. ([@charlie1404](https://github.com/charlie1404) in [#19054](https://github.com/facebook/react/pull/19054))
* Warn when `memo` or `forwardRef` components return `undefined`. ([@bvaughn](https://github.com/bvaughn) in [#19550](https://github.com/facebook/react/pull/19550))
* Improve the error message for invalid updates. ([@JoviDeCroock](https://github.com/JoviDeCroock) in [#18316](https://github.com/facebook/react/pull/18316))
* Exclude forwardRef and memo from stack frames. ([@sebmarkbage](https://github.com/sebmarkbage) in [#18559](https://github.com/facebook/react/pull/18559))
* Improve the error message when switching between controlled and uncontrolled inputs. ([@vcarl](https://github.com/vcarl) in [#17070](https://github.com/facebook/react/pull/17070))
* Keep `onTouchStart`, `onTouchMove`, and `onWheel` passive. ([@gaearon](https://github.com/gaearon) in [#19654](https://github.com/facebook/react/pull/19654))
* Fix `setState` hanging in development inside a closed iframe. ([@gaearon](https://github.com/gaearon) in [#19220](https://github.com/facebook/react/pull/19220))
* Fix rendering bailout for lazy components with `defaultProps`. ([@jddxf](https://github.com/jddxf) in [#18539](https://github.com/facebook/react/pull/18539))
* Fix a false positive warning when `dangerouslySetInnerHTML` is `undefined`. ([@eps1lon](https://github.com/eps1lon) in [#18676](https://github.com/facebook/react/pull/18676))
* Fix Test Utils with non-standard `require` implementation. ([@just-boris](https://github.com/just-boris) in [#18632](https://github.com/facebook/react/pull/18632))
* Fix `onBeforeInput` reporting an incorrect `event.type`. ([@eps1lon](https://github.com/eps1lon) in [#19561](https://github.com/facebook/react/pull/19561))
* Fix `event.relatedTarget` reported as `undefined` in Firefox. ([@claytercek](https://github.com/claytercek) in [#19607](https://github.com/facebook/react/pull/19607))
* Fix "unspecified error" in IE11. ([@hemakshis](https://github.com/hemakshis) in [#19664](https://github.com/facebook/react/pull/19664))
* Fix rendering into a shadow root. ([@Jack-Works](https://github.com/Jack-Works) in [#15894](https://github.com/facebook/react/pull/15894))
* Fix `movementX/Y` polyfill with capture events. ([@gaearon](https://github.com/gaearon) in [#19672](https://github.com/facebook/react/pull/19672))
* Use delegation for `onSubmit` and `onReset` events. ([@gaearon](https://github.com/gaearon) in [#19333](https://github.com/facebook/react/pull/19333))
* Improve memory usage. ([@trueadm](https://github.com/trueadm) in [#18970](https://github.com/facebook/react/pull/18970))
### React DOM Server
* Make `useCallback` behavior consistent with `useMemo` for the server renderer. ([@alexmckenley](https://github.com/alexmckenley) in [#18783](https://github.com/facebook/react/pull/18783))
* Fix state leaking when a function component throws. ([@pmaccart](https://github.com/pmaccart) in [#19212](https://github.com/facebook/react/pull/19212))
### React Test Renderer
* Improve `findByType` error message. ([@henryqdineen](https://github.com/henryqdineen) in [#17439](https://github.com/facebook/react/pull/17439))
### Concurrent Mode (Experimental)
* Revamp the priority batching heuristics. ([@acdlite](https://github.com/acdlite) in [#18796](https://github.com/facebook/react/pull/18796))
* Add the `unstable_` prefix before the experimental APIs. ([@acdlite](https://github.com/acdlite) in [#18825](https://github.com/facebook/react/pull/18825))
* Remove `unstable_discreteUpdates` and `unstable_flushDiscreteUpdates`. ([@trueadm](https://github.com/trueadm) in [#18825](https://github.com/facebook/react/pull/18825))
* Remove the `timeoutMs` argument. ([@acdlite](https://github.com/acdlite) in [#19703](https://github.com/facebook/react/pull/19703))
* Disable `<div hidden />` prerendering in favor of a different future API. ([@acdlite](https://github.com/acdlite) in [#18917](https://github.com/facebook/react/pull/18917))
* Add `unstable_expectedLoadTime` to Suspense for CPU-bound trees. ([@acdlite](https://github.com/acdlite) in [#19936](https://github.com/facebook/react/pull/19936))
* Add an experimental `unstable_useOpaqueIdentifier` Hook. ([@lunaruan](https://github.com/lunaruan) in [#17322](https://github.com/facebook/react/pull/17322))
* Add an experimental `unstable_startTransition` API. ([@rickhanlonii](https://github.com/rickhanlonii) in [#19696](https://github.com/facebook/react/pull/19696))
* Using `act` in the test renderer no longer flushes Suspense fallbacks. ([@acdlite](https://github.com/acdlite) in [#18596](https://github.com/facebook/react/pull/18596))
* Use global render timeout for CPU Suspense. ([@sebmarkbage](https://github.com/sebmarkbage) in [#19643](https://github.com/facebook/react/pull/19643))
* Clear the existing root content before mounting. ([@bvaughn](https://github.com/bvaughn) in [#18730](https://github.com/facebook/react/pull/18730))
* Fix a bug with error boundaries. ([@acdlite](https://github.com/acdlite) in [#18265](https://github.com/facebook/react/pull/18265))
* Fix a bug causing dropped updates in a suspended tree. ([@acdlite](https://github.com/acdlite) in [#18384](https://github.com/facebook/react/pull/18384) and [#18457](https://github.com/facebook/react/pull/18457))
* Fix a bug causing dropped render phase updates. ([@acdlite](https://github.com/acdlite) in [#18537](https://github.com/facebook/react/pull/18537))
* Fix a bug in SuspenseList. ([@sebmarkbage](https://github.com/sebmarkbage) in [#18412](https://github.com/facebook/react/pull/18412))
* Fix a bug causing Suspense fallback to show too early. ([@acdlite](https://github.com/acdlite) in [#18411](https://github.com/facebook/react/pull/18411))
* Fix a bug with class components inside SuspenseList. ([@sebmarkbage](https://github.com/sebmarkbage) in [#18448](https://github.com/facebook/react/pull/18448))
* Fix a bug with inputs that may cause updates to be dropped. ([@jddxf](https://github.com/jddxf) in [#18515](https://github.com/facebook/react/pull/18515) and [@acdlite](https://github.com/acdlite) in [#18535](https://github.com/facebook/react/pull/18535))
* Fix a bug causing Suspense fallback to get stuck. ([@acdlite](https://github.com/acdlite) in [#18663](https://github.com/facebook/react/pull/18663))
* Don't cut off the tail of a SuspenseList if hydrating. ([@sebmarkbage](https://github.com/sebmarkbage) in [#18854](https://github.com/facebook/react/pull/18854))
* Fix a bug in `useMutableSource` that may happen when `getSnapshot` changes. ([@bvaughn](https://github.com/bvaughn) in [#18297](https://github.com/facebook/react/pull/18297))
* Fix a tearing bug in `useMutableSource`. ([@bvaughn](https://github.com/bvaughn) in [#18912](https://github.com/facebook/react/pull/18912))
* Warn if calling setState outside of render but before commit. ([@sebmarkbage](https://github.com/sebmarkbage) in [#18838](https://github.com/facebook/react/pull/18838))
## 16.14.0 (October 14, 2020)
### React
* Add support for the [new JSX transform](https://reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html). ([@lunaruan](https://github.com/lunaruan) in [#18299](https://github.com/facebook/react/pull/18299))
## 16.13.1 (March 19, 2020)
### React DOM
* Fix bug in legacy mode Suspense where effect clean-up functions are not fired. This only affects users who use Suspense for data fetching in legacy mode, which is not technically supported. ([@acdlite](https://github.com/acdlite) in [#18238](https://github.com/facebook/react/pull/18238))
* Revert warning for cross-component updates that happen inside class render lifecycles (`componentWillReceiveProps`, `shouldComponentUpdate`, and so on). ([@gaearon](https://github.com/gaearon) in [#18330](https://github.com/facebook/react/pull/18330))
## 16.13.0 (February 26, 2020)
### React
* Warn when a string ref is used in a manner that's not amenable to a future codemod ([@lunaruan](https://github.com/lunaruan) in [#17864](https://github.com/facebook/react/pull/17864))
* Deprecate `React.createFactory()` ([@trueadm](https://github.com/trueadm) in [#17878](https://github.com/facebook/react/pull/17878))
### React DOM
* Warn when changes in `style` may cause an unexpected collision ([@sophiebits](https://github.com/sophiebits) in [#14181](https://github.com/facebook/react/pull/14181), [#18002](https://github.com/facebook/react/pull/18002))
* Warn when a function component is updated during another component's render phase ([@acdlite](https://github.com/acdlite) in [#17099](https://github.com/facebook/react/pull/17099))
* Deprecate `unstable_createPortal` ([@trueadm](https://github.com/trueadm) in [#17880](https://github.com/facebook/react/pull/17880))
* Fix `onMouseEnter` being fired on disabled buttons ([@AlfredoGJ](https://github.com/AlfredoGJ) in [#17675](https://github.com/facebook/react/pull/17675))
* Call `shouldComponentUpdate` twice when developing in `StrictMode` ([@bvaughn](https://github.com/bvaughn) in [#17942](https://github.com/facebook/react/pull/17942))
* Add `version` property to ReactDOM ([@ealush](https://github.com/ealush) in [#15780](https://github.com/facebook/react/pull/15780))
* Don't call `toString()` of `dangerouslySetInnerHTML` ([@sebmarkbage](https://github.com/sebmarkbage) in [#17773](https://github.com/facebook/react/pull/17773))
* Show component stacks in more warnings ([@gaearon](https://github.com/gaearon) in [#17922](https://github.com/facebook/react/pull/17922), [#17586](https://github.com/facebook/react/pull/17586))
### Concurrent Mode (Experimental)
* Warn for problematic usages of `ReactDOM.createRoot()` ([@trueadm](https://github.com/trueadm) in [#17937](https://github.com/facebook/react/pull/17937))
* Remove `ReactDOM.createRoot()` callback params and added warnings on usage ([@bvaughn](https://github.com/bvaughn) in [#17916](https://github.com/facebook/react/pull/17916))
* Don't group Idle/Offscreen work with other work ([@sebmarkbage](https://github.com/sebmarkbage) in [#17456](https://github.com/facebook/react/pull/17456))
* Adjust `SuspenseList` CPU bound heuristic ([@sebmarkbage](https://github.com/sebmarkbage) in [#17455](https://github.com/facebook/react/pull/17455))
* Add missing event plugin priorities ([@trueadm](https://github.com/trueadm) in [#17914](https://github.com/facebook/react/pull/17914))
* Fix `isPending` only being true when transitioning from inside an input event ([@acdlite](https://github.com/acdlite) in [#17382](https://github.com/facebook/react/pull/17382))
* Fix `React.memo` components dropping updates when interrupted by a higher priority update ([@acdlite]((https://github.com/acdlite)) in [#18091](https://github.com/facebook/react/pull/18091))
* Don't warn when suspending at the wrong priority ([@gaearon](https://github.com/gaearon) in [#17971](https://github.com/facebook/react/pull/17971))
* Fix a bug with rebasing updates ([@acdlite](https://github.com/acdlite) and [@sebmarkbage](https://github.com/sebmarkbage) in [#17560](https://github.com/facebook/react/pull/17560), [#17510](https://github.com/facebook/react/pull/17510), [#17483](https://github.com/facebook/react/pull/17483), [#17480](https://github.com/facebook/react/pull/17480))
## 16.12.0 (November 14, 2019)
@@ -543,7 +907,7 @@ This release was published in a broken state and should be skipped.
### React Is (New)
* First release of the [new package](https://github.com/facebook/react/tree/master/packages/react-is) that libraries can use to detect different React node types. ([@bvaughn](https://github.com/bvaughn) in [#12199](https://github.com/facebook/react/pull/12199))
* First release of the [new package](https://github.com/facebook/react/tree/main/packages/react-is) that libraries can use to detect different React node types. ([@bvaughn](https://github.com/bvaughn) in [#12199](https://github.com/facebook/react/pull/12199))
* Add `ReactIs.isValidElementType()` to help higher-order components validate their inputs. ([@jamesreggio](https://github.com/jamesreggio) in [#12483](https://github.com/facebook/react/pull/12483))
### React Lifecycles Compat (New)
@@ -552,7 +916,7 @@ This release was published in a broken state and should be skipped.
### Create Subscription (New)
* First release of the [new package](https://github.com/facebook/react/tree/master/packages/create-subscription) to subscribe to external data sources safely for async rendering. ([@bvaughn](https://github.com/bvaughn) in [#12325](https://github.com/facebook/react/pull/12325))
* First release of the [new package](https://github.com/facebook/react/tree/main/packages/create-subscription) to subscribe to external data sources safely for async rendering. ([@bvaughn](https://github.com/bvaughn) in [#12325](https://github.com/facebook/react/pull/12325))
### React Reconciler (Experimental)
@@ -683,12 +1047,12 @@ Starting with 16.1.0, we will no longer be publishing new releases on Bower. You
### React Reconciler (Experimental)
* First release of the [new experimental package](https://github.com/facebook/react/blob/master/packages/react-reconciler/README.md) for creating custom renderers. ([@iamdustan](https://github.com/iamdustan) in [#10758](https://github.com/facebook/react/pull/10758))
* First release of the [new experimental package](https://github.com/facebook/react/blob/main/packages/react-reconciler/README.md) for creating custom renderers. ([@iamdustan](https://github.com/iamdustan) in [#10758](https://github.com/facebook/react/pull/10758))
* Add support for React DevTools. ([@gaearon](https://github.com/gaearon) in [#11463](https://github.com/facebook/react/pull/11463))
### React Call Return (Experimental)
* First release of the [new experimental package](https://github.com/facebook/react/tree/master/packages/react-call-return) for parent-child communication. ([@gaearon](https://github.com/gaearon) in [#11364](https://github.com/facebook/react/pull/11364))
* First release of the [new experimental package](https://github.com/facebook/react/tree/main/packages/react-call-return) for parent-child communication. ([@gaearon](https://github.com/gaearon) in [#11364](https://github.com/facebook/react/pull/11364))
## 16.0.1 (August 1, 2018)
@@ -741,6 +1105,12 @@ Starting with 16.1.0, we will no longer be publishing new releases on Bower. You
- There is no `react-with-addons.js` build anymore. All compatible addons are published separately on npm, and have single-file browser versions if you need them.
- The deprecations introduced in 15.x have been removed from the core package. `React.createClass` is now available as create-react-class, `React.PropTypes` as prop-types, `React.DOM` as react-dom-factories, react-addons-test-utils as react-dom/test-utils, and shallow renderer as react-test-renderer/shallow. See [15.5.0](https://reactjs.org/blog/2017/04/07/react-v15.5.0.html) and [15.6.0](https://reactjs.org/blog/2017/06/13/react-v15.6.0.html) blog posts for instructions on migrating code and automated codemods.
## 15.7.0 (October 14, 2020)
### React
* Backport support for the [new JSX transform](https://reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html) to 15.x. ([@lunaruan](https://github.com/lunaruan) in [#18299](https://github.com/facebook/react/pull/18299) and [@gaearon](https://github.com/gaearon) in [#20024](https://github.com/facebook/react/pull/20024))
## 15.6.2 (September 25, 2017)
### All Packages
@@ -753,7 +1123,7 @@ Starting with 16.1.0, we will no longer be publishing new releases on Bower. You
* Fix bug in QtWebKit when wrapping synthetic events in proxies. ([@walrusfruitcake](https://github.com/walrusfruitcake) in [#10115](https://github.com/facebook/react/pull/10011))
* Prevent event handlers from receiving extra argument in development. ([@aweary](https://github.com/aweary) in [#10115](https://github.com/facebook/react/pull/8363))
* Fix cases where `onChange` would not fire with `defaultChecked` on radio inputs. ([@jquense](https://github.com/jquense) in [#10156](https://github.com/facebook/react/pull/10156))
* Add support for `controlList` attribute to DOM property whitelist ([@nhunzaker](https://github.com/nhunzaker) in [#9940](https://github.com/facebook/react/pull/9940))
* Add support for `controlList` attribute to allowed DOM properties ([@nhunzaker](https://github.com/nhunzaker) in [#9940](https://github.com/facebook/react/pull/9940))
* Fix a bug where creating an element with a ref in a constructor did not throw an error in development. ([@iansu](https://github.com/iansu) in [#10025](https://github.com/facebook/react/pull/10025))
## 15.6.1 (June 14, 2017)
@@ -1189,9 +1559,14 @@ Each of these changes will continue to work as before with a new warning until t
- Shallow renderer now returns the rendered output from `render()`. ([@simonewebdesign](https://github.com/simonewebdesign) in [#5411](https://github.com/facebook/react/pull/5411))
- React no longer depends on ES5 *shams* for `Object.create` and `Object.freeze` in older environments. It still, however, requires ES5 *shims* in those environments. ([@dgreensp](https://github.com/dgreensp) in [#4959](https://github.com/facebook/react/pull/4959))
- React DOM now allows `data-` attributes with names that start with numbers. ([@nLight](https://github.com/nLight) in [#5216](https://github.com/facebook/react/pull/5216))
- React DOM adds a new `suppressContentEditableWarning` prop for components like [Draft.js](https://facebook.github.io/draft-js/) that intentionally manage `contentEditable` children with React. ([@mxstbr](https://github.com/mxstbr) in [#6112](https://github.com/facebook/react/pull/6112))
- React DOM adds a new `suppressContentEditableWarning` prop for components like [Draft.js](https://draftjs.org/) that intentionally manage `contentEditable` children with React. ([@mxstbr](https://github.com/mxstbr) in [#6112](https://github.com/facebook/react/pull/6112))
- React improves the performance for `createClass()` on complex specs. ([@sophiebits](https://github.com/sophiebits) in [#5550](https://github.com/facebook/react/pull/5550))
## 0.14.10 (October 14, 2020)
### React
* Backport support for the [new JSX transform](https://reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html) to 0.14.x. ([@lunaruan](https://github.com/lunaruan) in [#18299](https://github.com/facebook/react/pull/18299) and [@gaearon](https://github.com/gaearon) in [#20024](https://github.com/facebook/react/pull/20024))
## 0.14.8 (March 29, 2016)

View File

@@ -52,6 +52,10 @@ project e-mail address, posting via an official social media account, or acting
as an appointed representative at an online or offline event. Representation of
a project may be further defined and clarified by project maintainers.
This Code of Conduct also applies outside the project spaces when there is a
reasonable belief that an individual's behavior may have a negative impact on
the project or its community.
## Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be

View File

@@ -2,4 +2,4 @@
Want to contribute to React? There are a few things you need to know.
We wrote a **[contribution guide](https://reactjs.org/contributing/how-to-contribute.html)** to help you get started.
We wrote a **[contribution guide](https://reactjs.org/docs/how-to-contribute.html)** to help you get started.

View File

@@ -1,6 +1,6 @@
MIT License
Copyright (c) Facebook, Inc. and its affiliates.
Copyright (c) Meta Platforms, Inc. and affiliates.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@@ -1,74 +1,77 @@
# [React](https://reactjs.org/) &middot; [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/facebook/react/blob/master/LICENSE) [![npm version](https://img.shields.io/npm/v/react.svg?style=flat)](https://www.npmjs.com/package/react) [![CircleCI Status](https://circleci.com/gh/facebook/react.svg?style=shield&circle-token=:circle-token)](https://circleci.com/gh/facebook/react) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://reactjs.org/docs/how-to-contribute.html#your-first-pull-request)
# [React](https://react.dev/) &middot; [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/facebook/react/blob/main/LICENSE) [![npm version](https://img.shields.io/npm/v/react.svg?style=flat)](https://www.npmjs.com/package/react) [![CircleCI Status](https://circleci.com/gh/facebook/react.svg?style=shield)](https://circleci.com/gh/facebook/react) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://legacy.reactjs.org/docs/how-to-contribute.html#your-first-pull-request)
React is a JavaScript library for building user interfaces.
* **Declarative:** React makes it painless to create interactive UIs. Design simple views for each state in your application, and React will efficiently update and render just the right components when your data changes. Declarative views make your code more predictable, simpler to understand, and easier to debug.
* **Component-Based:** Build encapsulated components that manage their own state, then compose them to make complex UIs. Since component logic is written in JavaScript instead of templates, you can easily pass rich data through your app and keep state out of the DOM.
* **Learn Once, Write Anywhere:** We don't make assumptions about the rest of your technology stack, so you can develop new features in React without rewriting existing code. React can also render on the server using Node and power mobile apps using [React Native](https://facebook.github.io/react-native/).
* **Component-Based:** Build encapsulated components that manage their own state, then compose them to make complex UIs. Since component logic is written in JavaScript instead of templates, you can easily pass rich data through your app and keep the state out of the DOM.
* **Learn Once, Write Anywhere:** We don't make assumptions about the rest of your technology stack, so you can develop new features in React without rewriting existing code. React can also render on the server using [Node](https://nodejs.org/en) and power mobile apps using [React Native](https://reactnative.dev/).
[Learn how to use React in your own project](https://reactjs.org/docs/getting-started.html).
[Learn how to use React in your project](https://react.dev/learn).
## Installation
React has been designed for gradual adoption from the start, and **you can use as little or as much React as you need**:
* Use [Online Playgrounds](https://reactjs.org/docs/getting-started.html#online-playgrounds) to get a taste of React.
* [Add React to a Website](https://reactjs.org/docs/add-react-to-a-website.html) as a `<script>` tag in one minute.
* [Create a New React App](https://reactjs.org/docs/create-a-new-react-app.html) if you're looking for a powerful JavaScript toolchain.
You can use React as a `<script>` tag from a [CDN](https://reactjs.org/docs/cdn-links.html), or as a `react` package on [npm](https://www.npmjs.com/).
* Use [Quick Start](https://react.dev/learn) to get a taste of React.
* [Add React to an Existing Project](https://react.dev/learn/add-react-to-an-existing-project) to use as little or as much React as you need.
* [Create a New React App](https://react.dev/learn/start-a-new-react-project) if you're looking for a powerful JavaScript toolchain.
## Documentation
You can find the React documentation [on the website](https://reactjs.org/docs).
You can find the React documentation [on the website](https://react.dev/).
Check out the [Getting Started](https://reactjs.org/docs/getting-started.html) page for a quick overview.
Check out the [Getting Started](https://react.dev/learn) page for a quick overview.
The documentation is divided into several sections:
* [Tutorial](https://reactjs.org/tutorial/tutorial.html)
* [Main Concepts](https://reactjs.org/docs/hello-world.html)
* [Advanced Guides](https://reactjs.org/docs/jsx-in-depth.html)
* [API Reference](https://reactjs.org/docs/react-api.html)
* [Where to Get Support](https://reactjs.org/community/support.html)
* [Contributing Guide](https://reactjs.org/docs/how-to-contribute.html)
* [Quick Start](https://react.dev/learn)
* [Tutorial](https://react.dev/learn/tutorial-tic-tac-toe)
* [Thinking in React](https://react.dev/learn/thinking-in-react)
* [Installation](https://react.dev/learn/installation)
* [Describing the UI](https://react.dev/learn/describing-the-ui)
* [Adding Interactivity](https://react.dev/learn/adding-interactivity)
* [Managing State](https://react.dev/learn/managing-state)
* [Advanced Guides](https://react.dev/learn/escape-hatches)
* [API Reference](https://react.dev/reference/react)
* [Where to Get Support](https://react.dev/community)
* [Contributing Guide](https://legacy.reactjs.org/docs/how-to-contribute.html)
You can improve it by sending pull requests to [this repository](https://github.com/reactjs/reactjs.org).
You can improve it by sending pull requests to [this repository](https://github.com/reactjs/react.dev).
## Examples
We have several examples [on the website](https://reactjs.org/). Here is the first one to get you started:
We have several examples [on the website](https://react.dev/). Here is the first one to get you started:
```jsx
import { createRoot } from 'react-dom/client';
function HelloMessage({ name }) {
return <div>Hello {name}</div>;
}
ReactDOM.render(
<HelloMessage name="Taylor" />,
document.getElementById('container')
);
const root = createRoot(document.getElementById('container'));
root.render(<HelloMessage name="Taylor" />);
```
This example will render "Hello Taylor" into a container on the page.
You'll notice that we used an HTML-like syntax; [we call it JSX](https://reactjs.org/docs/introducing-jsx.html). JSX is not required to use React, but it makes code more readable, and writing it feels like writing HTML. If you're using React as a `<script>` tag, read [this section](https://reactjs.org/docs/add-react-to-a-website.html#optional-try-react-with-jsx) on integrating JSX; otherwise, the [recommended JavaScript toolchains](https://reactjs.org/docs/create-a-new-react-app.html) handle it automatically.
You'll notice that we used an HTML-like syntax; [we call it JSX](https://react.dev/learn#writing-markup-with-jsx). JSX is not required to use React, but it makes code more readable, and writing it feels like writing HTML.
## Contributing
The main purpose of this repository is to continue to evolve React core, making it faster and easier to use. Development of React happens in the open on GitHub, and we are grateful to the community for contributing bugfixes and improvements. Read below to learn how you can take part in improving React.
The main purpose of this repository is to continue evolving React core, making it faster and easier to use. Development of React happens in the open on GitHub, and we are grateful to the community for contributing bugfixes and improvements. Read below to learn how you can take part in improving React.
### [Code of Conduct](https://code.fb.com/codeofconduct)
Facebook has adopted a Code of Conduct that we expect project participants to adhere to. Please read [the full text](https://code.fb.com/codeofconduct) so that you can understand what actions will and will not be tolerated.
### [Contributing Guide](https://reactjs.org/contributing/how-to-contribute.html)
### [Contributing Guide](https://legacy.reactjs.org/docs/how-to-contribute.html)
Read our [contributing guide](https://reactjs.org/contributing/how-to-contribute.html) to learn about our development process, how to propose bugfixes and improvements, and how to build and test your changes to React.
Read our [contributing guide](https://legacy.reactjs.org/docs/how-to-contribute.html) to learn about our development process, how to propose bugfixes and improvements, and how to build and test your changes to React.
### Good First Issues
### [Good First Issues](https://github.com/facebook/react/labels/good%20first%20issue)
To help you get your feet wet and get you familiar with our contribution process, we have a list of [good first issues](https://github.com/facebook/react/labels/good%20first%20issue) that contain bugs which have a relatively limited scope. This is a great place to get started.
To help you get your feet wet and get you familiar with our contribution process, we have a list of [good first issues](https://github.com/facebook/react/labels/good%20first%20issue) that contain bugs that have a relatively limited scope. This is a great place to get started.
### License

63
ReactVersions.js Normal file
View File

@@ -0,0 +1,63 @@
'use strict';
// This module is the single source of truth for versioning packages that we
// publish to npm.
//
// Packages will not be published unless they are added here.
//
// The @latest channel uses the version as-is, e.g.:
//
// 19.0.0
//
// The @canary channel appends additional information, with the scheme
// <version>-<label>-<commit_sha>, e.g.:
//
// 19.0.0-canary-a1c2d3e4
//
// The @experimental channel doesn't include a version, only a date and a sha, e.g.:
//
// 0.0.0-experimental-241c4467e-20200129
const ReactVersion = '19.0.0';
// The label used by the @canary channel. Represents the upcoming release's
// stability. Most of the time, this will be "canary", but we may temporarily
// choose to change it to "alpha", "beta", "rc", etc.
//
// It only affects the label used in the version string. To customize the
// npm dist tags used during publish, refer to .circleci/config.yml.
const canaryChannelLabel = 'rc';
// If the canaryChannelLabel is "rc", the build pipeline will use this to build
// an RC version of the packages.
const rcNumber = 0;
const stablePackages = {
'eslint-plugin-react-hooks': '5.1.0',
'jest-react': '0.16.0',
react: ReactVersion,
'react-art': ReactVersion,
'react-dom': ReactVersion,
'react-server-dom-webpack': ReactVersion,
'react-server-dom-turbopack': ReactVersion,
'react-is': ReactVersion,
'react-reconciler': '0.31.0',
'react-refresh': '0.16.0',
'react-test-renderer': ReactVersion,
'use-subscription': '1.10.0',
'use-sync-external-store': '1.4.0',
scheduler: '0.25.0',
};
// These packages do not exist in the @canary or @latest channel, only
// @experimental. We don't use semver, just the commit sha, so this is just a
// list of package names instead of a map.
const experimentalPackages = [];
module.exports = {
ReactVersion,
canaryChannelLabel,
rcNumber,
stablePackages,
experimentalPackages,
};

View File

@@ -1,41 +0,0 @@
image: Visual Studio 2017
# Fix line endings in Windows. (runs before repo cloning)
init:
- git config --global core.autocrlf input
environment:
JAVA_HOME: C:\Program Files\Java\jdk1.8.0
matrix:
- nodejs_version: 10
# Finish on first failed build
matrix:
fast_finish: true
platform:
- x64
branches:
only:
- master
# Disable Visual Studio build and deploy
build: off
deploy: off
install:
- ps: Install-Product node $env:nodejs_version $env:platform
- yarn install --frozen-lockfile
test_script:
- node --version
- yarn lint
# - yarn flow-ci
- yarn build
- yarn test
- yarn prettier
cache:
- node_modules
- "%LOCALAPPDATA%/Yarn"

View File

@@ -3,7 +3,6 @@
module.exports = {
plugins: [
'@babel/plugin-syntax-jsx',
'@babel/plugin-transform-react-jsx',
'@babel/plugin-transform-flow-strip-types',
['@babel/plugin-proposal-class-properties', {loose: true}],
'syntax-trailing-function-commas',

106
compiler/.eslintrc.js Normal file
View File

@@ -0,0 +1,106 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
/**
* Our philosophy for linting is that lints should be very high-signal:
* - Error, don't warn. If it's worth mentioning it's worth fixing.
* - Enable rules that consistently identify real problems. If we frequently would have to
* disable the rule due to false positives, it isn't high-signal.
* - Enable rules that help improve consistent style (to avoid code review about style rather
* than substance).
*/
module.exports = {
extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
rules: {
/*
* We prefer using const where variables are not reassigned, but occassional mistakes
* aren't a major issue
*/
"prefer-const": "off",
// Not valuable enough to enable
"no-useless-escape": "off",
/*
* There are valid use cases for loops with constant conditions where the body contains the
* break
*/
"no-constant-condition": "off",
// eslint only knows about builtin control flow (eg throw, return, break) and not custom ones
// like invariant.
"no-fallthrough": "off",
/*
* Low-value: this fires even for declarations that capture references which wouldn't be as
* obvious if the declaration was lifted to the parent root
*/
"no-inner-declarations": "off",
"multiline-comment-style": ["error", "starred-block"],
/**
* We sometimes need to check for control characters in regexes for things like preserving input
* strings
*/
"no-control-regex": "off",
"@typescript-eslint/no-empty-function": "off",
/*
* Explicitly casting to/through any is sometimes required, often for error messages to
* assertExhaustive()
*/
"@typescript-eslint/no-explicit-any": "off",
/*
* We use non-null assertions carefully. Ideally, there would be a TS option to codegen
* a non-null check at the assertion site.
*/
"@typescript-eslint/no-non-null-assertion": "off",
// Being explicit provides value in cases where inference may later change
"@typescript-eslint/no-inferrable-types": "off",
"@typescript-eslint/explicit-function-return-type": "error",
/*
* Unused variables are frequently a bug. Prefix unused variables with an _ to fix, but note
* that eslint won't warn you that an underscore prefixed variable is used and that the prefix
* should be dropped.
*/
"@typescript-eslint/no-unused-vars": [
"error",
{
argsIgnorePattern: "^_",
varsIgnorePattern: "^_",
caughtErrorsIgnorePattern: "^_",
},
],
// Consider enabling for consistency. Ideally violations could be auto-fixed.
"@typescript-eslint/consistent-generic-constructors": [
"off",
"constructor",
],
"@typescript-eslint/array-type": ["error", { default: "generic" }],
"@typescript-eslint/triple-slash-reference": "off",
"@typescript-eslint/no-var-requires": "off",
},
parser: "@typescript-eslint/parser",
plugins: ["@typescript-eslint"],
root: true,
ignorePatterns: ["**/__tests__/**/*", "**/*.d.ts", "**/dist/**/*"],
env: {
node: true,
},
/*
* If rules need to be disabled then the rule is insufficiently high signal
* and should be diasbled altogether or customized (in either case via a standalone PR)
*/
noInlineConfig: true,
reportUnusedDisableDirectives: true,
};

24
compiler/.gitignore vendored Normal file
View File

@@ -0,0 +1,24 @@
.DS_Store
.spr.yml
# Generated by Cargo
# will have compiled files and executables
debug/
target/
# These are backup files generated by rustfmt
**/*.rs.bk
# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb
node_modules
.watchmanconfig
.watchman-cookie-*
dist
.vscode
!packages/playground/.vscode
.spr.yml
testfilter.txt
bundle-oss.sh

0
compiler/.gitmodules vendored Normal file
View File

1
compiler/.watchmanconfig Normal file
View File

@@ -0,0 +1 @@
{}

View File

@@ -0,0 +1,80 @@
# Code of Conduct
## Our Pledge
In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to make participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, sex characteristics, gender identity and expression,
level of experience, education, socio-economic status, nationality, personal
appearance, race, religion, or sexual identity and orientation.
## Our Standards
Examples of behavior that contributes to creating a positive environment
include:
* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members
Examples of unacceptable behavior by participants include:
* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting
## Our Responsibilities
Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.
Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.
## Scope
This Code of Conduct applies within all project spaces, and it also applies when
an individual is representing the project or its community in public spaces.
Examples of representing a project or community include using an official
project e-mail address, posting via an official social media account, or acting
as an appointed representative at an online or offline event. Representation of
a project may be further defined and clarified by project maintainers.
This Code of Conduct also applies outside the project spaces when there is a
reasonable belief that an individual's behavior may have a negative impact on
the project or its community.
## Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at <opensource-conduct@fb.com>. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.
Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.
## Attribution
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
[homepage]: https://www.contributor-covenant.org
For answers to common questions about this code of conduct, see
https://www.contributor-covenant.org/faq

31
compiler/CONTRIBUTING.md Normal file
View File

@@ -0,0 +1,31 @@
# Contributing to react-forget
We want to make contributing to this project as easy and transparent as
possible.
## Pull Requests
We actively welcome your pull requests.
1. Fork the repo and create your branch from `main`.
2. If you've added code that should be tested, add tests.
3. If you've changed APIs, update the documentation.
4. Ensure the test suite passes.
5. Make sure your code lints.
6. If you haven't already, complete the Contributor License Agreement ("CLA").
## Contributor License Agreement ("CLA")
In order to accept your pull request, we need you to submit a CLA. You only need
to do this once to work on any of Facebook's open source projects.
Complete your CLA here: <https://code.facebook.com/cla>
## Issues
We use GitHub issues to track public bugs. Please ensure your description is
clear and has sufficient instructions to be able to reproduce the issue.
Facebook has a [bounty program](https://www.facebook.com/whitehat/) for the safe
disclosure of security bugs. In those cases, please go through the process
outlined on that page and do not file a public issue.
## License
By contributing to react-forget, you agree that your contributions will be licensed
under the LICENSE file in the root directory of this source tree.

1217
compiler/Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

61
compiler/Cargo.toml Normal file
View File

@@ -0,0 +1,61 @@
[workspace]
resolver = "2"
members = ["crates/*"]
[workspace.package]
authors = ["The React Team https://react.dev/community/team"]
description = "React Compiler"
edition = "2021"
homepage = "https://github.com/facebook/react"
keywords = ["JavaScript", "TypeScript", "React", "React Compiler", "Compiler"]
license = "MIT"
repository = "https://github.com/facebook/react"
[workspace.dependencies]
# workspace crates
react_build_hir = { path = "crates/react_build_hir" }
react_diagnostics = { path = "crates/react_diagnostics" }
react_estree = { path = "crates/react_estree" }
react_estree_codegen = { path = "crates/react_estree_codegen" }
react_fixtures = { path = "crates/react_fixtures" }
react_hermes_parser = { path = "crates/react_hermes_parser" }
react_hir = { path = "crates/react_hir" }
react_optimization = { path = "crates/react_optimization" }
react_semantic_analysis = { path = "crates/react_semantic_analysis" }
react_ssa = { path = "crates/react_ssa" }
react_utils = { path = "crates/react_utils" }
# dependencies
indexmap = { version = "2.0.0", features = ["serde"] }
insta = { version = "1.30.0", features = ["glob"] }
miette = { version = "5.9.0" }
prettyplease = "0.2.10"
quote = "1.0.29"
serde = { version = "1.0.167", features = ["serde_derive"] }
serde_json = "1.0.100"
stacker = "0.1.15"
static_assertions = "1.1.0"
syn = "2.0.23"
thiserror = "1.0.41"
hermes = { git = "https://github.com/facebook/hermes.git" }
juno_support = { git = "https://github.com/facebook/hermes.git" }
[profile.release]
# configuration adapted from oxc
# https://github.com/Boshen/oxc/blob/ea85ee9f2d64dd284c5b7410f491d81fb879abae/Cargo.toml#L89-L97
opt-level = 3
lto = "fat"
codegen-units = 1
strip = "symbols"
debug = false
panic = "abort" # Let it crash and force ourselves to write safe Rust.
# Make insta run faster by compiling with release mode optimizations
# https://docs.rs/insta/latest/insta/#optional-faster-runs
[profile.dev.package.insta]
opt-level = 3
# Make insta diffing libary faster by compiling with release mode optimizations
# https://docs.rs/insta/latest/insta/#optional-faster-runs
[profile.dev.package.similar]
opt-level = 3

21
compiler/LICENSE Normal file
View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) Meta Platforms, Inc. and affiliates.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

7
compiler/README.md Normal file
View File

@@ -0,0 +1,7 @@
# React Compiler
React Compiler is a compiler that optimizes React applications, ensuring that only the minimal parts of components and hooks will re-render when state changes. The compiler also validates that components and hooks follow the Rules of React.
More information about the design and architecture of the compiler are covered in the [Design Goals](./docs/DESIGN_GOALS.md).
More information about developing the compiler itself is covered in the [Development Guide](./docs/DEVELOPMENT_GUIDE.md).

View File

@@ -0,0 +1,3 @@
{
"extends": "next/core-web-vitals"
}

45
compiler/apps/playground/.gitignore vendored Normal file
View File

@@ -0,0 +1,45 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# dependencies
/node_modules
/.pnp
.pnp.js
# testing
/coverage
/test-results
# next.js
/.next/
/out/
# production
/build
# misc
.DS_Store
*.pem
# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.pnpm-debug.log*
# local env files
.env*.local
# vercel
.vercel
# typescript
*.tsbuildinfo
# external fonts
public/fonts/Optimistic_Display_W_Lt.woff2
public/fonts/Optimistic_Display_W_Md.woff2
public/fonts/Optimistic_Display_W_Bd.woff2
# vscode
.vscode/*
!.vscode/extensions.json

View File

@@ -0,0 +1,3 @@
{
"recommendations": ["bradlc.vscode-tailwindcss", "heybourn.headwind"]
}

View File

@@ -0,0 +1,35 @@
# React Compiler Playground
An interactive playground to demonstrate, test, and have fun with React Compiler.
## Setup
```sh
# Build React Compiler from source and install Playground dependencies.
$ yarn
# Or similarly
$ npm install
```
## Development
```sh
# Start the local development server with
$ yarn dev
# Or
$ npm run dev
# Rerun the following (in a separate terminal window) when React Compiler
# is changed locally to keep Playground in sync.
$ yarn
```
## Deployment
This project has been deployed using Vercel. Vercel does the exact same thing as we would
locally, by running `yarn` at the install step in the Playground directory to build
React Compiler from source and [symlink](https://classic.yarnpkg.com/en/docs/cli/link) it as its dependency.
This means that Playground is automatically deployed on every push and pull requests will reflect
the behaviors of React Compiler of that commit.

View File

@@ -0,0 +1,11 @@
function MyApp() {
  const $ = _c(1);
  let t0;
  if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
    t0 = <div>Hello World</div>;
    $[0] = t0;
  } else {
    t0 = $[0];
  }
  return t0;
}

View File

@@ -0,0 +1,13 @@
function TestComponent(t0) {
  const $ = _c(2);
  const { x } = t0;
  let t1;
  if ($[0] !== x) {
    t1 = <Button>{x}</Button>;
    $[0] = x;
    $[1] = t1;
  } else {
    t1 = $[1];
  }
  return t1;
}

View File

@@ -0,0 +1,49 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import { expect, test } from "@playwright/test";
import { encodeStore, type Store } from "../../lib/stores";
const STORE: Store = {
source: `export default function TestComponent({ x }) {
return <Button>{x}</Button>;
}
`,
};
const HASH = encodeStore(STORE);
function concat(data: Array<string>): string {
return data.join("");
}
test("editor should compile successfully", async ({ page }) => {
await page.goto(`/#${HASH}`, { waitUntil: "networkidle" });
await page.screenshot({
fullPage: true,
path: "test-results/00-on-networkidle.png",
});
// User input from hash compiles
await page.screenshot({
fullPage: true,
path: "test-results/01-show-js-before.png",
});
const userInput =
(await page.locator(".monaco-editor").nth(2).allInnerTexts()) ?? [];
expect(concat(userInput)).toMatchSnapshot("user-input.txt");
// Reset button works
page.on("dialog", (dialog) => dialog.accept());
await page.getByRole("button", { name: "Reset" }).click();
await page.screenshot({
fullPage: true,
path: "test-results/02-show-js-after.png",
});
const defaultInput =
(await page.locator(".monaco-editor").nth(2).allInnerTexts()) ?? [];
expect(concat(defaultInput)).toMatchSnapshot("default-input.txt");
});

View File

@@ -0,0 +1,58 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import type { NextPage } from "next";
import Head from "next/head";
import { SnackbarProvider } from "notistack";
import { Editor, Header, StoreProvider } from "../components";
import MessageSnackbar from "../components/Message";
const Home: NextPage = () => {
return (
<div className="flex flex-col w-screen h-screen font-light">
<Head>
<title>
{process.env.NODE_ENV === "development"
? "[DEV] React Compiler Playground"
: "React Compiler Playground"}
</title>
<meta
name="viewport"
content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0"
></meta>
<link rel="icon" href="/favicon.ico" />
<link rel="manifest" href="/site.webmanifest" />
<link
rel="preload"
href="/fonts/Source-Code-Pro-Regular.woff2"
as="font"
type="font/woff2"
crossOrigin="anonymous"
/>
<link
rel="preload"
href="/fonts/Optimistic_Display_W_Lt.woff2"
as="font"
type="font/woff2"
crossOrigin="anonymous"
/>
</Head>
<StoreProvider>
<SnackbarProvider
preventDuplicate
maxSnack={10}
Components={{ message: MessageSnackbar }}
>
<Header />
<Editor />
</SnackbarProvider>
</StoreProvider>
</div>
);
};
export default Home;

View File

@@ -0,0 +1,48 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import "../styles/globals.css";
export default function RootLayout({
children,
}: {
children: React.ReactNode;
}) {
"use no memo";
return (
<html lang="en">
<head>
<title>
{process.env.NODE_ENV === "development"
? "[DEV] React Compiler Playground"
: "React Compiler Playground"}
</title>
<meta
name="viewport"
content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0"
></meta>
<link rel="icon" href="/favicon.ico" />
<link rel="manifest" href="/site.webmanifest" />
<link
rel="preload"
href="/fonts/Source-Code-Pro-Regular.woff2"
as="font"
type="font/woff2"
crossOrigin="anonymous"
/>
<link
rel="preload"
href="/fonts/Optimistic_Display_W_Lt.woff2"
as="font"
type="font/woff2"
crossOrigin="anonymous"
/>
</head>
<body className="font-sans h-screen overflow-y-hidden">{children}</body>
</html>
);
}

View File

@@ -0,0 +1,27 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
"use client";
import { SnackbarProvider } from "notistack";
import { Editor, Header, StoreProvider } from "../components";
import MessageSnackbar from "../components/Message";
export default function Hoot() {
return (
<StoreProvider>
<SnackbarProvider
preventDuplicate
maxSnack={10}
Components={{ message: MessageSnackbar }}
>
<Header />
<Editor />
</SnackbarProvider>
</StoreProvider>
);
}

View File

@@ -0,0 +1,21 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
module.exports = function (api) {
api.cache(true);
return {
presets: ["next/babel"],
plugins: [
[
"babel-plugin-react-compiler",
{
runtimeModule: "react-compiler-runtime",
},
],
],
};
};

View File

@@ -0,0 +1,96 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
/**
* Sync from <https://github.com/reactjs/reactjs.org/blob/main/beta/colors.js>.
*/
module.exports = {
// Text colors
primary: "#23272F", // gray-90
"primary-dark": "#F6F7F9", // gray-5
secondary: "#404756", // gray-70
"secondary-dark": "#EBECF0", // gray-10
link: "#087EA4", // blue-50
"link-dark": "#149ECA", // blue-40
syntax: "#EBECF0", // gray-10
wash: "#FFFFFF",
"wash-dark": "#23272F", // gray-90
card: "#F6F7F9", // gray-05
"card-dark": "#343A46", // gray-80
highlight: "#E6F7FF", // blue-10
"highlight-dark": "rgba(88,175,223,.1)",
border: "#EBECF0", // gray-10
"border-dark": "#343A46", // gray-80
"secondary-button": "#EBECF0", // gray-10
"secondary-button-dark": "#404756", // gray-70
// Gray
"gray-95": "#16181D",
"gray-90": "#23272F",
"gray-80": "#343A46",
"gray-70": "#404756",
"gray-60": "#4E5769",
"gray-50": "#5E687E", // unused
"gray-40": "#78839B",
"gray-30": "#99A1B3",
"gray-20": "#BCC1CD",
"gray-10": "#EBECF0",
"gray-5": "#F6F7F9",
// Blue
"blue-60": "#045975",
"blue-50": "#087EA4",
"blue-40": "#149ECA", // Brand Blue
"blue-30": "#58C4DC", // unused
"blue-20": "#ABE2ED",
"blue-10": "#E6F7FF", // todo: doesn't match illustrations
"blue-5": "#E6F6FA",
// Yellow
"yellow-60": "#B65700",
"yellow-50": "#C76A15",
"yellow-40": "#DB7D27", // unused
"yellow-30": "#FABD62", // unused
"yellow-20": "#FCDEB0", // unused
"yellow-10": "#FDE7C7",
"yellow-5": "#FEF5E7",
// Purple
"purple-60": "#2B3491", // unused
"purple-50": "#575FB7",
"purple-40": "#6B75DB",
"purple-30": "#8891EC",
"purple-20": "#C3C8F5", // unused
"purple-10": "#E7E9FB",
"purple-5": "#F3F4FD",
// Green
"green-60": "#2B6E62",
"green-50": "#388F7F",
"green-40": "#44AC99",
"green-30": "#7FCCBF",
"green-20": "#ABDED5",
"green-10": "#E5F5F2",
"green-5": "#F4FBF9",
// RED
"red-60": "#712D28",
"red-50": "#A6423A", // unused
"red-40": "#C1554D",
"red-30": "#D07D77",
"red-20": "#E5B7B3", // unused
"red-10": "#F2DBD9", // unused
"red-5": "#FAF1F0",
// MISC
"code-block": "#99a1b30f", // gray-30 @ 6%
"gradient-blue": "#58C4DC", // Only used for the landing gradient for now.
github: {
highlight: "#fffbdd",
},
};

View File

@@ -0,0 +1,335 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import { parse, ParserPlugin } from "@babel/parser";
import traverse, { NodePath } from "@babel/traverse";
import * as t from "@babel/types";
import {
CompilerError,
CompilerErrorDetail,
Effect,
ErrorSeverity,
parseConfigPragma,
printHIR,
printReactiveFunction,
run,
ValueKind,
type Hook,
} from "babel-plugin-react-compiler/src";
import { type ReactFunctionType } from "babel-plugin-react-compiler/src/HIR/Environment";
import clsx from "clsx";
import invariant from "invariant";
import { useSnackbar } from "notistack";
import { useDeferredValue, useMemo } from "react";
import { useMountEffect } from "../../hooks";
import { defaultStore } from "../../lib/defaultStore";
import {
createMessage,
initStoreFromUrlOrLocalStorage,
MessageLevel,
MessageSource,
type Store,
} from "../../lib/stores";
import { useStore, useStoreDispatch } from "../StoreContext";
import Input from "./Input";
import {
CompilerOutput,
default as Output,
PrintedCompilerPipelineValue,
} from "./Output";
function parseFunctions(
source: string
): Array<
NodePath<
t.FunctionDeclaration | t.ArrowFunctionExpression | t.FunctionExpression
>
> {
const items: Array<
NodePath<
t.FunctionDeclaration | t.ArrowFunctionExpression | t.FunctionExpression
>
> = [];
try {
const isFlow = source
.trim()
.split("\n", 1)[0]
.match(/\s*\/\/\s*\@flow\s*/);
let type_transform: ParserPlugin;
if (isFlow) {
type_transform = "flow";
} else {
type_transform = "typescript";
}
const ast = parse(source, {
plugins: [type_transform, "jsx"],
sourceType: "module",
});
traverse(ast, {
FunctionDeclaration(nodePath) {
items.push(nodePath);
nodePath.skip();
},
ArrowFunctionExpression(nodePath) {
items.push(nodePath);
nodePath.skip();
},
FunctionExpression(nodePath) {
items.push(nodePath);
nodePath.skip();
},
});
} catch (e) {
console.error(e);
CompilerError.throwInvalidJS({
reason: String(e),
description: null,
loc: null,
suggestions: null,
});
}
return items;
}
const COMMON_HOOKS: Array<[string, Hook]> = [
[
"useFragment",
{
valueKind: ValueKind.Frozen,
effectKind: Effect.Freeze,
noAlias: true,
transitiveMixedData: true,
},
],
[
"usePaginationFragment",
{
valueKind: ValueKind.Frozen,
effectKind: Effect.Freeze,
noAlias: true,
transitiveMixedData: true,
},
],
[
"useRefetchableFragment",
{
valueKind: ValueKind.Frozen,
effectKind: Effect.Freeze,
noAlias: true,
transitiveMixedData: true,
},
],
[
"useLazyLoadQuery",
{
valueKind: ValueKind.Frozen,
effectKind: Effect.Freeze,
noAlias: true,
transitiveMixedData: true,
},
],
[
"usePreloadedQuery",
{
valueKind: ValueKind.Frozen,
effectKind: Effect.Freeze,
noAlias: true,
transitiveMixedData: true,
},
],
];
function isHookName(s: string): boolean {
return /^use[A-Z0-9]/.test(s);
}
function getReactFunctionType(
id: NodePath<t.Identifier | null | undefined>
): ReactFunctionType {
if (id && id.node && id.isIdentifier()) {
if (isHookName(id.node.name)) {
return "Hook";
}
const isPascalCaseNameSpace = /^[A-Z].*/;
if (isPascalCaseNameSpace.test(id.node.name)) {
return "Component";
}
}
return "Other";
}
function compile(source: string): CompilerOutput {
const results = new Map<string, PrintedCompilerPipelineValue[]>();
const error = new CompilerError();
const upsert = (result: PrintedCompilerPipelineValue) => {
const entry = results.get(result.name);
if (Array.isArray(entry)) {
entry.push(result);
} else {
results.set(result.name, [result]);
}
};
try {
// Extract the first line to quickly check for custom test directives
const pragma = source.substring(0, source.indexOf("\n"));
const config = parseConfigPragma(pragma);
for (const fn of parseFunctions(source)) {
if (!fn.isFunctionDeclaration()) {
error.pushErrorDetail(
new CompilerErrorDetail({
reason: `Unexpected function type ${fn.node.type}`,
description:
"Playground only supports parsing function declarations",
severity: ErrorSeverity.Todo,
loc: fn.node.loc ?? null,
suggestions: null,
})
);
continue;
}
const id = fn.get("id");
for (const result of run(
fn,
{
...config,
customHooks: new Map([...COMMON_HOOKS]),
},
getReactFunctionType(id),
"_c",
null,
null,
null
)) {
const fnName = fn.node.id?.name ?? null;
switch (result.kind) {
case "ast": {
upsert({
kind: "ast",
fnName,
name: result.name,
value: {
type: "FunctionDeclaration",
id: result.value.id,
async: result.value.async,
generator: result.value.generator,
body: result.value.body,
params: result.value.params,
},
});
break;
}
case "hir": {
upsert({
kind: "hir",
fnName,
name: result.name,
value: printHIR(result.value.body),
});
break;
}
case "reactive": {
upsert({
kind: "reactive",
fnName,
name: result.name,
value: printReactiveFunction(result.value),
});
break;
}
case "debug": {
upsert({
kind: "debug",
fnName,
name: result.name,
value: result.value,
});
break;
}
default: {
const _: never = result;
throw new Error(`Unhandled result ${result}`);
}
}
}
}
} catch (err) {
// error might be an invariant violation or other runtime error
// (i.e. object shape that is not CompilerError)
if (err instanceof CompilerError && err.details.length > 0) {
error.details.push(...err.details);
} else {
// Handle unexpected failures by logging (to get a stack trace)
// and reporting
console.error(err);
error.details.push(
new CompilerErrorDetail({
severity: ErrorSeverity.Invariant,
reason: `Unexpected failure when transforming input! ${err}`,
loc: null,
suggestions: null,
})
);
}
}
if (error.hasErrors()) {
return { kind: "err", results, error: error };
}
return { kind: "ok", results };
}
export default function Editor() {
const store = useStore();
const deferredStore = useDeferredValue(store);
const dispatchStore = useStoreDispatch();
const { enqueueSnackbar } = useSnackbar();
const compilerOutput = useMemo(
() => compile(deferredStore.source),
[deferredStore.source]
);
useMountEffect(() => {
let mountStore: Store;
try {
mountStore = initStoreFromUrlOrLocalStorage();
} catch (e) {
invariant(e instanceof Error, "Only Error may be caught.");
enqueueSnackbar(e.message, {
variant: "message",
...createMessage(
"Bad URL - fell back to the default Playground.",
MessageLevel.Info,
MessageSource.Playground
),
});
mountStore = defaultStore;
}
dispatchStore({
type: "setStore",
payload: { store: mountStore },
});
});
return (
<>
<div className="relative flex basis top-14">
<div className={clsx("relative sm:basis-1/4")}>
<Input
errors={
compilerOutput.kind === "err" ? compilerOutput.error.details : []
}
/>
</div>
<div className={clsx("flex sm:flex flex-wrap")}>
<Output store={deferredStore} compilerOutput={compilerOutput} />
</div>
</div>
</>
);
}

View File

@@ -0,0 +1,127 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import MonacoEditor, { loader, type Monaco } from "@monaco-editor/react";
import { CompilerErrorDetail } from "babel-plugin-react-compiler/src";
import invariant from "invariant";
import type { editor } from "monaco-editor";
import * as monaco from "monaco-editor";
import { Resizable } from "re-resizable";
import { useEffect, useState } from "react";
import { renderReactCompilerMarkers } from "../../lib/reactCompilerMonacoDiagnostics";
import { useStore, useStoreDispatch } from "../StoreContext";
import { monacoOptions } from "./monacoOptions";
// TODO: Make TS recognize .d.ts files, in addition to loading them with webpack.
// @ts-ignore
import React$Types from "../../node_modules/@types/react/index.d.ts";
loader.config({ monaco });
type Props = {
errors: CompilerErrorDetail[];
};
export default function Input({ errors }: Props) {
const [monaco, setMonaco] = useState<Monaco | null>(null);
const store = useStore();
const dispatchStore = useStoreDispatch();
// Set tab width to 2 spaces for the selected input file.
useEffect(() => {
if (!monaco) return;
const uri = monaco.Uri.parse(`file:///index.js`);
const model = monaco.editor.getModel(uri);
invariant(model, "Model must exist for the selected input file.");
renderReactCompilerMarkers({ monaco, model, details: errors });
// N.B. that `tabSize` is a model property, not an editor property.
// So, the tab size has to be set per model.
model.updateOptions({ tabSize: 2 });
}, [monaco, errors]);
const handleChange = (value: string | undefined) => {
if (!value) return;
dispatchStore({
type: "updateFile",
payload: {
source: value,
},
});
};
const handleMount = (_: editor.IStandaloneCodeEditor, monaco: Monaco) => {
setMonaco(monaco);
// Ignore "can only be used in TypeScript files." errors, since
// we want to support syntax highlighting for Flow (*.js) files
// and Flow is not a built-in language.
monaco.languages.typescript.javascriptDefaults.setDiagnosticsOptions({
diagnosticCodesToIgnore: [
8002, 8003, 8004, 8005, 8006, 8008, 8009, 8010, 8011, 8012, 8013,
],
noSemanticValidation: true,
noSyntaxValidation: false,
});
const tscOptions = {
allowNonTsExtensions: true,
target: monaco.languages.typescript.ScriptTarget.ES2015,
moduleResolution: monaco.languages.typescript.ModuleResolutionKind.NodeJs,
jsx: monaco.languages.typescript.JsxEmit.Preserve,
typeRoots: ["node_modules/@types"],
allowSyntheticDefaultImports: true,
};
monaco.languages.typescript.javascriptDefaults.setCompilerOptions(
tscOptions
);
monaco.languages.typescript.typescriptDefaults.setCompilerOptions({
...tscOptions,
checkJs: true,
allowJs: true,
});
// Add React type declarations to Monaco
const reactLib = [
React$Types,
"file:///node_modules/@types/react/index.d.ts",
] as [any, string];
monaco.languages.typescript.javascriptDefaults.addExtraLib(...reactLib);
monaco.languages.typescript.typescriptDefaults.addExtraLib(...reactLib);
// Remeasure the font in case the custom font is loaded only after
// Monaco Editor is mounted.
// N.B. that this applies also to the output editor as it seems
// Monaco Editor instances share the same font config.
document.fonts.ready.then(() => {
monaco.editor.remeasureFonts();
});
};
return (
<div className="relative flex flex-col flex-none border-r border-gray-200">
<Resizable
minWidth={650}
enable={{ right: true }}
// Restrict MonacoEditor's height, since the config autoLayout:true
// will grow the editor to fit within parent element
className="!h-[calc(100vh_-_3.5rem)]"
>
<MonacoEditor
path={"index.js"}
// .js and .jsx files are specified to be TS so that Monaco can actually
// check their syntax using its TS language service. They are still JS files
// due to their extensions, so TS language features don't work.
language={"javascript"}
value={store.source}
onMount={handleMount}
onChange={handleChange}
options={monacoOptions}
/>
</Resizable>
</div>
);
}

View File

@@ -0,0 +1,306 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import generate from "@babel/generator";
import * as t from "@babel/types";
import {
CodeIcon,
DocumentAddIcon,
InformationCircleIcon,
} from "@heroicons/react/outline";
import MonacoEditor, { DiffEditor } from "@monaco-editor/react";
import { type CompilerError } from "babel-plugin-react-compiler/src";
import parserBabel from "prettier/plugins/babel";
import * as prettierPluginEstree from "prettier/plugins/estree";
import * as prettier from "prettier/standalone";
import { memo, useEffect, useState } from "react";
import { type Store } from "../../lib/stores";
import TabbedWindow from "../TabbedWindow";
import { monacoOptions } from "./monacoOptions";
const MemoizedOutput = memo(Output);
export default MemoizedOutput;
export type PrintedCompilerPipelineValue =
| {
kind: "ast";
name: string;
fnName: string | null;
value: t.FunctionDeclaration;
}
| {
kind: "hir";
name: string;
fnName: string | null;
value: string;
}
| { kind: "reactive"; name: string; fnName: string | null; value: string }
| { kind: "debug"; name: string; fnName: string | null; value: string };
export type CompilerOutput =
| { kind: "ok"; results: Map<string, PrintedCompilerPipelineValue[]> }
| {
kind: "err";
results: Map<string, PrintedCompilerPipelineValue[]>;
error: CompilerError;
};
type Props = {
store: Store;
compilerOutput: CompilerOutput;
};
async function tabify(source: string, compilerOutput: CompilerOutput) {
const tabs = new Map<string, React.ReactNode>();
const reorderedTabs = new Map<string, React.ReactNode>();
const concattedResults = new Map<string, string>();
let topLevelFnDecls: Array<t.FunctionDeclaration> = [];
// Concat all top level function declaration results into a single tab for each pass
for (const [passName, results] of compilerOutput.results) {
for (const result of results) {
switch (result.kind) {
case "hir": {
const prev = concattedResults.get(result.name);
const next = result.value;
const identName = `function ${result.fnName}`;
if (prev != null) {
concattedResults.set(passName, `${prev}\n\n${identName}\n${next}`);
} else {
concattedResults.set(passName, `${identName}\n${next}`);
}
break;
}
case "reactive": {
const prev = concattedResults.get(passName);
const next = result.value;
if (prev != null) {
concattedResults.set(passName, `${prev}\n\n${next}`);
} else {
concattedResults.set(passName, next);
}
break;
}
case "ast":
topLevelFnDecls.push(result.value);
break;
case "debug": {
concattedResults.set(passName, result.value);
break;
}
default: {
const _: never = result;
throw new Error("Unexpected result kind");
}
}
}
}
let lastPassOutput: string | null = null;
for (const [passName, text] of concattedResults) {
tabs.set(
passName,
<TextTabContent
output={text}
diff={passName !== "HIR" ? lastPassOutput : null}
showInfoPanel={true}
></TextTabContent>
);
lastPassOutput = text;
}
// Ensure that JS and the JS source map come first
if (topLevelFnDecls.length > 0) {
// Make a synthetic Program so we can have a single AST with all the top level
// FunctionDeclarations
const ast = t.program(topLevelFnDecls);
const { code, sourceMapUrl } = await codegen(ast, source);
reorderedTabs.set(
"JS",
<TextTabContent
output={code}
diff={null}
showInfoPanel={false}
></TextTabContent>
);
if (sourceMapUrl) {
reorderedTabs.set(
"SourceMap",
<>
<iframe
src={sourceMapUrl}
className="w-full h-monaco_small sm:h-monaco"
title="Generated Code"
/>
</>
);
}
}
tabs.forEach((tab, name) => {
reorderedTabs.set(name, tab);
});
return reorderedTabs;
}
async function codegen(
ast: t.Program,
source: string
): Promise<{ code: any; sourceMapUrl: string | null }> {
const generated = generate(
ast,
{ sourceMaps: true, sourceFileName: "input.js" },
source
);
const sourceMapUrl = getSourceMapUrl(
generated.code,
JSON.stringify(generated.map)
);
const codegenOutput = await prettier.format(generated.code, {
semi: true,
parser: "babel",
plugins: [parserBabel, prettierPluginEstree],
});
return { code: codegenOutput, sourceMapUrl };
}
function utf16ToUTF8(s: string): string {
return unescape(encodeURIComponent(s));
}
function getSourceMapUrl(code: string, map: string): string | null {
code = utf16ToUTF8(code);
map = utf16ToUTF8(map);
return `https://evanw.github.io/source-map-visualization/#${btoa(
`${code.length}\0${code}${map.length}\0${map}`
)}`;
}
function Output({ store, compilerOutput }: Props) {
const [tabsOpen, setTabsOpen] = useState<Set<string>>(() => new Set(["JS"]));
const [tabs, setTabs] = useState<Map<string, React.ReactNode>>(
() => new Map()
);
useEffect(() => {
tabify(store.source, compilerOutput).then((tabs) => {
setTabs(tabs);
});
}, [store.source, compilerOutput]);
const changedPasses: Set<string> = new Set();
let lastResult: string = "";
for (const [passName, results] of compilerOutput.results) {
for (const result of results) {
let currResult = "";
if (result.kind === "hir" || result.kind === "reactive") {
currResult += `function ${result.fnName}\n\n${result.value}`;
}
if (passName !== "HIR" && currResult !== lastResult) {
changedPasses.add(passName);
}
lastResult = currResult;
}
}
return (
<>
<TabbedWindow
defaultTab="HIR"
setTabsOpen={setTabsOpen}
tabsOpen={tabsOpen}
tabs={tabs}
changedPasses={changedPasses}
/>
{compilerOutput.kind === "err" ? (
<div
className="flex flex-wrap absolute bottom-0 bg-white grow border-y border-grey-200 transition-all ease-in"
style={{ width: "calc(100vw - 650px)" }}
>
<div className="w-full p-4 basis-full border-b">
<h2>COMPILER ERRORS</h2>
</div>
<pre
className="p-4 basis-full text-red-600 overflow-y-scroll whitespace-pre-wrap"
style={{ width: "calc(100vw - 650px)", height: "150px" }}
>
<code>{compilerOutput.error.toString()}</code>
</pre>
</div>
) : null}
</>
);
}
function TextTabContent({
output,
diff,
showInfoPanel,
}: {
output: string;
diff: string | null;
showInfoPanel: boolean;
}) {
const [diffMode, setDiffMode] = useState(false);
return (
// Restrict MonacoEditor's height, since the config autoLayout:true
// will grow the editor to fit within parent element
<div className="w-full h-monaco_small sm:h-monaco">
{showInfoPanel ? (
<div className="flex items-center gap-1 bg-amber-50 p-2">
{diff != null && output !== diff ? (
<button
className="flex items-center gap-1 transition-colors duration-150 ease-in text-secondary hover:text-link"
onClick={() => setDiffMode((diffMode) => !diffMode)}
>
{!diffMode ? (
<>
<DocumentAddIcon className="w-5 h-5" /> Show Diff
</>
) : (
<>
<CodeIcon className="w-5 h-5" /> Show Output
</>
)}
</button>
) : (
<>
<span className="flex items-center gap-1">
<InformationCircleIcon className="w-5 h-5" /> No changes from
previous pass
</span>
</>
)}
</div>
) : null}
{diff != null && diffMode ? (
<DiffEditor
original={diff}
modified={output}
options={{
...monacoOptions,
readOnly: true,
lineNumbers: "off",
glyphMargin: false,
// Undocumented see https://github.com/Microsoft/vscode/issues/30795#issuecomment-410998882
lineDecorationsWidth: 0,
lineNumbersMinChars: 0,
}}
/>
) : (
<MonacoEditor
defaultLanguage="javascript"
value={output}
options={{
...monacoOptions,
readOnly: true,
lineNumbers: "off",
glyphMargin: false,
// Undocumented see https://github.com/Microsoft/vscode/issues/30795#issuecomment-410998882
lineDecorationsWidth: 0,
lineNumbersMinChars: 0,
}}
/>
)}
</div>
);
}

View File

@@ -0,0 +1,16 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import dynamic from "next/dynamic";
// monaco-editor is currently not compatible with ssr
// https://github.com/vercel/next.js/issues/31692
const Editor = dynamic(() => import("./EditorImpl"), {
ssr: false,
});
export default Editor;

View File

@@ -0,0 +1,32 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import type { EditorProps } from "@monaco-editor/react";
export const monacoOptions: Partial<EditorProps["options"]> = {
fontSize: 14,
padding: { top: 8 },
scrollbar: {
verticalScrollbarSize: 10,
alwaysConsumeMouseWheel: false,
},
minimap: {
enabled: false,
},
formatOnPaste: true,
formatOnType: true,
fontFamily: '"Source Code Pro", monospace',
glyphMargin: true,
autoClosingBrackets: "languageDefined",
autoClosingDelete: "always",
autoClosingOvertype: "always",
automaticLayout: true,
wordWrap: "on",
wrappingIndent: "deepIndent",
};

View File

@@ -0,0 +1,94 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import { RefreshIcon, ShareIcon } from "@heroicons/react/outline";
import { CheckIcon } from "@heroicons/react/solid";
import clsx from "clsx";
import Link from "next/link";
import { useSnackbar } from "notistack";
import { useState } from "react";
import { defaultStore } from "../lib/defaultStore";
import { IconGitHub } from "./Icons/IconGitHub";
import Logo from "./Logo";
import { useStoreDispatch } from "./StoreContext";
export default function Header() {
const [showCheck, setShowCheck] = useState(false);
const dispatchStore = useStoreDispatch();
const { enqueueSnackbar, closeSnackbar } = useSnackbar();
const handleReset = () => {
if (confirm("Are you sure you want to reset the playground?")) {
/*
Close open snackbars if any. This is necessary because when displaying
outputs (Preview or not), we only close previous snackbars if we received
new messages, which is needed in order to display "Bad URL" or success
messages when loading Playground for the first time. Otherwise, messages
such as "Bad URL" will be closed by the outputs calling `closeSnackbar`.
*/
closeSnackbar();
dispatchStore({ type: "setStore", payload: { store: defaultStore } });
}
};
const handleShare = () => {
navigator.clipboard.writeText(location.href).then(() => {
enqueueSnackbar("URL copied to clipboard");
setShowCheck(true);
// Show the check mark icon briefly after URL is copied
setTimeout(() => setShowCheck(false), 1000);
});
};
return (
<div className="fixed z-10 flex items-center justify-between w-screen px-5 py-3 bg-white border-b border-gray-200 h-14">
<div className="flex items-center flex-none h-full gap-2 text-lg">
<Logo
className={clsx(
"w-8 h-8 text-link",
process.env.NODE_ENV === "development" && "text-yellow-600"
)}
/>
<p className="hidden select-none sm:block">React Compiler Playground</p>
</div>
<div className="flex items-center text-[15px] gap-4">
<button
title="Reset Playground"
aria-label="Reset Playground"
className="flex items-center gap-1 transition-colors duration-150 ease-in text-secondary hover:text-link"
onClick={handleReset}
>
<RefreshIcon className="w-5 h-5" />
<p className="hidden sm:block">Reset</p>
</button>
<button
title="Copy sharable URL"
aria-label="Copy sharable URL"
className="flex items-center gap-1 transition-colors duration-150 ease-in text-secondary hover:text-link"
onClick={handleShare}
disabled={showCheck}
>
{!showCheck ? (
<ShareIcon className="w-5 h-5" />
) : (
<CheckIcon className="w-5 h-5 fill-blue-50" />
)}
<p className="hidden sm:block">Share</p>
</button>
<Link
href="https://github.com/facebook/react"
target="_blank"
rel="noreferrer noopener"
aria-label="Open on GitHub"
className="flex items-center gap-1 transition-colors duration-150 ease-in text-secondary hover:text-link"
>
<IconGitHub />
</Link>
</div>
</div>
);
}

View File

@@ -0,0 +1,25 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import { memo } from "react";
export const IconGitHub = memo<JSX.IntrinsicElements["svg"]>(
function IconGitHub(props) {
return (
<svg
xmlns="http://www.w3.org/2000/svg"
width="1.5em"
height="1.5em"
viewBox="0 -2 24 24"
fill="currentColor"
{...props}
>
<path d="M10 0a10 10 0 0 0-3.16 19.49c.5.1.68-.22.68-.48l-.01-1.7c-2.78.6-3.37-1.34-3.37-1.34-.46-1.16-1.11-1.47-1.11-1.47-.9-.62.07-.6.07-.6 1 .07 1.53 1.03 1.53 1.03.9 1.52 2.34 1.08 2.91.83.1-.65.35-1.09.63-1.34-2.22-.25-4.55-1.11-4.55-4.94 0-1.1.39-1.99 1.03-2.69a3.6 3.6 0 0 1 .1-2.64s.84-.27 2.75 1.02a9.58 9.58 0 0 1 5 0c1.91-1.3 2.75-1.02 2.75-1.02.55 1.37.2 2.4.1 2.64.64.7 1.03 1.6 1.03 2.69 0 3.84-2.34 4.68-4.57 4.93.36.31.68.92.68 1.85l-.01 2.75c0 .26.18.58.69.48A10 10 0 0 0 10 0"></path>
</svg>
);
}
);

View File

@@ -0,0 +1,28 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
// https://github.com/reactjs/reactjs.org/blob/main/beta/src/components/Logo.tsx
export default function Logo(props: JSX.IntrinsicElements["svg"]) {
return (
<svg
viewBox="0 0 410 369"
fill="none"
xmlns="http://www.w3.org/2000/svg"
{...props}
>
<path
d="M204.995 224.552C226.56 224.552 244.042 207.07 244.042 185.506C244.042 163.941 226.56 146.459 204.995 146.459C183.43 146.459 165.948 163.941 165.948 185.506C165.948 207.07 183.43 224.552 204.995 224.552Z"
fill="currentColor"
/>
<path
d="M409.99 184.505C409.99 153.707 381.437 126.667 335.996 108.925C343.342 60.6535 334.19 22.3878 307.492 6.98883C283.649 -6.77511 250.631 -0.0395641 214.512 25.9753C211.316 28.2692 208.143 30.7097 204.97 33.2477C201.822 30.7097 198.65 28.2692 195.477 25.9753C159.359 -0.0395641 126.34 -6.79951 102.497 6.98883C75.8237 22.3878 66.6721 60.6291 74.0422 108.852C28.5529 126.618 0 153.682 0 184.505C0 215.303 28.5528 242.342 73.9934 260.084C66.6477 308.356 75.7993 346.621 102.497 362.02C110.575 366.682 119.727 369 129.684 369C149.085 369 171.61 360.215 195.477 343.034C198.674 340.74 201.847 338.3 205.019 335.762C208.167 338.3 211.34 340.74 214.512 343.034C238.38 360.239 260.905 369 280.306 369C290.263 369 299.415 366.682 307.492 362.02C331.335 348.256 342 316.287 337.534 271.993C337.143 268.089 336.631 264.135 335.996 260.109C381.461 242.367 409.99 215.327 409.99 184.505ZM225.934 41.8136C246.238 27.1955 265.127 19.5814 280.306 19.5814C286.871 19.5814 292.728 20.9968 297.731 23.8765C315.204 33.9798 322.672 62.9475 317.327 102.433C299.756 97.0401 280.306 92.9158 259.392 90.2802C246.872 73.8074 233.597 58.9453 220.003 46.2551C221.98 44.7421 223.957 43.229 225.934 41.8136ZM112.259 23.8765C117.262 20.9968 123.119 19.5814 129.684 19.5814C144.863 19.5814 163.752 27.1711 184.056 41.8136C186.033 43.229 188.01 44.7176 189.986 46.2551C176.393 58.9453 163.142 73.783 150.622 90.2558C129.732 92.8914 110.258 97.0401 92.687 102.409C87.3424 62.9475 94.7857 33.9798 112.259 23.8765ZM19.5233 184.505C19.5233 164.322 40.9014 143.359 77.776 128.253C81.9003 146.141 88.0502 165.054 96.1768 184.456C88.0014 203.881 81.8515 222.819 77.7272 240.732C40.9014 225.626 19.5233 204.687 19.5233 184.505ZM184.056 327.196C154.966 348.134 128.805 354.675 112.259 345.133C94.7857 335.029 87.3181 306.062 92.6626 266.576C110.234 271.969 129.684 276.093 150.598 278.729C163.117 295.202 176.393 310.064 189.986 322.754C188.01 324.292 186.033 325.78 184.056 327.196ZM204.995 310.04C180.591 287.685 157.138 257.815 137.347 223.551C132.051 214.4 121.344 191.396 117 182.489C113.535 190.786 110.112 198.398 107.427 206.5C109.623 210.575 118.092 229.213 120.434 233.288C125.071 241.317 129.928 249.127 134.931 256.692C120.898 254.227 107.915 251.055 96.1035 247.321C102.815 217.011 116.213 182.064 137.347 145.458C142.545 136.453 153.838 116.346 159.5 108C150.568 109.147 143.395 108.767 135 110.5C132.56 114.453 122.777 131.645 120.434 135.721C115.749 143.823 111.454 151.925 107.427 159.978C102.546 146.581 98.8124 133.744 96.1524 121.64C125.755 112.293 162.727 106.411 204.995 106.411C215.562 106.411 237.63 106.197 247.49 106.905C242.048 99.7544 237.38 93.2819 231.694 86.888C227.082 86.7416 209.705 86.888 204.995 86.888C195.672 86.888 186.545 87.2053 177.589 87.7422C186.472 77.1752 195.672 67.5111 204.995 58.9697C229.375 81.3239 252.851 111.195 272.643 145.458C277.841 154.463 289.073 175.426 293.49 184.505C296.98 176.207 300.281 168.64 302.99 160.489C300.793 156.389 291.898 139.747 289.555 135.696C284.918 127.667 280.062 119.858 275.059 112.317C289.092 114.782 302.075 117.954 313.886 121.688C307.175 151.998 293.777 186.945 272.643 223.551C267.445 232.556 252.651 253.178 246.99 261.524C255.922 260.377 265.595 258.663 273.99 256.93C276.43 252.976 287.212 237.364 289.555 233.288C294.216 225.235 298.512 217.182 302.489 209.153C307.224 222.185 310.982 234.997 313.715 247.394C284.138 256.741 247.214 262.598 204.995 262.598C194.428 262.598 169.859 261.208 160 260.5C165.442 267.65 171.304 275.095 176.99 281.489C181.602 281.635 200.285 282.121 204.995 282.121C214.317 282.121 223.444 281.804 232.401 281.267C223.493 291.834 214.317 301.498 204.995 310.04ZM297.731 345.133C281.185 354.699 254.999 348.159 225.934 327.196C223.957 325.78 221.98 324.292 220.003 322.754C233.597 310.064 246.848 295.226 259.367 278.753C280.233 276.118 299.659 271.993 317.205 266.625C317.547 269.089 317.888 271.554 318.132 273.97C321.72 309.649 314.277 335.566 297.731 345.133ZM332.262 240.756C328.065 222.599 321.842 203.686 313.813 184.578C321.988 165.152 328.138 146.215 332.262 128.302C369.088 143.408 390.466 164.322 390.466 184.505C390.466 204.687 369.113 225.626 332.262 240.756Z"
fill="currentColor"
/>
</svg>
);
}

View File

@@ -0,0 +1,84 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import {
BanIcon,
ExclamationIcon,
InformationCircleIcon,
XIcon,
} from "@heroicons/react/solid";
import { CustomContentProps, SnackbarContent, useSnackbar } from "notistack";
import { forwardRef } from "react";
import { MessageLevel, MessageSource } from "../lib/stores";
// https://notistack.com/examples/advanced/custom-component#custom-variant-(typescript)
declare module "notistack" {
interface VariantOverrides {
message: {
title: string;
level: MessageLevel;
codeframe: string | undefined;
};
}
}
interface MessageProps extends CustomContentProps {
title: string;
level: MessageLevel;
source: MessageSource;
codeframe: string | undefined;
}
const Message = forwardRef<HTMLDivElement, MessageProps>(
({ id, title, level, source, codeframe }, ref) => {
const { closeSnackbar } = useSnackbar();
const isDismissible = source !== MessageSource.Playground;
return (
<SnackbarContent
ref={ref}
className="flex items-start justify-between gap-3 px-4 py-3 text-sm bg-white border rounded-md shadow w-toast"
>
<div className="flex gap-3 w-toast-body">
{level === MessageLevel.Warning ? (
<div className="flex items-center justify-center flex-none rounded-md w-7 h-7 bg-amber-100">
<ExclamationIcon className="w-5 h-5 text-amber-600" />
</div>
) : level === MessageLevel.Error ? (
<div className="flex items-center justify-center flex-none bg-red-100 rounded-md w-7 h-7">
<BanIcon className="w-5 h-5 text-red-600" />
</div>
) : (
<div className="flex items-center justify-center flex-none rounded-md bg-sky-100 w-7 h-7">
<InformationCircleIcon className="w-5 h-5 text-sky-600" />
</div>
)}
<div className="flex flex-col justify-center gap-1 w-toast-title">
<p className="w-full">{title}</p>
{codeframe ? (
<pre className="overflow-x-auto break-words whitespace-pre-wrap">
<code className="text-xs">{codeframe}</code>
</pre>
) : null}
</div>
</div>
{isDismissible ? (
<button
className="flex items-center justify-center flex-none transition-colors duration-150 ease-in rounded-md justify-self-end group w-7 h-7 hover:bg-gray-200"
onClick={() => closeSnackbar(id)}
>
<XIcon className="w-5 h-5 fill-gray-500 group-hover:fill-gray-800" />
</button>
) : null}
</SnackbarContent>
);
}
);
Message.displayName = "MessageComponent";
export default Message;

View File

@@ -0,0 +1,78 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import type { Dispatch, ReactNode } from "react";
import { useReducer } from "react";
import createContext from "../lib/createContext";
import { emptyStore } from "../lib/defaultStore";
import type { Store } from "../lib/stores";
import { saveStore } from "../lib/stores";
const StoreContext = createContext<Store>();
/**
* Hook to access the store.
*/
export const useStore = StoreContext.useContext;
const StoreDispatchContext = createContext<Dispatch<ReducerAction>>();
/**
* Hook to access the store dispatch function.
*/
export const useStoreDispatch = StoreDispatchContext.useContext;
/**
* Make Store and dispatch function available to all sub-components in children.
*/
export function StoreProvider({ children }: { children: ReactNode }) {
const [store, dispatch] = useReducer(storeReducer, emptyStore);
return (
<StoreContext.Provider value={store}>
<StoreDispatchContext.Provider value={dispatch}>
{children}
</StoreDispatchContext.Provider>
</StoreContext.Provider>
);
}
type ReducerAction =
| {
type: "setStore";
payload: {
store: Store;
};
}
| {
type: "updateFile";
payload: {
source: string;
};
};
function storeReducer(store: Store, action: ReducerAction): Store {
switch (action.type) {
case "setStore": {
const newStore = action.payload.store;
saveStore(newStore);
return newStore;
}
case "updateFile": {
const { source } = action.payload;
const newStore = {
...store,
source,
};
saveStore(newStore);
return newStore;
}
}
}

View File

@@ -0,0 +1,106 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import { Resizable } from "re-resizable";
import React, { useCallback } from "react";
type TabsRecord = Map<string, React.ReactNode>;
export default function TabbedWindow(props: {
defaultTab: string | null;
tabs: TabsRecord;
tabsOpen: Set<string>;
setTabsOpen: (newTab: Set<string>) => void;
changedPasses: Set<string>;
}): React.ReactElement {
if (props.tabs.size === 0) {
return (
<div
className="flex items-center justify-center"
style={{ width: "calc(100vw - 650px)" }}
>
No compiler output detected, see errors below
</div>
);
}
return (
<div className="flex flex-row">
{Array.from(props.tabs.keys()).map((name) => {
return (
<TabbedWindowItem
name={name}
key={name}
tabs={props.tabs}
tabsOpen={props.tabsOpen}
setTabsOpen={props.setTabsOpen}
hasChanged={props.changedPasses.has(name)}
/>
);
})}
</div>
);
}
function TabbedWindowItem({
name,
tabs,
tabsOpen,
setTabsOpen,
hasChanged,
}: {
name: string;
tabs: TabsRecord;
tabsOpen: Set<string>;
setTabsOpen: (newTab: Set<string>) => void;
hasChanged: boolean;
}): React.ReactElement {
const isShow = tabsOpen.has(name);
const toggleTabs = useCallback(() => {
const nextState = new Set(tabsOpen);
if (nextState.has(name)) {
nextState.delete(name);
} else {
nextState.add(name);
}
setTabsOpen(nextState);
}, [tabsOpen, name, setTabsOpen]);
return (
<div key={name} className="flex flex-row">
{isShow ? (
<Resizable className="border-r" minWidth={550} enable={{ right: true }}>
<h2
title="Minimize tab"
aria-label="Minimize tab"
onClick={toggleTabs}
className={`p-4 duration-150 ease-in border-b cursor-pointer border-grey-200 ${
hasChanged ? "font-bold" : "font-light"
} text-secondary hover:text-link`}
>
- {name}
</h2>
{tabs.get(name) ?? <div>No output for {name}</div>}
</Resizable>
) : (
<div className="relative items-center h-full px-1 py-6 align-middle border-r border-grey-200">
<button
title={`Expand compiler tab: ${name}`}
aria-label={`Expand compiler tab: ${name}`}
style={{ transform: "rotate(90deg) translate(-50%)" }}
onClick={toggleTabs}
className={`flex-grow-0 w-5 transition-colors duration-150 ease-in ${
hasChanged ? "font-bold" : "font-light"
} text-secondary hover:text-link`}
>
{name}
</button>
</div>
)}
</div>
);
}

View File

@@ -0,0 +1,10 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
export { default as Editor } from "./Editor";
export { default as Header } from "./Header";
export { StoreProvider } from "./StoreContext";

View File

@@ -0,0 +1,8 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
export { default as useMountEffect } from "./useMountEffect";

View File

@@ -0,0 +1,13 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import type { EffectCallback } from "react";
import { useEffect } from "react";
export default function useMountEffect(effect: EffectCallback) {
return useEffect(effect, []);
}

View File

@@ -0,0 +1,37 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import React from "react";
/**
* Replacement to React.createContext.
*
* Does not take any default value and avoids non-null assertions when using
* the value of the context, like the following scenario.
*
* ```ts
* const StoreDispatchContext = useContext<Dispatch<ReducerAction>>(null);
* const dispatchStore = useContext(StoreDispatchContext);
* ...
* dipatchStore!({ ... });
* ```
*
* Instead, it throws an error when `useContext` is not called within a
* Provider with a value.
*/
export default function createContext<T>() {
const context = React.createContext<T | null>(null);
function useContext() {
const c = React.useContext(context);
if (!c)
throw new Error("useContext must be within a Provider with a value");
return c;
}
return { useContext, Provider: context.Provider };
}

View File

@@ -0,0 +1,22 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import type { Store } from "./stores";
const index = `\
export default function MyApp() {
return <div>Hello World</div>;
}
`;
export const defaultStore: Store = {
source: index,
};
export const emptyStore: Store = {
source: "",
};

View File

@@ -0,0 +1,89 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import { Monaco } from "@monaco-editor/react";
import {
CompilerErrorDetail,
ErrorSeverity,
} from "babel-plugin-react-compiler/src";
import { MarkerSeverity, type editor } from "monaco-editor";
function mapReactCompilerSeverityToMonaco(
level: ErrorSeverity,
monaco: Monaco
): MarkerSeverity {
switch (level) {
case ErrorSeverity.Todo:
return monaco.MarkerSeverity.Warning;
default:
return monaco.MarkerSeverity.Error;
}
}
function mapReactCompilerDiagnosticToMonacoMarker(
detail: CompilerErrorDetail,
monaco: Monaco
): editor.IMarkerData | null {
if (detail.loc == null || typeof detail.loc === "symbol") {
return null;
}
const severity = mapReactCompilerSeverityToMonaco(detail.severity, monaco);
let message = detail.printErrorMessage();
return {
severity,
message,
startLineNumber: detail.loc.start.line,
startColumn: detail.loc.start.column + 1,
endLineNumber: detail.loc.end.line,
endColumn: detail.loc.end.column + 1,
};
}
type ReactCompilerMarkerConfig = {
monaco: Monaco;
model: editor.ITextModel;
details: CompilerErrorDetail[];
};
let decorations: string[] = [];
export function renderReactCompilerMarkers({
monaco,
model,
details,
}: ReactCompilerMarkerConfig): void {
let markers = [];
for (const detail of details) {
const marker = mapReactCompilerDiagnosticToMonacoMarker(detail, monaco);
if (marker == null) {
continue;
}
markers.push(marker);
}
if (markers.length > 0) {
monaco.editor.setModelMarkers(model, "owner", markers);
const newDecorations = markers.map((marker) => {
return {
range: new monaco.Range(
marker.startLineNumber,
marker.startColumn,
marker.endLineNumber,
marker.endColumn
),
options: {
isWholeLine: true,
glyphMarginClassName: "bg-red-300",
},
};
});
decorations = model.deltaDecorations(decorations, newDecorations);
} else {
monaco.editor.setModelMarkers(model, "owner", []);
decorations = model.deltaDecorations(
model.getAllDecorations().map((d) => d.id),
[]
);
}
}

View File

@@ -0,0 +1,9 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
export * from "./messages";
export * from "./store";

View File

@@ -0,0 +1,41 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
export enum MessageSource {
Babel,
Forget,
Playground,
}
export enum MessageLevel {
Info,
Warning,
Error,
}
export interface Message {
title: string;
level: MessageLevel;
source: MessageSource; // Can be used to further style messages differently.
codeframe: string | undefined;
}
export function createMessage(
message: string,
level: MessageLevel,
source: MessageSource
): Message {
const [title, ...body] = message.split("\n");
const codeframe = body.length > 0 ? body.join("\n") : undefined;
return {
source,
level,
title,
codeframe,
};
}

View File

@@ -0,0 +1,67 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import invariant from "invariant";
import {
compressToEncodedURIComponent,
decompressFromEncodedURIComponent,
} from "lz-string";
import { defaultStore } from "../defaultStore";
/**
* Global Store for Playground
*/
export interface Store {
source: string;
}
export function encodeStore(store: Store): string {
return compressToEncodedURIComponent(JSON.stringify(store));
}
export function decodeStore(hash: string): Store {
return JSON.parse(decompressFromEncodedURIComponent(hash));
}
/**
* Serialize, encode, and save @param store to localStorage and update URL.
*/
export function saveStore(store: Store) {
const hash = encodeStore(store);
localStorage.setItem("playgroundStore", hash);
history.replaceState({}, "", `#${hash}`);
}
/**
* Check if @param raw is a valid Store by if
* - it has a `source` property and is a string
*/
function isValidStore(raw: unknown): raw is Store {
return (
raw != null &&
typeof raw == "object" &&
"source" in raw &&
typeof raw["source"] === "string"
);
}
/**
* Deserialize, decode, and initialize @param store from URL and then
* localStorage. Throw an error if Store is malformed.
*/
export function initStoreFromUrlOrLocalStorage(): Store {
const encodedSourceFromUrl = location.hash.slice(1);
const encodedSourceFromLocal = localStorage.getItem("playgroundStore");
const encodedSource = encodedSourceFromUrl || encodedSourceFromLocal;
// No data in the URL and no data in the localStorage to fallback to.
// Initialize with the default store.
if (!encodedSource) return defaultStore;
const raw = decodeStore(encodedSource);
invariant(isValidStore(raw), "Invalid Store");
return raw;
}

View File

@@ -0,0 +1,5 @@
/// <reference types="next" />
/// <reference types="next/image-types/global" />
// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.

View File

@@ -0,0 +1,44 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
const MonacoWebpackPlugin = require("monaco-editor-webpack-plugin");
const path = require("path");
const nextConfig = {
reactStrictMode: true,
webpack: (config, options) => {
// Load *.d.ts files as strings using https://webpack.js.org/guides/asset-modules/#source-assets.
config.module.rules.push({
test: /\.d\.ts/,
type: "asset/source",
});
// Monaco Editor
if (!options.isServer) {
config.plugins.push(
new MonacoWebpackPlugin({
languages: ["typescript", "javascript"],
filename: "static/[name].worker.js",
})
);
}
config.resolve.alias = {
...config.resolve.alias,
"react-compiler-runtime": path.resolve(
__dirname,
"../../packages/react-compiler-runtime"
),
};
return config;
},
transpilePackages: ["monaco-editor"],
};
module.exports = nextConfig;

View File

@@ -0,0 +1,60 @@
{
"name": "playground",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "NODE_ENV=development next dev",
"build": "next build && node ./scripts/downloadFonts.js",
"vercel-build": "yarn workspaces run build",
"start": "next start",
"lint": "next lint",
"test": "playwright test"
},
"dependencies": {
"@babel/core": "^7.19.1",
"@babel/parser": "^7.19.1",
"@babel/plugin-syntax-typescript": "^7.18.6",
"@babel/plugin-transform-block-scoping": "^7.18.9",
"@babel/plugin-transform-modules-commonjs": "^7.18.6",
"@babel/preset-react": "^7.18.6",
"@babel/preset-typescript": "^7.18.6",
"@babel/traverse": "^7.19.1",
"@babel/types": "^7.19.0",
"@heroicons/react": "^1.0.6",
"@monaco-editor/react": "^4.4.6",
"@playwright/test": "^1.42.1",
"@use-gesture/react": "^10.2.22",
"hermes-eslint": "^0.14.0",
"invariant": "^2.2.4",
"lz-string": "^1.5.0",
"monaco-editor": "^0.34.1",
"next": "^13.5.6",
"notistack": "^3.0.0-alpha.7",
"prettier": "3.0.3",
"pretty-format": "^29.3.1",
"re-resizable": "^6.9.16",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-compiler-runtime": "*"
},
"devDependencies": {
"@types/node": "18.11.9",
"@types/prettier": "^2.7.1",
"@types/react": "18.0.25",
"@types/react-dom": "18.0.9",
"autoprefixer": "^10.4.13",
"clsx": "^1.2.1",
"eslint": "^8.28.0",
"eslint-config-next": "^13.5.6",
"monaco-editor-webpack-plugin": "^7.1.0",
"postcss": "^8.4.31",
"tailwindcss": "^3.2.4"
},
"resolutions": {
"./**/@babel/parser": "7.7.4",
"./**/@babel/types": "7.7.4",
"@babel/core": "7.2.0",
"@babel/traverse": "7.1.6",
"@babel/generator": "7.2.0"
}
}

View File

@@ -0,0 +1,84 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import { defineConfig, devices } from "@playwright/test";
import path from "path";
// Use process.env.PORT by default and fallback to port 3000
const PORT = process.env.PORT || 3000;
// Set webServer.url and use.baseURL with the location of the WebServer respecting the correct set port
const baseURL = `http://localhost:${PORT}`;
// Reference: https://playwright.dev/docs/test-configuration
export default defineConfig({
// Timeout per test
timeout: 30 * 1000,
// Test directory
testDir: path.join(__dirname, "__tests__/e2e"),
// If a test fails, retry it additional 2 times
retries: 2,
// Artifacts folder where screenshots, videos, and traces are stored.
outputDir: "test-results/",
// Note: we only use text snapshots, so its safe to omit the host environment name
snapshotPathTemplate: "{testDir}/__snapshots__/{testFilePath}/{arg}{ext}",
// Run your local dev server before starting the tests:
// https://playwright.dev/docs/test-advanced#launching-a-development-web-server-during-the-tests
webServer: {
command:
"yarn workspace babel-plugin-react-compiler build && yarn workspace react-compiler-runtime build && yarn dev",
url: baseURL,
timeout: 300 * 1000,
reuseExistingServer: !process.env.CI,
},
use: {
// Use baseURL so to make navigations relative.
// More information: https://playwright.dev/docs/api/class-testoptions#test-options-base-url
baseURL,
// Retry a test if its failing with enabled tracing. This allows you to analyze the DOM, console logs, network traffic etc.
// More information: https://playwright.dev/docs/trace-viewer
trace: "retry-with-trace",
// All available context options: https://playwright.dev/docs/api/class-browser#browser-new-context
// contextOptions: {
// ignoreHTTPSErrors: true,
// },
},
projects: [
{
name: "chromium",
use: { ...devices["Desktop Chrome"] },
},
// {
// name: 'Desktop Firefox',
// use: {
// ...devices['Desktop Firefox'],
// },
// },
// {
// name: 'Desktop Safari',
// use: {
// ...devices['Desktop Safari'],
// },
// },
// Test against mobile viewports.
// {
// name: "Mobile Chrome",
// use: {
// ...devices["Pixel 5"],
// },
// },
// {
// name: "Mobile Safari",
// use: devices["iPhone 12"],
// },
],
});

View File

@@ -0,0 +1,13 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
module.exports = {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
};

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.8 KiB

View File

@@ -0,0 +1,16 @@
{
"name": "React Compiler Playground",
"short_name": "React REPL",
"display": "standalone",
"start_url": "/",
"theme_color": "#fff",
"background_color": "#000000",
"orientation": "portrait",
"icons": [
{
"src": "/icon-180x180.png",
"type": "image/png",
"sizes": "180x180"
}
]
}

View File

@@ -0,0 +1,4 @@
<svg width="283" height="64" viewBox="0 0 283 64" fill="none"
xmlns="http://www.w3.org/2000/svg">
<path d="M141.04 16c-11.04 0-19 7.2-19 18s8.96 18 20 18c6.67 0 12.55-2.64 16.19-7.09l-7.65-4.42c-2.02 2.21-5.09 3.5-8.54 3.5-4.79 0-8.86-2.5-10.37-6.5h28.02c.22-1.12.35-2.28.35-3.5 0-10.79-7.96-17.99-19-17.99zm-9.46 14.5c1.25-3.99 4.67-6.5 9.45-6.5 4.79 0 8.21 2.51 9.45 6.5h-18.9zM248.72 16c-11.04 0-19 7.2-19 18s8.96 18 20 18c6.67 0 12.55-2.64 16.19-7.09l-7.65-4.42c-2.02 2.21-5.09 3.5-8.54 3.5-4.79 0-8.86-2.5-10.37-6.5h28.02c.22-1.12.35-2.28.35-3.5 0-10.79-7.96-17.99-19-17.99zm-9.45 14.5c1.25-3.99 4.67-6.5 9.45-6.5 4.79 0 8.21 2.51 9.45 6.5h-18.9zM200.24 34c0 6 3.92 10 10 10 4.12 0 7.21-1.87 8.8-4.92l7.68 4.43c-3.18 5.3-9.14 8.49-16.48 8.49-11.05 0-19-7.2-19-18s7.96-18 19-18c7.34 0 13.29 3.19 16.48 8.49l-7.68 4.43c-1.59-3.05-4.68-4.92-8.8-4.92-6.07 0-10 4-10 10zm82.48-29v46h-9V5h9zM36.95 0L73.9 64H0L36.95 0zm92.38 5l-27.71 48L73.91 5H84.3l17.32 30 17.32-30h10.39zm58.91 12v9.69c-1-.29-2.06-.49-3.2-.49-5.81 0-10 4-10 10V51h-9V17h9v9.2c0-5.08 5.91-9.2 13.2-9.2z" fill="#000"/>
</svg>

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@@ -0,0 +1,20 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
const { execSync } = require("child_process");
// So that we don't need to check them into the repo.
// See https://github.com/reactjs/reactjs.org/blob/main/beta/scripts/downloadFonts.js.
execSync(
"curl https://conf.reactjs.org/fonts/Optimistic_Display_W_Lt.woff2 --output public/fonts/Optimistic_Display_W_Lt.woff2"
);
execSync(
"curl https://conf.reactjs.org/fonts/Optimistic_Display_W_Md.woff2 --output public/fonts/Optimistic_Display_W_Md.woff2"
);
execSync(
"curl https://conf.reactjs.org/fonts/Optimistic_Display_W_Bd.woff2 --output public/fonts/Optimistic_Display_W_Bd.woff2"
);

View File

@@ -0,0 +1,71 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
@tailwind base;
@tailwind components;
@tailwind utilities;
@layer base {
@font-face {
font-family: "Source Code Pro";
font-style: normal;
font-weight: 400;
font-display: swap;
src: url("/fonts/Source-Code-Pro-Regular.woff2") format("woff2");
}
@font-face {
font-family: "Optimistic Display";
src: url("/fonts/Optimistic_Display_W_Lt.woff2") format("woff2");
font-weight: 300;
font-style: normal;
font-display: swap;
}
@font-face {
font-family: "Optimistic Display";
src: url("/fonts/Optimistic_Display_W_Md.woff2") format("woff2");
font-weight: 500;
font-style: normal;
font-display: swap;
}
@font-face {
font-family: "Optimistic Display";
src: url("/fonts/Optimistic_Display_W_Bd.woff2") format("woff2");
font-weight: 700;
font-style: normal;
font-display: swap;
}
html,
body {
padding: 0;
margin: 0;
}
a {
color: inherit;
text-decoration: none;
}
* {
box-sizing: border-box;
}
}
@layer utilities {
/* Chrome, Safari, Opera */
.no-scrollbar::-webkit-scrollbar {
display: none;
}
.no-scrollbar {
-ms-overflow-style: none; /* IE, Edge */
scrollbar-width: none; /* Firefox */
}
}

View File

@@ -0,0 +1,41 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
const defaultTheme = require("tailwindcss/defaultTheme");
const colors = require("./colors");
module.exports = {
content: [
"./app/**/*.{js,ts,jsx,tsx}",
"./pages/**/*.{js,ts,jsx,tsx}",
"./components/**/*.{js,ts,jsx,tsx}",
"./lib/forgetMonacoDiagnostics.ts",
],
theme: {
extend: {
colors,
width: {
toast: "min(900px, 100vw - 40px)",
"toast-body": "calc(100% - 60px)",
"toast-title": "calc(100% - 40px)",
},
height: {
content: "calc(100vh - 45px)",
monaco: "calc(100vh - 93px)",
monaco_small: "calc(100vh - 129px)",
},
fontFamily: {
sans: [
"Optimistic Display",
"-apple-system",
...defaultTheme.fontFamily.sans,
],
},
},
},
plugins: [],
};

View File

@@ -0,0 +1,36 @@
{
"compilerOptions": {
"target": "ES2015",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"plugins": [
{
"name": "next"
}
]
},
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx",
".next/types/**/*.ts"
],
"exclude": [
"node_modules"
]
}

Some files were not shown because too many files have changed in this diff Show More