Next.js: Does getInitialProps block the event loop on the server

Created on 15 Jan 2020  路  3Comments  路  Source: vercel/next.js

Question about Next.js

Related to #1840

While React's render is synchronous, is getInitialProps part of this render?

I assume that not to be the case, but for example, if you make an api request in getInitialProps does that block other requests from getting handled?

Most helpful comment

This question is very general but if it helps IO like making an API request is offloaded to https://github.com/libuv/libuv and handled asynchronously so node.js is capable to proceed with work while the request is in flight. This does not change the fact that node.js runs all your code synchronously.

All 3 comments

GetInitialProps is asynchronous and won鈥檛 block the main thread. However if your code inside of getInitialProps is blocking the main thread it will actually block. Fetches are also asynchronous though!

This question is very general but if it helps IO like making an API request is offloaded to https://github.com/libuv/libuv and handled asynchronously so node.js is capable to proceed with work while the request is in flight. This does not change the fact that node.js runs all your code synchronously.

Awesome, just what I needed! Thanks for the quick response guys.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rauchg picture rauchg  路  3Comments

swrdfish picture swrdfish  路  3Comments

jesselee34 picture jesselee34  路  3Comments

havefive picture havefive  路  3Comments

DvirSh picture DvirSh  路  3Comments