Commit Graph

16206 Commits

Author SHA1 Message Date
Matt Carroll 8f998bf93f Convert SyntheticEvent-test.js to createRoot (#28118) 2024-01-26 13:17:44 -08:00
Matt Carroll 7c79dafb71 Convert ReactDOMServerIntegrationUntrustedURL-test.js to createRoot (#28105) 2024-01-26 12:18:14 -08:00
Sebastian Silbermann 9aef5d225b Use modern rendering APIs for attribute-behavior fixture (#27883)
The attribute-behavior fixture now uses `createRoot().render()` and
`renderToReadableStream` instead of depdrecated APIs.

This revealed some changes to the snapshots that I annotated for
discussion.

I also added some new tests related to upcoming changes for easier
future diffing.

Also adds support for running the attribute-behavior fixture using Apple
Silicon chips (Apple MBP M-series).
2024-01-26 19:03:42 +01:00
Andrew Clark 60f190a559 Capture React.startTransition errors and pass to reportError (#28111)
To make React.startTransition more consistent with the hook form of
startTransition, we capture errors thrown by the scope function and pass
them to the global reportError function. (This is also what we do as a
default for onRecoverableError.)

This is a breaking change because it means that errors inside of
startTransition will no longer bubble up to the caller. You can still
catch the error by putting a try/catch block inside of the scope
function itself.

We do the same for async actions to prevent "unhandled promise
rejection" warnings.

The motivation is to avoid a refactor hazard when changing from a sync
to an async action, or from useTransition to startTransition.
2024-01-26 12:10:33 -05:00
Jack Pope 51c380d6ed Use createRoot in ReactEmptyComponent-test (#28095) 2024-01-26 11:37:51 -05:00
Tobias Koppers 763612647c fix incorrect insertion order of stylesheets (#28108)
## Summary

In the precendences Map every key is prefixed with `p`. This fixes one
case where this is missing.

## How did you test this change?

<!--
Demonstrate the code is solid. Example: The exact commands you ran and
their output, screenshots / videos if the pull request changes the user
interface.
How exactly did you verify that your PR solves the issue you wanted to
solve?
  If you leave this empty, your PR will very likely be closed.
-->
2024-01-26 07:54:58 -08:00
Sebastian Silbermann 6c64428d90 Convert ChangeEventPlugin to createRoot (#28090) 2024-01-26 10:20:26 +01:00
Sebastian Silbermann 36baa43560 Convert ReactDOMAttribute to createRoot (#28089) 2024-01-26 10:17:26 +01:00
Sebastian Silbermann 0c45e83071 Convert SelectEventPlugin to createRoot (#28076) 2024-01-26 10:17:13 +01:00
Sebastian Silbermann b30ec67c43 Convert ReactDOMSVG to createRoot (#28074) 2024-01-26 10:17:09 +01:00
Matt Carroll fbb21066a2 Convert SyntheticWheelEvent-test.js to createRoot (#28103) 2024-01-26 03:05:08 -05:00
Ricky 9bad8ed9a6 Convert validateDOMNesting to createRoot (#28098)
ezpz
2024-01-25 22:30:56 -05:00
Andrew Clark 85b296e9b6 Async action support for React.startTransition (#28097)
This adds support for async actions to the "isomorphic" version of
startTransition (i.e. the one exported by the "react" package).
Previously, async actions were only supported by the startTransition
that is returned from the useTransition hook.

The interesting part about the isomorphic startTransition is that it's
not associated with any particular root. It must work with updates to
arbitrary roots, or even arbitrary React renderers in the same app. (For
example, both React DOM and React Three Fiber.)

The idea is that React.startTransition should behave as if every root
had an implicit useTransition hook, and you composed together all the
startTransitions provided by those hooks. Multiple updates to the same
root will be batched together. However, updates to one root will not be
batched with updates to other roots.

Features like useOptimistic work the same as with the hook version.

There is one difference from from the hook version of startTransition:
an error triggered inside an async action cannot be captured by an error
boundary, because it's not associated with any particular part of the
tree. You should handle errors the same way you would in a regular
event, e.g. with a global error event handler, or with a local
`try/catch`.
2024-01-25 21:54:45 -05:00
Sebastian Markbåge 382190c595 [Flight/Fizz] Reset ThenableState Only in Branches Where It's Added (#28068)
Before, we used to reset the thenable state and extract the previous
state very early so that it's only the retried task that can possibly
consume it. This is nice because we can't accidentally consume that
state for any other node.

However, it does add a lot of branches of code that has to pass this
around. It also adds extra bytes on the stack per node. Even though it's
mostly just null.

This changes it so that where ever we can create a thenable state (e.g.
entering a component with hooks) we first extract this from the task.
The principle is that whatever could've created the thenable state in
the first place, must always be rerendered so it'll take the same code
paths to get there and so we'll always consume it.
2024-01-25 19:52:00 -05:00
Jan Kassens c7e735f625 Convert ReactLegacyContextDisabled-test.internal to createRoot (#28093)
Convert ReactLegacyContextDisabled-test.internal to createRoot
2024-01-25 16:02:13 -05:00
Jan Kassens 991b72a392 Upgrade flow to 0.227.0 (#28094)
Upgrade flow to 0.227.0
2024-01-25 16:01:40 -05:00
Jan Kassens 7724754573 Convert ReactFreshIntegration-test to createRoot (#28073)
Convert ReactFreshIntegration-test to createRoot
2024-01-25 15:07:57 -05:00
Jan Kassens a7fa58d8b6 Convert ReactDOMInput-test to createRoot (#28084)
Convert ReactDOMInput-test to createRoot
2024-01-25 14:22:12 -05:00
Ricky 0b32b3edd2 Convert ReactCompositeComponentState to createRoot (#28063) 2024-01-25 13:36:04 -05:00
Sebastian Silbermann 43a3653b19 Convert ReactContextValidator to createRoot (#28085) 2024-01-25 18:37:07 +01:00
Jack Pope a41ebfc5f6 Use createRoot in useFocus-test (#28083) 2024-01-25 12:10:56 -05:00
Sebastian Markbåge b123b9c4f0 [Flight] Refactor the Render Loop to Behave More Like Fizz (#28065)
This refactors the Flight render loop to behave more like Fizz with
similar naming conventions. So it's easier to apply similar techniques
across both. This is not necessarily better/faster - at least not yet.

This doesn't yet implement serialization by writing segments to chunks
but we probably should do that since the built-in parts that
`JSON.stringify` gets us isn't really much anymore (except serializing
strings). When we switch to that it probably makes sense for the whole
thing to be recursive.

Right now it's not technically fully recursive because each recursive
render returns the next JSON value to encode. So it's kind of like a
trampoline. This means we can't have many contextual things on the
stack. It needs to use the Server Context `__POP` trick. However, it
does work for things that are contextual only for one sequence of server
component abstractions in a row. Since those are now recursive.

An interesting observation here is that `renderModel` means that
anything can suspend while still serializing the outer siblings.
Typically only Lazy or Components would suspend but in principle a Proxy
can suspend/postpone too and now that is left serialized by reference to
a future value. It's only if the thing that we rendered was something
that can reduce to Lazy e.g. an Element that we can serialize it as a
lazy.

Similarly to how Suspense boundaries in Fizz can catch errors, anything
that can be reduced to Lazy can also catch an error rather than bubbling
it. It only errors when the Lazy resolves. Unlike Suspense boundaries
though, those things don't render anything so they're otherwise going to
use the destructive form. To ensure that throwing in an Element can
reuse the current task, this must be handled by `renderModel`, not for
example `renderElement`.
2024-01-25 12:09:11 -05:00
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