Repository navigation
fix: don't let route defaults override global options on partial route config - #448
Merged
mcollina merged 1 commit intoNov 22, 2026
Merged
Conversation
…e config When a route defined partial compress/decompress options, the processed route params were merged over the processed global params. Since processCompressParams/processDecompressParams fill in defaults for every option that is not set, those defaults silently replaced explicitly configured global options (e.g. a global onInvalidRequestPayload was lost when a route only set onUnsupportedRequestEncoding). The raw route options are now merged over the raw plugin options before processing, so a route override wins per key and everything else keeps the global configuration. Fixes fastify#340
3 of 4 tasks
This was referenced Nov 23, 2026
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.
Closes #340
Picking this up since it's been open a while and the PR that was asked for never arrived.
The problem is where the merge happens.
processCompressParams()/processDecompressParams()fill in a default for every option that isn't set, so by the time the route params get merged over the global params in theonRoutehook, there's no way to tell "the route chose this value" apart from "that's just the default". The route's defaults then clobber explicitly configured global options — in the reported case a globalonInvalidRequestPayloaddisappears as soon as a route sets onlyonUnsupportedRequestEncodingin itsdecompressconfig.So instead of merging the two processed objects, this merges the raw route options over the raw plugin options and processes the result once — same way the global params themselves are built. A route override still wins per key, everything the route doesn't mention keeps the global behavior.
Added one test for each side (compress and decompress) reproducing the report: global handler/flag plus a route that overrides a single different option. Both fail on main and pass with the fix. Full suite and type tests pass.
Checklist
npm run testandnpm run benchmark