fix: store VTIMEZONEs as raw jCal arrays for Vue reactivity safety

ICAL.Component instances break when wrapped by Vue's reactive proxy
(the .jCal getter returns undefined through the proxy, causing
serializeICS to crash with 'Cannot read properties of undefined').
Storing vtz.jCal (plain arrays) instead makes meta fully serializable
for both reactivity and JSON snapshot cloning.
This commit is contained in:
timeTable2 dev
2026-07-13 18:53:01 +08:00
parent 15b6f30896
commit 3af6b856e3

View File

@@ -111,7 +111,9 @@ export function parseICS(text) {
method: vcalendar.getFirstPropertyValue('method') || null, method: vcalendar.getFirstPropertyValue('method') || null,
xWrCalname: vcalendar.getFirstPropertyValue('x-wr-calname') || null, xWrCalname: vcalendar.getFirstPropertyValue('x-wr-calname') || null,
xWrTimezone: vcalendar.getFirstPropertyValue('x-wr-timezone') || null, xWrTimezone: vcalendar.getFirstPropertyValue('x-wr-timezone') || null,
vtimezones: vcalendar.getAllSubcomponents('vtimezone'), // Store raw jCal arrays (not ICAL.Component instances) so the meta stays
// plain-serializable for Vue reactivity and JSON snapshot cloning.
vtimezones: vcalendar.getAllSubcomponents('vtimezone').map((vtz) => vtz.jCal),
} }
// Events // Events
@@ -185,9 +187,10 @@ export function serializeICS({ meta, events }) {
if (meta.xWrCalname) vcalendar.updatePropertyWithValue('x-wr-calname', meta.xWrCalname) if (meta.xWrCalname) vcalendar.updatePropertyWithValue('x-wr-calname', meta.xWrCalname)
if (meta.xWrTimezone) vcalendar.updatePropertyWithValue('x-wr-timezone', meta.xWrTimezone) if (meta.xWrTimezone) vcalendar.updatePropertyWithValue('x-wr-timezone', meta.xWrTimezone)
// Re-add VTIMEZONEs (clone jCal to avoid moving from original parent) // Re-add VTIMEZONEs. meta.vtimezones stores raw jCal arrays (see parseICS),
for (const vtz of meta.vtimezones || []) { // so wrap each directly in a new Component (avoids moving the original).
vcalendar.addSubcomponent(new ICAL.Component(vtz.jCal)) for (const vtzJCal of meta.vtimezones || []) {
vcalendar.addSubcomponent(new ICAL.Component(vtzJCal))
} }
for (const ev of events) { for (const ev of events) {