Skip to content

Commit 30c0946

Browse files
slusarzcmouse
authored andcommitted
vitepress: Fix reloading dev server
Javascript/Nodejs/Vite fun: we use JS dynamic import to load the data files. When reloading the dev server, these imports aren't executed again, since the namespace that was imported already exists. This means that any modification of the data is actually global, since the object references the original data. The data manpulation code is assuming that the data is "fresh" from the data files, so this breaks things. Solution: when loading data, do a deep clone and pass that to our data manipulation functions.
1 parent 0ab9eb3 commit 30c0946

6 files changed

+8
-6
lines changed

lib/data/doveadm.data.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ export default {
151151
watch: await watchFiles(),
152152
async load() {
153153
return await normalizeDoveadm(
154-
(await loadData('doveadm')).doveadm
154+
structuredClone((await loadData('doveadm')).doveadm)
155155
)
156156
}
157157
}

lib/data/event_categories.data.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export default {
1515
watch: await watchFiles(),
1616
async load() {
1717
return await normalizeEventCategories(
18-
(await loadData('event_categories')).categories
18+
structuredClone((await loadData('event_categories')).categories)
1919
)
2020
}
2121
}

lib/data/event_reasons.data.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export default {
1515
watch: await watchFiles(),
1616
async load() {
1717
return await normalizeEventReasons(
18-
(await loadData('event_reasons')).reasons
18+
structuredClone((await loadData('event_reasons')).reasons)
1919
)
2020
}
2121
}

lib/data/events.data.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,9 @@ export default {
105105
async load() {
106106
const data = await loadData('events')
107107
return await normalizeEvents(
108-
data.events, data.global_inherits, data.inherits
108+
structuredClone(data.events),
109+
structuredClone(data.global_inherits),
110+
structuredClone(data.inherits)
109111
)
110112
}
111113
}

lib/data/lua.data.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export default {
2121
watch: await watchFiles(),
2222
async load() {
2323
return await normalizeLua(
24-
(await loadData('lua')).lua_functions
24+
structuredClone((await loadData('lua')).lua_functions)
2525
)
2626
}
2727
}

lib/data/settings.data.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export default {
6969
watch: await watchFiles(),
7070
async load() {
7171
return await normalizeSettings(
72-
(await loadData('settings')).settings
72+
structuredClone((await loadData('settings')).settings)
7373
)
7474
}
7575
}

0 commit comments

Comments
 (0)