Skip to content

Commit 0831dd5

Browse files
authored
chore: Clean up imports and unused code (vercel#39044)
A small refactor PR to convert some imports to type imports, as well as removing a couple of unused exports. The Edge SSR loader is also missing the global process injection (`enhanceGlobals`). ## Bug - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Errors have helpful link attached, see `contributing.md` ## Feature - [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Documentation added - [ ] Telemetry added. In case of a feature if it's used or not. - [ ] Errors have helpful link attached, see `contributing.md` ## Documentation / Examples - [ ] Make sure the linting passes by running `pnpm lint` - [ ] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
1 parent 8017d69 commit 0831dd5

File tree

8 files changed

+8
-31
lines changed

8 files changed

+8
-31
lines changed

packages/next/build/webpack/loaders/next-edge-ssr-loader/index.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,13 @@ export default async function edgeSSRLoader(this: any) {
4747
: null
4848

4949
const transformed = `
50-
import { adapter } from 'next/dist/server/web/adapter'
50+
import { adapter, enhanceGlobals } from 'next/dist/server/web/adapter'
5151
import { getRender } from 'next/dist/build/webpack/loaders/next-edge-ssr-loader/render'
5252
5353
import Document from ${stringifiedDocumentPath}
5454
55+
enhanceGlobals()
56+
5557
const appMod = require(${stringifiedAppPath})
5658
const pageMod = require(${stringifiedPagePath})
5759
const errorMod = require(${stringifiedErrorPath})

packages/next/build/webpack/loaders/next-edge-ssr-loader/render.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ import type { NextConfig } from '../../../../server/config-shared'
22
import type { DocumentType, AppType } from '../../../../shared/lib/utils'
33
import type { BuildManifest } from '../../../../server/get-page-files'
44
import type { ReactLoadableManifest } from '../../../../server/load-components'
5-
6-
import { NextRequest } from '../../../../server/web/spec-extension/request'
5+
import type { NextRequest } from '../../../../server/web/spec-extension/request'
76

87
import WebServer from '../../../../server/web-server'
98
import {

packages/next/build/webpack/loaders/next-serverless-loader/utils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import type {
99
GetStaticProps,
1010
} from '../../../../types'
1111
import type { BaseNextRequest } from '../../../../server/base-http'
12+
import type { __ApiPreviewProps } from '../../../../server/api-utils'
1213

1314
import { format as formatUrl, UrlWithParsedQuery, parse as parseUrl } from 'url'
1415
import { parse as parseQs, ParsedUrlQuery } from 'querystring'
@@ -20,7 +21,6 @@ import {
2021
matchHas,
2122
prepareDestination,
2223
} from '../../../../shared/lib/router/utils/prepare-destination'
23-
import { __ApiPreviewProps } from '../../../../server/api-utils'
2424
import { acceptLanguage } from '../../../../server/accept-header'
2525
import { detectLocaleCookie } from '../../../../shared/lib/i18n/detect-locale-cookie'
2626
import { detectDomainLocale } from '../../../../shared/lib/i18n/detect-domain-locale'

packages/next/lib/constants.ts

-8
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,10 @@ import { join } from '../shared/lib/isomorphic/path'
33

44
export const NEXT_PROJECT_ROOT = join(__dirname, '..', '..')
55
export const NEXT_PROJECT_ROOT_DIST = join(NEXT_PROJECT_ROOT, 'dist')
6-
export const NEXT_PROJECT_ROOT_NODE_MODULES = join(
7-
NEXT_PROJECT_ROOT,
8-
'node_modules'
9-
)
106
export const NEXT_PROJECT_ROOT_DIST_CLIENT = join(
117
NEXT_PROJECT_ROOT_DIST,
128
'client'
139
)
14-
export const NEXT_PROJECT_ROOT_DIST_SERVER = join(
15-
NEXT_PROJECT_ROOT_DIST,
16-
'server'
17-
)
1810

1911
// Regex for API routes
2012
export const API_ROUTE = /^\/api(?:\/|$)/

packages/next/server/node-web-streams-helper.ts

-15
Original file line numberDiff line numberDiff line change
@@ -222,21 +222,6 @@ export function createSuffixStream(
222222
})
223223
}
224224

225-
export function createPrefixStream(
226-
prefix: string
227-
): TransformStream<Uint8Array, Uint8Array> {
228-
let prefixFlushed = false
229-
return new TransformStream({
230-
transform(chunk, controller) {
231-
if (!prefixFlushed) {
232-
controller.enqueue(encodeText(prefix))
233-
prefixFlushed = true
234-
}
235-
controller.enqueue(chunk)
236-
},
237-
})
238-
}
239-
240225
// Suffix after main body content - scripts before </body>,
241226
// but wait for the major chunks to be enqueued.
242227
export function createDeferredSuffixStream(

packages/next/server/router.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ import type {
55
RouteMatch,
66
Params,
77
} from '../shared/lib/router/utils/route-matcher'
8+
import type { RouteHas } from '../lib/load-custom-routes'
89

910
import { getNextInternalQuery, NextUrlWithParsedQuery } from './request-meta'
1011
import { getPathMatch } from '../shared/lib/router/utils/path-match'
1112
import { removeTrailingSlash } from '../shared/lib/router/utils/remove-trailing-slash'
1213
import { normalizeLocalePath } from '../shared/lib/i18n/normalize-locale-path'
13-
import { RouteHas } from '../lib/load-custom-routes'
1414
import { matchHas } from '../shared/lib/router/utils/prepare-destination'
1515
import { removePathPrefix } from '../shared/lib/router/utils/remove-path-prefix'
1616
import { getRequestMeta } from './request-meta'

packages/next/server/utils.ts

-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ export function stripInternalQueries(query: NextParsedUrlQuery) {
4040
delete query.__props__
4141
// routing
4242
delete query.__flight_router_state_tree__
43-
44-
return query
4543
}
4644

4745
// When react version is >= 18 opt-in using reactRoot

packages/next/server/web/spec-extension/cookies.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
import type { CookieSerializeOptions } from '../types'
2+
13
import cookie from 'next/dist/compiled/cookie'
2-
import { CookieSerializeOptions } from '../types'
34

45
type GetWithOptionsOutput = {
56
value: string | undefined

0 commit comments

Comments
 (0)