From 784af469d139c95070909cb41e9d518313183193 Mon Sep 17 00:00:00 2001 From: Ryan Christian Date: Thu, 25 Apr 2024 23:09:11 -0500 Subject: [PATCH 1/4] fix: Incorrect "missing `transform-jsx-source`" warning --- debug/src/component-stack.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/debug/src/component-stack.js b/debug/src/component-stack.js index 58830ed32a..f3c7771a52 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 shouldShowJsxSourceWarning = 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 (shouldShowJsxSourceWarning) { 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.' ); } + shouldShowJsxSourceWarning = false; return (acc += '\n'); }, ''); From 61ce7a4f26ea9c431fa47247f7562d1acc5d3c02 Mon Sep 17 00:00:00 2001 From: Ryan Christian Date: Thu, 25 Apr 2024 23:19:49 -0500 Subject: [PATCH 2/4] refactor: Slight rename --- debug/src/component-stack.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/debug/src/component-stack.js b/debug/src/component-stack.js index f3c7771a52..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 shouldShowJsxSourceWarning = true; +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 (shouldShowJsxSourceWarning) { + } 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.' ); } - shouldShowJsxSourceWarning = false; + showJsxSourcePluginWarning = false; return (acc += '\n'); }, ''); From d4ff12e97cc14a347efa07ca12a82381ff025978 Mon Sep 17 00:00:00 2001 From: Ryan Christian Date: Fri, 26 Apr 2024 00:43:00 -0500 Subject: [PATCH 3/4] test: Add test for fixed jsx-source warning --- debug/test/browser/component-stack.test.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/debug/test/browser/component-stack.test.js b/debug/test/browser/component-stack.test.js index ac533b228f..9d01406f10 100644 --- a/debug/test/browser/component-stack.test.js +++ b/debug/test/browser/component-stack.test.js @@ -83,4 +83,19 @@ 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 'foo'; + return
foo
; + } + + try { + render(, scratch); + } catch {} + + expect(warnings.join(' ')).to.not.include( + '@babel/plugin-transform-react-jsx-source' + ); + }); }); From 2e2f5ab3a7b7e6a8cce2957136a138584726931e Mon Sep 17 00:00:00 2001 From: Ryan Christian Date: Fri, 26 Apr 2024 00:46:41 -0500 Subject: [PATCH 4/4] fix: Appease ESLint --- debug/test/browser/component-stack.test.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/debug/test/browser/component-stack.test.js b/debug/test/browser/component-stack.test.js index 9d01406f10..f64bdde3b3 100644 --- a/debug/test/browser/component-stack.test.js +++ b/debug/test/browser/component-stack.test.js @@ -86,8 +86,7 @@ describe('component stack', () => { it('should not print a warning when "@babel/plugin-transform-react-jsx-source" is installed', () => { function Thrower() { - throw 'foo'; - return
foo
; + throw new Error('foo'); } try {