Skip to content

fix(openapi-fetch): replace Math.random() with deterministic counter for request IDs#2763

Open
Nedunchezhiyan-M wants to merge 2 commits intoopenapi-ts:mainfrom
Nedunchezhiyan-M:fix/deterministic-random-id
Open

fix(openapi-fetch): replace Math.random() with deterministic counter for request IDs#2763
Nedunchezhiyan-M wants to merge 2 commits intoopenapi-ts:mainfrom
Nedunchezhiyan-M:fix/deterministic-random-id

Conversation

@Nedunchezhiyan-M
Copy link
Copy Markdown

Summary

  • randomID() was using Math.random() to generate per-request middleware correlation IDs
  • Math.random() is a non-deterministic side effect that can conflict with frameworks that cache or deduplicate fetch() calls (e.g. Next.js React Server Components)
  • Replaced with a monotonic counter (++_idCounter) that produces unique IDs within a process but is deterministic across runs, eliminating the unpredictable side effect

Test plan

  • Existing middleware test "receives a UUID per-request" continues to pass — IDs are still unique and correctly correlated between onRequest and onResponse
  • All 451 existing tests pass

Fixes #2486

…for request IDs

Math.random() is a non-deterministic side effect that can interfere
with frameworks that cache or deduplicate fetch calls (e.g. Next.js
React Server Components). Replace with a monotonic counter that
produces unique IDs within a process but is deterministic across
runs, eliminating the unpredictable side effect.

Fixes openapi-ts#2486
@Nedunchezhiyan-M Nedunchezhiyan-M requested a review from a team as a code owner April 13, 2026 14:26
@netlify
Copy link
Copy Markdown

netlify bot commented Apr 13, 2026

👷 Deploy request for openapi-ts pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit e2e0cbf

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 13, 2026

🦋 Changeset detected

Latest commit: e2e0cbf

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
openapi-fetch Patch
openapi-react-query Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

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.

Component caching with Math.random in openapi-fetch

2 participants