Unverified Commit 6d068aed authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

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
parent c81eadc6
...@@ -161,6 +161,7 @@ export default class Server { ...@@ -161,6 +161,7 @@ export default class Server {
locales?: string[] locales?: string[]
defaultLocale?: string defaultLocale?: string
domainLocales?: DomainLocales domainLocales?: DomainLocales
distDir: string
} }
private compression?: Middleware private compression?: Middleware
private onErrorMiddleware?: ({ err }: { err: Error }) => Promise<void> private onErrorMiddleware?: ({ err }: { err: Error }) => Promise<void>
...@@ -218,6 +219,7 @@ export default class Server { ...@@ -218,6 +219,7 @@ export default class Server {
optimizeImages: this.nextConfig.experimental.optimizeImages, optimizeImages: this.nextConfig.experimental.optimizeImages,
optimizeCss: this.nextConfig.experimental.optimizeCss, optimizeCss: this.nextConfig.experimental.optimizeCss,
domainLocales: this.nextConfig.i18n?.domains, domainLocales: this.nextConfig.i18n?.domains,
distDir: this.distDir,
} }
// Only the `publicRuntimeConfig` key is exposed to the client side // Only the `publicRuntimeConfig` key is exposed to the client side
......
...@@ -8,4 +8,10 @@ export default function Home() { ...@@ -8,4 +8,10 @@ export default function Home() {
) )
} }
Home.getInitialProps = () => ({}) export const getServerSideProps = () => {
return {
props: {
hello: 'world',
},
}
}
...@@ -19,7 +19,7 @@ let app ...@@ -19,7 +19,7 @@ let app
function runTests() { function runTests() {
it('should inline critical CSS', async () => { it('should inline critical CSS', async () => {
const html = await renderViaHTTP(appPort, '/index') const html = await renderViaHTTP(appPort, '/')
expect(html).toMatch( expect(html).toMatch(
/<link rel="stylesheet" href="\/_next\/static\/css\/.*\.css" .*>/ /<link rel="stylesheet" href="\/_next\/static\/css\/.*\.css" .*>/
) )
...@@ -27,7 +27,7 @@ function runTests() { ...@@ -27,7 +27,7 @@ function runTests() {
}) })
it('should not inline non-critical css', async () => { 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/) expect(html).not.toMatch(/.extra-style/)
}) })
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment