nativescript-community / nativescript-vscode-extension

A Visual Studio Code Extension for NativeScript
https://www.nativescript.org/visual-studio-code
Apache License 2.0
82 stars 32 forks source link

Adding breakpoint to events that are raised during the "loading" of a Page are not hit the first time that Page is navigated to #248

Closed VladimirAmiorkov closed 5 years ago

VladimirAmiorkov commented 5 years ago

Environment

Describe the bug When I place a breakpoint in an event that is consider to be raised very quickly like the onLoaded event of a Page, that breakpoint is not hit if this is the first navigation to that Page in the app's lifecycle. After that if you go back to the previous Page and navigate again to the other one the breakpoint is hit correctly.

To Reproduce Using the nativescript-ui-listview demo application that can be found here simply add a breakpoint here, start the app and navigate to the "Getting Started" example.

Expected behavior Breakpoints are hit correctly no matter where they are placed in the app's code.

Sample project Using the nativescript-ui-listview demo application that can be found [here]

VladimirAmiorkov commented 5 years ago

Workaround is to manually set the debugger in the code: debugger;

DimitarTachev commented 5 years ago

Hi @VladimirAmiorkov

Thanks for the detailed description.

This issue should be reproducible only on very slow devices.

When a script file is loaded for the first time, it has to be parsed and the Runtime sends a script parsed message through the Chrome protocol. Once this message is received, the client (Chrome Dev Tools or Visual Studio Code) sets the specified breakpoints. If the app is running on a slow device, the script parsing is slower than the page load and the breakpoint is skipped on the first navigation.

In order to get the breakpoints during page navigation working, you could use hardcoded debugger; statements in your code, run on a faster device or run your app with --bundle which will bundle all of your pages in bundle.js and they will be parsed together during the app start.