Auto-reconnect PackagerConnection to Metro dev server#56625
Open
javache wants to merge 1 commit intofacebook:mainfrom
Open
Auto-reconnect PackagerConnection to Metro dev server#56625javache wants to merge 1 commit intofacebook:mainfrom
javache wants to merge 1 commit intofacebook:mainfrom
Conversation
Summary: When MWA starts before Metro is running, PackagerConnection's WebSocket connection to Metro's `/message` endpoint silently fails with no retry. The developer must restart MWA after starting Metro to get HMR working. This diff adds reconnection logic to PackagerConnection so it automatically retries when Metro becomes available. On initial connect failure or WebSocket disconnect, PackagerConnection schedules a retry after 5 seconds using the existing `WebSocketClientFactory` to create a fresh client. On successful reconnect, it fires `liveReloadCallback_()` which triggers `FoxReactHost::reloadReactInstance()` to load the bundle from Metro and set up HMR. The reconnection is event-driven: each retry is a short-lived thread that sleeps 5 seconds then calls `attemptConnection()`. The connect callback handles success/failure — no long-lived polling thread. The `active_` flag is set to false in the destructor to stop retries during shutdown. Combined with D97570592's push-based route invalidation, this completes the dev loop: Metro can start at any time, PackagerConnection auto-reconnects, HMR keeps the bundle fresh, and route changes propagate automatically. Differential Revision: D97823787
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
When MWA starts before Metro is running, PackagerConnection's WebSocket connection to Metro's
/messageendpoint silently fails with no retry. The developer must restart MWA after starting Metro to get HMR working.This diff adds reconnection logic to PackagerConnection so it automatically retries when Metro becomes available. On initial connect failure or WebSocket disconnect, PackagerConnection schedules a retry after 5 seconds using the existing
WebSocketClientFactoryto create a fresh client. On successful reconnect, it firesliveReloadCallback_()which triggersFoxReactHost::reloadReactInstance()to load the bundle from Metro and set up HMR.The reconnection is event-driven: each retry is a short-lived thread that sleeps 5 seconds then calls
attemptConnection(). The connect callback handles success/failure — no long-lived polling thread. Theactive_flag is set to false in the destructor to stop retries during shutdown.Combined with D97570592's push-based route invalidation, this completes the dev loop: Metro can start at any time, PackagerConnection auto-reconnects, HMR keeps the bundle fresh, and route changes propagate automatically.
Differential Revision: D97823787