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 cache method handling during build #49633

Merged
merged 1 commit into from
May 11, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions packages/next/src/build/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ import { IncrementalCache } from '../server/lib/incremental-cache'
import { patchFetch } from '../server/lib/patch-fetch'
import { nodeFs } from '../server/lib/node-fs-methods'
import '../server/node-environment'
import * as ciEnvironment from '../telemetry/ci-info'

export type ROUTER_TYPE = 'pages' | 'app'

Expand Down Expand Up @@ -1216,6 +1217,7 @@ export async function buildAppStaticPaths({
}),
CurCacheHandler: CacheHandler,
requestHeaders,
minimalMode: ciEnvironment.hasNextSupport,
})

return StaticGenerationAsyncStorageWrapper.wrap(
Expand Down
1 change: 1 addition & 0 deletions packages/next/src/export/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ export default async function exportPage({
},
serverDistDir: join(distDir, 'server'),
CurCacheHandler: CacheHandler,
minimalMode: ciEnvironment.hasNextSupport,
})
;(globalThis as any).__incrementalCache = incrementalCache
curRenderOpts.incrementalCache = incrementalCache
Expand Down
19 changes: 15 additions & 4 deletions packages/next/src/server/lib/incremental-cache/fetch-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,21 @@ export default class FetchCache implements CacheHandler {
}
delete ctx._requestHeaders[FETCH_CACHE_HEADER]
}
if (ctx._requestHeaders['x-vercel-sc-host']) {
this.cacheEndpoint = `https://${ctx._requestHeaders['x-vercel-sc-host']}${
ctx._requestHeaders['x-vercel-sc-basepath'] || ''
}`
const scHost =
ctx._requestHeaders['x-vercel-sc-host'] || process.env.SUSPENSE_CACHE_URL

const scBasePath =
ctx._requestHeaders['x-vercel-sc-basepath'] ||
process.env.SUSPENSE_CACHE_BASEPATH

if (process.env.SUSPENSE_CACHE_AUTH_TOKEN) {
this.headers[
'Authorization'
] = `Bearer ${process.env.SUSPENSE_CACHE_AUTH_TOKEN}`
}

if (scHost) {
this.cacheEndpoint = `https://${scHost}${scBasePath || ''}`
if (this.debug) {
console.log('using cache endpoint', this.cacheEndpoint)
}
Expand Down