Skip to content

Commit

Permalink
Adds deprecation warning for ReactDOM.unstable_createPortal
Browse files Browse the repository at this point in the history
  • Loading branch information
ManasJayanth committed Dec 8, 2017
1 parent 6e258c1 commit ea0a1e3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
11 changes: 11 additions & 0 deletions packages/react-dom/src/__tests__/ReactDOMFiber-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ describe('ReactDOMFiber', () => {

// TODO: remove in React 17
it('should support unstable_createPortal alias', () => {
spyOnDev(console, 'warn');
const portalContainer = document.createElement('div');

ReactDOM.render(
Expand All @@ -233,6 +234,16 @@ describe('ReactDOMFiber', () => {
expect(portalContainer.innerHTML).toBe('<div>portal</div>');
expect(container.innerHTML).toBe('<div></div>');

if (__DEV__) {
expect(console.warn.calls.count()).toBe(1);
expect(console.warn.calls.argsFor(0)[0]).toContain(
'The ReactDOM.unstable_createPortal() alias has been deprecated, ' +
'and will be removed in React 17+. Update your code to use ' +
'ReactDOM.createPortal() instead. It has the exact same API, ' +
'but without the "unstable_" prefix.',
);
}

ReactDOM.unmountComponentAtNode(container);
expect(portalContainer.innerHTML).toBe('');
expect(container.innerHTML).toBe('');
Expand Down
15 changes: 14 additions & 1 deletion packages/react-dom/src/client/ReactDOM.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ const {precacheFiberNode, updateFiberProps} = ReactDOMComponentTree;
let SUPPRESS_HYDRATION_WARNING;
let topLevelUpdateWarnings;
let warnOnInvalidCallback;
let hasLoggedCreatePortalDeprecationWarning = false;

if (__DEV__) {
SUPPRESS_HYDRATION_WARNING = 'suppressHydrationWarning';
Expand Down Expand Up @@ -1276,7 +1277,19 @@ const ReactDOM: Object = {

// Temporary alias since we already shipped React 16 RC with it.
// TODO: remove in React 17.
unstable_createPortal: createPortal,
unstable_createPortal(...args) {
if (!hasLoggedCreatePortalDeprecationWarning) {
hasLoggedCreatePortalDeprecationWarning = true;
lowPriorityWarning(
false,
'The ReactDOM.unstable_createPortal() alias has been deprecated, ' +
'and will be removed in React 17+. Update your code to use ' +
'ReactDOM.createPortal() instead. It has the exact same API, ' +
'but without the "unstable_" prefix.',
);
}
return createPortal(...args);
},

unstable_batchedUpdates: ReactGenericBatching.batchedUpdates,

Expand Down

0 comments on commit ea0a1e3

Please sign in to comment.