Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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>,
);
});
});
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this so that we remember to do the same for ViewTransition when we ship it to Canary.

Original file line number Diff line number Diff line change
@@ -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>);
});
});
2 changes: 1 addition & 1 deletion packages/react/src/ReactServer.experimental.development.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
};
2 changes: 1 addition & 1 deletion packages/react/src/ReactServer.experimental.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
};
7 changes: 7 additions & 0 deletions packages/react/src/ReactServer.fb.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
};
2 changes: 2 additions & 0 deletions packages/react/src/ReactServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
Loading