Skip to content

Commit

Permalink
fix(mergeConfig): don't recreate server.hmr.server instance (#17763)
Browse files Browse the repository at this point in the history
  • Loading branch information
Vija02 authored Jul 30, 2024
1 parent e408542 commit 5c55b29
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
13 changes: 13 additions & 0 deletions packages/vite/src/node/__tests__/config.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import http from 'node:http'
import { describe, expect, test } from 'vitest'
import type { InlineConfig } from '..'
import type { PluginOption, UserConfig, UserConfigExport } from '../config'
Expand Down Expand Up @@ -185,6 +186,18 @@ describe('mergeConfig', () => {
expect(mergeConfig(newConfig, baseConfig)).toEqual(mergedConfig)
})

test('handles server.hmr.server', () => {
const httpServer = http.createServer()

const baseConfig = { server: { hmr: { server: httpServer } } }
const newConfig = { server: { hmr: { server: httpServer } } }

const mergedConfig = mergeConfig(baseConfig, newConfig)

// Server instance should not be recreated
expect(mergedConfig.server.hmr.server).toBe(httpServer)
})

test('throws error with functions', () => {
const baseConfig = defineConfig(() => ({ base: 'base' }))
const newConfig = defineConfig(() => ({ base: 'new' }))
Expand Down
3 changes: 3 additions & 0 deletions packages/vite/src/node/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1110,6 +1110,9 @@ function mergeConfigRecursively(
...backwardCompatibleWorkerPlugins(value),
]
continue
} else if (key === 'server' && rootPath === 'server.hmr') {
merged[key] = value
continue
}

if (Array.isArray(existing) || Array.isArray(value)) {
Expand Down

0 comments on commit 5c55b29

Please sign in to comment.