Skip to content

Commit 0d5baf2

Browse files
timneutkensijjk
andauthored
Mark this.router protected (vercel#23573)
* Mark this.router protected Seems that some people (vercel#23558) are using Next.js internals based on the typings that TS generates automatically even though these values are not documented / should not be used in applications. This ensures the router value on Server is not used by accident. * Mark all variables as protected vercel#23349 * fix type error Co-authored-by: JJ Kasper <[email protected]>
1 parent 68fc4de commit 0d5baf2

File tree

2 files changed

+25
-16
lines changed

2 files changed

+25
-16
lines changed

packages/next/next-server/server/image-optimizer.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import isAnimated from 'next/dist/compiled/is-animated'
88
import { join } from 'path'
99
import Stream from 'stream'
1010
import nodeUrl, { UrlWithParsedQuery } from 'url'
11+
import { NextConfig } from '../../next-server/server/config-shared'
1112
import { fileExists } from '../../lib/file-exists'
1213
import { ImageConfig, imageConfigDefault } from './image-config'
1314
import { processBuffer, Operation } from './lib/squoosh/main'
@@ -30,9 +31,10 @@ export async function imageOptimizer(
3031
server: Server,
3132
req: IncomingMessage,
3233
res: ServerResponse,
33-
parsedUrl: UrlWithParsedQuery
34+
parsedUrl: UrlWithParsedQuery,
35+
nextConfig: NextConfig,
36+
distDir: string
3437
) {
35-
const { nextConfig, distDir } = server
3638
const imageData: ImageConfig = nextConfig.images || imageConfigDefault
3739
const { deviceSizes = [], imageSizes = [], domains = [], loader } = imageData
3840

packages/next/next-server/server/next-server.ts

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -124,18 +124,18 @@ export type ServerConstructor = {
124124
}
125125

126126
export default class Server {
127-
dir: string
128-
quiet: boolean
129-
nextConfig: NextConfig
130-
distDir: string
131-
pagesDir?: string
132-
publicDir: string
133-
hasStaticDir: boolean
134-
serverBuildDir: string
135-
pagesManifest?: PagesManifest
136-
buildId: string
137-
minimalMode: boolean
138-
renderOpts: {
127+
protected dir: string
128+
protected quiet: boolean
129+
protected nextConfig: NextConfig
130+
protected distDir: string
131+
protected pagesDir?: string
132+
protected publicDir: string
133+
protected hasStaticDir: boolean
134+
protected serverBuildDir: string
135+
protected pagesManifest?: PagesManifest
136+
protected buildId: string
137+
protected minimalMode: boolean
138+
protected renderOpts: {
139139
poweredByHeader: boolean
140140
buildId: string
141141
generateEtags: boolean
@@ -161,7 +161,7 @@ export default class Server {
161161
private compression?: Middleware
162162
private onErrorMiddleware?: ({ err }: { err: Error }) => Promise<void>
163163
private incrementalCache: IncrementalCache
164-
router: Router
164+
protected router: Router
165165
protected dynamicRoutes?: DynamicRoutes
166166
protected customRoutes: CustomRoutes
167167

@@ -784,7 +784,14 @@ export default class Server {
784784
type: 'route',
785785
name: '_next/image catchall',
786786
fn: (req, res, _params, parsedUrl) =>
787-
imageOptimizer(server, req, res, parsedUrl),
787+
imageOptimizer(
788+
server,
789+
req,
790+
res,
791+
parsedUrl,
792+
server.nextConfig,
793+
server.distDir
794+
),
788795
},
789796
{
790797
match: route('/_next/:path*'),

0 commit comments

Comments
 (0)