fix: isolate tuple searchParams in init hooks#861
Merged
sindresorhus merged 1 commit intoApr 21, 2026
Merged
Conversation
productdevbook
added a commit
to productdevbook/misina
that referenced
this pull request
Apr 25, 2026
…sers Inspired by ky [PR #849](sindresorhus/ky#849). The parseJson option now receives an optional second argument with the request and response, so a single shared parser can route on URL or content-type: \`\`\`ts createMisina({ parseJson: (text, ctx) => { if (ctx?.response.headers.get('x-format') === 'bigint') { return JSON.parse(text, bigintReviver) } return JSON.parse(text) }, }) \`\`\` The previous one-arg signature still works — the second arg is optional and the existing tests (which pass a one-arg callback) continue to pass. ### test/init-isolation.test.ts Two new tests covering ky [PR #861](sindresorhus/ky#861 spirit: per-request init hook isolation. - Concurrent requests don't share a counter through options.headers. - A defaults.headers value mutated inside init doesn't compound across later requests. Both pass — verifies that resolveOptions() builds a fresh per-request options object each time, so default state isn't leaked or compounded. ### test/parsejson-context.test.ts Two new tests for the new signature: - ctx?.request.url and ctx?.response.headers.get(...) are observable. - The original one-arg form keeps working. 117/117 tests pass; lint, typecheck, build, bundle budget all clean. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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
searchParamstuple arrays before init hooks mutate them[[key, value]]search params formRoot cause
cloneInitHookOptions()is supposed to give init hooks a request-local mutable copy of the options, butsearchParamsin tuple-array form only got a shallow outer array copy. Mutating an existing tuple likeoptions.searchParams[0][1] = ...changed the shared default tuple, so the next request inherited the previous hook mutation.Fix
cloneSearchParametersForInitHook()helper that deep-copies tuple arrays while preserving the other supportedsearchParamsinput formsURLSearchParamsTesting
npm run buildnpx ava test/hooks.ts --match "init hook*do not leak across requests"npx ava test/hooks.ts --match "init hook tuple searchParams mutations do not leak across requests"Notes
npm testin this Windows checkout still hits upstreamxoproject-service parsing errors for the repo's test files before it reaches AVA. The targeted hook tests and build above passed locally.