-
Notifications
You must be signed in to change notification settings - Fork 24.3k
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
fix /open-debugger failing after relaunching Metro/target app #47623
Open
EdmondChuiHW
wants to merge
2
commits into
facebook:main
Choose a base branch
from
EdmondChuiHW:export-D65952134
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+80
−0
Conversation
This file contains 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
facebook-github-bot
added
CLA Signed
This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
p: Facebook
Partner: Facebook
Partner
labels
Nov 14, 2024
This pull request was exported from Phabricator. Differential Revision: D65952134 |
Summary: Changelog: [iOS][Fixed] - fix `r` & `d` not working from Metro sometimes While investigating these bugs, I've come across some cases where `r` (Reload) & `d` (Open Dev Menu) not working in Metro. * T206141946 / [WP: Reconnecting dev tools does not work after restarting the app](https://fb.workplace.com/groups/rn.debugger.feedback/posts/1107620434125533) * T206754760 / [WP: Can't launch DevTools from Metro sometimes](https://fb.workplace.com/groups/rn.debugger.feedback/posts/1112235073664069/) This is because when we 1. Start app without Metro 1. Start Metro 1. Reload from Dev Menu (rage shake) `RCTPackagerConnection` did not get notified about the change in bundle URL. It'd stay "listening" to the commands from the local bundle instead of Metro . Differential Revision: D65973309
…ok#47623) Summary: Changelog: [iOS][Fixed] - "Reconnect DevTools" button not working sometimes Hotfix for "Reconnect DevTools" button not working: * T206141946 / [WP: Reconnecting dev tools does not work after restarting the app](https://fb.workplace.com/groups/rn.debugger.feedback/posts/1107620434125533) * T206754760 / [WP: Can't launch DevTools from Metro sometimes](https://fb.workplace.com/groups/rn.debugger.feedback/posts/1112235073664069/) Basically, this dialog will keep reappearing like a bad dream: {F1960030622} # Repro Part 1 (Fixed in base stack D65973309) 1. Do NOT have Metro ready. 1. Build and run RNTester/FB Wilde 1. They should be using the local bundled version. App may prompt you to start Metro. 1. Start Metro 1. Go to the device Dev Menu (rage shake) and select Reload 1. Press `r` or `d` in Metro Expected: Reload and Dev Menu work accordingly Actual: Metro fails with `No apps connected`: {F1960039703} Part 2 (Fixed in this diff) 1. Open React Native DevTools via Metro `j` key or Dev Menu (rage shake) 1. Kill Metro 1. The RN DevTools should show the "disconnected" dialog 1. Start Metro 1. Click "Reconnect DevTools" in RN DevTools Expected: reconnects Actual: dialog reappears with an error in Metro: {F1960043097} Interestingly, the `r` and `d` keys from Metro works. # Root cause(s) Part 1: See D65973309 Part 2: The error indicates the target/device failed to call `/inspector/device` to register itself. The subsequent calls to `/json/list` returns empty and `/open-debugger` throws. 1. But because `r` & `d` (heh) works, we can observe that there is some kind of auto-reconnect mechanism: https://www.internalfb.com/code/fbsource/[cfe1706a60b2]/xplat/js/react-native-github/packages/react-native/Libraries/WebSocket/RCTReconnectingWebSocket.m?lines=77-82 1. We do have auto-reconnect for `j` too: https://www.internalfb.com/code/fbsource/[cfe1706a60b2]/xplat/js/react-native-github/packages/react-native/ReactCommon/jsinspector-modern/InspectorPackagerConnection.cpp?lines=246-254 But unfortunately it only tries once. A long-term fix would be calling reconnect recursively like the Objective-C impl above, e.g. ``` delegate_->scheduleCallback( [weakSelf = weak_from_this()] { auto strongSelf = weakSelf.lock(); if (strongSelf && !strongSelf->closed_) { strongSelf->reconnectPending_ = false; strongSelf->connect(); // Keep trying. Never. Give. Up. if (!strongSelf->isConnected()) { strongSelf->reconnect(); } } }, RECONNECT_DELAY); ``` It appears that the current impl of `isConnected()` is not a true reflection of the web socket state. My time box for this task ran out, so we'll do a hot fix for the short-term: since we know `r` & `d` reliably reconnects, we'll piggy-back on its lifecycle to attempt reconnection. This works. # PS If you start the app with Metro running in step 1, this bug is not present. This is the reason why FB Wilde/Marketplace/Quantum engineers run into this more often (because its custom menu changes the JS URL after start up) Differential Revision: D65952134
EdmondChuiHW
force-pushed
the
export-D65952134
branch
from
November 15, 2024 00:34
91675c0
to
fdc26e6
Compare
This pull request was exported from Phabricator. Differential Revision: D65952134 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
CLA Signed
This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
fb-exported
p: Facebook
Partner: Facebook
Partner
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:
Changelog:
[iOS][Fixed] - "Reconnect DevTools" button not working sometimes
Hotfix for "Reconnect DevTools" button not working:
Basically, this dialog will keep reappearing like a bad dream:
{F1960030622}
Repro
Part 1 (Fixed in base stack D65973309)
r
ord
in MetroExpected: Reload and Dev Menu work accordingly
Actual: Metro fails with
No apps connected
:{F1960039703}
Part 2 (Fixed in this diff)
j
key or Dev Menu (rage shake)Expected: reconnects
Actual: dialog reappears with an error in Metro:
{F1960043097}
Interestingly, the
r
andd
keys from Metro works.Root cause(s)
Part 1: See D65973309
Part 2:
The error indicates the target/device failed to call
/inspector/device
to register itself. The subsequent calls to/json/list
returns empty and/open-debugger
throws.r
&d
(heh) works, we can observe that there is some kind of auto-reconnect mechanism:https://www.internalfb.com/code/fbsource/[cfe1706a60b2]/xplat/js/react-native-github/packages/react-native/Libraries/WebSocket/RCTReconnectingWebSocket.m?lines=77-82
j
too:https://www.internalfb.com/code/fbsource/[cfe1706a60b2]/xplat/js/react-native-github/packages/react-native/ReactCommon/jsinspector-modern/InspectorPackagerConnection.cpp?lines=246-254
But unfortunately it only tries once. A long-term fix would be calling reconnect recursively like the Objective-C impl above, e.g.
It appears that the current impl of
isConnected()
is not a true reflection of the web socket state. My time box for this task ran out, so we'll do a hot fix for the short-term: since we knowr
&d
reliably reconnects, we'll piggy-back on its lifecycle to attempt reconnection. This works.PS
If you start the app with Metro running in step 1, this bug is not present. This is the reason why FB Wilde/Marketplace/Quantum engineers run into this more often (because its custom menu changes the JS URL after start up)
Differential Revision: D65952134