From 394146d45e8445dbbfddac8507488fcbb1d4bcb0 Mon Sep 17 00:00:00 2001 From: Sebastian Silbermann Date: Thu, 8 Apr 2021 19:36:42 +0200 Subject: [PATCH] Include actual type of `Profiler#id` on type mismatch (#20306) --- packages/react-reconciler/src/ReactFiber.new.js | 5 ++++- packages/react-reconciler/src/ReactFiber.old.js | 5 ++++- .../react/src/__tests__/ReactProfiler-test.internal.js | 9 ++++++--- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/packages/react-reconciler/src/ReactFiber.new.js b/packages/react-reconciler/src/ReactFiber.new.js index de9c83e3a35dd..95a5340b18730 100644 --- a/packages/react-reconciler/src/ReactFiber.new.js +++ b/packages/react-reconciler/src/ReactFiber.new.js @@ -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, + ); } } diff --git a/packages/react-reconciler/src/ReactFiber.old.js b/packages/react-reconciler/src/ReactFiber.old.js index f399ab3593146..159557e86a166 100644 --- a/packages/react-reconciler/src/ReactFiber.old.js +++ b/packages/react-reconciler/src/ReactFiber.old.js @@ -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, + ); } } diff --git a/packages/react/src/__tests__/ReactProfiler-test.internal.js b/packages/react/src/__tests__/ReactProfiler-test.internal.js index ab7fbb73f025a..6b0c02432544b 100644 --- a/packages/react/src/__tests__/ReactProfiler-test.internal.js +++ b/packages/react/src/__tests__/ReactProfiler-test.internal.js @@ -136,9 +136,12 @@ describe('Profiler', () => { it('should warn if required params are missing', () => { expect(() => { ReactTestRenderer.create(); - }).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, + }, + ); }); }