Skip to content

Commit

Permalink
Fix: Set image loader module name synchronously
Browse files Browse the repository at this point in the history
Summary: Changelog: [Internal]

Reviewed By: fkgozali

Differential Revision: D24290066

fbshipit-source-id: e2bad9ed8c126c7b49356bc7a2c1114160149fd3
  • Loading branch information
p-sun authored and facebook-github-bot committed Oct 14, 2020
1 parent cd6ebcd commit 38eb3f8
Showing 1 changed file with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ - (ImageRequest)requestImage:(ImageSource)imageSource surfaceId:(SurfaceId)surfa
auto sharedCancelationFunction = SharedFunction<>();
imageRequest.setCancelationFunction(sharedCancelationFunction);

NSURLRequest *request = NSURLRequestFromImageSource(imageSource);
BOOL hasModuleName = [self->_imageLoader respondsToSelector:@selector(loaderModuleNameForRequestUrl:)];
NSString *moduleName = hasModuleName ? [self->_imageLoader loaderModuleNameForRequestUrl:request.URL] : nil;
std::string moduleCString =
std::string([moduleName UTF8String], [moduleName lengthOfBytesUsingEncoding:NSUTF8StringEncoding]);
telemetry->setLoaderModuleName(moduleCString);

/*
* Even if an image is being loaded asynchronously on some other background thread, some other preparation
* work (such as creating an `NSURLRequest` object and some obscure logic inside `RCTImageLoader`) can take a couple
Expand All @@ -60,14 +67,6 @@ - (ImageRequest)requestImage:(ImageSource)imageSource surfaceId:(SurfaceId)surfa
* T46024425 for more details.
*/
dispatch_async(_backgroundSerialQueue, ^{
NSURLRequest *request = NSURLRequestFromImageSource(imageSource);

BOOL hasModuleName = [self->_imageLoader respondsToSelector:@selector(loaderModuleNameForRequestUrl:)];
NSString *moduleName = hasModuleName ? [self->_imageLoader loaderModuleNameForRequestUrl:request.URL] : nil;
std::string moduleCString =
std::string([moduleName UTF8String], [moduleName lengthOfBytesUsingEncoding:NSUTF8StringEncoding]);
telemetry->setLoaderModuleName(moduleCString);

auto completionBlock = ^(NSError *error, UIImage *image, id metadata) {
auto observerCoordinator = weakObserverCoordinator.lock();
if (!observerCoordinator) {
Expand Down

0 comments on commit 38eb3f8

Please sign in to comment.