fastify-compress icon indicating copy to clipboard operation
fastify-compress copied to clipboard

fix: prevents fastify-compress from trying to work with something it cannot

Open Aeolun opened this issue 5 months ago • 3 comments

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 compress function) 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:

  • Test that Response objects are not compressed on global hook
  • Test that objects get serialized normally when using compress
  • Test that Response objects are compressed after being serialized to {} with the compress function.

Checklist

Aeolun avatar Jun 17 '25 05:06 Aeolun

Great work! Can you document this new option?

mcollina avatar Jun 18 '25 05:06 mcollina

@mcollina I considered writing something about it, but I don't think this is something that you can really document? It doesn't so much change functionality so much as prevent a messy thrown error. I can add a gotcha or something at the end of the README.md?

Aeolun avatar Jun 18 '25 23:06 Aeolun

@Aeolun yes. There is a new option passed as the config of the plugin, and that should be mentioned in the README.md

mcollina avatar Jun 21 '25 16:06 mcollina