expo / eas-cli

Fastest way to build, submit, and update iOS and Android apps
https://docs.expo.dev/eas/
MIT License
767 stars 81 forks source link

EAS OTA Update Results in Application Fail State #1458

Closed meatberger closed 1 year ago

meatberger commented 1 year ago

Build/Submit details page URL

https://expo.dev/accounts/meatberger/projects/Datagee/builds/701ede57-b15c-464c-85b7-404848bea137

Summary

When building my application for all platforms using eas build --profile preview --platform all the app works perfectly fine on iOS and Android. When I push a single eas update (single text change or no change) to the channel using eas update --branch release and kill the app to initiate the OTA update, the application never receives a state update from the auth context, resulting in the app on all platforms only showing a loading indicator.

Managed or bare?

Managed

Environment

expo-env-info 1.0.5 environment info: System: OS: macOS 11.6.1 Shell: 5.8 - /bin/zsh Binaries: Node: 16.18.0 - ~/.nvm/versions/node/v16.18.0/bin/node Yarn: 1.22.19 - ~/.nvm/versions/node/v16.18.0/bin/yarn npm: 8.19.2 - ~/.nvm/versions/node/v16.18.0/bin/npm Watchman: 2022.07.04.00 - /usr/local/bin/watchman Managers: CocoaPods: 1.9.3 - /usr/local/bin/pod SDKs: iOS SDK: Platforms: DriverKit 21.2, iOS 15.2, macOS 12.1, tvOS 15.2, watchOS 8.3 IDEs: Android Studio: 4.0 AI-193.6911.18.40.6626763 Xcode: 13.2.1/13C100 - /usr/bin/xcodebuild npmPackages: @expo/webpack-config: ^0.17.0 => 0.17.2 expo: ^46.0.0 => 46.0.16 react: 18.0.0 => 18.0.0 react-dom: 18.0.0 => 18.0.0 react-native: 0.69.6 => 0.69.6 react-native-web: ~0.18.7 => 0.18.9 react-navigation: ^4.4.4 => 4.4.4 npmGlobalPackages: eas-cli: 2.4.1 expo-cli: 6.0.6 Expo Workflow: managed

Expo doctor: 🎉 Didn't find any issues with the project!

Error output

No response

Reproducible demo or steps to reproduce from a blank project

This was realized on a project with firebase and the react context API

  1. Initialize a blank project
  2. Install firebase using yarn add firebase
  3. Create a context provider with a user variable in state (user, setUser...)
  4. Set the auth state change handler to setUser
  5. Consume the context in a child component
  6. The app will authenticate successfully and set the user variable for the children as expected. Push an eas update

The app remains in a fail state. I created a snack, but am having trouble installing firebase in the environment so I could not test it. https://snack.expo.dev/@meatberger/eas-update-bug-example

Basically, the user variable starts as undefined. When firebase checks auth, "user" gets set to null if not logged in or a user variable if the auth is successful. I am rendering a loading view while the auth is undefined, log in controls if the user is null, else show the application. I am using this auth in 4 production applications with 0 issues. The auth works great when built, but the app breaks after an eas update, even with no changes (only shows loading screen after update). I tried adding an alert to the authstatechange, and the user variable is still being set properly as expected. However, it is as if state will not update for the children with the new user variable when the auth state changes. I tried drilling the user variable instead of consuming context and get the same result.

Have tried: killing the app, logging out first (or never logging in), uninstalling and reinstalling the build, etc. The result is still the same. If i run build again with eas build --profile preview --platform all the app works great. A single eas update --branch release and the app turns into a loading indicator on all platforms. Your help is greatly appreciated.

BTW my eas.json looks like:

{
  "cli": {
    "version": ">= 2.2.1"
  },
  "build": {
    "development": {
      "developmentClient": true,
      "distribution": "internal"
    },
    "preview": {
      "distribution": "internal",
      "channel": "release"
    },
    "production": {
      "channel": "main"
    }
  },
  "submit": {
    "production": {}
  }
}
selimjouan commented 1 year ago

Do you set environment variables during build phase? (I guess you set Firebase API key?) If so, you need to set them again when you use eas update. Otherwise, they are set back to null.

Hope it'll help.

meatberger commented 1 year ago

Do you set environment variables during build phase? (I guess you set Firebase API key?) If so, you need to set them again when you use eas update. Otherwise, they are set back to null.

Hope it'll help.

Actually, this was related to my issue! Thank you for the suggestion. I am marking this as resolved. I had two separate firebase configurations that were being used conditionally based on the ENVs and I was not setting the ENVs again on eas update. This caused a second Firebase app constructor failure after the update (attempting to init Firebase with my dev config when the initial application was created with the prod config). This caused the firebase variable to always be undefined after the update, hence my loading screen showing.