expo / vscode-expo

Expo Tools keep you productive with debugging, IntelliSense, and prebuild previews
https://marketplace.visualstudio.com/items?itemName=expo.vscode-expo-tools
MIT License
413 stars 11 forks source link

[dev client] Debugger crashes app on breakpoint hit #231

Closed erik-lissen closed 10 months ago

erik-lissen commented 11 months ago

Description of the bug

I managed to use the built in launch command to connect to my app that uses dev-client. The app successfully hits a breakpoint. Sometimes it crashes the app immediately, sometimes it works and halts execution. When it does stop correctly, if I try to look at variables in VSCode it crashes immediately.

To Reproduce

Connect to the app

Expected behavior

Should be able to inspect variables

Actual behavior

Crash

Additional context

There's no error in my logs, not sure how to debug this issue. If you could provide some guidance on how to debug the problem or how to give you more information I would be glad to help. Debugging does work in the chrome debugger (by pressing 'j' in terminal).

I'm using a monorepo if that makes any difference.

iboxgithub commented 11 months ago

Same problem for us

aeslami commented 11 months ago

I'm experiencing the same issue here. Was so excited about the debugger in SDK49 but can't use it.

papidb commented 11 months ago

I'm also experiencing this issue, same issue and setup as the initial issue raised, I can't seem to get it to work.

renzo4web commented 11 months ago

I am experiencing the same problem, using bun and expo 49.

ms007 commented 11 months ago

Same Problem. Really simple app with just one button. Crashes, when Breakpoint hit. console.log statements do work. OS: both Windows 11 / Mac OS (Ventura)

antoni-minkiewicz commented 11 months ago

Same problem for me

ghry5 commented 11 months ago

Sounds like https://github.com/microsoft/vscode-js-debug/issues/1837

ghry5 commented 11 months ago

After some more testing I can confirm that debugging works just find by installing VS Code v1.82.2

thully commented 11 months ago

Same issue here with Expo 49 and VSCode Expo Tools. VS Code 1.83.1 crashes on reaching breakpoints, while VS Code 1.82.3 works fine.https://github.com/microsoft/vscode-js-debug/issues/1837 was apparently fixed with a change to react-native-tools - does vscode-expo perhaps need a similar update to fix this here?

orefors commented 10 months ago

And same issue here as well, crashes on reaching bound break point. Windows 11, Node.js v 18.15.0, VS Code v 1.83.1, expo-tools v 1.2.1.

Just as ghry5 mentioned above, downgrading VS Code to v 1.82.2 works for me as well

fatihsever commented 10 months ago

Same issue here

MacOS Ventura VSCode 1.85.0-insider with Expo Tools v1.2.1 (pre-release) VSCode 1.84.0 with Expo Tools v1.0.7

fatihsever commented 10 months ago

I think, vscode-react-native solved the same issue by updating some code about callFunctionOn that mentioned on the vscode-js-debug repo comment.

https://github.com/microsoft/vscode-react-native/issues/2052 Issue https://github.com/microsoft/vscode-react-native/pull/2055 PR

alexey-yarmosh commented 10 months ago

Hey, are there any plans to fix that? Extension seems to be totally unusable right now

jeandonaldroselin commented 10 months ago

Same issue here with Expo 49 and VSCode Expo Tools. VS Code 1.83.1 crashes on reaching breakpoints, while VS Code 1.82.3 works fine.microsoft/vscode-js-debug#1837 was apparently fixed with a change to react-native-tools - does vscode-expo perhaps need a similar update to fix this here?

For now the best workaround is this message. Expo did not deliver a fix for now but by downloading the version 1.82.3 of vscode you are able to make it works :

Download page => https://code.visualstudio.com/updates/v1_82

byCedric commented 10 months ago

Hi all! Sorry for the delayed response. I was unavailable due to a short break. Let me quickly address some of the questions/mentions here.

Sounds like https://github.com/microsoft/vscode-js-debug/issues/1837

I think that's about right. There seems to be a change in the script that fetches debug info from within the app / scope. This script does not seem to play well with Hermes.

I think, vscode-react-native solved the same issue by updating some code about callFunctionOn that mentioned on the https://github.com/microsoft/vscode-js-debug/issues/1837#issuecomment-1754398203.

https://github.com/microsoft/vscode-react-native/issues/2052 Issue https://github.com/microsoft/vscode-react-native/pull/2055 PR

Thanks for that! I'll dig into these changes and see what we can do on Expo's side.

Hey, are there any plans to fix that? Extension seems to be totally unusable right now

The extension is not just debugging, it also enhances vscode with in-editor docs about app.json, eas.json, and store.config.json. That being said, debugging is an important feature of this extension and will prioritize a fix for this.

byCedric commented 10 months ago

PR to fix this is in review! If you are running into this, you could use this patch with patch-package to include the fix for SDK 49 right now.

You don't need to update the vscode-expo extension!

byCedric commented 10 months ago

Reopening, patch has not been shipped yet.

fatihsever commented 10 months ago

PR to fix this is in review! If you are running into this, you could use this patch with patch-package to include the fix for SDK 49 right now.

You don't need to update the vscode-expo extension!

Great! I can upgrade VSCode to the latest version again. I really like the debug toolbar shows up in the Command Center in the latest versions. I lost this when I downgraded.

For those who missed this feature: https://code.visualstudio.com/updates/v1_83#_command-center-and-debug-toolbar

cc-debugtoolbar
byCedric commented 10 months ago

Another (temporary) workaround would be to use an Expo dev client instead of Expo Go. I'll raise this issue internally, but it is likely related to an unexpected Hermes error within Expo Go.

Even when the JS code evaluated by vscode can't be run inside Hermes, e.g. using language features not available in Hermes, it should never cause the app to crash.

erik-lissen commented 10 months ago

@byCedric I raised the issue specifically for dev-client as it says in the title and description so not sure I understand your comment

byCedric commented 10 months ago

@erik-lissen Sorry, I was in the middle of a rabbit hole there and might not have been clear.

You mentioned that there are multiple cases where the vscode debugger could crash the app, e.g. by expanding the scope of the variables, or sometimes it crashes on a single breakpoint.

The "crash on breakpoint" is caused by a JS snippet injected by vscode to fetch information about certain variables and objects. I wrote a patch for the @expo/cli that prevents this snippet from being injected and should prevent crashing when hitting breakpoints.

Unfortunately, the CDP spec has more injection methods, and each CDP client has separate injection scripts. Expanding the scope variables, for example, uses Runtime.callFunctionOn in vscode, but Chrome Devtools uses Runtime.compileScript and Runtime.evaluate. Upon investigating this deeper, we found an issue in the Hermes and the versioned React Native layers from Expo Go. In other cases, an injected JS snippet could cause a hard crash because Hermes throws an exception without it being appropriately caught. This is likely the cause of the crashes related to expanding the scope of the variables.

Using dev clients solves some of these cases, but definitely not all. Hope this makes a bit more sense than my previous comment 😄

thully commented 10 months ago

The fix in Expo has been merged in the latest expo 49.0.18 release (or more specifically, in @expo/cli@0.10.15). I updated my project to that release and updated to the latest VS Code and everything seems fine now. Unless there is another issue elsewhere with this that has not been fix, this can probably be closed.

byCedric commented 10 months ago

You are right @thully! But, we still have one more fix to merge and release (specifically for Expo Go) - https://github.com/expo/expo/pull/25355

Once that's done, I'll close this issue.

byCedric commented 10 months ago

After talking internally, we likely will only merge the Expo Go change into SDK 50. Closing this issue as the original issue is resolved in expo@49.0.18.

byCedric commented 10 months ago

Thanks all! We discovered a really hard-to-track bug in React Native itself due to this issue 😄 https://github.com/facebook/react-native/issues/41498