Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Has onActive() condition changed?🐞 #382

Open
1 task done
alexlaw-leo opened this issue Jan 11, 2024 · 3 comments
Open
1 task done

Has onActive() condition changed?🐞 #382

alexlaw-leo opened this issue Jan 11, 2024 · 3 comments
Assignees
Labels
bug A verified and reproducible bug. triage Has not been reviewed yet and should not be worked on.

Comments

@alexlaw-leo
Copy link

What happened?

I could have sworn that previously, onActive() only ran if isPrompted() was true. Now, it also runs if syncTimers is set to a value > 0.

Reproduction Steps

1.Create an onActive method with logging.
2.See what happens when you move the mouse with / without syncTimers set.
3.Note that syncTimers appears to now switch on / off calling onActive, even if not prompted.
...

Relevant log output

No response

Screenshots or Additional Context

No response

Module Version

5.7.2

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

No response

What devices are you seeing the problem on?

No response

Verification

  • I have checked for existing closed issues and discussions.
@alexlaw-leo alexlaw-leo added bug A verified and reproducible bug. triage Has not been reviewed yet and should not be worked on. labels Jan 11, 2024
@SupremeTechnopriest
Copy link
Owner

onActive should not be called while prompted. This is by design so user action doesn't close your prompt. If you want to detect activity during the prompt phase, you should use onAction instead, as that is always called on every action.

Are you saying that when syncTimers is set, onActive is called in the prompted state? If so thats most likely a bug I will have to look into.

@alexlaw-leo
Copy link
Author

alexlaw-leo commented Jan 12, 2024

Yes - I took my existing code that used promptTimeout and changed it to use the newer promptBeforeIdle, and I added syncTimers: 200.

I noticed that my code:

  const onActive = () => {
    setOpen(false);
    setRemaining(0);
    if (isLeader()) {
      doRefresh();
    }
  };

was hitting my API over and over when moving the mouse, and this was tied to syncTimers. If I commented out the syncTimers line, onActive() worked as expected (it didn't execute when not prompted).

For now I'm working around this by enabling syncTimers and wrapping the logic:

const onActive = () => {
  if (isPrompted()) {
    setOpen(false);
    setRemaining(0);
    if (isLeader()) {
      doRefresh();
    }
  }
};

but my understanding is that I shouldn't need to do that.

Thanks!

@Josh68
Copy link

Josh68 commented Apr 11, 2024

It would be helpful for these details to be documented. As far as I can tell, they are not, and I don't know what the assumptions are I should be making in my app: https://idletimer.dev/docs/api/props#onactive, https://idletimer.dev/docs/api/methods#isprompted, https://idletimer.dev/docs/api/props#synctimers

That said, I was just looking into the idea of adding an onTimersSynced prop, because this is what I think I could use. I'm maintaining external times and activity states because we need to check actual timeout times with an external session-management server. If such a prop were added, I'd expect it to be always called, whether or not any tab was in isPrompted state.

The end result I'd like is for any tab (isPrompted or not) to be notified when another has its timeout value updated, and to know what that time is. And I may be running into bugs because of this logic feature and the way I've structured my timer component.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A verified and reproducible bug. triage Has not been reviewed yet and should not be worked on.
Projects
None yet
Development

No branches or pull requests

3 participants