Skip to content

Commit

Permalink
Add X-Prerender-Bypass-Mode header support
Browse files Browse the repository at this point in the history
  • Loading branch information
Timer committed Feb 8, 2020
1 parent 8d4d990 commit c4e4a61
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
1 change: 0 additions & 1 deletion packages/next/next-server/server/api-utils.ts
Expand Up @@ -253,7 +253,6 @@ export function sendJson(res: NextApiResponse, jsonBody: any): void {
res.send(jsonBody)
}

// X-Prerender-Bypass-Mode
const COOKIE_NAME_PRERENDER_BYPASS = `__prerender_bypass`
const COOKIE_NAME_PRERENDER_DATA = `__next_preview_data`

Expand Down
11 changes: 9 additions & 2 deletions packages/next/next-server/server/next-server.ts
Expand Up @@ -1034,8 +1034,15 @@ export default class Server {
return { html, pageData, sprRevalidate }
})

// render fallback if cached data wasn't available
if (!isResSent(res) && !isDataReq && isDynamicRoute(pathname)) {
// render fallback if for a preview path or a non-seeded dynamic path
if (
!isResSent(res) &&
!isDataReq &&
((isPreviewMode &&
// A header can opt into the blocking behavior.
req.headers['X-Prerender-Bypass-Mode'] !== 'Blocking') ||
isDynamicRoute(pathname))
) {
let html = ''

if (!this.renderOpts.dev) {
Expand Down

0 comments on commit c4e4a61

Please sign in to comment.