Skip to content

Commit

Permalink
Merge pull request #4350 from preactjs/fix/jsx-source-debug-warning
Browse files Browse the repository at this point in the history
fix: Incorrect "missing `transform-jsx-source`" warning
  • Loading branch information
rschristian committed Apr 30, 2024
2 parents 613cacc + 50c3f3e commit dbc4d61
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
6 changes: 3 additions & 3 deletions debug/src/component-stack.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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');
}, '');
Expand Down
14 changes: 14 additions & 0 deletions debug/test/browser/component-stack.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(<Thrower />, scratch);
} catch {}

expect(warnings.join(' ')).to.not.include(
'@babel/plugin-transform-react-jsx-source'
);
});
});

0 comments on commit dbc4d61

Please sign in to comment.