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
- Create a new expo app with
expo init
, using the blank template. - Add the following function to App.js and invoke the function from componentDidMount()
function loop() {
console.log(new Date().getSeconds())
setTimeout(loop, 1000)
}
expo start
and open the app on an iOS or Android device. Tested on iOS 12.2 and Android 7.1.1.- 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, …”
- 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
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:12 (5 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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!
This is still an Issue I can confirm, in the latest expo version 0.40.0
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