diff --git a/src/actions/receive-profile.ts b/src/actions/receive-profile.ts index 15a7903dea..cd392613fa 100644 --- a/src/actions/receive-profile.ts +++ b/src/actions/receive-profile.ts @@ -1416,9 +1416,9 @@ export function retrieveProfilesToCompare( dispatch(waitingForProfileFromUrl()); try { - // First we get a state from each URL. From these states we'll get all the - // data we need to fetch and process the profiles. - const profileStates = await Promise.all( + // Fetch each profile first so we can pass the upgrade info to + // stateFromLocation, allowing URL upgraders to work correctly. + const profilesAndStates = await Promise.all( profileViewUrls.map(async (url) => { if ( url.startsWith('https://perfht.ml/') || @@ -1427,28 +1427,23 @@ export function retrieveProfilesToCompare( ) { url = await expandUrl(url); } - // TODO: Pass the profileUpgradeInfo here. See #5871. - return stateFromLocation(new URL(url)); - }) - ); - // Then we retrieve the profiles from the online store, and unserialize - // and process them if needed. - const promises = profileStates.map( - async ({ dataSource, hash, profileUrl }) => { + const preliminaryState = stateFromLocation(new URL(url)); + let { profileUrl } = preliminaryState; + const { dataSource, hash } = preliminaryState; + switch (dataSource) { case 'public': - // Use a URL from the public store. profileUrl = getProfileUrlForHash(hash); break; case 'from-url': - // Use the profile URL in the decoded state, decoded from the input URL. break; default: throw new Error( 'Only public uploaded profiles are supported by the comparison function.' ); } + const response: ProfileOrZip = await _fetchProfile({ url: profileUrl, onTemporaryError: (e: TemporaryError) => { @@ -1458,18 +1453,27 @@ export function retrieveProfilesToCompare( if (response.responseType !== 'PROFILE') { throw new Error('Expected to receive a profile from _fetchProfile'); } - const serializedProfile = response.profile; - const profile = - unserializeProfileOfArbitraryFormat(serializedProfile); - return profile; - } + const upgradeInfo: ProfileUpgradeInfo = {}; + const profile = await unserializeProfileOfArbitraryFormat( + response.profile, + profileUrl, + upgradeInfo + ); + + const profileState = stateFromLocation(new URL(url), { + profile, + upgradeInfo, + }); + + return { profile, profileState }; + }) ); - // Once all profiles have been fetched and unserialized, we can start - // pushing them to a brand new profile. This resulting profile will keep - // only the 2 selected threads from the 2 profiles. - const profiles = await Promise.all(promises); + const profiles = profilesAndStates.map(({ profile }) => profile); + const profileStates = profilesAndStates.map( + ({ profileState }) => profileState + ); const { profile: resultProfile,