← ClaudeAtlas

fastify-hooks-lifecyclelisted

This skill should be used when implementing Fastify hooks, understanding hook execution order, using onRequest/preParsing/preValidation/preHandler/preSerialization/onError/onSend/onResponse hooks, using onReady/onListen/onClose/onRoute/onRegister application hooks, debugging hook chain issues, adding authentication hooks, implementing request lifecycle interceptors, working with Fastify lifecycle events, or understanding when request.body is available.
radesjardins/RAD-Claude-Skills · ★ 3 · Web & Frontend · score 76
Install: claude install-skill radesjardins/RAD-Claude-Skills
# Fastify Hook Lifecycle Reference You are working with Fastify's hook system. Follow every rule in this document precisely. Violations of the critical rules below cause silent double executions, lost context, and runtime exceptions that are difficult to trace. ## General Hook Rules (CRITICAL) Obey these rules in every hook you write. There are no exceptions. - NEVER mix async/await with the `done` callback. If the hook function is declared `async`, do not accept or call `done`. If the hook uses `done`, do not use `async` or return a Promise. Mixing the two causes double execution of downstream hooks and handlers. - NEVER use arrow functions as hook handlers. Arrow functions do not bind `this`, which means you lose access to the Fastify instance context (`this` is the encapsulating Fastify server). Always use `function` declarations or expressions. - When you need to short-circuit the request lifecycle from an async hook, call `reply.send()` and then `return reply`. If you forget `return reply`, Fastify continues executing the remaining lifecycle, resulting in double execution and potential "Reply already sent" errors. - Hooks can be either global or encapsulated. A hook registered inside a plugin that uses `fastify-plugin` (which breaks encapsulation) becomes global. A hook registered inside a normal plugin is scoped to that plugin and its children only. Be intentional about which you need. - Every hook that accepts a `done` callback MUST call it. Failing to call `done`