From 012e72c0bec7c563efe0eb852eec246e086821a2 Mon Sep 17 00:00:00 2001 From: Manas Date: Sat, 2 Dec 2017 02:22:13 +0530 Subject: [PATCH] Adds warning for older unstable methods --- packages/react-dom/src/__tests__/ReactDOMFiber-test.js | 9 +++++++++ packages/react-dom/src/client/ReactDOM.js | 9 ++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/packages/react-dom/src/__tests__/ReactDOMFiber-test.js b/packages/react-dom/src/__tests__/ReactDOMFiber-test.js index 66a0d34057d9a..0c305d42bb2c3 100644 --- a/packages/react-dom/src/__tests__/ReactDOMFiber-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMFiber-test.js @@ -222,6 +222,7 @@ describe('ReactDOMFiber', () => { // TODO: remove in React 17 it('should support unstable_createPortal alias', () => { + spyOnDev(console, 'warn'); var portalContainer = document.createElement('div'); ReactDOM.render( @@ -233,6 +234,14 @@ describe('ReactDOMFiber', () => { expect(portalContainer.innerHTML).toBe('
portal
'); expect(container.innerHTML).toBe('
'); + if (__DEV__) { + expect(console.warn.calls.count()).toBe(1); + expect(console.warn.calls.argsFor(0)[0]).toContain( + 'unstable_createPortal is merely an alias to createPortal ' + + 'and will not work in React 17+. Please update your code.', + ); + } + ReactDOM.unmountComponentAtNode(container); expect(portalContainer.innerHTML).toBe(''); expect(container.innerHTML).toBe(''); diff --git a/packages/react-dom/src/client/ReactDOM.js b/packages/react-dom/src/client/ReactDOM.js index f898bb673a418..829d815e3f004 100644 --- a/packages/react-dom/src/client/ReactDOM.js +++ b/packages/react-dom/src/client/ReactDOM.js @@ -1263,7 +1263,14 @@ 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, + 'unstable_createPortal is merely an alias to createPortal ' + + 'and will not work in React 17+. Please update your code.', + ); + return createPortal(...args); + }, unstable_batchedUpdates: ReactGenericBatching.batchedUpdates,