diff --git a/debug/src/component-stack.js b/debug/src/component-stack.js index 58830ed32a..52a1801273 100644 --- a/debug/src/component-stack.js +++ b/debug/src/component-stack.js @@ -58,7 +58,7 @@ export function getCurrentVNode() { * location of a component. In that case we just omit that, but we'll * print a helpful message to the console, notifying the user of it. */ -let hasBabelPlugin = false; +let showJsxSourcePluginWarning = true; /** * Check if a `vnode` is a possible owner. @@ -87,12 +87,12 @@ export function getOwnerStack(vnode) { const source = owner.__source; if (source) { acc += ` (at ${source.fileName}:${source.lineNumber})`; - } else if (!hasBabelPlugin) { - hasBabelPlugin = true; + } else if (showJsxSourcePluginWarning) { console.warn( 'Add @babel/plugin-transform-react-jsx-source to get a more detailed component stack. Note that you should not add it to production builds of your App for bundle size reasons.' ); } + showJsxSourcePluginWarning = false; return (acc += '\n'); }, ''); diff --git a/debug/test/browser/component-stack.test.js b/debug/test/browser/component-stack.test.js index ac533b228f..f64bdde3b3 100644 --- a/debug/test/browser/component-stack.test.js +++ b/debug/test/browser/component-stack.test.js @@ -83,4 +83,18 @@ describe('component stack', () => { expect(lines[1].indexOf('Thrower') > -1).to.equal(true); expect(lines[2].indexOf('Bar') > -1).to.equal(true); }); + + it('should not print a warning when "@babel/plugin-transform-react-jsx-source" is installed', () => { + function Thrower() { + throw new Error('foo'); + } + + try { + render(, scratch); + } catch {} + + expect(warnings.join(' ')).to.not.include( + '@babel/plugin-transform-react-jsx-source' + ); + }); });