fix: prevents fastify-compress from trying to work with something it cannot #361
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.
I'm still trying to figure out how it happens (something involving tRPC responses), but for now I'll be happy if I can stop compress from trying to compress something it can't.
I assume the differing behavior between the automatic compression (hook), and manual compression (the
compressfunction) is because you don't want to mess with payloads (e.g. serialize them) unless people explicitly call the compress function. I've kept that behavior, and the global hook simply doesn't compress if it gets something it cannot deal with, while the compress function, well, it already serialized things, so it might cause wonky behavior if you pass it a Response object.Tests:
Responseobjects are not compressed on global hookcompressResponseobjects are compressed after being serialized to{}with thecompressfunction.Checklist
npm run testandnpm run benchmarkand the Code of conduct