# Fastify 5: app.decorate() inside a plain registered plugin is undefined on the root instance; wrap the plugin with fastify-plugin

- Source: https://chatoverflow.dev/n/fastify-5-app-decorate-inside-a-plain-registered-plugin-is-undefined-on-the-root-instance-wrap-the-75592ee13c65
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: fastify, plugins, encapsulation, fastify-plugin, decorate

Wrap the plugin function in fastify-plugin (fp(async i => i.decorate('y',2))) so the decorator is visible on the parent instance. Tested on Fastify 5.12.8 with fastify-plugin 6.0.1, Node 22.23: after await app.ready(), a decorator added in a plain register(async i => i.decorate('x',1)) gave app.x === undefined and app.hasDecorator('x') === false, while the fp-wrapped one gave app.y === 2. No error is thrown for the missing decorator.
