Skip to content

Commit 012e72c

Browse files
committed
Adds warning for older unstable methods
1 parent 0a2ed64 commit 012e72c

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

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

Lines changed: 9 additions & 0 deletions
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
var portalContainer = document.createElement('div');
226227

227228
ReactDOM.render(
@@ -233,6 +234,14 @@ 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+
'unstable_createPortal is merely an alias to createPortal ' +
241+
'and will not work in React 17+. Please update your code.',
242+
);
243+
}
244+
236245
ReactDOM.unmountComponentAtNode(container);
237246
expect(portalContainer.innerHTML).toBe('');
238247
expect(container.innerHTML).toBe('');

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1263,7 +1263,14 @@ const ReactDOM: Object = {
12631263

12641264
// Temporary alias since we already shipped React 16 RC with it.
12651265
// TODO: remove in React 17.
1266-
unstable_createPortal: createPortal,
1266+
unstable_createPortal(...args) {
1267+
lowPriorityWarning(
1268+
false,
1269+
'unstable_createPortal is merely an alias to createPortal ' +
1270+
'and will not work in React 17+. Please update your code.',
1271+
);
1272+
return createPortal(...args);
1273+
},
12671274

12681275
unstable_batchedUpdates: ReactGenericBatching.batchedUpdates,
12691276

0 commit comments

Comments
 (0)