Skip to content

Commit

Permalink
Adds warning for older unstable methods
Browse files Browse the repository at this point in the history
  • Loading branch information
ManasJayanth committed Dec 1, 2017
1 parent 0a2ed64 commit 786659a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
7 changes: 7 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');
var portalContainer = document.createElement('div');

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

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('');
Expand Down
9 changes: 8 additions & 1 deletion packages/react-dom/src/client/ReactDOM.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand Down

0 comments on commit 786659a

Please sign in to comment.