Skip to content

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

Merged
merged 4 commits into from
Dec 27, 2019
Merged

Fix hook encapsulation #2004

merged 4 commits into from
Dec 27, 2019

Conversation

delvedor
Copy link
Member

Back in #642 we have decided to not encapsulate onRoute and onRegister, 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

  • run npm run test and npm run benchmark
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message and code follows Code of conduct

@delvedor delvedor added semver-major Issue or PR that should land as semver major v3.x Issue or pr related to Fastify v3 labels Dec 24, 2019
@delvedor delvedor requested a review from a team December 24, 2019 08:30
@delvedor delvedor added this to the v3.0.0 milestone Dec 24, 2019
Copy link
Member

@mcollina mcollina left a 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?

@delvedor
Copy link
Member Author

How much does this affect fastify-swagger?

cc @Eomm 😉

This was referenced Dec 24, 2019
@delvedor delvedor requested a review from Eomm December 26, 2019 13:17
@delvedor
Copy link
Member Author

How much does this affect fastify-swagger?

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.

Copy link
Member Author

@delvedor delvedor left a 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! :)

@delvedor delvedor merged commit 80d87c9 into next Dec 27, 2019
@delvedor delvedor deleted the fix-hook-encapsulation branch December 27, 2019 16:02
@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 10, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
semver-major Issue or PR that should land as semver major v3.x Issue or pr related to Fastify v3
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants