fix(nuxt): use deep assignment for app.config hmr (#6788)

This commit is contained in:
pooya parsa 2022-08-22 11:14:25 +02:00 committed by GitHub
parent 7e2fbcfb1d
commit 3b2b22e384
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 3 deletions

View File

@ -20,9 +20,7 @@ if (process.dev) {
function applyHMR (newConfig: AppConfig) {
const appConfig = useAppConfig()
if (newConfig && appConfig) {
for (const key in newConfig) {
(appConfig as any)[key] = (newConfig as any)[key]
}
deepAssign(appConfig, newConfig)
for (const key in appConfig) {
if (!(key in newConfig)) {
delete (appConfig as any)[key]
@ -31,6 +29,17 @@ if (process.dev) {
}
}
function deepAssign (obj: any, newObj: any) {
for (const key in newObj) {
const val = newObj[key]
if (val !== null && typeof val === 'object') {
deepAssign(obj[key], val)
} else {
obj[key] = val
}
}
}
// Vite
if (import.meta.hot) {
import.meta.hot.accept((newModule) => {