Skip to content

Commit

Permalink
Improve formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon committed Apr 20, 2022
1 parent f5e5e98 commit 21a7b3e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,8 @@ describe('ReactDOMServerHydration', () => {
fit('warns when client renders an extra element as only child', () => {
function Mismatch({isClient}) {
return (
<div className="parent">
{isClient && <main className="only" style={{opacity: 1}} />}
<div className="parent" style={{ opacity: 1}} onClick={() => {}}>
{isClient && <main className="only" style={{ opacity: 1 }} onClick={() => {}} />}
</div>
);
}
Expand Down
14 changes: 10 additions & 4 deletions packages/react-dom/src/client/ReactDOMComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -1235,14 +1235,20 @@ function formatProps(props): string {
}
const attributeName = prop;
const value = props[prop];
if (value != null) {
// TODO: what about non-strings
if (
value != null &&
typeof value !== 'function' &&
typeof value !== 'symbol'
) {
let trimmedValue = JSON.stringify(value);
if (value.length > 30) {
trimmedValue = value.substr(0, 30) + '...';
}
// TODO: what about quotes in attr values
str += ' ' + attributeName + '={' + trimmedValue + '}';
if (typeof value === 'string') {
str += ' ' + attributeName + '=' + trimmedValue + '';
} else {
str += ' ' + attributeName + '={' + trimmedValue + '}';
}
}
i++;
}
Expand Down

0 comments on commit 21a7b3e

Please sign in to comment.