Fix experimental optimizeCss for SSR (#22513)

This ensures `distDir` is set under `renderOpts` in `next-server` so that it is present when experimental `optimizeCss` is enabled. 

x-ref: https://github.com/vercel/next.js/pull/16539
This commit is contained in:
JJ Kasper 2021-02-25 03:56:11 -06:00 committed by GitHub
parent c81eadc6dc
commit 6d068aed4f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 3 deletions

View file

@ -161,6 +161,7 @@ export default class Server {
locales?: string[]
defaultLocale?: string
domainLocales?: DomainLocales
distDir: string
}
private compression?: Middleware
private onErrorMiddleware?: ({ err }: { err: Error }) => Promise<void>
@ -218,6 +219,7 @@ export default class Server {
optimizeImages: this.nextConfig.experimental.optimizeImages,
optimizeCss: this.nextConfig.experimental.optimizeCss,
domainLocales: this.nextConfig.i18n?.domains,
distDir: this.distDir,
}
// Only the `publicRuntimeConfig` key is exposed to the client side

View file

@ -8,4 +8,10 @@ export default function Home() {
)
}
Home.getInitialProps = () => ({})
export const getServerSideProps = () => {
return {
props: {
hello: 'world',
},
}
}

View file

@ -19,7 +19,7 @@ let app
function runTests() {
it('should inline critical CSS', async () => {
const html = await renderViaHTTP(appPort, '/index')
const html = await renderViaHTTP(appPort, '/')
expect(html).toMatch(
/<link rel="stylesheet" href="\/_next\/static\/css\/.*\.css" .*>/
)
@ -27,7 +27,7 @@ function runTests() {
})
it('should not inline non-critical css', async () => {
const html = await renderViaHTTP(appPort, '/index')
const html = await renderViaHTTP(appPort, '/')
expect(html).not.toMatch(/.extra-style/)
})
}