Skip to content

Commit

Permalink
Update entry point exports (facebook#21488)
Browse files Browse the repository at this point in the history
The following APIs have been added to the `react` stable entry point:
* `SuspenseList`
* `startTransition`
* `unstable_createMutableSource`
* `unstable_useMutableSource`
* `useDeferredValue`
* `useTransition`

The following APIs have been added or removed from the `react-dom` stable entry point:
* `createRoot`
* `unstable_createPortal` (removed)

The following APIs have been added to the `react-is` stable entry point:
* `SuspenseList`
* `isSuspenseList`

The following feature flags have been changed from experimental to true:
* `enableLazyElements`
* `enableSelectiveHydration`
* `enableSuspenseServerRenderer`
  • Loading branch information
Brian Vaughn authored and koto committed Jun 15, 2021
1 parent 121ee44 commit 16cb430
Show file tree
Hide file tree
Showing 92 changed files with 572 additions and 966 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,6 @@ describe('createSubscription', () => {
expect(Scheduler).toFlushAndYield(['b-1']);
});

// @gate experimental || !enableSyncDefaultUpdates
it('should ignore values emitted by a new subscribable until the commit phase', () => {
const log = [];

Expand Down Expand Up @@ -327,7 +326,7 @@ describe('createSubscription', () => {

// Start React update, but don't finish
if (gate(flags => flags.enableSyncDefaultUpdates)) {
React.unstable_startTransition(() => {
React.startTransition(() => {
ReactNoop.render(<Parent observed={observableB} />);
});
} else {
Expand Down Expand Up @@ -362,7 +361,6 @@ describe('createSubscription', () => {
]);
});

// @gate experimental || !enableSyncDefaultUpdates
it('should not drop values emitted between updates', () => {
const log = [];

Expand Down Expand Up @@ -421,7 +419,7 @@ describe('createSubscription', () => {

// Start React update, but don't finish
if (gate(flags => flags.enableSyncDefaultUpdates)) {
React.unstable_startTransition(() => {
React.startTransition(() => {
ReactNoop.render(<Parent observed={observableB} />);
});
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,10 +366,9 @@ describe('ReactHooksInspectionIntegration', () => {
]);
});

// @gate experimental
it('should support composite useTransition hook', () => {
function Foo(props) {
React.unstable_useTransition();
React.useTransition();
const memoizedValue = React.useMemo(() => 'hello', []);
return <div>{memoizedValue}</div>;
}
Expand All @@ -394,10 +393,9 @@ describe('ReactHooksInspectionIntegration', () => {
]);
});

// @gate experimental
it('should support composite useDeferredValue hook', () => {
function Foo(props) {
React.unstable_useDeferredValue('abc', {
React.useDeferredValue('abc', {
timeoutMs: 500,
});
const [state] = React.useState(() => 'hello', []);
Expand All @@ -424,7 +422,6 @@ describe('ReactHooksInspectionIntegration', () => {
]);
});

// @gate experimental
it('should support composite useOpaqueIdentifier hook', () => {
function Foo(props) {
const id = React.unstable_useOpaqueIdentifier();
Expand Down Expand Up @@ -452,7 +449,6 @@ describe('ReactHooksInspectionIntegration', () => {
});
});

// @gate experimental
it('should support composite useOpaqueIdentifier hook in concurrent mode', () => {
function Foo(props) {
const id = React.unstable_useOpaqueIdentifier();
Expand Down Expand Up @@ -846,37 +842,40 @@ describe('ReactHooksInspectionIntegration', () => {
]);
});

if (__EXPERIMENTAL__) {
it('should support composite useMutableSource hook', () => {
const mutableSource = React.unstable_createMutableSource({}, () => 1);
function Foo(props) {
React.unstable_useMutableSource(
mutableSource,
() => 'snapshot',
() => {},
);
React.useMemo(() => 'memo', []);
return <div />;
}
const renderer = ReactTestRenderer.create(<Foo />);
const childFiber = renderer.root.findByType(Foo)._currentFiber();
const tree = ReactDebugTools.inspectHooksOfFiber(childFiber);
expect(tree).toEqual([
{
id: 0,
isStateEditable: false,
name: 'MutableSource',
value: 'snapshot',
subHooks: [],
},
{
id: 1,
isStateEditable: false,
name: 'Memo',
value: 'memo',
subHooks: [],
},
]);
});
}
it('should support composite useMutableSource hook', () => {
const createMutableSource =
React.createMutableSource || React.unstable_createMutableSource;
const useMutableSource =
React.useMutableSource || React.unstable_useMutableSource;

const mutableSource = createMutableSource({}, () => 1);
function Foo(props) {
useMutableSource(
mutableSource,
() => 'snapshot',
() => {},
);
React.useMemo(() => 'memo', []);
return <div />;
}
const renderer = ReactTestRenderer.create(<Foo />);
const childFiber = renderer.root.findByType(Foo)._currentFiber();
const tree = ReactDebugTools.inspectHooksOfFiber(childFiber);
expect(tree).toEqual([
{
id: 0,
isStateEditable: false,
name: 'MutableSource',
value: 'snapshot',
subHooks: [],
},
{
id: 1,
isStateEditable: false,
name: 'Memo',
value: 'memo',
subHooks: [],
},
]);
});
});
2 changes: 1 addition & 1 deletion packages/react-devtools-core/src/standalone.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
// $FlowFixMe Flow does not yet know about flushSync()
flushSync,
// $FlowFixMe Flow does not yet know about createRoot()
unstable_createRoot as createRoot,
createRoot,
} from 'react-dom';
import Bridge from 'react-devtools-shared/src/bridge';
import Store from 'react-devtools-shared/src/devtools/store';
Expand Down
2 changes: 1 addition & 1 deletion packages/react-devtools-extensions/src/main.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* global chrome */

import {createElement} from 'react';
import {unstable_createRoot as createRoot, flushSync} from 'react-dom';
import {createRoot, flushSync} from 'react-dom';
import Bridge from 'react-devtools-shared/src/bridge';
import Store from 'react-devtools-shared/src/devtools/store';
import {getBrowserName, getBrowserTheme} from './utils';
Expand Down
4 changes: 3 additions & 1 deletion packages/react-devtools-scheduling-profiler/src/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
*/

import {
// $FlowFixMe
unstable_createMutableSource as createMutableSource,
unstable_useMutableSource as useMutableSource,
useLayoutEffect,
// $FlowFixMe
unstable_useMutableSource as useMutableSource,
} from 'react';

import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ describe(preprocessData, () => {
});
});

// @gate experimental && enableSchedulingProfiler
// @gate enableSchedulingProfiler
it('should process a sample createRoot render sequence', () => {
function App() {
const [didMount, setDidMount] = React.useState(false);
Expand Down
2 changes: 1 addition & 1 deletion packages/react-devtools-scheduling-profiler/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import 'regenerator-runtime/runtime';

import * as React from 'react';
// $FlowFixMe Flow does not yet know about createRoot()
import {unstable_createRoot as createRoot} from 'react-dom';
import {createRoot} from 'react-dom';
import nullthrows from 'nullthrows';
import App from './App';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ describe('commit tree', () => {

it('should support Lazy components (createRoot)', async () => {
const container = document.createElement('div');
const root = ReactDOM.unstable_createRoot(container);
const root = ReactDOM.createRoot(container);

utils.act(() => store.profilerStore.startProfiling());
utils.act(() => root.render(<App renderChildren={true} />));
Expand Down Expand Up @@ -226,7 +226,7 @@ describe('commit tree', () => {

it('should support Lazy components that are unmounted before resolving (createRoot)', async () => {
const container = document.createElement('div');
const root = ReactDOM.unstable_createRoot(container);
const root = ReactDOM.createRoot(container);

utils.act(() => store.profilerStore.startProfiling());
utils.act(() => root.render(<App renderChildren={true} />));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ describe('profiling HostRoot', () => {
utils.act(() => store.profilerStore.startProfiling());
utils.act(() => {
const container = document.createElement('div');
const root = ReactDOM.unstable_createRoot(container);
const root = ReactDOM.createRoot(container);
root.render(<App />);
});
utils.act(() => store.profilerStore.stopProfiling());
Expand Down Expand Up @@ -122,7 +122,7 @@ describe('profiling HostRoot', () => {
}

const container = document.createElement('div');
const root = ReactDOM.unstable_createRoot(container);
const root = ReactDOM.createRoot(container);

utils.act(() => store.profilerStore.startProfiling());
utils.act(() => root.render(<App />));
Expand Down
10 changes: 5 additions & 5 deletions packages/react-devtools-shared/src/__tests__/store-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -356,18 +356,18 @@ describe('Store', () => {
};
const Wrapper = ({shouldSuspense}) => (
<React.Fragment>
<React.unstable_SuspenseList revealOrder="forwards" tail="collapsed">
<React.SuspenseList revealOrder="forwards" tail="collapsed">
<Component key="A" />
<React.Suspense fallback={<Loading />}>
{shouldSuspense ? <SuspendingComponent /> : <Component key="B" />}
</React.Suspense>
<Component key="C" />
</React.unstable_SuspenseList>
</React.SuspenseList>
</React.Fragment>
);

const container = document.createElement('div');
const root = ReactDOM.unstable_createRoot(container);
const root = ReactDOM.createRoot(container);
act(() => {
root.render(<Wrapper shouldSuspense={true} />);
});
Expand Down Expand Up @@ -984,7 +984,7 @@ describe('Store', () => {

it('should support Lazy components in (createRoot)', async () => {
const container = document.createElement('div');
const root = ReactDOM.unstable_createRoot(container);
const root = ReactDOM.createRoot(container);

// Render once to start fetching the lazy component
act(() => root.render(<App renderChildren={true} />));
Expand Down Expand Up @@ -1020,7 +1020,7 @@ describe('Store', () => {

it('should support Lazy components that are unmounted before they finish loading in (createRoot)', async () => {
const container = document.createElement('div');
const root = ReactDOM.unstable_createRoot(container);
const root = ReactDOM.createRoot(container);

// Render once to start fetching the lazy component
act(() => root.render(<App renderChildren={true} />));
Expand Down
Loading

0 comments on commit 16cb430

Please sign in to comment.