question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Promise polyfill and async/await transpliation make it hard to debug

See original GitHub issue

Description:

During debugging, stack traces of code that contains Promises doesn’t supply data about code executed before promise resolution.

That is because currently have two mechanisms in place:

  1. Promises are polyfilled using promise
  2. async/await is transpiled using regenerator.

We can get a pretty stack trace if we manage to turn off the Promise polyfill and regenerator transpliations.

  1. Promise polyfill can be removed on both iOS (Supported from iOS 10 which is React Native’s new minimum & Android (JSCore & Hermes on Android support native Promises). Should be tested thoroughly to make sure the native implementations work as expected and are stable.

  2. Regenerator (async await) can’t be removed yet (as Hermes doesn’t support it and iOS minimum is iOS 12), but maybe we can supply an easy option to turn it off (using some flag in metro?)

React Native version:

0.61

Steps To Reproduce

  1. Create a react-native project
  2. Write code with async/await or Promises
  3. Debug
  4. Put a breakpoint after promise resolution (inside .then() callback or after await
  5. Look at the stack trace

Expected Results

See the full stack trace including code that ran before the Promise was initiaited, as is supported in Chrome DevTools.

Snack, code example, screenshot, or link to a repository:

How the stack trace looks currently (bad): image (1) How the stack trace looks with native Promise & async/await (good): image (2)

Code taken from open source project react-native-demo

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:17
  • Comments:6

github_iconTop GitHub Comments

1reaction
EdenGottliebcommented, Aug 19, 2021

(using native Promise works fine)

@EdenGottlieb could you please share how did you manage to disable React Native’s Promise polyfill?

Sure. This was a long time ago, so I can’t recall it perfectly, and it may not work on recent versions, so take this with a pinch of salt. It worked in a “hello world” app but didn’t do so well in a full fledged app.

For using native Promise: node_modules/react-native/Libraries/Core/InitializeCore.js: Comment out this line: require('./polyfillPromise');

For native async-await (this one caused me most of the problems):

  1. node_modules/react-native/Libraries/Core/InitializeCore.js: Comment out this line: require('./setUpRegeneratorRuntime');
  2. node_modules/metro-react-native-babel-preset/src/configs/main.js: From the defaultPlugins array, remove the entry with @babel/plugin-transform-regenerator (should look something like [require("@babel/plugin-transform-regenerator")])

Good luck!

0reactions
SimpleCreationscommented, Aug 18, 2021

(using native Promise works fine)

@EdenGottlieb could you please share how did you manage to disable React Native’s Promise polyfill?

Read more comments on GitHub >

github_iconTop Results From Across the Web

node.js - Debugging never resolving promises / async await
On the project I'm working on, we sometimes have some await never resolving due to bad promises never resolving. This is kind of...
Read more >
Top 5 promise-polyfill Code Examples - Snyk
To help you get started, we've selected a few promise-polyfill examples, based on popular ways it is used in public projects.
Read more >
Javascript Interview Questions ( Promises ) - YouTube
... #Javascript #FrontendInterviewJavascript Interview Questions on Async Javascript including Promises, Callback, async/await etc will be .
Read more >
Promise, Async, Await— Understanding and Implementation
It is hard to read, hard to debug, and easy to break while executing. So to avoid callbacks we use Promises or Async/Await....
Read more >
Flow Control in Modern JS: Callbacks to Promises to Async ...
... into key problems related to asynchronous programming in JavaScript, showing how to make your life easier with Promises and async/await.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found