Closed
Description
Description
In development mode on Android, if the app has no JS bundle and no fallback available, the app displays a RedBox error saying either Unable to load script.
or Could not connect to development server.
. If the user resolves this issue and chooses Reload
, the app will then successfully download the bundle from Metro, but will not actually initialize the application. Instead, the app simply shows a blank white screen.
Here's the series of steps that causes this to happen:
runCreateReactContextOnNewThread
is called as part of normal React Native initialization- The
mCreateReactContextThread
thread is created and started - Since no bundle is available, the thread exits early because
createReactContext
throws an exception; this is what triggers the RedBox - The user starts Metro and taps
Reload
, which causesBundleDownloader
to download the bundle BundleDownloader
'sonSuccess
callback callsrecreateReactContextInBackground
recreateReactContextInBackground
sees thatmCreateReactContextThread
was already set earlier, and thus setsmPendingReactContextInitParams
- The newly set
mPendingReactContextInitParams
is never used and the app sits idle
I have a proposed fix that I'll send a PR for.
Version
0.66.4
Output of npx react-native info
System:
OS: macOS 12.0.1
CPU: (10) arm64 Apple M1 Max
Memory: 573.08 MB / 32.00 GB
Shell: 5.8 - /bin/zsh
Binaries:
Node: 16.13.1 - ~/.nvm/versions/node/v16.13.1/bin/node
Yarn: 1.22.17 - ~/.nvm/versions/node/v16.13.1/bin/yarn
npm: 8.3.0 - ~/.nvm/versions/node/v16.13.1/bin/npm
Watchman: 2022.01.03.00 - /opt/homebrew/bin/watchman
Managers:
CocoaPods: 1.11.2 - /Users/samkline/.rbenv/shims/pod
SDKs:
iOS SDK:
Platforms: DriverKit 21.2, iOS 15.2, macOS 12.1, tvOS 15.2, watchOS 8.3
Android SDK:
Android NDK: 20.1.5948944
IDEs:
Android Studio: 2020.3 AI-203.7717.56.2031.7935034
Xcode: 13.2.1/13C100 - /usr/bin/xcodebuild
Languages:
Java: 11.0.11 - /usr/bin/javac
npmPackages:
@react-native-community/cli: Not Found
react: 17.0.2 => 17.0.2
react-native: 0.66.4 => 0.66.4
react-native-macos: Not Found
npmGlobalPackages:
*react-native*: Not Found
Steps to reproduce
- Stop any locally running Metro service
- Start a new project with
npx react-native init
- Run
yarn android
to build and launch the app in your emulator - Wait until you see the RedBox error
- Run
yarn start
- In the app, tap
Reload
to load the bundle from Metro - The app loads the bundle from Metro, then leaves you at a blank white screen
Snack, code example, screenshot, or link to a repository
No response