Commit Graph

5056 Commits

Author SHA1 Message Date
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 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
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
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
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
Ricky 29fbf6f626 Convert ReactError-test to createRoot (#27995) 2024-01-19 14:35:56 -05: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
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
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
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
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