From 3d0d8314631b9bc7e98aa98b6fd45ad674e6eb05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damian=20G=C5=82owala?= Date: Mon, 10 Feb 2025 18:10:10 +0100 Subject: [PATCH] fix(nuxt): delete existing properties in app config HMR (#30918) --- packages/nuxt/src/app/config.ts | 7 +++++++ packages/nuxt/src/core/templates.ts | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/nuxt/src/app/config.ts b/packages/nuxt/src/app/config.ts index 476f828abf..4a677359cd 100644 --- a/packages/nuxt/src/app/config.ts +++ b/packages/nuxt/src/app/config.ts @@ -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. * diff --git a/packages/nuxt/src/core/templates.ts b/packages/nuxt/src/core/templates.ts index a42e141637..15da3975cd 100644 --- a/packages/nuxt/src/core/templates.ts +++ b/packages/nuxt/src/core/templates.ts @@ -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) }) }