Skip to content

fix(core): measure response duration with performance.now() - #11411

Merged
jasonsaayman merged 1 commit into
v1.xfrom
fix/address-issue-11407
Nov 2, 2026
Merged

jasonsaayman merged 1 commit into
v1.xfrom
fix/address-issue-11407

Conversation

@jasonsaayman

@jasonsaayman jasonsaayman commented Nov 2, 2026 •

Copy link
Copy Markdown
Member

Summary

Since v1.21.0 (#11214), dispatchRequest reads Date.now() on every request to compute response.duration. Next.js rejects Date.now() while prerendering with Cache Components (cacheComponents: true), so production builds fail whenever a Server Component makes an axios request:

Error: Route "/search": Next.js encountered the unstable value `Date.now()` while prerendering.

This PR times the adapter with the monotonic performance.now(), which is the timing API Next.js allows for telemetry. It falls back to Date.now() only when performance.now() is missing. A monotonic clock also means system clock adjustments no longer skew the value.

Linked issue

Closes #11407

Changes

  • lib/core/dispatchRequest.js: choose the clock once per request (performance.now() when available, else Date.now()), so start and end always come from the same clock. duration is rounded to whole milliseconds, so it stays an integer as in v1.21.0, and it is still clamped at 0 for the wall-clock fallback.
  • Tests: the duration tests in tests/unit/core/dispatchRequest.test.js, tests/unit/adapters/responseDuration.test.js, tests/browser/responseDuration.browser.test.js, and tests/browser/requests.browser.test.js now mock performance.now(). New regression tests check that Date.now() is never called during dispatch when performance.now() exists, that sub-millisecond readings round, and that the fallback works (with the backward-clock clamp) when performance is missing or has no now().
  • index.d.ts / index.d.cts: only the duration doc comment changed, to say which clock is used. The declared type is still duration?: number.
  • PRE_RELEASE_CHANGELOG.md: Bug Fixes entry. PRE_RELEASE_DOCS.md: entry to update the "measured with Date.now()" wording on the docs site (EN/ES/FR/ZH) and in the README duration note during release prep.

Validation

Node v24.21.0.

  • npm ci --ignore-scripts
  • npm run lint: passes
  • npm run build: passes
  • npm run test:vitest:unit: 74 files, 1704 tests pass
  • The new tests fail without the source change: with only lib/core/dispatchRequest.js reverted, 8 tests in tests/unit/core/dispatchRequest.test.js fail, including does not read the wall clock when performance.now() is available.
  • Browser suite (npx vitest run --project browser-headless --browser.name=<browser>): Chromium and Firefox both pass 27 files (355 passed, 1 skipped). WebKit could not run locally because Playwright's WebKit build is missing a system library (libevent-2.1.so.7) on this machine, so WebKit coverage comes from CI.
  • I did not run the CJS/ESM module type suites. Only doc comments changed in the declaration files.
  • prettier --check warns on index.d.ts / index.d.cts, but those warnings are already on v1.x. This PR doesn't reformat those files.
  • I didn't build a Next.js app to reproduce this end to end. The fix relies on the documented Next.js behaviour that performance.now() is allowed during prerendering, and on the unit test showing that dispatch no longer calls Date.now().

Compatibility and documentation

Patch. No public API or type changes. duration stays a non-negative integer number of milliseconds, measured over the same window (adapter invocation to settlement). Values can now differ slightly from v1.21.0 only when the system clock is adjusted mid-request. Every supported runtime has performance.now() (Node ≥ 16, browsers, Bun, Deno), and the Date.now() fallback covers custom environments without it.

Not in scope: Date.now() is still used by the progress helpers (speedometer, throttle, AxiosTransformStream), but those only run when onUploadProgress/onDownloadProgress or rate limiting is configured. It is also still used by browser cookie removal. None of these run on the default request path in the issue's setup.

Checklist

  • Scope, target branch, and linked issue/rationale checked
  • PRE_RELEASE_CHANGELOG.md entry added or updated (or AGENTS.md's automated release-preparation exception explained)
  • Regression tests and relevant negative/platform cases covered (or N/A with reason)
  • Applicable local checks completed, with actual commands and results recorded above
  • Deferred release docs and ESM/CJS types/tests updated where needed (or N/A with reason)
  • Semver impact stated and intentional breaking changes explained
  • Final diff reviewed for security, unrelated changes, generated artifacts, and test/debug leftovers
  • Latest GitHub Actions status recorded separately from review/security bot results

🤖 Generated with Claude Code


Summary by cubic

Description

Fixes #11407. Since v1.21.0, dispatchRequest read Date.now() on every request to compute response.duration, which Next.js rejects while prerendering with Cache Components (cacheComponents: true). Response duration is now measured with the monotonic performance.now(), falling back to Date.now() only when performance.now() is unavailable. A monotonic clock also means system clock adjustments no longer skew the value.

  • The clock is chosen once per request so start and end always come from the same clock.
  • duration is rounded to whole milliseconds and clamped at 0 for the wall-clock fallback, keeping its non-negative integer type.
  • No public API changes; only the duration doc comments in index.d.ts and index.d.cts changed.

Docs

PRE_RELEASE_DOCS.md adds an entry to update the "measured with Date.now()" wording in the docs site (EN/ES/FR/ZH) and the README duration note during release prep.

Testing

Duration tests in the unit, adapter, and browser suites now mock performance.now(). New regression tests verify Date.now() is never called when performance.now() exists, sub-millisecond readings round, and the Date.now() fallback works (with backward-clock clamp) when performance is missing or lacks now().

Semantic version impact

Patch. No breaking or feature changes; duration keeps its non-negative integer type. Values can differ from v1.21.0 only when the system clock is adjusted mid-request.

Written for commit 9c4e893. Summary will update on new commits.

View guided diff Turn on auto-fix

Since v1.21.0 dispatchRequest read Date.now() on every request to compute
response.duration. Next.js Cache Components rejects Date.now() during
prerendering, which broke production builds that make axios requests in
Server Components.

Use the monotonic performance.now() when available and fall back to
Date.now() otherwise. Round to whole milliseconds so duration stays an
integer, and keep the zero clamp for the wall-clock fallback.

Fixes #11407
@jasonsaayman jasonsaayman added the ai-assisted This PR was created with or in conjunction with AI label Nov 2, 2026

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 9 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

View guided diff | Turn on auto-fix | Re-trigger cubic

@jasonsaayman jasonsaayman self-assigned this Nov 2, 2026
@jasonsaayman jasonsaayman added commit::fix The PR is related to a bugfix v1x Version 1 labels Nov 2, 2026
@greptile-apps

greptile-apps Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The validated changes are safe to merge; no blocking issues were identified.

Summary

Changes response.duration to prefer performance.now(), with a Date.now() fallback.

  • Axios measures response duration with a monotonic clock when available.

No actionable issues were found. All 29 focused unit tests passed. Additional runtime checks confirmed that default HTTP requests avoid Date.now() when performance.now() is available, preserve response-bearing errors, and retain the intended buffered-response and stream timing boundaries. Fractional rounding, missing or nonfunction performance.now(), and backward-clock clamping also passed. A Next.js production build was not exercised.

Acknowledged scope: jasonsaayman explicitly deferred the existing Date.now() calls used by progress callbacks, rate limiting, and browser cookie removal; these paths do not run for the default request configuration described in the issue.

The validated changes are safe to merge; no blocking issues were identified.

Reviews (1) · Last reviewed commit: "fix(core): measure response duration wit..." · Reviewed by Greptile

@jasonsaayman
jasonsaayman merged commit 4417c7e into v1.x Nov 2, 2026
@jasonsaayman
jasonsaayman deleted the fix/address-issue-11407 branch November 2, 2026 11:15
markharding pushed a commit to futo-org/Harbor that referenced this pull request Nov 17, 2026
This PR contains the following updates:

| Package | Change | [Age](https://docs.renovatebot.com/merge-confidence/) | [Confidence](https://docs.renovatebot.com/merge-confidence/) |
|---|---|---|---|
| [axios](https://axios-http.com) ([source](https://github.com/axios/axios)) | [`1.21.0` → `1.21.1`](https://renovatebot.com/diffs/npm/axios/1.21.0/1.21.1) | ![age](https://developer.mend.io/api/mc/badges/age/npm/axios/1.21.1?slim=true) | ![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/axios/1.21.0/1.21.1?slim=true) |

---

> ⚠️ **Warning**
>
> Some dependencies could not be looked up. Check the [Dependency Dashboard](issues/2097) for more information.

---

### Release Notes

<details>
<summary>axios/axios (axios)</summary>

### [`v1.21.1`](https://github.com/axios/axios/releases/tag/v1.21.1)

[Compare Source](axios/axios@v1.21.0...v1.21.1)

#### v1.21.1 — November 9, 2026

This release raises the minimum `follow-redirects` version to fix a published CVE, fixes a Next.js prerendering failure caused by the response duration timer, corrects the `getAdapter` typings, and includes documentation corrections, new test coverage, CI runner changes and dependency updates.

#### 🔒 Security Fixes

- **follow-redirects:** Raised the `follow-redirects` range from `^1.16.0` to `^1.16.2` to fix CVE-2026-116689 (GHSA-mrwp-f3q8-3g9p). In the vulnerable versions, `sensitiveHeaders` arrays from another realm were ignored and custom credentials could follow redirects. Only the Node.js HTTP adapter is affected, and there are no API changes. (**[#&#8203;11410](axios/axios#11410)

#### 🐛 Bug Fixes

- **Response Duration:** `dispatchRequest` now measures `response.duration` with `performance.now()` and uses `Date.now()` only when `performance.now()` isn't available. In v1.21.0, any axios request from a Server Component failed Next.js production builds with Cache Components (`cacheComponents: true`), because Next.js rejects `Date.now()` while prerendering. The duration is still a whole number of milliseconds, and system clock changes no longer affect it. (**[#&#8203;11411](axios/axios#11411)
- **TypeScript:** `getAdapter` now accepts an optional `config?: AxiosRequestConfig` in `index.d.ts` and `index.d.cts`, matching what it does at runtime. You can now call `getAdapter('fetch', { env: { fetch: myFetch } })` without a cast. (**[#&#8203;11404](axios/axios#11404)

#### 🔧 Maintenance & Chores

- **Documentation Corrections:** Brought the README and docs site in line with how axios actually behaves:

  - `transformRequest` runs for every method, and transformers receive `(data, headers, status)`.
  - `responseType` and `Content-Type` have no default value.
  - `AxiosHeaders#get` and `#normalize` are described correctly.
  - Errors should be identified with `axios.isAxiosError()`, not by `name`.
  - The error tables now list `ECONNREFUSED` and `ERR_FORM_DATA_DEPTH_EXCEEDED`, and note that FormData parsing has a fixed depth limit that `maxDepth` doesn't change.
  - New notes cover what `redact` doesn't scan, which adapters enforce `maxContentLength` / `maxBodyLength`, and how `formToJSON()` handles field name collisions.

  (**[#&#8203;11374](axios/axios#11374, **[#&#8203;11373](axios/axios#11373, **[#&#8203;11389](axios/axios#11389, **[#&#8203;11419](axios/axios#11419, **[#&#8203;11429](axios/axios#11429, **[#&#8203;11430](axios/axios#11430)
- **Docs Site:** Added a Partners page, a shared card design for sponsors and partners, a Namespace sponsor badge, and a blog whose first post announces HeroDevs Never-Ending Support for Axios v0. Also applied the v1.20.0/v1.21.0 release notes to the docs, and fixed internal links in the es, fr and zh translations so they keep their locale prefix. (**[#&#8203;11390](axios/axios#11390, **[#&#8203;11399](axios/axios#11399, **[#&#8203;11400](axios/axios#11400, **[#&#8203;11412](axios/axios#11412, **[#&#8203;11401](axios/axios#11401)
- **Test Coverage:** Added cancellation tests across the HTTP, fetch and XHR adapters. They cover `AbortSignal`, `CancelToken`, cancelling while a request interceptor is pending, and timeout precedence. Also added tests for `no_proxy` edge cases in `shouldBypassProxy`, such as internationalized domain names, malformed CIDR and IPv4 entries, and port-qualified entries. Neither changes runtime behavior. (**[#&#8203;11376](axios/axios#11376, **[#&#8203;11431](axios/axios#11431)
- **CI:** GitHub Actions jobs now run on Namespace runners. The npm publish job stays on GitHub-hosted runners, because npm provenance and trusted publishing (OIDC) only work there. (**[#&#8203;11396](axios/axios#11396)
- **Dependencies:** Updated development and tooling dependencies, including `vitest` and `@vitest/*` (to 5.x at the root), `typescript` (7.x at the root), `vite`, `rollup`, `eslint`, `playwright`, `@commitlint/*`, `@rollup/plugin-alias`, `@rollup/plugin-terser`, `body-parser`, `multer`, `serialize-javascript`, `fast-uri`, `qs`, `zizmorcore/zizmor-action`, and `follow-redirects` in `/docs`. (**[#&#8203;11383](axios/axios#11383, **[#&#8203;11375](axios/axios#11375, **[#&#8203;11372](axios/axios#11372, **[#&#8203;11345](axios/axios#11345, **[#&#8203;11392](axios/axios#11392, **[#&#8203;11387](axios/axios#11387, **[#&#8203;11386](axios/axios#11386, **[#&#8203;11385](axios/axios#11385, **[#&#8203;11391](axios/axios#11391, **[#&#8203;11388](axios/axios#11388, **[#&#8203;11395](axios/axios#11395, **[#&#8203;11421](axios/axios#11421, **[#&#8203;11422](axios/axios#11422, **[#&#8203;11426](axios/axios#11426)
- **Release:** Prepared the 1.21.1 release. (**[#&#8203;11435](axios/axios#11435)

#### 🌟 New Contributors

We are thrilled to welcome our new contributors. Thank you for helping improve axios:

- **[@&#8203;Ghoscro](https://github.com/Ghoscro)** (**[#&#8203;11374](axios/axios#11374)
- **[@&#8203;pei711](https://github.com/pei711)** (**[#&#8203;11373](axios/axios#11373)
- **[@&#8203;ivanhapaz](https://github.com/ivanhapaz)** (**[#&#8203;11399](axios/axios#11399)
- **[@&#8203;aelmanaa](https://github.com/aelmanaa)** (**[#&#8203;11404](axios/axios#11404)
- **[@&#8203;Aryapatel-007](https://github.com/Aryapatel-007)** (**[#&#8203;11429](axios/axios#11429, **[#&#8203;11430](axios/axios#11430)
- **[@&#8203;umair-ghafoor-ai](https://github.com/umair-ghafoor-ai)** (**[#&#8203;11376](axios/axios#11376)
- **[@&#8203;yxshee](https://github.com/yxshee)** (**[#&#8203;11389](axios/axios#11389)
- **[@&#8203;malinele](https://github.com/malinele)** (**[#&#8203;11401](axios/axios#11401)
- **[@&#8203;AnantDuhan](https://github.com/AnantDuhan)** (**[#&#8203;11431](axios/axios#11431)

[Full Changelog](axios/axios@v1.21.0...v1.21.1)

</details>

---

### Configuration

📅 **Schedule**: (UTC)

- Branch creation
  - "before 9am on tuesday"
- Automerge
  - At any time (no schedule defined)

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Mend Renovate CLI](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0NC4yMjcuNCIsInVwZGF0ZWRJblZlciI6IjQ0LjIyNy40IiwidGFyZ2V0QnJhbmNoIjoiZGV2ZWxvcCIsImxhYmVscyI6WyJkZXBlbmRlbmNpZXMiLCJyZW5vdmF0ZSJdfQ==-->

Reviewed-on: https://code.futo.org/harbor/harbor/pulls/2336
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-assisted This PR was created with or in conjunction with AI commit::fix The PR is related to a bugfix v1x Version 1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Axios 1.21.0 breaks Next.js prerendering with Cache Components due to Date.now()

1 participant