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

View File

@ -20,9 +20,7 @@ if (process.dev) {
function applyHMR (newConfig: AppConfig) { function applyHMR (newConfig: AppConfig) {
const appConfig = useAppConfig() const appConfig = useAppConfig()
if (newConfig && appConfig) { if (newConfig && appConfig) {
for (const key in newConfig) { deepAssign(appConfig, newConfig)
(appConfig as any)[key] = (newConfig as any)[key]
}
for (const key in appConfig) { for (const key in appConfig) {
if (!(key in newConfig)) { if (!(key in newConfig)) {
delete (appConfig as any)[key] 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 // Vite
if (import.meta.hot) { if (import.meta.hot) {
import.meta.hot.accept((newModule) => { import.meta.hot.accept((newModule) => {