Skip to content

Commit

Permalink
DevTools console patching should handle Symbols without erroring
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Vaughn committed Apr 27, 2021
1 parent 29faeb2 commit 9a4db27
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
12 changes: 12 additions & 0 deletions packages/react-devtools-shared/src/__tests__/console-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -453,4 +453,16 @@ describe('console', () => {
'\n in Child (at **)\n in Intermediate (at **)\n in Parent (at **)',
);
});

it('should correctly log Symbols', () => {
const Component = ({children}) => {
fakeConsole.warn('Symbol:', Symbol(''));
return null;
};

act(() => ReactDOM.render(<Component />, document.createElement('div')));

expect(mockWarn).toHaveBeenCalledTimes(1);
expect(mockWarn.mock.calls[0][0]).toBe('Symbol:');
});
});
2 changes: 1 addition & 1 deletion packages/react-devtools-shared/src/backend/console.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export function patch({
if (consoleSettingsRef.appendComponentStack) {
const lastArg = args.length > 0 ? args[args.length - 1] : null;
const alreadyHasComponentStack =
lastArg !== null && isStringComponentStack(lastArg);
typeof lastArg === 'string' && isStringComponentStack(lastArg);

// If we are ever called with a string that already has a component stack,
// e.g. a React error/warning, don't append a second stack.
Expand Down
7 changes: 7 additions & 0 deletions packages/react-devtools-shell/src/app/InlineWarnings/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@ function ComponentWithMissingKey({children}) {
return [<div />];
}

function ComponentWithSymbolWarning() {
console.warn('this is a symbol', Symbol('foo'));
console.error('this is a symbol', Symbol.for('bar'));
return null;
}

export default function ErrorsAndWarnings() {
const [count, setCount] = useState(0);
const handleClick = () => setCount(count + 1);
Expand Down Expand Up @@ -176,6 +182,7 @@ export default function ErrorsAndWarnings() {
<ReallyLongErrorMessageThatWillCauseTextToBeTruncated />
<DuplicateWarningsAndErrors />
<MultipleWarningsAndErrors />
<ComponentWithSymbolWarning />
</Fragment>
);
}

0 comments on commit 9a4db27

Please sign in to comment.