-
Notifications
You must be signed in to change notification settings - Fork 8
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
useEffectListener doesn't fire when window is not in focus #57
Comments
Hi @artt — thanks for the report. This is partially expected because the effects are fired from
If I understand the bug correctly this is what’s happening:
Once you switch to tab 2 (before I think slow/paused effects in an inactive tab is acceptable, but we should still make sure effects complete as expected rather than getting lost like they currently seem to be. |
I agree with this. I have no idea how all of this works... they're all magic to me :P |
After doing some more research, there are two parts:
|
Partially addresses #57. `requestAnimationFrame` is usually paused when a browser tab is inactive or in the background. We now schedule a `setTimeout` each time we request a new frame, which will only get run if the rAF callback is not called within 1000ms. `setTimeout` is also usually throttled, but will more likely run in the background than `requestAnimationFrame`.
This should be fully resolved in v0.7.0 if you‘d like to try it out! |
Issue description
It seems like the effects doesn't fire until the window/tab is in focus. Minimal demonstration of the problem:
updateStateAfterEffects
totrue
ctx.effects.foo()
.Use case
This is quite a weird problem but basically I have three effects to be fired in a row when a dice is rolled:
ctx.effects.roll()
withduration
of3
, animates the dice (usingsetInterval
to random dice face)ctx.effects.rollDone()
with no duration, clears that interval show the final outcome.When I develop my game, I have two tabs open, one for each player. Tab A clicks roll. I then switch to Tab B. Wait until everything is done. Perform some action that alters
G
. Everything looks fine in Tab B. But then when I switch back to Tab A, the dice is still rolling sincerollDone()
was never fired.At first I thought this has something to do with
setInterval
on my code, but removing it doesn't solve the problem.Not sure if you could recommend some workaround for this. Thanks a lot!
The text was updated successfully, but these errors were encountered: