Commit Graph

16166 Commits

Author SHA1 Message Date
kassens c8b941f8d2 Warn about legacy context when legacy context is not disabled (#30297)
For environments that still have legacy contexts available, this adds a
warning to make the remaining call sites easier to locate and encourage
upgrades.

DiffTrain build for [378b305958](https://github.com/facebook/react/commit/378b305958eb7259cacfce8ad0e66eec07e07074)
2024-07-10 15:57:56 +00:00
sebmarkbage 6460f04862 [Fiber] Override the getCurrentStack temporarily while printing errors (#30300)
Only for parent stacks. This ensures that we can use the regular
mechanism for appending stack traces. E.g. you can polyfill it.

This is mainly so that I can later remove the automatic appending.

DiffTrain build for [3b2e5f27c5](https://github.com/facebook/react/commit/3b2e5f27c5b72708677da27779852b9aa83ef909)
2024-07-10 04:21:47 +00:00
sebmarkbage 7776712f5d [Flight] Serialize rate limited objects in console logs as marker an increase limit (#30294)
This marker can then be emitted as a getter. When this object gets
accessed we use a special error to let the user know what is going on.

<img width="1350" alt="Screenshot 2024-07-08 at 10 13 46 PM"
src="https://github.com/facebook/react/assets/63648/e3eb698f-e02d-4394-a051-ba9ac3236480">

When you click the `...`:
<img width="1357" alt="Screenshot 2024-07-08 at 10 13 56 PM"
src="https://github.com/facebook/react/assets/63648/4b8ce1cf-d762-49a4-97b9-aeeb1aa8722c">

I also increased the object limit in console logs. It was arbitrarily
set very low before.

These limits are per message. So if you have a loop of many logs it can
quickly add up a lot of strain on the server memory and the client. This
is trying to find some tradeoff. Unfortunately we don't really do much
deduping in these logs so with cyclic objects it ends up maximizing the
limit and then siblings aren't logged.

Ideally we should be able to lazy load them but that requires a lot of
plumbing to wire up so if we can avoid it we should try to. If we want
to that though one idea is to use the getter to do a sync XHR to load
more data but the server needs to retain the objects in memory for an
unknown amount of time. The client could maybe send a signal to retain
them until a weakref clean up but even then it kind of needs a heartbeat
to let the server know the client is still alive. That's a lot of
complexity. There's probably more we can do to optimize deduping and
other parts of the protocol to make it possible to have even higher
limits.

DiffTrain build for [14fdd0e21c](https://github.com/facebook/react/commit/14fdd0e21c420deb4bb96fc1e9021b531543d15a)
2024-07-10 04:21:32 +00:00
kassens 31e9c9e052 Dedupe legacy context warnings (#30299)
Similar to other warnings about legacy APIs, only raise a warning once per component.

DiffTrain build for [39e69dc665](https://github.com/facebook/react/commit/39e69dc665ef6f6dd1f9fe2f63348afb09694eab)
2024-07-09 23:59:57 +00:00
sebmarkbage 5f6d91c458 [Fizz] Refactor Component Stack Nodes (#30298)
Component stacks have a similar problem to the problem with keyPath
where we had to move it down and set it late right before recursing.
Currently we work around that by popping exactly one off when something
suspends. That doesn't work with the new server stacks being added which
are more than one. It also meant that we kept having add a single frame
that could be popped when there shouldn't need to be one.

Unlike keyPath component stacks has this weird property that once
something throws we might need the stack that was attempted for errors
or the previous stack if we're going to retry and just recreate it.

I've tried a few different approaches and I didn't like either but this
is the one that seems least problematic.

I first split out renderNodeDestructive into a retryNode helper. During
retries only retryNode is called. When we first discover a node, we pass
through renderNodeDestructive.

Instead of add a component stack frame deep inside renderNodeDestructive
after we've already refined a node, we now add it before in
renderNodeDestructive. That way it's only added once before being
attempted. This is similar to how Fiber works where in ChildFiber we
match the node once to create the instance and then later do we attempt
to actually render it and it's only the second part that's ever retried.

This unfortunately means that we now have to refine the node down to
element/lazy/thenables twice. To avoid refining the type too I move that
to be done lazily.

DiffTrain build for [b73dcdc04f](https://github.com/facebook/react/commit/b73dcdc04ffa2dd9f2197d796388657d64ad53be)
2024-07-09 19:49:46 +00:00
kassens 5c54f842d0 Remove propTypes on instance warning (#30296)
`propTypes` are no longer supported at all in React 19, remove this
outdated warning.

DiffTrain build for [ba95cf4b8f](https://github.com/facebook/react/commit/ba95cf4b8f39acfd7c0ccf2795a19430d35ea6b3)
2024-07-09 17:35:50 +00:00
sebmarkbage 14213c5b0a Warn for useFormState on initial render (#30292)
This was missed in the mount dev dispatcher. It was only in the rerender
dispatcher which means that it was only logged during the rerender.
Since DevTools can hide logs during rerenders, this hid the warning in
StrictMode.

DiffTrain build for [274c980c53](https://github.com/facebook/react/commit/274c980c535bb34e17f5d97cc22ef4dd296ab413)
2024-07-08 20:50:22 +00:00
sebmarkbage d255e1adc9 Add unknown location information to component stacks (#30290)
This is the same change as in #30289 but for the main runtime - e.g.
parent stacks in errorInfo.componentStack, appended stacks to
console.error coming from React itself and when we add virtual frames to
owner stacks.

Since we don't add location information these frames look weird to some
stack parsers - such as the native one. This is an existing issue when
you want to use some off-the-shelf parsers to parse production component
stacks for example.

While we won't add Error objects to logs ourselves necessarily, some
third party could want to do the same thing we do in DevTools and so we
should provide the same capability to just take this trace and print it
using an Error object.

DiffTrain build for [df783f9ea1](https://github.com/facebook/react/commit/df783f9ea1b6f95e05f830602da1de5ffb325d30)
2024-07-08 16:00:16 +00:00
eps1lon ac28fa9045 Consider dispatch from useActionState stable (#29665)
DiffTrain build for [1b0132c05a](https://github.com/facebook/react/commit/1b0132c05acabae5aebd32c2cadddfb16bda70bc)
2024-07-06 06:58:09 +00:00
sebmarkbage 07d044a91e [Fizz] Track Current debugTask and run it for onError Callbacks (#30182)
Stacked on #30174.

This tracks the current debugTask on the Task so that when an error is
thrown we can use it to run the `onError` (and `onShellError` and
`onFatalError`) callbacks within the Context of that task. Ideally it
would be associated with the error object but neither console.error [nor
reportError](https://crbug.com/350426235) reports this as the async
stack so we have to manually restore it.

That way when you inspect Fizz using node `--inspect` we show the right
async stack.

<img width="616" alt="Screenshot 2024-07-01 at 10 52 29 PM"
src="https://github.com/facebook/react/assets/63648/db68133e-124e-4509-8241-c67160db94fc">

This is equivalent to how we track the task that created the parent
server component or the Fiber:

https://github.com/facebook/react/blob/6d2a97a7113dfac2ad45067001b7e49a98718324/packages/react-reconciler/src/ReactChildFiber.js#L1985

Then use them when invoking the error callbacks:

https://github.com/facebook/react/blob/6d2a97a7113dfac2ad45067001b7e49a98718324/packages/react-reconciler/src/ReactFiberThrow.js#L104-L108

---------

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

DiffTrain build for [3db98c9177](https://github.com/facebook/react/commit/3db98c917701d59f62cf1fbe45cbf01b0b61c704)
2024-07-02 23:52:03 +00:00
sebmarkbage a3323b760a [Fizz] Implement debugInfo (#30174)
Stacked on #30170.

This lets us track Server Component parent stacks in Fizz which also
lets us track the correct owner stack for lazy.

In Fiber we're careful not to make any DEV only fibers but since the
ReactFizzComponentStack data structures just exist for debug meta data
anyway we can just expand on that.

DiffTrain build for [cfb8945f51](https://github.com/facebook/react/commit/cfb8945f511add040e1d5427d9961337f98f7618)
2024-07-02 22:32:32 +00:00
sebmarkbage 3ae0357e67 [Fizz] Include a component stack in prod but only lazily generate it (#30132)
When we added component stacks to Fizz in prod it severely slowed down
common cases where you intentionally are throwing error for purposes of
client rendering. Our parent component stack generation is very slow
since call components with fake errors to generate them.

Therefore we disabled them in prod but included them in prerenders.
https://github.com/facebook/react/pull/27850

However, we still kept generating data structures for them and the code
still exists there for the prerenders. We could stop generating the data
structures which are not completely free but also not crazy bad.

What we can do instead is just lazily generate the component stacks.
This is in fact what plain stacks do anyway. This doesn't work as well
in Fiber because the data structures are live but on the server they're
immutable so it's fine to do it later as well.

That way you can choose to not read this getter for intentionally thrown
errors - after inspecting the Error object - yet still get component
stacks in prod for other errors.

DiffTrain build for [e60063d9e7](https://github.com/facebook/react/commit/e60063d9e7d346e92a5af42975a2fe7dd306f86f)
2024-07-02 20:11:22 +00:00
sebmarkbage f6969ad590 [Fizz] Gate legacyContext field on disableLegacyContext (#30173)
We're running out of fields and this one we can avoid at runtime in any
modern builds.

DiffTrain build for [6d2a97a711](https://github.com/facebook/react/commit/6d2a97a7113dfac2ad45067001b7e49a98718324)
2024-07-01 19:43:58 +00:00
sebmarkbage b8decade28 [Fizz] Enable owner stacks for SSR (#30152)
Stacked on #30142.

This tracks owners and their stacks in DEV in Fizz. We use the
ComponentStackNode as the data structure to track this information -
effectively like ReactComponentInfo (Server) or Fiber (Client). They're
the instance.

I then port them same logic from ReactFiberComponentStack,
ReactFiberOwnerStack and ReactFiberCallUserSpace to Fizz equivalents.

This gets us both owner stacks from `captureOwnerStack()`, as well as
appended to console.errors logged by Fizz, while rendering and in
onError.

DiffTrain build for [315109b02b](https://github.com/facebook/react/commit/315109b02b0c9460b7466ca88f3f4d6ed1215a21)
2024-07-01 14:32:38 +00:00
sebmarkbage 0f2a59e321 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.

DiffTrain build for [e02baf6c92](https://github.com/facebook/react/commit/e02baf6c92833a0d45a77fb2e741676f393c24f7)
2024-06-27 16:16:24 +00:00
sebmarkbage 4365cb3a72 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.

DiffTrain build for [349a99a7a3](https://github.com/facebook/react/commit/349a99a7a347f280ce40e9297cac5a3bd796901e)
2024-06-26 17:33:14 +00:00
jackpope 893bdf02aa 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">

DiffTrain build for [89580f209c](https://github.com/facebook/react/commit/89580f209ce68ae9e266e309dfeb1625b434fb58)
2024-06-24 16:36:04 +00:00
jackpope ae90e9f856 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

DiffTrain build for [c21bcd627b](https://github.com/facebook/react/commit/c21bcd627b6a8f31548edfc149dd3b879fea6558)
2024-06-24 15:23:46 +00:00
kassens 174a36cbec www: remove dynamic scheduler feature flag: enableProfiling (#29996)
I removed the wrong feature flag in #29995, this is the correct one to
match D58682445.

DiffTrain build for [0b724e9e9c](https://github.com/facebook/react/commit/0b724e9e9c6469983f73631edb2e6abcc9c1193b)
2024-06-21 13:57:34 +00:00
kassens 2220b11e0a Revert "www: remove dynamic feature flag enableSchedulingProfiler" (#29995)
Reverts facebook/react#29994

DiffTrain build for [6ab67c35f1](https://github.com/facebook/react/commit/6ab67c35f15bd0ebf93af8d48d4d0545e9bb9551)
2024-06-20 21:22:30 +00:00
kassens 07cbad5450 www: remove dynamic feature flag enableSchedulingProfiler (#29994)
DiffTrain build for [babe5a2f1b](https://github.com/facebook/react/commit/babe5a2f1be70f67a456c4a96db9163f4ea60503)
2024-06-20 20:54:14 +00:00
kassens aed6d81a34 Revert "Set disableLegacyMode to true for www" (#29901)
Reverts facebook/react#29871

Just temporarily while we're investigating something.

DiffTrain build for [88959fd54a](https://github.com/facebook/react/commit/88959fd54af7d418b799a9898b921f32a356b212)
2024-06-14 19:32:45 +00:00
kassens 34a319d355 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.

DiffTrain build for [f0e8164410](https://github.com/facebook/react/commit/f0e8164410049aabc680035e8fd45b657eb020ab)
2024-06-14 17:22:56 +00:00
kassens dc2c2d7bb9 Set disableLegacyMode to true for www (#29871)
Set disableLegacyMode to true for www

DiffTrain build for [fb9a90fa48](https://github.com/facebook/react/commit/fb9a90fa480efce40ac2a845478817467f965ddc)
2024-06-14 13:58:57 +00:00
eps1lon bf7873152c Avoid acccessing React internals from use-sync-external-store/shim (#29868)
Co-authored-by: eps1lon <sebastian.silbermann@vercel.com>

DiffTrain build for [50e89ec9f2](https://github.com/facebook/react/commit/50e89ec9f2d44ab140e771e585226f7771da9652)
2024-06-12 18:19:45 +00:00
kassens 8cd41090d3 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="https://github.com/micromatch/braces/commit/74b2db2938fad48a2ea54a9c8bf27a37a62c350d"><code>74b2db2</code></a>
3.0.3</li>
<li><a
href="https://github.com/micromatch/braces/commit/88f1429a0f47e1dd3813de35211fc97ffda27f9e"><code>88f1429</code></a>
update eslint. lint, fix unit tests.</li>
<li><a
href="https://github.com/micromatch/braces/commit/415d660c3002d1ab7e63dbf490c9851da80596ff"><code>415d660</code></a>
Snyk js braces 6838727 (<a
href="https://redirect.github.com/micromatch/braces/issues/40">#40</a>)</li>
<li><a
href="https://github.com/micromatch/braces/commit/190510f79db1adf21d92798b0bb6fccc1f72c9d6"><code>190510f</code></a>
fix tests, skip 1 test in test/braces.expand</li>
<li><a
href="https://github.com/micromatch/braces/commit/716eb9f12d820b145a831ad678618731927e8856"><code>716eb9f</code></a>
readme bump</li>
<li><a
href="https://github.com/micromatch/braces/commit/a5851e57f45c3431a94d83fc565754bc10f5bbc3"><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="https://github.com/micromatch/braces/commit/2092bd1fb108d2c59bd62e243b70ad98db961538"><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="https://github.com/micromatch/braces/commit/9f5b4cf47329351bcb64287223ffb6ecc9a5e6d3"><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="https://github.com/micromatch/braces/commit/98414f9f1fabe021736e26836d8306d5de747e0d"><code>98414f9</code></a>
remove funding file</li>
<li><a
href="https://github.com/micromatch/braces/commit/665ab5d561c017a38ba7aafd92cc6655b91d8c14"><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>

DiffTrain build for [f3e09d6328](https://github.com/facebook/react/commit/f3e09d6328eb0eca53d8dbc19ea6f8f4aa43db25)
2024-06-12 15:22:22 +00:00
kassens 7000bd3923 remove unstable_renderSubtreeIntoContainer (#29771)
remove unstable_renderSubtreeIntoContainer

This is finally no longer used and can be deleted.

DiffTrain build for [93826c8483](https://github.com/facebook/react/commit/93826c8483ffaf6676c437c25619d82f13444413)
2024-06-12 15:19:50 +00:00
sebmarkbage 25dfa8e601 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">

DiffTrain build for [383b2a1845](https://github.com/facebook/react/commit/383b2a18456215d2d3ec46f33c0c912e84efa08f)
2024-06-11 22:17:20 +00:00
sebmarkbage 5ad4e799fa [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.

DiffTrain build for [270229f0c3](https://github.com/facebook/react/commit/270229f0c337dc652f07ef27d2254bb922bfaa9e)
2024-06-11 20:02:42 +00:00
sebmarkbage fe0295afe6 [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.

DiffTrain build for [01a40570c3](https://github.com/facebook/react/commit/01a40570c3cd852593c9bc88978b11cb9a2c5720)
2024-06-11 20:00:19 +00:00
sebmarkbage 08b8f37152 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.

DiffTrain build for [2774208039](https://github.com/facebook/react/commit/277420803947724b43c47bbc47d3a353553868f1)
2024-06-10 22:46:52 +00:00
sebmarkbage fcd14111f7 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.

DiffTrain build for [c2ae9e28bc](https://github.com/facebook/react/commit/c2ae9e28bc02fdd29c46b247d908e6b467ef06af)
2024-06-08 15:21:53 +00:00
gnoff 19bb8676ab [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.

DiffTrain build for [20b6f4c0e8](https://github.com/facebook/react/commit/20b6f4c0e8a1f40ee61735201645e0395ff08f94)
2024-06-07 23:58:40 +00:00
poteto cdfa569576 [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: 5705479135
Pull Request resolved: https://github.com/facebook/react/pull/29806

DiffTrain build for [20841f9a62](https://github.com/facebook/react/commit/20841f9a6205a633e6d08a274db974481daaca23)
2024-06-07 19:55:52 +00:00
kassens 39e6b27fee www: make disableLegacyMode dynamic flag (#29774)
This makes the flag dynamic for Meta and turns it on for the www test
renderer.

DiffTrain build for [142b2a8230](https://github.com/facebook/react/commit/142b2a8230130ddf3de8a9c8e7799a291f4d1a97)
2024-06-07 11:41:12 +00:00
dmytrorykun e0ef1b20bc 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.

DiffTrain build for [eb259b5d3b](https://github.com/facebook/react/commit/eb259b5d3b20b053dc0444e6ae442774c396c4a7)
2024-06-05 14:12:44 +00:00
kassens d3308e2254 www: set enableRefAsProp to true (#29756)
www: set enableRefAsProp to true

DiffTrain build for [a26e90c29c](https://github.com/facebook/react/commit/a26e90c29cfa841d3e2bc08876c5929d5680fb6d)
2024-06-04 15:22:19 +00:00
sebmarkbage dae837bc64 [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.)

DiffTrain build for [4dcdf21325](https://github.com/facebook/react/commit/4dcdf21325028d7ae9bb3c2172dbbe9647a744ac)
2024-06-03 16:31:47 +00:00
acdlite 27402d4be2 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.

DiffTrain build for [9598c41a20](https://github.com/facebook/react/commit/9598c41a20162c8a9d57ccf6a356aa183b00b61a)
2024-06-03 15:33:06 +00:00
acdlite a56f5cf224 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.

DiffTrain build for [67b05be0d2](https://github.com/facebook/react/commit/67b05be0d216c4efebc4bb5acb12c861a18bd87c)
2024-06-03 15:25:35 +00:00
gnoff 6c317aabdc Fix stylesheet typo in 29693 (#29732)
stylehsheet -> stylesheet

DiffTrain build for [def67b9b32](https://github.com/facebook/react/commit/def67b9b329c8aa204e611cd510c5a64680aee58)
2024-06-03 14:56:38 +00:00
gnoff a4058776de [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

DiffTrain build for [47d0c30246](https://github.com/facebook/react/commit/47d0c30246134ad9ce04abdcf0977cf2d49d00ce)
2024-06-03 14:52:55 +00:00
rickhanlonii 9f1a9c59f5 Don't skip www commit
DiffTrain build for [b421783110](https://github.com/facebook/react/commit/b421783110fb20f139adf4c4f9a8911dc63f9c68)
2024-06-03 14:26:53 +00:00
sebmarkbage c5b72a9c3b [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.

DiffTrain build for [ba099e442b](https://github.com/facebook/react/commit/ba099e442b602b9414693dab9cfa67e19051037c)
2024-06-03 03:03:13 +00:00
poteto 84fea4d26f Bump version to 0.0.0-experimental-7054a14-20240601
DiffTrain build for [d77dd31a32](https://github.com/facebook/react/commit/d77dd31a329df55a051800fc76668af8da8332b4)
2024-05-31 23:20:40 +00:00
poteto 23fac22ae2 [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: 60afcdb89a
Pull Request resolved: https://github.com/facebook/react/pull/29631

DiffTrain build for [113c8e7f72](https://github.com/facebook/react/commit/113c8e7f72bcf5d3bc285546da1508b45da3cf53)
2024-05-31 23:09:32 +00:00
acdlite 4ca2342331 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>

DiffTrain build for [adbec0c25a](https://github.com/facebook/react/commit/adbec0c25aff07f04b0678679554505ba2813168)
2024-05-31 21:57:52 +00:00
mvitousek 11f55031dd [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

DiffTrain build for [c69211a9df](https://github.com/facebook/react/commit/c69211a9dfa683038b1a758aba2ca09c7862a6d3)
2024-05-31 21:15:34 +00:00
mvitousek c01853d370 [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

DiffTrain build for [ec6fe57a50](https://github.com/facebook/react/commit/ec6fe57a5027d60a959493a2e44b6872b8de0ab8)
2024-05-31 21:14:40 +00:00
mvitousek e82072d2aa [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

DiffTrain build for [8b01a2e0bf](https://github.com/facebook/react/commit/8b01a2e0bf17adc6bb7b81d1d0063c7efe9ea8b1)
2024-05-31 21:12:34 +00:00