Commit Graph
16316 Commits
Author SHA1 Message Date
Sebastian SilbermannandGitHub 82e47e83ca Ensure useState and useReducer initializer functions are double invoked in StrictMode (#28248) 2024-02-06 17:53:08 +01:00
Ruslan LesiutinandGitHub 560b0ddf01 chore: use versioned render in storeStressSync test and gate them for legacy rendering (#28216) 2024-02-06 16:51:58 +00:00
Sathya GunasekaranandGitHub 0b12600842 Patch devtools before running useMemo function in strict mode (#28249)
This fixes a regression https://github.com/facebook/react/pull/25583
where we stopped patching before calling useMemo function.

Fixes https://github.com/facebook/react/issues/27989
2024-02-06 16:45:18 +00:00
Ruslan LesiutinandGitHub 8f312757af chore: use versioned render in storeComponentFilters test (#28241) 2024-02-06 16:25:03 +00:00
Ruslan LesiutinandGitHub 30a2ada11e chore: use versioned render in profilerContext test (#28243) 2024-02-06 15:58:11 +00:00
RickyandGitHub 913338badb Convert ReactBrowserEventEmitter to createRoot (#28253)
pretty boring
2024-02-06 10:43:37 -05:00
Ruslan LesiutinandGitHub a65698a427 fix: gate react/jsx-runtime upgrade only for React >= 17 tests (#28256)
https://github.com/facebook/react/pull/28252 broke RDT tests with React
16.x.

These changes gate the `jsx-runtime` upgrade only for cases when we are
testing against React >= 17.

Validated with:
```
 ./scripts/circleci/download_devtools_regression_build.js 16.0 --replaceBuild && node ./scripts/jest/jest-cli.js --build --project devtools --release-channel=experimental --reactVersion 16.0 --ci && ./scripts/circleci/download_devtools_regression_build.js 16.5 --replaceBuild && node ./scripts/jest/jest-cli.js --build --project devtools --release-channel=experimental --reactVersion 16.5 --ci && ./scripts/circleci/download_devtools_regression_build.js 16.8 --replaceBuild && node ./scripts/jest/jest-cli.js --build --project devtools --release-channel=experimental --reactVersion 16.8 --ci && ./scripts/circleci/download_devtools_regression_build.js 17.0 --replaceBuild && node ./scripts/jest/jest-cli.js --build --project devtools --release-channel=experimental --reactVersion 17.0 --ci && ./scripts/circleci/download_devtools_regression_build.js 18.0 --replaceBuild && node ./scripts/jest/jest-cli.js --build --project devtools --release-channel=experimental --reactVersion 18.0 --ci
 ```
2024-02-06 15:03:36 +00:00
Ruslan LesiutinandGitHub b3add067b7 chore: use versioned render in profilingCommitTreeBuilder test and gate some for legacy rendering (#28236) 2024-02-06 12:26:50 +00:00
Ruslan LesiutinandGitHub 598ae02478 chore: use versioned render in profilingHostRoot test and gate some for legacy rendering (#28237) 2024-02-06 11:40:50 +00:00
Ruslan LesiutinandGitHub 8ff8393dfb chore: use versioned render in profilingCache test (#28242) 2024-02-06 11:24:54 +00: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
Josh StoryandGitHub 6a70a27c32 Add flag to disable caching behavior of React.cache on the client (#28250)
Adds a feature flag to control whether the client cache function is just
a passthrough. before we land breaking changes for the next major it
will be off and then we can flag it on when we want to break it.

flag is off for OSS for now and on elsewhere (though the parent flag
enableCache is off in some cases)
2024-02-05 16:32:03 -08: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 MarkbĂĄgeandGitHub 280baaf7e2 [Flight] Support Keyed Server Components (#28123)
Conceptually a Server Component in the tree is the same as a Client
Component.

When we render a Server Component with a key, that key should be used as
part of the reconciliation process to ensure the children's state are
preserved when they move in a set. The key of a child should also be
used to clear the state of the children when that key changes.

Conversely, if a Server Component doesn't have a key it should get an
implicit key based on the slot number. It should not inherit the key of
its children since the children don't know if that would collide with
other keys in the set the Server Component is rendered in.

A Client Component also has an identity based on the function's
implementation type. That mainly has to do with the state (or future
state after a refactor) that Component might contain. To transfer state
between two implementations it needs to be of the same state type. This
is not a concern for a Server Components since they never have state so
identity doesn't matter.

A Component returns a set of children. If it returns a single child,
that's the same as returning a fragment of one child. So if you
conditionally return a single child or a fragment, they should
technically reconcile against each other.

The simple way to do this is to simply emit a Fragment for every Server
Component. That would be correct in all cases. Unfortunately that is
also unfortunate since it bloats the payload in the common cases. It
also means that Fiber creates an extra indirection in the runtime.

Ideally we want to fold Server Component aways into zero cost on the
client. At least where possible. The common cases are that you don't
specify a key on a single return child, and that you do specify a key on
a Server Component in a dynamic set.

The approach in this PR treats a Server Component that returns other
Server Components or Lazy Nodes as a sequence that can be folded away.
I.e. the parts that don't generate any output in the RSC payload.
Instead, it keeps track of their keys on an internal "context". Which
gets reset after each new reified JSON node gets rendered.

Then we transfer the accumulated keys from any parent Server Components
onto the child element. In the simple case, the child just inherits the
key of the parent.

If the Server Component itself is keyless but a child isn't, we have to
add a wrapper fragment to ensure that this fragment gets the implicit
key but we can still use the key to reset state. This is unusual though
because typically if you keyed something it's because it was already in
a fragment.

In the case a Server Component is keyed but forks its children using a
fragment, we need to key that fragment so that the whole set can move
around as one. In theory this could be flattened into a parent array but
that gets tricky if something suspends, because then we can't send the
siblings early.

The main downside of this approach is that switching between single
child and fragment in a Server Component isn't always going to reconcile
against each other. That's because if we saw a single child first, we'd
have to add the fragment preemptively in case it forks later. This
semantic of React isn't very well known anyway and it might be ok to
break it here for pragmatic reasons. The tests document this
discrepancy.

Another compromise of this approach is that when combining keys we don't
escape them fully. We instead just use a simple `,` separated concat.
This is probably good enough in practice. Additionally, since we don't
encode the implicit 0 index slot key, you can move things around between
parents which shouldn't really reconcile but does. This keeps the keys
shorter and more human readable.
2024-02-05 09:33:35 -08:00
Ruslan LesiutinandGitHub 6ca9e03110 chore: use versioned render in ownersListContext test (#28240) 2024-02-05 17:32:31 +00:00
Ruslan LesiutinandGitHub 4d495859eb chore: use versioned render in editing test (#28239) 2024-02-05 17:30:46 +00:00
Ruslan LesiutinandGitHub 413aa1748f chore: use versioned render in treeContext test (#28245) 2024-02-05 17:29:10 +00:00
Ruslan LesiutinandGitHub cc0ddf52d7 chore: use versioned render in store test (#28244) 2024-02-05 17:24:22 +00:00
Ruslan LesiutinandGitHub 3a52aee824 chore: use versioned render in profilerStore test (#28238) 2024-02-05 17:20:05 +00:00
Ruslan LesiutinandGitHub d4906eeb47 chore: use versioned render in profilingCharts test (#28235) 2024-02-05 17:18:32 +00:00
Ruslan LesiutinandGitHub 2c4e20d24a chore: use versioned render in profilerChangeDescriptions test (#28221) 2024-02-05 17:17:07 +00:00
Ruslan LesiutinandGitHub 5ed8b91202 chore: use versioned render in storeOwners test (#28215) 2024-02-05 17:15:16 +00:00
Ruslan LesiutinandGitHub 8a9bfb0096 chore: use versioned render in componentStacks test (#28214) 2024-02-05 17:14:00 +00:00
Ruslan LesiutinandGitHub 5434c61754 chore: use versioned render in console test (#28213) 2024-02-05 17:12:40 +00:00
Ruslan LesiutinandGitHub be8ed55a59 chore: use versioned render in useEditableValue test (#28212) 2024-02-05 17:11:22 +00:00
Ruslan LesiutinandGitHub 7fdfac565a chore: use versioned render in FastRefreshDevToolsIntegration test (#28211) 2024-02-05 17:09:26 +00:00
Ruslan LesiutinandGitHub 651eef76d5 fix: partially revert jest setup config removal to fix regression tests (#28247)
Partially reverting what has been removed in
https://github.com/facebook/react/pull/28186.

We need `'scheduler/tracing'` mock for React >= 16.8.
The error:
```
Invariant Violation: It is not supported to run the profiling version of a renderer (for example, `react-dom/profiling`) without also replacing the `scheduler/tracing` module with `scheduler/tracing-profiling`. Your bundler might have a setting for aliasing both modules. Learn more at http://fb.me/react-profiling
```

Validated by running regression tests for the whole version matrix:
```
./scripts/circleci/download_devtools_regression_build.js 16.0 --replaceBuild && node ./scripts/jest/jest-cli.js --build --project devtools --release-channel=experimental --reactVersion 16.0 --ci && ./scripts/circleci/download_devtools_regression_build.js 16.5 --replaceBuild && node ./scripts/jest/jest-cli.js --build --project devtools --release-channel=experimental --reactVersion 16.5 --ci && ./scripts/circleci/download_devtools_regression_build.js 16.8 --replaceBuild && node ./scripts/jest/jest-cli.js --build --project devtools --release-channel=experimental --reactVersion 16.8 --ci && ./scripts/circleci/download_devtools_regression_build.js 17.0 --replaceBuild && node ./scripts/jest/jest-cli.js --build --project devtools --release-channel=experimental --reactVersion 17.0 --ci && ./scripts/circleci/download_devtools_regression_build.js 18.0 --replaceBuild && node ./scripts/jest/jest-cli.js --build --project devtools --release-channel=experimental --reactVersion 18.0 --ci
```
2024-02-05 17:07:41 +00:00
Ruslan LesiutinandGitHub bac2fe287f chore: add versioned render implementation for DevTools tests (#28210)
Adding getter-functions for renderer implementations, which can be used
for jest tests. If we are testing against React with version < 18, we
are going to use legacy rendering, otherwise the concurrent one.
2024-02-05 15:53:23 +00:00
Ruslan LesiutinandGitHub 0512295bfa chore: add single versioned implementation of act for DevTools tests (#28186)
- Moving `act` implementation to a single getter-function, which is
based on React version we are testing RDT against.
- Removing unused mocks for `act`, which were designed for legacy
versions of React, validated with running tests against React 16 build.
2024-02-05 15:38:48 +00:00
Sebastian SilbermannandGitHub 84d4d3db04 DevTools: Add support for useFormState (#28232)
## Summary

Add support for `useFormState` Hook fixing "Unsupported hook in the
react-debug-tools package: Missing method in Dispatcher: useFormState"
when inspecting components using `useFormState`

## How did you test this change?

- Added test to ReactHooksInspectionIntegration
- Added dedicated section for form actions to devtools-shell
![Screenshot 2024-02-04 at 12 02
05](https://github.com/facebook/react/assets/12292047/bb274789-64b8-4594-963e-87c4b6962144)
2024-02-05 15:39:45 +01: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 623d3b0e1c Convert ReactFresh to createRoot (#28170) 2024-02-04 11:09:49 +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 3e34152524 DevTools: Add support for useOptimistic Hook (#27982)
## Summary

Add support for `useOptimistic` Hook fixing "Unsupported hook in the
react-debug-tools package: Missing method in Dispatcher: useOptimistic"
when inspecting components using `useOptimistic`

## How did you test this change?

- Added test following the same pattern as for `useDeferredValue`
2024-02-02 23:18:16 +01:00
Josh StoryandGitHub 74c368da0b add RSC entrypoint for jsx-runtime (#28217)
Adds a new entrypoint for the production jsx-runtime when using
react-server condition. Currently the entrypoints are the same but in
the future we will potentially change the implementation of the runtime
in ways that can only be optimized for react-server constraints and we
want to have the entrypoint already separated so environments using it
will be pulling in the right version
2024-02-02 13:37:48 -08:00
Noah LemenandGitHub 55de815d45 convert ReactElementValidator-test to createRoot (#28223)
## Summary

Converts `ReactTestUtils.renderIntoDocument` and `ReactDOM.findDOMNode`
to `ReactDOMClient.createRoot`

## How did you test this change?
`yarn test ReactElementValidator`
2024-02-02 15:19:55 -05:00
RickyandGitHub d18c9ef229 Convert ReactJSXElement to createRoot (#28208) 2024-02-02 12:56:30 -05:00
RickyandGitHub d1f990a824 Convert ReactJSXElementValidator to createRoot (#28209) 2024-02-02 12:56:18 -05: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 6591985101 Convert createReactClassIntegration to createRoot (#28196) 2024-02-02 09:15:33 +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 5917fdf078 Convert ReactChildren to createRoot (#28191) 2024-02-02 09:15:01 +01:00
Sebastian SilbermannandGitHub c1d50802f7 Convert EnterLeaveEventPlugin to createRoot (#28182) 2024-02-02 09:14:52 +01:00