SupremeTechnopriest / react-idle-timer

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

`isLeader` and `getTabId` runtime error with `crossTab: true` #317

Closed tgelu closed 1 year ago

tgelu commented 1 year ago

Bug information

I'm trying to call isLeader and getTabId on the first render. This results in the below runtime exception:

Uncaught Error: ❌ Cross Tab feature is not enabled. To enable it set the "crossTab" property to true.

Affected Module

Describe the bug

Seems like the tab manager is instantiated in an effect. This means those functions (like isLeader or getTabId) that have the following check won't be callable except at certain times:

    if (!manager.current) {
      throw new Error('❌ Cross Tab feature is not enabled. To enable it set the "crossTab" property to true.')
    }

Either the error message is deceiving or the behavior is unexpected.

To Reproduce

Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error.

Expected behavior

Etiher: 1) the error message should reflect reality since one can get the exception even with crossTab: true. 2) or the functions in question should reflect the "not initialized state" in their return value instead of throwing. Throwing should happen only if crossTab is really set to false. 3) or this initialization should not happen in an effect, if that's feasible.

Either way this should probably be documented.

Screenshots

N/A

System Information (please complete the following information)

Additional context

-

SupremeTechnopriest commented 1 year ago

Can you try the new release candidate npm i react-idle-timer@next

tgelu commented 1 year ago

I will get back once I try that :) thanks.

SupremeTechnopriest commented 1 year ago

Any luck?

tgelu commented 1 year ago

this seems to work in @next. Thanks! 👍