next.js
1e5932d5 - [Runtime prefetch] resolve runtime APIs in a separate task (#82475)

Commit
147 days ago
[Runtime prefetch] resolve runtime APIs in a separate task (#82475) In a runtime prefetch, sync IO is dangerous, because it makes us abort the whole prerender. If this abort happens early, a runtime prefetch can end up giving us *less* data than a static prefetch. To prevent this, we can split the final prerender into two separate tasks (which i'm calling "stages" in the code): 1. The static stage (task 1). This is meant to be equivalent to what we'd do during build, so runtime APIs like `cookies()` aren't resolved yet. This lets us render everything that's reachable statically. We should not hit a sync IO here -- if we had, it would've also caused an error during build. 2. The runtime stage (task 2). Here, we allow `cookies()` (and all other runtime APIs available in a runtime prerender) to resolve. We might encounter sync IO errors here (e.g. `await cookies(); Date.now()`), which will make the result suboptimal, but still usable.
Author
Parents
Loading