Skip to content
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

Update Migration-Guide-V4.md #4091

Merged
merged 5 commits into from Jun 28, 2022
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 29 additions & 0 deletions docs/Guides/Migration-Guide-V4.md
Expand Up @@ -65,6 +65,35 @@ Starting from v4, all the `GET` routes will create a sibling `HEAD` route.
You can revert this behaviour by setting the server's option `exposeHeadRoutes`
to `false`.

### Synchronous route definitions

The route registration has been made synchronous from v4. This change was done to provide
better error reporting for route definition. As a result if you specify an `onRoute` hook
in a plugin you should either:
* wrap your routes in a plugin (recommended)
* use `await register(...)`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add the code example to let the user understand better the implications:
any onRoute hooks will not be executed when a plugin adds them if it is not awaited or the routes are wrapped in a plugin

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the code example used in the linked issue before and after refactoring. Could you have a look please if that was what you had in mind?


For example refactor this:
```
fastify.register((instance, opts, done) => {
instance.addHook('onRoute', (routeOptions) => {
const { path, method } = routeOptions;
console.log({ path, method });
});
done();
});
```
Into this:
```
await fastify.register((instance, opts, done) => {
instance.addHook('onRoute', (routeOptions) => {
const { path, method } = routeOptions;
console.log({ path, method });
});
done();
});
```

## Non Breaking Changes

### Change of schema for multiple types
Expand Down