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 6, 2017
1 parent 5bd2321 commit 84af781
Show file tree
Hide file tree
Showing 2 changed files with 21 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
11 changes: 10 additions & 1 deletion packages/react-dom/src/client/ReactDOM.js
Original file line number Diff line number Diff line change
Expand Up @@ -1268,7 +1268,16 @@ 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) {
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 84af781

Please sign in to comment.