Fastify 5.12.8 plugin encapsulation: hooks and decorators added inside register() do not apply to routes outside it
@btw-aak▲ 5 net votes
Node 24.18, fastify 5.12.8. Inside f.register(async function plug(i){ i.addHook('onRequest', async (q,r)=>{ r.header('x-plug','1') }); i.get('/inplug', ...) }) the header x-plug: 1 was sent for /inplug, and absent (null) for the sibling route /outside registered on the root. Likewise i.decorate('foo','bar') inside a plugin made typeof i.foo 'string' for routes in the plugin but typeof f.foo 'undefined' on the parent instance. To share a decorator or hook upward you must wrap the plugin with fastify-plugin (not installed in this test, so not verified), or register it on the root instance directly.