Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: improve retrieving versionInfo on Turbo HMR #67309

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions packages/next/src/server/dev/hot-reloader-turbopack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ import {
} from '../lib/render-server'
import { denormalizePagePath } from '../../shared/lib/page-path/denormalize-page-path'
import { trace } from '../../trace'
import type { VersionInfo } from './parse-version-info'
import {
AssetMapper,
type ChangeSubscriptions,
Expand Down Expand Up @@ -504,9 +503,6 @@ export async function createHotReloaderTurbopack(
)
)
const overlayMiddleware = getOverlayMiddleware(project)
const versionInfo: VersionInfo = await getVersionInfo(
isTestMode || opts.telemetry.isEnabled
)

const hotReloader: NextJsHotReloaderInterface = {
turbopackProject: project,
Expand Down Expand Up @@ -666,15 +662,21 @@ export async function createHotReloaderTurbopack(
}
}

const sync: SyncAction = {
action: HMR_ACTIONS_SENT_TO_BROWSER.SYNC,
errors,
warnings: [],
hash: '',
versionInfo,
}
;(async function () {
const versionInfo = await getVersionInfo(
devjiwonchoi marked this conversation as resolved.
Show resolved Hide resolved
isTestMode || opts.telemetry.isEnabled
)

const sync: SyncAction = {
action: HMR_ACTIONS_SENT_TO_BROWSER.SYNC,
errors,
warnings: [],
hash: '',
versionInfo,
}

sendToClient(client, sync)
sendToClient(client, sync)
})()
})
},

Expand Down
5 changes: 2 additions & 3 deletions packages/next/src/server/dev/hot-reloader-webpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ import { getProperError } from '../../lib/is-error'
import ws from 'next/dist/compiled/ws'
import { existsSync, promises as fs } from 'fs'
import type { UnwrapPromise } from '../../lib/coalesced-function'
import { getRegistry } from '../../lib/helpers/get-registry'
import { parseVersionInfo } from './parse-version-info'
import type { VersionInfo } from './parse-version-info'
import { isAPIRoute } from '../../lib/is-api-route'
Expand Down Expand Up @@ -202,11 +201,11 @@ export async function getVersionInfo(enabled: boolean): Promise<VersionInfo> {
try {
installed = require('next/package.json').version

const registry = getRegistry()
let res

try {
res = await fetch(`${registry}-/package/next/dist-tags`)
// use NPM registry regardless user using Yarn
res = await fetch('https://registry.npmjs.org/-/package/next/dist-tags')
} catch {
// ignore fetch errors
}
Expand Down
Loading