Skip to content

High performance self-hosted photo and video management solution.

fix(web): copy yearMonth in MonthGroup to avoid shared object reference with asset (#26890)

rthrth-svg2c6d4f3fe1df
diff --git a/web/src/lib/managers/timeline-manager/month-group.svelte.ts b/web/src/lib/managers/timeline-manager/month-group.svelte.ts
index 3b3860eb9c..b41deb5785 100644
--- a/web/src/lib/managers/timeline-manager/month-group.svelte.ts
+++ b/web/src/lib/managers/timeline-manager/month-group.svelte.ts
@@ -60,7 +60,7 @@ export class MonthGroup {
this.#initialCount = initialCount;
this.#sortOrder = order;
- this.yearMonth = yearMonth;
+ this.yearMonth = { year: yearMonth.year, month: yearMonth.month };
this.monthGroupTitle = formatMonthGroupTitle(fromTimelinePlainYearMonth(yearMonth));
this.loader = new CancellableTask(
diff --git a/web/src/lib/managers/timeline-manager/timeline-manager.svelte.spec.ts b/web/src/lib/managers/timeline-manager/timeline-manager.svelte.spec.ts
index 8addc173c4..943b5d12a8 100644
--- a/web/src/lib/managers/timeline-manager/timeline-manager.svelte.spec.ts
+++ b/web/src/lib/managers/timeline-manager/timeline-manager.svelte.spec.ts
@@ -355,6 +355,29 @@ describe('TimelineManager', () => {
expect(getMonthGroupByDate(timelineManager, { year: 2024, month: 3 })).not.toBeUndefined();
expect(getMonthGroupByDate(timelineManager, { year: 2024, month: 3 })?.getAssets().length).toEqual(1);
});
+
+ it('yearMonth is not a shared reference with asset.localDateTime (reference bug)', () => {
+ const asset = deriveLocalDateTimeFromFileCreatedAt(
+ timelineAssetFactory.build({
+ fileCreatedAt: fromISODateTimeUTCToObject('2024-01-20T12:00:00.000Z'),
+ }),
+ );
+
+ timelineManager.upsertAssets([asset]);
+ const januaryMonth = getMonthGroupByDate(timelineManager, { year: 2024, month: 1 })!;
+ const monthYearMonth = januaryMonth.yearMonth;
+
+ const originalMonth = monthYearMonth.month;
+ expect(originalMonth).toEqual(1);
+
+ // Simulating updateObject
+ asset.localDateTime.month = 3;
+ asset.localDateTime.day = 20;
+
+ expect(monthYearMonth.month).toEqual(originalMonth);
+ expect(monthYearMonth.month).toEqual(1);
+ });
+
it('asset is removed during upsert when TimelineManager if visibility changes', async () => {
await timelineManager.updateOptions({
visibility: AssetVisibility.Archive,