Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/canary' into wbinnssmith/write-a…
Browse files Browse the repository at this point in the history
…ll-endpoints
  • Loading branch information
wbinnssmith committed Jan 30, 2025
2 parents 9303b4b + 0f7251f commit 9b469ad
Show file tree
Hide file tree
Showing 22 changed files with 311 additions and 108 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ jobs:
name: test-reports-start-${{ matrix.group }}
if-no-files-found: 'error'
path: |
test/turbopack-test-junit-report
test/rspack-test-junit-report
test-integration-production:
name: Next.js integration test (Integration)
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/rspack-nextjs-dev-integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ jobs:
name: test-reports-dev-${{ matrix.group }}
if-no-files-found: 'error'
path: |
test/turbopack-test-junit-report
test/rspack-test-junit-report
test-integration-development:
name: Next.js integration test (Integration)
Expand Down Expand Up @@ -149,7 +149,7 @@ jobs:
name: test-reports-dev-integration-${{ matrix.group }}
if-no-files-found: 'error'
path: |
test/turbopack-test-junit-report
test/rspack-test-junit-report
# Collect integration test results from execute_tests,
# Store it as github artifact for next step to consume.
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/rspack-update-tests-manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN_PULL_REQUESTS }}
BRANCH_NAME: rspack-manifest
SCRIPT: test/build-turbopack-dev-tests-manifest.js
SCRIPT: test/build-rspack-dev-tests-manifest.js
PR_TITLE: Update Rspack development test manifest
PR_BODY: This auto-generated PR updates the development integration test manifest used when testing Rspack.
update_build_manifest:
name: Update and upload Turbopack production test manifest
name: Update and upload Rspack production test manifest
if: github.repository_owner == 'vercel'
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -71,6 +71,6 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN_PULL_REQUESTS }}
BRANCH_NAME: rspack-manifest
SCRIPT: test/build-turbopack-build-tests-manifest.js
SCRIPT: test/build-rspack-build-tests-manifest.js
PR_TITLE: Update Rspack production test manifest
PR_BODY: This auto-generated PR updates the production integration test manifest used when testing Rspack.
11 changes: 8 additions & 3 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,14 @@ if (enableTestReport) {
customJestConfig.reporters = ['default']
}

const outputDirectory = process.env.TURBOPACK
? '<rootDir>/turbopack-test-junit-report'
: '<rootDir>/test-junit-report'
let outputDirectory
if (process.env.TURBOPACK) {
outputDirectory = '<rootDir>/turbopack-test-junit-report'
} else if (process.env.NEXT_RSPACK) {
outputDirectory = '<rootDir>/rspack-test-junit-report'
} else {
outputDirectory = '<rootDir>/test-junit-report'
}

customJestConfig.reporters.push([
'jest-junit',
Expand Down
26 changes: 21 additions & 5 deletions packages/next/src/server/base-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1182,7 +1182,8 @@ export default abstract class Server<
let params: ParsedUrlQuery | false = {}

let paramsResult = utils.normalizeDynamicRouteParams(
parsedUrl.query
parsedUrl.query,
false
)

// for prerendered ISR paths we attempt parsing the route
Expand All @@ -1196,7 +1197,7 @@ export default abstract class Server<
let matcherParams = utils.dynamicRouteMatcher?.(normalizedUrlPath)

if (matcherParams) {
utils.normalizeDynamicRouteParams(matcherParams)
utils.normalizeDynamicRouteParams(matcherParams, false)
Object.assign(paramsResult.params, matcherParams)
paramsResult.hasValidParams = true
}
Expand All @@ -1218,8 +1219,10 @@ export default abstract class Server<
let matcherParams = utils.dynamicRouteMatcher?.(matchedPath)

if (matcherParams) {
const curParamsResult =
utils.normalizeDynamicRouteParams(matcherParams)
const curParamsResult = utils.normalizeDynamicRouteParams(
matcherParams,
false
)

if (curParamsResult.hasValidParams) {
Object.assign(params, matcherParams)
Expand Down Expand Up @@ -1254,6 +1257,19 @@ export default abstract class Server<
}
}

// Try to parse the params from the query if we couldn't parse them
// from the route matches but ignore missing optional params.
if (!paramsResult.hasValidParams) {
paramsResult = utils.normalizeDynamicRouteParams(
parsedUrl.query,
true
)

if (paramsResult.hasValidParams) {
params = paramsResult.params
}
}

// handle the actual dynamic route name being requested
if (
utils.defaultRouteMatches &&
Expand All @@ -1276,7 +1292,7 @@ export default abstract class Server<
}

if (pageIsDynamic || didRewrite) {
utils.normalizeVercelUrl(req, true, [
utils.normalizeVercelUrl(req, [
...rewriteParamKeys,
...Object.keys(utils.defaultRouteRegex?.groups || {}),
])
Expand Down
19 changes: 7 additions & 12 deletions packages/next/src/server/dev/hot-middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,11 @@ class EventStream {
this.clients = new Set()
}

everyClient(fn: (client: ws) => void) {
for (const client of this.clients) {
fn(client)
}
}

close() {
this.everyClient((client) => {
client.close()
})
for (const wsClient of this.clients) {
// it's okay to not cleanly close these websocket connections, this is dev
wsClient.terminate()
}
this.clients.clear()
}

Expand All @@ -93,9 +88,9 @@ class EventStream {
}

publish(payload: any) {
this.everyClient((client) => {
client.send(JSON.stringify(payload))
})
for (const wsClient of this.clients) {
wsClient.send(JSON.stringify(payload))
}
}
}

Expand Down
7 changes: 7 additions & 0 deletions packages/next/src/server/dev/hot-reloader-turbopack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1059,6 +1059,13 @@ export async function createHotReloaderTurbopack(
}
})
},
close() {
for (const wsClient of clients) {
// it's okay to not cleanly close these websocket connections, this is dev
wsClient.terminate()
}
clients.clear()
},
}

handleEntrypointsSubscription().catch((err) => {
Expand Down
1 change: 1 addition & 0 deletions packages/next/src/server/dev/hot-reloader-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,4 +182,5 @@ export interface NextJsHotReloaderInterface {
definition: RouteDefinition | undefined
url?: string
}): Promise<void>
close(): void
}
4 changes: 4 additions & 0 deletions packages/next/src/server/dev/hot-reloader-webpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1595,4 +1595,8 @@ export default class HotReloaderWebpack implements NextJsHotReloaderInterface {
})
})
}

public close() {
this.webpackHotMiddleware?.close()
}
}
4 changes: 4 additions & 0 deletions packages/next/src/server/lib/dev-bundler-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,8 @@ export class DevBundlerService {
data: this.appIsrManifest,
})
}

public close() {
this.bundler.hotReloader.close()
}
}
5 changes: 5 additions & 0 deletions packages/next/src/server/lib/render-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export type ServerInitResult = {
requestHandler: RequestHandler
upgradeHandler: UpgradeHandler
server: NextServer
// Make an effort to close upgraded HTTP requests (e.g. Turbopack HMR websockets)
closeUpgraded: () => void
}

let initializations: Record<string, Promise<ServerInitResult> | undefined> = {}
Expand Down Expand Up @@ -109,6 +111,9 @@ async function initializeImpl(opts: {
requestHandler,
upgradeHandler,
server,
closeUpgraded() {
opts.bundlerService?.close()
},
}
}

Expand Down
9 changes: 8 additions & 1 deletion packages/next/src/server/lib/router-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -751,5 +751,12 @@ export async function initialize(opts: {
}
}

return { requestHandler, upgradeHandler, server: handlers.server }
return {
requestHandler,
upgradeHandler,
server: handlers.server,
closeUpgraded() {
developmentBundler?.hotReloader?.close()
},
}
}
10 changes: 8 additions & 2 deletions packages/next/src/server/lib/start-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ export async function startServer(

try {
let cleanupStarted = false
let closeUpgraded: (() => void) | null = null
const cleanup = () => {
if (cleanupStarted) {
// We can get duplicate signals, e.g. when `ctrl+c` is used in an
Expand All @@ -303,12 +304,16 @@ export async function startServer(

// first, stop accepting new connections and finish pending requests,
// because they might affect `nextServer.close()` (e.g. by scheduling an `after`)
await new Promise<void>((res) =>
await new Promise<void>((res) => {
server.close((err) => {
if (err) console.error(err)
res()
})
)
if (isDev) {
server.closeAllConnections()
closeUpgraded?.()
}
})

// now that no new requests can come in, clean up the rest
await Promise.all([
Expand Down Expand Up @@ -360,6 +365,7 @@ export async function startServer(
requestHandler = initResult.requestHandler
upgradeHandler = initResult.upgradeHandler
nextServer = initResult.server
closeUpgraded = initResult.closeUpgraded

const startServerProcessDuration =
performance.mark('next-start-end') &&
Expand Down
Loading

0 comments on commit 9b469ad

Please sign in to comment.