Skip to content

Commit

Permalink
RN: Remove Android setTimeout Warning
Browse files Browse the repository at this point in the history
Summary:
Many third-party libraries (especially data management and caching ones) make use of long timeouts.

There are currently no plans to change `setTimeout` on Android to support firing when apps are in the background. In the meantime, this warning is not actionable for developers who are using these frameworks. Their workarounds are to 1) deal with the noise in their logs, or 2) suppress the warning.

Changelog:
[General][Removed] - Removed warning on Android for `setTimeout` with delays greater than 1 minute.

Reviewed By: lunaleaps

Differential Revision: D24964958

fbshipit-source-id: 1b40c8ba95d554c29dec74477aa63ea3ef8e4768
  • Loading branch information
yungsters authored and facebook-github-bot committed Nov 14, 2020
1 parent 9be3356 commit 480dabd
Showing 1 changed file with 0 additions and 27 deletions.
27 changes: 0 additions & 27 deletions Libraries/Core/Timers/JSTimers.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
'use strict';

const BatchedBridge = require('../../BatchedBridge/BatchedBridge');
const Platform = require('../../Utilities/Platform');
const Systrace = require('../../Performance/Systrace');

const invariant = require('invariant');
Expand All @@ -36,14 +35,6 @@ export type JSTimerType =
const FRAME_DURATION = 1000 / 60;
const IDLE_CALLBACK_FRAME_DEADLINE = 1;

const MAX_TIMER_DURATION_MS = 60 * 1000;
const IS_ANDROID = Platform.OS === 'android';
const ANDROID_LONG_TIMER_MESSAGE =
'Setting a timer for a long period of time, i.e. multiple minutes, is a ' +
'performance and correctness issue on Android as it keeps the timer ' +
'module awake, and timers can only be called when the app is in the foreground. ' +
'See https://github.com/facebook/react-native/issues/12981 for more info.';

// Parallel arrays
const callbacks: Array<?Function> = [];
const types: Array<?JSTimerType> = [];
Expand Down Expand Up @@ -218,15 +209,6 @@ const JSTimers = {
* @param {number} duration Number of milliseconds.
*/
setTimeout: function(func: Function, duration: number, ...args: any): number {
if (__DEV__ && IS_ANDROID && duration > MAX_TIMER_DURATION_MS) {
console.warn(
ANDROID_LONG_TIMER_MESSAGE +
'\n' +
'(Saw setTimeout with duration ' +
duration +
'ms)',
);
}
const id = _allocateCallback(
() => func.apply(undefined, args),
'setTimeout',
Expand All @@ -244,15 +226,6 @@ const JSTimers = {
duration: number,
...args: any
): number {
if (__DEV__ && IS_ANDROID && duration > MAX_TIMER_DURATION_MS) {
console.warn(
ANDROID_LONG_TIMER_MESSAGE +
'\n' +
'(Saw setInterval with duration ' +
duration +
'ms)',
);
}
const id = _allocateCallback(
() => func.apply(undefined, args),
'setInterval',
Expand Down

0 comments on commit 480dabd

Please sign in to comment.