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 1 commit
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
10 changes: 10 additions & 0 deletions packages/next/server/base-server.ts
Expand Up @@ -58,6 +58,7 @@ import { MIDDLEWARE_ROUTE } from '../lib/constants'
import { addRequestMeta, getRequestMeta } from './request-meta'
import { createHeaderRoute, createRedirectRoute } from './server-route-utils'
import { PrerenderManifest } from '../build'
import { ImageOptimizerCache } from './image-optimizer'

export type FindComponentsResult = {
components: LoadComponentsReturnType
Expand Down Expand Up @@ -165,6 +166,7 @@ export default abstract class Server {
}
private incrementalCache: IncrementalCache
private responseCache: ResponseCache
protected imageResponseCache: ResponseCache
protected router: Router
protected dynamicRoutes?: DynamicRoutes
protected customRoutes: CustomRoutes
Expand Down Expand Up @@ -360,6 +362,12 @@ export default abstract class Server {
},
})
this.responseCache = new ResponseCache(this.incrementalCache)
this.imageResponseCache = new ResponseCache(
new ImageOptimizerCache({
distDir: this.distDir,
nextConfig: this.nextConfig,
}) as any
ijjk marked this conversation as resolved.
Show resolved Hide resolved
)
}

public logError(err: Error): void {
Expand Down Expand Up @@ -1516,6 +1524,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