Special case printing Promises in Performance Track Properties (#33670)
Before: <img width="266" alt="Screenshot 2025-06-30 at 8 32 23 AM" src="https://github.com/user-attachments/assets/98aae5e1-4b2c-49bd-9b71-040b788c36ba" /> After: <img width="342" alt="Screenshot 2025-06-30 at 8 39 17 AM" src="https://github.com/user-attachments/assets/cd91c4a6-f6ae-4bec-9cd9-f42f4af468fe" />
Sebastian Markbåge committed
Jun 30, 2025 at 09:21 UTC
e9cab42ece435ac3478ec85847e352177e596ae0
1 file changed
+34
packages/shared/ReactPerformanceTrackProperties.js
+34
@@ -145,6 +145,40 @@ export function addValueToProperties(
145
return;
146
}
147
}
148
+ if (objectName === 'Promise') {
149
+ if (value.status === 'fulfilled') {
150
+ // Print the inner value
151
+ const idx = properties.length;
152
+ addValueToProperties(propertyName, value.value, properties, indent);
153
+ if (properties.length > idx) {
154
+ // Wrap the value or type in Promise descriptor.
155
+ const insertedEntry = properties[idx];
156
+ insertedEntry[1] =
157
+ 'Promise<' + (insertedEntry[1] || 'Object') + '>';
158
+ return;
159
+ }
160
+ } else if (value.status === 'rejected') {
161
+ // Print the inner error
162
+ const idx = properties.length;
163
+ addValueToProperties(
164
+ propertyName,
165
+ value.reason,
166
+ properties,
167
+ indent,
168
+ );
169
+ if (properties.length > idx) {
170
+ // Wrap the value or type in Promise descriptor.
171
+ const insertedEntry = properties[idx];
172
+ insertedEntry[1] = 'Rejected Promise<' + insertedEntry[1] + '>';
173
+ return;
174
+ }
175
+ }
176
+ properties.push([
177
+ '\xa0\xa0'.repeat(indent) + propertyName,
178
+ 'Promise',
179
+ ]);
180
+ return;
181
+ }
182
if (objectName === 'Object') {
183
const proto: any = Object.getPrototypeOf(value);
184
if (proto && typeof proto.constructor === 'function') {