[Flight] Add <Activity> (#34697)

This commit is contained in:
Sebastian "Sebbie" Silbermann 2025-10-02 23:14:52 +02:00 committed by GitHub
parent f89ed71ddf
commit 6a8a8ef326
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 140 additions and 2 deletions

View 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>,
);
});
});

View 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>);
});
});

View File

@ -58,6 +58,7 @@ export {
export {
Children,
REACT_ACTIVITY_TYPE as Activity,
REACT_FRAGMENT_TYPE as Fragment,
REACT_PROFILER_TYPE as Profiler,
REACT_STRICT_MODE_TYPE as StrictMode,
@ -83,6 +84,5 @@ export {
// Experimental
REACT_SUSPENSE_LIST_TYPE as unstable_SuspenseList,
REACT_VIEW_TRANSITION_TYPE as unstable_ViewTransition,
REACT_ACTIVITY_TYPE as unstable_Activity,
captureOwnerStack, // DEV-only
};

View File

@ -57,6 +57,7 @@ export {
export {
Children,
REACT_ACTIVITY_TYPE as Activity,
REACT_FRAGMENT_TYPE as Fragment,
REACT_PROFILER_TYPE as Profiler,
REACT_STRICT_MODE_TYPE as StrictMode,
@ -82,5 +83,4 @@ export {
// Experimental
REACT_SUSPENSE_LIST_TYPE as unstable_SuspenseList,
REACT_VIEW_TRANSITION_TYPE as unstable_ViewTransition,
REACT_ACTIVITY_TYPE as Activity,
};

View File

@ -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 {captureOwnerStack as captureOwnerStackImpl} from './ReactOwnerStack';
import {
REACT_ACTIVITY_TYPE,
REACT_FRAGMENT_TYPE,
REACT_PROFILER_TYPE,
REACT_STRICT_MODE_TYPE,
REACT_SUSPENSE_TYPE,
REACT_SUSPENSE_LIST_TYPE,
REACT_VIEW_TRANSITION_TYPE,
} from 'shared/ReactSymbols';
import {
cloneElement,
@ -45,6 +48,7 @@ if (__DEV__) {
export {
Children,
REACT_ACTIVITY_TYPE as Activity,
REACT_FRAGMENT_TYPE as Fragment,
REACT_PROFILER_TYPE as Profiler,
REACT_STRICT_MODE_TYPE as StrictMode,
@ -65,4 +69,7 @@ export {
useMemo,
version,
captureOwnerStack, // DEV-only
// Experimental
REACT_SUSPENSE_LIST_TYPE as unstable_SuspenseList,
REACT_VIEW_TRANSITION_TYPE as unstable_ViewTransition,
};

View File

@ -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 {
REACT_ACTIVITY_TYPE,
REACT_FRAGMENT_TYPE,
REACT_PROFILER_TYPE,
REACT_STRICT_MODE_TYPE,
@ -40,6 +41,7 @@ const Children = {
export {
Children,
REACT_ACTIVITY_TYPE as Activity,
REACT_FRAGMENT_TYPE as Fragment,
REACT_PROFILER_TYPE as Profiler,
REACT_STRICT_MODE_TYPE as StrictMode,