Commit Graph

1695 Commits

Author SHA1 Message Date
Sebastian Silbermann f8b26862d6 Convert CSSProperty to createRoot (#28181) 2024-02-02 09:14:43 +01:00
Sebastian Silbermann f28f022f22 Convert InvalidEventListeners to createRoot (#28180) 2024-02-02 09:14:34 +01:00
Sebastian Silbermann e9c13cde64 Convert ReactComponentLifeycle to createRoot (#28178) 2024-02-02 09:14:25 +01:00
Sebastian Silbermann 11aa263844 Remove usage of /test-utils in ReactLegacyCompositeComponent (#28201) 2024-02-02 09:14:05 +01:00
Sebastian Silbermann 7f8798a3f2 Convert ReactDOMSelection to createRoot (#28176) 2024-02-02 08:58:30 +01:00
Ricky b25dcd3958 Add ReactDOMClient to ServerIntegration tests (minor fixes) (#28131)
## Overview 

Branched off https://github.com/facebook/react/pull/28130

Converts to `createRoot`, with a few additional in-line conversions in
each file.
2024-02-01 19:01:16 -05:00
Sebastian Silbermann 44952dc984 Convert ReactComponent to createRoot (#28171) 2024-02-01 18:50:38 -05:00
Sebastian Silbermann a7f1622117 Convert SyntheticFocusEvent to createRoot (#28173) 2024-02-01 18:49:40 -05:00
Sebastian Silbermann bc219090e3 Convert SyntheticClipboardEvent to createRoot (#28174) 2024-02-01 18:49:18 -05:00
Sebastian Silbermann c39ec17e66 Convert ReactErrorBoundariesHooks to createRoot (#28175) 2024-02-01 18:48:58 -05:00
Ricky 4bd5e3ea5c Add ReactDOMClient to ServerIntegrationReconnecting (#28136)
## Overview

Branched off https://github.com/facebook/react/pull/28130

## Why

In https://github.com/facebook/react/pull/24276 we changed the new root
behavior to error when a client-render is forced for certain cases, so
these now expect a mismatch even though they're using
`suppressHydrationWarning`.
2024-02-01 18:32:38 -05:00
Ricky fa6674b5bc Add ReactDOMClient to ServerIntegration(Hooks|NewContext) (#28135)
## Overview

Branched off https://github.com/facebook/react/pull/28130

### ~Failing~ Fixed by @eps1lon 
Most of the tests pass, but there are 3 tests that have additional
warnings due to client render error retries.

For example, before we would log:

```
Warning: Do not call Hooks inside useEffect(...), useMemo(...), or other built-in Hooks.
Warning: Expected server HTML to contain a matching text node for "0" in <div>.
```

And now we log

```
Warning: Do not call Hooks inside useEffect(...), useMemo(...), or other built-in Hooks.
Warning: Expected server HTML to contain a matching text node for "0" in <div>.
Warning: Do not call Hooks inside useEffect(...), useMemo(...), or other built-in Hooks.
```

We can't just update the expected error count for these tests, because
the additional error only happens on the client. So I need some guidance
on how to fix these.

---------

Co-authored-by: Sebastian Silbermann <sebastian.silbermann@klarna.com>
2024-02-01 18:32:27 -05:00
Ricky c0d9277130 Add ReactDOMClient to ServerIntegrationElements (#28134)
## Overview 

Branched off https://github.com/facebook/react/pull/28130

## ~Failing~ Fixed by @eps1lon 

The tests are currently failing because of two tests covering special
characters. I've tried a few ways to fix, but I'm stuck and will need
some help understanding why they fail and how to fix.

---------

Co-authored-by: Sebastian Silbermann <sebastian.silbermann@klarna.com>
2024-02-01 18:32:18 -05:00
Ricky 278199b3de Add ReactDOMClient to ServerIntegrationBasic (#28133)
## Overview

Branched off https://github.com/facebook/react/pull/28130

In `hydrateRoot`, we now error if you pass `undefined`:

```
Warning: Must provide initial children as second argument to hydrateRoot. 
```

So we expect 1 error for this now.
2024-02-01 18:32:04 -05:00
Ricky c42e7c7adc Add ReactDOMClient to ServerIntegrationSelect (#28132)
## Overview

Branched off https://github.com/facebook/react/pull/28130

## React for count changing
### Before
These tests are weird because on main they pass, but log to the console:

```
We expected 2 warning(s), but saw 1 warning(s).
We saw these warnings:
    Warning: Expected server HTML to contain a matching <select> in <div>.
        at select
```

The other one is ignored. The `expect(console.errors).toBeCalledWith(2)`
doesn't account for ignored calls, so the test passes with the two
expected (the +1 is in the test utiles). The ignored warning is

```
Warning: ReactDOM.hydrate is no longer supported in React 18. Use hydrateRoot instead. 
```

So the mismatch is in the ignored warnings. 

### After

After switching to `createRoot`, it still logs:

```
We expected 2 warning(s), but saw 1 warning(s).
We saw these warnings:
    Warning: Expected server HTML to contain a matching <select> in <div>.
        at select
```

But the test fails due to an unexpected error count. The new ignored
errors are:

```
Error: Uncaught [Error: Hydration failed because the initial UI does not match what was rendered on the server.]
Warning: An error occurred during hydration. The server HTML was replaced with client content in <div>.
Error: Hydration failed because the initial UI does not match what was rendered on the server.
Error: There was an error while hydrating. Because the error happened outside of a Suspense boundary, the entire root will switch to client rendering.
```

These seem to be the correct warnings to fire in `createRoot`, so the
fix is to update the number of warnings we expect.
2024-02-01 18:31:52 -05:00
Ricky 6054be9c86 Add ReactDOMClient to ServerIntegrationTestUtils (#28130)
## Overview

Adds support for `ReactDOMClient` for  `ServerIntegration*` tests. 

Also converts tests that pass without any other changes. Will follow up
with other PRs for more complex cases.
2024-02-01 18:26:33 -05:00
Ricky 3d1da1f9ab Remove createRootStrictEffectsByDefault flag (#28102)
There's no need to separate strict mode from strict effects mode any
more.

I didn't clean up the `StrictEffectMode` fiber flag, because it's used
to prevent strict effects in legacy mode. I could replace those checks
with `LegacyMode` checks, but when we remove legacy mode, we can remove
that flag and condense them into one StrictMode flag away.
2024-02-01 14:54:20 -05:00
Andrew Clark 53b12e46a1 Add stable React.act export (#28160)
Starting in version 19, users can import the `act` testing API from the
`react` package instead of using a renderer specific API, like
`react-dom/test-utils`.
2024-02-01 13:28:14 -05:00
Josh Story 1219d57fc9 [Fizz] Support aborting with Postpone (#28183)
Semantically if you make your reason for aborting a Postpone instance
the render should not hit the error pathways but should instead follow
the postpone pathways. It's awkward today to actually get your hands on
a Postpone instance because you have to catch the throw from postpone
and then pass that into `abort()` or `AbortController.abort()`
(depending on the renderer API you are using)

This change makes it so that in most circumstances if you abort with a
postpone the `onPostpone` handler will be called and the Suspense
boundaries still pending will be put into client render mode with the
appropriate postpone digest to avoid trigger recoverable error pathways
on the client.

Similar to postponing in the shell during a resume or render however if
you abort before the shell is complete in a resume or render we will
fatally error. The fatal error is contextualized by React to avoid
passing the postpone object itself to the `onError` and related options.
2024-02-01 07:14:08 -08:00
Sebastian Silbermann f3ce87ab65 Restore old behavior for empty href props on anchor tags (#28124)
Treat `<a href="" />` the same with and without
`enableFilterEmptyStringAttributesDOM`

in https://github.com/facebook/react/pull/18513 we started to warn and
ignore for empty `href` and `src` props since it usually hinted at a
mistake. However, for anchor tags there's a valid use case since `<a
href=""></a>` will by spec render a link to the current page. It could
be used to reload the page without having to rely on browser
affordances.

The implementation for Fizz is in the spirit of
https://github.com/facebook/react/pull/21153. I gated the fork behind
the flag so that the fork is DCE'd when the flag is off.
2024-01-31 00:43:40 +01:00
Sebastian Silbermann af7e8c7a71 Convert trustedTypes to createRoot (#28163) 2024-01-30 22:22:33 +01:00
Sebastian Silbermann 13aae52aea Convert SimpleEventPlugin to createRoot (#28164) 2024-01-30 22:22:02 +01:00
Josh Story 554fc49f41 [Fizz] improve Hoistable handling for Elements and Resources inside Suspense Boundaries (#28069)
Updates Fizz to handle Hoistables (Resources and Elements) in a way that
better aligns with Suspense fallbacks

1. Hoistable Elements inside a fallback (regardless of how deep and how
many additional boundaries are intermediate) will be ignored. The
reasoning is fallbacks are transient and since there is not good way to
clean up hoistables because they escape their Suspense container its
better to not emit them in the first place. SSR fallbacks are already
not full fidelity because they never hydrate so this aligns with that
somewhat.
2. Hoistable stylesheets in fallbacks will only block the reveal of a
parent suspense boundary if the fallback is going to flush with that
completed parent suspense boundary. Previously if you rendered a
stylesheet Resource inside a fallback any parent suspense boundaries
that completed after the shell flushed would include that resource in
the set required to resolve before the boundary reveal happens on the
client. This is not a semantic change, just a performance optimization
3. preconnect and preload hoistable queues are gone, if you want to
optimize resource loading you shoudl use `ReactDOM.preconnect` and
`ReactDOM.preload`. `viewport` meta tags get their own queue because
they need to go before any preloads since they affect the media state.

In addition to those functional changes this PR also refactors the
boundary resource tracking by moving it to the task rather than using
function calls at the start of each render and flush. Tasks also now
track whether they are a fallback task

supercedes prior work here: https://github.com/facebook/react/pull/27534
2024-01-30 10:14:59 -08:00
Sebastian Silbermann 2477384650 Complete DOMPluginEventSystem migration to createRoot (#28148)
Follow-up to
https://github.com/facebook/react/pull/28139#discussion_r1468852457

I mistakenly kept the tests using comment nodes as containers as legacy
tests. It's not that comments nodes aren't allowed in createRoot
entirely. Only behind `disableCommentsAsDOMContainers`. We already had
one test following that pattern so I just applied the same pattern to
the other tests for consistency.

Now `DOMPluginEventSystem` no longer uses any legacy roots.
2024-01-30 09:11:58 +01:00
Ricky 4c73da8cbd Convert ReactCompositeComponent to createRoot (#28099)
Moves tests depending on legacy APIs to `ReactLegacyCompositeComponents`
and updates the rest.
2024-01-29 14:03:16 -05:00
Sebastian Silbermann cdfaae73c4 Convert ReactDOMTextarea to createRoot (#28126)
Also removes usage of `ReactTestUtils`
2024-01-29 17:02:20 +01:00
Sebastian Silbermann 00d42ac354 Convert DOMPluginEventSystem to createRoot (#28139) 2024-01-29 09:12:20 +01:00
Sebastian Silbermann 6d2a1d0334 Convert ReactMultiChildText to createRoot (#28140) 2024-01-29 09:11:24 +01:00
Sebastian Silbermann 313e4d4129 Convert ReactDOMTextComponent to createRoot (#28141) 2024-01-29 09:11:02 +01:00
Sebastian Silbermann 1c8901f750 Convert ReactDOMSelect to createRoot (#28142) 2024-01-29 09:10:34 +01:00
Sebastian Silbermann 7aa45db6a2 Convert refs to createRoot (#28113) 2024-01-28 10:41:47 +01:00
Sebastian Silbermann 3e58b0af0c Convert ReactDOMInvalidARIAHook to createRoot (#28129) 2024-01-27 16:08:01 -05:00
Matt Carroll e2b93afc60 Convert renderSubtreeIntoContainer-test.js to createRoot (#28114)
Co-authored-by: Ricky <rickhanlonii@gmail.com>
2024-01-26 19:30:02 -05:00
Jack Pope 407faf5a69 Remove ReactDOM.render tests in ReactDOMConsoleErrorReporting-test (#28053)
Each it block here was duplicated to cover ReactDOM.render and
ReactDOMClient.createRoot. Here we delete the ReactDOM.render coverage.

Co-authored-by: Jack Pope <jackpope@meta.com>
2024-01-26 19:29:45 -05:00
Jack Pope 91212b09ed Clean up legacy render from ReactTestUtilsAct-test (#28091)
Co-authored-by: Jack Pope <jackpope@meta.com>
2024-01-26 19:29:25 -05:00
Jack Pope 54f2314e9c Use createRoot in ReactMockedComponent-test (#28087)
Co-authored-by: Jack Pope <jackpope@meta.com>
2024-01-26 17:28:58 -05:00
Jack Pope 4c41c09ccc Use createRoot in ReactDOMComponentTree-test (#28112) 2024-01-26 17:18:03 -05:00
Jack Pope 38997cf19a Use createRoot in ReactTestUtilsActUnmockedScheduler-test (#28086) 2024-01-26 17:17:34 -05:00
Matt Carroll 37bdff675c Convert ReactIdentity-test.js to createRoot (#28106) 2024-01-26 13:18:48 -08:00
Matt Carroll 759811b062 Convert ReactMultiChild-test.js to createRoot (#28117) 2024-01-26 13:18:19 -08:00
Matt Carroll 8f998bf93f Convert SyntheticEvent-test.js to createRoot (#28118) 2024-01-26 13:17:44 -08:00
Matt Carroll 7c79dafb71 Convert ReactDOMServerIntegrationUntrustedURL-test.js to createRoot (#28105) 2024-01-26 12:18:14 -08:00
Jack Pope 51c380d6ed Use createRoot in ReactEmptyComponent-test (#28095) 2024-01-26 11:37:51 -05: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
Jan Kassens c7e735f625 Convert ReactLegacyContextDisabled-test.internal to createRoot (#28093)
Convert ReactLegacyContextDisabled-test.internal to createRoot
2024-01-25 16:02:13 -05:00