Skip to content

Commit

Permalink
apply suggestions from review
Browse files Browse the repository at this point in the history
  • Loading branch information
ijjk committed Jul 30, 2024
1 parent 33ac621 commit 5922a08
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ export function getSocketUrl(assetPrefix: string | undefined): string {
const protocol = getSocketProtocol(assetPrefix || '')
const prefix = normalizedAssetPrefix(assetPrefix)

// same check but on original assetPrefix value
if (assetPrefix?.replace(/^\/+/, '').startsWith('http')) {
// if original assetPrefix is a full URL with protocol
// we just update to use the correct `ws` protocol
if (assetPrefix?.replace(/^\/+/, '').includes('://')) {
return `${protocol}://${prefix}`
}

Expand Down
2 changes: 2 additions & 0 deletions packages/next/src/server/lib/router-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,8 @@ export async function initialize(opts: {
const { basePath, assetPrefix } = config

let hmrPrefix = basePath

// assetPrefix overrides basePath for HMR path
if (assetPrefix) {
hmrPrefix = normalizedAssetPrefix(assetPrefix)
}
Expand Down
4 changes: 2 additions & 2 deletions packages/next/src/shared/lib/normalized-asset-prefix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ export function normalizedAssetPrefix(assetPrefix: string | undefined): string {
const escapedAssetPrefix = assetPrefix?.replace(/^\/+/, '') || false

// assetPrefix as a url
if (escapedAssetPrefix && escapedAssetPrefix.startsWith('http')) {
if (escapedAssetPrefix && escapedAssetPrefix.startsWith('://')) {
return escapedAssetPrefix.split('://', 2)[1]
}

// assetPrefix is set to `undefined` or '/'
if (!escapedAssetPrefix || escapedAssetPrefix === '') {
if (!escapedAssetPrefix) {
return ''
}

Expand Down
6 changes: 2 additions & 4 deletions test/development/basic/hmr.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@ import type { NextConfig } from 'next'

describe.each([
{ basePath: '', assetPrefix: '' },
{ basePath: '', assetPrefix: undefined },
{ basePath: '', assetPrefix: '/ap' },
{ basePath: '', assetPrefix: '/asset-prefix' },
{ basePath: '/docs', assetPrefix: '' },
{ basePath: '/docs', assetPrefix: undefined },
{ basePath: '/docs', assetPrefix: '/ap' },
{ basePath: '/docs', assetPrefix: '/asset-prefix' },
])('basic HMR, nextConfig: %o', (nextConfig: Partial<NextConfig>) => {
const { basePath } = nextConfig
let next: NextInstance
Expand Down

0 comments on commit 5922a08

Please sign in to comment.