Skip to content

Commit 062b849

Browse files
committed
perf(router): skip paginator checks for plain JSON
Guard paginator duck typing behind the distinguishing data field so ordinary object responses serialize directly. A live CPU profile of the warm static JSON route reduced formatResult self-time from 12.7% to 0.1%; the laptop network generator was too noisy for a trustworthy throughput claim.\n\nValidated with 501 router tests, framework type checks, and pickier lint.
1 parent f78f342 commit 062b849

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

storage/framework/core/router/src/stacks-router.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2904,7 +2904,7 @@ function formatResult(result: unknown, req: EnhancedRequest): Response {
29042904
// CursorPaginator, emit `Link: <prev>; rel="prev", <next>; rel="next"`
29052905
// alongside the JSON body — HATEOAS for REST clients + crawlers
29062906
// who'd otherwise have to dig through the body to find next/prev.
2907-
const linkHeader = buildPaginatorLinkHeader(result)
2907+
const linkHeader = 'data' in result ? buildPaginatorLinkHeader(result) : null
29082908
return formatJsonResult(result, req, linkHeader)
29092909
}
29102910

0 commit comments

Comments
 (0)