Skip to content

Commit 84af781

Browse files
committed
Adds deprecation warning for ReactDOM.unstable_createPortal
1 parent 5bd2321 commit 84af781

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

packages/react-dom/src/__tests__/ReactDOMFiber-test.js

+11
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ describe('ReactDOMFiber', () => {
222222

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

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

237+
if (__DEV__) {
238+
expect(console.warn.calls.count()).toBe(1);
239+
expect(console.warn.calls.argsFor(0)[0]).toContain(
240+
'The ReactDOM.unstable_createPortal() alias has been deprecated, ' +
241+
'and will be removed in React 17+. Update your code to use ' +
242+
'ReactDOM.createPortal() instead. It has the exact same API, ' +
243+
'but without the "unstable_" prefix.',
244+
);
245+
}
246+
236247
ReactDOM.unmountComponentAtNode(container);
237248
expect(portalContainer.innerHTML).toBe('');
238249
expect(container.innerHTML).toBe('');

packages/react-dom/src/client/ReactDOM.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -1268,7 +1268,16 @@ const ReactDOM: Object = {
12681268

12691269
// Temporary alias since we already shipped React 16 RC with it.
12701270
// TODO: remove in React 17.
1271-
unstable_createPortal: createPortal,
1271+
unstable_createPortal(...args) {
1272+
lowPriorityWarning(
1273+
false,
1274+
'The ReactDOM.unstable_createPortal() alias has been deprecated, ' +
1275+
'and will be removed in React 17+. Update your code to use ' +
1276+
'ReactDOM.createPortal() instead. It has the exact same API, ' +
1277+
'but without the "unstable_" prefix.',
1278+
);
1279+
return createPortal(...args);
1280+
},
12721281

12731282
unstable_batchedUpdates: ReactGenericBatching.batchedUpdates,
12741283

0 commit comments

Comments
 (0)