Skip to content

Comments

Prevent double fetching when force refreshing paginated views#1637

Merged
jeffvli merged 5 commits intojeffvli:developmentfrom
eramdam:fix-double-request-reload
Feb 3, 2026
Merged

Prevent double fetching when force refreshing paginated views#1637
jeffvli merged 5 commits intojeffvli:developmentfrom
eramdam:fix-double-request-reload

Conversation

@eramdam
Copy link
Contributor

@eramdam eramdam commented Feb 2, 2026

This fixes a bug I recently noticed when refreshing the Albums view with the random sort, it seems the refresh method in item-list-paginated-loader.ts triggers two network requests instead of one. This is usually fine1 in views where two requests with the same arguments will return the same result but this is visible on lists with a random sort, as shown in this recording I took earlier today.

CleanShot.2026-02-02.at.09.50.08.mp4

This PR fixes that by not calling invalidateQueries() when passing force to the refresh method, which results in only one network request as expected. My react-query chops are a bit rusty so perhaps this isn't how you're supposed to fix that issue, happy to adjust if necessary.

Footnotes

  1. Albeit not optimal because the first request still happens and isn't being cancelled like it probably should.

@vercel
Copy link

vercel bot commented Feb 2, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
feishin Ready Ready Preview, Comment Feb 3, 2026 4:04am

@eramdam
Copy link
Contributor Author

eramdam commented Feb 2, 2026

Seems like that behavior might have been there as long as this code, it wasn't as noticeable in 1.2.0 for example (flashes more quickly) but recent updates made the render slower which makes the issue more noticeable

CleanShot.2026-02-02.at.10.32.03.mp4

@eramdam
Copy link
Contributor Author

eramdam commented Feb 2, 2026

I opened a PR to fix the performance regression that made that bug more apparent in this PR

@jeffvli
Copy link
Owner

jeffvli commented Feb 3, 2026

I believe the two fetches you're noticing is actually:

  1. The listCount query
  2. The actual page query

It's more apparent if you're not on page 1 of the list, as the listCount query is always run on the first page.

@eramdam
Copy link
Contributor Author

eramdam commented Feb 3, 2026

I believe the two fetches you're noticing is actually:

1. The listCount query

2. The actual page query

It's more apparent if you're not on page 1 of the list, as the listCount query is always run on the first page.

Ah yes indeed. Still, it feels like the listCount query shouldn't refresh the UI in the case of a sortBy: random query?

@jeffvli
Copy link
Owner

jeffvli commented Feb 3, 2026

Yep, I needed to add a condition to exclude this behavior specifically for random 0af5ff6. The function was setting page data based on the list count fetch to improve the initial load time of the list which usually requires sequential fetches for the count and then the actual data.

@jeffvli jeffvli merged commit 55a6ea4 into jeffvli:development Feb 3, 2026
7 checks passed
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

Successfully merging this pull request may close these issues.

2 participants