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.

setTimeout executes callback immediately when Remote JS Debugging is enabled

See original GitHub issue

🐛 Bug Report

Environment

Expo CLI 2.17.1 environment info: System: OS: Windows 10 Binaries: Yarn: 1.15.2 - C:\Program Files (x86)\Yarn\bin\yarn.CMD npm: 6.4.1 - C:\Program Files (x86)\nodejs\npm.CMD

Target: Android and iOS

Steps to Reproduce

  1. Create a new expo app with expo init, using the blank template.
  2. Add the following function to App.js and invoke the function from componentDidMount()
function loop() {
    console.log(new Date().getSeconds())
    setTimeout(loop, 1000)
}
  1. expo start and open the app on an iOS or Android device. Tested on iOS 12.2 and Android 7.1.1.
  2. By default, remote JS debugging is disabled. The log messages in the expo console window will show the expected behavior: “1, 2, 3, 4, 5, …”
  3. On the mobile device, enable remote JS debugging from the developer menu. The log messages in the Expo console windows will be “4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, …”. I.e. the loop is executing very rapidly.

Expected Behavior

The console.log() messages show each second exactly once while Remote JS Debugging is enabled:

1
2
3
4
5
6
...

Actual Behavior

console.log() is called rapidly and each second displays many times, e.g.:

1
1
1
1
1
1
1
1
1
1
2
2
2
2
2
2
2
2
2
2
...

Reproducible Demo

https://github.com/srmagura/expo-settimeout-repro

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
srmaguracommented, Feb 28, 2020

I was able to reproduce it in bare React Native and found that there is already an issue for it in the React Native repo, #26828. 😁

Turns out it occurs when the iPhone’s time and the PC’s time don’t match. My iPhone’s clock has been 10+ minutes in the future this whole time (possibly because it is lacking a SIM card), so that explains it!

0reactions
sandinosasocommented, Jan 14, 2021

This is still an Issue I can confirm, in the latest expo version 0.40.0

expo@~40.0.0:
  version "40.0.0"
  resolved "https://registry.yarnpkg.com/expo/-/expo-40.0.0.tgz#6caf03587532cd18b482991332a8b75eeca2fcb7"

It was hard for me to figure out what was going on, I literally expended hours thinking my Hooks logic was wrong, then I doubted the Snackbar component from ‘react-native-paper’ (internally uses setTimeout for the duration it uses to show the snackbar) was not working ok, till I figured out that it was this issue.

This also happens when you go to https://snack.expo.io/ and Choose Android as Device (so I assume that it using debug mode on).

Try for example: SnackBar Expo Example

Read more comments on GitHub >

github_iconTop Results From Across the Web

Javascript setTimeout Immediately runs in React Native
My problem is that setTimeout runs ‍ about 5 seconds earlier. For example, when I set it to 5 seconds , it runs...
Read more >
Mocha - the fun, simple, flexible JavaScript test framework
Mocha is a feature-rich JavaScript test framework running on Node.js and in the browser, making asynchronous testing simple and fun. Mocha tests run...
Read more >
8 Essential Node.js Interview Questions and Answers | Toptal®
Comprehensive, community-driven list of essential Node.js interview questions. Whether you're a candidate or interviewer, these interview questions will ...
Read more >
intro - CommandFusion iViewer - Scripting Documentation
To help you with developing and debugging your scripts, iViewer provides an easy to use Remote Debugger that runs in your computer's web...
Read more >
Debug user code with Just My Code - Visual Studio (Windows)
Just My Code is a debugging feature that automatically steps over calls to non-user code. Learn how to enable, disable, ...
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