Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[expo-asset] Load local expo-updates manifest assets #15667

Merged
merged 8 commits into from
Dec 21, 2021

Conversation

jonsamp
Copy link
Member

@jonsamp jonsamp commented Dec 21, 2021

Why

Fixes 4081

Closes ENG-2748, ENG-2288

As described in the issues above, there was one issue that was causing problems:

  • The expo-asset library could not load local assets when using an expo-updates manifest
  • Using React Native <Image />'s defaultSource prop would cause an app to error.

This PR exposes the manifest2.extra.expoGo.debuggerHost to the selectAssetSources function, which returns the correct local asset URLs. This makes it possible to run expo start --force-manifest-type=expo-updates and to load assets.

How

For expo-asset to know the correct local URL, we must pass it the URL of the currently running local session. For classic manifests, we pass in the manifest.bundleUrl (example: http://127.0.0.1:19000/node_modules/expo/AppEntry.bundle?platform=ios&dev=true&hot=false&minify=false). The expo-asset library code then takes the pathname (http://127.0.0.1:19000) and uses that to construct the asset URL.

In similar fashion, I decided to take the manifest2.extra.expoGo.debuggerHost property (example: 127.0.0.1:19000) for expo-updates manifests. If this property is likely to change, we should pass another prop when running Expo CLI that is more specific, but using this one since I think it is likely stable.

Test Plan

  1. Run unit tests inside expo-asset.
  2. In apps/sandbox, add the following App.js file and some images named image-one.png and image-two.png:
    import ImageOne from './image-one.png';
    import ImageTwo from './image-two.png';
    
    // ...
    <Image defaultSource={ImageOne} source={ImageTwo} style={{ height: 200, width: 300 }} />
  3. Install dependencies with yarn, then run the server with expo start --force-manifest-type=expo-updates and open the app in Expo Go in a simulator. You should see an image appear. You can also write console.log(Image.resolveAssetSource(ImageOne)), and make sure that the URL starts with a URL like "https://127.0.0.1:19000/...".
  4. Then, try running the server with expo start --force-manifest-type=classic, to make sure that classic updates are unaffected.

@linear
Copy link

linear bot commented Dec 21, 2021

ENG-2748 Manifest type "expo-updates" does not show images in development

expo/expo-cli#4081

ENG-2288 Using w/modern manifests in development produces expo-asset error with a production CloudFront URL

We don't yet know why this happens but it's definitely something we need to fix.

A minimum, complete, reproducible example: https://github.com/jonsamp/mcr-expo-manifest-image-default-source

I have a hunch this code is involved:

https://github.com/expo/expo/blame/master/packages/expo-asset/src/AssetSources.ts#L86

Note: defaultSource does not work on Android in development (according to RN docs) so it makes sense that we're only seeing this on iOS

@expo-bot expo-bot added the bot: suggestions ExpoBot has some suggestions label Dec 21, 2021
@expo-bot expo-bot added bot: passed checks ExpoBot has nothing to complain about and removed bot: suggestions ExpoBot has some suggestions labels Dec 21, 2021
Copy link
Contributor

@esamelson esamelson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me (aside from the one detail) -- thanks so much for fixing this, @jonsamp!! And for the comprehensive test plan 🙏 🙏

It looks like we should probably take a pass over the rest of the getManifest() calls in this file as well, to make them compatible with manifest2 (could also consider removing the hardcoded cloudfront URL altogether, although it has useful to have a last resort fallback at times) -- but this seems great as a hotfix for the current issue.

packages/expo-asset/src/AssetSources.ts Outdated Show resolved Hide resolved
Co-authored-by: Eric Samelson <esamelson@users.noreply.github.com>
@jonsamp jonsamp merged commit 0fbe04a into master Dec 21, 2021
@jonsamp jonsamp deleted the jon/support-manifest2-local-assets branch December 21, 2021 18:02
esamelson added a commit that referenced this pull request Dec 21, 2021
* adds manifest2 support during development

* makes manifest2 its own function and logic

* adds test

* adds changelog

* updates changelog

* Update packages/expo-asset/src/AssetSources.ts

Co-authored-by: Eric Samelson <esamelson@users.noreply.github.com>

* rebuilds expo-asset

* updates test

Co-authored-by: Eric Samelson <esamelson@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bot: passed checks ExpoBot has nothing to complain about
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Manifest type "expo-updates" does not show images in development
4 participants