Skip to content

Commit

Permalink
Ensure conf type for createServer is not changed (#32134)
Browse files Browse the repository at this point in the history
This reverts the type for the `conf` field in `ServerOptions` isn't changed to require all `NextConfig` values as this is a breaking change from what was previously required. We should investigate making sure this field is normalized when it is provided via a user. 

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

Fixes: #32123
x-ref: #31858
  • Loading branch information
ijjk authored Dec 4, 2021
1 parent c1a1aa4 commit 769d680
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
8 changes: 5 additions & 3 deletions packages/next/server/next-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type { IncomingMessage, ServerResponse } from 'http'
import type { LoadComponentsReturnType } from './load-components'
import type { MiddlewareManifest } from '../build/webpack/plugins/middleware-plugin'
import type { NextApiRequest, NextApiResponse } from '../shared/lib/utils'
import type { NextConfigComplete } from './config-shared'
import type { NextConfig, NextConfigComplete } from './config-shared'
import type { NextParsedUrlQuery, NextUrlWithParsedQuery } from './request-meta'
import type { ParsedNextUrl } from '../shared/lib/router/utils/parse-next-url'
import type { ParsedUrl } from '../shared/lib/router/utils/parse-url'
Expand Down Expand Up @@ -123,7 +123,7 @@ export interface Options {
/**
* Object containing the configuration next.config.js
*/
conf: NextConfigComplete
conf: NextConfig
/**
* Set to false when the server was created by Next.js
*/
Expand Down Expand Up @@ -233,7 +233,9 @@ export default class Server {
this.quiet = quiet
loadEnvConfig(this.dir, dev, Log)

this.nextConfig = conf
// TODO: should conf be normalized to prevent missing
// values from causing issues as this can be user provided
this.nextConfig = conf as NextConfigComplete
this.hostname = hostname
this.port = port

Expand Down
12 changes: 12 additions & 0 deletions test/production/typescript-basic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ describe('TypeScript basic', () => {
)
}
`,
'server.ts': `
import next from 'next';
const app = next({
dir: '.',
dev: process.env.NODE_ENV !== 'production',
conf: {
compress: false,
},
quiet: false,
});
const requestHandler = app.getRequestHandler();
`,
},
dependencies: {
typescript: '4.4.3',
Expand Down

0 comments on commit 769d680

Please sign in to comment.