SupremeTechnopriest / react-idle-timer

User activity timer component
https://idletimer.dev
MIT License
1.15k stars 143 forks source link

Problems with getTotalActiveTime() and reset() on v5.4 #272

Closed d9k closed 2 years ago

d9k commented 2 years ago

Bug information

Affected Module

Describe the bug

timer.reset() doesn't affect timer.getTotalActiveTime() result.

To Reproduce

const timerProps = {
 debounce: 500,
 timeout: 2000,
}

const timer = useIdleTimer(timerProps);

// after some time active

const T1 = timer.getTotalActiveTime();

timer.reset();

// then immediately after

const T2 = timer.getTotalActiveTime();

Expected behavior

T2 should be 0. But it's T1.

System Information (please complete the following information)

Additional context

See previous issue about getTotalActiveTime() and reset: https://github.com/SupremeTechnopriest/react-idle-timer/issues/257

SupremeTechnopriest commented 2 years ago

This was actually by design, but after the recent changes to reset I think your suggestion should be implemented. I will get this out in the next release.

SupremeTechnopriest commented 2 years ago

@d9k, This is resolved in 5.4.1. I added a test for this case so you should be good to go, but feel free to re open if you are still having issues.

d9k commented 2 years ago

I tried to update my code. With 5.4.2 after reset() time doesn't go "below zero", but actually there is a delay before getTotalActiveTime() gets > 0 again. So strange...

d9k commented 2 years ago

1) Can't debug compiled react-idle-timer with storybook in my project because when I try to pretty print oneliner in Chrome dev tools it's empty 2) Tried to include react-idle-timer to the code of my project to debug how it works with my code but got so many compilation errors...

ERROR in /home/user/my-project/lib/react-idle-timer/IdleTimerContext.tsx(7,59):   
TS2345: Argument of type 'null' is not assignable to parameter of type 'IIdleTimer'.               
ERROR in /home/user/my-project/lib/react-idle-timer/IdleTimerContext.tsx(24,8):   
TS2532: Object is possibly 'undefined'.                                                            
ERROR in /home/user/my-project/lib/react-idle-timer/TabManager/BroadcastChannel.ts(29,5):
TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{}'.
  No index signature with a parameter of type 'string' was found on type '{}'.                        
ERROR in /home/user/my-project/lib/react-idle-timer/TabManager/BroadcastChannel.ts(29,22):               
TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{}'.
  No index signature with a parameter of type 'string' was found on type '{}'.                                 
ERROR in /home/user/my-project/lib/react-idle-timer/TabManager/BroadcastChannel.ts(30,5):                
TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{}'.
  No index signature with a parameter of type 'string' was found on type '{}'.                                 
ERROR in /home/user/my-project/lib/react-idle-timer/TabManager/BroadcastChannel.ts(43,9):     
TS2531: Object is possibly 'null'.                                                                    
ERROR in /home/user/my-project/lib/react-idle-timer/TabManager/BroadcastChannel.ts(61,5):                
TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{}'.
  No index signature with a parameter of type 'string' was found on type '{}'.                     
ERROR in /home/user/my-project/lib/react-idle-timer/TabManager/BroadcastChannel.ts(75,19):
TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{}'.
  No index signature with a parameter of type 'string' was found on type '{}'.                     
ERROR in /home/user/my-project/lib/react-idle-timer/TabManager/BroadcastChannel.ts(76,5):                
TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{}'.
  No index signature with a parameter of type 'string' was found on type '{}'.                                 
ERROR in /home/user/my-project/lib/react-idle-timer/TabManager/BroadcastChannel.ts(80,5):                
TS2322: Type '((this: MessagePort, ev: MessageEvent<any>) => any) | null' is not assignable to type '(event: MessageEvent<any>) => void'.
  Type 'null' is not assignable to type '(event: MessageEvent<any>) => void'.                                  
ERROR in /home/user/my-project/lib/react-idle-timer/TabManager/BroadcastChannel.ts(88,5):     
TS2322: Type '((this: MessagePort, ev: MessageEvent<any>) => any) | null' is not assignable to type '(event: MessageEvent<any>) => void'.
  Type 'null' is not assignable to type '(event: MessageEvent<any>) => void'.                                                          
ERROR in /home/user/my-project/lib/react-idle-timer/TabManager/BroadcastChannel.ts(96,12):    
d9k commented 2 years ago

@SupremeTechnopriest, how can I rebuild react-idle-timer 5.4.2 (index.esm.js) locally without minification to debug it step-by-step with my code?