Skip to content

fix: Increase rate-limit factor for Next.js app router#973

Merged
franky47 merged 4 commits intonextfrom
test/rate-limits
Apr 14, 2025
Merged

fix: Increase rate-limit factor for Next.js app router#973
franky47 merged 4 commits intonextfrom
test/rate-limits

Conversation

@franky47
Copy link
Member

@franky47 franky47 commented Apr 11, 2025

This tests how the throttled queue alleviates browsers rate-limiting calls to the History API for URL updates.

Updates to a counter are made every 20ms for one minute, and the test keeps count of the result for each URL update (the resolved Promise from the state updater function).

Note: updates are not made using the internal state of useQueryState, as it's data-racing against the URL. Instead, we keep a steady increasing count and only render the current URL value for progress.

Note: as these tests are long-running and browser-dependent, they don't have an associated Cypress fixture.

It allowed detecting that a rate-limit factor of 3 is needed in the Next.js app router, which calls the History API on top of our own updates (so we have 3 calls per update for some reason).

See #960 (comment)

@vercel
Copy link

vercel bot commented Apr 11, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
nuqs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 14, 2025 8:41am

@franky47 franky47 added the adapters/next/app Uses the Next.js app router label Apr 11, 2025
@franky47 franky47 added this to the 🪵 Backlog milestone Apr 11, 2025
@franky47 franky47 changed the title test: Add rate limit stress test fix: Increase rate-limit factor for Next.js app router Apr 11, 2025
@pkg-pr-new
Copy link

pkg-pr-new bot commented Apr 11, 2025

pnpm add https://pkg.pr.new/nuqs@973

commit: 814eca7

This tests how the throttled queue alleviates browsers rate-limiting
calls to the History API for URL updates.

Updates to a counter are made every 20ms for one minute, and
the test keeps count of the result for each URL update (the resolved
Promise from the state updater function).

Note: updates are not made using the internal state of useQueryState,
as it's data-racing against the URL. Instead, we keep a steady
increasing count and only render the current URL value for progress.
@franky47 franky47 enabled auto-merge (squash) April 14, 2025 08:39
@franky47 franky47 merged commit 20ce7b9 into next Apr 14, 2025
27 checks passed
@franky47 franky47 deleted the test/rate-limits branch April 14, 2025 08:44
@github-actions
Copy link

🎉 This PR is included in version 2.4.2-beta.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

@github-actions
Copy link

🎉 This PR is included in version 2.4.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

@franky47 franky47 removed this from the 🚀 Shipping next milestone Apr 14, 2025
@franky47 franky47 mentioned this pull request Apr 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant