Commit Graph
1861 Commits
Author SHA1 Message Date
Sebastian MarkbågeandGitHub c77dae88f4 Remove __self and __source location from elements (#28265)
Along with all the places using it like the `_debugSource` on Fiber.
This still lets them be passed into `createElement` (and JSX dev
runtime) since those can still be used in existing already compiled code
and we don't want that to start spreading to DOM attributes.

We used to have a DEV mode that compiles the source location of JSX into
the compiled output. This was nice because we could get the actual call
site of the JSX (instead of just somewhere in the component). It had a
bunch of issues though:

- It only works with JSX.
- The way this source location is compiled is different in all the
pipelines along the way. It relies on this transform being first and the
source location we want to extract but it doesn't get preserved along
source maps and don't have a way to be connected to the source hosted by
the source maps. Ideally it should just use the mechanism other source
maps use.
- Since it's expensive it only works in DEV so if it's used for
component stacks it would vary between dev and prod.
- It only captures the callsite of the JSX and not the stack between the
component and that callsite. In the happy case it's in the component but
not always.

Instead, we have another zero-cost trick to extract the call site of
each component lazily only if it's needed. This ensures that component
stacks are the same in DEV and PROD. At the cost of worse line number
information.

The better way to get the JSX call site would be to get it from `new
Error()` or `console.createTask()` inside the JSX runtime which can
capture the whole stack in a consistent way with other source mappings.
We might explore that in the future.

This removes source location info from React DevTools and React Native
Inspector. The "jump to source code" feature or inspection can be made
lazy instead by invoking the lazy component stack frame generation. That
way it can be made to work in prod too. The filtering based on file path
is a bit trickier.

When redesigned this UI should ideally also account for more than one
stack frame.

With this change the DEV only Babel transforms are effectively
deprecated since they're not necessary for anything.
2024-02-07 16:38:00 -05:00
7fd6b17039 Convert ReactRenderDocument to hydrateRoot (#28153)
Co-authored-by: Sebastian Silbermann <[email protected]>
2024-02-07 09:54:46 -05:00
RickyandGitHub 1a5d7dd130 [Tests] Reset modules by default (#28254)
## Overview

Sets `resetModules: true` in the base Jest config, and deletes all the
`jest.resetModule()` calls we don't need.
2024-02-06 12:43:27 -05:00
RickyandGitHub 913338badb Convert ReactBrowserEventEmitter to createRoot (#28253)
pretty boring
2024-02-06 10:43:37 -05:00
Josh StoryandGitHub 74557f272c Update ReactDOMServerSuspense-test to not use legacy rendering APIs (#28251)
Updates ReactDOMServerSuspense-test to not use legacy rendering APIs
Also removes an experimental only gate that is not necessary
2024-02-05 21:25:22 -08:00
Andrew ClarkandGitHub 0a71ac160b Upgrade tests to use react/jsx-runtime (#28252)
Instead of createElement.

We should have done this when we initially released jsx-runtime but
better late than never. The general principle is that our tests should
be written using the most up-to-date idioms that we recommend for users,
except when explicitly testing an edge case or legacy behavior, like for
backwards compatibility.

Most of the diff is related to tweaking test output and isn't very
interesting.

I did have to workaround an issue related to component stacks. The
component stack logic depends on shared state that lives in the React
module. The problem is that most of our tests reset the React module
state and re-require a fresh instance of React, React DOM, etc. However,
the JSX runtime is not re-required because it's injected by the compiler
as a static import. This means its copy of the shared state is no longer
the same as the one used by React, causing any warning logged by the JSX
runtime to not include a component stack. (This same issue also breaks
string refs, but since we're removing those soon I'm not so concerned
about that.) The solution I went with for now is to mock the JSX runtime
with a proxy that re-requires the module on every function invocation. I
don't love this but it will have to do for now. What we should really do
is migrate our tests away from manually resetting the module state and
use import syntax instead.
2024-02-05 23:07:41 -05:00
danandGitHub c8865a2cda [Flight] Delete Server Context (#28225)
Server Context was never documented, and has been deprecated in
https://github.com/facebook/react/pull/27424.

This PR removes it completely, including the implementation code.

Notably, `useContext` is removed from the shared subset, so importing it
from a React Server environment would now should be a build error in
environments that are able to enforce that.
2024-02-05 22:39:15 +00:00
Sebastian SilbermannandGitHub cd70e79dda Convert ReactMultiChildReconcile to createRoot (#28169) 2024-02-04 15:44:46 +01:00
Sebastian SilbermannandGitHub c821c4e9c5 Convert ReactDOMEventPropagation to createRoot (#28177) 2024-02-04 11:29:06 +01:00
Sebastian SilbermannandGitHub c8b30f0ef7 Convert ReactDOMSuspensePlaceholder to createRoot (#28168) 2024-02-04 11:02:22 +01:00
Matt CarrollandGitHub 2084c4540c Convert ReactErrorBoundaries-test.internal.js to createRoot (#28122) 2024-02-02 17:41:56 -08:00
Sebastian SilbermannandGitHub bc32ac8e8b Convert SyntheticMouseEvent to createRoot (#28200) 2024-02-02 16:52:29 +01:00
Sebastian SilbermannandGitHub 937dc1fa5d Convert BeforeInputEventPlugin to createRoot (#28199) 2024-02-02 16:52:19 +01:00
Sebastian SilbermannandGitHub a7a5c3ec22 Convert multiple-copies-of-react to createRoot (#28198) 2024-02-02 09:15:53 +01:00
Sebastian SilbermannandGitHub 702f2d673f Convert ReactDOMIframe to createRoot (#28197) 2024-02-02 09:15:43 +01:00
Sebastian SilbermannandGitHub 903efc9f71 Convert ReactCompositeComponentDOMMinimalism to createRoot (#28194)
Not sure if this was also meant to test findDOMNode. But sounded like it
was more interested in the rendering aspect and findDOMNode was just
used as a utility. If we want to keep the findDOMNode tests, I'd just
rename it to a legacy test to indicate it needs to be flagged.
2024-02-02 09:15:19 +01:00
Sebastian SilbermannandGitHub f543a3a459 Convert ReactChildReconciler to createRoot (#28192) 2024-02-02 09:15:10 +01:00
Sebastian SilbermannandGitHub c1d50802f7 Convert EnterLeaveEventPlugin to createRoot (#28182) 2024-02-02 09:14:52 +01:00
Sebastian SilbermannandGitHub bc7237b2a3 Convert CSSProperty to createRoot (#28181) 2024-02-02 09:14:43 +01:00
Sebastian SilbermannandGitHub e4151df8c2 Convert InvalidEventListeners to createRoot (#28180) 2024-02-02 09:14:34 +01:00
Sebastian SilbermannandGitHub 03be063d66 Convert ReactComponentLifeycle to createRoot (#28178) 2024-02-02 09:14:25 +01:00
Sebastian SilbermannandGitHub d7986df8aa Remove usage of /test-utils in ReactLegacyCompositeComponent (#28201) 2024-02-02 09:14:05 +01:00
Sebastian SilbermannandGitHub e3898ac076 Convert ReactDOMSelection to createRoot (#28176) 2024-02-02 08:58:30 +01:00
RickyandGitHub 21de6ad79f 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 SilbermannandGitHub 629b13165e Convert ReactComponent to createRoot (#28171) 2024-02-01 18:50:38 -05:00
Sebastian SilbermannandGitHub 80065b3100 Convert SyntheticFocusEvent to createRoot (#28173) 2024-02-01 18:49:40 -05:00
Sebastian SilbermannandGitHub a51375f5cf Convert SyntheticClipboardEvent to createRoot (#28174) 2024-02-01 18:49:18 -05:00
Sebastian SilbermannandGitHub f0a34c4030 Convert ReactErrorBoundariesHooks to createRoot (#28175) 2024-02-01 18:48:58 -05:00
RickyandGitHub e1d880d499 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
e249b76477 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 <[email protected]>
2024-02-01 18:32:27 -05:00
d3fd0eeeb0 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 <[email protected]>
2024-02-01 18:32:18 -05:00
RickyandGitHub b956b871ce 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
RickyandGitHub be3585c742 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
RickyandGitHub e17a45aa08 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
RickyandGitHub 6c89398d89 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 ClarkandGitHub 424201eb6a 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 StoryandGitHub 00388bcfe9 [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 SilbermannandGitHub 56cab852ba 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 SilbermannandGitHub 7e59ba86e4 Convert trustedTypes to createRoot (#28163) 2024-01-30 22:22:33 +01:00
Sebastian SilbermannandGitHub 06a43acccf Convert SimpleEventPlugin to createRoot (#28164) 2024-01-30 22:22:02 +01:00
Josh StoryandGitHub 5824218507 [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 SilbermannandGitHub cadef9b3eb 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
RickyandGitHub cfb4091916 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 SilbermannandGitHub 7239d38e1d Convert ReactDOMTextarea to createRoot (#28126)
Also removes usage of `ReactTestUtils`
2024-01-29 17:02:20 +01:00
Sebastian SilbermannandGitHub b12ef5c572 Convert DOMPluginEventSystem to createRoot (#28139) 2024-01-29 09:12:20 +01:00
Sebastian SilbermannandGitHub 5f9c147e51 Convert ReactMultiChildText to createRoot (#28140) 2024-01-29 09:11:24 +01:00
Sebastian SilbermannandGitHub 866499a334 Convert ReactDOMTextComponent to createRoot (#28141) 2024-01-29 09:11:02 +01:00
Sebastian SilbermannandGitHub 42027243db Convert ReactDOMSelect to createRoot (#28142) 2024-01-29 09:10:34 +01:00
Sebastian SilbermannandGitHub f755786bc6 Convert refs to createRoot (#28113) 2024-01-28 10:41:47 +01:00
Sebastian SilbermannandGitHub 351b3c4f77 Convert ReactDOMInvalidARIAHook to createRoot (#28129) 2024-01-27 16:08:01 -05:00