Repository navigation
Conversation
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
Adds an opt-in flag that times every server-side
fetchContentandevaluatecall and reports it in theServer-Timingof the response being rendered, following croct-tech/plug-next#215.Enable via
nuxt.config.ts(croct: { serverTiming: true }) or at runtime viaNUXT_CROCT_SERVER_TIMING=true:When disabled (the default), nothing is wrapped and no header or trailer is added.
How it works
runtimeConfig.croct.serverTimingistrue, a Nitro server plugin wrapsnitroApp.h3App.handlerand tracks each top-level request'sServerResponsein aglobalThis-sharedAsyncLocalStorage(Symbol.for('@croct/plug-nuxt/server-timing')).useRequestFetch()calling/api/_croct/contentor/api/_croct/evaluate) inherit the outer request's store so timings are written to the SSR response being rendered rather than the discarded internal subrequest response.fetchContentandevaluatecall records its elapsed duration to that response: viaappendHeader('Server-Timing', metric)while headers are still open, and viaaddTrailers({'Server-Timing': ...})(accumulating trailers per response because Node replaces trailers on everyaddTrailers()call) onceresponse.headersSentistrue.Validation
npm run validate,npm run lint,npm run build, andnpm test(12 files, 124 tests) pass.serverTiming(including a realnode:httpserver verifying headers before streaming, accumulated trailers after streaming, description sanitization, rejected calls, nested subrequest inheritance, concurrent isolation, and ended responses) and for the Nitro plugin.e2e/specs/server-timing.spec.tsand verified opt-in omission ine2e/specs/prerender/hybrid-rendering.spec.ts.nuxi build e2e/app && node e2e/app/.output/server/index.mjs) andnuxi dev(including streamed headers + trailers and 120 concurrent keep-alive requests).Checklist