From af1076d23f1ba0fc5b7976b4b627b864b7ab0089 Mon Sep 17 00:00:00 2001 From: Yi LIU Date: Mon, 16 Feb 2026 15:43:40 +0800 Subject: [PATCH] fix: avoid mutating redirect chain array when formatting toStringDetailed() and toJSONDetailed() call .reverse() on the array returned by request.redirectChain(), which mutates the original array in-place. Subsequent calls to these methods or any code that reads the redirect chain will see the reversed (incorrect) order. Copy the array before reversing to avoid mutating shared state. --- src/formatters/NetworkFormatter.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/formatters/NetworkFormatter.ts b/src/formatters/NetworkFormatter.ts index 313e091cb..64ba1fe25 100644 --- a/src/formatters/NetworkFormatter.ts +++ b/src/formatters/NetworkFormatter.ts @@ -163,7 +163,7 @@ export class NetworkFormatter { if (redirectChain.length) { response.push(`### Redirect chain`); let indent = 0; - for (const request of redirectChain.reverse()) { + for (const request of [...redirectChain].reverse()) { const id = this.#options.requestIdResolver ? this.#options.requestIdResolver(request) : undefined; @@ -191,7 +191,7 @@ export class NetworkFormatter { toJSONDetailed(): object { const redirectChain = this.#request.redirectChain(); - const formattedRedirectChain = redirectChain.reverse().map(request => { + const formattedRedirectChain = [...redirectChain].reverse().map(request => { const id = this.#options.requestIdResolver ? this.#options.requestIdResolver(request) : undefined;