Skip to content

Commit 75c6165

Browse files
authored
Include actual type of Profiler#id on type mismatch (#20306)
1 parent 1214b30 commit 75c6165

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

packages/react-reconciler/src/ReactFiber.new.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,10 @@ function createFiberFromProfiler(
651651
): Fiber {
652652
if (__DEV__) {
653653
if (typeof pendingProps.id !== 'string') {
654-
console.error('Profiler must specify an "id" as a prop');
654+
console.error(
655+
'Profiler must specify an "id" of type `string` as a prop. Received the type `%s` instead.',
656+
typeof pendingProps.id,
657+
);
655658
}
656659
}
657660

packages/react-reconciler/src/ReactFiber.old.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,10 @@ function createFiberFromProfiler(
651651
): Fiber {
652652
if (__DEV__) {
653653
if (typeof pendingProps.id !== 'string') {
654-
console.error('Profiler must specify an "id" as a prop');
654+
console.error(
655+
'Profiler must specify an "id" of type `string` as a prop. Received the type `%s` instead.',
656+
typeof pendingProps.id,
657+
);
655658
}
656659
}
657660

packages/react/src/__tests__/ReactProfiler-test.internal.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,12 @@ describe('Profiler', () => {
136136
it('should warn if required params are missing', () => {
137137
expect(() => {
138138
ReactTestRenderer.create(<React.Profiler />);
139-
}).toErrorDev('Profiler must specify an "id" as a prop', {
140-
withoutStack: true,
141-
});
139+
}).toErrorDev(
140+
'Profiler must specify an "id" of type `string` as a prop. Received the type `undefined` instead.',
141+
{
142+
withoutStack: true,
143+
},
144+
);
142145
});
143146
}
144147

0 commit comments

Comments
 (0)