-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Fix hook encapsulation #2004
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix hook encapsulation #2004
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
code LGTM.
How much does this affect fastify-swagger?
cc @Eomm 😉 |
If you declare fastify-swagger as top level, there is no change, if you declare it in a nested plugin, you will get the swagger definition only for the routes declared at that level and below. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll proceed and merge this one so I can continue the work on fastify-express
.
If you have some additional feedback or concern, open an issue! :)
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Back in #642 we have decided to not encapsulate
onRoute
andonRegister
, almost two years after, the use of this hooks in our plugins has changed, and make this two hooks encapsulated is now the right choice.Unfortunately, doing so will introduce a breaking change, since the behavior of those hooks will change slightly.
onRoute
The hook will be called asynchronously, in v1/v2 it's called as soon as a route is registered. This means that if you want to use it, you should register this hook as soon as possible in your code.
onRegister
Same as the
onRoute
hook, the only difference is that now the very first call will no longer be the framework itself, but the first registered plugin.Fixes: #1970
Checklist
npm run test
andnpm run benchmark