Commit Graph

824 Commits

Author SHA1 Message Date
acdlite 800cc35d48 Fix: Synchronous popstate transitions (#30759)
This is a refactor of the fix in #27505.

When a transition update is scheduled by a popstate event, (i.e. a back/
forward navigation) we attempt to render it synchronously even though
it's a transition, since it's likely the previous page's data is cached.

In #27505, I changed the implementation so that it only "upgrades" the
priority of the transition for a single attempt. If the attempt
suspends, say because the data is not cached after all, from then on it
should be treated as a normal transition.

But it turns out #27505 did not work as intended, because it relied on
marking the root with pending synchronous work (root.pendingLanes),
which was never cleared until the popstate update completed.

The test scenarios I wrote accidentally worked for a different reason
related to suspending the work loop, which I'm currently in the middle
of refactoring.

DiffTrain build for [ee7f6757c4](https://github.com/facebook/react/commit/ee7f6757c446c4e79ecc7e2bc22b8c9b712834b7)
2024-08-23 09:38:02 -07:00
poteto d1fee4a2fe [ez] Add noformat etc headers into some files
These are only needed internally so I'm opting to just do it in the
commit artifacts job instead of amending the build config.

ghstack-source-id: 6a5382b028
Pull Request resolved: https://github.com/facebook/react/pull/30775

DiffTrain build for [1d989965a6](https://github.com/facebook/react/commit/1d989965a6aac11d71ecf28030796f5475a86642)
2024-08-21 08:57:13 -07:00
gnoff d533aef7ab [Fizz] use microtasks rather than tasks when scheduling work while prerendering (#30770)
Similar to https://github.com/facebook/react/pull/30768 we want to
schedule work during prerendering in microtasks both for the root task
and pings. We continue to schedule flushes as Tasks to allow as much
work to be batched up as possible.

DiffTrain build for [ab24f643d0](https://github.com/facebook/react/commit/ab24f643d0809ee09a7499862fef135fb09a0225)
2024-08-21 08:03:00 -07:00
gnoff d094ee1eec [Fizz][Static] when aborting a prerender halt unfinished boundaries instead of erroring (#30732)
When we introduced prerendering for flight we modeled an abort of a
flight prerender as having unfinished rows. This is similar to how
postpone was already implemented when you postponed from "within" a
prerender using React.unstable_postpone. However when aborting with a
postponed instance every boundary would be eagerly marked for client
rendering which is more akin to prerendering and then resuming with an
aborted signal.

The insight with the flight work was that it's not so much the postpone
that describes the intended semantics but the abort combined with a
prerender. So like in flight when you abort a prerender and enableHalt
is enabled boundaries and the shell won't error for any reason. Fizz
will still call onPostpone and onError according to the abort reason but
the consuemr of the prerender should expect to resume it before trying
to use it.

DiffTrain build for [85180b8cf8](https://github.com/facebook/react/commit/85180b8cf84274795986c8f2c8473f8816db8b7b)
2024-08-20 13:42:54 -07:00
gnoff 7420875c72 [Fizz] track postpones when aborting boundaries with a postpone (#30751)
When aborting with a postpone value boundaries are put into client
rendered mode even during prerenders. This doesn't follow the postpoen
semantics of the rest of fizz where during a prerender a postpone is
tracked and it will leave holes in tracked postpone state that can be
resumed. This change updates this behavior to match the postpones
semantics between aborts and imperative postpones.

DiffTrain build for [2505bf9b34](https://github.com/facebook/react/commit/2505bf9b3400c6a00381e86d30b495935f5339df)
2024-08-20 09:58:23 -07:00
gnoff 6f94ca81fd [Fizz] handle throwing after abort during render (#30730)
It is possible to throw after aborting during a render and we were not
properly tracking this. We use an AbortSigil to mark whether a rendering
task needs to abort but the throw interrupts that and we end up handling
an error on the error pathway instead.

This change reworks the abort-while-rendering support to be robust to
throws after calling abort

DiffTrain build for [7954db9398](https://github.com/facebook/react/commit/7954db9398b9afa962167577a6c6940be3856c39)
2024-08-16 18:39:11 -07:00
gaearon b41f0cd50d [Fresh] Always reset useMemoCache on Fast Refresh (#30700)
Stacked on https://github.com/facebook/react/pull/30662.

Alternative to https://github.com/facebook/react/pull/30663 and
https://github.com/facebook/react/pull/30677.

During a Fast Refresh, we always want to evict the memo cache, same as
we do with normal `useMemo`. The mechanism used by `useMemo` and other
Hooks is this module-level variable:

https://github.com/facebook/react/blob/fca5d655d78917400a2722287351c20938166669/packages/react-reconciler/src/ReactFiberHooks.js#L304-L307

which has DEV-only behavior as if the dependencies are always different:

https://github.com/facebook/react/blob/fca5d655d78917400a2722287351c20938166669/packages/react-reconciler/src/ReactFiberHooks.js#L451-L460

The `useMemoCache` Hook doesn't use a dependency array but conceptually
I think we want the same behavior.

## Test Plan

The test passes.

---------

Co-authored-by: Lauren Tan <poteto@users.noreply.github.com>

DiffTrain build for [7e8a06cf4c](https://github.com/facebook/react/commit/7e8a06cf4c628be45171da52c1a8e97f9869b7ee)
2024-08-14 17:11:16 -07:00
jackpope e3cf3d59b4 Fix unstable_useContextWithBailout dispatcher assignment (#30692)
One more copy pasta fix

Assignments are unique now
```
% cat packages/react-reconciler/src/ReactFiberHooks.js | grep .unstable_useContextWithBailout
function unstable_useContextWithBailout<T>(
  (ContextOnlyDispatcher: Dispatcher).unstable_useContextWithBailout =
  (HooksDispatcherOnMount: Dispatcher).unstable_useContextWithBailout =
    unstable_useContextWithBailout;
  (HooksDispatcherOnUpdate: Dispatcher).unstable_useContextWithBailout =
    unstable_useContextWithBailout;
  (HooksDispatcherOnRerender: Dispatcher).unstable_useContextWithBailout =
    unstable_useContextWithBailout;
    (HooksDispatcherOnMountInDEV: Dispatcher).unstable_useContextWithBailout =
        return unstable_useContextWithBailout(context, select);
    (HooksDispatcherOnMountWithHookTypesInDEV: Dispatcher).unstable_useContextWithBailout =
        return unstable_useContextWithBailout(context, select);
    (HooksDispatcherOnUpdateInDEV: Dispatcher).unstable_useContextWithBailout =
        return unstable_useContextWithBailout(context, select);
    (HooksDispatcherOnRerenderInDEV: Dispatcher).unstable_useContextWithBailout =
        return unstable_useContextWithBailout(context, select);
    (InvalidNestedHooksDispatcherOnMountInDEV: Dispatcher).unstable_useContextWithBailout =
        return unstable_useContextWithBailout(context, select);
    (InvalidNestedHooksDispatcherOnUpdateInDEV: Dispatcher).unstable_useContextWithBailout =
        return unstable_useContextWithBailout(context, select);
    (InvalidNestedHooksDispatcherOnRerenderInDEV: Dispatcher).unstable_useContextWithBailout =
        return unstable_useContextWithBailout(context, select);
```

DiffTrain build for [0ad0fac1dc](https://github.com/facebook/react/commit/0ad0fac1dc11db8d5a6831987fb0324cd6d59498)
2024-08-14 08:13:51 -07:00
jackpope b903fc08c5 Fix unstable_useContextWithBailout incorrect dispatcher assignment (#30673)
Fixing a mistaken copy from another dispatcher property assignment

DiffTrain build for [d48603a525](https://github.com/facebook/react/commit/d48603a52564675ce02152fff245e38b6816da47)
2024-08-13 08:40:45 -07:00
kassens 3221ff0d9f Remove flag enableUseDeferredValueInitialArg (#30595)
This is enabled everywhere for a while and I don't think we'd be backing
this out of 19. Seems like it's good to clean up to me.

DiffTrain build for [65903583d2](https://github.com/facebook/react/commit/65903583d2ab45aea45bdd23ed0b5dc214ff3c1c)
2024-08-05 08:32:25 -07:00
eps1lon 76d8d060b5 [Devtools] Ensure initial read of useFormStatus returns NotPendingTransition (#28728)
DiffTrain build for [88ee14ffa5](https://github.com/facebook/react/commit/88ee14ffa57beb0689f26f0c52c357e3ac446af8)
2024-08-01 02:03:31 -07:00
gnoff c8a80954f1 [Fizz] Update postpone abort semantics when prerendering (#30541)
When aborting with a postpone value in Fizz if any tasks are still
pending in the root while prerendering the prerender will fatally error.
This is different from postponing imperatively in a root task and really
the semantics should be the same. This change updates React to treat an
abort with a postpone value as a postponed root rather than a fatal
error.

DiffTrain build for [a7d1240c96](https://github.com/facebook/react/commit/a7d1240c962d2fdeac3ba31f1fdc12b5be4bbd2e)
2024-07-31 08:40:57 -07:00
gaearon 57f6b8f122 Remove RefreshRuntime.findAffectedHostInstances (#30538)
I originally added this with a plan to visualize which nodes got updated
after a Fast Refresh. I didn't end up implementing that part, and to my
knowledge, no actively used integration actually does that or use this
method.

- [Webpack plugin doesn't use
it](https://github.com/pmmmwh/react-refresh-webpack-plugin/blob/f1c8b9a44198449093ca95f85af5df97925e1cfc/lib/runtime/RefreshUtils.js)
- [RN doesn't use
it](https://github.com/facebook/react-native/blob/23c5c42de01953ed7b8e8938c2d3a8fac82250a0/packages/react-native/Libraries/Core/setUpReactRefresh.js)
- [Global GitHub code
search](https://github.com/search?q=findAffectedHostInstances&type=code&p=1)
only shows copies of this code and the type definition based on it, but
not actual calls to it

We should be able to delete this without a problem.

DiffTrain build for [96f3093bec](https://github.com/facebook/react/commit/96f3093becc1f26e06549b9a54b93db9df8f5689)
2024-07-30 14:14:59 -07:00
sebmarkbage 53526c55b1 [Fiber] Make DevTools Config use Static Injection (#30522)
We use static dependency injection. We shouldn't use this dynamic
dependency injection we do for DevTools internals. There's also meta
programming like spreading and stuff that isn't needed.

This moves the config from `injectIntoDevTools` to the FiberConfig so it
can be statically resolved.

Closure Compiler has some trouble generating optimal code for this
anyway so ideally we'd refactor this further but at least this is better
and saves a few bytes and avoids some code paths (when minified).

DiffTrain build for [146df7c311](https://github.com/facebook/react/commit/146df7c311831a1d5b35f3783dae4a7030638fcf)
2024-07-30 12:11:01 -07:00
sebmarkbage 5654af66b3 [Fiber/DevTools] Stop injecting findHostInstanceByFiber (#30519)
This is not used by DevTools since it has its own implementation of it.

This function is getting removed since `findDOMNode` is getting removed
so we shouldn't keep around extra bytes unnecessarily.

There is also `findHostInstancesForRefresh` which should really be
implemented on the `react-refresh` side. Not using an injection but
that's a heavier lift and only affects `__DEV__`.

DiffTrain build for [bea5a2bc46](https://github.com/facebook/react/commit/bea5a2bc46cc95713392175c3c6307e49c14cd98)
2024-07-29 17:12:35 -07:00
jackpope 5c9e62fada Update enableLazyContextPropagation flag (#30514)
- Flag set to true for FB
- Flag set to experimental for OSS

DiffTrain build for [397646ad51](https://github.com/facebook/react/commit/397646ad5123de02486b08e34aba1a480f5af186)
2024-07-29 13:57:34 -07:00
gnoff 05ad6512c1 [Fizz] Allow aborting during render (#30488)
Currently if you abort a Fizz render during rendering the render will
not complete correctly because there are inconsistencies with task
counting. This change updates the abort implementation to allow you to
abort from within a render itself. We already landed a similar change
for Flight in #29764

DiffTrain build for [a451de014c](https://github.com/facebook/react/commit/a451de014ca71718aee924bb57d5b4a1d87e20f2)
2024-07-29 13:32:12 -07:00
gnoff 1cde450e4e [Fizz] Don't perform work when closing (#30497)
When a Fizz render is closing but not yet closed it's possible that
pinged tasks can spawn more work. The point of the closing state is to
allow time to start piping/reading the underlying stream but
semantically the render is finished at that point so work should no
longer happen.

DiffTrain build for [9938e248fe](https://github.com/facebook/react/commit/9938e248feecc6410738cc905744836d6f78c7f8)
2024-07-29 11:18:55 -07:00
gnoff 62e71f4110 [Fizz] Prerender fallbacks before children (#30483)
When prerendering it can be convenient to abort the prerender while
rendering. However if any Suspense fallbacks have not yet rendered
before the abort happens the fallback itself will error and cause the
nearest parent Suspense boundary to render a fallback instead.
Prerenders are by definition not time critical so the prioritization of
children over fallbacks which makes sense for render isn't similarly
motivated for prerender. Given this, this change updates fallback
rendering during a prerender to attempt the fallback before attempting
children.

DiffTrain build for [d17e9d1ce5](https://github.com/facebook/react/commit/d17e9d1ce566276fc54a8ea27f4e9ea1fa434e62)
2024-07-26 14:14:00 -07:00
poteto 872ed4b354 [ci] Fix invalid username and email in synthetic commit
ghstack-source-id: 951d0ef445
Pull Request resolved: https://github.com/facebook/react/pull/30486

DiffTrain build for [b9af819f8b](https://github.com/facebook/react/commit/b9af819f8b0e7f14200cfffe04da835b56f2f75d)
2024-07-26 12:22:38 -07:00
gnoff e1ad904186 [Fiber] use srcset to trigger load even on img mount (#30351)
In https://github.com/facebook/react/pull/23316 we fixed a bug where
onload events were missed if they happened too early. This update adds
support for srcset to retrigger the load event. Firefox unfortunately
does not trigger a load even when you assign srcset so this won't work
in every browser when you use srcset without src however it does close a
gap in chrome at least

DiffTrain build for [7f217d1d88](https://github.com/facebook/react/commit/7f217d1d88d3b628d97a714ce1573526080af47d)
2024-07-25 15:51:39 -07:00
sebmarkbage ecd0adf469 Switch to binding the console with badging instead of calling it directly (#30461)
This is a major nit but this avoids an extra stack frame when we're
replaying logs.

Normally the `printToConsole` frame doesn't show up because it'd be
ignore listed.

<img width="421" alt="Screenshot 2024-07-25 at 11 49 39 AM"
src="https://github.com/user-attachments/assets/81334c2f-e19e-476a-871e-c4db9dee294e">

When you expand to show ignore listed frames a ton of other frames show
up.

<img width="516" alt="Screenshot 2024-07-25 at 11 49 47 AM"
src="https://github.com/user-attachments/assets/2ab8bdfb-464c-408d-9176-ee2fabc114b6">

The annoying thing about this frame is that it's at the top of the stack
where as typically framework stuff ends up at the bottom and something
you can ignore. The user space stack comes first.

With this fix there's no longer any `printToConsole` frame.

<img width="590" alt="Screenshot 2024-07-25 at 12 09 09 PM"
src="https://github.com/user-attachments/assets/b8365d53-31f3-43df-abce-172d608d3c9c">

Am I wiling to eat the added complexity and slightly slower performance
for this nit? Definitely.

DiffTrain build for [e8df0cf9f7](https://github.com/facebook/react/commit/e8df0cf9f7c7f641192f19841db9bf34b6a0abf7)
2024-07-25 09:37:18 -07:00
jackpope 0083afd4d2 Remove allowConcurrentByDefault flag (#30445)
Following https://github.com/facebook/react/pull/30436

Concurrent by default strategy has been unshipped. Here we clean up the
`allowConcurrentByDefault` path and related logic/tests.

For now, this keeps the `concurrentUpdatesByDefaultOverride` argument in
`createContainer` and `createHydrationContainer` and ignores the value
to prevent more breaking changes to `react-reconciler` in the RC stage.

DiffTrain build for [14a4699ff1](https://github.com/facebook/react/commit/14a4699ff173936a30ec453f7b94d47105bbb252)
2024-07-25 09:04:47 -07:00
sebmarkbage 6115286319 [Fiber] Call life-cycles with a react-stack-bottom-frame stack frame (#30429)
Stacked on #30427.

Most hooks and such are called inside renders which already have these
on the stack but life-cycles that call out on them are useful to cut off
too.

Typically we don't create JSX in here so they wouldn't be part of owner
stacks anyway but they can be apart of plain stacks such as the ones
prefixes to console logs or printed by error dialogs.

This lets us cut off any React internals below. This should really be
possible using just ignore listing too ideally.

At this point we should maybe just build a Babel plugin that lets us
annotate a function to need to have this name.

DiffTrain build for [da4abf0047](https://github.com/facebook/react/commit/da4abf0047cf6dc6d9bff505bd93815264c8c3b7)
2024-07-23 15:54:43 -07:00
eps1lon 288b7b795b Log Fragment name when trying to render a lazy fragment (#30372)
DiffTrain build for [9cc0f6e68d](https://github.com/facebook/react/commit/9cc0f6e68de2b83b11d1fb2b514d2f508c2da6f7)
2024-07-23 10:07:59 -07:00
kassens a9dbaee08c [BE] upgrade prettier to 3.3.3 (#30420)
Mostly just changes in ternary formatting.

DiffTrain build for [b7e7f1a3fa](https://github.com/facebook/react/commit/b7e7f1a3fab87e8fc19e86a8088a9e0fe4710973)
2024-07-22 13:16:11 -07:00
kassens 32ff1a42f3 Set enableFastJSX flag to true (#30343)
When these to diffs are landed, we can merge this

- [x] D59772879
- [x] D59773043

DiffTrain build for [d025ddd3b9](https://github.com/facebook/react/commit/d025ddd3b954dfc52ad7e6a036913946a8ca2644)
2024-07-22 08:55:29 -07:00
sebmarkbage 48b7a7e1b0 [Flight] Normalize Stack Using Fake Evals (#30401)
Stacked on https://github.com/facebook/react/pull/30400 and
https://github.com/facebook/react/pull/30369

Previously we were using fake evals to recreate a stack for console
replaying and thrown errors. However, for owner stacks we just used the
raw string that came from the server.

This means that the format of the owner stack could include different
formats. Like Spidermonkey format for the client components and V8 for
the server components. This means that this stack can't be parsed
natively by the browser like when printing them as error like in
https://github.com/facebook/react/pull/30289. Additionally, since
there's no source file registered with that name and no source mapping
url, it can't be source mapped.

Before:

<img width="1329" alt="before-firefox"
src="https://github.com/user-attachments/assets/cbe03f9c-96ac-48fb-b58f-f3a224a774f4">

Instead, we need to create a fake stack like we do for the other things.
That way when it's printed as an Error it gets source mapped. It also
means that the format is consistently in the native format of the
current browser.

After:

<img width="753" alt="after-firefox"
src="https://github.com/user-attachments/assets/b436f1f5-ca37-4203-b29f-df9828c9fad3">

So this is nice because you can just take the result from
`captureOwnerStack()` and append it to an `Error` stack and print it
natively. E.g. this is what React DevTools will do.

If you want to parse and present it yourself though it's a bit awkward
though. The `captureOwnerStack()` API now includes a bunch of
`rsc://React/` URLs. These don't really have any direct connection to
the source map. Only the browser knows this connection from the eval.
You basically have to strip the prefix and then manually pass the
remainder to your own `findSourceMapURL`.

Another awkward part is that since Safari doesn't support eval sourceURL
exposed into `error.stack` - it means that `captureOwnerStack()` get an
empty location for server components since the fake eval doesn't work
there. That's not a big deal since these stacks are already broken even
for client modules for many because the `eval-source-map` strategy in
Webpack doesn't work in Safari for this same reason.

A lot of this refactoring is just clarifying that there's three kind of
ReactComponentInfo fields:

- `stack` - The raw stack as described on the original server.
- `debugStack` - The Error object containing the stack as represented in
the current client as fake evals.
- `debugTask` - The same thing as `debugStack` but described in terms of
a native `console.createTask`.

DiffTrain build for [b15c1983dc](https://github.com/facebook/react/commit/b15c1983dcf96f19400b0ca7337be1e1fb1a8717)
2024-07-22 08:08:11 -07:00
sebmarkbage 97b42fd534 Tag all user space call sites with the "react-stack-bottom-frame" name (#30369)
Ideally we wouldn't need to filter out React internals and it'd just be
covered by ignore listing by any downstream tool. E.g. a framework using
captureOwnerStack could have its own ignore listing. Printed owner
stacks would get browser source map ignore-listing. React DevTools could
have its own ignore list for internals. However, it's nice to be able to
provide nice owner stacks without a bunch of noise by default.
Especially on the server since they have to be serialized.

We currently call each function that calls into user space and track its
stack frame. However, this needs code for checking each one and doesn't
let us work across bundles.

Instead, we can name each of these frame something predictable by giving
the function a name.

Unfortunately, it's a common practice to rename functions or inline them
in compilers. Even if we didn't, others downstream from us or a dev-mode
minifier could. I use this `.bind()` trick to avoid minifying these
functions and ensure they get a unique name added to them in all
browsers. It's not 100% fool proof since a smart enough compiler could
also discover that the `this` value is not used and strip out the
function and then inline it but nobody does this yet at least.

This lets us find the bottom stack easily from stack traces just by
looking for the name.

DiffTrain build for [792f192114](https://github.com/facebook/react/commit/792f1921145e51bd06b836ffa0a16ecc39c8ee82)
2024-07-22 07:52:59 -07:00
gnoff 92282b20ad [Fiber] Ensure srcset and src are assigned last on img instances (#30340)
Safari has a behavior (bug) where when you consturct an Image in
javascript if you set srcset before properties for `sizes` the brwoser
will download the largest image size because it starts to load before
you communicate the sizes information.

https://x.com/OliverJAsh/status/1812408504444989588?t=CVHPqBaUiF5-6DBPGERTDA

There are likely other combinations or property order assignment that
can cause problems such as setting crossorigin after assigning src or
srcset. Conceptually we should withold the src and srcSet from the Image
instance until last so all relevant other properties can be assigned
before actually initiating any network activity.

This is an unforunate amount of code for what is realistically a bug in
Browsers but it should allow us to avoid weird regressions depending on
prop object order.

I didn't change the preload prop order because I don't believe preload
links have the same issue (they are not fetched as eagerly I believe).

One nice benefit of this change though is the img case can move higher
in the switch which is likely optimal given it's a relatively common
tag. Previously it was as low as it was because it was part of the void
element set so it couldn't be elevated without elevating less common
tags

---------

Co-authored-by: Jan Kassens <jan@kassens.net>

DiffTrain build for [0117239720](https://github.com/facebook/react/commit/0117239720b6ea830376f4f8605957ccae8b3735)
2024-07-16 08:30:28 -07:00
gnoff 153c995f13 [Fizz] correctly track header length (#30327)
The interstital characters in our link header tracking are not
contributing to the remaining capacity calculation so when a lot of
inditidual links are present in the link header it can allow an
overflowing link header to be included. This change corrects the math so
it properly prevents overflow.

DiffTrain build for [79e4f23808](https://github.com/facebook/react/commit/79e4f23808435d74eaa4a199ae0093cfc176f583)
2024-07-13 07:29:35 -07:00
sebmarkbage d38d9536ab Disable consoleWithStackDev Transform except in RN/WWW (#30313)
Stacked on #30308.

This is now a noop module so we can stop applying the transform of
console.error using the Babel plugin in the mainline builds. I'm keeping
the transform for RN/WWW for now although it might be nice if the
transform moved into those systems as it gets synced instead of keeping
it upstream.

In jest tests we're already not running the forks for RN/WWW so we don't
need it at all there.

DiffTrain build for [ff89ba7346](https://github.com/facebook/react/commit/ff89ba734668fdac06e8de476486830bbf9e0785)
2024-07-12 11:44:41 -07:00
sebmarkbage f91895deda Remove top stack frame from getCurrentStack (#30306)
The full stack is the current execution stack (`new Error().stack`) +
the current owner stack (`React.captureOwnerStack()`).

The idea with the top frame was that when we append it to console.error
we'd include both since otherwise the true reason would be obscured
behind the little `>` to expand. So we'd just put both stack front and
center. By adding this into getCurrentStack it was easy to use the same
filtering. I never implemented in Fizz or Flight though.

However, with the public API `React.captureOwnerStack()` it's not
necessary to include the current stack since you already have it and
you'd have filtering capabilities in user space too.

Since I'm removing the component stacks from React itself we no longer
need this. It's expected that maybe RDT or framework polyfill would
include this same technique though.

DiffTrain build for [433068eece](https://github.com/facebook/react/commit/433068eece2071a96de98b60f99ce6a9121a629c)
2024-07-11 22:39:32 +00:00
kassens 2a5d4d4c6b Feature flag to disable legacy context for function components (#30319)
While the goal is to remove legacy context completely, I think we can
already land the removal of legacy context for function components. I
didn't even know this feature existed until reading the code recently.

The win is just a couple of property lookups on function renders, but it
trims down the API already as the full removal will likely still take a
bit more time.

www: Starting with enabled test renderer and a feature flag for
production rollout.

RN: Not enabled, will follow up on this.

DiffTrain build for [af28f480e8](https://github.com/facebook/react/commit/af28f480e8e74ce71bb33259b61fef8a5a228f74)
2024-07-11 20:27:09 +00:00
sebmarkbage b71b43e3a7 Gate inlined consoleWithStackDev transpilation (#30317)
This code is getting deleted in #30313 anyway but it should've been
gated all along.

This code exists to basically manually transpile console.error to
consoleWithStackDev because the transpiler doesn't work on `.apply` or
`.bind` or the dynamic look up. We only apply the transform in DEV so we
should've only done this in DEV.

Otherwise these logs get silenced in prod.

DiffTrain build for [a09950ed41](https://github.com/facebook/react/commit/a09950ed418adb26a5e735b4ee9eca5e5282ffc7)
2024-07-11 17:10:22 +00:00
sebmarkbage 855d676372 Delete suppressWarning in OSS (#30312)
I'm pretty sure this is completely unnecessary even in www and RN
because it's only useful if you use the mock scheduler which typically
only we do in our own tests. But all our tests pass so unless www/RN
does something with it, I don't think this is used.

Also remove unnecessary `__DEV__` check. If it gets pulled in prod, we'd
want to know about it.

DiffTrain build for [85acf2d195](https://github.com/facebook/react/commit/85acf2d19527df568136ba08be97aa766d427ff2)
2024-07-11 15:26:45 +00:00
kassens 2563348f30 easy: add link to legacy context warning (#30315)
Missed this when adding the link to other places of the same warning in
https://github.com/facebook/react/commit/378b305958eb7259cacfce8ad0e66eec07e07074

DiffTrain build for [8e00cf04de](https://github.com/facebook/react/commit/8e00cf04de3c6b0f09efdf6f8f37a7fbe2c0a3e0)
2024-07-11 14:48:35 +00:00
sebmarkbage 5fb5ce8173 Override the getCurrentStack temporarily while printing uncaught errors (#30309)
This is just a follow up to #30300.

I forgot the uncaught branch.

DiffTrain build for [29552c7907](https://github.com/facebook/react/commit/29552c7907230222acd3f2c586784d24f9da6200)
2024-07-10 21:04:35 +00:00
kassens f70848628d Experiment with using an object literal for Fiber creation (#28734)
Object literals should be faster at least on React Native with Hermes as
the JS engine.
It might also be interesting to confirm the old comments in this file
from years ago are even still valid. Creating an object from a literal
should be a simpler operation.

It's a bit unfortunate that this introduces a bunch of copied code, but
since we rearely update the fields on fibers, this seems like an okay
tradeoff for a hot code path. An alternative would be some sort of macro
system, but that doesn't seem worth the extra complexity.

DiffTrain build for [fe9828954a](https://github.com/facebook/react/commit/fe9828954adcc51aa2bd21fe53d969a44dd3c9d2)
2024-07-10 20:48:02 +00:00
sebmarkbage f4ccb1f263 Format DOM Nesting Warning as Diff View + An Additional Log for Stack Trace (#30302)
Currently we're printing parent stacks at the end of DOM nesting even
with owner stacks enabled. That's because the context of parent tree is
relevant for determining why two things are nested. It might not be
sufficient to see the owner stack alone.

I'm trying to get rid of parent stacks and rely on more of the plain
owner stacks or ideally console.createTask. These are generally better
anyway since the exact line for creating the JSX is available. It also
lets you find a parent stack frame that is most relevant e.g. if it's
hidden inside internals.

For DOM nesting there's really only two stacks that are relevant. The
creation of the parent and the creation of the child. Sometimes they're
close enough to be the same thing. Such as for parents that can't have
text children or when the ancestor is the direct parent created at the
same place (same owner).

Sometimes they're far apart. In this case I add a second console.error
within the context of the ancestor. That way the second stack trace can
be used to read the stack trace for where it was created.

To preserve some parent context I now print the parent stack in a diff
view format using the logic from hydration diffs. This includes some
siblings and props for context.

<img width="756" alt="Screenshot 2024-07-10 at 12 21 38 AM"
src="https://github.com/facebook/react/assets/63648/0843133d-cc7a-4ecc-91c0-f46ae8e99f20">

Text Nodes:

<img width="749" alt="Screenshot 2024-07-10 at 12 37 40 AM"
src="https://github.com/facebook/react/assets/63648/ee377d82-54ee-450a-99d1-fcc3ef290d59">

---------

Co-authored-by: tjallingt <tjallingt@gmail.com>

DiffTrain build for [2d3f81bb6a](https://github.com/facebook/react/commit/2d3f81bb6a650386832d885d7b63a7d0d517ba15)
2024-07-10 16:22:14 +00:00
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