kacgrzes / use-pomodoro

Use pomodoro logic wrapped in a react hook
https://kacgrzes.github.io/use-pomodoro/
9 stars 1 forks source link

The timing is not accurate when the page is in the background #1

Open haydenull opened 2 years ago

haydenull commented 2 years ago

Thanks to this wonderful tool, I recently discovered a small problem

  1. open https://kacgrzes.github.io/use-pomodoro/ with Chrome
  2. click the start button
  3. Use my phone's timer while switching to another TAB
  4. Back to Pomodoro after ten minutes
  5. The pomodoro has gone by five minutes and 15 seconds

I think this is probably because setInterval may be interrupted when the page  is inactive,Maybe we could use a timestamp comparison to keep track of how much time has passed。

kacgrzes commented 2 years ago

Hello @haydenull you are right, I have also noticed that recently. Do you have any idea on how to resolve this issue? I will try to work on it.

haydenull commented 2 years ago

Hello, I have submitted a pr. Maybe can help with this. Please let me know if you have any questions.

https://github.com/kacgrzes/use-pomodoro/pull/2.

christianhubbard commented 1 year ago

I'm using this in a project and noticing this as well. Any chance this gets fixed? Happy to help.

I think the 'setInterval' function in javascript should be used to run the timer, instead of a useEffect in the useInterval hook