Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

Commit

Permalink
fix(nuxt): use deep assignment for app.config hmr (#6788)
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Aug 22, 2022
1 parent 7e2fbcf commit 3b2b22e
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions packages/nuxt/src/app/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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) => {
Expand Down

0 comments on commit 3b2b22e

Please sign in to comment.