Repository navigation
feat(core): expose request duration on the response - #11214
Merged
Merged
Conversation
Adds `response.duration`: milliseconds from dispatch to response, present on successful responses and on `error.response` when the server replied. Timing a request currently requires an interceptor pair plus a Map keyed by config to correlate request and response, which every consumer reimplements. This is one clock read at the single adapter-agnostic choke point, so it works identically for the http, xhr and fetch adapters with no per-adapter code. `Date.now()` rather than `performance.now()` to match the existing convention in speedometer.js, throttle.js, cookies.js and AxiosTransformStream.js. The result is clamped at zero so a backwards clock adjustment mid-request cannot yield a negative duration. Additive and opt-out-free: no config, no behaviour change for existing callers. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Contributor
There was a problem hiding this comment.
All reported issues were addressed across 3 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
Contributor
[Medium impact] Safe to merge; there are no outstanding blocking issues. SummaryThis change exposes adapter execution time through the optional Reviews (2) · Last reviewed commit: "fix(core): complete response duration ty..." · Reviewed by Greptile |
jasonsaayman
marked this pull request as ready for review
October 9, 2026 16:55
jasonsaayman
approved these changes
Oct 14, 2026
ModyQyW
added a commit
to uni-helper/uni-network
that referenced
this pull request
Nov 1, 2026
7 of 8 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Expose elapsed adapter time as
response.duration, in milliseconds, on successful responses and onerror.responsewhen present. Applications can inspect response latency without installing their own timing interceptors.Linked issue
Related to request/response timing #695 and the metrics item in feature suggestions #6984. This implements a single elapsed-time value; it does not implement per-phase network metrics.
Changes
Date.now()with two clock reads for a response receiving timing metadata. Clamp backward clock adjustments to zero; forward adjustments can inflate the result.duration?: numberproperty and timing documentation aligned in ESM and CommonJS declarations.PRE_RELEASE_CHANGELOG.mdand deferred release documentation inPRE_RELEASE_DOCS.md.v1.xat790b2ca8b6d8486dde3ce54cda20990ba91b0831; the PR diff contains no dependency, workflow, version, or generated-bundle changes.Validation
Validated on 14 October 2026, macOS 27.0.1 ARM64. Source/build/browser/ESM checks used Node 26.8.1 and npm 11.19.0. CommonJS module checks used the supported Node 18.20.8 runtime, npm 10.8.2, and TypeScript 4.9.5; ESM types used TypeScript 5.9.3.
npm ci --ignore-scripts: passed. Package manifests and lockfiles are unchanged.npm run lint: passed. Focused ESLint checks for the four changed/new JavaScript test files also passed.npm run build: passed.npm run test:vitest:unit -- tests/unit/core/dispatchRequest.test.js tests/unit/adapters/responseDuration.test.js: 25 passed. Removing the two duration assignments makes 14 timing checks fail; the implementation was restored before the full suite.npm run test:vitest:unit: 1,682 passed, 74 files, with default settings.npx playwright install, followed bynpm run test:vitest:browser:headless: 1,053 passed, three existing skips, 81 files across Chromium, Firefox, and WebKit, with default settings.npm pack --json: passed. Installed that tarball into both module packages afternpm ci --ignore-scripts, usingnpm install --no-save --package-lock=false --ignore-scripts <tarball>. Verified installed declarations and dispatch source match the validated files.npm run test:module:cjs: 8 passed against the packed package. Removing the installed CommonJSdurationdeclaration makes the new consumer assertions fail with TS2339; restoring it passes.npm run test:module:esm: 9 passed against the same packed package.git diff --check: passed. Existing declaration formatting was preserved to avoid unrelated changes.Latest published head:
36bb79cd1774008f2e557a9c23b111f0c115fe97. GitHub Actions currently requires maintainer authorization for Continuous integration, build reproducibility, Bundle Size, and zizmor. These workflows have not executed for this head. Review/security bots are separate from build and test evidence. The full hosted runtime matrix and smoke suites remain unverified; the results above are local validation.Compatibility and documentation
Semver: minor. The new enumerable response field requires no migration for built-in-adapter users. Both declaration formats keep it optional so existing custom adapters and manually constructed responses remain type-compatible. Dispatch replaces any custom adapter's existing
durationvalue.Timing excludes request/response interceptors and transforms. Buffered responses include body reception; streaming responses stop timing when the stream becomes available, and later stream consumption or failure does not update the duration. Adapter work such as connection queuing and redirects is included. This is approximate wall-clock elapsed time, not a monotonic measurement, server-processing time, or a DNS/TCP/TLS/TTFB breakdown. Errors without a response have no duration.
Required documentation is recorded in
PRE_RELEASE_DOCS.mdfor response-schema and error-handling examples, including timing boundaries and guarded error access. README/docs-site updates remain deferred to release preparation. No runtime export or packaging configuration changes are needed; both public declaration formats and packed module suites are covered.AI assistance was used for review, implementation, tests, and this description; the
ai-assistedlabel is applied.Checklist
PRE_RELEASE_CHANGELOG.mdentry describes the final feature