Skip to content

Commit

Permalink
Promote concurrent mode APIs from experimental to stable
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Vaughn committed May 10, 2021
1 parent ea9b1ad commit 8a0e2ab
Show file tree
Hide file tree
Showing 26 changed files with 50 additions and 118 deletions.
6 changes: 1 addition & 5 deletions packages/react-devtools-scheduling-profiler/src/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@
* @flow
*/

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

import {
updateDisplayDensity,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import * as React from 'react';
import {
createContext,
unstable_startTransition as startTransition,
startTransition,
unstable_useCacheRefresh as useCacheRefresh,
useCallback,
useContext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import * as React from 'react';
import {
useContext,
unstable_useCacheRefresh as useCacheRefresh,
unstable_useTransition as useTransition,
useTransition,
} from 'react';
import Button from '../Button';
import ButtonIcon from '../ButtonIcon';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,7 @@
*/

import * as React from 'react';
import {
unstable_useTransition as useTransition,
useContext,
useRef,
useState,
} from 'react';
import {useTransition, useContext, useRef, useState} from 'react';
import EditableName from './EditableName';
import EditableValue from './EditableValue';
import NewArrayValue from './NewArrayValue';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import {
useMemo,
useReducer,
useRef,
unstable_startTransition as startTransition,
startTransition,
} from 'react';
import {createRegExp} from '../utils';
import {BridgeContext, StoreContext} from '../context';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import type {Wakeable} from 'shared/ReactTypes';
import type {GitHubIssue} from './githubAPI';

import {unstable_getCacheForType} from 'react';
import {unstable_getCacheForType as getCacheForType} from 'react';
import {searchGitHubIssues} from './githubAPI';

const API_TIMEOUT = 3000;
Expand Down Expand Up @@ -55,7 +55,7 @@ function createMap(): GitHubIssueMap {
}

function getRecordMap(): Map<string, Record<GitHubIssue>> {
return unstable_getCacheForType(createMap);
return getCacheForType(createMap);
}

export function findGitHubIssue(errorMessage: string): GitHubIssue | null {
Expand Down
6 changes: 3 additions & 3 deletions packages/react-devtools-shared/src/inspectedElementCache.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
*/

import {
unstable_getCacheForType,
unstable_startTransition as startTransition,
unstable_getCacheForType as getCacheForType,
startTransition,
} from 'react';
import Store from './devtools/store';
import {inspectElement as inspectElementMutableSource} from './inspectedElementMutableSource';
Expand Down Expand Up @@ -60,7 +60,7 @@ function createMap(): InspectedElementMap {
}

function getRecordMap(): WeakMap<Element, Record<InspectedElementFrontend>> {
return unstable_getCacheForType(createMap);
return getCacheForType(createMap);
}

function createCacheSeed(
Expand Down
7 changes: 1 addition & 6 deletions packages/react-devtools-shell/src/app/SuspenseTree/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,7 @@
*/

import * as React from 'react';
import {
Fragment,
Suspense,
unstable_SuspenseList as SuspenseList,
useState,
} from 'react';
import {Fragment, Suspense, SuspenseList, useState} from 'react';

function SuspenseTree() {
return (
Expand Down
3 changes: 1 addition & 2 deletions packages/react-dom/index.classic.fb.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,14 @@ export {
__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,
createPortal,
createRoot,
createRoot as unstable_createRoot,
createRoot as unstable_createRoot, // TODO Remove once callsites use createRoot
findDOMNode,
flushSync,
hydrate,
render,
unmountComponentAtNode,
unstable_batchedUpdates,
unstable_createEventHandle,
unstable_createPortal, // Temporary alias
unstable_flushControlled,
unstable_isNewReconciler,
unstable_renderSubtreeIntoContainer,
Expand Down
3 changes: 1 addition & 2 deletions packages/react-dom/index.experimental.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@
export {
__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,
createPortal,
createRoot as unstable_createRoot,
createRoot,
findDOMNode,
flushSync,
hydrate,
render,
unmountComponentAtNode,
unstable_batchedUpdates,
unstable_createPortal, // Temporary alias
unstable_flushControlled,
unstable_renderSubtreeIntoContainer,
unstable_runWithPriority, // DO NOT USE: Temporarily exposed to migrate off of Scheduler.runWithPriority.
Expand Down
1 change: 0 additions & 1 deletion packages/react-dom/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export {
unmountComponentAtNode,
unstable_batchedUpdates,
unstable_createEventHandle,
unstable_createPortal, // Temporary alias
unstable_flushControlled,
unstable_isNewReconciler,
unstable_renderSubtreeIntoContainer,
Expand Down
2 changes: 1 addition & 1 deletion packages/react-dom/index.modern.fb.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export {
__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,
createPortal,
createRoot,
createRoot as unstable_createRoot,
createRoot as unstable_createRoot, // TODO Remove once callsites use createRoot
flushSync,
unstable_batchedUpdates,
unstable_createEventHandle,
Expand Down
2 changes: 1 addition & 1 deletion packages/react-dom/index.stable.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
export {
__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,
createPortal,
createRoot,
findDOMNode,
flushSync,
hydrate,
render,
unmountComponentAtNode,
unstable_batchedUpdates,
unstable_createPortal, // Temporary alias
unstable_renderSubtreeIntoContainer,
version,
} from './src/client/ReactDOM';
28 changes: 0 additions & 28 deletions packages/react-dom/src/__tests__/ReactDOMFiber-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,34 +246,6 @@ describe('ReactDOMFiber', () => {
expect(container.innerHTML).toBe('');
});

// TODO: remove in React 18
if (!__EXPERIMENTAL__) {
it('should support unstable_createPortal alias', () => {
const portalContainer = document.createElement('div');

expect(() =>
ReactDOM.render(
<div>
{ReactDOM.unstable_createPortal(<div>portal</div>, portalContainer)}
</div>,
container,
),
).toWarnDev(
'The ReactDOM.unstable_createPortal() alias has been deprecated, ' +
'and will be removed in React 18+. Update your code to use ' +
'ReactDOM.createPortal() instead. It has the exact same API, ' +
'but without the "unstable_" prefix.',
{withoutStack: true},
);
expect(portalContainer.innerHTML).toBe('<div>portal</div>');
expect(container.innerHTML).toBe('<div></div>');

ReactDOM.unmountComponentAtNode(container);
expect(portalContainer.innerHTML).toBe('');
expect(container.innerHTML).toBe('');
});
}

it('should render many portals', () => {
const portalContainer1 = document.createElement('div');
const portalContainer2 = document.createElement('div');
Expand Down
24 changes: 0 additions & 24 deletions packages/react-dom/src/client/ReactDOM.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ setAttemptHydrationAtCurrentPriority(attemptHydrationAtCurrentPriority);
setGetCurrentUpdatePriority(getCurrentUpdatePriority);
setAttemptHydrationAtPriority(runWithPriority);

let didWarnAboutUnstableCreatePortal = false;
let didWarnAboutUnstableRenderSubtreeIntoContainer = false;

if (__DEV__) {
Expand Down Expand Up @@ -155,25 +154,6 @@ function renderSubtreeIntoContainer(
);
}

function unstable_createPortal(
children: ReactNodeList,
container: Container,
key: ?string = null,
) {
if (__DEV__) {
if (!didWarnAboutUnstableCreatePortal) {
didWarnAboutUnstableCreatePortal = true;
console.warn(
'The ReactDOM.unstable_createPortal() alias has been deprecated, ' +
'and will be removed in React 18+. Update your code to use ' +
'ReactDOM.createPortal() instead. It has the exact same API, ' +
'but without the "unstable_" prefix.',
);
}
}
return createPortal(children, container, key);
}

const Internals = {
// Keep in sync with ReactTestUtils.js, and ReactTestUtilsAct.js.
// This is an array for better minification.
Expand Down Expand Up @@ -206,10 +186,6 @@ export {
scheduleHydration as unstable_scheduleHydration,
// Disabled behind disableUnstableRenderSubtreeIntoContainer
renderSubtreeIntoContainer as unstable_renderSubtreeIntoContainer,
// Disabled behind disableUnstableCreatePortal
// Temporary alias since we already shipped React 16 RC with it.
// TODO: remove in React 18.
unstable_createPortal,
// enableCreateEventHandleAPI
createEventHandle as unstable_createEventHandle,
// TODO: Remove this once callers migrate to alternatives.
Expand Down
4 changes: 2 additions & 2 deletions packages/react-is/index.experimental.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export {
Profiler,
StrictMode,
Suspense,
unstable_SuspenseList,
SuspenseList,
isAsyncMode,
isConcurrentMode,
isContextConsumer,
Expand All @@ -37,5 +37,5 @@ export {
isProfiler,
isStrictMode,
isSuspense,
unstable_isSuspenseList,
isSuspenseList,
} from './src/ReactIs';
2 changes: 2 additions & 0 deletions packages/react-is/index.stable.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export {
Profiler,
StrictMode,
Suspense,
SuspenseList,
isAsyncMode,
isConcurrentMode,
isContextConsumer,
Expand All @@ -36,4 +37,5 @@ export {
isProfiler,
isStrictMode,
isSuspense,
isSuspenseList,
} from './src/ReactIs';
4 changes: 2 additions & 2 deletions packages/react-is/src/ReactIs.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export const Portal = REACT_PORTAL_TYPE;
export const Profiler = REACT_PROFILER_TYPE;
export const StrictMode = REACT_STRICT_MODE_TYPE;
export const Suspense = REACT_SUSPENSE_TYPE;
export const unstable_SuspenseList = REACT_SUSPENSE_LIST_TYPE;
export const SuspenseList = REACT_SUSPENSE_LIST_TYPE;

export {isValidElementType};

Expand Down Expand Up @@ -143,6 +143,6 @@ export function isStrictMode(object: any) {
export function isSuspense(object: any) {
return typeOf(object) === REACT_SUSPENSE_TYPE;
}
export function unstable_isSuspenseList(object: any) {
export function isSuspenseList(object: any) {
return typeOf(object) === REACT_SUSPENSE_LIST_TYPE;
}
15 changes: 7 additions & 8 deletions packages/react-is/src/__tests__/ReactIs-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,22 +186,21 @@ describe('ReactIs', () => {
expect(ReactIs.isSuspense(<div />)).toBe(false);
});

// @gate experimental
it('should identify suspense list', () => {
expect(ReactIs.isValidElementType(React.unstable_SuspenseList)).toBe(true);
expect(ReactIs.typeOf(<React.unstable_SuspenseList />)).toBe(
ReactIs.unstable_SuspenseList,
expect(ReactIs.isValidElementType(React.SuspenseList)).toBe(true);
expect(ReactIs.typeOf(<React.SuspenseList />)).toBe(
ReactIs.SuspenseList,
);
expect(
ReactIs.unstable_isSuspenseList(<React.unstable_SuspenseList />),
ReactIs.isSuspenseList(<React.SuspenseList />),
).toBe(true);
expect(
ReactIs.unstable_isSuspenseList({type: ReactIs.unstable_SuspenseList}),
ReactIs.isSuspenseList({type: ReactIs.SuspenseList}),
).toBe(false);
expect(ReactIs.unstable_isSuspenseList('React.unstable_SuspenseList')).toBe(
expect(ReactIs.isSuspenseList('React.SuspenseList')).toBe(
false,
);
expect(ReactIs.unstable_isSuspenseList(<div />)).toBe(false);
expect(ReactIs.isSuspenseList(<div />)).toBe(false);
});

it('should identify profile root', () => {
Expand Down
8 changes: 4 additions & 4 deletions packages/react/index.classic.fb.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export {
StrictMode,
Suspense,
SuspenseList,
SuspenseList as unstable_SuspenseList,
SuspenseList as unstable_SuspenseList, // TODO: Remove once call sights updated to SuspenseList
cloneElement,
createContext,
createElement,
Expand All @@ -30,7 +30,7 @@ export {
lazy,
memo,
startTransition,
startTransition as unstable_startTransition,
startTransition as unstable_startTransition, // TODO: Remove once call sights updated to startTransition
unstable_Cache,
unstable_DebugTracingMode,
unstable_LegacyHidden,
Expand All @@ -42,7 +42,7 @@ export {
useContext,
useDebugValue,
useDeferredValue,
useDeferredValue as unstable_useDeferredValue,
useDeferredValue as unstable_useDeferredValue, // TODO: Remove once call sights updated to useDeferredValue
useEffect,
useImperativeHandle,
useLayoutEffect,
Expand All @@ -53,7 +53,7 @@ export {
useRef,
useState,
useTransition,
useTransition as unstable_useTransition,
useTransition as unstable_useTransition, // TODO: Remove once call sights updated to useTransition
version,
} from './src/React';
export {jsx, jsxs, jsxDEV} from './src/jsx/ReactJSX';
7 changes: 3 additions & 4 deletions packages/react/index.experimental.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export {
PureComponent,
StrictMode,
Suspense,
SuspenseList as unstable_SuspenseList,
SuspenseList,
cloneElement,
createContext,
createElement,
Expand All @@ -27,7 +27,7 @@ export {
isValidElement,
lazy,
memo,
startTransition as unstable_startTransition,
startTransition,
unstable_Cache,
unstable_DebugTracingMode,
unstable_LegacyHidden,
Expand All @@ -37,7 +37,6 @@ export {
useCallback,
useContext,
useDebugValue,
useDeferredValue as unstable_useDeferredValue,
useEffect,
useImperativeHandle,
useLayoutEffect,
Expand All @@ -46,6 +45,6 @@ export {
useReducer,
useRef,
useState,
useTransition as unstable_useTransition,
useTransition,
version,
} from './src/React';
Loading

0 comments on commit 8a0e2ab

Please sign in to comment.