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

Co-authored-by: Min Idzelis <min123@gmail.com>
This commit is contained in:
rthrth-svg 2026-03-13 21:27:08 +00:00 committed by GitHub
parent 55513cd59f
commit 2c6d4f3fe1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 24 additions and 1 deletions

View File

@ -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(

View File

@ -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,