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 to leverage response-cache for image-optimizer #34075

Merged
merged 20 commits into from Feb 8, 2022
Merged
Show file tree
Hide file tree
Changes from 18 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
24 changes: 19 additions & 5 deletions packages/next/server/api-utils.ts
Expand Up @@ -365,15 +365,29 @@ async function unstable_revalidate(
)
}

if (typeof urlPath !== 'string' || !urlPath.startsWith('/')) {
throw new Error(
`Invalid urlPath provided to revalidate(), must be a path e.g. /blog/post-1, received ${urlPath}`
)
}

const baseUrl = context.trustHostHeader
? `https://${req.headers.host}`
: `http://${context.hostname}:${context.port}`

return fetch(`${baseUrl}${urlPath}`, {
headers: {
[PRERENDER_REVALIDATE_HEADER]: context.previewModeId,
},
})
try {
const res = await fetch(`${baseUrl}${urlPath}`, {
headers: {
[PRERENDER_REVALIDATE_HEADER]: context.previewModeId,
},
})

if (!res.ok) {
throw new Error(`Invalid response ${res.status}`)
}
} catch (err) {
throw new Error(`Failed to revalidate ${urlPath}`)
}
}

const COOKIE_NAME_PRERENDER_BYPASS = `__prerender_bypass`
Expand Down
2 changes: 2 additions & 0 deletions packages/next/server/base-server.ts
Expand Up @@ -1543,6 +1543,8 @@ export default abstract class Server {
await handleRedirect(cachedData.props)
return null
}
} else if (cachedData.kind === 'IMAGE') {
throw new Error('invariant SSG should not return an image cache value')
} else {
return {
type: isDataReq ? 'json' : 'html',
Expand Down
2 changes: 1 addition & 1 deletion packages/next/server/config-shared.ts
Expand Up @@ -8,7 +8,7 @@ import {
} from './image-config'

export type NextConfigComplete = Required<NextConfig> & {
images: ImageConfigComplete
images: Required<ImageConfigComplete>
typescript: Required<TypeScriptConfig>
configOrigin?: string
configFile?: string
Expand Down