From e9cab42ece435ac3478ec85847e352177e596ae0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Markb=C3=A5ge?= Date: Mon, 30 Jun 2025 09:21:04 -0400 Subject: [PATCH] Special case printing Promises in Performance Track Properties (#33670) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before: Screenshot 2025-06-30 at 8 32 23 AM After: Screenshot 2025-06-30 at 8 39 17 AM --- .../shared/ReactPerformanceTrackProperties.js | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/packages/shared/ReactPerformanceTrackProperties.js b/packages/shared/ReactPerformanceTrackProperties.js index 8b5f980856..cb6cab00a7 100644 --- a/packages/shared/ReactPerformanceTrackProperties.js +++ b/packages/shared/ReactPerformanceTrackProperties.js @@ -145,6 +145,40 @@ export function addValueToProperties( return; } } + if (objectName === 'Promise') { + if (value.status === 'fulfilled') { + // Print the inner value + const idx = properties.length; + addValueToProperties(propertyName, value.value, properties, indent); + if (properties.length > idx) { + // Wrap the value or type in Promise descriptor. + const insertedEntry = properties[idx]; + insertedEntry[1] = + 'Promise<' + (insertedEntry[1] || 'Object') + '>'; + return; + } + } else if (value.status === 'rejected') { + // Print the inner error + const idx = properties.length; + addValueToProperties( + propertyName, + value.reason, + properties, + indent, + ); + if (properties.length > idx) { + // Wrap the value or type in Promise descriptor. + const insertedEntry = properties[idx]; + insertedEntry[1] = 'Rejected Promise<' + insertedEntry[1] + '>'; + return; + } + } + properties.push([ + '\xa0\xa0'.repeat(indent) + propertyName, + 'Promise', + ]); + return; + } if (objectName === 'Object') { const proto: any = Object.getPrototypeOf(value); if (proto && typeof proto.constructor === 'function') {