diff --git a/packages/next/src/client/components/react-dev-overlay/internal/helpers/get-socket-url.ts b/packages/next/src/client/components/react-dev-overlay/internal/helpers/get-socket-url.ts index 3a3b87ac28a5b3..61b42d9afcb6d5 100644 --- a/packages/next/src/client/components/react-dev-overlay/internal/helpers/get-socket-url.ts +++ b/packages/next/src/client/components/react-dev-overlay/internal/helpers/get-socket-url.ts @@ -16,8 +16,8 @@ export function getSocketUrl(assetPrefix: string | undefined): string { const protocol = getSocketProtocol(assetPrefix || '') if (URL.canParse(prefix)) { - // since normalized asset prefix is ensured to be a URL format, - // we can safely replace the protocol + // since normalized asset prefix is ensured to be in URL format, + // we can trust to simply replace the protocol return prefix.replace(/^http/, 'ws') } diff --git a/packages/next/src/shared/lib/normalized-asset-prefix.test.ts b/packages/next/src/shared/lib/normalized-asset-prefix.test.ts index 03b8f4d0b43245..6f8a0773db519e 100644 --- a/packages/next/src/shared/lib/normalized-asset-prefix.test.ts +++ b/packages/next/src/shared/lib/normalized-asset-prefix.test.ts @@ -9,6 +9,11 @@ describe('normalizedAssetPrefix', () => { expect(normalizedAssetPrefix('')).toBe('') }) + it('should return an empty string when assetPrefix is a single slash', () => { + expect(normalizedAssetPrefix('/')).toBe('') + }) + + // we expect an empty string because it could be an unnecessary trailing slash it('should remove leading slash(es) when assetPrefix has more than one', () => { expect(normalizedAssetPrefix('///path/to/asset')).toBe('/path/to/asset') }) @@ -21,9 +26,9 @@ describe('normalizedAssetPrefix', () => { expect(normalizedAssetPrefix('path/to/asset')).toBe('/path/to/asset') }) - it('should return a pathname when assetPrefix is a URL', () => { + it('should return the URL when assetPrefix is a URL', () => { expect(normalizedAssetPrefix('https://example.com/path/to/asset')).toBe( - '/path/to/asset' + 'https://example.com/path/to/asset' ) }) })