mirror of
https://github.com/zebrajr/react.git
synced 2025-12-06 12:20:20 +01:00
[Flight] Add <Activity> (#34697)
This commit is contained in:
parent
f89ed71ddf
commit
6a8a8ef326
65
packages/react-reconciler/src/__tests__/ActivityReactServer-test.js
vendored
Normal file
65
packages/react-reconciler/src/__tests__/ActivityReactServer-test.js
vendored
Normal file
|
|
@ -0,0 +1,65 @@
|
||||||
|
/**
|
||||||
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||||
|
*
|
||||||
|
* This source code is licensed under the MIT license found in the
|
||||||
|
* LICENSE file in the root directory of this source tree.
|
||||||
|
*
|
||||||
|
* @emails react-core
|
||||||
|
* @jest-environment node
|
||||||
|
*/
|
||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
let act;
|
||||||
|
let Activity;
|
||||||
|
let React;
|
||||||
|
let ReactServer;
|
||||||
|
let ReactNoop;
|
||||||
|
let ReactNoopFlightClient;
|
||||||
|
let ReactNoopFlightServer;
|
||||||
|
|
||||||
|
describe('ActivityReactServer', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
jest.resetModules();
|
||||||
|
jest.mock('react', () => require('react/react.react-server'));
|
||||||
|
ReactServer = require('react');
|
||||||
|
Activity = ReactServer.Activity;
|
||||||
|
ReactNoopFlightServer = require('react-noop-renderer/flight-server');
|
||||||
|
|
||||||
|
jest.resetModules();
|
||||||
|
__unmockReact();
|
||||||
|
React = require('react');
|
||||||
|
ReactNoopFlightClient = require('react-noop-renderer/flight-client');
|
||||||
|
ReactNoop = require('react-noop-renderer');
|
||||||
|
const InternalTestUtils = require('internal-test-utils');
|
||||||
|
act = InternalTestUtils.act;
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
jest.restoreAllMocks();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('can be rendered in React Server', async () => {
|
||||||
|
function App() {
|
||||||
|
return ReactServer.createElement(
|
||||||
|
Activity,
|
||||||
|
{mode: 'hidden'},
|
||||||
|
ReactServer.createElement('div', null, 'Hello, Dave!'),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const transport = ReactNoopFlightServer.render(
|
||||||
|
ReactServer.createElement(App, null),
|
||||||
|
);
|
||||||
|
|
||||||
|
await act(async () => {
|
||||||
|
const app = await ReactNoopFlightClient.read(transport);
|
||||||
|
|
||||||
|
ReactNoop.render(app);
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(ReactNoop).toMatchRenderedOutput(
|
||||||
|
<div hidden={true}>Hello, Dave!</div>,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
64
packages/react-reconciler/src/__tests__/ViewTransitionReactServer-test.js
vendored
Normal file
64
packages/react-reconciler/src/__tests__/ViewTransitionReactServer-test.js
vendored
Normal file
|
|
@ -0,0 +1,64 @@
|
||||||
|
/**
|
||||||
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||||
|
*
|
||||||
|
* This source code is licensed under the MIT license found in the
|
||||||
|
* LICENSE file in the root directory of this source tree.
|
||||||
|
*
|
||||||
|
* @emails react-core
|
||||||
|
* @jest-environment node
|
||||||
|
*/
|
||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
let act;
|
||||||
|
let ViewTransition;
|
||||||
|
let React;
|
||||||
|
let ReactServer;
|
||||||
|
let ReactNoop;
|
||||||
|
let ReactNoopFlightClient;
|
||||||
|
let ReactNoopFlightServer;
|
||||||
|
|
||||||
|
describe('ViewTransitionReactServer', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
jest.resetModules();
|
||||||
|
jest.mock('react', () => require('react/react.react-server'));
|
||||||
|
ReactServer = require('react');
|
||||||
|
ViewTransition = ReactServer.unstable_ViewTransition;
|
||||||
|
ReactNoopFlightServer = require('react-noop-renderer/flight-server');
|
||||||
|
|
||||||
|
jest.resetModules();
|
||||||
|
__unmockReact();
|
||||||
|
React = require('react');
|
||||||
|
ReactNoopFlightClient = require('react-noop-renderer/flight-client');
|
||||||
|
ReactNoop = require('react-noop-renderer');
|
||||||
|
const InternalTestUtils = require('internal-test-utils');
|
||||||
|
act = InternalTestUtils.act;
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
jest.restoreAllMocks();
|
||||||
|
});
|
||||||
|
|
||||||
|
// @gate enableViewTransition || fb
|
||||||
|
it('can be rendered in React Server', async () => {
|
||||||
|
function App() {
|
||||||
|
return ReactServer.createElement(
|
||||||
|
ViewTransition,
|
||||||
|
{},
|
||||||
|
ReactServer.createElement('div', null, 'Hello, Dave!'),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const transport = ReactNoopFlightServer.render(
|
||||||
|
ReactServer.createElement(App, null),
|
||||||
|
);
|
||||||
|
|
||||||
|
await act(async () => {
|
||||||
|
const app = await ReactNoopFlightClient.read(transport);
|
||||||
|
|
||||||
|
ReactNoop.render(app);
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(ReactNoop).toMatchRenderedOutput(<div>Hello, Dave!</div>);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
@ -58,6 +58,7 @@ export {
|
||||||
|
|
||||||
export {
|
export {
|
||||||
Children,
|
Children,
|
||||||
|
REACT_ACTIVITY_TYPE as Activity,
|
||||||
REACT_FRAGMENT_TYPE as Fragment,
|
REACT_FRAGMENT_TYPE as Fragment,
|
||||||
REACT_PROFILER_TYPE as Profiler,
|
REACT_PROFILER_TYPE as Profiler,
|
||||||
REACT_STRICT_MODE_TYPE as StrictMode,
|
REACT_STRICT_MODE_TYPE as StrictMode,
|
||||||
|
|
@ -83,6 +84,5 @@ export {
|
||||||
// Experimental
|
// Experimental
|
||||||
REACT_SUSPENSE_LIST_TYPE as unstable_SuspenseList,
|
REACT_SUSPENSE_LIST_TYPE as unstable_SuspenseList,
|
||||||
REACT_VIEW_TRANSITION_TYPE as unstable_ViewTransition,
|
REACT_VIEW_TRANSITION_TYPE as unstable_ViewTransition,
|
||||||
REACT_ACTIVITY_TYPE as unstable_Activity,
|
|
||||||
captureOwnerStack, // DEV-only
|
captureOwnerStack, // DEV-only
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -57,6 +57,7 @@ export {
|
||||||
|
|
||||||
export {
|
export {
|
||||||
Children,
|
Children,
|
||||||
|
REACT_ACTIVITY_TYPE as Activity,
|
||||||
REACT_FRAGMENT_TYPE as Fragment,
|
REACT_FRAGMENT_TYPE as Fragment,
|
||||||
REACT_PROFILER_TYPE as Profiler,
|
REACT_PROFILER_TYPE as Profiler,
|
||||||
REACT_STRICT_MODE_TYPE as StrictMode,
|
REACT_STRICT_MODE_TYPE as StrictMode,
|
||||||
|
|
@ -82,5 +83,4 @@ export {
|
||||||
// Experimental
|
// Experimental
|
||||||
REACT_SUSPENSE_LIST_TYPE as unstable_SuspenseList,
|
REACT_SUSPENSE_LIST_TYPE as unstable_SuspenseList,
|
||||||
REACT_VIEW_TRANSITION_TYPE as unstable_ViewTransition,
|
REACT_VIEW_TRANSITION_TYPE as unstable_ViewTransition,
|
||||||
REACT_ACTIVITY_TYPE as Activity,
|
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -12,10 +12,13 @@ export {default as __SERVER_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRA
|
||||||
import {forEach, map, count, toArray, only} from './ReactChildren';
|
import {forEach, map, count, toArray, only} from './ReactChildren';
|
||||||
import {captureOwnerStack as captureOwnerStackImpl} from './ReactOwnerStack';
|
import {captureOwnerStack as captureOwnerStackImpl} from './ReactOwnerStack';
|
||||||
import {
|
import {
|
||||||
|
REACT_ACTIVITY_TYPE,
|
||||||
REACT_FRAGMENT_TYPE,
|
REACT_FRAGMENT_TYPE,
|
||||||
REACT_PROFILER_TYPE,
|
REACT_PROFILER_TYPE,
|
||||||
REACT_STRICT_MODE_TYPE,
|
REACT_STRICT_MODE_TYPE,
|
||||||
REACT_SUSPENSE_TYPE,
|
REACT_SUSPENSE_TYPE,
|
||||||
|
REACT_SUSPENSE_LIST_TYPE,
|
||||||
|
REACT_VIEW_TRANSITION_TYPE,
|
||||||
} from 'shared/ReactSymbols';
|
} from 'shared/ReactSymbols';
|
||||||
import {
|
import {
|
||||||
cloneElement,
|
cloneElement,
|
||||||
|
|
@ -45,6 +48,7 @@ if (__DEV__) {
|
||||||
|
|
||||||
export {
|
export {
|
||||||
Children,
|
Children,
|
||||||
|
REACT_ACTIVITY_TYPE as Activity,
|
||||||
REACT_FRAGMENT_TYPE as Fragment,
|
REACT_FRAGMENT_TYPE as Fragment,
|
||||||
REACT_PROFILER_TYPE as Profiler,
|
REACT_PROFILER_TYPE as Profiler,
|
||||||
REACT_STRICT_MODE_TYPE as StrictMode,
|
REACT_STRICT_MODE_TYPE as StrictMode,
|
||||||
|
|
@ -65,4 +69,7 @@ export {
|
||||||
useMemo,
|
useMemo,
|
||||||
version,
|
version,
|
||||||
captureOwnerStack, // DEV-only
|
captureOwnerStack, // DEV-only
|
||||||
|
// Experimental
|
||||||
|
REACT_SUSPENSE_LIST_TYPE as unstable_SuspenseList,
|
||||||
|
REACT_VIEW_TRANSITION_TYPE as unstable_ViewTransition,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ export {default as __SERVER_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRA
|
||||||
|
|
||||||
import {forEach, map, count, toArray, only} from './ReactChildren';
|
import {forEach, map, count, toArray, only} from './ReactChildren';
|
||||||
import {
|
import {
|
||||||
|
REACT_ACTIVITY_TYPE,
|
||||||
REACT_FRAGMENT_TYPE,
|
REACT_FRAGMENT_TYPE,
|
||||||
REACT_PROFILER_TYPE,
|
REACT_PROFILER_TYPE,
|
||||||
REACT_STRICT_MODE_TYPE,
|
REACT_STRICT_MODE_TYPE,
|
||||||
|
|
@ -40,6 +41,7 @@ const Children = {
|
||||||
|
|
||||||
export {
|
export {
|
||||||
Children,
|
Children,
|
||||||
|
REACT_ACTIVITY_TYPE as Activity,
|
||||||
REACT_FRAGMENT_TYPE as Fragment,
|
REACT_FRAGMENT_TYPE as Fragment,
|
||||||
REACT_PROFILER_TYPE as Profiler,
|
REACT_PROFILER_TYPE as Profiler,
|
||||||
REACT_STRICT_MODE_TYPE as StrictMode,
|
REACT_STRICT_MODE_TYPE as StrictMode,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user