From 2dfee7b0b38e126b92a7d305cdfcefcb23d8b4eb Mon Sep 17 00:00:00 2001 From: "nedunchezhiyan.m" Date: Mon, 13 Apr 2026 19:45:16 +0530 Subject: [PATCH 1/2] fix(openapi-fetch): replace Math.random() with deterministic counter 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 #2486 --- packages/openapi-fetch/src/index.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/openapi-fetch/src/index.js b/packages/openapi-fetch/src/index.js index 4c7250fb0..d067fd107 100644 --- a/packages/openapi-fetch/src/index.js +++ b/packages/openapi-fetch/src/index.js @@ -9,12 +9,17 @@ const supportsRequestInitExt = () => { ); }; +/** Counter for deterministic request ID generation */ +let _idCounter = 0; + /** - * Returns a cheap, non-cryptographically-secure random ID - * Courtesy of @imranbarbhuiya (https://github.com/imranbarbhuiya) + * Returns a cheap, non-cryptographically-secure unique ID. + * Uses a monotonic counter instead of Math.random() so IDs are + * deterministic within a process, which is compatible with + * frameworks that cache or deduplicate fetch calls (e.g. Next.js). */ export function randomID() { - return Math.random().toString(36).slice(2, 11); + return (++_idCounter).toString(36); } /** From e2e0cbfac75bb70b40a6acfea46d6458c62fd804 Mon Sep 17 00:00:00 2001 From: Nedunchezhiyan-M Date: Mon, 13 Apr 2026 20:42:02 +0530 Subject: [PATCH 2/2] chore: add changeset for deterministic request ID fix --- .changeset/fix-deterministic-request-id.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/fix-deterministic-request-id.md diff --git a/.changeset/fix-deterministic-request-id.md b/.changeset/fix-deterministic-request-id.md new file mode 100644 index 000000000..89cea3661 --- /dev/null +++ b/.changeset/fix-deterministic-request-id.md @@ -0,0 +1,5 @@ +--- +"openapi-fetch": patch +--- + +Replace `Math.random()` with a monotonic counter in `randomID()`. `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). The counter produces unique IDs within a process while being deterministic across runs.