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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fill Migration-Guide-V4.md #3988

Closed
2 tasks done
mcollina opened this issue Jun 9, 2022 · 8 comments 路 Fixed by #4087 or #4242
Closed
2 tasks done

Fill Migration-Guide-V4.md #3988

mcollina opened this issue Jun 9, 2022 · 8 comments 路 Fixed by #4087 or #4242
Labels
documentation Improvements or additions to documentation feature request New feature to be added good first issue Good for newcomers

Comments

@mcollina
Copy link
Member

mcollina commented Jun 9, 2022

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the feature has not already been requested

馃殌 Feature Proposal

As titled, it's currently missing all the content of the release blog post https://medium.com/@fastifyjs/fastify-v4-ga-59f2103b5f0e

Motivation

No response

Example

No response

@mcollina mcollina added feature request New feature to be added documentation Improvements or additions to documentation good first issue Good for newcomers labels Jun 9, 2022
@Fdawgs
Copy link
Member

Fdawgs commented Jun 10, 2022

Will have a go at this next week as I plan on moving some of the hospital's minor Fastify-based APIs over to v4, so will probably stumble on things not covered in the blog post. Edit: Won't be able to try this out until July 7th at earliest.

Few questions related to the breaking changes:

  • Making it mandatory to return reply
    • Is there any reason a user should/would use reply.send('hello') now that returns are mandatory?
      • In v3 you would either use a return or use a reply.send(), so reply.send() seems redundant now.
  • Route registration now being synchronous
    • Does this only apply to .register() functions, or do all server functions (i.e. .addHook()) need to be awaited?
    • Can the functions be chained or do they need to be awaited individually?
  • Deprecation of variadic .listen signature
    • As they are not mentioned explicitly I wanted to double-check, are the following options still valid?:
      fastify.listen(
      	{
      		port: 0,
      		host: "localhost",
      		exclusive: false,
      		readableAll: false,
      		writableAll: false,
      		ipv6Only: false,
      	},
      	(err) => {}
      );

@112RG
Copy link
Contributor

112RG commented Jun 10, 2022

I too am confused about return reply being mandatory.

Since routes like this still function?

  fastify.get('/', async (req, reply) => {
    reply.view('login', { captcha: process.env.CAPTCHA_LOGIN, sitekey: process.env.CAPTCHA_SITE_KEY, token: await reply.generateCsrf() })

@climba03003
Copy link
Member

Since routes like this still function?

Yes, and you can also do the following.

fastify.get('/', async function(request, reply) {
  return reply.view('index')
})

@mcollina
Copy link
Member Author

Is there any reason a user should/would use reply.send('hello') now that returns are mandatory?

There are advanced cases for which it's still needed, but the majority of users should not use it.

Does this only apply to .register() functions, or do all server functions (i.e. .addHook()) need to be awaited?

only register

Can the functions be chained or do they need to be awaited individually?

You can just await the last one

Deprecation of variadic .listen signature

All other options are still there

@jsumners
Copy link
Member

function (request, reply) {
  reply.send('foo')
}
// is different than
async function (request, reply) {
  return reply.send('foo')
}

@mhamann
Copy link

mhamann commented Jun 17, 2022

One thing that's unclear to me from the Medium post is whether it's possible to migrate to Fastify v4 without converting your entire app to ESM? Based on the new way plugins are shown to be imported async import('module"), it feels like this is going to cause a ton of pain for v3.x users who are still largely doing CJS. Maybe I'm missing something?

@jsumners
Copy link
Member

No. We are not ESM only and likely never will be.

@Fdawgs
Copy link
Member

Fdawgs commented Jul 20, 2022

So i've almost completed a migration of one API from v3 to v4.

I think what is already in the migration guide, as well as what is in the Medium post, covers the majority of changes.

The documentation around the changes to the error handler need to be expanded though, as I ran into the same issue as #3959 with checking res.statusCode.

@Fdawgs Fdawgs linked a pull request Sep 1, 2022 that will close this issue
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation feature request New feature to be added good first issue Good for newcomers
Projects
None yet
7 participants
@mcollina @mhamann @jsumners @112RG @climba03003 @Fdawgs and others