Skip to content

🐞 useIdleTimer hook issue with rerendering and lazy-loaded config options #407

@jon-cullison

Description

@jon-cullison

What happened?

We have a component which instantiates useIdleTimer using a lazy-loaded boolean value for crossTab (we default to false until we finish loading the actual value). The component rerenders when the boolean value has been loaded and may be set to true. If the user takes no action before this rerender, then isLastActiveTab() will always return false, even if there is only one tab.

Reproduction Steps

1. Create a component which accepts a boolean prop and uses the useIdleTimer hook, setting crossTab to the prop value.
2. In the parent component, create a state variable which defaults to false, create a setTimeout which will flip it to true after 100ms, and pass that into the child component in step 1.
3. Add some logging or display the status of isLastActiveTab() in a modal that is shown when `onPrompt` is called.
4. Notice that when refreshing and doing nothing, isLastActiveTab() is false. When refreshing and moving the mouse after the 100ms timeout, isLastActiveTab() is true

Relevant log output

Screenshots or Additional Context

I have created a codesandbox example which reproduces this behavior here:

https://codesandbox.io/p/sandbox/react-idle-timer-repro-2yv78s

IdleTimerContainer.js contains the idle timer, App.js sets and flips the boolean prop as described in the steps above.

Module Version

5.7.2

What browsers are you seeing the problem on? Select all that apply.

Chrome

What devices are you seeing the problem on?

Desktop

Verification

  • I have checked for existing closed issues and discussions.

Metadata

Metadata

Labels

bugA verified and reproducible bug.triageHas not been reviewed yet and should not be worked on.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions