Skip to content

Commit

Permalink
Include actual type of Profiler#id on type mismatch (facebook#20306)
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon authored and acdlite committed Apr 16, 2021
1 parent 2754141 commit 0c4859e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
5 changes: 4 additions & 1 deletion packages/react-reconciler/src/ReactFiber.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,10 @@ function createFiberFromProfiler(
): Fiber {
if (__DEV__) {
if (typeof pendingProps.id !== 'string') {
console.error('Profiler must specify an "id" as a prop');
console.error(
'Profiler must specify an "id" of type `string` as a prop. Received the type `%s` instead.',
typeof pendingProps.id,
);
}
}

Expand Down
5 changes: 4 additions & 1 deletion packages/react-reconciler/src/ReactFiber.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,10 @@ function createFiberFromProfiler(
): Fiber {
if (__DEV__) {
if (typeof pendingProps.id !== 'string') {
console.error('Profiler must specify an "id" as a prop');
console.error(
'Profiler must specify an "id" of type `string` as a prop. Received the type `%s` instead.',
typeof pendingProps.id,
);
}
}

Expand Down
9 changes: 6 additions & 3 deletions packages/react/src/__tests__/ReactProfiler-test.internal.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,12 @@ describe('Profiler', () => {
it('should warn if required params are missing', () => {
expect(() => {
ReactTestRenderer.create(<React.Profiler />);
}).toErrorDev('Profiler must specify an "id" as a prop', {
withoutStack: true,
});
}).toErrorDev(
'Profiler must specify an "id" of type `string` as a prop. Received the type `undefined` instead.',
{
withoutStack: true,
},
);
});
}

Expand Down

0 comments on commit 0c4859e

Please sign in to comment.