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

focusThrottleInterval is not honoured for the first refresh on focus after mount #2856

Open
mgoodfellow opened this issue Dec 12, 2023 · 3 comments

Comments

@mgoodfellow
Copy link

Bug report

Description / Observed Behavior

It seems that sometimes focusThrottleInterval is not honoured

Expected Behavior

I expected it to be honoured

Repro Steps / Code Example

https://github.com/mgoodfellow/swr_revalidate_test

Additional Context

SWR version 2.2.4

Add any other context about the problem here

Run repo with npm run dev

Page loads, cat fact shown.

Click away from window (lose focus)

Wait ~ 10 seconds, click back to window:

image

If we review this waterfall, we have filtered requests by "cat" so we see the requests for this URL.

We can see the request on the page load, then we see another request ~10s. Surely the focusThrottleInterval should have inhibited this 2nd request from occuring?

@mgoodfellow
Copy link
Author

Some additional info: https://github.com/mgoodfellow/swr_revalidate_test/blob/master/swr-revalidate-test/src/pages/index.tsx#L15

It seems this value is honoured for subsequent requests, but the initial focusThrottleInterval after a page load is the default of 5s

@mgoodfellow
Copy link
Author

Right, I see the issue:

nextFocusRevalidatedAt = now + getConfig().focusThrottleInterval

The nextFocusRevalidatedAt is only calculated after the initial focus revalidation. So we end up with this issue where the first throttle interval is always ignored.

This effect is then repeated on a remount (such as due to a page change).

I guess ideally we need to calculate the next possible revalidation window due to focus, when it initially mounts.

let nextFocusRevalidatedAt = 0

@mgoodfellow
Copy link
Author

So updating my example from the initial repo: mgoodfellow/swr_revalidate_test#1

This uses the built libraries from the PR I opened above, and the behaviour is now as expected:

image

That initial refresh does not occur, and then the refresh on focus after 60s is allowed

@mgoodfellow mgoodfellow changed the title focusThrottleInterval is not honoured all the time focusThrottleInterval is not honoured for the first refresh on focus after mount Dec 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant