fix(nuxt): delete existing properties in app config HMR (#30918)

This commit is contained in:
Damian Głowala 2025-02-10 18:10:10 +01:00 committed by Daniel Roe
parent 31e72ded69
commit 3d0d831463
No known key found for this signature in database
GPG Key ID: CBC814C393D93268
2 changed files with 9 additions and 2 deletions

View File

@ -54,6 +54,13 @@ export function useAppConfig (): AppConfig {
return nuxtApp._appConfig
}
export function _replaceAppConfig (newConfig: AppConfig) {
const appConfig = useAppConfig()
deepAssign(appConfig, newConfig)
deepDelete(appConfig, newConfig)
}
/**
* Deep assign the current appConfig with the new one.
*

View File

@ -425,7 +425,7 @@ export const appConfigTemplate: NuxtTemplate = {
write: true,
getContents ({ app, nuxt }) {
return `
import { updateAppConfig } from '#app/config'
import { _replaceAppConfig } from '#app/config'
import { defuFn } from 'defu'
const inlineConfig = ${JSON.stringify(nuxt.options.appConfig, null, 2)}
@ -433,7 +433,7 @@ const inlineConfig = ${JSON.stringify(nuxt.options.appConfig, null, 2)}
// Vite - webpack is handled directly in #app/config
if (import.meta.hot) {
import.meta.hot.accept((newModule) => {
updateAppConfig(newModule.default)
_replaceAppConfig(newModule.default)
})
}