Skip to content

react native setTimeout Android warning #173

@bojidaryovchev

Description

@bojidaryovchev

Hello there, I saw the discussion here expo/examples#209 and that the implementation around handling refresh tokens with Expo is still foggy so I turned to your library. I successfully plugged it in my react native project however I am getting the following warning:

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 facebook/react-native#12981 for more info.

which comes from this piece of code:

  setTimeout(() => {
      let refreshTokenData = data;
      if (token.refresh_token) {
          refreshTokenData = {
              ...data,
              refresh_token: token.refresh_token,
              grant_type: "refresh_token",
          };
      }
      fetchAccessToken(refreshTokenData, domain, setAccessToken, setUser, onTokenRequestFailure);
  }, token.expires_in * 1000 - requestNewAccessTokenBuffer);

I found out that I can suppress the warning using LogBox.ignoreLogs(['Setting a timer for a long period of time']); however I am not sure that would be the right way to go so I wanted to ask for your expertise on the matter as to what would the best approach be. Regards!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions