Add performance marksf or individual fetch() requests (#22176)
Brian Vaughn committed
Aug 26, 2021 at 09:19 UTC
2bf2e76d366439766ab6b4acb851a65963490920
1 file changed
+16
packages/react-devtools-extensions/src/parseHookNames/parseHookNames.js
+16
@@ -451,6 +451,10 @@ function extractAndLoadSourceMaps(
451
}
452
453
function fetchFile(url: string): Promise<string> {
454
+ if (__PERFORMANCE_PROFILE__) {
455
+ mark('fetchFile("' + url + '")');
456
+ }
457
+
458
return new Promise((resolve, reject) => {
459
fetch(url).then(
460
response => {
@@ -458,18 +462,27 @@ function fetchFile(url: string): Promise<string> {
462
response
463
.text()
464
.then(text => {
465
+ if (__PERFORMANCE_PROFILE__) {
466
+ measure('fetchFile("' + url + '")');
467
+ }
468
resolve(text);
469
})
470
.catch(error => {
471
if (__DEBUG__) {
472
console.log(`fetchFile() Could not read text for url "${url}"`);
473
}
474
+ if (__PERFORMANCE_PROFILE__) {
475
+ measure('fetchFile("' + url + '")');
476
+ }
477
reject(null);
478
});
479
} else {
480
if (__DEBUG__) {
481
console.log(`fetchFile() Got bad response for url "${url}"`);
482
}
483
+ if (__PERFORMANCE_PROFILE__) {
484
+ measure('fetchFile("' + url + '")');
485
+ }
486
reject(null);
487
}
488
},
@@ -477,6 +490,9 @@ function fetchFile(url: string): Promise<string> {
490
if (__DEBUG__) {
491
console.log(`fetchFile() Could not fetch file: ${error.message}`);
492
}
493
+ if (__PERFORMANCE_PROFILE__) {
494
+ measure('fetchFile("' + url + '")');
495
+ }
496
reject(null);
497
},
498
);