From 2c6d4f3fe1df8b1acba1de90cda5312f61fd4323 Mon Sep 17 00:00:00 2001 From: rthrth-svg <267244824+rthrth-svg@users.noreply.github.com> Date: Fri, 13 Mar 2026 21:27:08 +0000 Subject: [PATCH] fix(web): copy yearMonth in MonthGroup to avoid shared object reference with asset (#26890) Co-authored-by: Min Idzelis --- .../timeline-manager/month-group.svelte.ts | 2 +- .../timeline-manager.svelte.spec.ts | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) 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,