Skip to content

Commit

Permalink
enhance: ignore nextjs version fetch error in dev overlay (#66271)
Browse files Browse the repository at this point in the history
### What 

It's not helpful to see the network issue of fetching error on reading
nextjs version in dev overlay

### Why

Error case:

<img width="400"
src="https://github.com/vercel/next.js/assets/4800338/a7852d9b-1f98-4098-8498-a3b832efdbb0">

This should just be ignored, it's fine that the fetching is failed.
There're so many fetch errors code, it's easy to try-catch on fetch
instead of enumerate all the codes
  • Loading branch information
huozhi committed May 28, 2024
1 parent 0ec02b0 commit 9c993ec
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions packages/next/src/server/dev/hot-reloader-webpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,6 @@ function erroredPages(compilation: webpack.Compilation) {
return failedPages
}

const networkErrors = [
'EADDRINFO',
'ENOTFOUND',
'ETIMEDOUT',
'ECONNREFUSED',
'EAI_AGAIN',
]

export async function getVersionInfo(enabled: boolean): Promise<VersionInfo> {
let installed = '0.0.0'

Expand All @@ -211,15 +203,21 @@ export async function getVersionInfo(enabled: boolean): Promise<VersionInfo> {
installed = require('next/package.json').version

const registry = getRegistry()
const res = await fetch(`${registry}-/package/next/dist-tags`)
let res

try {
res = await fetch(`${registry}-/package/next/dist-tags`)
} catch {
// ignore fetch errors
}

if (!res.ok) return { installed, staleness: 'unknown' }
if (!res || !res.ok) return { installed, staleness: 'unknown' }

const { latest, canary } = await res.json()

return parseVersionInfo({ installed, latest, canary })
} catch (e: any) {
if (!networkErrors.includes(e?.code)) console.error(e)
console.error(e)
return { installed, staleness: 'unknown' }
}
}
Expand Down

0 comments on commit 9c993ec

Please sign in to comment.