Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DevTools console patching should handle Symbols without erroring #21368

Merged
merged 1 commit into from
Apr 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>
);
}